1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/module.h>
4 #include <linux/platform_device.h>
5 #include <linux/regmap.h>
6 #include <linux/regulator/driver.h>
8 #include <linux/mfd/88pm886.h>
10 static const struct regmap_config pm886_regulator_regmap_config
= {
13 .max_register
= PM886_REG_BUCK5_VOUT
,
16 static const struct regulator_ops pm886_ldo_ops
= {
17 .list_voltage
= regulator_list_voltage_table
,
18 .map_voltage
= regulator_map_voltage_iterate
,
19 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
20 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
21 .enable
= regulator_enable_regmap
,
22 .disable
= regulator_disable_regmap
,
23 .is_enabled
= regulator_is_enabled_regmap
,
26 static const struct regulator_ops pm886_buck_ops
= {
27 .list_voltage
= regulator_list_voltage_linear_range
,
28 .map_voltage
= regulator_map_voltage_linear_range
,
29 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
30 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
31 .enable
= regulator_enable_regmap
,
32 .disable
= regulator_disable_regmap
,
33 .is_enabled
= regulator_is_enabled_regmap
,
36 static const unsigned int pm886_ldo_volt_table1
[] = {
37 1700000, 1800000, 1900000, 2500000, 2800000, 2900000, 3100000, 3300000,
40 static const unsigned int pm886_ldo_volt_table2
[] = {
41 1200000, 1250000, 1700000, 1800000, 1850000, 1900000, 2500000, 2600000,
42 2700000, 2750000, 2800000, 2850000, 2900000, 3000000, 3100000, 3300000,
45 static const unsigned int pm886_ldo_volt_table3
[] = {
46 1700000, 1800000, 1900000, 2000000, 2100000, 2500000, 2700000, 2800000,
49 static const struct linear_range pm886_buck_volt_ranges1
[] = {
50 REGULATOR_LINEAR_RANGE(600000, 0, 79, 12500),
51 REGULATOR_LINEAR_RANGE(1600000, 80, 84, 50000),
54 static const struct linear_range pm886_buck_volt_ranges2
[] = {
55 REGULATOR_LINEAR_RANGE(600000, 0, 79, 12500),
56 REGULATOR_LINEAR_RANGE(1600000, 80, 114, 50000),
59 static struct regulator_desc pm886_regulators
[] = {
62 .regulators_node
= "regulators",
64 .ops
= &pm886_ldo_ops
,
65 .type
= REGULATOR_VOLTAGE
,
66 .enable_reg
= PM886_REG_LDO_EN1
,
67 .enable_mask
= BIT(0),
68 .volt_table
= pm886_ldo_volt_table1
,
69 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table1
),
70 .vsel_reg
= PM886_REG_LDO1_VOUT
,
71 .vsel_mask
= PM886_LDO_VSEL_MASK
,
75 .regulators_node
= "regulators",
77 .ops
= &pm886_ldo_ops
,
78 .type
= REGULATOR_VOLTAGE
,
79 .enable_reg
= PM886_REG_LDO_EN1
,
80 .enable_mask
= BIT(1),
81 .volt_table
= pm886_ldo_volt_table1
,
82 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table1
),
83 .vsel_reg
= PM886_REG_LDO2_VOUT
,
84 .vsel_mask
= PM886_LDO_VSEL_MASK
,
88 .regulators_node
= "regulators",
90 .ops
= &pm886_ldo_ops
,
91 .type
= REGULATOR_VOLTAGE
,
92 .enable_reg
= PM886_REG_LDO_EN1
,
93 .enable_mask
= BIT(2),
94 .volt_table
= pm886_ldo_volt_table1
,
95 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table1
),
96 .vsel_reg
= PM886_REG_LDO3_VOUT
,
97 .vsel_mask
= PM886_LDO_VSEL_MASK
,
101 .regulators_node
= "regulators",
103 .ops
= &pm886_ldo_ops
,
104 .type
= REGULATOR_VOLTAGE
,
105 .enable_reg
= PM886_REG_LDO_EN1
,
106 .enable_mask
= BIT(3),
107 .volt_table
= pm886_ldo_volt_table2
,
108 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
109 .vsel_reg
= PM886_REG_LDO4_VOUT
,
110 .vsel_mask
= PM886_LDO_VSEL_MASK
,
114 .regulators_node
= "regulators",
116 .ops
= &pm886_ldo_ops
,
117 .type
= REGULATOR_VOLTAGE
,
118 .enable_reg
= PM886_REG_LDO_EN1
,
119 .enable_mask
= BIT(4),
120 .volt_table
= pm886_ldo_volt_table2
,
121 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
122 .vsel_reg
= PM886_REG_LDO5_VOUT
,
123 .vsel_mask
= PM886_LDO_VSEL_MASK
,
127 .regulators_node
= "regulators",
129 .ops
= &pm886_ldo_ops
,
130 .type
= REGULATOR_VOLTAGE
,
131 .enable_reg
= PM886_REG_LDO_EN1
,
132 .enable_mask
= BIT(5),
133 .volt_table
= pm886_ldo_volt_table2
,
134 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
135 .vsel_reg
= PM886_REG_LDO6_VOUT
,
136 .vsel_mask
= PM886_LDO_VSEL_MASK
,
140 .regulators_node
= "regulators",
142 .ops
= &pm886_ldo_ops
,
143 .type
= REGULATOR_VOLTAGE
,
144 .enable_reg
= PM886_REG_LDO_EN1
,
145 .enable_mask
= BIT(6),
146 .volt_table
= pm886_ldo_volt_table2
,
147 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
148 .vsel_reg
= PM886_REG_LDO7_VOUT
,
149 .vsel_mask
= PM886_LDO_VSEL_MASK
,
153 .regulators_node
= "regulators",
155 .ops
= &pm886_ldo_ops
,
156 .type
= REGULATOR_VOLTAGE
,
157 .enable_reg
= PM886_REG_LDO_EN1
,
158 .enable_mask
= BIT(7),
159 .volt_table
= pm886_ldo_volt_table2
,
160 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
161 .vsel_reg
= PM886_REG_LDO8_VOUT
,
162 .vsel_mask
= PM886_LDO_VSEL_MASK
,
166 .regulators_node
= "regulators",
168 .ops
= &pm886_ldo_ops
,
169 .type
= REGULATOR_VOLTAGE
,
170 .enable_reg
= PM886_REG_LDO_EN2
,
171 .enable_mask
= BIT(0),
172 .volt_table
= pm886_ldo_volt_table2
,
173 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
174 .vsel_reg
= PM886_REG_LDO9_VOUT
,
175 .vsel_mask
= PM886_LDO_VSEL_MASK
,
179 .regulators_node
= "regulators",
181 .ops
= &pm886_ldo_ops
,
182 .type
= REGULATOR_VOLTAGE
,
183 .enable_reg
= PM886_REG_LDO_EN2
,
184 .enable_mask
= BIT(1),
185 .volt_table
= pm886_ldo_volt_table2
,
186 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
187 .vsel_reg
= PM886_REG_LDO10_VOUT
,
188 .vsel_mask
= PM886_LDO_VSEL_MASK
,
192 .regulators_node
= "regulators",
194 .ops
= &pm886_ldo_ops
,
195 .type
= REGULATOR_VOLTAGE
,
196 .enable_reg
= PM886_REG_LDO_EN2
,
197 .enable_mask
= BIT(2),
198 .volt_table
= pm886_ldo_volt_table2
,
199 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
200 .vsel_reg
= PM886_REG_LDO11_VOUT
,
201 .vsel_mask
= PM886_LDO_VSEL_MASK
,
205 .regulators_node
= "regulators",
207 .ops
= &pm886_ldo_ops
,
208 .type
= REGULATOR_VOLTAGE
,
209 .enable_reg
= PM886_REG_LDO_EN2
,
210 .enable_mask
= BIT(3),
211 .volt_table
= pm886_ldo_volt_table2
,
212 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
213 .vsel_reg
= PM886_REG_LDO12_VOUT
,
214 .vsel_mask
= PM886_LDO_VSEL_MASK
,
218 .regulators_node
= "regulators",
220 .ops
= &pm886_ldo_ops
,
221 .type
= REGULATOR_VOLTAGE
,
222 .enable_reg
= PM886_REG_LDO_EN2
,
223 .enable_mask
= BIT(4),
224 .volt_table
= pm886_ldo_volt_table2
,
225 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
226 .vsel_reg
= PM886_REG_LDO13_VOUT
,
227 .vsel_mask
= PM886_LDO_VSEL_MASK
,
231 .regulators_node
= "regulators",
233 .ops
= &pm886_ldo_ops
,
234 .type
= REGULATOR_VOLTAGE
,
235 .enable_reg
= PM886_REG_LDO_EN2
,
236 .enable_mask
= BIT(5),
237 .volt_table
= pm886_ldo_volt_table2
,
238 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
239 .vsel_reg
= PM886_REG_LDO14_VOUT
,
240 .vsel_mask
= PM886_LDO_VSEL_MASK
,
244 .regulators_node
= "regulators",
246 .ops
= &pm886_ldo_ops
,
247 .type
= REGULATOR_VOLTAGE
,
248 .enable_reg
= PM886_REG_LDO_EN2
,
249 .enable_mask
= BIT(6),
250 .volt_table
= pm886_ldo_volt_table2
,
251 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table2
),
252 .vsel_reg
= PM886_REG_LDO15_VOUT
,
253 .vsel_mask
= PM886_LDO_VSEL_MASK
,
257 .regulators_node
= "regulators",
259 .ops
= &pm886_ldo_ops
,
260 .type
= REGULATOR_VOLTAGE
,
261 .enable_reg
= PM886_REG_LDO_EN2
,
262 .enable_mask
= BIT(7),
263 .volt_table
= pm886_ldo_volt_table3
,
264 .n_voltages
= ARRAY_SIZE(pm886_ldo_volt_table3
),
265 .vsel_reg
= PM886_REG_LDO16_VOUT
,
266 .vsel_mask
= PM886_LDO_VSEL_MASK
,
270 .regulators_node
= "regulators",
272 .ops
= &pm886_buck_ops
,
273 .type
= REGULATOR_VOLTAGE
,
275 .linear_ranges
= pm886_buck_volt_ranges1
,
276 .n_linear_ranges
= ARRAY_SIZE(pm886_buck_volt_ranges1
),
277 .vsel_reg
= PM886_REG_BUCK1_VOUT
,
278 .vsel_mask
= PM886_BUCK_VSEL_MASK
,
279 .enable_reg
= PM886_REG_BUCK_EN
,
280 .enable_mask
= BIT(0),
284 .regulators_node
= "regulators",
286 .ops
= &pm886_buck_ops
,
287 .type
= REGULATOR_VOLTAGE
,
289 .linear_ranges
= pm886_buck_volt_ranges2
,
290 .n_linear_ranges
= ARRAY_SIZE(pm886_buck_volt_ranges2
),
291 .vsel_reg
= PM886_REG_BUCK2_VOUT
,
292 .vsel_mask
= PM886_BUCK_VSEL_MASK
,
293 .enable_reg
= PM886_REG_BUCK_EN
,
294 .enable_mask
= BIT(1),
298 .regulators_node
= "regulators",
300 .ops
= &pm886_buck_ops
,
301 .type
= REGULATOR_VOLTAGE
,
303 .linear_ranges
= pm886_buck_volt_ranges2
,
304 .n_linear_ranges
= ARRAY_SIZE(pm886_buck_volt_ranges2
),
305 .vsel_reg
= PM886_REG_BUCK3_VOUT
,
306 .vsel_mask
= PM886_BUCK_VSEL_MASK
,
307 .enable_reg
= PM886_REG_BUCK_EN
,
308 .enable_mask
= BIT(2),
312 .regulators_node
= "regulators",
314 .ops
= &pm886_buck_ops
,
315 .type
= REGULATOR_VOLTAGE
,
317 .linear_ranges
= pm886_buck_volt_ranges2
,
318 .n_linear_ranges
= ARRAY_SIZE(pm886_buck_volt_ranges2
),
319 .vsel_reg
= PM886_REG_BUCK4_VOUT
,
320 .vsel_mask
= PM886_BUCK_VSEL_MASK
,
321 .enable_reg
= PM886_REG_BUCK_EN
,
322 .enable_mask
= BIT(3),
326 .regulators_node
= "regulators",
328 .ops
= &pm886_buck_ops
,
329 .type
= REGULATOR_VOLTAGE
,
331 .linear_ranges
= pm886_buck_volt_ranges2
,
332 .n_linear_ranges
= ARRAY_SIZE(pm886_buck_volt_ranges2
),
333 .vsel_reg
= PM886_REG_BUCK5_VOUT
,
334 .vsel_mask
= PM886_BUCK_VSEL_MASK
,
335 .enable_reg
= PM886_REG_BUCK_EN
,
336 .enable_mask
= BIT(4),
340 static int pm886_regulator_probe(struct platform_device
*pdev
)
342 struct pm886_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
343 struct regulator_config rcfg
= { };
344 struct device
*dev
= &pdev
->dev
;
345 struct regulator_desc
*rdesc
;
346 struct regulator_dev
*rdev
;
347 struct i2c_client
*page
;
348 struct regmap
*regmap
;
350 page
= devm_i2c_new_dummy_device(dev
, chip
->client
->adapter
,
351 chip
->client
->addr
+ PM886_PAGE_OFFSET_REGULATORS
);
353 return dev_err_probe(dev
, PTR_ERR(page
),
354 "Failed to initialize regulators client\n");
356 regmap
= devm_regmap_init_i2c(page
, &pm886_regulator_regmap_config
);
358 return dev_err_probe(dev
, PTR_ERR(regmap
),
359 "Failed to initialize regulators regmap\n");
360 rcfg
.regmap
= regmap
;
362 rcfg
.dev
= dev
->parent
;
364 for (int i
= 0; i
< ARRAY_SIZE(pm886_regulators
); i
++) {
365 rdesc
= &pm886_regulators
[i
];
366 rdev
= devm_regulator_register(dev
, rdesc
, &rcfg
);
368 return dev_err_probe(dev
, PTR_ERR(rdev
),
369 "Failed to register %s\n", rdesc
->name
);
375 static const struct platform_device_id pm886_regulator_id_table
[] = {
376 { "88pm886-regulator", },
379 MODULE_DEVICE_TABLE(platform
, pm886_regulator_id_table
);
381 static struct platform_driver pm886_regulator_driver
= {
383 .name
= "88pm886-regulator",
385 .probe
= pm886_regulator_probe
,
386 .id_table
= pm886_regulator_id_table
,
388 module_platform_driver(pm886_regulator_driver
);
390 MODULE_DESCRIPTION("Marvell 88PM886 PMIC regulator driver");
391 MODULE_AUTHOR("Karel Balej <balejk@matfyz.cz>");
392 MODULE_LICENSE("GPL");