Blame view

drivers/mfd/sun6i-prcm.c 4.31 KB
0376148f3   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
d58603cc3   Boris BREZILLON   mfd: Add support ...
2
3
4
  /*
   * Copyright (C) 2014 Free Electrons
   *
d58603cc3   Boris BREZILLON   mfd: Add support ...
5
6
7
   * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
   *
   * Allwinner PRCM (Power/Reset/Clock Management) driver
d58603cc3   Boris BREZILLON   mfd: Add support ...
8
9
10
   */
  
  #include <linux/mfd/core.h>
391cd33a0   Paul Gortmaker   mfd: sun6i-prcm: ...
11
  #include <linux/init.h>
d58603cc3   Boris BREZILLON   mfd: Add support ...
12
  #include <linux/of.h>
ea1628e85   Chen-Yu Tsai   mfd: sun6i-prcm: ...
13
14
  #define SUN8I_CODEC_ANALOG_BASE	0x1c0
  #define SUN8I_CODEC_ANALOG_SIZE	0x4
d58603cc3   Boris BREZILLON   mfd: Add support ...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  struct prcm_data {
  	int nsubdevs;
  	const struct mfd_cell *subdevs;
  };
  
  static const struct resource sun6i_a31_ar100_clk_res[] = {
  	{
  		.start = 0x0,
  		.end = 0x3,
  		.flags = IORESOURCE_MEM,
  	},
  };
  
  static const struct resource sun6i_a31_apb0_clk_res[] = {
  	{
  		.start = 0xc,
  		.end = 0xf,
  		.flags = IORESOURCE_MEM,
  	},
  };
  
  static const struct resource sun6i_a31_apb0_gates_clk_res[] = {
  	{
  		.start = 0x28,
  		.end = 0x2b,
  		.flags = IORESOURCE_MEM,
  	},
  };
6f262ecfd   Hans de Goede   mfd: sun6i-prcm: ...
43
44
45
46
47
48
49
  static const struct resource sun6i_a31_ir_clk_res[] = {
  	{
  		.start = 0x54,
  		.end = 0x57,
  		.flags = IORESOURCE_MEM,
  	},
  };
d58603cc3   Boris BREZILLON   mfd: Add support ...
50
51
52
53
54
55
56
  static const struct resource sun6i_a31_apb0_rstc_res[] = {
  	{
  		.start = 0xb0,
  		.end = 0xb3,
  		.flags = IORESOURCE_MEM,
  	},
  };
ea1628e85   Chen-Yu Tsai   mfd: sun6i-prcm: ...
57
58
59
  static const struct resource sun8i_codec_analog_res[] = {
  	DEFINE_RES_MEM(SUN8I_CODEC_ANALOG_BASE, SUN8I_CODEC_ANALOG_SIZE),
  };
d58603cc3   Boris BREZILLON   mfd: Add support ...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  static const struct mfd_cell sun6i_a31_prcm_subdevs[] = {
  	{
  		.name = "sun6i-a31-ar100-clk",
  		.of_compatible = "allwinner,sun6i-a31-ar100-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_ar100_clk_res),
  		.resources = sun6i_a31_ar100_clk_res,
  	},
  	{
  		.name = "sun6i-a31-apb0-clk",
  		.of_compatible = "allwinner,sun6i-a31-apb0-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  		.resources = sun6i_a31_apb0_clk_res,
  	},
  	{
  		.name = "sun6i-a31-apb0-gates-clk",
  		.of_compatible = "allwinner,sun6i-a31-apb0-gates-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  		.resources = sun6i_a31_apb0_gates_clk_res,
  	},
  	{
6f262ecfd   Hans de Goede   mfd: sun6i-prcm: ...
80
81
82
83
84
85
  		.name = "sun6i-a31-ir-clk",
  		.of_compatible = "allwinner,sun4i-a10-mod0-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_ir_clk_res),
  		.resources = sun6i_a31_ir_clk_res,
  	},
  	{
d58603cc3   Boris BREZILLON   mfd: Add support ...
86
87
88
89
90
91
  		.name = "sun6i-a31-apb0-clock-reset",
  		.of_compatible = "allwinner,sun6i-a31-clock-reset",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  		.resources = sun6i_a31_apb0_rstc_res,
  	},
  };
4eb9560b8   Chen-Yu Tsai   mfd: sun6i-prcm: ...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  static const struct mfd_cell sun8i_a23_prcm_subdevs[] = {
  	{
  		.name = "sun8i-a23-apb0-clk",
  		.of_compatible = "allwinner,sun8i-a23-apb0-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_clk_res),
  		.resources = sun6i_a31_apb0_clk_res,
  	},
  	{
  		.name = "sun6i-a31-apb0-gates-clk",
  		.of_compatible = "allwinner,sun8i-a23-apb0-gates-clk",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_gates_clk_res),
  		.resources = sun6i_a31_apb0_gates_clk_res,
  	},
  	{
  		.name = "sun6i-a31-apb0-clock-reset",
  		.of_compatible = "allwinner,sun6i-a31-clock-reset",
  		.num_resources = ARRAY_SIZE(sun6i_a31_apb0_rstc_res),
  		.resources = sun6i_a31_apb0_rstc_res,
  	},
ea1628e85   Chen-Yu Tsai   mfd: sun6i-prcm: ...
111
112
113
114
115
116
  	{
  		.name		= "sun8i-codec-analog",
  		.of_compatible	= "allwinner,sun8i-a23-codec-analog",
  		.num_resources	= ARRAY_SIZE(sun8i_codec_analog_res),
  		.resources	= sun8i_codec_analog_res,
  	},
4eb9560b8   Chen-Yu Tsai   mfd: sun6i-prcm: ...
117
  };
d58603cc3   Boris BREZILLON   mfd: Add support ...
118
119
120
121
  static const struct prcm_data sun6i_a31_prcm_data = {
  	.nsubdevs = ARRAY_SIZE(sun6i_a31_prcm_subdevs),
  	.subdevs = sun6i_a31_prcm_subdevs,
  };
4eb9560b8   Chen-Yu Tsai   mfd: sun6i-prcm: ...
122
123
124
125
  static const struct prcm_data sun8i_a23_prcm_data = {
  	.nsubdevs = ARRAY_SIZE(sun8i_a23_prcm_subdevs),
  	.subdevs = sun8i_a23_prcm_subdevs,
  };
d58603cc3   Boris BREZILLON   mfd: Add support ...
126
127
128
129
130
  static const struct of_device_id sun6i_prcm_dt_ids[] = {
  	{
  		.compatible = "allwinner,sun6i-a31-prcm",
  		.data = &sun6i_a31_prcm_data,
  	},
4eb9560b8   Chen-Yu Tsai   mfd: sun6i-prcm: ...
131
132
133
134
  	{
  		.compatible = "allwinner,sun8i-a23-prcm",
  		.data = &sun8i_a23_prcm_data,
  	},
d58603cc3   Boris BREZILLON   mfd: Add support ...
135
136
137
138
139
  	{ /* sentinel */ },
  };
  
  static int sun6i_prcm_probe(struct platform_device *pdev)
  {
d58603cc3   Boris BREZILLON   mfd: Add support ...
140
141
142
143
  	const struct of_device_id *match;
  	const struct prcm_data *data;
  	struct resource *res;
  	int ret;
8ca6ff16d   Arnd Bergmann   mfd: sun6i-prcm: ...
144
  	match = of_match_node(sun6i_prcm_dt_ids, pdev->dev.of_node);
d58603cc3   Boris BREZILLON   mfd: Add support ...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  	if (!match)
  		return -EINVAL;
  
  	data = match->data;
  
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	if (!res) {
  		dev_err(&pdev->dev, "no prcm memory region provided
  ");
  		return -ENOENT;
  	}
  
  	ret = mfd_add_devices(&pdev->dev, 0, data->subdevs, data->nsubdevs,
  			      res, -1, NULL);
  	if (ret) {
  		dev_err(&pdev->dev, "failed to add subdevices
  ");
  		return ret;
  	}
  
  	return 0;
  }
  
  static struct platform_driver sun6i_prcm_driver = {
  	.driver = {
  		.name = "sun6i-prcm",
d58603cc3   Boris BREZILLON   mfd: Add support ...
171
172
173
174
  		.of_match_table = sun6i_prcm_dt_ids,
  	},
  	.probe = sun6i_prcm_probe,
  };
391cd33a0   Paul Gortmaker   mfd: sun6i-prcm: ...
175
  builtin_platform_driver(sun6i_prcm_driver);