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>
19 * BD718(37/47/50) have two "enable control modes". ON/OFF can either be
20 * controlled by software - or by PMIC internal HW state machine. Whether
21 * regulator should be under SW or HW control can be defined from device-tree.
22 * Let's provide separate ops for regulators to use depending on the "enable
25 #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
27 #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
28 _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay) \
29 static const struct regulator_ops name = { \
30 .enable = regulator_enable_regmap, \
31 .disable = regulator_disable_regmap, \
32 .is_enabled = regulator_is_enabled_regmap, \
33 .list_voltage = (_list_voltage), \
34 .map_voltage = (_map_voltage), \
35 .set_voltage_sel = (_set_voltage_sel), \
36 .get_voltage_sel = (_get_voltage_sel), \
37 .set_voltage_time_sel = (_set_voltage_time_sel), \
38 .set_ramp_delay = (_set_ramp_delay), \
41 static const struct regulator_ops BD718XX_HWOPNAME(name) = { \
42 .is_enabled = always_enabled_by_hwstate, \
43 .list_voltage = (_list_voltage), \
44 .map_voltage = (_map_voltage), \
45 .set_voltage_sel = (_set_voltage_sel), \
46 .get_voltage_sel = (_get_voltage_sel), \
47 .set_voltage_time_sel = (_set_voltage_time_sel), \
48 .set_ramp_delay = (_set_ramp_delay), \
53 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
54 * 00: 10.00mV/usec 10mV 1uS
55 * 01: 5.00mV/usec 10mV 2uS
56 * 10: 2.50mV/usec 10mV 4uS
57 * 11: 1.25mV/usec 10mV 8uS
59 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
62 int id = rdev_get_id(rdev);
63 unsigned int ramp_value;
65 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
69 ramp_value = BUCK_RAMPRATE_1P25MV;
72 ramp_value = BUCK_RAMPRATE_2P50MV;
75 ramp_value = BUCK_RAMPRATE_5P00MV;
78 ramp_value = BUCK_RAMPRATE_10P00MV;
81 ramp_value = BUCK_RAMPRATE_10P00MV;
83 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
84 rdev->desc->name, ramp_delay);
87 return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
88 BUCK_RAMPRATE_MASK, ramp_value << 6);
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, bd718xx_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 = bd718xx_buck1234_set_ramp_delay,
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);
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 .owner = THIS_MODULE,
617 .of_parse_cb = buck_set_hw_dvs_levels,
620 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
621 ROHM_DVS_LEVEL_SUSPEND,
622 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
623 .run_mask = DVS_BUCK_RUN_MASK,
624 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
625 .idle_mask = DVS_BUCK_RUN_MASK,
626 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
627 .suspend_mask = DVS_BUCK_RUN_MASK,
630 .reg = BD718XX_REG_BUCK1_CTRL,
631 .mask = BD718XX_BUCK_SEL,
632 .val = BD718XX_BUCK_SEL,
638 .of_match = of_match_ptr("BUCK2"),
639 .regulators_node = of_match_ptr("regulators"),
641 .type = REGULATOR_VOLTAGE,
642 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
643 .linear_ranges = bd718xx_dvs_buck_volts,
644 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
645 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
646 .vsel_mask = DVS_BUCK_RUN_MASK,
647 .enable_reg = BD718XX_REG_BUCK2_CTRL,
648 .enable_mask = BD718XX_BUCK_EN,
649 .owner = THIS_MODULE,
650 .of_parse_cb = buck_set_hw_dvs_levels,
653 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
654 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
655 .run_mask = DVS_BUCK_RUN_MASK,
656 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
657 .idle_mask = DVS_BUCK_RUN_MASK,
660 .reg = BD718XX_REG_BUCK2_CTRL,
661 .mask = BD718XX_BUCK_SEL,
662 .val = BD718XX_BUCK_SEL,
668 .of_match = of_match_ptr("BUCK3"),
669 .regulators_node = of_match_ptr("regulators"),
671 .type = REGULATOR_VOLTAGE,
672 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
673 .linear_ranges = bd71847_buck3_volts,
675 ARRAY_SIZE(bd71847_buck3_volts),
676 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
677 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
678 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
679 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
680 .linear_range_selectors = bd71847_buck3_volt_range_sel,
681 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
682 .enable_mask = BD718XX_BUCK_EN,
683 .owner = THIS_MODULE,
686 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
687 .mask = BD718XX_BUCK_SEL,
688 .val = BD718XX_BUCK_SEL,
694 .of_match = of_match_ptr("BUCK4"),
695 .regulators_node = of_match_ptr("regulators"),
697 .type = REGULATOR_VOLTAGE,
698 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
699 .linear_ranges = bd71847_buck4_volts,
701 ARRAY_SIZE(bd71847_buck4_volts),
702 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
703 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
704 .vsel_mask = BD71847_BUCK4_MASK,
705 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
706 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
707 .linear_range_selectors = bd71847_buck4_volt_range_sel,
708 .enable_mask = BD718XX_BUCK_EN,
709 .owner = THIS_MODULE,
712 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
713 .mask = BD718XX_BUCK_SEL,
714 .val = BD718XX_BUCK_SEL,
720 .of_match = of_match_ptr("BUCK5"),
721 .regulators_node = of_match_ptr("regulators"),
723 .type = REGULATOR_VOLTAGE,
724 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
725 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
726 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
727 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
728 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
729 .enable_mask = BD718XX_BUCK_EN,
730 .owner = THIS_MODULE,
733 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
734 .mask = BD718XX_BUCK_SEL,
735 .val = BD718XX_BUCK_SEL,
741 .of_match = of_match_ptr("BUCK6"),
742 .regulators_node = of_match_ptr("regulators"),
744 .type = REGULATOR_VOLTAGE,
745 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
746 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
748 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
749 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
750 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
751 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
752 .enable_mask = BD718XX_BUCK_EN,
753 .owner = THIS_MODULE,
756 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
757 .mask = BD718XX_BUCK_SEL,
758 .val = BD718XX_BUCK_SEL,
764 .of_match = of_match_ptr("LDO1"),
765 .regulators_node = of_match_ptr("regulators"),
767 .type = REGULATOR_VOLTAGE,
768 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
769 .linear_ranges = bd718xx_ldo1_volts,
770 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
771 .vsel_reg = BD718XX_REG_LDO1_VOLT,
772 .vsel_mask = BD718XX_LDO1_MASK,
773 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
774 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
775 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
776 .enable_reg = BD718XX_REG_LDO1_VOLT,
777 .enable_mask = BD718XX_LDO_EN,
778 .owner = THIS_MODULE,
781 .reg = BD718XX_REG_LDO1_VOLT,
782 .mask = BD718XX_LDO_SEL,
783 .val = BD718XX_LDO_SEL,
789 .of_match = of_match_ptr("LDO2"),
790 .regulators_node = of_match_ptr("regulators"),
792 .type = REGULATOR_VOLTAGE,
793 .volt_table = &ldo_2_volts[0],
794 .vsel_reg = BD718XX_REG_LDO2_VOLT,
795 .vsel_mask = BD718XX_LDO2_MASK,
796 .n_voltages = ARRAY_SIZE(ldo_2_volts),
797 .enable_reg = BD718XX_REG_LDO2_VOLT,
798 .enable_mask = BD718XX_LDO_EN,
799 .owner = THIS_MODULE,
802 .reg = BD718XX_REG_LDO2_VOLT,
803 .mask = BD718XX_LDO_SEL,
804 .val = BD718XX_LDO_SEL,
810 .of_match = of_match_ptr("LDO3"),
811 .regulators_node = of_match_ptr("regulators"),
813 .type = REGULATOR_VOLTAGE,
814 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
815 .linear_ranges = bd718xx_ldo3_volts,
816 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
817 .vsel_reg = BD718XX_REG_LDO3_VOLT,
818 .vsel_mask = BD718XX_LDO3_MASK,
819 .enable_reg = BD718XX_REG_LDO3_VOLT,
820 .enable_mask = BD718XX_LDO_EN,
821 .owner = THIS_MODULE,
824 .reg = BD718XX_REG_LDO3_VOLT,
825 .mask = BD718XX_LDO_SEL,
826 .val = BD718XX_LDO_SEL,
832 .of_match = of_match_ptr("LDO4"),
833 .regulators_node = of_match_ptr("regulators"),
835 .type = REGULATOR_VOLTAGE,
836 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
837 .linear_ranges = bd718xx_ldo4_volts,
838 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
839 .vsel_reg = BD718XX_REG_LDO4_VOLT,
840 .vsel_mask = BD718XX_LDO4_MASK,
841 .enable_reg = BD718XX_REG_LDO4_VOLT,
842 .enable_mask = BD718XX_LDO_EN,
843 .owner = THIS_MODULE,
846 .reg = BD718XX_REG_LDO4_VOLT,
847 .mask = BD718XX_LDO_SEL,
848 .val = BD718XX_LDO_SEL,
854 .of_match = of_match_ptr("LDO5"),
855 .regulators_node = of_match_ptr("regulators"),
857 .type = REGULATOR_VOLTAGE,
858 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
859 .linear_ranges = bd71847_ldo5_volts,
860 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
861 .vsel_reg = BD718XX_REG_LDO5_VOLT,
862 .vsel_mask = BD71847_LDO5_MASK,
863 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
864 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
865 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
866 .enable_reg = BD718XX_REG_LDO5_VOLT,
867 .enable_mask = BD718XX_LDO_EN,
868 .owner = THIS_MODULE,
871 .reg = BD718XX_REG_LDO5_VOLT,
872 .mask = BD718XX_LDO_SEL,
873 .val = BD718XX_LDO_SEL,
879 .of_match = of_match_ptr("LDO6"),
880 .regulators_node = of_match_ptr("regulators"),
882 .type = REGULATOR_VOLTAGE,
883 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
884 .linear_ranges = bd718xx_ldo6_volts,
885 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
886 /* LDO6 is supplied by buck5 */
887 .supply_name = "buck5",
888 .vsel_reg = BD718XX_REG_LDO6_VOLT,
889 .vsel_mask = BD718XX_LDO6_MASK,
890 .enable_reg = BD718XX_REG_LDO6_VOLT,
891 .enable_mask = BD718XX_LDO_EN,
892 .owner = THIS_MODULE,
895 .reg = BD718XX_REG_LDO6_VOLT,
896 .mask = BD718XX_LDO_SEL,
897 .val = BD718XX_LDO_SEL,
902 static const struct regulator_ops *bd71837_swcontrol_ops[] = {
903 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
904 &bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
905 &bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
906 &bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
907 &bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
908 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
909 &bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
910 &bd71837_ldo_regulator_ops,
913 static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
914 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
915 &BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
916 &bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
917 &BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
918 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
919 &BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
920 &BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
921 &BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
922 &BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
923 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
924 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
925 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
926 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
927 &BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
930 static struct bd718xx_regulator_data bd71837_regulators[] = {
934 .of_match = of_match_ptr("BUCK1"),
935 .regulators_node = of_match_ptr("regulators"),
937 .type = REGULATOR_VOLTAGE,
938 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
939 .linear_ranges = bd718xx_dvs_buck_volts,
940 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
941 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
942 .vsel_mask = DVS_BUCK_RUN_MASK,
943 .enable_reg = BD718XX_REG_BUCK1_CTRL,
944 .enable_mask = BD718XX_BUCK_EN,
945 .owner = THIS_MODULE,
946 .of_parse_cb = buck_set_hw_dvs_levels,
949 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
950 ROHM_DVS_LEVEL_SUSPEND,
951 .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
952 .run_mask = DVS_BUCK_RUN_MASK,
953 .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
954 .idle_mask = DVS_BUCK_RUN_MASK,
955 .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
956 .suspend_mask = DVS_BUCK_RUN_MASK,
959 .reg = BD718XX_REG_BUCK1_CTRL,
960 .mask = BD718XX_BUCK_SEL,
961 .val = BD718XX_BUCK_SEL,
967 .of_match = of_match_ptr("BUCK2"),
968 .regulators_node = of_match_ptr("regulators"),
970 .type = REGULATOR_VOLTAGE,
971 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
972 .linear_ranges = bd718xx_dvs_buck_volts,
973 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
974 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
975 .vsel_mask = DVS_BUCK_RUN_MASK,
976 .enable_reg = BD718XX_REG_BUCK2_CTRL,
977 .enable_mask = BD718XX_BUCK_EN,
978 .owner = THIS_MODULE,
979 .of_parse_cb = buck_set_hw_dvs_levels,
982 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
983 .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
984 .run_mask = DVS_BUCK_RUN_MASK,
985 .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
986 .idle_mask = DVS_BUCK_RUN_MASK,
989 .reg = BD718XX_REG_BUCK2_CTRL,
990 .mask = BD718XX_BUCK_SEL,
991 .val = BD718XX_BUCK_SEL,
997 .of_match = of_match_ptr("BUCK3"),
998 .regulators_node = of_match_ptr("regulators"),
1000 .type = REGULATOR_VOLTAGE,
1001 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1002 .linear_ranges = bd718xx_dvs_buck_volts,
1003 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1004 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
1005 .vsel_mask = DVS_BUCK_RUN_MASK,
1006 .enable_reg = BD71837_REG_BUCK3_CTRL,
1007 .enable_mask = BD718XX_BUCK_EN,
1008 .owner = THIS_MODULE,
1009 .of_parse_cb = buck_set_hw_dvs_levels,
1012 .level_map = ROHM_DVS_LEVEL_RUN,
1013 .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
1014 .run_mask = DVS_BUCK_RUN_MASK,
1017 .reg = BD71837_REG_BUCK3_CTRL,
1018 .mask = BD718XX_BUCK_SEL,
1019 .val = BD718XX_BUCK_SEL,
1025 .of_match = of_match_ptr("BUCK4"),
1026 .regulators_node = of_match_ptr("regulators"),
1027 .id = BD718XX_BUCK4,
1028 .type = REGULATOR_VOLTAGE,
1029 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
1030 .linear_ranges = bd718xx_dvs_buck_volts,
1031 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
1032 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
1033 .vsel_mask = DVS_BUCK_RUN_MASK,
1034 .enable_reg = BD71837_REG_BUCK4_CTRL,
1035 .enable_mask = BD718XX_BUCK_EN,
1036 .owner = THIS_MODULE,
1037 .of_parse_cb = buck_set_hw_dvs_levels,
1040 .level_map = ROHM_DVS_LEVEL_RUN,
1041 .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
1042 .run_mask = DVS_BUCK_RUN_MASK,
1045 .reg = BD71837_REG_BUCK4_CTRL,
1046 .mask = BD718XX_BUCK_SEL,
1047 .val = BD718XX_BUCK_SEL,
1053 .of_match = of_match_ptr("BUCK5"),
1054 .regulators_node = of_match_ptr("regulators"),
1055 .id = BD718XX_BUCK5,
1056 .type = REGULATOR_VOLTAGE,
1057 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
1058 .linear_ranges = bd71837_buck5_volts,
1060 ARRAY_SIZE(bd71837_buck5_volts),
1061 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1062 .vsel_mask = BD71837_BUCK5_MASK,
1063 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
1064 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
1065 .linear_range_selectors = bd71837_buck5_volt_range_sel,
1066 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1067 .enable_mask = BD718XX_BUCK_EN,
1068 .owner = THIS_MODULE,
1071 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
1072 .mask = BD718XX_BUCK_SEL,
1073 .val = BD718XX_BUCK_SEL,
1079 .of_match = of_match_ptr("BUCK6"),
1080 .regulators_node = of_match_ptr("regulators"),
1081 .id = BD718XX_BUCK6,
1082 .type = REGULATOR_VOLTAGE,
1083 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
1084 .linear_ranges = bd71837_buck6_volts,
1086 ARRAY_SIZE(bd71837_buck6_volts),
1087 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
1088 .vsel_mask = BD71837_BUCK6_MASK,
1089 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1090 .enable_mask = BD718XX_BUCK_EN,
1091 .owner = THIS_MODULE,
1094 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
1095 .mask = BD718XX_BUCK_SEL,
1096 .val = BD718XX_BUCK_SEL,
1102 .of_match = of_match_ptr("BUCK7"),
1103 .regulators_node = of_match_ptr("regulators"),
1104 .id = BD718XX_BUCK7,
1105 .type = REGULATOR_VOLTAGE,
1106 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
1107 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
1108 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
1109 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
1110 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1111 .enable_mask = BD718XX_BUCK_EN,
1112 .owner = THIS_MODULE,
1115 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
1116 .mask = BD718XX_BUCK_SEL,
1117 .val = BD718XX_BUCK_SEL,
1123 .of_match = of_match_ptr("BUCK8"),
1124 .regulators_node = of_match_ptr("regulators"),
1125 .id = BD718XX_BUCK8,
1126 .type = REGULATOR_VOLTAGE,
1127 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
1128 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
1130 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
1131 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
1132 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
1133 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1134 .enable_mask = BD718XX_BUCK_EN,
1135 .owner = THIS_MODULE,
1138 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
1139 .mask = BD718XX_BUCK_SEL,
1140 .val = BD718XX_BUCK_SEL,
1146 .of_match = of_match_ptr("LDO1"),
1147 .regulators_node = of_match_ptr("regulators"),
1149 .type = REGULATOR_VOLTAGE,
1150 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
1151 .linear_ranges = bd718xx_ldo1_volts,
1152 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
1153 .vsel_reg = BD718XX_REG_LDO1_VOLT,
1154 .vsel_mask = BD718XX_LDO1_MASK,
1155 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
1156 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
1157 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
1158 .enable_reg = BD718XX_REG_LDO1_VOLT,
1159 .enable_mask = BD718XX_LDO_EN,
1160 .owner = THIS_MODULE,
1163 .reg = BD718XX_REG_LDO1_VOLT,
1164 .mask = BD718XX_LDO_SEL,
1165 .val = BD718XX_LDO_SEL,
1171 .of_match = of_match_ptr("LDO2"),
1172 .regulators_node = of_match_ptr("regulators"),
1174 .type = REGULATOR_VOLTAGE,
1175 .volt_table = &ldo_2_volts[0],
1176 .vsel_reg = BD718XX_REG_LDO2_VOLT,
1177 .vsel_mask = BD718XX_LDO2_MASK,
1178 .n_voltages = ARRAY_SIZE(ldo_2_volts),
1179 .enable_reg = BD718XX_REG_LDO2_VOLT,
1180 .enable_mask = BD718XX_LDO_EN,
1181 .owner = THIS_MODULE,
1184 .reg = BD718XX_REG_LDO2_VOLT,
1185 .mask = BD718XX_LDO_SEL,
1186 .val = BD718XX_LDO_SEL,
1192 .of_match = of_match_ptr("LDO3"),
1193 .regulators_node = of_match_ptr("regulators"),
1195 .type = REGULATOR_VOLTAGE,
1196 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1197 .linear_ranges = bd718xx_ldo3_volts,
1198 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1199 .vsel_reg = BD718XX_REG_LDO3_VOLT,
1200 .vsel_mask = BD718XX_LDO3_MASK,
1201 .enable_reg = BD718XX_REG_LDO3_VOLT,
1202 .enable_mask = BD718XX_LDO_EN,
1203 .owner = THIS_MODULE,
1206 .reg = BD718XX_REG_LDO3_VOLT,
1207 .mask = BD718XX_LDO_SEL,
1208 .val = BD718XX_LDO_SEL,
1214 .of_match = of_match_ptr("LDO4"),
1215 .regulators_node = of_match_ptr("regulators"),
1217 .type = REGULATOR_VOLTAGE,
1218 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1219 .linear_ranges = bd718xx_ldo4_volts,
1220 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1221 .vsel_reg = BD718XX_REG_LDO4_VOLT,
1222 .vsel_mask = BD718XX_LDO4_MASK,
1223 .enable_reg = BD718XX_REG_LDO4_VOLT,
1224 .enable_mask = BD718XX_LDO_EN,
1225 .owner = THIS_MODULE,
1228 .reg = BD718XX_REG_LDO4_VOLT,
1229 .mask = BD718XX_LDO_SEL,
1230 .val = BD718XX_LDO_SEL,
1236 .of_match = of_match_ptr("LDO5"),
1237 .regulators_node = of_match_ptr("regulators"),
1239 .type = REGULATOR_VOLTAGE,
1240 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1241 .linear_ranges = bd71837_ldo5_volts,
1242 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
1243 /* LDO5 is supplied by buck6 */
1244 .supply_name = "buck6",
1245 .vsel_reg = BD718XX_REG_LDO5_VOLT,
1246 .vsel_mask = BD71837_LDO5_MASK,
1247 .enable_reg = BD718XX_REG_LDO5_VOLT,
1248 .enable_mask = BD718XX_LDO_EN,
1249 .owner = THIS_MODULE,
1252 .reg = BD718XX_REG_LDO5_VOLT,
1253 .mask = BD718XX_LDO_SEL,
1254 .val = BD718XX_LDO_SEL,
1256 .additional_inits = bd71837_ldo5_inits,
1257 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1262 .of_match = of_match_ptr("LDO6"),
1263 .regulators_node = of_match_ptr("regulators"),
1265 .type = REGULATOR_VOLTAGE,
1266 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1267 .linear_ranges = bd718xx_ldo6_volts,
1268 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1269 /* LDO6 is supplied by buck7 */
1270 .supply_name = "buck7",
1271 .vsel_reg = BD718XX_REG_LDO6_VOLT,
1272 .vsel_mask = BD718XX_LDO6_MASK,
1273 .enable_reg = BD718XX_REG_LDO6_VOLT,
1274 .enable_mask = BD718XX_LDO_EN,
1275 .owner = THIS_MODULE,
1278 .reg = BD718XX_REG_LDO6_VOLT,
1279 .mask = BD718XX_LDO_SEL,
1280 .val = BD718XX_LDO_SEL,
1282 .additional_inits = bd71837_ldo6_inits,
1283 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1288 .of_match = of_match_ptr("LDO7"),
1289 .regulators_node = of_match_ptr("regulators"),
1291 .type = REGULATOR_VOLTAGE,
1292 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1293 .linear_ranges = bd71837_ldo7_volts,
1294 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1295 .vsel_reg = BD71837_REG_LDO7_VOLT,
1296 .vsel_mask = BD71837_LDO7_MASK,
1297 .enable_reg = BD71837_REG_LDO7_VOLT,
1298 .enable_mask = BD718XX_LDO_EN,
1299 .owner = THIS_MODULE,
1302 .reg = BD71837_REG_LDO7_VOLT,
1303 .mask = BD718XX_LDO_SEL,
1304 .val = BD718XX_LDO_SEL,
1309 static void mark_hw_controlled(struct device *dev, struct device_node *np,
1310 struct bd718xx_regulator_data *reg_data,
1311 unsigned int num_reg_data, int *info)
1315 for (i = 1; i <= num_reg_data; i++) {
1316 if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
1319 *info |= 1 << (i - 1);
1320 dev_dbg(dev, "regulator %d runlevel controlled\n", i);
1323 dev_warn(dev, "Bad regulator node\n");
1327 * Setups where regulator (especially the buck8) output voltage is scaled
1328 * by adding external connection where some other regulator output is connected
1329 * to feedback-pin (over suitable resistors) is getting popular amongst users
1330 * of BD71837. (This allows for example scaling down the buck8 voltages to suit
1331 * lover GPU voltages for projects where buck8 is (ab)used to supply power
1332 * for GPU. Additionally some setups do allow DVS for buck8 but as this do
1333 * produce voltage spikes the HW must be evaluated to be able to survive this
1334 * - hence I keep the DVS disabled for non DVS bucks by default. I don't want
1335 * to help you burn your proto board)
1337 * So we allow describing this external connection from DT and scale the
1338 * voltages accordingly. This is what the connection should look like:
1341 * | buck 8 |-------+----->Vout
1352 * Here the buck output is sifted according to formula:
1354 * Vout_o = Vo - (Vpu - Vo)*R2/R1
1355 * Linear_step = step_orig*(R1+R2)/R1
1358 * Vout_o is adjusted voltage output at vsel reg value 0
1359 * Vo is original voltage output at vsel reg value 0
1360 * Vpu is the pull-up voltage V FB-pull-up in the picture
1361 * R1 and R2 are resistor values.
1363 * As a real world example for buck8 and a specific GPU:
1364 * VLDO = 1.6V (used as FB-pull-up)
1367 * VSEL 0x0 => 0.8V – (VLDO – 0.8) * R2 / R1 = 0.68V
1368 * Linear Step = 10mV * (R1 + R2) / R1 = 11.5mV
1370 static int setup_feedback_loop(struct device *dev, struct device_node *np,
1371 struct bd718xx_regulator_data *reg_data,
1372 unsigned int num_reg_data, int fb_uv)
1377 * We do adjust the values in the global desc based on DT settings.
1378 * This may not be best approach as it can cause problems if more than
1379 * one PMIC is controlled from same processor. I don't see such use-case
1380 * for BD718x7 now - so we spare some bits.
1382 * If this will point out to be a problem - then we can allocate new
1383 * bd718xx_regulator_data array at probe and just use the global
1384 * array as a template where we copy initial values. Then we can
1385 * use allocated descs for regultor registration and do IC specific
1386 * modifications to this copy while leaving other PMICs untouched. But
1387 * that means allocating new array for each PMIC - and currently I see
1391 for (i = 0; i < num_reg_data; i++) {
1392 struct regulator_desc *desc = ®_data[i].desc;
1395 if (!of_node_name_eq(np, desc->of_match))
1398 pr_info("Looking at node '%s'\n", desc->of_match);
1400 /* The feedback loop connection does not make sense for LDOs */
1401 if (desc->id >= BD718XX_LDO1)
1404 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r1-ohms",
1412 ret = of_property_read_u32(np, "rohm,feedback-pull-up-r2-ohms",
1417 if (desc->n_linear_ranges && desc->linear_ranges) {
1418 struct linear_range *new;
1420 new = devm_kzalloc(dev, desc->n_linear_ranges *
1421 sizeof(struct linear_range),
1426 for (j = 0; j < desc->n_linear_ranges; j++) {
1427 int min = desc->linear_ranges[j].min;
1428 int step = desc->linear_ranges[j].step;
1430 min -= (fb_uv - min)*r2/r1;
1431 step = step * (r1 + r2);
1437 dev_dbg(dev, "%s: old range min %d, step %d\n",
1438 desc->name, desc->linear_ranges[j].min,
1439 desc->linear_ranges[j].step);
1440 dev_dbg(dev, "new range min %d, step %d\n", min,
1443 desc->linear_ranges = new;
1445 dev_dbg(dev, "regulator '%s' has FB pull-up configured\n",
1454 static int get_special_regulators(struct device *dev,
1455 struct bd718xx_regulator_data *reg_data,
1456 unsigned int num_reg_data, int *info)
1459 struct device_node *np;
1460 struct device_node *nproot = dev->of_node;
1465 nproot = of_get_child_by_name(nproot, "regulators");
1467 dev_err(dev, "failed to find regulators node\n");
1470 for_each_child_of_node(nproot, np) {
1471 if (of_property_read_bool(np, "rohm,no-regulator-enable-control"))
1472 mark_hw_controlled(dev, np, reg_data, num_reg_data,
1474 ret = of_property_read_u32(np, "rohm,fb-pull-up-microvolt",
1483 ret = setup_feedback_loop(dev, np, reg_data, num_reg_data, uv);
1488 of_node_put(nproot);
1493 of_node_put(nproot);
1498 static int bd718xx_probe(struct platform_device *pdev)
1500 struct bd718xx *mfd;
1501 struct regulator_config config = { 0 };
1502 int i, j, err, omit_enable;
1504 struct bd718xx_regulator_data *reg_data;
1505 unsigned int num_reg_data;
1506 enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
1507 const struct regulator_ops **swops, **hwops;
1509 mfd = dev_get_drvdata(pdev->dev.parent);
1511 dev_err(&pdev->dev, "No MFD driver data\n");
1517 case ROHM_CHIP_TYPE_BD71837:
1518 reg_data = bd71837_regulators;
1519 num_reg_data = ARRAY_SIZE(bd71837_regulators);
1520 swops = &bd71837_swcontrol_ops[0];
1521 hwops = &bd71837_hwcontrol_ops[0];
1523 case ROHM_CHIP_TYPE_BD71847:
1524 reg_data = bd71847_regulators;
1525 num_reg_data = ARRAY_SIZE(bd71847_regulators);
1526 swops = &bd71847_swcontrol_ops[0];
1527 hwops = &bd71847_hwcontrol_ops[0];
1530 dev_err(&pdev->dev, "Unsupported chip type\n");
1535 /* Register LOCK release */
1536 err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK,
1537 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1539 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1542 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
1543 BD718XX_REG_REGLOCK);
1546 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1547 "rohm,reset-snvs-powered");
1550 * Change the next stage from poweroff to be READY instead of SNVS
1551 * for all reset types because OTP loading at READY will clear SEL
1552 * bit allowing HW defaults for power rails to be used
1555 err = regmap_update_bits(mfd->chip.regmap,
1556 BD718XX_REG_TRANS_COND1,
1557 BD718XX_ON_REQ_POWEROFF_MASK |
1558 BD718XX_SWRESET_POWEROFF_MASK |
1559 BD718XX_WDOG_POWEROFF_MASK |
1560 BD718XX_KEY_L_POWEROFF_MASK,
1561 BD718XX_POWOFF_TO_RDY);
1563 dev_err(&pdev->dev, "Failed to change reset target\n");
1567 "Changed all resets from SVNS to READY\n");
1571 config.dev = pdev->dev.parent;
1572 config.regmap = mfd->chip.regmap;
1574 * There are cases when we want to leave the enable-control for
1575 * the HW state machine and use this driver only for voltage control.
1576 * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
1577 * in order to set the system to SUSPEND state.
1579 * If regulator is taken under SW control the regulator state will not
1580 * be affected by PMIC state machine - Eg. regulator is likely to stay
1581 * on even in SUSPEND
1583 err = get_special_regulators(pdev->dev.parent, reg_data, num_reg_data,
1588 for (i = 0; i < num_reg_data; i++) {
1590 struct regulator_desc *desc;
1591 struct regulator_dev *rdev;
1592 struct bd718xx_regulator_data *r;
1593 int no_enable_control = omit_enable & (1 << i);
1598 if (no_enable_control)
1599 desc->ops = hwops[i];
1601 desc->ops = swops[i];
1603 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1606 "failed to register %s regulator\n",
1608 err = PTR_ERR(rdev);
1613 * Regulator register gets the regulator constraints and
1614 * applies them (set_machine_constraints). This should have
1615 * turned the control register(s) to correct values and we
1616 * can now switch the control from PMIC state machine to the
1617 * register interface
1619 * At poweroff transition PMIC HW disables EN bit for
1620 * regulators but leaves SEL bit untouched. So if state
1621 * transition from POWEROFF is done to SNVS - then all power
1622 * rails controlled by SW (having SEL bit set) stay disabled
1623 * as EN is cleared. This will result boot failure if any
1624 * crucial systems are powered by these rails. We don't
1625 * enable SW control for crucial regulators if snvs state is
1628 if (!no_enable_control && (!use_snvs ||
1629 !rdev->constraints->always_on ||
1630 !rdev->constraints->boot_on)) {
1631 err = regmap_update_bits(mfd->chip.regmap, r->init.reg,
1632 r->init.mask, r->init.val);
1635 "Failed to take control for (%s)\n",
1640 for (j = 0; j < r->additional_init_amnt; j++) {
1641 err = regmap_update_bits(mfd->chip.regmap,
1642 r->additional_inits[j].reg,
1643 r->additional_inits[j].mask,
1644 r->additional_inits[j].val);
1647 "Buck (%s) initialization failed\n",
1658 static const struct platform_device_id bd718x7_pmic_id[] = {
1659 { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
1660 { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
1663 MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
1665 static struct platform_driver bd718xx_regulator = {
1667 .name = "bd718xx-pmic",
1669 .probe = bd718xx_probe,
1670 .id_table = bd718x7_pmic_id,
1673 module_platform_driver(bd718xx_regulator);
1675 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1676 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1677 MODULE_LICENSE("GPL");
1678 MODULE_ALIAS("platform:bd718xx-pmic");