1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 ROHM Semiconductors
3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
4
5 #include <linux/delay.h>
6 #include <linux/err.h>
7 #include <linux/interrupt.h>
8 #include <linux/kernel.h>
9 #include <linux/mfd/rohm-bd718x7.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/machine.h>
15 #include <linux/regulator/of_regulator.h>
16 #include <linux/slab.h>
17
18 /* Typical regulator startup times as per data sheet in uS */
19 #define BD71847_BUCK1_STARTUP_TIME 144
20 #define BD71847_BUCK2_STARTUP_TIME 162
21 #define BD71847_BUCK3_STARTUP_TIME 162
22 #define BD71847_BUCK4_STARTUP_TIME 240
23 #define BD71847_BUCK5_STARTUP_TIME 270
24 #define BD71847_BUCK6_STARTUP_TIME 200
25 #define BD71847_LDO1_STARTUP_TIME 440
26 #define BD71847_LDO2_STARTUP_TIME 370
27 #define BD71847_LDO3_STARTUP_TIME 310
28 #define BD71847_LDO4_STARTUP_TIME 400
29 #define BD71847_LDO5_STARTUP_TIME 530
30 #define BD71847_LDO6_STARTUP_TIME 400
31
32 #define BD71837_BUCK1_STARTUP_TIME 160
33 #define BD71837_BUCK2_STARTUP_TIME 180
34 #define BD71837_BUCK3_STARTUP_TIME 180
35 #define BD71837_BUCK4_STARTUP_TIME 180
36 #define BD71837_BUCK5_STARTUP_TIME 160
37 #define BD71837_BUCK6_STARTUP_TIME 240
38 #define BD71837_BUCK7_STARTUP_TIME 220
39 #define BD71837_BUCK8_STARTUP_TIME 200
40 #define BD71837_LDO1_STARTUP_TIME 440
41 #define BD71837_LDO2_STARTUP_TIME 370
42 #define BD71837_LDO3_STARTUP_TIME 310
43 #define BD71837_LDO4_STARTUP_TIME 400
44 #define BD71837_LDO5_STARTUP_TIME 310
45 #define BD71837_LDO6_STARTUP_TIME 400
46 #define BD71837_LDO7_STARTUP_TIME 530
47
48 /*
49 * BD718(37/47/50) have two "enable control modes". ON/OFF can either be
50 * controlled by software - or by PMIC internal HW state machine. Whether
51 * regulator should be under SW or HW control can be defined from device-tree.
52 * Let's provide separate ops for regulators to use depending on the "enable
53 * control mode".
54 */
55 #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
56
57 #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
58 _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay, \
59 _set_uvp, _set_ovp) \
60 static const struct regulator_ops name = { \
61 .enable = regulator_enable_regmap, \
62 .disable = regulator_disable_regmap, \
63 .is_enabled = regulator_is_enabled_regmap, \
64 .list_voltage = (_list_voltage), \
65 .map_voltage = (_map_voltage), \
66 .set_voltage_sel = (_set_voltage_sel), \
67 .get_voltage_sel = (_get_voltage_sel), \
68 .set_voltage_time_sel = (_set_voltage_time_sel), \
69 .set_ramp_delay = (_set_ramp_delay), \
70 .set_under_voltage_protection = (_set_uvp), \
71 .set_over_voltage_protection = (_set_ovp), \
72 }; \
73 \
74 static const struct regulator_ops BD718XX_HWOPNAME(name) = { \
75 .is_enabled = always_enabled_by_hwstate, \
76 .list_voltage = (_list_voltage), \
77 .map_voltage = (_map_voltage), \
78 .set_voltage_sel = (_set_voltage_sel), \
79 .get_voltage_sel = (_get_voltage_sel), \
80 .set_voltage_time_sel = (_set_voltage_time_sel), \
81 .set_ramp_delay = (_set_ramp_delay), \
82 .set_under_voltage_protection = (_set_uvp), \
83 .set_over_voltage_protection = (_set_ovp), \
84 } \
85
86 /*
87 * BUCK1/2/3/4
88 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
89 * 00: 10.00mV/usec 10mV 1uS
90 * 01: 5.00mV/usec 10mV 2uS
91 * 10: 2.50mV/usec 10mV 4uS
92 * 11: 1.25mV/usec 10mV 8uS
93 */
94 static const unsigned int bd718xx_ramp_delay[] = { 10000, 5000, 2500, 1250 };
95
96 /* These functions are used when regulators are under HW state machine control.
97 * We assume PMIC is in RUN state because SW running and able to query the
98 * status. Most of the regulators have fixed ON or OFF state at RUN/IDLE so for
99 * them we just return a constant. BD71837 BUCK3 and BUCK4 are exceptions as
100 * they support configuring the ON/OFF state for RUN.
101 *
102 * Note for next hacker - these PMICs have a register where the HW state can be
103 * read. If assuming RUN appears to be false in your use-case - you can
104 * implement state reading (although that is not going to be atomic) before
105 * returning the enable state.
106 */
always_enabled_by_hwstate(struct regulator_dev * rdev)107 static int always_enabled_by_hwstate(struct regulator_dev *rdev)
108 {
109 return 1;
110 }
111
never_enabled_by_hwstate(struct regulator_dev * rdev)112 static int never_enabled_by_hwstate(struct regulator_dev *rdev)
113 {
114 return 0;
115 }
116
bd71837_get_buck34_enable_hwctrl(struct regulator_dev * rdev)117 static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
118 {
119 int ret;
120 unsigned int val;
121
122 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
123 if (ret)
124 return ret;
125
126 return !!(BD718XX_BUCK_RUN_ON & val);
127 }
128 /*
129 * On BD71837 (not on BD71847, BD71850, ...)
130 * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
131 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
132 * is changed. Hence we return -EBUSY for these if voltage is changed
133 * when BUCK/LDO is enabled.
134 *
135 * On BD71847, BD71850, ... The LDO voltage can be changed when LDO is
136 * enabled. But if voltage is increased the LDO power-good monitoring
137 * must be disabled for the duration of changing + 1mS to ensure voltage
138 * has reached the higher level before HW does next under voltage detection
139 * cycle.
140 */
bd71837_set_voltage_sel_restricted(struct regulator_dev * rdev,unsigned int sel)141 static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
142 unsigned int sel)
143 {
144 if (rdev->desc->ops->is_enabled(rdev))
145 return -EBUSY;
146
147 return regulator_set_voltage_sel_regmap(rdev, sel);
148 }
149
voltage_change_done(struct regulator_dev * rdev,unsigned int sel,unsigned int * mask)150 static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
151 unsigned int *mask)
152 {
153 int ret;
154
155 if (*mask) {
156 /*
157 * Let's allow scheduling as we use I2C anyways. We just need to
158 * guarantee minimum of 1ms sleep - it shouldn't matter if we
159 * exceed it due to the scheduling.
160 */
161 msleep(1);
162
163 ret = regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
164 *mask);
165 if (ret)
166 dev_err(&rdev->dev,
167 "Failed to re-enable voltage monitoring (%d)\n",
168 ret);
169 }
170 }
171
voltage_change_prepare(struct regulator_dev * rdev,unsigned int sel,unsigned int * mask)172 static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
173 unsigned int *mask)
174 {
175 int ret;
176
177 *mask = 0;
178 if (rdev->desc->ops->is_enabled(rdev)) {
179 int now, new;
180
181 now = rdev->desc->ops->get_voltage_sel(rdev);
182 if (now < 0)
183 return now;
184
185 now = rdev->desc->ops->list_voltage(rdev, now);
186 if (now < 0)
187 return now;
188
189 new = rdev->desc->ops->list_voltage(rdev, sel);
190 if (new < 0)
191 return new;
192
193 /*
194 * If we increase LDO voltage when LDO is enabled we need to
195 * disable the power-good detection until voltage has reached
196 * the new level. According to HW colleagues the maximum time
197 * it takes is 1000us. I assume that on systems with light load
198 * this might be less - and we could probably use DT to give
199 * system specific delay value if performance matters.
200 *
201 * Well, knowing we use I2C here and can add scheduling delays
202 * I don't think it is worth the hassle and I just add fixed
203 * 1ms sleep here (and allow scheduling). If this turns out to
204 * be a problem we can change it to delay and make the delay
205 * time configurable.
206 */
207 if (new > now) {
208 int tmp;
209 int prot_bit;
210 int ldo_offset = rdev->desc->id - BD718XX_LDO1;
211
212 prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
213 ret = regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
214 &tmp);
215 if (ret) {
216 dev_err(&rdev->dev,
217 "Failed to read voltage monitoring state\n");
218 return ret;
219 }
220
221 if (!(tmp & prot_bit)) {
222 /* We disable protection if it was enabled... */
223 ret = regmap_set_bits(rdev->regmap,
224 BD718XX_REG_MVRFLTMASK2,
225 prot_bit);
226 /* ...and we also want to re-enable it */
227 *mask = prot_bit;
228 }
229 if (ret) {
230 dev_err(&rdev->dev,
231 "Failed to stop voltage monitoring\n");
232 return ret;
233 }
234 }
235 }
236
237 return 0;
238 }
239
bd718xx_set_voltage_sel_restricted(struct regulator_dev * rdev,unsigned int sel)240 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
241 unsigned int sel)
242 {
243 int ret;
244 int mask;
245
246 ret = voltage_change_prepare(rdev, sel, &mask);
247 if (ret)
248 return ret;
249
250 ret = regulator_set_voltage_sel_regmap(rdev, sel);
251 voltage_change_done(rdev, sel, &mask);
252
253 return ret;
254 }
255
bd718xx_set_voltage_sel_pickable_restricted(struct regulator_dev * rdev,unsigned int sel)256 static int bd718xx_set_voltage_sel_pickable_restricted(
257 struct regulator_dev *rdev, unsigned int sel)
258 {
259 int ret;
260 int mask;
261
262 ret = voltage_change_prepare(rdev, sel, &mask);
263 if (ret)
264 return ret;
265
266 ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
267 voltage_change_done(rdev, sel, &mask);
268
269 return ret;
270 }
271
bd71837_set_voltage_sel_pickable_restricted(struct regulator_dev * rdev,unsigned int sel)272 static int bd71837_set_voltage_sel_pickable_restricted(
273 struct regulator_dev *rdev, unsigned int sel)
274 {
275 if (rdev->desc->ops->is_enabled(rdev))
276 return -EBUSY;
277
278 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
279 }
280
281 /*
282 * BD71837 BUCK1/2/3/4
283 * BD71847 BUCK1/2
284 * 0.70 to 1.30V (10mV step)
285 */
286 static const struct linear_range bd718xx_dvs_buck_volts[] = {
287 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
288 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
289 };
290
291 /*
292 * BD71837 BUCK5
293 * 0.7V to 1.35V (range 0)
294 * and
295 * 0.675 to 1.325 (range 1)
296 */
297 static const struct linear_range bd71837_buck5_volts[] = {
298 /* Ranges when VOLT_SEL bit is 0 */
299 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
300 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
301 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
302 /* Ranges when VOLT_SEL bit is 1 */
303 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
304 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
305 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
306 };
307
308 /*
309 * Range selector for first 3 linear ranges is 0x0
310 * and 0x1 for last 3 ranges.
311 */
312 static const unsigned int bd71837_buck5_volt_range_sel[] = {
313 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
314 };
315
316 /*
317 * BD71847 BUCK3
318 */
319 static const struct linear_range bd71847_buck3_volts[] = {
320 /* Ranges when VOLT_SEL bits are 00 */
321 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
322 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
323 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
324 /* Ranges when VOLT_SEL bits are 01 */
325 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
326 /* Ranges when VOLT_SEL bits are 11 */
327 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
328 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
329 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
330 };
331
332 static const unsigned int bd71847_buck3_volt_range_sel[] = {
333 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
334 };
335
336 static const struct linear_range bd71847_buck4_volts[] = {
337 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
338 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
339 };
340
341 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
342
343 /*
344 * BUCK6
345 * 3.0V to 3.3V (step 100mV)
346 */
347 static const struct linear_range bd71837_buck6_volts[] = {
348 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
349 };
350
351 /*
352 * BD71837 BUCK7
353 * BD71847 BUCK5
354 * 000 = 1.605V
355 * 001 = 1.695V
356 * 010 = 1.755V
357 * 011 = 1.8V (Initial)
358 * 100 = 1.845V
359 * 101 = 1.905V
360 * 110 = 1.95V
361 * 111 = 1.995V
362 */
363 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
364 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
365 };
366
367 /*
368 * BUCK8
369 * 0.8V to 1.40V (step 10mV)
370 */
371 static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
372 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
373 };
374
375 /*
376 * LDO1
377 * 3.0 to 3.3V (100mV step)
378 */
379 static const struct linear_range bd718xx_ldo1_volts[] = {
380 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
381 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
382 };
383
384 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
385
386 /*
387 * LDO2
388 * 0.8 or 0.9V
389 */
390 static const unsigned int ldo_2_volts[] = {
391 900000, 800000
392 };
393
394 /*
395 * LDO3
396 * 1.8 to 3.3V (100mV step)
397 */
398 static const struct linear_range bd718xx_ldo3_volts[] = {
399 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
400 };
401
402 /*
403 * LDO4
404 * 0.9 to 1.8V (100mV step)
405 */
406 static const struct linear_range bd718xx_ldo4_volts[] = {
407 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
408 };
409
410 /*
411 * LDO5 for BD71837
412 * 1.8 to 3.3V (100mV step)
413 */
414 static const struct linear_range bd71837_ldo5_volts[] = {
415 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
416 };
417
418 /*
419 * LDO5 for BD71837
420 * 1.8 to 3.3V (100mV step)
421 */
422 static const struct linear_range bd71847_ldo5_volts[] = {
423 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
424 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
425 };
426
427 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
428
429 /*
430 * LDO6
431 * 0.9 to 1.8V (100mV step)
432 */
433 static const struct linear_range bd718xx_ldo6_volts[] = {
434 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
435 };
436
437 /*
438 * LDO7
439 * 1.8 to 3.3V (100mV step)
440 */
441 static const struct linear_range bd71837_ldo7_volts[] = {
442 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
443 };
444
445 struct reg_init {
446 unsigned int reg;
447 unsigned int mask;
448 unsigned int val;
449 };
450 struct bd718xx_regulator_data {
451 struct regulator_desc desc;
452 const struct rohm_dvs_config dvs;
453 const struct reg_init init;
454 const struct reg_init *additional_inits;
455 int additional_init_amnt;
456 };
457
bd718x7_xvp_sanity_check(struct regulator_dev * rdev,int lim_uV,int severity)458 static int bd718x7_xvp_sanity_check(struct regulator_dev *rdev, int lim_uV,
459 int severity)
460 {
461 /*
462 * BD71837/47/50 ... (ICs supported by this driver) do not provide
463 * warnings, only protection
464 */
465 if (severity != REGULATOR_SEVERITY_PROT) {
466 dev_err(&rdev->dev,
467 "Unsupported Under Voltage protection level\n");
468 return -EINVAL;
469 }
470
471 /*
472 * And protection limit is not changeable. It can only be enabled
473 * or disabled
474 */
475 if (lim_uV)
476 return -EINVAL;
477
478 return 0;
479 }
480
bd718x7_set_ldo_uvp(struct regulator_dev * rdev,int lim_uV,int severity,bool enable)481 static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV,
482 int severity, bool enable)
483 {
484 int ldo_offset = rdev->desc->id - BD718XX_LDO1;
485 int prot_bit, ret;
486
487 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
488 if (ret)
489 return ret;
490
491 prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
492
493 if (enable)
494 return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
495 prot_bit);
496
497 return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
498 prot_bit);
499 }
500
bd718x7_get_buck_prot_reg(int id,int * reg)501 static int bd718x7_get_buck_prot_reg(int id, int *reg)
502 {
503
504 if (id > BD718XX_BUCK8) {
505 WARN_ON(id > BD718XX_BUCK8);
506 return -EINVAL;
507 }
508
509 if (id > BD718XX_BUCK4)
510 *reg = BD718XX_REG_MVRFLTMASK0;
511 else
512 *reg = BD718XX_REG_MVRFLTMASK1;
513
514 return 0;
515 }
516
bd718x7_get_buck_ovp_info(int id,int * reg,int * bit)517 static int bd718x7_get_buck_ovp_info(int id, int *reg, int *bit)
518 {
519 int ret;
520
521 ret = bd718x7_get_buck_prot_reg(id, reg);
522 if (ret)
523 return ret;
524
525 *bit = BIT((id % 4) * 2 + 1);
526
527 return 0;
528 }
529
bd718x7_get_buck_uvp_info(int id,int * reg,int * bit)530 static int bd718x7_get_buck_uvp_info(int id, int *reg, int *bit)
531 {
532 int ret;
533
534 ret = bd718x7_get_buck_prot_reg(id, reg);
535 if (ret)
536 return ret;
537
538 *bit = BIT((id % 4) * 2);
539
540 return 0;
541 }
542
bd718x7_set_buck_uvp(struct regulator_dev * rdev,int lim_uV,int severity,bool enable)543 static int bd718x7_set_buck_uvp(struct regulator_dev *rdev, int lim_uV,
544 int severity, bool enable)
545 {
546 int bit, reg, ret;
547
548 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
549 if (ret)
550 return ret;
551
552 ret = bd718x7_get_buck_uvp_info(rdev->desc->id, ®, &bit);
553 if (ret)
554 return ret;
555
556 if (enable)
557 return regmap_clear_bits(rdev->regmap, reg, bit);
558
559 return regmap_set_bits(rdev->regmap, reg, bit);
560
561 }
562
bd718x7_set_buck_ovp(struct regulator_dev * rdev,int lim_uV,int severity,bool enable)563 static int bd718x7_set_buck_ovp(struct regulator_dev *rdev, int lim_uV,
564 int severity,
565 bool enable)
566 {
567 int bit, reg, ret;
568
569 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
570 if (ret)
571 return ret;
572
573 ret = bd718x7_get_buck_ovp_info(rdev->desc->id, ®, &bit);
574 if (ret)
575 return ret;
576
577 if (enable)
578 return regmap_clear_bits(rdev->regmap, reg, bit);
579
580 return regmap_set_bits(rdev->regmap, reg, bit);
581 }
582
583 /*
584 * OPS common for BD71847 and BD71850
585 */
586 BD718XX_OPS(bd718xx_pickable_range_ldo_ops,
587 regulator_list_voltage_pickable_linear_range, NULL,
588 bd718xx_set_voltage_sel_pickable_restricted,
589 regulator_get_voltage_sel_pickable_regmap, NULL, NULL,
590 bd718x7_set_ldo_uvp, NULL);
591
592 /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */
593 static const struct regulator_ops bd718xx_ldo5_ops_hwstate = {
594 .is_enabled = never_enabled_by_hwstate,
595 .list_voltage = regulator_list_voltage_pickable_linear_range,
596 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
597 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
598 .set_under_voltage_protection = bd718x7_set_ldo_uvp,
599 };
600
601 BD718XX_OPS(bd718xx_pickable_range_buck_ops,
602 regulator_list_voltage_pickable_linear_range, NULL,
603 regulator_set_voltage_sel_pickable_regmap,
604 regulator_get_voltage_sel_pickable_regmap,
605 regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp,
606 bd718x7_set_buck_ovp);
607
608 BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range,
609 NULL, bd718xx_set_voltage_sel_restricted,
610 regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
611 NULL);
612
613 BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
614 NULL, bd718xx_set_voltage_sel_restricted,
615 regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
616 NULL);
617
618 BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range,
619 NULL, regulator_set_voltage_sel_regmap,
620 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
621 NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
622
623 BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table,
624 regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap,
625 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
626 NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
627
628 /*
629 * OPS for BD71837
630 */
631 BD718XX_OPS(bd71837_pickable_range_ldo_ops,
632 regulator_list_voltage_pickable_linear_range, NULL,
633 bd71837_set_voltage_sel_pickable_restricted,
634 regulator_get_voltage_sel_pickable_regmap, NULL, NULL,
635 bd718x7_set_ldo_uvp, NULL);
636
637 BD718XX_OPS(bd71837_pickable_range_buck_ops,
638 regulator_list_voltage_pickable_linear_range, NULL,
639 bd71837_set_voltage_sel_pickable_restricted,
640 regulator_get_voltage_sel_pickable_regmap,
641 regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp,
642 bd718x7_set_buck_ovp);
643
644 BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range,
645 NULL, bd71837_set_voltage_sel_restricted,
646 regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
647 NULL);
648
649 BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
650 NULL, bd71837_set_voltage_sel_restricted,
651 regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp,
652 NULL);
653
654 BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range,
655 NULL, bd71837_set_voltage_sel_restricted,
656 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
657 NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
658
659 BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
660 regulator_map_voltage_ascend, bd71837_set_voltage_sel_restricted,
661 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
662 NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp);
663 /*
664 * BD71837 bucks 3 and 4 support defining their enable/disable state also
665 * when buck enable state is under HW state machine control. In that case the
666 * bit [2] in CTRL register is used to indicate if regulator should be ON.
667 */
668 static const struct regulator_ops bd71837_buck34_ops_hwctrl = {
669 .is_enabled = bd71837_get_buck34_enable_hwctrl,
670 .list_voltage = regulator_list_voltage_linear_range,
671 .set_voltage_sel = regulator_set_voltage_sel_regmap,
672 .get_voltage_sel = regulator_get_voltage_sel_regmap,
673 .set_voltage_time_sel = regulator_set_voltage_time_sel,
674 .set_ramp_delay = regulator_set_ramp_delay_regmap,
675 .set_under_voltage_protection = bd718x7_set_buck_uvp,
676 .set_over_voltage_protection = bd718x7_set_buck_ovp,
677 };
678
679 /*
680 * OPS for all of the ICs - BD718(37/47/50)
681 */
682 BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range,
683 NULL, regulator_set_voltage_sel_regmap,
684 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
685 regulator_set_ramp_delay_regmap, bd718x7_set_buck_uvp,
686 bd718x7_set_buck_ovp);
687
688
689
690 /*
691 * There is a HW quirk in BD71837. The shutdown sequence timings for
692 * bucks/LDOs which are controlled via register interface are changed.
693 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
694 * beginning of shut-down sequence. As bucks 6 and 7 are parent
695 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
696 * monitoring to errorneously detect under voltage and force PMIC to
697 * emergency state instead of poweroff. In order to avoid this we
698 * disable voltage monitoring for LDO5 and LDO6
699 */
700 static const struct reg_init bd71837_ldo5_inits[] = {
701 {
702 .reg = BD718XX_REG_MVRFLTMASK2,
703 .mask = BD718XX_LDO5_VRMON80,
704 .val = BD718XX_LDO5_VRMON80,
705 },
706 };
707
708 static const struct reg_init bd71837_ldo6_inits[] = {
709 {
710 .reg = BD718XX_REG_MVRFLTMASK2,
711 .mask = BD718XX_LDO6_VRMON80,
712 .val = BD718XX_LDO6_VRMON80,
713 },
714 };
715
buck_set_hw_dvs_levels(struct device_node * np,const struct regulator_desc * desc,struct regulator_config * cfg)716 static int buck_set_hw_dvs_levels(struct device_node *np,
717 const struct regulator_desc *desc,
718 struct regulator_config *cfg)
719 {
720 struct bd718xx_regulator_data *data;
721
722 data = container_of(desc, struct bd718xx_regulator_data, desc);
723
724 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
725 }
726
727 static const struct regulator_ops *bd71847_swcontrol_ops[] = {
728 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
729 &bd718xx_pickable_range_buck_ops, &bd718xx_pickable_range_buck_ops,
730 &bd718xx_buck_regulator_nolinear_ops, &bd718xx_buck_regulator_ops,
731 &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_nolinear_ops,
732 &bd718xx_ldo_regulator_ops, &bd718xx_ldo_regulator_ops,
733 &bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_ops,
734 };
735
736 static const struct regulator_ops *bd71847_hwcontrol_ops[] = {
737 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
738 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
739 &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
740 &BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
741 &BD718XX_HWOPNAME(bd718xx_buck_regulator_nolinear_ops),
742 &BD718XX_HWOPNAME(bd718xx_buck_regulator_ops),
743 &BD718XX_HWOPNAME(bd718xx_pickable_range_ldo_ops),
744 &BD718XX_HWOPNAME(bd718xx_ldo_regulator_nolinear_ops),
745 &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
746 &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
747 &bd718xx_ldo5_ops_hwstate,
748 &BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
749 };
750
751 static struct bd718xx_regulator_data bd71847_regulators[] = {
752 {
753 .desc = {
754 .name = "buck1",
755 .of_match = of_match_ptr("BUCK1"),
756 .regulators_node = of_match_ptr("regulators"),
757 .id = BD718XX_BUCK1,
758 .type = REGULATOR_VOLTAGE,
759 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
760 .linear_ranges = bd718xx_dvs_buck_volts,
761 .n_linear_ranges =
762 ARRAY_SIZE(bd718xx_dvs_buck_volts),
763 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
764 .vsel_mask = DVS_BUCK_RUN_MASK,
765 .enable_reg = BD718XX_REG_BUCK1_CTRL,
766 .enable_mask = BD718XX_BUCK_EN,
767 .enable_time = BD71847_BUCK1_STARTUP_TIME,
768 .owner = THIS_MODULE,
769 .ramp_delay_table = bd718xx_ramp_delay,
770 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
771 .ramp_reg = BD718XX_REG_BUCK1_CTRL,
772 .ramp_mask = BUCK_RAMPRATE_MASK,
773 .of_parse_cb = buck_set_hw_dvs_levels,
774 },
775 .dvs = {
776 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
777 ROHM_DVS_LEVEL_SUSPEND,
778 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
779 .run_mask = DVS_BUCK_RUN_MASK,
780 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
781 .idle_mask = DVS_BUCK_RUN_MASK,
782 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
783 .suspend_mask = DVS_BUCK_RUN_MASK,
784 },
785 .init = {
786 .reg = BD718XX_REG_BUCK1_CTRL,
787 .mask = BD718XX_BUCK_SEL,
788 .val = BD718XX_BUCK_SEL,
789 },
790 },
791 {
792 .desc = {
793 .name = "buck2",
794 .of_match = of_match_ptr("BUCK2"),
795 .regulators_node = of_match_ptr("regulators"),
796 .id = BD718XX_BUCK2,
797 .type = REGULATOR_VOLTAGE,
798 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
799 .linear_ranges = bd718xx_dvs_buck_volts,
800 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
801 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
802 .vsel_mask = DVS_BUCK_RUN_MASK,
803 .enable_reg = BD718XX_REG_BUCK2_CTRL,
804 .enable_mask = BD718XX_BUCK_EN,
805 .enable_time = BD71847_BUCK2_STARTUP_TIME,
806 .ramp_delay_table = bd718xx_ramp_delay,
807 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
808 .ramp_reg = BD718XX_REG_BUCK2_CTRL,
809 .ramp_mask = BUCK_RAMPRATE_MASK,
810 .owner = THIS_MODULE,
811 .of_parse_cb = buck_set_hw_dvs_levels,
812 },
813 .dvs = {
814 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
815 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
816 .run_mask = DVS_BUCK_RUN_MASK,
817 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
818 .idle_mask = DVS_BUCK_RUN_MASK,
819 },
820 .init = {
821 .reg = BD718XX_REG_BUCK2_CTRL,
822 .mask = BD718XX_BUCK_SEL,
823 .val = BD718XX_BUCK_SEL,
824 },
825 },
826 {
827 .desc = {
828 .name = "buck3",
829 .of_match = of_match_ptr("BUCK3"),
830 .regulators_node = of_match_ptr("regulators"),
831 .id = BD718XX_BUCK3,
832 .type = REGULATOR_VOLTAGE,
833 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
834 .linear_ranges = bd71847_buck3_volts,
835 .n_linear_ranges =
836 ARRAY_SIZE(bd71847_buck3_volts),
837 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
838 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
839 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
840 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
841 .linear_range_selectors = bd71847_buck3_volt_range_sel,
842 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
843 .enable_mask = BD718XX_BUCK_EN,
844 .enable_time = BD71847_BUCK3_STARTUP_TIME,
845 .owner = THIS_MODULE,
846 },
847 .init = {
848 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
849 .mask = BD718XX_BUCK_SEL,
850 .val = BD718XX_BUCK_SEL,
851 },
852 },
853 {
854 .desc = {
855 .name = "buck4",
856 .of_match = of_match_ptr("BUCK4"),
857 .regulators_node = of_match_ptr("regulators"),
858 .id = BD718XX_BUCK4,
859 .type = REGULATOR_VOLTAGE,
860 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
861 .linear_ranges = bd71847_buck4_volts,
862 .n_linear_ranges =
863 ARRAY_SIZE(bd71847_buck4_volts),
864 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
865 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
866 .vsel_mask = BD71847_BUCK4_MASK,
867 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
868 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
869 .linear_range_selectors = bd71847_buck4_volt_range_sel,
870 .enable_mask = BD718XX_BUCK_EN,
871 .enable_time = BD71847_BUCK4_STARTUP_TIME,
872 .owner = THIS_MODULE,
873 },
874 .init = {
875 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
876 .mask = BD718XX_BUCK_SEL,
877 .val = BD718XX_BUCK_SEL,
878 },
879 },
880 {
881 .desc = {
882 .name = "buck5",
883 .of_match = of_match_ptr("BUCK5"),
884 .regulators_node = of_match_ptr("regulators"),
885 .id = BD718XX_BUCK5,
886 .type = REGULATOR_VOLTAGE,
887 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
888 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
889 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
890 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
891 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
892 .enable_mask = BD718XX_BUCK_EN,
893 .enable_time = BD71847_BUCK5_STARTUP_TIME,
894 .owner = THIS_MODULE,
895 },
896 .init = {
897 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
898 .mask = BD718XX_BUCK_SEL,
899 .val = BD718XX_BUCK_SEL,
900 },
901 },
902 {
903 .desc = {
904 .name = "buck6",
905 .of_match = of_match_ptr("BUCK6"),
906 .regulators_node = of_match_ptr("regulators"),
907 .id = BD718XX_BUCK6,
908 .type = REGULATOR_VOLTAGE,
909 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
910 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
911 .n_linear_ranges =
912 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
913 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
914 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
915 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
916 .enable_mask = BD718XX_BUCK_EN,
917 .enable_time = BD71847_BUCK6_STARTUP_TIME,
918 .owner = THIS_MODULE,
919 },
920 .init = {
921 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
922 .mask = BD718XX_BUCK_SEL,
923 .val = BD718XX_BUCK_SEL,
924 },
925 },
926 {
927 .desc = {
928 .name = "ldo1",
929 .of_match = of_match_ptr("LDO1"),
930 .regulators_node = of_match_ptr("regulators"),
931 .id = BD718XX_LDO1,
932 .type = REGULATOR_VOLTAGE,
933 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
934 .linear_ranges = bd718xx_ldo1_volts,
935 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
936 .vsel_reg = BD718XX_REG_LDO1_VOLT,
937 .vsel_mask = BD718XX_LDO1_MASK,
938 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
939 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
940 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
941 .enable_reg = BD718XX_REG_LDO1_VOLT,
942 .enable_mask = BD718XX_LDO_EN,
943 .enable_time = BD71847_LDO1_STARTUP_TIME,
944 .owner = THIS_MODULE,
945 },
946 .init = {
947 .reg = BD718XX_REG_LDO1_VOLT,
948 .mask = BD718XX_LDO_SEL,
949 .val = BD718XX_LDO_SEL,
950 },
951 },
952 {
953 .desc = {
954 .name = "ldo2",
955 .of_match = of_match_ptr("LDO2"),
956 .regulators_node = of_match_ptr("regulators"),
957 .id = BD718XX_LDO2,
958 .type = REGULATOR_VOLTAGE,
959 .volt_table = &ldo_2_volts[0],
960 .vsel_reg = BD718XX_REG_LDO2_VOLT,
961 .vsel_mask = BD718XX_LDO2_MASK,
962 .n_voltages = ARRAY_SIZE(ldo_2_volts),
963 .enable_reg = BD718XX_REG_LDO2_VOLT,
964 .enable_mask = BD718XX_LDO_EN,
965 .enable_time = BD71847_LDO2_STARTUP_TIME,
966 .owner = THIS_MODULE,
967 },
968 .init = {
969 .reg = BD718XX_REG_LDO2_VOLT,
970 .mask = BD718XX_LDO_SEL,
971 .val = BD718XX_LDO_SEL,
972 },
973 },
974 {
975 .desc = {
976 .name = "ldo3",
977 .of_match = of_match_ptr("LDO3"),
978 .regulators_node = of_match_ptr("regulators"),
979 .id = BD718XX_LDO3,
980 .type = REGULATOR_VOLTAGE,
981 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
982 .linear_ranges = bd718xx_ldo3_volts,
983 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
984 .vsel_reg = BD718XX_REG_LDO3_VOLT,
985 .vsel_mask = BD718XX_LDO3_MASK,
986 .enable_reg = BD718XX_REG_LDO3_VOLT,
987 .enable_mask = BD718XX_LDO_EN,
988 .enable_time = BD71847_LDO3_STARTUP_TIME,
989 .owner = THIS_MODULE,
990 },
991 .init = {
992 .reg = BD718XX_REG_LDO3_VOLT,
993 .mask = BD718XX_LDO_SEL,
994 .val = BD718XX_LDO_SEL,
995 },
996 },
997 {
998 .desc = {
999 .name = "ldo4",
1000 .of_match = of_match_ptr("LDO4"),
1001 .regulators_node = of_match_ptr("regulators"),
1002 .id = BD718XX_LDO4,
1003 .type = REGULATOR_VOLTAGE,
1004 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1005 .linear_ranges = bd718xx_ldo4_volts,
1006 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1007 .vsel_reg = BD718XX_REG_LDO4_VOLT,
1008 .vsel_mask = BD718XX_LDO4_MASK,
1009 .enable_reg = BD718XX_REG_LDO4_VOLT,
1010 .enable_mask = BD718XX_LDO_EN,
1011 .enable_time = BD71847_LDO4_STARTUP_TIME,
1012 .owner = THIS_MODULE,
1013 },
1014 .init = {
1015 .reg = BD718XX_REG_LDO4_VOLT,
1016 .mask = BD718XX_LDO_SEL,
1017 .val = BD718XX_LDO_SEL,
1018 },
1019 },
1020 {
1021 .desc = {
1022 .name = "ldo5",
1023 .of_match = of_match_ptr("LDO5"),
1024 .regulators_node = of_match_ptr("regulators"),
1025 .id = BD718XX_LDO5,
1026 .type = REGULATOR_VOLTAGE,
1027 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
1028 .linear_ranges = bd71847_ldo5_volts,
1029 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
1030 .vsel_reg = BD718XX_REG_LDO5_VOLT,
1031 .vsel_mask = BD71847_LDO5_MASK,
1032 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
1033 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
1034 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
1035 .enable_reg = BD718XX_REG_LDO5_VOLT,
1036 .enable_mask = BD718XX_LDO_EN,
1037 .enable_time = BD71847_LDO5_STARTUP_TIME,
1038 .owner = THIS_MODULE,
1039 },
1040 .init = {
1041 .reg = BD718XX_REG_LDO5_VOLT,
1042 .mask = BD718XX_LDO_SEL,
1043 .val = BD718XX_LDO_SEL,
1044 },
1045 },
1046 {
1047 .desc = {
1048 .name = "ldo6",
1049 .of_match = of_match_ptr("LDO6"),
1050 .regulators_node = of_match_ptr("regulators"),
1051 .id = BD718XX_LDO6,
1052 .type = REGULATOR_VOLTAGE,
1053 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1054 .linear_ranges = bd718xx_ldo6_volts,
1055 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1056 /* LDO6 is supplied by buck5 */
1057 .supply_name = "buck5",
1058 .vsel_reg = BD718XX_REG_LDO6_VOLT,
1059 .vsel_mask = BD718XX_LDO6_MASK,
1060 .enable_reg = BD718XX_REG_LDO6_VOLT,
1061 .enable_mask = BD718XX_LDO_EN,
1062 .enable_time = BD71847_LDO6_STARTUP_TIME,
1063 .owner = THIS_MODULE,
1064 },
1065 .init = {
1066 .reg = BD718XX_REG_LDO6_VOLT,
1067 .mask = BD718XX_LDO_SEL,
1068 .val = BD718XX_LDO_SEL,
1069 },
1070 },
1071 };
1072
1073 static const struct regulator_ops *bd71837_swcontrol_ops[] = {
1074 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
1075 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
1076 &bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
1077 &bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
1078 &bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
1079 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
1080 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
1081 &bd71837_ldo_regulator_ops,
1082 };
1083
1084 static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
1085 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
1086 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
1087 &bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
1088 &BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
1089 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
1090 &BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
1091 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
1092 &BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
1093 &BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
1094 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
1095 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
1096 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
1097 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
1098 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
1099 };
1100
1101 static struct bd718xx_regulator_data bd71837_regulators[] = {
1102 {
1103 .desc = {
1104 .name = "buck1",
1105 .of_match = of_match_ptr("BUCK1"),
1106 .regulators_node = of_match_ptr("regulators"),
1107 .id = BD718XX_BUCK1,
1108 .type = REGULATOR_VOLTAGE,
1109 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1110 .linear_ranges = bd718xx_dvs_buck_volts,
1111 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1112 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
1113 .vsel_mask = DVS_BUCK_RUN_MASK,
1114 .enable_reg = BD718XX_REG_BUCK1_CTRL,
1115 .enable_mask = BD718XX_BUCK_EN,
1116 .enable_time = BD71837_BUCK1_STARTUP_TIME,
1117 .ramp_delay_table = bd718xx_ramp_delay,
1118 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1119 .ramp_reg = BD718XX_REG_BUCK1_CTRL,
1120 .ramp_mask = BUCK_RAMPRATE_MASK,
1121 .owner = THIS_MODULE,
1122 .of_parse_cb = buck_set_hw_dvs_levels,
1123 },
1124 .dvs = {
1125 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
1126 ROHM_DVS_LEVEL_SUSPEND,
1127 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
1128 .run_mask = DVS_BUCK_RUN_MASK,
1129 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
1130 .idle_mask = DVS_BUCK_RUN_MASK,
1131 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
1132 .suspend_mask = DVS_BUCK_RUN_MASK,
1133 },
1134 .init = {
1135 .reg = BD718XX_REG_BUCK1_CTRL,
1136 .mask = BD718XX_BUCK_SEL,
1137 .val = BD718XX_BUCK_SEL,
1138 },
1139 },
1140 {
1141 .desc = {
1142 .name = "buck2",
1143 .of_match = of_match_ptr("BUCK2"),
1144 .regulators_node = of_match_ptr("regulators"),
1145 .id = BD718XX_BUCK2,
1146 .type = REGULATOR_VOLTAGE,
1147 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1148 .linear_ranges = bd718xx_dvs_buck_volts,
1149 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1150 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
1151 .vsel_mask = DVS_BUCK_RUN_MASK,
1152 .enable_reg = BD718XX_REG_BUCK2_CTRL,
1153 .enable_mask = BD718XX_BUCK_EN,
1154 .enable_time = BD71837_BUCK2_STARTUP_TIME,
1155 .ramp_delay_table = bd718xx_ramp_delay,
1156 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1157 .ramp_reg = BD718XX_REG_BUCK2_CTRL,
1158 .ramp_mask = BUCK_RAMPRATE_MASK,
1159 .owner = THIS_MODULE,
1160 .of_parse_cb = buck_set_hw_dvs_levels,
1161 },
1162 .dvs = {
1163 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
1164 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
1165 .run_mask = DVS_BUCK_RUN_MASK,
1166 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
1167 .idle_mask = DVS_BUCK_RUN_MASK,
1168 },
1169 .init = {
1170 .reg = BD718XX_REG_BUCK2_CTRL,
1171 .mask = BD718XX_BUCK_SEL,
1172 .val = BD718XX_BUCK_SEL,
1173 },
1174 },
1175 {
1176 .desc = {
1177 .name = "buck3",
1178 .of_match = of_match_ptr("BUCK3"),
1179 .regulators_node = of_match_ptr("regulators"),
1180 .id = BD718XX_BUCK3,
1181 .type = REGULATOR_VOLTAGE,
1182 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1183 .linear_ranges = bd718xx_dvs_buck_volts,
1184 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1185 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
1186 .vsel_mask = DVS_BUCK_RUN_MASK,
1187 .enable_reg = BD71837_REG_BUCK3_CTRL,
1188 .enable_mask = BD718XX_BUCK_EN,
1189 .enable_time = BD71837_BUCK3_STARTUP_TIME,
1190 .ramp_delay_table = bd718xx_ramp_delay,
1191 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1192 .ramp_reg = BD71837_REG_BUCK3_CTRL,
1193 .ramp_mask = BUCK_RAMPRATE_MASK,
1194 .owner = THIS_MODULE,
1195 .of_parse_cb = buck_set_hw_dvs_levels,
1196 },
1197 .dvs = {
1198 .level_map = ROHM_DVS_LEVEL_RUN,
1199 .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
1200 .run_mask = DVS_BUCK_RUN_MASK,
1201 },
1202 .init = {
1203 .reg = BD71837_REG_BUCK3_CTRL,
1204 .mask = BD718XX_BUCK_SEL,
1205 .val = BD718XX_BUCK_SEL,
1206 },
1207 },
1208 {
1209 .desc = {
1210 .name = "buck4",
1211 .of_match = of_match_ptr("BUCK4"),
1212 .regulators_node = of_match_ptr("regulators"),
1213 .id = BD718XX_BUCK4,
1214 .type = REGULATOR_VOLTAGE,
1215 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1216 .linear_ranges = bd718xx_dvs_buck_volts,
1217 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1218 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
1219 .vsel_mask = DVS_BUCK_RUN_MASK,
1220 .enable_reg = BD71837_REG_BUCK4_CTRL,
1221 .enable_mask = BD718XX_BUCK_EN,
1222 .enable_time = BD71837_BUCK4_STARTUP_TIME,
1223 .ramp_delay_table = bd718xx_ramp_delay,
1224 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1225 .ramp_reg = BD71837_REG_BUCK4_CTRL,
1226 .ramp_mask = BUCK_RAMPRATE_MASK,
1227 .owner = THIS_MODULE,
1228 .of_parse_cb = buck_set_hw_dvs_levels,
1229 },
1230 .dvs = {
1231 .level_map = ROHM_DVS_LEVEL_RUN,
1232 .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
1233 .run_mask = DVS_BUCK_RUN_MASK,
1234 },
1235 .init = {
1236 .reg = BD71837_REG_BUCK4_CTRL,
1237 .mask = BD718XX_BUCK_SEL,
1238 .val = BD718XX_BUCK_SEL,
1239 },
1240 },
1241 {
1242 .desc = {
1243 .name = "buck5",
1244 .of_match = of_match_ptr("BUCK5"),
1245 .regulators_node = of_match_ptr("regulators"),
1246 .id = BD718XX_BUCK5,
1247 .type = REGULATOR_VOLTAGE,
1248 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
1249 .linear_ranges = bd71837_buck5_volts,
1250 .n_linear_ranges =
1251 ARRAY_SIZE(bd71837_buck5_volts),
1252 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1253 .vsel_mask = BD71837_BUCK5_MASK,
1254 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1255 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
1256 .linear_range_selectors = bd71837_buck5_volt_range_sel,
1257 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1258 .enable_mask = BD718XX_BUCK_EN,
1259 .enable_time = BD71837_BUCK5_STARTUP_TIME,
1260 .owner = THIS_MODULE,
1261 },
1262 .init = {
1263 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1264 .mask = BD718XX_BUCK_SEL,
1265 .val = BD718XX_BUCK_SEL,
1266 },
1267 },
1268 {
1269 .desc = {
1270 .name = "buck6",
1271 .of_match = of_match_ptr("BUCK6"),
1272 .regulators_node = of_match_ptr("regulators"),
1273 .id = BD718XX_BUCK6,
1274 .type = REGULATOR_VOLTAGE,
1275 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
1276 .linear_ranges = bd71837_buck6_volts,
1277 .n_linear_ranges =
1278 ARRAY_SIZE(bd71837_buck6_volts),
1279 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
1280 .vsel_mask = BD71837_BUCK6_MASK,
1281 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1282 .enable_mask = BD718XX_BUCK_EN,
1283 .enable_time = BD71837_BUCK6_STARTUP_TIME,
1284 .owner = THIS_MODULE,
1285 },
1286 .init = {
1287 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1288 .mask = BD718XX_BUCK_SEL,
1289 .val = BD718XX_BUCK_SEL,
1290 },
1291 },
1292 {
1293 .desc = {
1294 .name = "buck7",
1295 .of_match = of_match_ptr("BUCK7"),
1296 .regulators_node = of_match_ptr("regulators"),
1297 .id = BD718XX_BUCK7,
1298 .type = REGULATOR_VOLTAGE,
1299 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
1300 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
1301 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
1302 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
1303 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1304 .enable_mask = BD718XX_BUCK_EN,
1305 .enable_time = BD71837_BUCK7_STARTUP_TIME,
1306 .owner = THIS_MODULE,
1307 },
1308 .init = {
1309 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1310 .mask = BD718XX_BUCK_SEL,
1311 .val = BD718XX_BUCK_SEL,
1312 },
1313 },
1314 {
1315 .desc = {
1316 .name = "buck8",
1317 .of_match = of_match_ptr("BUCK8"),
1318 .regulators_node = of_match_ptr("regulators"),
1319 .id = BD718XX_BUCK8,
1320 .type = REGULATOR_VOLTAGE,
1321 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
1322 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
1323 .n_linear_ranges =
1324 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
1325 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
1326 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
1327 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1328 .enable_mask = BD718XX_BUCK_EN,
1329 .enable_time = BD71837_BUCK8_STARTUP_TIME,
1330 .owner = THIS_MODULE,
1331 },
1332 .init = {
1333 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1334 .mask = BD718XX_BUCK_SEL,
1335 .val = BD718XX_BUCK_SEL,
1336 },
1337 },
1338 {
1339 .desc = {
1340 .name = "ldo1",
1341 .of_match = of_match_ptr("LDO1"),
1342 .regulators_node = of_match_ptr("regulators"),
1343 .id = BD718XX_LDO1,
1344 .type = REGULATOR_VOLTAGE,
1345 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
1346 .linear_ranges = bd718xx_ldo1_volts,
1347 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
1348 .vsel_reg = BD718XX_REG_LDO1_VOLT,
1349 .vsel_mask = BD718XX_LDO1_MASK,
1350 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
1351 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
1352 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
1353 .enable_reg = BD718XX_REG_LDO1_VOLT,
1354 .enable_mask = BD718XX_LDO_EN,
1355 .enable_time = BD71837_LDO1_STARTUP_TIME,
1356 .owner = THIS_MODULE,
1357 },
1358 .init = {
1359 .reg = BD718XX_REG_LDO1_VOLT,
1360 .mask = BD718XX_LDO_SEL,
1361 .val = BD718XX_LDO_SEL,
1362 },
1363 },
1364 {
1365 .desc = {
1366 .name = "ldo2",
1367 .of_match = of_match_ptr("LDO2"),
1368 .regulators_node = of_match_ptr("regulators"),
1369 .id = BD718XX_LDO2,
1370 .type = REGULATOR_VOLTAGE,
1371 .volt_table = &ldo_2_volts[0],
1372 .vsel_reg = BD718XX_REG_LDO2_VOLT,
1373 .vsel_mask = BD718XX_LDO2_MASK,
1374 .n_voltages = ARRAY_SIZE(ldo_2_volts),
1375 .enable_reg = BD718XX_REG_LDO2_VOLT,
1376 .enable_mask = BD718XX_LDO_EN,
1377 .enable_time = BD71837_LDO2_STARTUP_TIME,
1378 .owner = THIS_MODULE,
1379 },
1380 .init = {
1381 .reg = BD718XX_REG_LDO2_VOLT,
1382 .mask = BD718XX_LDO_SEL,
1383 .val = BD718XX_LDO_SEL,
1384 },
1385 },
1386 {
1387 .desc = {
1388 .name = "ldo3",
1389 .of_match = of_match_ptr("LDO3"),
1390 .regulators_node = of_match_ptr("regulators"),
1391 .id = BD718XX_LDO3,
1392 .type = REGULATOR_VOLTAGE,
1393 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1394 .linear_ranges = bd718xx_ldo3_volts,
1395 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1396 .vsel_reg = BD718XX_REG_LDO3_VOLT,
1397 .vsel_mask = BD718XX_LDO3_MASK,
1398 .enable_reg = BD718XX_REG_LDO3_VOLT,
1399 .enable_mask = BD718XX_LDO_EN,
1400 .enable_time = BD71837_LDO3_STARTUP_TIME,
1401 .owner = THIS_MODULE,
1402 },
1403 .init = {
1404 .reg = BD718XX_REG_LDO3_VOLT,
1405 .mask = BD718XX_LDO_SEL,
1406 .val = BD718XX_LDO_SEL,
1407 },
1408 },
1409 {
1410 .desc = {
1411 .name = "ldo4",
1412 .of_match = of_match_ptr("LDO4"),
1413 .regulators_node = of_match_ptr("regulators"),
1414 .id = BD718XX_LDO4,
1415 .type = REGULATOR_VOLTAGE,
1416 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1417 .linear_ranges = bd718xx_ldo4_volts,
1418 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1419 .vsel_reg = BD718XX_REG_LDO4_VOLT,
1420 .vsel_mask = BD718XX_LDO4_MASK,
1421 .enable_reg = BD718XX_REG_LDO4_VOLT,
1422 .enable_mask = BD718XX_LDO_EN,
1423 .enable_time = BD71837_LDO4_STARTUP_TIME,
1424 .owner = THIS_MODULE,
1425 },
1426 .init = {
1427 .reg = BD718XX_REG_LDO4_VOLT,
1428 .mask = BD718XX_LDO_SEL,
1429 .val = BD718XX_LDO_SEL,
1430 },
1431 },
1432 {
1433 .desc = {
1434 .name = "ldo5",
1435 .of_match = of_match_ptr("LDO5"),
1436 .regulators_node = of_match_ptr("regulators"),
1437 .id = BD718XX_LDO5,
1438 .type = REGULATOR_VOLTAGE,
1439 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1440 .linear_ranges = bd71837_ldo5_volts,
1441 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
1442 /* LDO5 is supplied by buck6 */
1443 .supply_name = "buck6",
1444 .vsel_reg = BD718XX_REG_LDO5_VOLT,
1445 .vsel_mask = BD71837_LDO5_MASK,
1446 .enable_reg = BD718XX_REG_LDO5_VOLT,
1447 .enable_mask = BD718XX_LDO_EN,
1448 .enable_time = BD71837_LDO5_STARTUP_TIME,
1449 .owner = THIS_MODULE,
1450 },
1451 .init = {
1452 .reg = BD718XX_REG_LDO5_VOLT,
1453 .mask = BD718XX_LDO_SEL,
1454 .val = BD718XX_LDO_SEL,
1455 },
1456 .additional_inits = bd71837_ldo5_inits,
1457 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1458 },
1459 {
1460 .desc = {
1461 .name = "ldo6",
1462 .of_match = of_match_ptr("LDO6"),
1463 .regulators_node = of_match_ptr("regulators"),
1464 .id = BD718XX_LDO6,
1465 .type = REGULATOR_VOLTAGE,
1466 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1467 .linear_ranges = bd718xx_ldo6_volts,
1468 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1469 /* LDO6 is supplied by buck7 */
1470 .supply_name = "buck7",
1471 .vsel_reg = BD718XX_REG_LDO6_VOLT,
1472 .vsel_mask = BD718XX_LDO6_MASK,
1473 .enable_reg = BD718XX_REG_LDO6_VOLT,
1474 .enable_mask = BD718XX_LDO_EN,
1475 .enable_time = BD71837_LDO6_STARTUP_TIME,
1476 .owner = THIS_MODULE,
1477 },
1478 .init = {
1479 .reg = BD718XX_REG_LDO6_VOLT,
1480 .mask = BD718XX_LDO_SEL,
1481 .val = BD718XX_LDO_SEL,
1482 },
1483 .additional_inits = bd71837_ldo6_inits,
1484 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1485 },
1486 {
1487 .desc = {
1488 .name = "ldo7",
1489 .of_match = of_match_ptr("LDO7"),
1490 .regulators_node = of_match_ptr("regulators"),
1491 .id = BD718XX_LDO7,
1492 .type = REGULATOR_VOLTAGE,
1493 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1494 .linear_ranges = bd71837_ldo7_volts,
1495 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1496 .vsel_reg = BD71837_REG_LDO7_VOLT,
1497 .vsel_mask = BD71837_LDO7_MASK,
1498 .enable_reg = BD71837_REG_LDO7_VOLT,
1499 .enable_mask = BD718XX_LDO_EN,
1500 .enable_time = BD71837_LDO7_STARTUP_TIME,
1501 .owner = THIS_MODULE,
1502 },
1503 .init = {
1504 .reg = BD71837_REG_LDO7_VOLT,
1505 .mask = BD718XX_LDO_SEL,
1506 .val = BD718XX_LDO_SEL,
1507 },
1508 },
1509 };
1510
mark_hw_controlled(struct device * dev,struct device_node * np,struct bd718xx_regulator_data * reg_data,unsigned int num_reg_data,int * info)1511 static void mark_hw_controlled(struct device *dev, struct device_node *np,
1512 struct bd718xx_regulator_data *reg_data,
1513 unsigned int num_reg_data, int *info)
1514 {
1515 int i;
1516
1517 for (i = 1; i <= num_reg_data; i++) {
1518 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
1519 continue;
1520
1521 *info |= 1 << (i - 1);
1522 dev_dbg(dev, "regulator %d runlevel controlled\n", i);
1523 return;
1524 }
1525 dev_warn(dev, "Bad regulator node\n");
1526 }
1527
1528 /*
1529 * Setups where regulator (especially the buck8) output voltage is scaled
1530 * by adding external connection where some other regulator output is connected
1531 * to feedback-pin (over suitable resistors) is getting popular amongst users
1532 * of BD71837. (This allows for example scaling down the buck8 voltages to suit
1533 * lover GPU voltages for projects where buck8 is (ab)used to supply power
1534 * for GPU. Additionally some setups do allow DVS for buck8 but as this do
1535 * produce voltage spikes the HW must be evaluated to be able to survive this
1536 * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1537 * to help you burn your proto board)
1538 *
1539 * So we allow describing this external connection from DT and scale the
1540 * voltages accordingly. This is what the connection should look like:
1541 *
1542 * |------------|
1543 * | buck 8 |-------+----->Vout
1544 * | | |
1545 * |------------| |
1546 * | FB pin |
1547 * | |
1548 * +-------+--R2---+
1549 * |
1550 * R1
1551 * |
1552 * V FB-pull-up
1553 *
1554 * Here the buck output is sifted according to formula:
1555 *
1556 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1557 * Linear_step = step_orig*(R1+R2)/R1
1558 *
1559 * where:
1560 * Vout_o is adjusted voltage output at vsel reg value 0
1561 * Vo is original voltage output at vsel reg value 0
1562 * Vpu is the pull-up voltage V FB-pull-up in the picture
1563 * R1 and R2 are resistor values.
1564 *
1565 * As a real world example for buck8 and a specific GPU:
1566 * VLDO = 1.6V (used as FB-pull-up)
1567 * R1 = 1000ohms
1568 * R2 = 150ohms
1569 * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
1570 * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
1571 */
setup_feedback_loop(struct device * dev,struct device_node * np,struct bd718xx_regulator_data * reg_data,unsigned int num_reg_data,int fb_uv)1572 static int setup_feedback_loop(struct device *dev, struct device_node *np,
1573 struct bd718xx_regulator_data *reg_data,
1574 unsigned int num_reg_data, int fb_uv)
1575 {
1576 int i, r1, r2, ret;
1577
1578 /*
1579 * We do adjust the values in the global desc based on DT settings.
1580 * This may not be best approach as it can cause problems if more than
1581 * one PMIC is controlled from same processor. I don't see such use-case
1582 * for BD718x7 now - so we spare some bits.
1583 *
1584 * If this will point out to be a problem - then we can allocate new
1585 * bd718xx_regulator_data array at probe and just use the global
1586 * array as a template where we copy initial values. Then we can
1587 * use allocated descs for regultor registration and do IC specific
1588 * modifications to this copy while leaving other PMICs untouched. But
1589 * that means allocating new array for each PMIC - and currently I see
1590 * no need for that.
1591 */
1592
1593 for (i = 0; i < num_reg_data; i++) {
1594 struct regulator_desc *desc = ®_data[i].desc;
1595 int j;
1596
1597 if (!of_node_name_eq(np, desc->of_match))
1598 continue;
1599
1600 pr_info("Looking at node '%s'\n", desc->of_match);
1601
1602 /* The feedback loop connection does not make sense for LDOs */
1603 if (desc->id >= BD718XX_LDO1)
1604 return -EINVAL;
1605
1606 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
1607 &r1);
1608 if (ret)
1609 return ret;
1610
1611 if (!r1)
1612 return -EINVAL;
1613
1614 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
1615 &r2);
1616 if (ret)
1617 return ret;
1618
1619 if (desc->n_linear_ranges && desc->linear_ranges) {
1620 struct linear_range *new;
1621
1622 new = devm_kzalloc(dev, desc->n_linear_ranges *
1623 sizeof(struct linear_range),
1624 GFP_KERNEL);
1625 if (!new)
1626 return -ENOMEM;
1627
1628 for (j = 0; j < desc->n_linear_ranges; j++) {
1629 int min = desc->linear_ranges[j].min;
1630 int step = desc->linear_ranges[j].step;
1631
1632 min -= (fb_uv - min)*r2/r1;
1633 step = step * (r1 + r2);
1634 step /= r1;
1635
1636 new[j].min = min;
1637 new[j].step = step;
1638
1639 dev_dbg(dev, "%s: old range min %d, step %d\n",
1640 desc->name, desc->linear_ranges[j].min,
1641 desc->linear_ranges[j].step);
1642 dev_dbg(dev, "new range min %d, step %d\n", min,
1643 step);
1644 }
1645 desc->linear_ranges = new;
1646 }
1647 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
1648 desc->name);
1649
1650 return 0;
1651 }
1652
1653 return -ENODEV;
1654 }
1655
get_special_regulators(struct device * dev,struct bd718xx_regulator_data * reg_data,unsigned int num_reg_data,int * info)1656 static int get_special_regulators(struct device *dev,
1657 struct bd718xx_regulator_data *reg_data,
1658 unsigned int num_reg_data, int *info)
1659 {
1660 int ret;
1661 struct device_node *np;
1662 struct device_node *nproot = dev->of_node;
1663 int uv;
1664
1665 *info = 0;
1666
1667 nproot = of_get_child_by_name(nproot, "regulators");
1668 if (!nproot) {
1669 dev_err(dev, "failed to find regulators node\n");
1670 return -ENODEV;
1671 }
1672 for_each_child_of_node(nproot, np) {
1673 if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
1674 mark_hw_controlled(dev, np, reg_data, num_reg_data,
1675 info);
1676 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
1677 &uv);
1678 if (ret) {
1679 if (ret == -EINVAL)
1680 continue;
1681 else
1682 goto err_out;
1683 }
1684
1685 ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
1686 if (ret)
1687 goto err_out;
1688 }
1689
1690 of_node_put(nproot);
1691 return 0;
1692
1693 err_out:
1694 of_node_put(np);
1695 of_node_put(nproot);
1696
1697 return ret;
1698 }
1699
bd718xx_probe(struct platform_device * pdev)1700 static int bd718xx_probe(struct platform_device *pdev)
1701 {
1702 struct regmap *regmap;
1703 struct regulator_config config = { 0 };
1704 int i, j, err, omit_enable;
1705 bool use_snvs;
1706 struct bd718xx_regulator_data *reg_data;
1707 unsigned int num_reg_data;
1708 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
1709 const struct regulator_ops **swops, **hwops;
1710
1711 regmap = dev_get_regmap(pdev->dev.parent, NULL);
1712 if (!regmap) {
1713 dev_err(&pdev->dev, "No MFD driver data\n");
1714 return -EINVAL;
1715 }
1716
1717 switch (chip) {
1718 case ROHM_CHIP_TYPE_BD71837:
1719 reg_data = bd71837_regulators;
1720 num_reg_data = ARRAY_SIZE(bd71837_regulators);
1721 swops = &bd71837_swcontrol_ops[0];
1722 hwops = &bd71837_hwcontrol_ops[0];
1723 break;
1724 case ROHM_CHIP_TYPE_BD71847:
1725 reg_data = bd71847_regulators;
1726 num_reg_data = ARRAY_SIZE(bd71847_regulators);
1727 swops = &bd71847_swcontrol_ops[0];
1728 hwops = &bd71847_hwcontrol_ops[0];
1729 break;
1730 default:
1731 dev_err(&pdev->dev, "Unsupported chip type\n");
1732 err = -EINVAL;
1733 goto err;
1734 }
1735
1736 /* Register LOCK release */
1737 err = regmap_update_bits(regmap, BD718XX_REG_REGLOCK,
1738 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1739 if (err) {
1740 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1741 goto err;
1742 } else {
1743 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1744 BD718XX_REG_REGLOCK);
1745 }
1746
1747 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1748 "rohm,reset-snvs-powered");
1749
1750 /*
1751 * Change the next stage from poweroff to be READY instead of SNVS
1752 * for all reset types because OTP loading at READY will clear SEL
1753 * bit allowing HW defaults for power rails to be used
1754 */
1755 if (!use_snvs) {
1756 err = regmap_update_bits(regmap, BD718XX_REG_TRANS_COND1,
1757 BD718XX_ON_REQ_POWEROFF_MASK |
1758 BD718XX_SWRESET_POWEROFF_MASK |
1759 BD718XX_WDOG_POWEROFF_MASK |
1760 BD718XX_KEY_L_POWEROFF_MASK,
1761 BD718XX_POWOFF_TO_RDY);
1762 if (err) {
1763 dev_err(&pdev->dev, "Failed to change reset target\n");
1764 goto err;
1765 } else {
1766 dev_dbg(&pdev->dev,
1767 "Changed all resets from SVNS to READY\n");
1768 }
1769 }
1770
1771 config.dev = pdev->dev.parent;
1772 config.regmap = regmap;
1773 /*
1774 * There are cases when we want to leave the enable-control for
1775 * the HW state machine and use this driver only for voltage control.
1776 * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
1777 * in order to set the system to SUSPEND state.
1778 *
1779 * If regulator is taken under SW control the regulator state will not
1780 * be affected by PMIC state machine - Eg. regulator is likely to stay
1781 * on even in SUSPEND
1782 */
1783 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
1784 &omit_enable);
1785 if (err)
1786 return err;
1787
1788 for (i = 0; i < num_reg_data; i++) {
1789
1790 struct regulator_desc *desc;
1791 struct regulator_dev *rdev;
1792 struct bd718xx_regulator_data *r;
1793 int no_enable_control = omit_enable & (1 << i);
1794
1795 r = ®_data[i];
1796 desc = &r->desc;
1797
1798 if (no_enable_control)
1799 desc->ops = hwops[i];
1800 else
1801 desc->ops = swops[i];
1802
1803 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1804 if (IS_ERR(rdev)) {
1805 dev_err(&pdev->dev,
1806 "failed to register %s regulator\n",
1807 desc->name);
1808 err = PTR_ERR(rdev);
1809 goto err;
1810 }
1811
1812 /*
1813 * Regulator register gets the regulator constraints and
1814 * applies them (set_machine_constraints). This should have
1815 * turned the control register(s) to correct values and we
1816 * can now switch the control from PMIC state machine to the
1817 * register interface
1818 *
1819 * At poweroff transition PMIC HW disables EN bit for
1820 * regulators but leaves SEL bit untouched. So if state
1821 * transition from POWEROFF is done to SNVS - then all power
1822 * rails controlled by SW (having SEL bit set) stay disabled
1823 * as EN is cleared. This will result boot failure if any
1824 * crucial systems are powered by these rails. We don't
1825 * enable SW control for crucial regulators if snvs state is
1826 * used
1827 */
1828 if (!no_enable_control && (!use_snvs ||
1829 !rdev->constraints->always_on ||
1830 !rdev->constraints->boot_on)) {
1831 err = regmap_update_bits(regmap, r->init.reg,
1832 r->init.mask, r->init.val);
1833 if (err) {
1834 dev_err(&pdev->dev,
1835 "Failed to take control for (%s)\n",
1836 desc->name);
1837 goto err;
1838 }
1839 }
1840 for (j = 0; j < r->additional_init_amnt; j++) {
1841 err = regmap_update_bits(regmap,
1842 r->additional_inits[j].reg,
1843 r->additional_inits[j].mask,
1844 r->additional_inits[j].val);
1845 if (err) {
1846 dev_err(&pdev->dev,
1847 "Buck (%s) initialization failed\n",
1848 desc->name);
1849 goto err;
1850 }
1851 }
1852 }
1853
1854 err:
1855 return err;
1856 }
1857
1858 static const struct platform_device_id bd718x7_pmic_id[] = {
1859 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1860 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1861 { },
1862 };
1863 MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
1864
1865 static struct platform_driver bd718xx_regulator = {
1866 .driver = {
1867 .name = "bd718xx-pmic",
1868 },
1869 .probe = bd718xx_probe,
1870 .id_table = bd718x7_pmic_id,
1871 };
1872
1873 module_platform_driver(bd718xx_regulator);
1874
1875 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1876 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1877 MODULE_LICENSE("GPL");
1878 MODULE_ALIAS("platform:bd718xx-pmic");
1879