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/gpio.h>
8 #include <linux/interrupt.h>
9 #include <linux/kernel.h>
10 #include <linux/mfd/rohm-bd718x7.h>
11 #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>
20 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
21 * 00: 10.00mV/usec 10mV 1uS
22 * 01: 5.00mV/usec 10mV 2uS
23 * 10: 2.50mV/usec 10mV 4uS
24 * 11: 1.25mV/usec 10mV 8uS
26 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev
*rdev
,
29 int id
= rdev
->desc
->id
;
30 unsigned int ramp_value
= BUCK_RAMPRATE_10P00MV
;
32 dev_dbg(&rdev
->dev
, "Buck[%d] Set Ramp = %d\n", id
+ 1,
36 ramp_value
= BUCK_RAMPRATE_1P25MV
;
39 ramp_value
= BUCK_RAMPRATE_2P50MV
;
42 ramp_value
= BUCK_RAMPRATE_5P00MV
;
45 ramp_value
= BUCK_RAMPRATE_10P00MV
;
48 ramp_value
= BUCK_RAMPRATE_10P00MV
;
50 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
51 rdev
->desc
->name
, ramp_delay
);
54 return regmap_update_bits(rdev
->regmap
, BD718XX_REG_BUCK1_CTRL
+ id
,
55 BUCK_RAMPRATE_MASK
, ramp_value
<< 6);
58 /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
59 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
60 * is changed. Hence we return -EBUSY for these if voltage is changed
61 * when BUCK/LDO is enabled.
63 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev
*rdev
,
66 if (regulator_is_enabled_regmap(rdev
))
69 return regulator_set_voltage_sel_regmap(rdev
, sel
);
72 static int bd718xx_set_voltage_sel_pickable_restricted(
73 struct regulator_dev
*rdev
, unsigned int sel
)
75 if (regulator_is_enabled_regmap(rdev
))
78 return regulator_set_voltage_sel_pickable_regmap(rdev
, sel
);
81 static struct regulator_ops bd718xx_pickable_range_ldo_ops
= {
82 .enable
= regulator_enable_regmap
,
83 .disable
= regulator_disable_regmap
,
84 .is_enabled
= regulator_is_enabled_regmap
,
85 .list_voltage
= regulator_list_voltage_pickable_linear_range
,
86 .set_voltage_sel
= bd718xx_set_voltage_sel_pickable_restricted
,
87 .get_voltage_sel
= regulator_get_voltage_sel_pickable_regmap
,
90 static struct regulator_ops bd718xx_pickable_range_buck_ops
= {
91 .enable
= regulator_enable_regmap
,
92 .disable
= regulator_disable_regmap
,
93 .is_enabled
= regulator_is_enabled_regmap
,
94 .list_voltage
= regulator_list_voltage_pickable_linear_range
,
95 .set_voltage_sel
= bd718xx_set_voltage_sel_pickable_restricted
,
96 .get_voltage_sel
= regulator_get_voltage_sel_pickable_regmap
,
97 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
100 static struct regulator_ops bd718xx_ldo_regulator_ops
= {
101 .enable
= regulator_enable_regmap
,
102 .disable
= regulator_disable_regmap
,
103 .is_enabled
= regulator_is_enabled_regmap
,
104 .list_voltage
= regulator_list_voltage_linear_range
,
105 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
106 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
109 static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops
= {
110 .enable
= regulator_enable_regmap
,
111 .disable
= regulator_disable_regmap
,
112 .is_enabled
= regulator_is_enabled_regmap
,
113 .list_voltage
= regulator_list_voltage_table
,
114 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
115 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
118 static struct regulator_ops bd718xx_buck_regulator_ops
= {
119 .enable
= regulator_enable_regmap
,
120 .disable
= regulator_disable_regmap
,
121 .is_enabled
= regulator_is_enabled_regmap
,
122 .list_voltage
= regulator_list_voltage_linear_range
,
123 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
124 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
125 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
128 static struct regulator_ops bd718xx_buck_regulator_nolinear_ops
= {
129 .enable
= regulator_enable_regmap
,
130 .disable
= regulator_disable_regmap
,
131 .is_enabled
= regulator_is_enabled_regmap
,
132 .list_voltage
= regulator_list_voltage_table
,
133 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
134 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
135 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
138 static struct regulator_ops bd718xx_dvs_buck_regulator_ops
= {
139 .enable
= regulator_enable_regmap
,
140 .disable
= regulator_disable_regmap
,
141 .is_enabled
= regulator_is_enabled_regmap
,
142 .list_voltage
= regulator_list_voltage_linear_range
,
143 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
144 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
145 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
146 .set_ramp_delay
= bd718xx_buck1234_set_ramp_delay
,
150 * BD71837 BUCK1/2/3/4
152 * 0.70 to 1.30V (10mV step)
154 static const struct regulator_linear_range bd718xx_dvs_buck_volts
[] = {
155 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
156 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
161 * 0.7V to 1.35V (range 0)
163 * 0.675 to 1.325 (range 1)
165 static const struct regulator_linear_range bd71837_buck5_volts
[] = {
166 /* Ranges when VOLT_SEL bit is 0 */
167 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
168 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
169 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
170 /* Ranges when VOLT_SEL bit is 1 */
171 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
172 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
173 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
177 * Range selector for first 3 linear ranges is 0x0
178 * and 0x1 for last 3 ranges.
180 static const unsigned int bd71837_buck5_volt_range_sel
[] = {
181 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
187 static const struct regulator_linear_range bd71847_buck3_volts
[] = {
188 /* Ranges when VOLT_SEL bits are 00 */
189 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
190 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
191 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
192 /* Ranges when VOLT_SEL bits are 01 */
193 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
194 /* Ranges when VOLT_SEL bits are 11 */
195 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
196 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
197 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
200 static const unsigned int bd71847_buck3_volt_range_sel
[] = {
201 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
204 static const struct regulator_linear_range bd71847_buck4_volts
[] = {
205 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
206 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
209 static const unsigned int bd71847_buck4_volt_range_sel
[] = { 0x0, 0x40 };
213 * 3.0V to 3.3V (step 100mV)
215 static const struct regulator_linear_range bd71837_buck6_volts
[] = {
216 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
225 * 011 = 1.8V (Initial)
231 static const unsigned int bd718xx_3rd_nodvs_buck_volts
[] = {
232 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
237 * 0.8V to 1.40V (step 10mV)
239 static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts
[] = {
240 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
245 * 3.0 to 3.3V (100mV step)
247 static const struct regulator_linear_range bd718xx_ldo1_volts
[] = {
248 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
249 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
252 static const unsigned int bd718xx_ldo1_volt_range_sel
[] = { 0x0, 0x20 };
258 static const unsigned int ldo_2_volts
[] = {
264 * 1.8 to 3.3V (100mV step)
266 static const struct regulator_linear_range bd718xx_ldo3_volts
[] = {
267 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
272 * 0.9 to 1.8V (100mV step)
274 static const struct regulator_linear_range bd718xx_ldo4_volts
[] = {
275 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
280 * 1.8 to 3.3V (100mV step)
282 static const struct regulator_linear_range bd71837_ldo5_volts
[] = {
283 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
288 * 1.8 to 3.3V (100mV step)
290 static const struct regulator_linear_range bd71847_ldo5_volts
[] = {
291 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
292 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
295 static const unsigned int bd71847_ldo5_volt_range_sel
[] = { 0x0, 0x20 };
299 * 0.9 to 1.8V (100mV step)
301 static const struct regulator_linear_range bd718xx_ldo6_volts
[] = {
302 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
307 * 1.8 to 3.3V (100mV step)
309 static const struct regulator_linear_range bd71837_ldo7_volts
[] = {
310 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
318 struct bd718xx_regulator_data
{
319 struct regulator_desc desc
;
320 const struct reg_init init
;
321 const struct reg_init
*additional_inits
;
322 int additional_init_amnt
;
326 * There is a HW quirk in BD71837. The shutdown sequence timings for
327 * bucks/LDOs which are controlled via register interface are changed.
328 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
329 * beginning of shut-down sequence. As bucks 6 and 7 are parent
330 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
331 * monitoring to errorneously detect under voltage and force PMIC to
332 * emergency state instead of poweroff. In order to avoid this we
333 * disable voltage monitoring for LDO5 and LDO6
335 static const struct reg_init bd71837_ldo5_inits
[] = {
337 .reg
= BD718XX_REG_MVRFLTMASK2
,
338 .mask
= BD718XX_LDO5_VRMON80
,
339 .val
= BD718XX_LDO5_VRMON80
,
343 static const struct reg_init bd71837_ldo6_inits
[] = {
345 .reg
= BD718XX_REG_MVRFLTMASK2
,
346 .mask
= BD718XX_LDO6_VRMON80
,
347 .val
= BD718XX_LDO6_VRMON80
,
351 static const struct bd718xx_regulator_data bd71847_regulators
[] = {
355 .of_match
= of_match_ptr("BUCK1"),
356 .regulators_node
= of_match_ptr("regulators"),
358 .ops
= &bd718xx_dvs_buck_regulator_ops
,
359 .type
= REGULATOR_VOLTAGE
,
360 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
361 .linear_ranges
= bd718xx_dvs_buck_volts
,
363 ARRAY_SIZE(bd718xx_dvs_buck_volts
),
364 .vsel_reg
= BD718XX_REG_BUCK1_VOLT_RUN
,
365 .vsel_mask
= DVS_BUCK_RUN_MASK
,
366 .enable_reg
= BD718XX_REG_BUCK1_CTRL
,
367 .enable_mask
= BD718XX_BUCK_EN
,
368 .owner
= THIS_MODULE
,
371 .reg
= BD718XX_REG_BUCK1_CTRL
,
372 .mask
= BD718XX_BUCK_SEL
,
373 .val
= BD718XX_BUCK_SEL
,
379 .of_match
= of_match_ptr("BUCK2"),
380 .regulators_node
= of_match_ptr("regulators"),
382 .ops
= &bd718xx_dvs_buck_regulator_ops
,
383 .type
= REGULATOR_VOLTAGE
,
384 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
385 .linear_ranges
= bd718xx_dvs_buck_volts
,
386 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
387 .vsel_reg
= BD718XX_REG_BUCK2_VOLT_RUN
,
388 .vsel_mask
= DVS_BUCK_RUN_MASK
,
389 .enable_reg
= BD718XX_REG_BUCK2_CTRL
,
390 .enable_mask
= BD718XX_BUCK_EN
,
391 .owner
= THIS_MODULE
,
394 .reg
= BD718XX_REG_BUCK2_CTRL
,
395 .mask
= BD718XX_BUCK_SEL
,
396 .val
= BD718XX_BUCK_SEL
,
402 .of_match
= of_match_ptr("BUCK3"),
403 .regulators_node
= of_match_ptr("regulators"),
405 .ops
= &bd718xx_pickable_range_buck_ops
,
406 .type
= REGULATOR_VOLTAGE
,
407 .n_voltages
= BD71847_BUCK3_VOLTAGE_NUM
,
408 .linear_ranges
= bd71847_buck3_volts
,
410 ARRAY_SIZE(bd71847_buck3_volts
),
411 .vsel_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
412 .vsel_mask
= BD718XX_1ST_NODVS_BUCK_MASK
,
413 .vsel_range_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
414 .vsel_range_mask
= BD71847_BUCK3_RANGE_MASK
,
415 .linear_range_selectors
= bd71847_buck3_volt_range_sel
,
416 .enable_reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
417 .enable_mask
= BD718XX_BUCK_EN
,
418 .owner
= THIS_MODULE
,
421 .reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
422 .mask
= BD718XX_BUCK_SEL
,
423 .val
= BD718XX_BUCK_SEL
,
429 .of_match
= of_match_ptr("BUCK4"),
430 .regulators_node
= of_match_ptr("regulators"),
432 .ops
= &bd718xx_pickable_range_buck_ops
,
433 .type
= REGULATOR_VOLTAGE
,
434 .n_voltages
= BD71847_BUCK4_VOLTAGE_NUM
,
435 .linear_ranges
= bd71847_buck4_volts
,
437 ARRAY_SIZE(bd71847_buck4_volts
),
438 .enable_reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
439 .vsel_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
440 .vsel_mask
= BD71847_BUCK4_MASK
,
441 .vsel_range_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
442 .vsel_range_mask
= BD71847_BUCK4_RANGE_MASK
,
443 .linear_range_selectors
= bd71847_buck4_volt_range_sel
,
444 .enable_mask
= BD718XX_BUCK_EN
,
445 .owner
= THIS_MODULE
,
448 .reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
449 .mask
= BD718XX_BUCK_SEL
,
450 .val
= BD718XX_BUCK_SEL
,
456 .of_match
= of_match_ptr("BUCK5"),
457 .regulators_node
= of_match_ptr("regulators"),
459 .ops
= &bd718xx_buck_regulator_nolinear_ops
,
460 .type
= REGULATOR_VOLTAGE
,
461 .volt_table
= &bd718xx_3rd_nodvs_buck_volts
[0],
462 .n_voltages
= ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts
),
463 .vsel_reg
= BD718XX_REG_3RD_NODVS_BUCK_VOLT
,
464 .vsel_mask
= BD718XX_3RD_NODVS_BUCK_MASK
,
465 .enable_reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
466 .enable_mask
= BD718XX_BUCK_EN
,
467 .owner
= THIS_MODULE
,
470 .reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
471 .mask
= BD718XX_BUCK_SEL
,
472 .val
= BD718XX_BUCK_SEL
,
478 .of_match
= of_match_ptr("BUCK6"),
479 .regulators_node
= of_match_ptr("regulators"),
481 .ops
= &bd718xx_buck_regulator_ops
,
482 .type
= REGULATOR_VOLTAGE
,
483 .n_voltages
= BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM
,
484 .linear_ranges
= bd718xx_4th_nodvs_buck_volts
,
486 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts
),
487 .vsel_reg
= BD718XX_REG_4TH_NODVS_BUCK_VOLT
,
488 .vsel_mask
= BD718XX_4TH_NODVS_BUCK_MASK
,
489 .enable_reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
490 .enable_mask
= BD718XX_BUCK_EN
,
491 .owner
= THIS_MODULE
,
494 .reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
495 .mask
= BD718XX_BUCK_SEL
,
496 .val
= BD718XX_BUCK_SEL
,
502 .of_match
= of_match_ptr("LDO1"),
503 .regulators_node
= of_match_ptr("regulators"),
505 .ops
= &bd718xx_pickable_range_ldo_ops
,
506 .type
= REGULATOR_VOLTAGE
,
507 .n_voltages
= BD718XX_LDO1_VOLTAGE_NUM
,
508 .linear_ranges
= bd718xx_ldo1_volts
,
509 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo1_volts
),
510 .vsel_reg
= BD718XX_REG_LDO1_VOLT
,
511 .vsel_mask
= BD718XX_LDO1_MASK
,
512 .vsel_range_reg
= BD718XX_REG_LDO1_VOLT
,
513 .vsel_range_mask
= BD718XX_LDO1_RANGE_MASK
,
514 .linear_range_selectors
= bd718xx_ldo1_volt_range_sel
,
515 .enable_reg
= BD718XX_REG_LDO1_VOLT
,
516 .enable_mask
= BD718XX_LDO_EN
,
517 .owner
= THIS_MODULE
,
520 .reg
= BD718XX_REG_LDO1_VOLT
,
521 .mask
= BD718XX_LDO_SEL
,
522 .val
= BD718XX_LDO_SEL
,
528 .of_match
= of_match_ptr("LDO2"),
529 .regulators_node
= of_match_ptr("regulators"),
531 .ops
= &bd718xx_ldo_regulator_nolinear_ops
,
532 .type
= REGULATOR_VOLTAGE
,
533 .volt_table
= &ldo_2_volts
[0],
534 .vsel_reg
= BD718XX_REG_LDO2_VOLT
,
535 .vsel_mask
= BD718XX_LDO2_MASK
,
536 .n_voltages
= ARRAY_SIZE(ldo_2_volts
),
537 .enable_reg
= BD718XX_REG_LDO2_VOLT
,
538 .enable_mask
= BD718XX_LDO_EN
,
539 .owner
= THIS_MODULE
,
542 .reg
= BD718XX_REG_LDO2_VOLT
,
543 .mask
= BD718XX_LDO_SEL
,
544 .val
= BD718XX_LDO_SEL
,
550 .of_match
= of_match_ptr("LDO3"),
551 .regulators_node
= of_match_ptr("regulators"),
553 .ops
= &bd718xx_ldo_regulator_ops
,
554 .type
= REGULATOR_VOLTAGE
,
555 .n_voltages
= BD718XX_LDO3_VOLTAGE_NUM
,
556 .linear_ranges
= bd718xx_ldo3_volts
,
557 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo3_volts
),
558 .vsel_reg
= BD718XX_REG_LDO3_VOLT
,
559 .vsel_mask
= BD718XX_LDO3_MASK
,
560 .enable_reg
= BD718XX_REG_LDO3_VOLT
,
561 .enable_mask
= BD718XX_LDO_EN
,
562 .owner
= THIS_MODULE
,
565 .reg
= BD718XX_REG_LDO3_VOLT
,
566 .mask
= BD718XX_LDO_SEL
,
567 .val
= BD718XX_LDO_SEL
,
573 .of_match
= of_match_ptr("LDO4"),
574 .regulators_node
= of_match_ptr("regulators"),
576 .ops
= &bd718xx_ldo_regulator_ops
,
577 .type
= REGULATOR_VOLTAGE
,
578 .n_voltages
= BD718XX_LDO4_VOLTAGE_NUM
,
579 .linear_ranges
= bd718xx_ldo4_volts
,
580 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo4_volts
),
581 .vsel_reg
= BD718XX_REG_LDO4_VOLT
,
582 .vsel_mask
= BD718XX_LDO4_MASK
,
583 .enable_reg
= BD718XX_REG_LDO4_VOLT
,
584 .enable_mask
= BD718XX_LDO_EN
,
585 .owner
= THIS_MODULE
,
588 .reg
= BD718XX_REG_LDO4_VOLT
,
589 .mask
= BD718XX_LDO_SEL
,
590 .val
= BD718XX_LDO_SEL
,
596 .of_match
= of_match_ptr("LDO5"),
597 .regulators_node
= of_match_ptr("regulators"),
599 .ops
= &bd718xx_pickable_range_ldo_ops
,
600 .type
= REGULATOR_VOLTAGE
,
601 .n_voltages
= BD71847_LDO5_VOLTAGE_NUM
,
602 .linear_ranges
= bd71847_ldo5_volts
,
603 .n_linear_ranges
= ARRAY_SIZE(bd71847_ldo5_volts
),
604 .vsel_reg
= BD718XX_REG_LDO5_VOLT
,
605 .vsel_mask
= BD71847_LDO5_MASK
,
606 .vsel_range_reg
= BD718XX_REG_LDO5_VOLT
,
607 .vsel_range_mask
= BD71847_LDO5_RANGE_MASK
,
608 .linear_range_selectors
= bd71847_ldo5_volt_range_sel
,
609 .enable_reg
= BD718XX_REG_LDO5_VOLT
,
610 .enable_mask
= BD718XX_LDO_EN
,
611 .owner
= THIS_MODULE
,
614 .reg
= BD718XX_REG_LDO5_VOLT
,
615 .mask
= BD718XX_LDO_SEL
,
616 .val
= BD718XX_LDO_SEL
,
622 .of_match
= of_match_ptr("LDO6"),
623 .regulators_node
= of_match_ptr("regulators"),
625 .ops
= &bd718xx_ldo_regulator_ops
,
626 .type
= REGULATOR_VOLTAGE
,
627 .n_voltages
= BD718XX_LDO6_VOLTAGE_NUM
,
628 .linear_ranges
= bd718xx_ldo6_volts
,
629 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo6_volts
),
630 /* LDO6 is supplied by buck5 */
631 .supply_name
= "buck5",
632 .vsel_reg
= BD718XX_REG_LDO6_VOLT
,
633 .vsel_mask
= BD718XX_LDO6_MASK
,
634 .enable_reg
= BD718XX_REG_LDO6_VOLT
,
635 .enable_mask
= BD718XX_LDO_EN
,
636 .owner
= THIS_MODULE
,
639 .reg
= BD718XX_REG_LDO6_VOLT
,
640 .mask
= BD718XX_LDO_SEL
,
641 .val
= BD718XX_LDO_SEL
,
646 static const struct bd718xx_regulator_data bd71837_regulators
[] = {
650 .of_match
= of_match_ptr("BUCK1"),
651 .regulators_node
= of_match_ptr("regulators"),
653 .ops
= &bd718xx_dvs_buck_regulator_ops
,
654 .type
= REGULATOR_VOLTAGE
,
655 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
656 .linear_ranges
= bd718xx_dvs_buck_volts
,
657 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
658 .vsel_reg
= BD718XX_REG_BUCK1_VOLT_RUN
,
659 .vsel_mask
= DVS_BUCK_RUN_MASK
,
660 .enable_reg
= BD718XX_REG_BUCK1_CTRL
,
661 .enable_mask
= BD718XX_BUCK_EN
,
662 .owner
= THIS_MODULE
,
665 .reg
= BD718XX_REG_BUCK1_CTRL
,
666 .mask
= BD718XX_BUCK_SEL
,
667 .val
= BD718XX_BUCK_SEL
,
673 .of_match
= of_match_ptr("BUCK2"),
674 .regulators_node
= of_match_ptr("regulators"),
676 .ops
= &bd718xx_dvs_buck_regulator_ops
,
677 .type
= REGULATOR_VOLTAGE
,
678 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
679 .linear_ranges
= bd718xx_dvs_buck_volts
,
680 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
681 .vsel_reg
= BD718XX_REG_BUCK2_VOLT_RUN
,
682 .vsel_mask
= DVS_BUCK_RUN_MASK
,
683 .enable_reg
= BD718XX_REG_BUCK2_CTRL
,
684 .enable_mask
= BD718XX_BUCK_EN
,
685 .owner
= THIS_MODULE
,
688 .reg
= BD718XX_REG_BUCK2_CTRL
,
689 .mask
= BD718XX_BUCK_SEL
,
690 .val
= BD718XX_BUCK_SEL
,
696 .of_match
= of_match_ptr("BUCK3"),
697 .regulators_node
= of_match_ptr("regulators"),
699 .ops
= &bd718xx_dvs_buck_regulator_ops
,
700 .type
= REGULATOR_VOLTAGE
,
701 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
702 .linear_ranges
= bd718xx_dvs_buck_volts
,
703 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
704 .vsel_reg
= BD71837_REG_BUCK3_VOLT_RUN
,
705 .vsel_mask
= DVS_BUCK_RUN_MASK
,
706 .enable_reg
= BD71837_REG_BUCK3_CTRL
,
707 .enable_mask
= BD718XX_BUCK_EN
,
708 .owner
= THIS_MODULE
,
711 .reg
= BD71837_REG_BUCK3_CTRL
,
712 .mask
= BD718XX_BUCK_SEL
,
713 .val
= BD718XX_BUCK_SEL
,
719 .of_match
= of_match_ptr("BUCK4"),
720 .regulators_node
= of_match_ptr("regulators"),
722 .ops
= &bd718xx_dvs_buck_regulator_ops
,
723 .type
= REGULATOR_VOLTAGE
,
724 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
725 .linear_ranges
= bd718xx_dvs_buck_volts
,
726 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
727 .vsel_reg
= BD71837_REG_BUCK4_VOLT_RUN
,
728 .vsel_mask
= DVS_BUCK_RUN_MASK
,
729 .enable_reg
= BD71837_REG_BUCK4_CTRL
,
730 .enable_mask
= BD718XX_BUCK_EN
,
731 .owner
= THIS_MODULE
,
734 .reg
= BD71837_REG_BUCK4_CTRL
,
735 .mask
= BD718XX_BUCK_SEL
,
736 .val
= BD718XX_BUCK_SEL
,
742 .of_match
= of_match_ptr("BUCK5"),
743 .regulators_node
= of_match_ptr("regulators"),
745 .ops
= &bd718xx_pickable_range_buck_ops
,
746 .type
= REGULATOR_VOLTAGE
,
747 .n_voltages
= BD71837_BUCK5_VOLTAGE_NUM
,
748 .linear_ranges
= bd71837_buck5_volts
,
750 ARRAY_SIZE(bd71837_buck5_volts
),
751 .vsel_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
752 .vsel_mask
= BD71837_BUCK5_MASK
,
753 .vsel_range_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
754 .vsel_range_mask
= BD71837_BUCK5_RANGE_MASK
,
755 .linear_range_selectors
= bd71837_buck5_volt_range_sel
,
756 .enable_reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
757 .enable_mask
= BD718XX_BUCK_EN
,
758 .owner
= THIS_MODULE
,
761 .reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
762 .mask
= BD718XX_BUCK_SEL
,
763 .val
= BD718XX_BUCK_SEL
,
769 .of_match
= of_match_ptr("BUCK6"),
770 .regulators_node
= of_match_ptr("regulators"),
772 .ops
= &bd718xx_buck_regulator_ops
,
773 .type
= REGULATOR_VOLTAGE
,
774 .n_voltages
= BD71837_BUCK6_VOLTAGE_NUM
,
775 .linear_ranges
= bd71837_buck6_volts
,
777 ARRAY_SIZE(bd71837_buck6_volts
),
778 .vsel_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
779 .vsel_mask
= BD71837_BUCK6_MASK
,
780 .enable_reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
781 .enable_mask
= BD718XX_BUCK_EN
,
782 .owner
= THIS_MODULE
,
785 .reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
786 .mask
= BD718XX_BUCK_SEL
,
787 .val
= BD718XX_BUCK_SEL
,
793 .of_match
= of_match_ptr("BUCK7"),
794 .regulators_node
= of_match_ptr("regulators"),
796 .ops
= &bd718xx_buck_regulator_nolinear_ops
,
797 .type
= REGULATOR_VOLTAGE
,
798 .volt_table
= &bd718xx_3rd_nodvs_buck_volts
[0],
799 .n_voltages
= ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts
),
800 .vsel_reg
= BD718XX_REG_3RD_NODVS_BUCK_VOLT
,
801 .vsel_mask
= BD718XX_3RD_NODVS_BUCK_MASK
,
802 .enable_reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
803 .enable_mask
= BD718XX_BUCK_EN
,
804 .owner
= THIS_MODULE
,
807 .reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
808 .mask
= BD718XX_BUCK_SEL
,
809 .val
= BD718XX_BUCK_SEL
,
815 .of_match
= of_match_ptr("BUCK8"),
816 .regulators_node
= of_match_ptr("regulators"),
818 .ops
= &bd718xx_buck_regulator_ops
,
819 .type
= REGULATOR_VOLTAGE
,
820 .n_voltages
= BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM
,
821 .linear_ranges
= bd718xx_4th_nodvs_buck_volts
,
823 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts
),
824 .vsel_reg
= BD718XX_REG_4TH_NODVS_BUCK_VOLT
,
825 .vsel_mask
= BD718XX_4TH_NODVS_BUCK_MASK
,
826 .enable_reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
827 .enable_mask
= BD718XX_BUCK_EN
,
828 .owner
= THIS_MODULE
,
831 .reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
832 .mask
= BD718XX_BUCK_SEL
,
833 .val
= BD718XX_BUCK_SEL
,
839 .of_match
= of_match_ptr("LDO1"),
840 .regulators_node
= of_match_ptr("regulators"),
842 .ops
= &bd718xx_pickable_range_ldo_ops
,
843 .type
= REGULATOR_VOLTAGE
,
844 .n_voltages
= BD718XX_LDO1_VOLTAGE_NUM
,
845 .linear_ranges
= bd718xx_ldo1_volts
,
846 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo1_volts
),
847 .vsel_reg
= BD718XX_REG_LDO1_VOLT
,
848 .vsel_mask
= BD718XX_LDO1_MASK
,
849 .vsel_range_reg
= BD718XX_REG_LDO1_VOLT
,
850 .vsel_range_mask
= BD718XX_LDO1_RANGE_MASK
,
851 .linear_range_selectors
= bd718xx_ldo1_volt_range_sel
,
852 .enable_reg
= BD718XX_REG_LDO1_VOLT
,
853 .enable_mask
= BD718XX_LDO_EN
,
854 .owner
= THIS_MODULE
,
857 .reg
= BD718XX_REG_LDO1_VOLT
,
858 .mask
= BD718XX_LDO_SEL
,
859 .val
= BD718XX_LDO_SEL
,
865 .of_match
= of_match_ptr("LDO2"),
866 .regulators_node
= of_match_ptr("regulators"),
868 .ops
= &bd718xx_ldo_regulator_nolinear_ops
,
869 .type
= REGULATOR_VOLTAGE
,
870 .volt_table
= &ldo_2_volts
[0],
871 .vsel_reg
= BD718XX_REG_LDO2_VOLT
,
872 .vsel_mask
= BD718XX_LDO2_MASK
,
873 .n_voltages
= ARRAY_SIZE(ldo_2_volts
),
874 .enable_reg
= BD718XX_REG_LDO2_VOLT
,
875 .enable_mask
= BD718XX_LDO_EN
,
876 .owner
= THIS_MODULE
,
879 .reg
= BD718XX_REG_LDO2_VOLT
,
880 .mask
= BD718XX_LDO_SEL
,
881 .val
= BD718XX_LDO_SEL
,
887 .of_match
= of_match_ptr("LDO3"),
888 .regulators_node
= of_match_ptr("regulators"),
890 .ops
= &bd718xx_ldo_regulator_ops
,
891 .type
= REGULATOR_VOLTAGE
,
892 .n_voltages
= BD718XX_LDO3_VOLTAGE_NUM
,
893 .linear_ranges
= bd718xx_ldo3_volts
,
894 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo3_volts
),
895 .vsel_reg
= BD718XX_REG_LDO3_VOLT
,
896 .vsel_mask
= BD718XX_LDO3_MASK
,
897 .enable_reg
= BD718XX_REG_LDO3_VOLT
,
898 .enable_mask
= BD718XX_LDO_EN
,
899 .owner
= THIS_MODULE
,
902 .reg
= BD718XX_REG_LDO3_VOLT
,
903 .mask
= BD718XX_LDO_SEL
,
904 .val
= BD718XX_LDO_SEL
,
910 .of_match
= of_match_ptr("LDO4"),
911 .regulators_node
= of_match_ptr("regulators"),
913 .ops
= &bd718xx_ldo_regulator_ops
,
914 .type
= REGULATOR_VOLTAGE
,
915 .n_voltages
= BD718XX_LDO4_VOLTAGE_NUM
,
916 .linear_ranges
= bd718xx_ldo4_volts
,
917 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo4_volts
),
918 .vsel_reg
= BD718XX_REG_LDO4_VOLT
,
919 .vsel_mask
= BD718XX_LDO4_MASK
,
920 .enable_reg
= BD718XX_REG_LDO4_VOLT
,
921 .enable_mask
= BD718XX_LDO_EN
,
922 .owner
= THIS_MODULE
,
925 .reg
= BD718XX_REG_LDO4_VOLT
,
926 .mask
= BD718XX_LDO_SEL
,
927 .val
= BD718XX_LDO_SEL
,
933 .of_match
= of_match_ptr("LDO5"),
934 .regulators_node
= of_match_ptr("regulators"),
936 .ops
= &bd718xx_ldo_regulator_ops
,
937 .type
= REGULATOR_VOLTAGE
,
938 .n_voltages
= BD71837_LDO5_VOLTAGE_NUM
,
939 .linear_ranges
= bd71837_ldo5_volts
,
940 .n_linear_ranges
= ARRAY_SIZE(bd71837_ldo5_volts
),
941 /* LDO5 is supplied by buck6 */
942 .supply_name
= "buck6",
943 .vsel_reg
= BD718XX_REG_LDO5_VOLT
,
944 .vsel_mask
= BD71837_LDO5_MASK
,
945 .enable_reg
= BD718XX_REG_LDO5_VOLT
,
946 .enable_mask
= BD718XX_LDO_EN
,
947 .owner
= THIS_MODULE
,
950 .reg
= BD718XX_REG_LDO5_VOLT
,
951 .mask
= BD718XX_LDO_SEL
,
952 .val
= BD718XX_LDO_SEL
,
954 .additional_inits
= bd71837_ldo5_inits
,
955 .additional_init_amnt
= ARRAY_SIZE(bd71837_ldo5_inits
),
960 .of_match
= of_match_ptr("LDO6"),
961 .regulators_node
= of_match_ptr("regulators"),
963 .ops
= &bd718xx_ldo_regulator_ops
,
964 .type
= REGULATOR_VOLTAGE
,
965 .n_voltages
= BD718XX_LDO6_VOLTAGE_NUM
,
966 .linear_ranges
= bd718xx_ldo6_volts
,
967 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo6_volts
),
968 /* LDO6 is supplied by buck7 */
969 .supply_name
= "buck7",
970 .vsel_reg
= BD718XX_REG_LDO6_VOLT
,
971 .vsel_mask
= BD718XX_LDO6_MASK
,
972 .enable_reg
= BD718XX_REG_LDO6_VOLT
,
973 .enable_mask
= BD718XX_LDO_EN
,
974 .owner
= THIS_MODULE
,
977 .reg
= BD718XX_REG_LDO6_VOLT
,
978 .mask
= BD718XX_LDO_SEL
,
979 .val
= BD718XX_LDO_SEL
,
981 .additional_inits
= bd71837_ldo6_inits
,
982 .additional_init_amnt
= ARRAY_SIZE(bd71837_ldo6_inits
),
987 .of_match
= of_match_ptr("LDO7"),
988 .regulators_node
= of_match_ptr("regulators"),
990 .ops
= &bd718xx_ldo_regulator_ops
,
991 .type
= REGULATOR_VOLTAGE
,
992 .n_voltages
= BD71837_LDO7_VOLTAGE_NUM
,
993 .linear_ranges
= bd71837_ldo7_volts
,
994 .n_linear_ranges
= ARRAY_SIZE(bd71837_ldo7_volts
),
995 .vsel_reg
= BD71837_REG_LDO7_VOLT
,
996 .vsel_mask
= BD71837_LDO7_MASK
,
997 .enable_reg
= BD71837_REG_LDO7_VOLT
,
998 .enable_mask
= BD718XX_LDO_EN
,
999 .owner
= THIS_MODULE
,
1002 .reg
= BD71837_REG_LDO7_VOLT
,
1003 .mask
= BD718XX_LDO_SEL
,
1004 .val
= BD718XX_LDO_SEL
,
1009 struct bd718xx_pmic_inits
{
1010 const struct bd718xx_regulator_data (*r_datas
)[];
1011 unsigned int r_amount
;
1014 static int bd718xx_probe(struct platform_device
*pdev
)
1016 struct bd718xx
*mfd
;
1017 struct regulator_config config
= { 0 };
1018 struct bd718xx_pmic_inits pmic_regulators
[] = {
1019 [BD718XX_TYPE_BD71837
] = {
1020 .r_datas
= &bd71837_regulators
,
1021 .r_amount
= ARRAY_SIZE(bd71837_regulators
),
1023 [BD718XX_TYPE_BD71847
] = {
1024 .r_datas
= &bd71847_regulators
,
1025 .r_amount
= ARRAY_SIZE(bd71847_regulators
),
1031 mfd
= dev_get_drvdata(pdev
->dev
.parent
);
1033 dev_err(&pdev
->dev
, "No MFD driver data\n");
1038 if (mfd
->chip_type
>= BD718XX_TYPE_AMOUNT
||
1039 !pmic_regulators
[mfd
->chip_type
].r_datas
) {
1040 dev_err(&pdev
->dev
, "Unsupported chip type\n");
1045 /* Register LOCK release */
1046 err
= regmap_update_bits(mfd
->regmap
, BD718XX_REG_REGLOCK
,
1047 (REGLOCK_PWRSEQ
| REGLOCK_VREG
), 0);
1049 dev_err(&pdev
->dev
, "Failed to unlock PMIC (%d)\n", err
);
1052 dev_dbg(&pdev
->dev
, "Unlocked lock register 0x%x\n",
1053 BD718XX_REG_REGLOCK
);
1056 for (i
= 0; i
< pmic_regulators
[mfd
->chip_type
].r_amount
; i
++) {
1058 const struct regulator_desc
*desc
;
1059 struct regulator_dev
*rdev
;
1060 const struct bd718xx_regulator_data
*r
;
1062 r
= &(*pmic_regulators
[mfd
->chip_type
].r_datas
)[i
];
1065 config
.dev
= pdev
->dev
.parent
;
1066 config
.regmap
= mfd
->regmap
;
1068 rdev
= devm_regulator_register(&pdev
->dev
, desc
, &config
);
1071 "failed to register %s regulator\n",
1073 err
= PTR_ERR(rdev
);
1076 /* Regulator register gets the regulator constraints and
1077 * applies them (set_machine_constraints). This should have
1078 * turned the control register(s) to correct values and we
1079 * can now switch the control from PMIC state machine to the
1080 * register interface
1082 err
= regmap_update_bits(mfd
->regmap
, r
->init
.reg
,
1083 r
->init
.mask
, r
->init
.val
);
1086 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1090 for (j
= 0; j
< r
->additional_init_amnt
; j
++) {
1091 err
= regmap_update_bits(mfd
->regmap
,
1092 r
->additional_inits
[j
].reg
,
1093 r
->additional_inits
[j
].mask
,
1094 r
->additional_inits
[j
].val
);
1097 "Buck (%s) initialization failed\n",
1108 static struct platform_driver bd718xx_regulator
= {
1110 .name
= "bd718xx-pmic",
1112 .probe
= bd718xx_probe
,
1115 module_platform_driver(bd718xx_regulator
);
1117 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1118 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1119 MODULE_LICENSE("GPL");