]>
Commit | Line | Data |
---|---|---|
ba08799e MV |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | // Copyright (C) 2018 ROHM Semiconductors | |
dd2be639 | 3 | // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver |
ba08799e | 4 | |
c9dc4cfa | 5 | #include <linux/delay.h> |
ba08799e MV |
6 | #include <linux/err.h> |
7 | #include <linux/interrupt.h> | |
c9dc4cfa | 8 | #include <linux/kernel.h> |
410e8b4f | 9 | #include <linux/mfd/rohm-bd718x7.h> |
c9dc4cfa | 10 | #include <linux/module.h> |
9cce7244 | 11 | #include <linux/of.h> |
ba08799e MV |
12 | #include <linux/platform_device.h> |
13 | #include <linux/regulator/driver.h> | |
14 | #include <linux/regulator/machine.h> | |
ba08799e | 15 | #include <linux/regulator/of_regulator.h> |
c9dc4cfa | 16 | #include <linux/slab.h> |
ba08799e | 17 | |
1d848d68 MV |
18 | /* |
19 | * BD718(37/47/50) have two "enable control modes". ON/OFF can either be | |
20 | * controlled by software - or by PMIC internal HW state machine. Whether | |
21 | * regulator should be under SW or HW control can be defined from device-tree. | |
22 | * Let's provide separate ops for regulators to use depending on the "enable | |
23 | * control mode". | |
24 | */ | |
25 | #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol | |
26 | ||
27 | #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \ | |
28 | _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay) \ | |
29 | static const struct regulator_ops name = { \ | |
30 | .enable = regulator_enable_regmap, \ | |
31 | .disable = regulator_disable_regmap, \ | |
32 | .is_enabled = regulator_is_enabled_regmap, \ | |
33 | .list_voltage = (_list_voltage), \ | |
34 | .map_voltage = (_map_voltage), \ | |
35 | .set_voltage_sel = (_set_voltage_sel), \ | |
36 | .get_voltage_sel = (_get_voltage_sel), \ | |
37 | .set_voltage_time_sel = (_set_voltage_time_sel), \ | |
38 | .set_ramp_delay = (_set_ramp_delay), \ | |
39 | }; \ | |
40 | \ | |
41 | static const struct regulator_ops BD718XX_HWOPNAME(name) = { \ | |
42 | .is_enabled = always_enabled_by_hwstate, \ | |
43 | .list_voltage = (_list_voltage), \ | |
44 | .map_voltage = (_map_voltage), \ | |
45 | .set_voltage_sel = (_set_voltage_sel), \ | |
46 | .get_voltage_sel = (_get_voltage_sel), \ | |
47 | .set_voltage_time_sel = (_set_voltage_time_sel), \ | |
48 | .set_ramp_delay = (_set_ramp_delay), \ | |
49 | } \ | |
50 | ||
ba08799e MV |
51 | /* |
52 | * BUCK1/2/3/4 | |
53 | * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting | |
54 | * 00: 10.00mV/usec 10mV 1uS | |
55 | * 01: 5.00mV/usec 10mV 2uS | |
56 | * 10: 2.50mV/usec 10mV 4uS | |
57 | * 11: 1.25mV/usec 10mV 8uS | |
58 | */ | |
dd2be639 | 59 | static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev, |
ba08799e MV |
60 | int ramp_delay) |
61 | { | |
0a245f0e AL |
62 | int id = rdev_get_id(rdev); |
63 | unsigned int ramp_value; | |
ba08799e | 64 | |
bcb047eb | 65 | dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1, |
ba08799e MV |
66 | ramp_delay); |
67 | switch (ramp_delay) { | |
68 | case 1 ... 1250: | |
69 | ramp_value = BUCK_RAMPRATE_1P25MV; | |
70 | break; | |
71 | case 1251 ... 2500: | |
72 | ramp_value = BUCK_RAMPRATE_2P50MV; | |
73 | break; | |
74 | case 2501 ... 5000: | |
75 | ramp_value = BUCK_RAMPRATE_5P00MV; | |
76 | break; | |
77 | case 5001 ... 10000: | |
78 | ramp_value = BUCK_RAMPRATE_10P00MV; | |
79 | break; | |
80 | default: | |
81 | ramp_value = BUCK_RAMPRATE_10P00MV; | |
bcb047eb | 82 | dev_err(&rdev->dev, |
ba08799e MV |
83 | "%s: ramp_delay: %d not supported, setting 10000mV//us\n", |
84 | rdev->desc->name, ramp_delay); | |
85 | } | |
86 | ||
bcb047eb | 87 | return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id, |
ba08799e MV |
88 | BUCK_RAMPRATE_MASK, ramp_value << 6); |
89 | } | |
90 | ||
1d848d68 MV |
91 | /* These functions are used when regulators are under HW state machine control. |
92 | * We assume PMIC is in RUN state because SW running and able to query the | |
93 | * status. Most of the regulators have fixed ON or OFF state at RUN/IDLE so for | |
94 | * them we just return a constant. BD71837 BUCK3 and BUCK4 are exceptions as | |
95 | * they support configuring the ON/OFF state for RUN. | |
96 | * | |
97 | * Note for next hacker - these PMICs have a register where the HW state can be | |
98 | * read. If assuming RUN appears to be false in your use-case - you can | |
99 | * implement state reading (although that is not going to be atomic) before | |
100 | * returning the enable state. | |
101 | */ | |
102 | static int always_enabled_by_hwstate(struct regulator_dev *rdev) | |
103 | { | |
104 | return 1; | |
105 | } | |
106 | ||
107 | static int never_enabled_by_hwstate(struct regulator_dev *rdev) | |
108 | { | |
109 | return 0; | |
110 | } | |
111 | ||
112 | static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev) | |
113 | { | |
114 | int ret; | |
115 | unsigned int val; | |
116 | ||
117 | ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); | |
118 | if (ret) | |
119 | return ret; | |
120 | ||
121 | return !!(BD718XX_BUCK_RUN_ON & val); | |
122 | } | |
f0ca7b24 MV |
123 | /* |
124 | * On BD71837 (not on BD71847, BD71850, ...) | |
125 | * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed. | |
ba08799e MV |
126 | * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage |
127 | * is changed. Hence we return -EBUSY for these if voltage is changed | |
128 | * when BUCK/LDO is enabled. | |
f0ca7b24 | 129 | * |
9bcbabaf MV |
130 | * On BD71847, BD71850, ... The LDO voltage can be changed when LDO is |
131 | * enabled. But if voltage is increased the LDO power-good monitoring | |
132 | * must be disabled for the duration of changing + 1mS to ensure voltage | |
133 | * has reached the higher level before HW does next under voltage detection | |
134 | * cycle. | |
ba08799e | 135 | */ |
9bcbabaf | 136 | static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev, |
ba08799e MV |
137 | unsigned int sel) |
138 | { | |
1d848d68 | 139 | if (rdev->desc->ops->is_enabled(rdev)) |
ffdc4984 | 140 | return -EBUSY; |
ba08799e | 141 | |
ffdc4984 | 142 | return regulator_set_voltage_sel_regmap(rdev, sel); |
ba08799e MV |
143 | } |
144 | ||
9bcbabaf MV |
145 | static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel, |
146 | unsigned int *mask) | |
147 | { | |
148 | int ret; | |
149 | ||
150 | if (*mask) { | |
151 | /* | |
152 | * Let's allow scheduling as we use I2C anyways. We just need to | |
153 | * guarantee minimum of 1ms sleep - it shouldn't matter if we | |
154 | * exceed it due to the scheduling. | |
155 | */ | |
156 | msleep(1); | |
157 | /* | |
158 | * Note for next hacker. The PWRGOOD should not be masked on | |
159 | * BD71847 so we will just unconditionally enable detection | |
160 | * when voltage is set. | |
161 | * If someone want's to disable PWRGOOD he must implement | |
162 | * caching and restoring the old value here. I am not | |
163 | * aware of such use-cases so for the sake of the simplicity | |
164 | * we just always enable PWRGOOD here. | |
165 | */ | |
166 | ret = regmap_update_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, | |
167 | *mask, 0); | |
168 | if (ret) | |
169 | dev_err(&rdev->dev, | |
170 | "Failed to re-enable voltage monitoring (%d)\n", | |
171 | ret); | |
172 | } | |
173 | } | |
174 | ||
175 | static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel, | |
176 | unsigned int *mask) | |
177 | { | |
178 | int ret; | |
179 | ||
180 | *mask = 0; | |
1d848d68 | 181 | if (rdev->desc->ops->is_enabled(rdev)) { |
9bcbabaf MV |
182 | int now, new; |
183 | ||
184 | now = rdev->desc->ops->get_voltage_sel(rdev); | |
185 | if (now < 0) | |
186 | return now; | |
187 | ||
188 | now = rdev->desc->ops->list_voltage(rdev, now); | |
189 | if (now < 0) | |
190 | return now; | |
191 | ||
192 | new = rdev->desc->ops->list_voltage(rdev, sel); | |
193 | if (new < 0) | |
194 | return new; | |
195 | ||
196 | /* | |
197 | * If we increase LDO voltage when LDO is enabled we need to | |
198 | * disable the power-good detection until voltage has reached | |
199 | * the new level. According to HW colleagues the maximum time | |
200 | * it takes is 1000us. I assume that on systems with light load | |
201 | * this might be less - and we could probably use DT to give | |
202 | * system specific delay value if performance matters. | |
203 | * | |
204 | * Well, knowing we use I2C here and can add scheduling delays | |
205 | * I don't think it is worth the hassle and I just add fixed | |
206 | * 1ms sleep here (and allow scheduling). If this turns out to | |
207 | * be a problem we can change it to delay and make the delay | |
208 | * time configurable. | |
209 | */ | |
210 | if (new > now) { | |
211 | int ldo_offset = rdev->desc->id - BD718XX_LDO1; | |
212 | ||
213 | *mask = BD718XX_LDO1_VRMON80 << ldo_offset; | |
214 | ret = regmap_update_bits(rdev->regmap, | |
215 | BD718XX_REG_MVRFLTMASK2, | |
216 | *mask, *mask); | |
217 | if (ret) { | |
218 | dev_err(&rdev->dev, | |
219 | "Failed to stop voltage monitoring\n"); | |
220 | return ret; | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | return 0; | |
226 | } | |
227 | ||
228 | static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev, | |
229 | unsigned int sel) | |
230 | { | |
231 | int ret; | |
232 | int mask; | |
233 | ||
234 | ret = voltage_change_prepare(rdev, sel, &mask); | |
235 | if (ret) | |
236 | return ret; | |
237 | ||
238 | ret = regulator_set_voltage_sel_regmap(rdev, sel); | |
239 | voltage_change_done(rdev, sel, &mask); | |
240 | ||
241 | return ret; | |
242 | } | |
243 | ||
a4bfc2c2 MV |
244 | static int bd718xx_set_voltage_sel_pickable_restricted( |
245 | struct regulator_dev *rdev, unsigned int sel) | |
9bcbabaf MV |
246 | { |
247 | int ret; | |
248 | int mask; | |
249 | ||
250 | ret = voltage_change_prepare(rdev, sel, &mask); | |
251 | if (ret) | |
252 | return ret; | |
253 | ||
254 | ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel); | |
255 | voltage_change_done(rdev, sel, &mask); | |
256 | ||
257 | return ret; | |
258 | } | |
259 | ||
260 | static int bd71837_set_voltage_sel_pickable_restricted( | |
261 | struct regulator_dev *rdev, unsigned int sel) | |
a4bfc2c2 | 262 | { |
1d848d68 | 263 | if (rdev->desc->ops->is_enabled(rdev)) |
a4bfc2c2 MV |
264 | return -EBUSY; |
265 | ||
266 | return regulator_set_voltage_sel_pickable_regmap(rdev, sel); | |
267 | } | |
268 | ||
1d848d68 MV |
269 | /* |
270 | * OPS common for BD71847 and BD71850 | |
271 | */ | |
272 | BD718XX_OPS(bd718xx_pickable_range_ldo_ops, | |
273 | regulator_list_voltage_pickable_linear_range, NULL, | |
274 | bd718xx_set_voltage_sel_pickable_restricted, | |
275 | regulator_get_voltage_sel_pickable_regmap, NULL, NULL); | |
276 | ||
277 | /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */ | |
278 | static const struct regulator_ops bd718xx_ldo5_ops_hwstate = { | |
279 | .is_enabled = never_enabled_by_hwstate, | |
a4bfc2c2 MV |
280 | .list_voltage = regulator_list_voltage_pickable_linear_range, |
281 | .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, | |
282 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, | |
9bcbabaf MV |
283 | }; |
284 | ||
1d848d68 MV |
285 | BD718XX_OPS(bd718xx_pickable_range_buck_ops, |
286 | regulator_list_voltage_pickable_linear_range, NULL, | |
287 | regulator_set_voltage_sel_pickable_regmap, | |
288 | regulator_get_voltage_sel_pickable_regmap, | |
289 | regulator_set_voltage_time_sel, NULL); | |
f0ca7b24 | 290 | |
1d848d68 MV |
291 | BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range, |
292 | NULL, bd718xx_set_voltage_sel_restricted, | |
293 | regulator_get_voltage_sel_regmap, NULL, NULL); | |
9bcbabaf | 294 | |
1d848d68 MV |
295 | BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table, |
296 | NULL, bd718xx_set_voltage_sel_restricted, | |
297 | regulator_get_voltage_sel_regmap, NULL, NULL); | |
ba08799e | 298 | |
1d848d68 MV |
299 | BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range, |
300 | NULL, regulator_set_voltage_sel_regmap, | |
301 | regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, | |
302 | NULL); | |
9bcbabaf | 303 | |
1d848d68 MV |
304 | BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table, |
305 | regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap, | |
306 | regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, | |
307 | NULL); | |
ba08799e | 308 | |
1d848d68 MV |
309 | /* |
310 | * OPS for BD71837 | |
311 | */ | |
312 | BD718XX_OPS(bd71837_pickable_range_ldo_ops, | |
313 | regulator_list_voltage_pickable_linear_range, NULL, | |
314 | bd71837_set_voltage_sel_pickable_restricted, | |
315 | regulator_get_voltage_sel_pickable_regmap, NULL, NULL); | |
316 | ||
317 | BD718XX_OPS(bd71837_pickable_range_buck_ops, | |
318 | regulator_list_voltage_pickable_linear_range, NULL, | |
319 | bd71837_set_voltage_sel_pickable_restricted, | |
320 | regulator_get_voltage_sel_pickable_regmap, | |
321 | regulator_set_voltage_time_sel, NULL); | |
322 | ||
323 | BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range, | |
324 | NULL, bd71837_set_voltage_sel_restricted, | |
325 | regulator_get_voltage_sel_regmap, NULL, NULL); | |
326 | ||
327 | BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table, | |
328 | NULL, bd71837_set_voltage_sel_restricted, | |
329 | regulator_get_voltage_sel_regmap, NULL, NULL); | |
330 | ||
331 | BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range, | |
332 | NULL, bd71837_set_voltage_sel_restricted, | |
333 | regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, | |
334 | NULL); | |
335 | ||
336 | BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table, | |
337 | regulator_map_voltage_ascend, bd718xx_set_voltage_sel_restricted, | |
338 | regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, | |
339 | NULL); | |
340 | /* | |
341 | * BD71837 bucks 3 and 4 support defining their enable/disable state also | |
342 | * when buck enable state is under HW state machine control. In that case the | |
343 | * bit [2] in CTRL register is used to indicate if regulator should be ON. | |
344 | */ | |
345 | static const struct regulator_ops bd71837_buck34_ops_hwctrl = { | |
346 | .is_enabled = bd71837_get_buck34_enable_hwctrl, | |
ba08799e MV |
347 | .list_voltage = regulator_list_voltage_linear_range, |
348 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
349 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
350 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
dd2be639 | 351 | .set_ramp_delay = bd718xx_buck1234_set_ramp_delay, |
ba08799e MV |
352 | }; |
353 | ||
1d848d68 MV |
354 | /* |
355 | * OPS for all of the ICs - BD718(37/47/50) | |
356 | */ | |
357 | BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range, | |
358 | NULL, regulator_set_voltage_sel_regmap, | |
359 | regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, | |
360 | bd718xx_buck1234_set_ramp_delay); | |
361 | ||
ba08799e | 362 | /* |
494edd26 MV |
363 | * BD71837 BUCK1/2/3/4 |
364 | * BD71847 BUCK1/2 | |
ba08799e MV |
365 | * 0.70 to 1.30V (10mV step) |
366 | */ | |
60ab7f41 | 367 | static const struct linear_range bd718xx_dvs_buck_volts[] = { |
ba08799e MV |
368 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000), |
369 | REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0), | |
370 | }; | |
371 | ||
372 | /* | |
494edd26 | 373 | * BD71837 BUCK5 |
a4bfc2c2 MV |
374 | * 0.7V to 1.35V (range 0) |
375 | * and | |
376 | * 0.675 to 1.325 (range 1) | |
377 | */ | |
60ab7f41 | 378 | static const struct linear_range bd71837_buck5_volts[] = { |
a4bfc2c2 MV |
379 | /* Ranges when VOLT_SEL bit is 0 */ |
380 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), | |
381 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), | |
382 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), | |
383 | /* Ranges when VOLT_SEL bit is 1 */ | |
384 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), | |
385 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), | |
386 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), | |
387 | }; | |
388 | ||
389 | /* | |
390 | * Range selector for first 3 linear ranges is 0x0 | |
391 | * and 0x1 for last 3 ranges. | |
392 | */ | |
393 | static const unsigned int bd71837_buck5_volt_range_sel[] = { | |
394 | 0x0, 0x0, 0x0, 0x80, 0x80, 0x80 | |
395 | }; | |
396 | ||
397 | /* | |
494edd26 | 398 | * BD71847 BUCK3 |
ba08799e | 399 | */ |
60ab7f41 | 400 | static const struct linear_range bd71847_buck3_volts[] = { |
a4bfc2c2 | 401 | /* Ranges when VOLT_SEL bits are 00 */ |
ba08799e MV |
402 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), |
403 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), | |
404 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), | |
a4bfc2c2 MV |
405 | /* Ranges when VOLT_SEL bits are 01 */ |
406 | REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000), | |
407 | /* Ranges when VOLT_SEL bits are 11 */ | |
408 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), | |
409 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), | |
410 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), | |
411 | }; | |
412 | ||
413 | static const unsigned int bd71847_buck3_volt_range_sel[] = { | |
414 | 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80 | |
ba08799e MV |
415 | }; |
416 | ||
60ab7f41 | 417 | static const struct linear_range bd71847_buck4_volts[] = { |
494edd26 | 418 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
a4bfc2c2 | 419 | REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000), |
494edd26 MV |
420 | }; |
421 | ||
a4bfc2c2 MV |
422 | static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 }; |
423 | ||
ba08799e MV |
424 | /* |
425 | * BUCK6 | |
426 | * 3.0V to 3.3V (step 100mV) | |
427 | */ | |
60ab7f41 | 428 | static const struct linear_range bd71837_buck6_volts[] = { |
ba08799e MV |
429 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
430 | }; | |
431 | ||
432 | /* | |
494edd26 MV |
433 | * BD71837 BUCK7 |
434 | * BD71847 BUCK5 | |
ba08799e MV |
435 | * 000 = 1.605V |
436 | * 001 = 1.695V | |
437 | * 010 = 1.755V | |
438 | * 011 = 1.8V (Initial) | |
439 | * 100 = 1.845V | |
440 | * 101 = 1.905V | |
441 | * 110 = 1.95V | |
442 | * 111 = 1.995V | |
443 | */ | |
494edd26 | 444 | static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = { |
ba08799e MV |
445 | 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000 |
446 | }; | |
447 | ||
448 | /* | |
449 | * BUCK8 | |
450 | * 0.8V to 1.40V (step 10mV) | |
451 | */ | |
60ab7f41 | 452 | static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = { |
ba08799e | 453 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000), |
ba08799e MV |
454 | }; |
455 | ||
456 | /* | |
457 | * LDO1 | |
458 | * 3.0 to 3.3V (100mV step) | |
459 | */ | |
60ab7f41 | 460 | static const struct linear_range bd718xx_ldo1_volts[] = { |
ba08799e | 461 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
a4bfc2c2 | 462 | REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000), |
ba08799e MV |
463 | }; |
464 | ||
a4bfc2c2 MV |
465 | static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 }; |
466 | ||
ba08799e MV |
467 | /* |
468 | * LDO2 | |
469 | * 0.8 or 0.9V | |
470 | */ | |
adb78a8e | 471 | static const unsigned int ldo_2_volts[] = { |
ba08799e MV |
472 | 900000, 800000 |
473 | }; | |
474 | ||
475 | /* | |
476 | * LDO3 | |
477 | * 1.8 to 3.3V (100mV step) | |
478 | */ | |
60ab7f41 | 479 | static const struct linear_range bd718xx_ldo3_volts[] = { |
ba08799e MV |
480 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
481 | }; | |
482 | ||
483 | /* | |
484 | * LDO4 | |
485 | * 0.9 to 1.8V (100mV step) | |
486 | */ | |
60ab7f41 | 487 | static const struct linear_range bd718xx_ldo4_volts[] = { |
ba08799e | 488 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
ba08799e MV |
489 | }; |
490 | ||
491 | /* | |
494edd26 | 492 | * LDO5 for BD71837 |
ba08799e MV |
493 | * 1.8 to 3.3V (100mV step) |
494 | */ | |
60ab7f41 | 495 | static const struct linear_range bd71837_ldo5_volts[] = { |
ba08799e MV |
496 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
497 | }; | |
498 | ||
a4bfc2c2 MV |
499 | /* |
500 | * LDO5 for BD71837 | |
501 | * 1.8 to 3.3V (100mV step) | |
502 | */ | |
60ab7f41 | 503 | static const struct linear_range bd71847_ldo5_volts[] = { |
a4bfc2c2 MV |
504 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
505 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000), | |
506 | }; | |
507 | ||
508 | static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 }; | |
509 | ||
ba08799e MV |
510 | /* |
511 | * LDO6 | |
512 | * 0.9 to 1.8V (100mV step) | |
513 | */ | |
60ab7f41 | 514 | static const struct linear_range bd718xx_ldo6_volts[] = { |
ba08799e | 515 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
ba08799e MV |
516 | }; |
517 | ||
518 | /* | |
519 | * LDO7 | |
520 | * 1.8 to 3.3V (100mV step) | |
521 | */ | |
60ab7f41 | 522 | static const struct linear_range bd71837_ldo7_volts[] = { |
ba08799e MV |
523 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
524 | }; | |
525 | ||
494edd26 MV |
526 | struct reg_init { |
527 | unsigned int reg; | |
528 | unsigned int mask; | |
529 | unsigned int val; | |
530 | }; | |
531 | struct bd718xx_regulator_data { | |
532 | struct regulator_desc desc; | |
21b72156 | 533 | const struct rohm_dvs_config dvs; |
494edd26 MV |
534 | const struct reg_init init; |
535 | const struct reg_init *additional_inits; | |
536 | int additional_init_amnt; | |
537 | }; | |
538 | ||
539 | /* | |
540 | * There is a HW quirk in BD71837. The shutdown sequence timings for | |
541 | * bucks/LDOs which are controlled via register interface are changed. | |
542 | * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the | |
543 | * beginning of shut-down sequence. As bucks 6 and 7 are parent | |
544 | * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage | |
545 | * monitoring to errorneously detect under voltage and force PMIC to | |
546 | * emergency state instead of poweroff. In order to avoid this we | |
547 | * disable voltage monitoring for LDO5 and LDO6 | |
548 | */ | |
549 | static const struct reg_init bd71837_ldo5_inits[] = { | |
550 | { | |
551 | .reg = BD718XX_REG_MVRFLTMASK2, | |
552 | .mask = BD718XX_LDO5_VRMON80, | |
553 | .val = BD718XX_LDO5_VRMON80, | |
554 | }, | |
555 | }; | |
556 | ||
557 | static const struct reg_init bd71837_ldo6_inits[] = { | |
558 | { | |
559 | .reg = BD718XX_REG_MVRFLTMASK2, | |
560 | .mask = BD718XX_LDO6_VRMON80, | |
561 | .val = BD718XX_LDO6_VRMON80, | |
562 | }, | |
563 | }; | |
564 | ||
21b72156 | 565 | static int buck_set_hw_dvs_levels(struct device_node *np, |
049369d4 MV |
566 | const struct regulator_desc *desc, |
567 | struct regulator_config *cfg) | |
568 | { | |
21b72156 | 569 | struct bd718xx_regulator_data *data; |
049369d4 | 570 | |
21b72156 | 571 | data = container_of(desc, struct bd718xx_regulator_data, desc); |
049369d4 | 572 | |
21b72156 | 573 | return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); |
049369d4 MV |
574 | } |
575 | ||
02f8eaab | 576 | static const struct regulator_ops *bd71847_swcontrol_ops[] = { |
1d848d68 MV |
577 | &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops, |
578 | &bd718xx_pickable_range_buck_ops, &bd718xx_pickable_range_buck_ops, | |
579 | &bd718xx_buck_regulator_nolinear_ops, &bd718xx_buck_regulator_ops, | |
580 | &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_nolinear_ops, | |
581 | &bd718xx_ldo_regulator_ops, &bd718xx_ldo_regulator_ops, | |
582 | &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_ops, | |
583 | }; | |
584 | ||
02f8eaab | 585 | static const struct regulator_ops *bd71847_hwcontrol_ops[] = { |
1d848d68 MV |
586 | &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops), |
587 | &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops), | |
588 | &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops), | |
589 | &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops), | |
590 | &BD718XX_HWOPNAME(bd718xx_buck_regulator_nolinear_ops), | |
591 | &BD718XX_HWOPNAME(bd718xx_buck_regulator_ops), | |
592 | &BD718XX_HWOPNAME(bd718xx_pickable_range_ldo_ops), | |
593 | &BD718XX_HWOPNAME(bd718xx_ldo_regulator_nolinear_ops), | |
594 | &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops), | |
595 | &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops), | |
596 | &bd718xx_ldo5_ops_hwstate, | |
597 | &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops), | |
598 | }; | |
599 | ||
600 | static struct bd718xx_regulator_data bd71847_regulators[] = { | |
494edd26 MV |
601 | { |
602 | .desc = { | |
603 | .name = "buck1", | |
604 | .of_match = of_match_ptr("BUCK1"), | |
605 | .regulators_node = of_match_ptr("regulators"), | |
606 | .id = BD718XX_BUCK1, | |
494edd26 MV |
607 | .type = REGULATOR_VOLTAGE, |
608 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
609 | .linear_ranges = bd718xx_dvs_buck_volts, | |
610 | .n_linear_ranges = | |
611 | ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
612 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
613 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
614 | .enable_reg = BD718XX_REG_BUCK1_CTRL, | |
615 | .enable_mask = BD718XX_BUCK_EN, | |
616 | .owner = THIS_MODULE, | |
21b72156 MV |
617 | .of_parse_cb = buck_set_hw_dvs_levels, |
618 | }, | |
619 | .dvs = { | |
620 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | | |
621 | ROHM_DVS_LEVEL_SUSPEND, | |
622 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
623 | .run_mask = DVS_BUCK_RUN_MASK, | |
624 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, | |
625 | .idle_mask = DVS_BUCK_RUN_MASK, | |
626 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, | |
627 | .suspend_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
628 | }, |
629 | .init = { | |
630 | .reg = BD718XX_REG_BUCK1_CTRL, | |
631 | .mask = BD718XX_BUCK_SEL, | |
632 | .val = BD718XX_BUCK_SEL, | |
633 | }, | |
634 | }, | |
ba08799e | 635 | { |
494edd26 MV |
636 | .desc = { |
637 | .name = "buck2", | |
638 | .of_match = of_match_ptr("BUCK2"), | |
639 | .regulators_node = of_match_ptr("regulators"), | |
640 | .id = BD718XX_BUCK2, | |
494edd26 MV |
641 | .type = REGULATOR_VOLTAGE, |
642 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
643 | .linear_ranges = bd718xx_dvs_buck_volts, | |
644 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
645 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
646 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
647 | .enable_reg = BD718XX_REG_BUCK2_CTRL, | |
648 | .enable_mask = BD718XX_BUCK_EN, | |
649 | .owner = THIS_MODULE, | |
21b72156 MV |
650 | .of_parse_cb = buck_set_hw_dvs_levels, |
651 | }, | |
652 | .dvs = { | |
653 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, | |
654 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
655 | .run_mask = DVS_BUCK_RUN_MASK, | |
656 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, | |
657 | .idle_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
658 | }, |
659 | .init = { | |
660 | .reg = BD718XX_REG_BUCK2_CTRL, | |
661 | .mask = BD718XX_BUCK_SEL, | |
662 | .val = BD718XX_BUCK_SEL, | |
663 | }, | |
ba08799e MV |
664 | }, |
665 | { | |
494edd26 MV |
666 | .desc = { |
667 | .name = "buck3", | |
668 | .of_match = of_match_ptr("BUCK3"), | |
669 | .regulators_node = of_match_ptr("regulators"), | |
670 | .id = BD718XX_BUCK3, | |
494edd26 | 671 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
672 | .n_voltages = BD71847_BUCK3_VOLTAGE_NUM, |
673 | .linear_ranges = bd71847_buck3_volts, | |
494edd26 | 674 | .n_linear_ranges = |
a4bfc2c2 | 675 | ARRAY_SIZE(bd71847_buck3_volts), |
494edd26 MV |
676 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
677 | .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK, | |
a4bfc2c2 MV |
678 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
679 | .vsel_range_mask = BD71847_BUCK3_RANGE_MASK, | |
680 | .linear_range_selectors = bd71847_buck3_volt_range_sel, | |
494edd26 MV |
681 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
682 | .enable_mask = BD718XX_BUCK_EN, | |
683 | .owner = THIS_MODULE, | |
684 | }, | |
685 | .init = { | |
686 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, | |
687 | .mask = BD718XX_BUCK_SEL, | |
688 | .val = BD718XX_BUCK_SEL, | |
689 | }, | |
ba08799e MV |
690 | }, |
691 | { | |
494edd26 MV |
692 | .desc = { |
693 | .name = "buck4", | |
694 | .of_match = of_match_ptr("BUCK4"), | |
695 | .regulators_node = of_match_ptr("regulators"), | |
696 | .id = BD718XX_BUCK4, | |
494edd26 MV |
697 | .type = REGULATOR_VOLTAGE, |
698 | .n_voltages = BD71847_BUCK4_VOLTAGE_NUM, | |
a4bfc2c2 | 699 | .linear_ranges = bd71847_buck4_volts, |
494edd26 | 700 | .n_linear_ranges = |
a4bfc2c2 | 701 | ARRAY_SIZE(bd71847_buck4_volts), |
494edd26 MV |
702 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
703 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, | |
704 | .vsel_mask = BD71847_BUCK4_MASK, | |
a4bfc2c2 MV |
705 | .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
706 | .vsel_range_mask = BD71847_BUCK4_RANGE_MASK, | |
707 | .linear_range_selectors = bd71847_buck4_volt_range_sel, | |
494edd26 MV |
708 | .enable_mask = BD718XX_BUCK_EN, |
709 | .owner = THIS_MODULE, | |
710 | }, | |
711 | .init = { | |
712 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
713 | .mask = BD718XX_BUCK_SEL, | |
714 | .val = BD718XX_BUCK_SEL, | |
715 | }, | |
ba08799e MV |
716 | }, |
717 | { | |
494edd26 MV |
718 | .desc = { |
719 | .name = "buck5", | |
720 | .of_match = of_match_ptr("BUCK5"), | |
dd2be639 | 721 | .regulators_node = of_match_ptr("regulators"), |
494edd26 | 722 | .id = BD718XX_BUCK5, |
494edd26 MV |
723 | .type = REGULATOR_VOLTAGE, |
724 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], | |
725 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), | |
726 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, | |
727 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, | |
728 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
729 | .enable_mask = BD718XX_BUCK_EN, | |
730 | .owner = THIS_MODULE, | |
731 | }, | |
732 | .init = { | |
733 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
734 | .mask = BD718XX_BUCK_SEL, | |
735 | .val = BD718XX_BUCK_SEL, | |
736 | }, | |
ba08799e MV |
737 | }, |
738 | { | |
494edd26 MV |
739 | .desc = { |
740 | .name = "buck6", | |
741 | .of_match = of_match_ptr("BUCK6"), | |
742 | .regulators_node = of_match_ptr("regulators"), | |
743 | .id = BD718XX_BUCK6, | |
494edd26 | 744 | .type = REGULATOR_VOLTAGE, |
dd2be639 | 745 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
494edd26 MV |
746 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
747 | .n_linear_ranges = | |
748 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), | |
749 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, | |
750 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, | |
751 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
752 | .enable_mask = BD718XX_BUCK_EN, | |
753 | .owner = THIS_MODULE, | |
754 | }, | |
755 | .init = { | |
756 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
757 | .mask = BD718XX_BUCK_SEL, | |
758 | .val = BD718XX_BUCK_SEL, | |
759 | }, | |
ba08799e MV |
760 | }, |
761 | { | |
494edd26 MV |
762 | .desc = { |
763 | .name = "ldo1", | |
764 | .of_match = of_match_ptr("LDO1"), | |
765 | .regulators_node = of_match_ptr("regulators"), | |
766 | .id = BD718XX_LDO1, | |
494edd26 MV |
767 | .type = REGULATOR_VOLTAGE, |
768 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, | |
769 | .linear_ranges = bd718xx_ldo1_volts, | |
770 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), | |
771 | .vsel_reg = BD718XX_REG_LDO1_VOLT, | |
772 | .vsel_mask = BD718XX_LDO1_MASK, | |
a4bfc2c2 MV |
773 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
774 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, | |
775 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, | |
494edd26 MV |
776 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
777 | .enable_mask = BD718XX_LDO_EN, | |
778 | .owner = THIS_MODULE, | |
779 | }, | |
780 | .init = { | |
781 | .reg = BD718XX_REG_LDO1_VOLT, | |
782 | .mask = BD718XX_LDO_SEL, | |
783 | .val = BD718XX_LDO_SEL, | |
784 | }, | |
ba08799e MV |
785 | }, |
786 | { | |
494edd26 MV |
787 | .desc = { |
788 | .name = "ldo2", | |
789 | .of_match = of_match_ptr("LDO2"), | |
790 | .regulators_node = of_match_ptr("regulators"), | |
791 | .id = BD718XX_LDO2, | |
494edd26 MV |
792 | .type = REGULATOR_VOLTAGE, |
793 | .volt_table = &ldo_2_volts[0], | |
794 | .vsel_reg = BD718XX_REG_LDO2_VOLT, | |
795 | .vsel_mask = BD718XX_LDO2_MASK, | |
796 | .n_voltages = ARRAY_SIZE(ldo_2_volts), | |
797 | .enable_reg = BD718XX_REG_LDO2_VOLT, | |
798 | .enable_mask = BD718XX_LDO_EN, | |
799 | .owner = THIS_MODULE, | |
800 | }, | |
801 | .init = { | |
802 | .reg = BD718XX_REG_LDO2_VOLT, | |
803 | .mask = BD718XX_LDO_SEL, | |
804 | .val = BD718XX_LDO_SEL, | |
805 | }, | |
ba08799e MV |
806 | }, |
807 | { | |
494edd26 MV |
808 | .desc = { |
809 | .name = "ldo3", | |
810 | .of_match = of_match_ptr("LDO3"), | |
811 | .regulators_node = of_match_ptr("regulators"), | |
812 | .id = BD718XX_LDO3, | |
494edd26 MV |
813 | .type = REGULATOR_VOLTAGE, |
814 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, | |
815 | .linear_ranges = bd718xx_ldo3_volts, | |
816 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), | |
817 | .vsel_reg = BD718XX_REG_LDO3_VOLT, | |
818 | .vsel_mask = BD718XX_LDO3_MASK, | |
819 | .enable_reg = BD718XX_REG_LDO3_VOLT, | |
820 | .enable_mask = BD718XX_LDO_EN, | |
821 | .owner = THIS_MODULE, | |
822 | }, | |
823 | .init = { | |
824 | .reg = BD718XX_REG_LDO3_VOLT, | |
825 | .mask = BD718XX_LDO_SEL, | |
826 | .val = BD718XX_LDO_SEL, | |
827 | }, | |
ba08799e MV |
828 | }, |
829 | { | |
494edd26 MV |
830 | .desc = { |
831 | .name = "ldo4", | |
832 | .of_match = of_match_ptr("LDO4"), | |
833 | .regulators_node = of_match_ptr("regulators"), | |
834 | .id = BD718XX_LDO4, | |
494edd26 MV |
835 | .type = REGULATOR_VOLTAGE, |
836 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, | |
837 | .linear_ranges = bd718xx_ldo4_volts, | |
838 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), | |
839 | .vsel_reg = BD718XX_REG_LDO4_VOLT, | |
840 | .vsel_mask = BD718XX_LDO4_MASK, | |
841 | .enable_reg = BD718XX_REG_LDO4_VOLT, | |
842 | .enable_mask = BD718XX_LDO_EN, | |
843 | .owner = THIS_MODULE, | |
844 | }, | |
845 | .init = { | |
846 | .reg = BD718XX_REG_LDO4_VOLT, | |
847 | .mask = BD718XX_LDO_SEL, | |
848 | .val = BD718XX_LDO_SEL, | |
849 | }, | |
ba08799e MV |
850 | }, |
851 | { | |
494edd26 MV |
852 | .desc = { |
853 | .name = "ldo5", | |
854 | .of_match = of_match_ptr("LDO5"), | |
855 | .regulators_node = of_match_ptr("regulators"), | |
856 | .id = BD718XX_LDO5, | |
494edd26 | 857 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
858 | .n_voltages = BD71847_LDO5_VOLTAGE_NUM, |
859 | .linear_ranges = bd71847_ldo5_volts, | |
860 | .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts), | |
494edd26 MV |
861 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
862 | .vsel_mask = BD71847_LDO5_MASK, | |
a4bfc2c2 MV |
863 | .vsel_range_reg = BD718XX_REG_LDO5_VOLT, |
864 | .vsel_range_mask = BD71847_LDO5_RANGE_MASK, | |
865 | .linear_range_selectors = bd71847_ldo5_volt_range_sel, | |
494edd26 MV |
866 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
867 | .enable_mask = BD718XX_LDO_EN, | |
868 | .owner = THIS_MODULE, | |
869 | }, | |
870 | .init = { | |
871 | .reg = BD718XX_REG_LDO5_VOLT, | |
872 | .mask = BD718XX_LDO_SEL, | |
873 | .val = BD718XX_LDO_SEL, | |
874 | }, | |
ba08799e MV |
875 | }, |
876 | { | |
494edd26 MV |
877 | .desc = { |
878 | .name = "ldo6", | |
879 | .of_match = of_match_ptr("LDO6"), | |
880 | .regulators_node = of_match_ptr("regulators"), | |
881 | .id = BD718XX_LDO6, | |
494edd26 MV |
882 | .type = REGULATOR_VOLTAGE, |
883 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, | |
884 | .linear_ranges = bd718xx_ldo6_volts, | |
885 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), | |
886 | /* LDO6 is supplied by buck5 */ | |
887 | .supply_name = "buck5", | |
888 | .vsel_reg = BD718XX_REG_LDO6_VOLT, | |
889 | .vsel_mask = BD718XX_LDO6_MASK, | |
890 | .enable_reg = BD718XX_REG_LDO6_VOLT, | |
891 | .enable_mask = BD718XX_LDO_EN, | |
892 | .owner = THIS_MODULE, | |
893 | }, | |
894 | .init = { | |
895 | .reg = BD718XX_REG_LDO6_VOLT, | |
896 | .mask = BD718XX_LDO_SEL, | |
897 | .val = BD718XX_LDO_SEL, | |
898 | }, | |
899 | }, | |
900 | }; | |
901 | ||
02f8eaab | 902 | static const struct regulator_ops *bd71837_swcontrol_ops[] = { |
1d848d68 MV |
903 | &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops, |
904 | &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops, | |
905 | &bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops, | |
906 | &bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops, | |
907 | &bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops, | |
908 | &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops, | |
909 | &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops, | |
910 | &bd71837_ldo_regulator_ops, | |
911 | }; | |
912 | ||
02f8eaab | 913 | static const struct regulator_ops *bd71837_hwcontrol_ops[] = { |
1d848d68 MV |
914 | &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops), |
915 | &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops), | |
916 | &bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl, | |
917 | &BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops), | |
918 | &BD718XX_HWOPNAME(bd71837_buck_regulator_ops), | |
919 | &BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops), | |
920 | &BD718XX_HWOPNAME(bd71837_buck_regulator_ops), | |
921 | &BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops), | |
922 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops), | |
923 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops), | |
924 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops), | |
925 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops), | |
926 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops), | |
927 | &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops), | |
928 | }; | |
929 | ||
930 | static struct bd718xx_regulator_data bd71837_regulators[] = { | |
494edd26 MV |
931 | { |
932 | .desc = { | |
933 | .name = "buck1", | |
934 | .of_match = of_match_ptr("BUCK1"), | |
935 | .regulators_node = of_match_ptr("regulators"), | |
936 | .id = BD718XX_BUCK1, | |
494edd26 MV |
937 | .type = REGULATOR_VOLTAGE, |
938 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
939 | .linear_ranges = bd718xx_dvs_buck_volts, | |
940 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
941 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
942 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
943 | .enable_reg = BD718XX_REG_BUCK1_CTRL, | |
944 | .enable_mask = BD718XX_BUCK_EN, | |
945 | .owner = THIS_MODULE, | |
21b72156 MV |
946 | .of_parse_cb = buck_set_hw_dvs_levels, |
947 | }, | |
948 | .dvs = { | |
949 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | | |
950 | ROHM_DVS_LEVEL_SUSPEND, | |
951 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
952 | .run_mask = DVS_BUCK_RUN_MASK, | |
953 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, | |
954 | .idle_mask = DVS_BUCK_RUN_MASK, | |
955 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, | |
956 | .suspend_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
957 | }, |
958 | .init = { | |
959 | .reg = BD718XX_REG_BUCK1_CTRL, | |
960 | .mask = BD718XX_BUCK_SEL, | |
961 | .val = BD718XX_BUCK_SEL, | |
962 | }, | |
963 | }, | |
964 | { | |
965 | .desc = { | |
966 | .name = "buck2", | |
967 | .of_match = of_match_ptr("BUCK2"), | |
968 | .regulators_node = of_match_ptr("regulators"), | |
969 | .id = BD718XX_BUCK2, | |
494edd26 MV |
970 | .type = REGULATOR_VOLTAGE, |
971 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
972 | .linear_ranges = bd718xx_dvs_buck_volts, | |
973 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
974 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
975 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
976 | .enable_reg = BD718XX_REG_BUCK2_CTRL, | |
977 | .enable_mask = BD718XX_BUCK_EN, | |
978 | .owner = THIS_MODULE, | |
21b72156 MV |
979 | .of_parse_cb = buck_set_hw_dvs_levels, |
980 | }, | |
981 | .dvs = { | |
982 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, | |
983 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
984 | .run_mask = DVS_BUCK_RUN_MASK, | |
985 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, | |
986 | .idle_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
987 | }, |
988 | .init = { | |
989 | .reg = BD718XX_REG_BUCK2_CTRL, | |
990 | .mask = BD718XX_BUCK_SEL, | |
991 | .val = BD718XX_BUCK_SEL, | |
992 | }, | |
993 | }, | |
994 | { | |
995 | .desc = { | |
996 | .name = "buck3", | |
997 | .of_match = of_match_ptr("BUCK3"), | |
998 | .regulators_node = of_match_ptr("regulators"), | |
999 | .id = BD718XX_BUCK3, | |
494edd26 MV |
1000 | .type = REGULATOR_VOLTAGE, |
1001 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
1002 | .linear_ranges = bd718xx_dvs_buck_volts, | |
1003 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
1004 | .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN, | |
1005 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
1006 | .enable_reg = BD71837_REG_BUCK3_CTRL, | |
1007 | .enable_mask = BD718XX_BUCK_EN, | |
1008 | .owner = THIS_MODULE, | |
21b72156 MV |
1009 | .of_parse_cb = buck_set_hw_dvs_levels, |
1010 | }, | |
1011 | .dvs = { | |
1012 | .level_map = ROHM_DVS_LEVEL_RUN, | |
1013 | .run_reg = BD71837_REG_BUCK3_VOLT_RUN, | |
1014 | .run_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
1015 | }, |
1016 | .init = { | |
1017 | .reg = BD71837_REG_BUCK3_CTRL, | |
1018 | .mask = BD718XX_BUCK_SEL, | |
1019 | .val = BD718XX_BUCK_SEL, | |
1020 | }, | |
1021 | }, | |
1022 | { | |
1023 | .desc = { | |
1024 | .name = "buck4", | |
1025 | .of_match = of_match_ptr("BUCK4"), | |
1026 | .regulators_node = of_match_ptr("regulators"), | |
1027 | .id = BD718XX_BUCK4, | |
494edd26 MV |
1028 | .type = REGULATOR_VOLTAGE, |
1029 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
1030 | .linear_ranges = bd718xx_dvs_buck_volts, | |
1031 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
1032 | .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN, | |
1033 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
1034 | .enable_reg = BD71837_REG_BUCK4_CTRL, | |
1035 | .enable_mask = BD718XX_BUCK_EN, | |
1036 | .owner = THIS_MODULE, | |
21b72156 MV |
1037 | .of_parse_cb = buck_set_hw_dvs_levels, |
1038 | }, | |
1039 | .dvs = { | |
1040 | .level_map = ROHM_DVS_LEVEL_RUN, | |
1041 | .run_reg = BD71837_REG_BUCK4_VOLT_RUN, | |
1042 | .run_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
1043 | }, |
1044 | .init = { | |
1045 | .reg = BD71837_REG_BUCK4_CTRL, | |
1046 | .mask = BD718XX_BUCK_SEL, | |
1047 | .val = BD718XX_BUCK_SEL, | |
1048 | }, | |
ba08799e MV |
1049 | }, |
1050 | { | |
494edd26 MV |
1051 | .desc = { |
1052 | .name = "buck5", | |
1053 | .of_match = of_match_ptr("BUCK5"), | |
1054 | .regulators_node = of_match_ptr("regulators"), | |
1055 | .id = BD718XX_BUCK5, | |
494edd26 | 1056 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
1057 | .n_voltages = BD71837_BUCK5_VOLTAGE_NUM, |
1058 | .linear_ranges = bd71837_buck5_volts, | |
494edd26 | 1059 | .n_linear_ranges = |
a4bfc2c2 | 1060 | ARRAY_SIZE(bd71837_buck5_volts), |
494edd26 | 1061 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
a4bfc2c2 MV |
1062 | .vsel_mask = BD71837_BUCK5_MASK, |
1063 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, | |
1064 | .vsel_range_mask = BD71837_BUCK5_RANGE_MASK, | |
1065 | .linear_range_selectors = bd71837_buck5_volt_range_sel, | |
494edd26 MV |
1066 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
1067 | .enable_mask = BD718XX_BUCK_EN, | |
1068 | .owner = THIS_MODULE, | |
1069 | }, | |
1070 | .init = { | |
1071 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, | |
1072 | .mask = BD718XX_BUCK_SEL, | |
1073 | .val = BD718XX_BUCK_SEL, | |
1074 | }, | |
ba08799e MV |
1075 | }, |
1076 | { | |
494edd26 MV |
1077 | .desc = { |
1078 | .name = "buck6", | |
1079 | .of_match = of_match_ptr("BUCK6"), | |
1080 | .regulators_node = of_match_ptr("regulators"), | |
1081 | .id = BD718XX_BUCK6, | |
494edd26 MV |
1082 | .type = REGULATOR_VOLTAGE, |
1083 | .n_voltages = BD71837_BUCK6_VOLTAGE_NUM, | |
a4bfc2c2 | 1084 | .linear_ranges = bd71837_buck6_volts, |
494edd26 | 1085 | .n_linear_ranges = |
a4bfc2c2 | 1086 | ARRAY_SIZE(bd71837_buck6_volts), |
494edd26 MV |
1087 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
1088 | .vsel_mask = BD71837_BUCK6_MASK, | |
1089 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
1090 | .enable_mask = BD718XX_BUCK_EN, | |
1091 | .owner = THIS_MODULE, | |
1092 | }, | |
1093 | .init = { | |
1094 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
1095 | .mask = BD718XX_BUCK_SEL, | |
1096 | .val = BD718XX_BUCK_SEL, | |
1097 | }, | |
ba08799e MV |
1098 | }, |
1099 | { | |
494edd26 MV |
1100 | .desc = { |
1101 | .name = "buck7", | |
1102 | .of_match = of_match_ptr("BUCK7"), | |
1103 | .regulators_node = of_match_ptr("regulators"), | |
1104 | .id = BD718XX_BUCK7, | |
494edd26 MV |
1105 | .type = REGULATOR_VOLTAGE, |
1106 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], | |
1107 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), | |
1108 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, | |
1109 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, | |
1110 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
1111 | .enable_mask = BD718XX_BUCK_EN, | |
1112 | .owner = THIS_MODULE, | |
1113 | }, | |
1114 | .init = { | |
1115 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
1116 | .mask = BD718XX_BUCK_SEL, | |
1117 | .val = BD718XX_BUCK_SEL, | |
1118 | }, | |
ba08799e MV |
1119 | }, |
1120 | { | |
494edd26 MV |
1121 | .desc = { |
1122 | .name = "buck8", | |
1123 | .of_match = of_match_ptr("BUCK8"), | |
1124 | .regulators_node = of_match_ptr("regulators"), | |
1125 | .id = BD718XX_BUCK8, | |
494edd26 | 1126 | .type = REGULATOR_VOLTAGE, |
dd2be639 | 1127 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
494edd26 MV |
1128 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
1129 | .n_linear_ranges = | |
1130 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), | |
1131 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, | |
1132 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, | |
1133 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
1134 | .enable_mask = BD718XX_BUCK_EN, | |
1135 | .owner = THIS_MODULE, | |
1136 | }, | |
1137 | .init = { | |
1138 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
1139 | .mask = BD718XX_BUCK_SEL, | |
1140 | .val = BD718XX_BUCK_SEL, | |
1141 | }, | |
1142 | }, | |
1143 | { | |
1144 | .desc = { | |
1145 | .name = "ldo1", | |
1146 | .of_match = of_match_ptr("LDO1"), | |
1147 | .regulators_node = of_match_ptr("regulators"), | |
1148 | .id = BD718XX_LDO1, | |
494edd26 MV |
1149 | .type = REGULATOR_VOLTAGE, |
1150 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, | |
1151 | .linear_ranges = bd718xx_ldo1_volts, | |
1152 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), | |
1153 | .vsel_reg = BD718XX_REG_LDO1_VOLT, | |
1154 | .vsel_mask = BD718XX_LDO1_MASK, | |
a4bfc2c2 MV |
1155 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
1156 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, | |
1157 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, | |
494edd26 MV |
1158 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
1159 | .enable_mask = BD718XX_LDO_EN, | |
1160 | .owner = THIS_MODULE, | |
1161 | }, | |
1162 | .init = { | |
1163 | .reg = BD718XX_REG_LDO1_VOLT, | |
1164 | .mask = BD718XX_LDO_SEL, | |
1165 | .val = BD718XX_LDO_SEL, | |
1166 | }, | |
1167 | }, | |
1168 | { | |
1169 | .desc = { | |
1170 | .name = "ldo2", | |
1171 | .of_match = of_match_ptr("LDO2"), | |
1172 | .regulators_node = of_match_ptr("regulators"), | |
1173 | .id = BD718XX_LDO2, | |
494edd26 MV |
1174 | .type = REGULATOR_VOLTAGE, |
1175 | .volt_table = &ldo_2_volts[0], | |
1176 | .vsel_reg = BD718XX_REG_LDO2_VOLT, | |
1177 | .vsel_mask = BD718XX_LDO2_MASK, | |
1178 | .n_voltages = ARRAY_SIZE(ldo_2_volts), | |
1179 | .enable_reg = BD718XX_REG_LDO2_VOLT, | |
1180 | .enable_mask = BD718XX_LDO_EN, | |
1181 | .owner = THIS_MODULE, | |
1182 | }, | |
1183 | .init = { | |
1184 | .reg = BD718XX_REG_LDO2_VOLT, | |
1185 | .mask = BD718XX_LDO_SEL, | |
1186 | .val = BD718XX_LDO_SEL, | |
1187 | }, | |
1188 | }, | |
1189 | { | |
1190 | .desc = { | |
1191 | .name = "ldo3", | |
1192 | .of_match = of_match_ptr("LDO3"), | |
1193 | .regulators_node = of_match_ptr("regulators"), | |
1194 | .id = BD718XX_LDO3, | |
494edd26 MV |
1195 | .type = REGULATOR_VOLTAGE, |
1196 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, | |
1197 | .linear_ranges = bd718xx_ldo3_volts, | |
1198 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), | |
1199 | .vsel_reg = BD718XX_REG_LDO3_VOLT, | |
1200 | .vsel_mask = BD718XX_LDO3_MASK, | |
1201 | .enable_reg = BD718XX_REG_LDO3_VOLT, | |
1202 | .enable_mask = BD718XX_LDO_EN, | |
1203 | .owner = THIS_MODULE, | |
1204 | }, | |
1205 | .init = { | |
1206 | .reg = BD718XX_REG_LDO3_VOLT, | |
1207 | .mask = BD718XX_LDO_SEL, | |
1208 | .val = BD718XX_LDO_SEL, | |
1209 | }, | |
1210 | }, | |
1211 | { | |
1212 | .desc = { | |
1213 | .name = "ldo4", | |
1214 | .of_match = of_match_ptr("LDO4"), | |
1215 | .regulators_node = of_match_ptr("regulators"), | |
1216 | .id = BD718XX_LDO4, | |
494edd26 MV |
1217 | .type = REGULATOR_VOLTAGE, |
1218 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, | |
1219 | .linear_ranges = bd718xx_ldo4_volts, | |
1220 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), | |
1221 | .vsel_reg = BD718XX_REG_LDO4_VOLT, | |
1222 | .vsel_mask = BD718XX_LDO4_MASK, | |
1223 | .enable_reg = BD718XX_REG_LDO4_VOLT, | |
1224 | .enable_mask = BD718XX_LDO_EN, | |
1225 | .owner = THIS_MODULE, | |
1226 | }, | |
1227 | .init = { | |
1228 | .reg = BD718XX_REG_LDO4_VOLT, | |
1229 | .mask = BD718XX_LDO_SEL, | |
1230 | .val = BD718XX_LDO_SEL, | |
1231 | }, | |
1232 | }, | |
1233 | { | |
1234 | .desc = { | |
1235 | .name = "ldo5", | |
1236 | .of_match = of_match_ptr("LDO5"), | |
1237 | .regulators_node = of_match_ptr("regulators"), | |
1238 | .id = BD718XX_LDO5, | |
494edd26 | 1239 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
1240 | .n_voltages = BD71837_LDO5_VOLTAGE_NUM, |
1241 | .linear_ranges = bd71837_ldo5_volts, | |
1242 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts), | |
494edd26 MV |
1243 | /* LDO5 is supplied by buck6 */ |
1244 | .supply_name = "buck6", | |
1245 | .vsel_reg = BD718XX_REG_LDO5_VOLT, | |
1246 | .vsel_mask = BD71837_LDO5_MASK, | |
1247 | .enable_reg = BD718XX_REG_LDO5_VOLT, | |
1248 | .enable_mask = BD718XX_LDO_EN, | |
1249 | .owner = THIS_MODULE, | |
1250 | }, | |
1251 | .init = { | |
1252 | .reg = BD718XX_REG_LDO5_VOLT, | |
1253 | .mask = BD718XX_LDO_SEL, | |
1254 | .val = BD718XX_LDO_SEL, | |
1255 | }, | |
1256 | .additional_inits = bd71837_ldo5_inits, | |
1257 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits), | |
1258 | }, | |
1259 | { | |
1260 | .desc = { | |
1261 | .name = "ldo6", | |
1262 | .of_match = of_match_ptr("LDO6"), | |
1263 | .regulators_node = of_match_ptr("regulators"), | |
1264 | .id = BD718XX_LDO6, | |
494edd26 MV |
1265 | .type = REGULATOR_VOLTAGE, |
1266 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, | |
1267 | .linear_ranges = bd718xx_ldo6_volts, | |
1268 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), | |
1269 | /* LDO6 is supplied by buck7 */ | |
1270 | .supply_name = "buck7", | |
1271 | .vsel_reg = BD718XX_REG_LDO6_VOLT, | |
1272 | .vsel_mask = BD718XX_LDO6_MASK, | |
1273 | .enable_reg = BD718XX_REG_LDO6_VOLT, | |
1274 | .enable_mask = BD718XX_LDO_EN, | |
1275 | .owner = THIS_MODULE, | |
1276 | }, | |
1277 | .init = { | |
1278 | .reg = BD718XX_REG_LDO6_VOLT, | |
1279 | .mask = BD718XX_LDO_SEL, | |
1280 | .val = BD718XX_LDO_SEL, | |
1281 | }, | |
1282 | .additional_inits = bd71837_ldo6_inits, | |
1283 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits), | |
1284 | }, | |
1285 | { | |
1286 | .desc = { | |
1287 | .name = "ldo7", | |
1288 | .of_match = of_match_ptr("LDO7"), | |
1289 | .regulators_node = of_match_ptr("regulators"), | |
1290 | .id = BD718XX_LDO7, | |
494edd26 MV |
1291 | .type = REGULATOR_VOLTAGE, |
1292 | .n_voltages = BD71837_LDO7_VOLTAGE_NUM, | |
1293 | .linear_ranges = bd71837_ldo7_volts, | |
1294 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts), | |
1295 | .vsel_reg = BD71837_REG_LDO7_VOLT, | |
1296 | .vsel_mask = BD71837_LDO7_MASK, | |
1297 | .enable_reg = BD71837_REG_LDO7_VOLT, | |
1298 | .enable_mask = BD718XX_LDO_EN, | |
1299 | .owner = THIS_MODULE, | |
1300 | }, | |
1301 | .init = { | |
1302 | .reg = BD71837_REG_LDO7_VOLT, | |
1303 | .mask = BD718XX_LDO_SEL, | |
1304 | .val = BD718XX_LDO_SEL, | |
1305 | }, | |
ba08799e MV |
1306 | }, |
1307 | }; | |
1308 | ||
1d848d68 MV |
1309 | static void mark_hw_controlled(struct device *dev, struct device_node *np, |
1310 | struct bd718xx_regulator_data *reg_data, | |
1311 | unsigned int num_reg_data, int *info) | |
1312 | { | |
1313 | int i; | |
1314 | ||
1315 | for (i = 1; i <= num_reg_data; i++) { | |
1316 | if (!of_node_name_eq(np, reg_data[i-1].desc.of_match)) | |
1317 | continue; | |
1318 | ||
1319 | *info |= 1 << (i - 1); | |
1320 | dev_dbg(dev, "regulator %d runlevel controlled\n", i); | |
1321 | return; | |
1322 | } | |
1323 | dev_warn(dev, "Bad regulator node\n"); | |
1324 | } | |
1325 | ||
1326 | static int get_hw_controlled_regulators(struct device *dev, | |
1327 | struct bd718xx_regulator_data *reg_data, | |
1328 | unsigned int num_reg_data, int *info) | |
1329 | { | |
1330 | struct device_node *np; | |
1331 | struct device_node *nproot = dev->of_node; | |
1332 | const char *prop = "rohm,no-regulator-enable-control"; | |
1333 | ||
1334 | *info = 0; | |
1335 | ||
1336 | nproot = of_get_child_by_name(nproot, "regulators"); | |
1337 | if (!nproot) { | |
1338 | dev_err(dev, "failed to find regulators node\n"); | |
1339 | return -ENODEV; | |
1340 | } | |
1341 | for_each_child_of_node(nproot, np) | |
1342 | if (of_property_read_bool(np, prop)) | |
1343 | mark_hw_controlled(dev, np, reg_data, num_reg_data, | |
1344 | info); | |
1345 | ||
1346 | of_node_put(nproot); | |
1347 | return 0; | |
1348 | } | |
1349 | ||
dd2be639 | 1350 | static int bd718xx_probe(struct platform_device *pdev) |
ba08799e | 1351 | { |
bcb047eb | 1352 | struct bd718xx *mfd; |
ba08799e | 1353 | struct regulator_config config = { 0 }; |
1d848d68 | 1354 | int i, j, err, omit_enable; |
049369d4 | 1355 | bool use_snvs; |
1d848d68 | 1356 | struct bd718xx_regulator_data *reg_data; |
b389ceae | 1357 | unsigned int num_reg_data; |
1b1c26b2 | 1358 | enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; |
1d848d68 | 1359 | const struct regulator_ops **swops, **hwops; |
ba08799e | 1360 | |
bcb047eb AL |
1361 | mfd = dev_get_drvdata(pdev->dev.parent); |
1362 | if (!mfd) { | |
ba08799e MV |
1363 | dev_err(&pdev->dev, "No MFD driver data\n"); |
1364 | err = -EINVAL; | |
1365 | goto err; | |
1366 | } | |
bcb047eb | 1367 | |
af32f3a4 | 1368 | switch (chip) { |
b389ceae AL |
1369 | case ROHM_CHIP_TYPE_BD71837: |
1370 | reg_data = bd71837_regulators; | |
1371 | num_reg_data = ARRAY_SIZE(bd71837_regulators); | |
1d848d68 MV |
1372 | swops = &bd71837_swcontrol_ops[0]; |
1373 | hwops = &bd71837_hwcontrol_ops[0]; | |
b389ceae AL |
1374 | break; |
1375 | case ROHM_CHIP_TYPE_BD71847: | |
1376 | reg_data = bd71847_regulators; | |
1377 | num_reg_data = ARRAY_SIZE(bd71847_regulators); | |
1d848d68 MV |
1378 | swops = &bd71847_swcontrol_ops[0]; |
1379 | hwops = &bd71847_hwcontrol_ops[0]; | |
b389ceae AL |
1380 | break; |
1381 | default: | |
494edd26 MV |
1382 | dev_err(&pdev->dev, "Unsupported chip type\n"); |
1383 | err = -EINVAL; | |
1384 | goto err; | |
1385 | } | |
1386 | ||
ba08799e | 1387 | /* Register LOCK release */ |
2a6a7aac | 1388 | err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK, |
ba08799e MV |
1389 | (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); |
1390 | if (err) { | |
bcb047eb | 1391 | dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); |
ba08799e MV |
1392 | goto err; |
1393 | } else { | |
bcb047eb | 1394 | dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", |
494edd26 | 1395 | BD718XX_REG_REGLOCK); |
823f18f8 MV |
1396 | } |
1397 | ||
049369d4 MV |
1398 | use_snvs = of_property_read_bool(pdev->dev.parent->of_node, |
1399 | "rohm,reset-snvs-powered"); | |
1400 | ||
1401 | /* | |
e770b18b MV |
1402 | * Change the next stage from poweroff to be READY instead of SNVS |
1403 | * for all reset types because OTP loading at READY will clear SEL | |
1404 | * bit allowing HW defaults for power rails to be used | |
1405 | */ | |
049369d4 | 1406 | if (!use_snvs) { |
2a6a7aac MV |
1407 | err = regmap_update_bits(mfd->chip.regmap, |
1408 | BD718XX_REG_TRANS_COND1, | |
049369d4 MV |
1409 | BD718XX_ON_REQ_POWEROFF_MASK | |
1410 | BD718XX_SWRESET_POWEROFF_MASK | | |
1411 | BD718XX_WDOG_POWEROFF_MASK | | |
1412 | BD718XX_KEY_L_POWEROFF_MASK, | |
1413 | BD718XX_POWOFF_TO_RDY); | |
1414 | if (err) { | |
1415 | dev_err(&pdev->dev, "Failed to change reset target\n"); | |
1416 | goto err; | |
1417 | } else { | |
1418 | dev_dbg(&pdev->dev, | |
1419 | "Changed all resets from SVNS to READY\n"); | |
1420 | } | |
e770b18b MV |
1421 | } |
1422 | ||
df9db254 MV |
1423 | config.dev = pdev->dev.parent; |
1424 | config.regmap = mfd->chip.regmap; | |
1d848d68 MV |
1425 | /* |
1426 | * There are cases when we want to leave the enable-control for | |
1427 | * the HW state machine and use this driver only for voltage control. | |
1428 | * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC | |
1429 | * in order to set the system to SUSPEND state. | |
1430 | * | |
1431 | * If regulator is taken under SW control the regulator state will not | |
1432 | * be affected by PMIC state machine - Eg. regulator is likely to stay | |
1433 | * on even in SUSPEND | |
1434 | */ | |
1435 | get_hw_controlled_regulators(pdev->dev.parent, reg_data, num_reg_data, | |
1436 | &omit_enable); | |
df9db254 | 1437 | |
b389ceae | 1438 | for (i = 0; i < num_reg_data; i++) { |
ba08799e | 1439 | |
1d848d68 | 1440 | struct regulator_desc *desc; |
ba08799e | 1441 | struct regulator_dev *rdev; |
1d848d68 MV |
1442 | struct bd718xx_regulator_data *r; |
1443 | int no_enable_control = omit_enable & (1 << i); | |
ba08799e | 1444 | |
b389ceae | 1445 | r = ®_data[i]; |
494edd26 | 1446 | desc = &r->desc; |
ba08799e | 1447 | |
1d848d68 MV |
1448 | if (no_enable_control) |
1449 | desc->ops = hwops[i]; | |
1450 | else | |
1451 | desc->ops = swops[i]; | |
ba08799e MV |
1452 | |
1453 | rdev = devm_regulator_register(&pdev->dev, desc, &config); | |
1454 | if (IS_ERR(rdev)) { | |
bcb047eb | 1455 | dev_err(&pdev->dev, |
ba08799e MV |
1456 | "failed to register %s regulator\n", |
1457 | desc->name); | |
1458 | err = PTR_ERR(rdev); | |
1459 | goto err; | |
1460 | } | |
049369d4 MV |
1461 | |
1462 | /* | |
1463 | * Regulator register gets the regulator constraints and | |
ba08799e MV |
1464 | * applies them (set_machine_constraints). This should have |
1465 | * turned the control register(s) to correct values and we | |
1466 | * can now switch the control from PMIC state machine to the | |
1467 | * register interface | |
049369d4 MV |
1468 | * |
1469 | * At poweroff transition PMIC HW disables EN bit for | |
1470 | * regulators but leaves SEL bit untouched. So if state | |
1471 | * transition from POWEROFF is done to SNVS - then all power | |
1472 | * rails controlled by SW (having SEL bit set) stay disabled | |
1473 | * as EN is cleared. This will result boot failure if any | |
1474 | * crucial systems are powered by these rails. We don't | |
1475 | * enable SW control for crucial regulators if snvs state is | |
1476 | * used | |
ba08799e | 1477 | */ |
1d848d68 MV |
1478 | if (!no_enable_control && (!use_snvs || |
1479 | !rdev->constraints->always_on || | |
1480 | !rdev->constraints->boot_on)) { | |
2a6a7aac | 1481 | err = regmap_update_bits(mfd->chip.regmap, r->init.reg, |
049369d4 MV |
1482 | r->init.mask, r->init.val); |
1483 | if (err) { | |
1484 | dev_err(&pdev->dev, | |
1485 | "Failed to take control for (%s)\n", | |
1486 | desc->name); | |
1487 | goto err; | |
1488 | } | |
ba08799e | 1489 | } |
494edd26 | 1490 | for (j = 0; j < r->additional_init_amnt; j++) { |
2a6a7aac | 1491 | err = regmap_update_bits(mfd->chip.regmap, |
494edd26 MV |
1492 | r->additional_inits[j].reg, |
1493 | r->additional_inits[j].mask, | |
1494 | r->additional_inits[j].val); | |
1495 | if (err) { | |
bcb047eb | 1496 | dev_err(&pdev->dev, |
494edd26 MV |
1497 | "Buck (%s) initialization failed\n", |
1498 | desc->name); | |
1499 | goto err; | |
1500 | } | |
1501 | } | |
ba08799e MV |
1502 | } |
1503 | ||
ba08799e MV |
1504 | err: |
1505 | return err; | |
1506 | } | |
1507 | ||
1b1c26b2 MV |
1508 | static const struct platform_device_id bd718x7_pmic_id[] = { |
1509 | { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 }, | |
1510 | { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 }, | |
1511 | { }, | |
1512 | }; | |
1513 | MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id); | |
1514 | ||
dd2be639 | 1515 | static struct platform_driver bd718xx_regulator = { |
ba08799e | 1516 | .driver = { |
494edd26 | 1517 | .name = "bd718xx-pmic", |
ba08799e | 1518 | }, |
dd2be639 | 1519 | .probe = bd718xx_probe, |
1b1c26b2 | 1520 | .id_table = bd718x7_pmic_id, |
ba08799e MV |
1521 | }; |
1522 | ||
dd2be639 | 1523 | module_platform_driver(bd718xx_regulator); |
ba08799e MV |
1524 | |
1525 | MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); | |
dd2be639 | 1526 | MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver"); |
ba08799e | 1527 | MODULE_LICENSE("GPL"); |
95bddd8b | 1528 | MODULE_ALIAS("platform:bd718xx-pmic"); |