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, \
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), \
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), \
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
94 static const unsigned int bd718xx_ramp_delay[] = { 10000, 5000, 2500, 1250 };
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.
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.
107 static int always_enabled_by_hwstate(struct regulator_dev *rdev)
112 static int never_enabled_by_hwstate(struct regulator_dev *rdev)
117 static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
122 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
126 return !!(BD718XX_BUCK_RUN_ON & val);
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.
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
141 static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
144 if (rdev->desc->ops->is_enabled(rdev))
147 return regulator_set_voltage_sel_regmap(rdev, sel);
150 static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
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.
163 ret = regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
167 "Failed to re-enable voltage monitoring (%d)\n",
172 static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
178 if (rdev->desc->ops->is_enabled(rdev)) {
181 now = rdev->desc->ops->get_voltage_sel(rdev);
185 now = rdev->desc->ops->list_voltage(rdev, now);
189 new = rdev->desc->ops->list_voltage(rdev, sel);
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.
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
210 int ldo_offset = rdev->desc->id - BD718XX_LDO1;
212 prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
213 ret = regmap_read(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
217 "Failed to read voltage monitoring state\n");
221 if (!(tmp & prot_bit)) {
222 /* We disable protection if it was enabled... */
223 ret = regmap_set_bits(rdev->regmap,
224 BD718XX_REG_MVRFLTMASK2,
226 /* ...and we also want to re-enable it */
231 "Failed to stop voltage monitoring\n");
240 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
246 ret = voltage_change_prepare(rdev, sel, &mask);
250 ret = regulator_set_voltage_sel_regmap(rdev, sel);
251 voltage_change_done(rdev, sel, &mask);
256 static int bd718xx_set_voltage_sel_pickable_restricted(
257 struct regulator_dev *rdev, unsigned int sel)
262 ret = voltage_change_prepare(rdev, sel, &mask);
266 ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
267 voltage_change_done(rdev, sel, &mask);
272 static int bd71837_set_voltage_sel_pickable_restricted(
273 struct regulator_dev *rdev, unsigned int sel)
275 if (rdev->desc->ops->is_enabled(rdev))
278 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
282 * BD71837 BUCK1/2/3/4
284 * 0.70 to 1.30V (10mV step)
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),
293 * 0.7V to 1.35V (range 0)
295 * 0.675 to 1.325 (range 1)
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),
309 * Range selector for first 3 linear ranges is 0x0
310 * and 0x1 for last 3 ranges.
312 static const unsigned int bd71837_buck5_volt_range_sel[] = {
313 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
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),
332 static const unsigned int bd71847_buck3_volt_range_sel[] = {
333 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
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),
341 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
345 * 3.0V to 3.3V (step 100mV)
347 static const struct linear_range bd71837_buck6_volts[] = {
348 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
357 * 011 = 1.8V (Initial)
363 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
364 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
369 * 0.8V to 1.40V (step 10mV)
371 static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
372 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
377 * 3.0 to 3.3V (100mV step)
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),
384 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
390 static const unsigned int ldo_2_volts[] = {
396 * 1.8 to 3.3V (100mV step)
398 static const struct linear_range bd718xx_ldo3_volts[] = {
399 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
404 * 0.9 to 1.8V (100mV step)
406 static const struct linear_range bd718xx_ldo4_volts[] = {
407 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
412 * 1.8 to 3.3V (100mV step)
414 static const struct linear_range bd71837_ldo5_volts[] = {
415 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
420 * 1.8 to 3.3V (100mV step)
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),
427 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
431 * 0.9 to 1.8V (100mV step)
433 static const struct linear_range bd718xx_ldo6_volts[] = {
434 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
439 * 1.8 to 3.3V (100mV step)
441 static const struct linear_range bd71837_ldo7_volts[] = {
442 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
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;
458 static int bd718x7_xvp_sanity_check(struct regulator_dev *rdev, int lim_uV,
462 * BD71837/47/50 ... (ICs supported by this driver) do not provide
463 * warnings, only protection
465 if (severity != REGULATOR_SEVERITY_PROT) {
467 "Unsupported Under Voltage protection level\n");
472 * And protection limit is not changeable. It can only be enabled
481 static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV,
482 int severity, bool enable)
484 int ldo_offset = rdev->desc->id - BD718XX_LDO1;
487 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
491 prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;
494 return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
497 return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
501 static int bd718x7_get_buck_prot_reg(int id, int *reg)
504 if (id > BD718XX_BUCK8) {
505 WARN_ON(id > BD718XX_BUCK8);
509 if (id > BD718XX_BUCK4)
510 *reg = BD718XX_REG_MVRFLTMASK0;
512 *reg = BD718XX_REG_MVRFLTMASK1;
517 static int bd718x7_get_buck_ovp_info(int id, int *reg, int *bit)
521 ret = bd718x7_get_buck_prot_reg(id, reg);
525 *bit = BIT((id % 4) * 2 + 1);
530 static int bd718x7_get_buck_uvp_info(int id, int *reg, int *bit)
534 ret = bd718x7_get_buck_prot_reg(id, reg);
538 *bit = BIT((id % 4) * 2);
543 static int bd718x7_set_buck_uvp(struct regulator_dev *rdev, int lim_uV,
544 int severity, bool enable)
548 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
552 ret = bd718x7_get_buck_uvp_info(rdev->desc->id, ®, &bit);
557 return regmap_clear_bits(rdev->regmap, reg, bit);
559 return regmap_set_bits(rdev->regmap, reg, bit);
563 static int bd718x7_set_buck_ovp(struct regulator_dev *rdev, int lim_uV,
569 ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
573 ret = bd718x7_get_buck_ovp_info(rdev->desc->id, ®, &bit);
578 return regmap_clear_bits(rdev->regmap, reg, bit);
580 return regmap_set_bits(rdev->regmap, reg, bit);
584 * OPS common for BD71847 and BD71850
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);
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,
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);
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,
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,
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);
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);
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);
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);
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,
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,
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);
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);
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.
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,
680 * OPS for all of the ICs - BD718(37/47/50)
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);
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
700 static const struct reg_init bd71837_ldo5_inits[] = {
702 .reg = BD718XX_REG_MVRFLTMASK2,
703 .mask = BD718XX_LDO5_VRMON80,
704 .val = BD718XX_LDO5_VRMON80,
708 static const struct reg_init bd71837_ldo6_inits[] = {
710 .reg = BD718XX_REG_MVRFLTMASK2,
711 .mask = BD718XX_LDO6_VRMON80,
712 .val = BD718XX_LDO6_VRMON80,
716 static int buck_set_hw_dvs_levels(struct device_node *np,
717 const struct regulator_desc *desc,
718 struct regulator_config *cfg)
720 struct bd718xx_regulator_data *data;
722 data = container_of(desc, struct bd718xx_regulator_data, desc);
724 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
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,
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),
751 static struct bd718xx_regulator_data bd71847_regulators[] = {
755 .of_match = of_match_ptr("BUCK1"),
756 .regulators_node = of_match_ptr("regulators"),
758 .type = REGULATOR_VOLTAGE,
759 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
760 .linear_ranges = bd718xx_dvs_buck_volts,
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,
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,
786 .reg = BD718XX_REG_BUCK1_CTRL,
787 .mask = BD718XX_BUCK_SEL,
788 .val = BD718XX_BUCK_SEL,
794 .of_match = of_match_ptr("BUCK2"),
795 .regulators_node = of_match_ptr("regulators"),
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,
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,
821 .reg = BD718XX_REG_BUCK2_CTRL,
822 .mask = BD718XX_BUCK_SEL,
823 .val = BD718XX_BUCK_SEL,
829 .of_match = of_match_ptr("BUCK3"),
830 .regulators_node = of_match_ptr("regulators"),
832 .type = REGULATOR_VOLTAGE,
833 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
834 .linear_ranges = bd71847_buck3_volts,
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,
848 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
849 .mask = BD718XX_BUCK_SEL,
850 .val = BD718XX_BUCK_SEL,
856 .of_match = of_match_ptr("BUCK4"),
857 .regulators_node = of_match_ptr("regulators"),
859 .type = REGULATOR_VOLTAGE,
860 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
861 .linear_ranges = bd71847_buck4_volts,
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,
875 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
876 .mask = BD718XX_BUCK_SEL,
877 .val = BD718XX_BUCK_SEL,
883 .of_match = of_match_ptr("BUCK5"),
884 .regulators_node = of_match_ptr("regulators"),
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,
897 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
898 .mask = BD718XX_BUCK_SEL,
899 .val = BD718XX_BUCK_SEL,
905 .of_match = of_match_ptr("BUCK6"),
906 .regulators_node = of_match_ptr("regulators"),
908 .type = REGULATOR_VOLTAGE,
909 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
910 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
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,
921 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
922 .mask = BD718XX_BUCK_SEL,
923 .val = BD718XX_BUCK_SEL,
929 .of_match = of_match_ptr("LDO1"),
930 .regulators_node = of_match_ptr("regulators"),
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,
947 .reg = BD718XX_REG_LDO1_VOLT,
948 .mask = BD718XX_LDO_SEL,
949 .val = BD718XX_LDO_SEL,
955 .of_match = of_match_ptr("LDO2"),
956 .regulators_node = of_match_ptr("regulators"),
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,
969 .reg = BD718XX_REG_LDO2_VOLT,
970 .mask = BD718XX_LDO_SEL,
971 .val = BD718XX_LDO_SEL,
977 .of_match = of_match_ptr("LDO3"),
978 .regulators_node = of_match_ptr("regulators"),
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,
992 .reg = BD718XX_REG_LDO3_VOLT,
993 .mask = BD718XX_LDO_SEL,
994 .val = BD718XX_LDO_SEL,
1000 .of_match = of_match_ptr("LDO4"),
1001 .regulators_node = of_match_ptr("regulators"),
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,
1015 .reg = BD718XX_REG_LDO4_VOLT,
1016 .mask = BD718XX_LDO_SEL,
1017 .val = BD718XX_LDO_SEL,
1023 .of_match = of_match_ptr("LDO5"),
1024 .regulators_node = of_match_ptr("regulators"),
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,
1041 .reg = BD718XX_REG_LDO5_VOLT,
1042 .mask = BD718XX_LDO_SEL,
1043 .val = BD718XX_LDO_SEL,
1049 .of_match = of_match_ptr("LDO6"),
1050 .regulators_node = of_match_ptr("regulators"),
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,
1066 .reg = BD718XX_REG_LDO6_VOLT,
1067 .mask = BD718XX_LDO_SEL,
1068 .val = BD718XX_LDO_SEL,
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,
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),
1101 static struct bd718xx_regulator_data bd71837_regulators[] = {
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,
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,
1135 .reg = BD718XX_REG_BUCK1_CTRL,
1136 .mask = BD718XX_BUCK_SEL,
1137 .val = BD718XX_BUCK_SEL,
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,
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,
1170 .reg = BD718XX_REG_BUCK2_CTRL,
1171 .mask = BD718XX_BUCK_SEL,
1172 .val = BD718XX_BUCK_SEL,
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,
1198 .level_map = ROHM_DVS_LEVEL_RUN,
1199 .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
1200 .run_mask = DVS_BUCK_RUN_MASK,
1203 .reg = BD71837_REG_BUCK3_CTRL,
1204 .mask = BD718XX_BUCK_SEL,
1205 .val = BD718XX_BUCK_SEL,
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,
1231 .level_map = ROHM_DVS_LEVEL_RUN,
1232 .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
1233 .run_mask = DVS_BUCK_RUN_MASK,
1236 .reg = BD71837_REG_BUCK4_CTRL,
1237 .mask = BD718XX_BUCK_SEL,
1238 .val = BD718XX_BUCK_SEL,
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,
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,
1263 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1264 .mask = BD718XX_BUCK_SEL,
1265 .val = BD718XX_BUCK_SEL,
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,
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,
1287 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1288 .mask = BD718XX_BUCK_SEL,
1289 .val = BD718XX_BUCK_SEL,
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,
1309 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1310 .mask = BD718XX_BUCK_SEL,
1311 .val = BD718XX_BUCK_SEL,
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,
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,
1333 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1334 .mask = BD718XX_BUCK_SEL,
1335 .val = BD718XX_BUCK_SEL,
1341 .of_match = of_match_ptr("LDO1"),
1342 .regulators_node = of_match_ptr("regulators"),
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,
1359 .reg = BD718XX_REG_LDO1_VOLT,
1360 .mask = BD718XX_LDO_SEL,
1361 .val = BD718XX_LDO_SEL,
1367 .of_match = of_match_ptr("LDO2"),
1368 .regulators_node = of_match_ptr("regulators"),
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,
1381 .reg = BD718XX_REG_LDO2_VOLT,
1382 .mask = BD718XX_LDO_SEL,
1383 .val = BD718XX_LDO_SEL,
1389 .of_match = of_match_ptr("LDO3"),
1390 .regulators_node = of_match_ptr("regulators"),
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,
1404 .reg = BD718XX_REG_LDO3_VOLT,
1405 .mask = BD718XX_LDO_SEL,
1406 .val = BD718XX_LDO_SEL,
1412 .of_match = of_match_ptr("LDO4"),
1413 .regulators_node = of_match_ptr("regulators"),
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,
1427 .reg = BD718XX_REG_LDO4_VOLT,
1428 .mask = BD718XX_LDO_SEL,
1429 .val = BD718XX_LDO_SEL,
1435 .of_match = of_match_ptr("LDO5"),
1436 .regulators_node = of_match_ptr("regulators"),
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,
1452 .reg = BD718XX_REG_LDO5_VOLT,
1453 .mask = BD718XX_LDO_SEL,
1454 .val = BD718XX_LDO_SEL,
1456 .additional_inits = bd71837_ldo5_inits,
1457 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1462 .of_match = of_match_ptr("LDO6"),
1463 .regulators_node = of_match_ptr("regulators"),
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,
1479 .reg = BD718XX_REG_LDO6_VOLT,
1480 .mask = BD718XX_LDO_SEL,
1481 .val = BD718XX_LDO_SEL,
1483 .additional_inits = bd71837_ldo6_inits,
1484 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1489 .of_match = of_match_ptr("LDO7"),
1490 .regulators_node = of_match_ptr("regulators"),
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,
1504 .reg = BD71837_REG_LDO7_VOLT,
1505 .mask = BD718XX_LDO_SEL,
1506 .val = BD718XX_LDO_SEL,
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)
1517 for (i = 1; i <= num_reg_data; i++) {
1518 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
1521 *info |= 1 << (i - 1);
1522 dev_dbg(dev, "regulator %d runlevel controlled\n", i);
1525 dev_warn(dev, "Bad regulator node\n");
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)
1539 * So we allow describing this external connection from DT and scale the
1540 * voltages accordingly. This is what the connection should look like:
1543 * | buck 8 |-------+----->Vout
1554 * Here the buck output is sifted according to formula:
1556 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1557 * Linear_step = step_orig*(R1+R2)/R1
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.
1565 * As a real world example for buck8 and a specific GPU:
1566 * VLDO = 1.6V (used as FB-pull-up)
1569 * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
1570 * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
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)
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.
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
1593 for (i = 0; i < num_reg_data; i++) {
1594 struct regulator_desc *desc = ®_data[i].desc;
1597 if (!of_node_name_eq(np, desc->of_match))
1600 pr_info("Looking at node '%s'\n", desc->of_match);
1602 /* The feedback loop connection does not make sense for LDOs */
1603 if (desc->id >= BD718XX_LDO1)
1606 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
1614 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
1619 if (desc->n_linear_ranges && desc->linear_ranges) {
1620 struct linear_range *new;
1622 new = devm_kzalloc(dev, desc->n_linear_ranges *
1623 sizeof(struct linear_range),
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;
1632 min -= (fb_uv - min)*r2/r1;
1633 step = step * (r1 + r2);
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,
1645 desc->linear_ranges = new;
1647 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
1656 static int get_special_regulators(struct device *dev,
1657 struct bd718xx_regulator_data *reg_data,
1658 unsigned int num_reg_data, int *info)
1661 struct device_node *np;
1662 struct device_node *nproot = dev->of_node;
1667 nproot = of_get_child_by_name(nproot, "regulators");
1669 dev_err(dev, "failed to find regulators node\n");
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,
1676 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
1685 ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
1690 of_node_put(nproot);
1695 of_node_put(nproot);
1700 static int bd718xx_probe(struct platform_device *pdev)
1702 struct regmap *regmap;
1703 struct regulator_config config = { 0 };
1704 int i, j, err, omit_enable;
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;
1711 regmap = dev_get_regmap(pdev->dev.parent, NULL);
1713 dev_err(&pdev->dev, "No MFD driver data\n");
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];
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];
1731 dev_err(&pdev->dev, "Unsupported chip type\n");
1736 /* Register LOCK release */
1737 err = regmap_update_bits(regmap, BD718XX_REG_REGLOCK,
1738 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1740 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1743 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1744 BD718XX_REG_REGLOCK);
1747 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1748 "rohm,reset-snvs-powered");
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
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);
1763 dev_err(&pdev->dev, "Failed to change reset target\n");
1767 "Changed all resets from SVNS to READY\n");
1771 config.dev = pdev->dev.parent;
1772 config.regmap = regmap;
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.
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
1783 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
1788 for (i = 0; i < num_reg_data; i++) {
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);
1798 if (no_enable_control)
1799 desc->ops = hwops[i];
1801 desc->ops = swops[i];
1803 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1806 "failed to register %s regulator\n",
1808 err = PTR_ERR(rdev);
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
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
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);
1835 "Failed to take control for (%s)\n",
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);
1847 "Buck (%s) initialization failed\n",
1858 static const struct platform_device_id bd718x7_pmic_id[] = {
1859 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1860 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1863 MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
1865 static struct platform_driver bd718xx_regulator = {
1867 .name = "bd718xx-pmic",
1869 .probe = bd718xx_probe,
1870 .id_table = bd718x7_pmic_id,
1873 module_platform_driver(bd718xx_regulator);
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");