1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 ROHM Semiconductors
3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
5 #include <linux/delay.h>
7 #include <linux/interrupt.h>
8 #include <linux/kernel.h>
9 #include <linux/mfd/rohm-bd718x7.h>
10 #include <linux/module.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>
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
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
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
55 #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
57 #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
58 _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay) \
59 static const struct regulator_ops name = { \
60 .enable = regulator_enable_regmap, \
61 .disable = regulator_disable_regmap, \
62 .is_enabled = regulator_is_enabled_regmap, \
63 .list_voltage = (_list_voltage), \
64 .map_voltage = (_map_voltage), \
65 .set_voltage_sel = (_set_voltage_sel), \
66 .get_voltage_sel = (_get_voltage_sel), \
67 .set_voltage_time_sel = (_set_voltage_time_sel), \
68 .set_ramp_delay = (_set_ramp_delay), \
71 static const struct regulator_ops BD718XX_HWOPNAME(name) = { \
72 .is_enabled = always_enabled_by_hwstate, \
73 .list_voltage = (_list_voltage), \
74 .map_voltage = (_map_voltage), \
75 .set_voltage_sel = (_set_voltage_sel), \
76 .get_voltage_sel = (_get_voltage_sel), \
77 .set_voltage_time_sel = (_set_voltage_time_sel), \
78 .set_ramp_delay = (_set_ramp_delay), \
83 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
84 * 00: 10.00mV/usec 10mV 1uS
85 * 01: 5.00mV/usec 10mV 2uS
86 * 10: 2.50mV/usec 10mV 4uS
87 * 11: 1.25mV/usec 10mV 8uS
89 static const unsigned int bd718xx_ramp_delay[] = { 10000, 5000, 2500, 1250 };
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.
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.
102 static int always_enabled_by_hwstate(struct regulator_dev *rdev)
107 static int never_enabled_by_hwstate(struct regulator_dev *rdev)
112 static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
117 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
121 return !!(BD718XX_BUCK_RUN_ON & val);
124 * On BD71837 (not on BD71847, BD71850, ...)
125 * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
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.
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
136 static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
139 if (rdev->desc->ops->is_enabled(rdev))
142 return regulator_set_voltage_sel_regmap(rdev, sel);
145 static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
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.
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.
166 ret = regmap_update_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
170 "Failed to re-enable voltage monitoring (%d)\n",
175 static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
181 if (rdev->desc->ops->is_enabled(rdev)) {
184 now = rdev->desc->ops->get_voltage_sel(rdev);
188 now = rdev->desc->ops->list_voltage(rdev, now);
192 new = rdev->desc->ops->list_voltage(rdev, sel);
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.
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
211 int ldo_offset = rdev->desc->id - BD718XX_LDO1;
213 *mask = BD718XX_LDO1_VRMON80 << ldo_offset;
214 ret = regmap_update_bits(rdev->regmap,
215 BD718XX_REG_MVRFLTMASK2,
219 "Failed to stop voltage monitoring\n");
228 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
234 ret = voltage_change_prepare(rdev, sel, &mask);
238 ret = regulator_set_voltage_sel_regmap(rdev, sel);
239 voltage_change_done(rdev, sel, &mask);
244 static int bd718xx_set_voltage_sel_pickable_restricted(
245 struct regulator_dev *rdev, unsigned int sel)
250 ret = voltage_change_prepare(rdev, sel, &mask);
254 ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
255 voltage_change_done(rdev, sel, &mask);
260 static int bd71837_set_voltage_sel_pickable_restricted(
261 struct regulator_dev *rdev, unsigned int sel)
263 if (rdev->desc->ops->is_enabled(rdev))
266 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
270 * OPS common for BD71847 and BD71850
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);
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,
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,
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);
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);
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);
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,
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,
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);
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);
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);
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);
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,
336 BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
337 regulator_map_voltage_ascend, bd71837_set_voltage_sel_restricted,
338 regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
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.
345 static const struct regulator_ops bd71837_buck34_ops_hwctrl = {
346 .is_enabled = bd71837_get_buck34_enable_hwctrl,
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,
351 .set_ramp_delay = regulator_set_ramp_delay_regmap,
355 * OPS for all of the ICs - BD718(37/47/50)
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 */ regulator_set_ramp_delay_regmap);
363 * BD71837 BUCK1/2/3/4
365 * 0.70 to 1.30V (10mV step)
367 static const struct linear_range bd718xx_dvs_buck_volts[] = {
368 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
369 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
374 * 0.7V to 1.35V (range 0)
376 * 0.675 to 1.325 (range 1)
378 static const struct linear_range bd71837_buck5_volts[] = {
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),
390 * Range selector for first 3 linear ranges is 0x0
391 * and 0x1 for last 3 ranges.
393 static const unsigned int bd71837_buck5_volt_range_sel[] = {
394 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
400 static const struct linear_range bd71847_buck3_volts[] = {
401 /* Ranges when VOLT_SEL bits are 00 */
402 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
403 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
404 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
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),
413 static const unsigned int bd71847_buck3_volt_range_sel[] = {
414 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
417 static const struct linear_range bd71847_buck4_volts[] = {
418 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
419 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
422 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
426 * 3.0V to 3.3V (step 100mV)
428 static const struct linear_range bd71837_buck6_volts[] = {
429 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
438 * 011 = 1.8V (Initial)
444 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
445 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
450 * 0.8V to 1.40V (step 10mV)
452 static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
453 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
458 * 3.0 to 3.3V (100mV step)
460 static const struct linear_range bd718xx_ldo1_volts[] = {
461 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
462 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
465 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
471 static const unsigned int ldo_2_volts[] = {
477 * 1.8 to 3.3V (100mV step)
479 static const struct linear_range bd718xx_ldo3_volts[] = {
480 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
485 * 0.9 to 1.8V (100mV step)
487 static const struct linear_range bd718xx_ldo4_volts[] = {
488 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
493 * 1.8 to 3.3V (100mV step)
495 static const struct linear_range bd71837_ldo5_volts[] = {
496 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
501 * 1.8 to 3.3V (100mV step)
503 static const struct linear_range bd71847_ldo5_volts[] = {
504 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
505 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
508 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
512 * 0.9 to 1.8V (100mV step)
514 static const struct linear_range bd718xx_ldo6_volts[] = {
515 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
520 * 1.8 to 3.3V (100mV step)
522 static const struct linear_range bd71837_ldo7_volts[] = {
523 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
531 struct bd718xx_regulator_data {
532 struct regulator_desc desc;
533 const struct rohm_dvs_config dvs;
534 const struct reg_init init;
535 const struct reg_init *additional_inits;
536 int additional_init_amnt;
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
549 static const struct reg_init bd71837_ldo5_inits[] = {
551 .reg = BD718XX_REG_MVRFLTMASK2,
552 .mask = BD718XX_LDO5_VRMON80,
553 .val = BD718XX_LDO5_VRMON80,
557 static const struct reg_init bd71837_ldo6_inits[] = {
559 .reg = BD718XX_REG_MVRFLTMASK2,
560 .mask = BD718XX_LDO6_VRMON80,
561 .val = BD718XX_LDO6_VRMON80,
565 static int buck_set_hw_dvs_levels(struct device_node *np,
566 const struct regulator_desc *desc,
567 struct regulator_config *cfg)
569 struct bd718xx_regulator_data *data;
571 data = container_of(desc, struct bd718xx_regulator_data, desc);
573 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
576 static const struct regulator_ops *bd71847_swcontrol_ops[] = {
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,
585 static const struct regulator_ops *bd71847_hwcontrol_ops[] = {
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),
600 static struct bd718xx_regulator_data bd71847_regulators[] = {
604 .of_match = of_match_ptr("BUCK1"),
605 .regulators_node = of_match_ptr("regulators"),
607 .type = REGULATOR_VOLTAGE,
608 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
609 .linear_ranges = bd718xx_dvs_buck_volts,
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 .enable_time = BD71847_BUCK1_STARTUP_TIME,
617 .owner = THIS_MODULE,
618 .ramp_delay_table = bd718xx_ramp_delay,
619 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
620 .ramp_reg = BD718XX_REG_BUCK1_CTRL,
621 .ramp_mask = BUCK_RAMPRATE_MASK,
622 .of_parse_cb = buck_set_hw_dvs_levels,
625 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
626 ROHM_DVS_LEVEL_SUSPEND,
627 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
628 .run_mask = DVS_BUCK_RUN_MASK,
629 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
630 .idle_mask = DVS_BUCK_RUN_MASK,
631 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
632 .suspend_mask = DVS_BUCK_RUN_MASK,
635 .reg = BD718XX_REG_BUCK1_CTRL,
636 .mask = BD718XX_BUCK_SEL,
637 .val = BD718XX_BUCK_SEL,
643 .of_match = of_match_ptr("BUCK2"),
644 .regulators_node = of_match_ptr("regulators"),
646 .type = REGULATOR_VOLTAGE,
647 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
648 .linear_ranges = bd718xx_dvs_buck_volts,
649 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
650 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
651 .vsel_mask = DVS_BUCK_RUN_MASK,
652 .enable_reg = BD718XX_REG_BUCK2_CTRL,
653 .enable_mask = BD718XX_BUCK_EN,
654 .enable_time = BD71847_BUCK2_STARTUP_TIME,
655 .ramp_delay_table = bd718xx_ramp_delay,
656 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
657 .ramp_reg = BD718XX_REG_BUCK2_CTRL,
658 .ramp_mask = BUCK_RAMPRATE_MASK,
659 .owner = THIS_MODULE,
660 .of_parse_cb = buck_set_hw_dvs_levels,
663 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
664 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
665 .run_mask = DVS_BUCK_RUN_MASK,
666 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
667 .idle_mask = DVS_BUCK_RUN_MASK,
670 .reg = BD718XX_REG_BUCK2_CTRL,
671 .mask = BD718XX_BUCK_SEL,
672 .val = BD718XX_BUCK_SEL,
678 .of_match = of_match_ptr("BUCK3"),
679 .regulators_node = of_match_ptr("regulators"),
681 .type = REGULATOR_VOLTAGE,
682 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
683 .linear_ranges = bd71847_buck3_volts,
685 ARRAY_SIZE(bd71847_buck3_volts),
686 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
687 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
688 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
689 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
690 .linear_range_selectors = bd71847_buck3_volt_range_sel,
691 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
692 .enable_mask = BD718XX_BUCK_EN,
693 .enable_time = BD71847_BUCK3_STARTUP_TIME,
694 .owner = THIS_MODULE,
697 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
698 .mask = BD718XX_BUCK_SEL,
699 .val = BD718XX_BUCK_SEL,
705 .of_match = of_match_ptr("BUCK4"),
706 .regulators_node = of_match_ptr("regulators"),
708 .type = REGULATOR_VOLTAGE,
709 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
710 .linear_ranges = bd71847_buck4_volts,
712 ARRAY_SIZE(bd71847_buck4_volts),
713 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
714 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
715 .vsel_mask = BD71847_BUCK4_MASK,
716 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
717 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
718 .linear_range_selectors = bd71847_buck4_volt_range_sel,
719 .enable_mask = BD718XX_BUCK_EN,
720 .enable_time = BD71847_BUCK4_STARTUP_TIME,
721 .owner = THIS_MODULE,
724 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
725 .mask = BD718XX_BUCK_SEL,
726 .val = BD718XX_BUCK_SEL,
732 .of_match = of_match_ptr("BUCK5"),
733 .regulators_node = of_match_ptr("regulators"),
735 .type = REGULATOR_VOLTAGE,
736 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
737 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
738 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
739 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
740 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
741 .enable_mask = BD718XX_BUCK_EN,
742 .enable_time = BD71847_BUCK5_STARTUP_TIME,
743 .owner = THIS_MODULE,
746 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
747 .mask = BD718XX_BUCK_SEL,
748 .val = BD718XX_BUCK_SEL,
754 .of_match = of_match_ptr("BUCK6"),
755 .regulators_node = of_match_ptr("regulators"),
757 .type = REGULATOR_VOLTAGE,
758 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
759 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
761 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
762 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
763 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
764 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
765 .enable_mask = BD718XX_BUCK_EN,
766 .enable_time = BD71847_BUCK6_STARTUP_TIME,
767 .owner = THIS_MODULE,
770 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
771 .mask = BD718XX_BUCK_SEL,
772 .val = BD718XX_BUCK_SEL,
778 .of_match = of_match_ptr("LDO1"),
779 .regulators_node = of_match_ptr("regulators"),
781 .type = REGULATOR_VOLTAGE,
782 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
783 .linear_ranges = bd718xx_ldo1_volts,
784 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
785 .vsel_reg = BD718XX_REG_LDO1_VOLT,
786 .vsel_mask = BD718XX_LDO1_MASK,
787 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
788 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
789 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
790 .enable_reg = BD718XX_REG_LDO1_VOLT,
791 .enable_mask = BD718XX_LDO_EN,
792 .enable_time = BD71847_LDO1_STARTUP_TIME,
793 .owner = THIS_MODULE,
796 .reg = BD718XX_REG_LDO1_VOLT,
797 .mask = BD718XX_LDO_SEL,
798 .val = BD718XX_LDO_SEL,
804 .of_match = of_match_ptr("LDO2"),
805 .regulators_node = of_match_ptr("regulators"),
807 .type = REGULATOR_VOLTAGE,
808 .volt_table = &ldo_2_volts[0],
809 .vsel_reg = BD718XX_REG_LDO2_VOLT,
810 .vsel_mask = BD718XX_LDO2_MASK,
811 .n_voltages = ARRAY_SIZE(ldo_2_volts),
812 .enable_reg = BD718XX_REG_LDO2_VOLT,
813 .enable_mask = BD718XX_LDO_EN,
814 .enable_time = BD71847_LDO2_STARTUP_TIME,
815 .owner = THIS_MODULE,
818 .reg = BD718XX_REG_LDO2_VOLT,
819 .mask = BD718XX_LDO_SEL,
820 .val = BD718XX_LDO_SEL,
826 .of_match = of_match_ptr("LDO3"),
827 .regulators_node = of_match_ptr("regulators"),
829 .type = REGULATOR_VOLTAGE,
830 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
831 .linear_ranges = bd718xx_ldo3_volts,
832 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
833 .vsel_reg = BD718XX_REG_LDO3_VOLT,
834 .vsel_mask = BD718XX_LDO3_MASK,
835 .enable_reg = BD718XX_REG_LDO3_VOLT,
836 .enable_mask = BD718XX_LDO_EN,
837 .enable_time = BD71847_LDO3_STARTUP_TIME,
838 .owner = THIS_MODULE,
841 .reg = BD718XX_REG_LDO3_VOLT,
842 .mask = BD718XX_LDO_SEL,
843 .val = BD718XX_LDO_SEL,
849 .of_match = of_match_ptr("LDO4"),
850 .regulators_node = of_match_ptr("regulators"),
852 .type = REGULATOR_VOLTAGE,
853 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
854 .linear_ranges = bd718xx_ldo4_volts,
855 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
856 .vsel_reg = BD718XX_REG_LDO4_VOLT,
857 .vsel_mask = BD718XX_LDO4_MASK,
858 .enable_reg = BD718XX_REG_LDO4_VOLT,
859 .enable_mask = BD718XX_LDO_EN,
860 .enable_time = BD71847_LDO4_STARTUP_TIME,
861 .owner = THIS_MODULE,
864 .reg = BD718XX_REG_LDO4_VOLT,
865 .mask = BD718XX_LDO_SEL,
866 .val = BD718XX_LDO_SEL,
872 .of_match = of_match_ptr("LDO5"),
873 .regulators_node = of_match_ptr("regulators"),
875 .type = REGULATOR_VOLTAGE,
876 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
877 .linear_ranges = bd71847_ldo5_volts,
878 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
879 .vsel_reg = BD718XX_REG_LDO5_VOLT,
880 .vsel_mask = BD71847_LDO5_MASK,
881 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
882 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
883 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
884 .enable_reg = BD718XX_REG_LDO5_VOLT,
885 .enable_mask = BD718XX_LDO_EN,
886 .enable_time = BD71847_LDO5_STARTUP_TIME,
887 .owner = THIS_MODULE,
890 .reg = BD718XX_REG_LDO5_VOLT,
891 .mask = BD718XX_LDO_SEL,
892 .val = BD718XX_LDO_SEL,
898 .of_match = of_match_ptr("LDO6"),
899 .regulators_node = of_match_ptr("regulators"),
901 .type = REGULATOR_VOLTAGE,
902 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
903 .linear_ranges = bd718xx_ldo6_volts,
904 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
905 /* LDO6 is supplied by buck5 */
906 .supply_name = "buck5",
907 .vsel_reg = BD718XX_REG_LDO6_VOLT,
908 .vsel_mask = BD718XX_LDO6_MASK,
909 .enable_reg = BD718XX_REG_LDO6_VOLT,
910 .enable_mask = BD718XX_LDO_EN,
911 .enable_time = BD71847_LDO6_STARTUP_TIME,
912 .owner = THIS_MODULE,
915 .reg = BD718XX_REG_LDO6_VOLT,
916 .mask = BD718XX_LDO_SEL,
917 .val = BD718XX_LDO_SEL,
922 static const struct regulator_ops *bd71837_swcontrol_ops[] = {
923 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
924 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
925 &bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
926 &bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
927 &bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
928 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
929 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
930 &bd71837_ldo_regulator_ops,
933 static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
934 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
935 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
936 &bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
937 &BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
938 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
939 &BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
940 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
941 &BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
942 &BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
943 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
944 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
945 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
946 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
947 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
950 static struct bd718xx_regulator_data bd71837_regulators[] = {
954 .of_match = of_match_ptr("BUCK1"),
955 .regulators_node = of_match_ptr("regulators"),
957 .type = REGULATOR_VOLTAGE,
958 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
959 .linear_ranges = bd718xx_dvs_buck_volts,
960 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
961 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
962 .vsel_mask = DVS_BUCK_RUN_MASK,
963 .enable_reg = BD718XX_REG_BUCK1_CTRL,
964 .enable_mask = BD718XX_BUCK_EN,
965 .enable_time = BD71837_BUCK1_STARTUP_TIME,
966 .ramp_delay_table = bd718xx_ramp_delay,
967 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
968 .ramp_reg = BD718XX_REG_BUCK1_CTRL,
969 .ramp_mask = BUCK_RAMPRATE_MASK,
970 .owner = THIS_MODULE,
971 .of_parse_cb = buck_set_hw_dvs_levels,
974 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
975 ROHM_DVS_LEVEL_SUSPEND,
976 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
977 .run_mask = DVS_BUCK_RUN_MASK,
978 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
979 .idle_mask = DVS_BUCK_RUN_MASK,
980 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
981 .suspend_mask = DVS_BUCK_RUN_MASK,
984 .reg = BD718XX_REG_BUCK1_CTRL,
985 .mask = BD718XX_BUCK_SEL,
986 .val = BD718XX_BUCK_SEL,
992 .of_match = of_match_ptr("BUCK2"),
993 .regulators_node = of_match_ptr("regulators"),
995 .type = REGULATOR_VOLTAGE,
996 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
997 .linear_ranges = bd718xx_dvs_buck_volts,
998 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
999 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
1000 .vsel_mask = DVS_BUCK_RUN_MASK,
1001 .enable_reg = BD718XX_REG_BUCK2_CTRL,
1002 .enable_mask = BD718XX_BUCK_EN,
1003 .enable_time = BD71837_BUCK2_STARTUP_TIME,
1004 .ramp_delay_table = bd718xx_ramp_delay,
1005 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1006 .ramp_reg = BD718XX_REG_BUCK2_CTRL,
1007 .ramp_mask = BUCK_RAMPRATE_MASK,
1008 .owner = THIS_MODULE,
1009 .of_parse_cb = buck_set_hw_dvs_levels,
1012 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
1013 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
1014 .run_mask = DVS_BUCK_RUN_MASK,
1015 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
1016 .idle_mask = DVS_BUCK_RUN_MASK,
1019 .reg = BD718XX_REG_BUCK2_CTRL,
1020 .mask = BD718XX_BUCK_SEL,
1021 .val = BD718XX_BUCK_SEL,
1027 .of_match = of_match_ptr("BUCK3"),
1028 .regulators_node = of_match_ptr("regulators"),
1029 .id = BD718XX_BUCK3,
1030 .type = REGULATOR_VOLTAGE,
1031 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1032 .linear_ranges = bd718xx_dvs_buck_volts,
1033 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1034 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
1035 .vsel_mask = DVS_BUCK_RUN_MASK,
1036 .enable_reg = BD71837_REG_BUCK3_CTRL,
1037 .enable_mask = BD718XX_BUCK_EN,
1038 .enable_time = BD71837_BUCK3_STARTUP_TIME,
1039 .ramp_delay_table = bd718xx_ramp_delay,
1040 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1041 .ramp_reg = BD71837_REG_BUCK3_CTRL,
1042 .ramp_mask = BUCK_RAMPRATE_MASK,
1043 .owner = THIS_MODULE,
1044 .of_parse_cb = buck_set_hw_dvs_levels,
1047 .level_map = ROHM_DVS_LEVEL_RUN,
1048 .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
1049 .run_mask = DVS_BUCK_RUN_MASK,
1052 .reg = BD71837_REG_BUCK3_CTRL,
1053 .mask = BD718XX_BUCK_SEL,
1054 .val = BD718XX_BUCK_SEL,
1060 .of_match = of_match_ptr("BUCK4"),
1061 .regulators_node = of_match_ptr("regulators"),
1062 .id = BD718XX_BUCK4,
1063 .type = REGULATOR_VOLTAGE,
1064 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1065 .linear_ranges = bd718xx_dvs_buck_volts,
1066 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1067 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
1068 .vsel_mask = DVS_BUCK_RUN_MASK,
1069 .enable_reg = BD71837_REG_BUCK4_CTRL,
1070 .enable_mask = BD718XX_BUCK_EN,
1071 .enable_time = BD71837_BUCK4_STARTUP_TIME,
1072 .ramp_delay_table = bd718xx_ramp_delay,
1073 .n_ramp_values = ARRAY_SIZE(bd718xx_ramp_delay),
1074 .ramp_reg = BD71837_REG_BUCK4_CTRL,
1075 .ramp_mask = BUCK_RAMPRATE_MASK,
1076 .owner = THIS_MODULE,
1077 .of_parse_cb = buck_set_hw_dvs_levels,
1080 .level_map = ROHM_DVS_LEVEL_RUN,
1081 .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
1082 .run_mask = DVS_BUCK_RUN_MASK,
1085 .reg = BD71837_REG_BUCK4_CTRL,
1086 .mask = BD718XX_BUCK_SEL,
1087 .val = BD718XX_BUCK_SEL,
1093 .of_match = of_match_ptr("BUCK5"),
1094 .regulators_node = of_match_ptr("regulators"),
1095 .id = BD718XX_BUCK5,
1096 .type = REGULATOR_VOLTAGE,
1097 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
1098 .linear_ranges = bd71837_buck5_volts,
1100 ARRAY_SIZE(bd71837_buck5_volts),
1101 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1102 .vsel_mask = BD71837_BUCK5_MASK,
1103 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1104 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
1105 .linear_range_selectors = bd71837_buck5_volt_range_sel,
1106 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1107 .enable_mask = BD718XX_BUCK_EN,
1108 .enable_time = BD71837_BUCK5_STARTUP_TIME,
1109 .owner = THIS_MODULE,
1112 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1113 .mask = BD718XX_BUCK_SEL,
1114 .val = BD718XX_BUCK_SEL,
1120 .of_match = of_match_ptr("BUCK6"),
1121 .regulators_node = of_match_ptr("regulators"),
1122 .id = BD718XX_BUCK6,
1123 .type = REGULATOR_VOLTAGE,
1124 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
1125 .linear_ranges = bd71837_buck6_volts,
1127 ARRAY_SIZE(bd71837_buck6_volts),
1128 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
1129 .vsel_mask = BD71837_BUCK6_MASK,
1130 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1131 .enable_mask = BD718XX_BUCK_EN,
1132 .enable_time = BD71837_BUCK6_STARTUP_TIME,
1133 .owner = THIS_MODULE,
1136 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1137 .mask = BD718XX_BUCK_SEL,
1138 .val = BD718XX_BUCK_SEL,
1144 .of_match = of_match_ptr("BUCK7"),
1145 .regulators_node = of_match_ptr("regulators"),
1146 .id = BD718XX_BUCK7,
1147 .type = REGULATOR_VOLTAGE,
1148 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
1149 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
1150 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
1151 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
1152 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1153 .enable_mask = BD718XX_BUCK_EN,
1154 .enable_time = BD71837_BUCK7_STARTUP_TIME,
1155 .owner = THIS_MODULE,
1158 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1159 .mask = BD718XX_BUCK_SEL,
1160 .val = BD718XX_BUCK_SEL,
1166 .of_match = of_match_ptr("BUCK8"),
1167 .regulators_node = of_match_ptr("regulators"),
1168 .id = BD718XX_BUCK8,
1169 .type = REGULATOR_VOLTAGE,
1170 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
1171 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
1173 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
1174 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
1175 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
1176 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1177 .enable_mask = BD718XX_BUCK_EN,
1178 .enable_time = BD71837_BUCK8_STARTUP_TIME,
1179 .owner = THIS_MODULE,
1182 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1183 .mask = BD718XX_BUCK_SEL,
1184 .val = BD718XX_BUCK_SEL,
1190 .of_match = of_match_ptr("LDO1"),
1191 .regulators_node = of_match_ptr("regulators"),
1193 .type = REGULATOR_VOLTAGE,
1194 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
1195 .linear_ranges = bd718xx_ldo1_volts,
1196 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
1197 .vsel_reg = BD718XX_REG_LDO1_VOLT,
1198 .vsel_mask = BD718XX_LDO1_MASK,
1199 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
1200 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
1201 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
1202 .enable_reg = BD718XX_REG_LDO1_VOLT,
1203 .enable_mask = BD718XX_LDO_EN,
1204 .enable_time = BD71837_LDO1_STARTUP_TIME,
1205 .owner = THIS_MODULE,
1208 .reg = BD718XX_REG_LDO1_VOLT,
1209 .mask = BD718XX_LDO_SEL,
1210 .val = BD718XX_LDO_SEL,
1216 .of_match = of_match_ptr("LDO2"),
1217 .regulators_node = of_match_ptr("regulators"),
1219 .type = REGULATOR_VOLTAGE,
1220 .volt_table = &ldo_2_volts[0],
1221 .vsel_reg = BD718XX_REG_LDO2_VOLT,
1222 .vsel_mask = BD718XX_LDO2_MASK,
1223 .n_voltages = ARRAY_SIZE(ldo_2_volts),
1224 .enable_reg = BD718XX_REG_LDO2_VOLT,
1225 .enable_mask = BD718XX_LDO_EN,
1226 .enable_time = BD71837_LDO2_STARTUP_TIME,
1227 .owner = THIS_MODULE,
1230 .reg = BD718XX_REG_LDO2_VOLT,
1231 .mask = BD718XX_LDO_SEL,
1232 .val = BD718XX_LDO_SEL,
1238 .of_match = of_match_ptr("LDO3"),
1239 .regulators_node = of_match_ptr("regulators"),
1241 .type = REGULATOR_VOLTAGE,
1242 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1243 .linear_ranges = bd718xx_ldo3_volts,
1244 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1245 .vsel_reg = BD718XX_REG_LDO3_VOLT,
1246 .vsel_mask = BD718XX_LDO3_MASK,
1247 .enable_reg = BD718XX_REG_LDO3_VOLT,
1248 .enable_mask = BD718XX_LDO_EN,
1249 .enable_time = BD71837_LDO3_STARTUP_TIME,
1250 .owner = THIS_MODULE,
1253 .reg = BD718XX_REG_LDO3_VOLT,
1254 .mask = BD718XX_LDO_SEL,
1255 .val = BD718XX_LDO_SEL,
1261 .of_match = of_match_ptr("LDO4"),
1262 .regulators_node = of_match_ptr("regulators"),
1264 .type = REGULATOR_VOLTAGE,
1265 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1266 .linear_ranges = bd718xx_ldo4_volts,
1267 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1268 .vsel_reg = BD718XX_REG_LDO4_VOLT,
1269 .vsel_mask = BD718XX_LDO4_MASK,
1270 .enable_reg = BD718XX_REG_LDO4_VOLT,
1271 .enable_mask = BD718XX_LDO_EN,
1272 .enable_time = BD71837_LDO4_STARTUP_TIME,
1273 .owner = THIS_MODULE,
1276 .reg = BD718XX_REG_LDO4_VOLT,
1277 .mask = BD718XX_LDO_SEL,
1278 .val = BD718XX_LDO_SEL,
1284 .of_match = of_match_ptr("LDO5"),
1285 .regulators_node = of_match_ptr("regulators"),
1287 .type = REGULATOR_VOLTAGE,
1288 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1289 .linear_ranges = bd71837_ldo5_volts,
1290 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
1291 /* LDO5 is supplied by buck6 */
1292 .supply_name = "buck6",
1293 .vsel_reg = BD718XX_REG_LDO5_VOLT,
1294 .vsel_mask = BD71837_LDO5_MASK,
1295 .enable_reg = BD718XX_REG_LDO5_VOLT,
1296 .enable_mask = BD718XX_LDO_EN,
1297 .enable_time = BD71837_LDO5_STARTUP_TIME,
1298 .owner = THIS_MODULE,
1301 .reg = BD718XX_REG_LDO5_VOLT,
1302 .mask = BD718XX_LDO_SEL,
1303 .val = BD718XX_LDO_SEL,
1305 .additional_inits = bd71837_ldo5_inits,
1306 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1311 .of_match = of_match_ptr("LDO6"),
1312 .regulators_node = of_match_ptr("regulators"),
1314 .type = REGULATOR_VOLTAGE,
1315 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1316 .linear_ranges = bd718xx_ldo6_volts,
1317 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1318 /* LDO6 is supplied by buck7 */
1319 .supply_name = "buck7",
1320 .vsel_reg = BD718XX_REG_LDO6_VOLT,
1321 .vsel_mask = BD718XX_LDO6_MASK,
1322 .enable_reg = BD718XX_REG_LDO6_VOLT,
1323 .enable_mask = BD718XX_LDO_EN,
1324 .enable_time = BD71837_LDO6_STARTUP_TIME,
1325 .owner = THIS_MODULE,
1328 .reg = BD718XX_REG_LDO6_VOLT,
1329 .mask = BD718XX_LDO_SEL,
1330 .val = BD718XX_LDO_SEL,
1332 .additional_inits = bd71837_ldo6_inits,
1333 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1338 .of_match = of_match_ptr("LDO7"),
1339 .regulators_node = of_match_ptr("regulators"),
1341 .type = REGULATOR_VOLTAGE,
1342 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1343 .linear_ranges = bd71837_ldo7_volts,
1344 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1345 .vsel_reg = BD71837_REG_LDO7_VOLT,
1346 .vsel_mask = BD71837_LDO7_MASK,
1347 .enable_reg = BD71837_REG_LDO7_VOLT,
1348 .enable_mask = BD718XX_LDO_EN,
1349 .enable_time = BD71837_LDO7_STARTUP_TIME,
1350 .owner = THIS_MODULE,
1353 .reg = BD71837_REG_LDO7_VOLT,
1354 .mask = BD718XX_LDO_SEL,
1355 .val = BD718XX_LDO_SEL,
1360 static void mark_hw_controlled(struct device *dev, struct device_node *np,
1361 struct bd718xx_regulator_data *reg_data,
1362 unsigned int num_reg_data, int *info)
1366 for (i = 1; i <= num_reg_data; i++) {
1367 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
1370 *info |= 1 << (i - 1);
1371 dev_dbg(dev, "regulator %d runlevel controlled\n", i);
1374 dev_warn(dev, "Bad regulator node\n");
1378 * Setups where regulator (especially the buck8) output voltage is scaled
1379 * by adding external connection where some other regulator output is connected
1380 * to feedback-pin (over suitable resistors) is getting popular amongst users
1381 * of BD71837. (This allows for example scaling down the buck8 voltages to suit
1382 * lover GPU voltages for projects where buck8 is (ab)used to supply power
1383 * for GPU. Additionally some setups do allow DVS for buck8 but as this do
1384 * produce voltage spikes the HW must be evaluated to be able to survive this
1385 * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1386 * to help you burn your proto board)
1388 * So we allow describing this external connection from DT and scale the
1389 * voltages accordingly. This is what the connection should look like:
1392 * | buck 8 |-------+----->Vout
1403 * Here the buck output is sifted according to formula:
1405 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1406 * Linear_step = step_orig*(R1+R2)/R1
1409 * Vout_o is adjusted voltage output at vsel reg value 0
1410 * Vo is original voltage output at vsel reg value 0
1411 * Vpu is the pull-up voltage V FB-pull-up in the picture
1412 * R1 and R2 are resistor values.
1414 * As a real world example for buck8 and a specific GPU:
1415 * VLDO = 1.6V (used as FB-pull-up)
1418 * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
1419 * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
1421 static int setup_feedback_loop(struct device *dev, struct device_node *np,
1422 struct bd718xx_regulator_data *reg_data,
1423 unsigned int num_reg_data, int fb_uv)
1428 * We do adjust the values in the global desc based on DT settings.
1429 * This may not be best approach as it can cause problems if more than
1430 * one PMIC is controlled from same processor. I don't see such use-case
1431 * for BD718x7 now - so we spare some bits.
1433 * If this will point out to be a problem - then we can allocate new
1434 * bd718xx_regulator_data array at probe and just use the global
1435 * array as a template where we copy initial values. Then we can
1436 * use allocated descs for regultor registration and do IC specific
1437 * modifications to this copy while leaving other PMICs untouched. But
1438 * that means allocating new array for each PMIC - and currently I see
1442 for (i = 0; i < num_reg_data; i++) {
1443 struct regulator_desc *desc = ®_data[i].desc;
1446 if (!of_node_name_eq(np, desc->of_match))
1449 pr_info("Looking at node '%s'\n", desc->of_match);
1451 /* The feedback loop connection does not make sense for LDOs */
1452 if (desc->id >= BD718XX_LDO1)
1455 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
1463 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
1468 if (desc->n_linear_ranges && desc->linear_ranges) {
1469 struct linear_range *new;
1471 new = devm_kzalloc(dev, desc->n_linear_ranges *
1472 sizeof(struct linear_range),
1477 for (j = 0; j < desc->n_linear_ranges; j++) {
1478 int min = desc->linear_ranges[j].min;
1479 int step = desc->linear_ranges[j].step;
1481 min -= (fb_uv - min)*r2/r1;
1482 step = step * (r1 + r2);
1488 dev_dbg(dev, "%s: old range min %d, step %d\n",
1489 desc->name, desc->linear_ranges[j].min,
1490 desc->linear_ranges[j].step);
1491 dev_dbg(dev, "new range min %d, step %d\n", min,
1494 desc->linear_ranges = new;
1496 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
1505 static int get_special_regulators(struct device *dev,
1506 struct bd718xx_regulator_data *reg_data,
1507 unsigned int num_reg_data, int *info)
1510 struct device_node *np;
1511 struct device_node *nproot = dev->of_node;
1516 nproot = of_get_child_by_name(nproot, "regulators");
1518 dev_err(dev, "failed to find regulators node\n");
1521 for_each_child_of_node(nproot, np) {
1522 if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
1523 mark_hw_controlled(dev, np, reg_data, num_reg_data,
1525 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
1534 ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
1539 of_node_put(nproot);
1544 of_node_put(nproot);
1549 static int bd718xx_probe(struct platform_device *pdev)
1551 struct regmap *regmap;
1552 struct regulator_config config = { 0 };
1553 int i, j, err, omit_enable;
1555 struct bd718xx_regulator_data *reg_data;
1556 unsigned int num_reg_data;
1557 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
1558 const struct regulator_ops **swops, **hwops;
1560 regmap = dev_get_regmap(pdev->dev.parent, NULL);
1562 dev_err(&pdev->dev, "No MFD driver data\n");
1567 case ROHM_CHIP_TYPE_BD71837:
1568 reg_data = bd71837_regulators;
1569 num_reg_data = ARRAY_SIZE(bd71837_regulators);
1570 swops = &bd71837_swcontrol_ops[0];
1571 hwops = &bd71837_hwcontrol_ops[0];
1573 case ROHM_CHIP_TYPE_BD71847:
1574 reg_data = bd71847_regulators;
1575 num_reg_data = ARRAY_SIZE(bd71847_regulators);
1576 swops = &bd71847_swcontrol_ops[0];
1577 hwops = &bd71847_hwcontrol_ops[0];
1580 dev_err(&pdev->dev, "Unsupported chip type\n");
1585 /* Register LOCK release */
1586 err = regmap_update_bits(regmap, BD718XX_REG_REGLOCK,
1587 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1589 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1592 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1593 BD718XX_REG_REGLOCK);
1596 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1597 "rohm,reset-snvs-powered");
1600 * Change the next stage from poweroff to be READY instead of SNVS
1601 * for all reset types because OTP loading at READY will clear SEL
1602 * bit allowing HW defaults for power rails to be used
1605 err = regmap_update_bits(regmap, BD718XX_REG_TRANS_COND1,
1606 BD718XX_ON_REQ_POWEROFF_MASK |
1607 BD718XX_SWRESET_POWEROFF_MASK |
1608 BD718XX_WDOG_POWEROFF_MASK |
1609 BD718XX_KEY_L_POWEROFF_MASK,
1610 BD718XX_POWOFF_TO_RDY);
1612 dev_err(&pdev->dev, "Failed to change reset target\n");
1616 "Changed all resets from SVNS to READY\n");
1620 config.dev = pdev->dev.parent;
1621 config.regmap = regmap;
1623 * There are cases when we want to leave the enable-control for
1624 * the HW state machine and use this driver only for voltage control.
1625 * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
1626 * in order to set the system to SUSPEND state.
1628 * If regulator is taken under SW control the regulator state will not
1629 * be affected by PMIC state machine - Eg. regulator is likely to stay
1630 * on even in SUSPEND
1632 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
1637 for (i = 0; i < num_reg_data; i++) {
1639 struct regulator_desc *desc;
1640 struct regulator_dev *rdev;
1641 struct bd718xx_regulator_data *r;
1642 int no_enable_control = omit_enable & (1 << i);
1647 if (no_enable_control)
1648 desc->ops = hwops[i];
1650 desc->ops = swops[i];
1652 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1655 "failed to register %s regulator\n",
1657 err = PTR_ERR(rdev);
1662 * Regulator register gets the regulator constraints and
1663 * applies them (set_machine_constraints). This should have
1664 * turned the control register(s) to correct values and we
1665 * can now switch the control from PMIC state machine to the
1666 * register interface
1668 * At poweroff transition PMIC HW disables EN bit for
1669 * regulators but leaves SEL bit untouched. So if state
1670 * transition from POWEROFF is done to SNVS - then all power
1671 * rails controlled by SW (having SEL bit set) stay disabled
1672 * as EN is cleared. This will result boot failure if any
1673 * crucial systems are powered by these rails. We don't
1674 * enable SW control for crucial regulators if snvs state is
1677 if (!no_enable_control && (!use_snvs ||
1678 !rdev->constraints->always_on ||
1679 !rdev->constraints->boot_on)) {
1680 err = regmap_update_bits(regmap, r->init.reg,
1681 r->init.mask, r->init.val);
1684 "Failed to take control for (%s)\n",
1689 for (j = 0; j < r->additional_init_amnt; j++) {
1690 err = regmap_update_bits(regmap,
1691 r->additional_inits[j].reg,
1692 r->additional_inits[j].mask,
1693 r->additional_inits[j].val);
1696 "Buck (%s) initialization failed\n",
1707 static const struct platform_device_id bd718x7_pmic_id[] = {
1708 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1709 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1712 MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
1714 static struct platform_driver bd718xx_regulator = {
1716 .name = "bd718xx-pmic",
1718 .probe = bd718xx_probe,
1719 .id_table = bd718x7_pmic_id,
1722 module_platform_driver(bd718xx_regulator);
1724 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1725 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1726 MODULE_LICENSE("GPL");
1727 MODULE_ALIAS("platform:bd718xx-pmic");