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>
13 #include <linux/platform_device.h>
14 #include <linux/regulator/driver.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/regulator/of_regulator.h>
17 #include <linux/slab.h>
21 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
22 * 00: 10.00mV/usec 10mV 1uS
23 * 01: 5.00mV/usec 10mV 2uS
24 * 10: 2.50mV/usec 10mV 4uS
25 * 11: 1.25mV/usec 10mV 8uS
27 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev
*rdev
,
30 int id
= rdev
->desc
->id
;
31 unsigned int ramp_value
= BUCK_RAMPRATE_10P00MV
;
33 dev_dbg(&rdev
->dev
, "Buck[%d] Set Ramp = %d\n", id
+ 1,
37 ramp_value
= BUCK_RAMPRATE_1P25MV
;
40 ramp_value
= BUCK_RAMPRATE_2P50MV
;
43 ramp_value
= BUCK_RAMPRATE_5P00MV
;
46 ramp_value
= BUCK_RAMPRATE_10P00MV
;
49 ramp_value
= BUCK_RAMPRATE_10P00MV
;
51 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
52 rdev
->desc
->name
, ramp_delay
);
55 return regmap_update_bits(rdev
->regmap
, BD718XX_REG_BUCK1_CTRL
+ id
,
56 BUCK_RAMPRATE_MASK
, ramp_value
<< 6);
59 /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
60 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
61 * is changed. Hence we return -EBUSY for these if voltage is changed
62 * when BUCK/LDO is enabled.
64 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev
*rdev
,
67 if (regulator_is_enabled_regmap(rdev
))
70 return regulator_set_voltage_sel_regmap(rdev
, sel
);
73 static int bd718xx_set_voltage_sel_pickable_restricted(
74 struct regulator_dev
*rdev
, unsigned int sel
)
76 if (regulator_is_enabled_regmap(rdev
))
79 return regulator_set_voltage_sel_pickable_regmap(rdev
, sel
);
82 static struct regulator_ops bd718xx_pickable_range_ldo_ops
= {
83 .enable
= regulator_enable_regmap
,
84 .disable
= regulator_disable_regmap
,
85 .is_enabled
= regulator_is_enabled_regmap
,
86 .list_voltage
= regulator_list_voltage_pickable_linear_range
,
87 .set_voltage_sel
= bd718xx_set_voltage_sel_pickable_restricted
,
88 .get_voltage_sel
= regulator_get_voltage_sel_pickable_regmap
,
91 static struct regulator_ops bd718xx_pickable_range_buck_ops
= {
92 .enable
= regulator_enable_regmap
,
93 .disable
= regulator_disable_regmap
,
94 .is_enabled
= regulator_is_enabled_regmap
,
95 .list_voltage
= regulator_list_voltage_pickable_linear_range
,
96 .set_voltage_sel
= bd718xx_set_voltage_sel_pickable_restricted
,
97 .get_voltage_sel
= regulator_get_voltage_sel_pickable_regmap
,
98 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
101 static struct regulator_ops bd718xx_ldo_regulator_ops
= {
102 .enable
= regulator_enable_regmap
,
103 .disable
= regulator_disable_regmap
,
104 .is_enabled
= regulator_is_enabled_regmap
,
105 .list_voltage
= regulator_list_voltage_linear_range
,
106 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
107 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
110 static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops
= {
111 .enable
= regulator_enable_regmap
,
112 .disable
= regulator_disable_regmap
,
113 .is_enabled
= regulator_is_enabled_regmap
,
114 .list_voltage
= regulator_list_voltage_table
,
115 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
116 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
119 static struct regulator_ops bd718xx_buck_regulator_ops
= {
120 .enable
= regulator_enable_regmap
,
121 .disable
= regulator_disable_regmap
,
122 .is_enabled
= regulator_is_enabled_regmap
,
123 .list_voltage
= regulator_list_voltage_linear_range
,
124 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
125 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
126 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
129 static struct regulator_ops bd718xx_buck_regulator_nolinear_ops
= {
130 .enable
= regulator_enable_regmap
,
131 .disable
= regulator_disable_regmap
,
132 .is_enabled
= regulator_is_enabled_regmap
,
133 .list_voltage
= regulator_list_voltage_table
,
134 .map_voltage
= regulator_map_voltage_ascend
,
135 .set_voltage_sel
= bd718xx_set_voltage_sel_restricted
,
136 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
137 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
140 static struct regulator_ops bd718xx_dvs_buck_regulator_ops
= {
141 .enable
= regulator_enable_regmap
,
142 .disable
= regulator_disable_regmap
,
143 .is_enabled
= regulator_is_enabled_regmap
,
144 .list_voltage
= regulator_list_voltage_linear_range
,
145 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
146 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
147 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
148 .set_ramp_delay
= bd718xx_buck1234_set_ramp_delay
,
152 * BD71837 BUCK1/2/3/4
154 * 0.70 to 1.30V (10mV step)
156 static const struct regulator_linear_range bd718xx_dvs_buck_volts
[] = {
157 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
158 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
163 * 0.7V to 1.35V (range 0)
165 * 0.675 to 1.325 (range 1)
167 static const struct regulator_linear_range bd71837_buck5_volts
[] = {
168 /* Ranges when VOLT_SEL bit is 0 */
169 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
170 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
171 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
172 /* Ranges when VOLT_SEL bit is 1 */
173 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
174 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
175 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
179 * Range selector for first 3 linear ranges is 0x0
180 * and 0x1 for last 3 ranges.
182 static const unsigned int bd71837_buck5_volt_range_sel
[] = {
183 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
189 static const struct regulator_linear_range bd71847_buck3_volts
[] = {
190 /* Ranges when VOLT_SEL bits are 00 */
191 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
192 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
193 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
194 /* Ranges when VOLT_SEL bits are 01 */
195 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
196 /* Ranges when VOLT_SEL bits are 11 */
197 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
198 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
199 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
202 static const unsigned int bd71847_buck3_volt_range_sel
[] = {
203 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
206 static const struct regulator_linear_range bd71847_buck4_volts
[] = {
207 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
208 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
211 static const unsigned int bd71847_buck4_volt_range_sel
[] = { 0x0, 0x40 };
215 * 3.0V to 3.3V (step 100mV)
217 static const struct regulator_linear_range bd71837_buck6_volts
[] = {
218 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
227 * 011 = 1.8V (Initial)
233 static const unsigned int bd718xx_3rd_nodvs_buck_volts
[] = {
234 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
239 * 0.8V to 1.40V (step 10mV)
241 static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts
[] = {
242 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
247 * 3.0 to 3.3V (100mV step)
249 static const struct regulator_linear_range bd718xx_ldo1_volts
[] = {
250 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
251 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
254 static const unsigned int bd718xx_ldo1_volt_range_sel
[] = { 0x0, 0x20 };
260 static const unsigned int ldo_2_volts
[] = {
266 * 1.8 to 3.3V (100mV step)
268 static const struct regulator_linear_range bd718xx_ldo3_volts
[] = {
269 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
274 * 0.9 to 1.8V (100mV step)
276 static const struct regulator_linear_range bd718xx_ldo4_volts
[] = {
277 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
282 * 1.8 to 3.3V (100mV step)
284 static const struct regulator_linear_range bd71837_ldo5_volts
[] = {
285 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
290 * 1.8 to 3.3V (100mV step)
292 static const struct regulator_linear_range bd71847_ldo5_volts
[] = {
293 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
294 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
297 static const unsigned int bd71847_ldo5_volt_range_sel
[] = { 0x0, 0x20 };
301 * 0.9 to 1.8V (100mV step)
303 static const struct regulator_linear_range bd718xx_ldo6_volts
[] = {
304 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
309 * 1.8 to 3.3V (100mV step)
311 static const struct regulator_linear_range bd71837_ldo7_volts
[] = {
312 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
320 struct bd718xx_regulator_data
{
321 struct regulator_desc desc
;
322 const struct reg_init init
;
323 const struct reg_init
*additional_inits
;
324 int additional_init_amnt
;
328 * There is a HW quirk in BD71837. The shutdown sequence timings for
329 * bucks/LDOs which are controlled via register interface are changed.
330 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
331 * beginning of shut-down sequence. As bucks 6 and 7 are parent
332 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
333 * monitoring to errorneously detect under voltage and force PMIC to
334 * emergency state instead of poweroff. In order to avoid this we
335 * disable voltage monitoring for LDO5 and LDO6
337 static const struct reg_init bd71837_ldo5_inits
[] = {
339 .reg
= BD718XX_REG_MVRFLTMASK2
,
340 .mask
= BD718XX_LDO5_VRMON80
,
341 .val
= BD718XX_LDO5_VRMON80
,
345 static const struct reg_init bd71837_ldo6_inits
[] = {
347 .reg
= BD718XX_REG_MVRFLTMASK2
,
348 .mask
= BD718XX_LDO6_VRMON80
,
349 .val
= BD718XX_LDO6_VRMON80
,
353 static const struct bd718xx_regulator_data bd71847_regulators
[] = {
357 .of_match
= of_match_ptr("BUCK1"),
358 .regulators_node
= of_match_ptr("regulators"),
360 .ops
= &bd718xx_dvs_buck_regulator_ops
,
361 .type
= REGULATOR_VOLTAGE
,
362 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
363 .linear_ranges
= bd718xx_dvs_buck_volts
,
365 ARRAY_SIZE(bd718xx_dvs_buck_volts
),
366 .vsel_reg
= BD718XX_REG_BUCK1_VOLT_RUN
,
367 .vsel_mask
= DVS_BUCK_RUN_MASK
,
368 .enable_reg
= BD718XX_REG_BUCK1_CTRL
,
369 .enable_mask
= BD718XX_BUCK_EN
,
370 .owner
= THIS_MODULE
,
373 .reg
= BD718XX_REG_BUCK1_CTRL
,
374 .mask
= BD718XX_BUCK_SEL
,
375 .val
= BD718XX_BUCK_SEL
,
381 .of_match
= of_match_ptr("BUCK2"),
382 .regulators_node
= of_match_ptr("regulators"),
384 .ops
= &bd718xx_dvs_buck_regulator_ops
,
385 .type
= REGULATOR_VOLTAGE
,
386 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
387 .linear_ranges
= bd718xx_dvs_buck_volts
,
388 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
389 .vsel_reg
= BD718XX_REG_BUCK2_VOLT_RUN
,
390 .vsel_mask
= DVS_BUCK_RUN_MASK
,
391 .enable_reg
= BD718XX_REG_BUCK2_CTRL
,
392 .enable_mask
= BD718XX_BUCK_EN
,
393 .owner
= THIS_MODULE
,
396 .reg
= BD718XX_REG_BUCK2_CTRL
,
397 .mask
= BD718XX_BUCK_SEL
,
398 .val
= BD718XX_BUCK_SEL
,
404 .of_match
= of_match_ptr("BUCK3"),
405 .regulators_node
= of_match_ptr("regulators"),
407 .ops
= &bd718xx_pickable_range_buck_ops
,
408 .type
= REGULATOR_VOLTAGE
,
409 .n_voltages
= BD71847_BUCK3_VOLTAGE_NUM
,
410 .linear_ranges
= bd71847_buck3_volts
,
412 ARRAY_SIZE(bd71847_buck3_volts
),
413 .vsel_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
414 .vsel_mask
= BD718XX_1ST_NODVS_BUCK_MASK
,
415 .vsel_range_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
416 .vsel_range_mask
= BD71847_BUCK3_RANGE_MASK
,
417 .linear_range_selectors
= bd71847_buck3_volt_range_sel
,
418 .enable_reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
419 .enable_mask
= BD718XX_BUCK_EN
,
420 .owner
= THIS_MODULE
,
423 .reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
424 .mask
= BD718XX_BUCK_SEL
,
425 .val
= BD718XX_BUCK_SEL
,
431 .of_match
= of_match_ptr("BUCK4"),
432 .regulators_node
= of_match_ptr("regulators"),
434 .ops
= &bd718xx_pickable_range_buck_ops
,
435 .type
= REGULATOR_VOLTAGE
,
436 .n_voltages
= BD71847_BUCK4_VOLTAGE_NUM
,
437 .linear_ranges
= bd71847_buck4_volts
,
439 ARRAY_SIZE(bd71847_buck4_volts
),
440 .enable_reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
441 .vsel_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
442 .vsel_mask
= BD71847_BUCK4_MASK
,
443 .vsel_range_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
444 .vsel_range_mask
= BD71847_BUCK4_RANGE_MASK
,
445 .linear_range_selectors
= bd71847_buck4_volt_range_sel
,
446 .enable_mask
= BD718XX_BUCK_EN
,
447 .owner
= THIS_MODULE
,
450 .reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
451 .mask
= BD718XX_BUCK_SEL
,
452 .val
= BD718XX_BUCK_SEL
,
458 .of_match
= of_match_ptr("BUCK5"),
459 .regulators_node
= of_match_ptr("regulators"),
461 .ops
= &bd718xx_buck_regulator_nolinear_ops
,
462 .type
= REGULATOR_VOLTAGE
,
463 .volt_table
= &bd718xx_3rd_nodvs_buck_volts
[0],
464 .n_voltages
= ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts
),
465 .vsel_reg
= BD718XX_REG_3RD_NODVS_BUCK_VOLT
,
466 .vsel_mask
= BD718XX_3RD_NODVS_BUCK_MASK
,
467 .enable_reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
468 .enable_mask
= BD718XX_BUCK_EN
,
469 .owner
= THIS_MODULE
,
472 .reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
473 .mask
= BD718XX_BUCK_SEL
,
474 .val
= BD718XX_BUCK_SEL
,
480 .of_match
= of_match_ptr("BUCK6"),
481 .regulators_node
= of_match_ptr("regulators"),
483 .ops
= &bd718xx_buck_regulator_ops
,
484 .type
= REGULATOR_VOLTAGE
,
485 .n_voltages
= BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM
,
486 .linear_ranges
= bd718xx_4th_nodvs_buck_volts
,
488 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts
),
489 .vsel_reg
= BD718XX_REG_4TH_NODVS_BUCK_VOLT
,
490 .vsel_mask
= BD718XX_4TH_NODVS_BUCK_MASK
,
491 .enable_reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
492 .enable_mask
= BD718XX_BUCK_EN
,
493 .owner
= THIS_MODULE
,
496 .reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
497 .mask
= BD718XX_BUCK_SEL
,
498 .val
= BD718XX_BUCK_SEL
,
504 .of_match
= of_match_ptr("LDO1"),
505 .regulators_node
= of_match_ptr("regulators"),
507 .ops
= &bd718xx_pickable_range_ldo_ops
,
508 .type
= REGULATOR_VOLTAGE
,
509 .n_voltages
= BD718XX_LDO1_VOLTAGE_NUM
,
510 .linear_ranges
= bd718xx_ldo1_volts
,
511 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo1_volts
),
512 .vsel_reg
= BD718XX_REG_LDO1_VOLT
,
513 .vsel_mask
= BD718XX_LDO1_MASK
,
514 .vsel_range_reg
= BD718XX_REG_LDO1_VOLT
,
515 .vsel_range_mask
= BD718XX_LDO1_RANGE_MASK
,
516 .linear_range_selectors
= bd718xx_ldo1_volt_range_sel
,
517 .enable_reg
= BD718XX_REG_LDO1_VOLT
,
518 .enable_mask
= BD718XX_LDO_EN
,
519 .owner
= THIS_MODULE
,
522 .reg
= BD718XX_REG_LDO1_VOLT
,
523 .mask
= BD718XX_LDO_SEL
,
524 .val
= BD718XX_LDO_SEL
,
530 .of_match
= of_match_ptr("LDO2"),
531 .regulators_node
= of_match_ptr("regulators"),
533 .ops
= &bd718xx_ldo_regulator_nolinear_ops
,
534 .type
= REGULATOR_VOLTAGE
,
535 .volt_table
= &ldo_2_volts
[0],
536 .vsel_reg
= BD718XX_REG_LDO2_VOLT
,
537 .vsel_mask
= BD718XX_LDO2_MASK
,
538 .n_voltages
= ARRAY_SIZE(ldo_2_volts
),
539 .enable_reg
= BD718XX_REG_LDO2_VOLT
,
540 .enable_mask
= BD718XX_LDO_EN
,
541 .owner
= THIS_MODULE
,
544 .reg
= BD718XX_REG_LDO2_VOLT
,
545 .mask
= BD718XX_LDO_SEL
,
546 .val
= BD718XX_LDO_SEL
,
552 .of_match
= of_match_ptr("LDO3"),
553 .regulators_node
= of_match_ptr("regulators"),
555 .ops
= &bd718xx_ldo_regulator_ops
,
556 .type
= REGULATOR_VOLTAGE
,
557 .n_voltages
= BD718XX_LDO3_VOLTAGE_NUM
,
558 .linear_ranges
= bd718xx_ldo3_volts
,
559 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo3_volts
),
560 .vsel_reg
= BD718XX_REG_LDO3_VOLT
,
561 .vsel_mask
= BD718XX_LDO3_MASK
,
562 .enable_reg
= BD718XX_REG_LDO3_VOLT
,
563 .enable_mask
= BD718XX_LDO_EN
,
564 .owner
= THIS_MODULE
,
567 .reg
= BD718XX_REG_LDO3_VOLT
,
568 .mask
= BD718XX_LDO_SEL
,
569 .val
= BD718XX_LDO_SEL
,
575 .of_match
= of_match_ptr("LDO4"),
576 .regulators_node
= of_match_ptr("regulators"),
578 .ops
= &bd718xx_ldo_regulator_ops
,
579 .type
= REGULATOR_VOLTAGE
,
580 .n_voltages
= BD718XX_LDO4_VOLTAGE_NUM
,
581 .linear_ranges
= bd718xx_ldo4_volts
,
582 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo4_volts
),
583 .vsel_reg
= BD718XX_REG_LDO4_VOLT
,
584 .vsel_mask
= BD718XX_LDO4_MASK
,
585 .enable_reg
= BD718XX_REG_LDO4_VOLT
,
586 .enable_mask
= BD718XX_LDO_EN
,
587 .owner
= THIS_MODULE
,
590 .reg
= BD718XX_REG_LDO4_VOLT
,
591 .mask
= BD718XX_LDO_SEL
,
592 .val
= BD718XX_LDO_SEL
,
598 .of_match
= of_match_ptr("LDO5"),
599 .regulators_node
= of_match_ptr("regulators"),
601 .ops
= &bd718xx_pickable_range_ldo_ops
,
602 .type
= REGULATOR_VOLTAGE
,
603 .n_voltages
= BD71847_LDO5_VOLTAGE_NUM
,
604 .linear_ranges
= bd71847_ldo5_volts
,
605 .n_linear_ranges
= ARRAY_SIZE(bd71847_ldo5_volts
),
606 .vsel_reg
= BD718XX_REG_LDO5_VOLT
,
607 .vsel_mask
= BD71847_LDO5_MASK
,
608 .vsel_range_reg
= BD718XX_REG_LDO5_VOLT
,
609 .vsel_range_mask
= BD71847_LDO5_RANGE_MASK
,
610 .linear_range_selectors
= bd71847_ldo5_volt_range_sel
,
611 .enable_reg
= BD718XX_REG_LDO5_VOLT
,
612 .enable_mask
= BD718XX_LDO_EN
,
613 .owner
= THIS_MODULE
,
616 .reg
= BD718XX_REG_LDO5_VOLT
,
617 .mask
= BD718XX_LDO_SEL
,
618 .val
= BD718XX_LDO_SEL
,
624 .of_match
= of_match_ptr("LDO6"),
625 .regulators_node
= of_match_ptr("regulators"),
627 .ops
= &bd718xx_ldo_regulator_ops
,
628 .type
= REGULATOR_VOLTAGE
,
629 .n_voltages
= BD718XX_LDO6_VOLTAGE_NUM
,
630 .linear_ranges
= bd718xx_ldo6_volts
,
631 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo6_volts
),
632 /* LDO6 is supplied by buck5 */
633 .supply_name
= "buck5",
634 .vsel_reg
= BD718XX_REG_LDO6_VOLT
,
635 .vsel_mask
= BD718XX_LDO6_MASK
,
636 .enable_reg
= BD718XX_REG_LDO6_VOLT
,
637 .enable_mask
= BD718XX_LDO_EN
,
638 .owner
= THIS_MODULE
,
641 .reg
= BD718XX_REG_LDO6_VOLT
,
642 .mask
= BD718XX_LDO_SEL
,
643 .val
= BD718XX_LDO_SEL
,
648 static const struct bd718xx_regulator_data bd71837_regulators
[] = {
652 .of_match
= of_match_ptr("BUCK1"),
653 .regulators_node
= of_match_ptr("regulators"),
655 .ops
= &bd718xx_dvs_buck_regulator_ops
,
656 .type
= REGULATOR_VOLTAGE
,
657 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
658 .linear_ranges
= bd718xx_dvs_buck_volts
,
659 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
660 .vsel_reg
= BD718XX_REG_BUCK1_VOLT_RUN
,
661 .vsel_mask
= DVS_BUCK_RUN_MASK
,
662 .enable_reg
= BD718XX_REG_BUCK1_CTRL
,
663 .enable_mask
= BD718XX_BUCK_EN
,
664 .owner
= THIS_MODULE
,
667 .reg
= BD718XX_REG_BUCK1_CTRL
,
668 .mask
= BD718XX_BUCK_SEL
,
669 .val
= BD718XX_BUCK_SEL
,
675 .of_match
= of_match_ptr("BUCK2"),
676 .regulators_node
= of_match_ptr("regulators"),
678 .ops
= &bd718xx_dvs_buck_regulator_ops
,
679 .type
= REGULATOR_VOLTAGE
,
680 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
681 .linear_ranges
= bd718xx_dvs_buck_volts
,
682 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
683 .vsel_reg
= BD718XX_REG_BUCK2_VOLT_RUN
,
684 .vsel_mask
= DVS_BUCK_RUN_MASK
,
685 .enable_reg
= BD718XX_REG_BUCK2_CTRL
,
686 .enable_mask
= BD718XX_BUCK_EN
,
687 .owner
= THIS_MODULE
,
690 .reg
= BD718XX_REG_BUCK2_CTRL
,
691 .mask
= BD718XX_BUCK_SEL
,
692 .val
= BD718XX_BUCK_SEL
,
698 .of_match
= of_match_ptr("BUCK3"),
699 .regulators_node
= of_match_ptr("regulators"),
701 .ops
= &bd718xx_dvs_buck_regulator_ops
,
702 .type
= REGULATOR_VOLTAGE
,
703 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
704 .linear_ranges
= bd718xx_dvs_buck_volts
,
705 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
706 .vsel_reg
= BD71837_REG_BUCK3_VOLT_RUN
,
707 .vsel_mask
= DVS_BUCK_RUN_MASK
,
708 .enable_reg
= BD71837_REG_BUCK3_CTRL
,
709 .enable_mask
= BD718XX_BUCK_EN
,
710 .owner
= THIS_MODULE
,
713 .reg
= BD71837_REG_BUCK3_CTRL
,
714 .mask
= BD718XX_BUCK_SEL
,
715 .val
= BD718XX_BUCK_SEL
,
721 .of_match
= of_match_ptr("BUCK4"),
722 .regulators_node
= of_match_ptr("regulators"),
724 .ops
= &bd718xx_dvs_buck_regulator_ops
,
725 .type
= REGULATOR_VOLTAGE
,
726 .n_voltages
= BD718XX_DVS_BUCK_VOLTAGE_NUM
,
727 .linear_ranges
= bd718xx_dvs_buck_volts
,
728 .n_linear_ranges
= ARRAY_SIZE(bd718xx_dvs_buck_volts
),
729 .vsel_reg
= BD71837_REG_BUCK4_VOLT_RUN
,
730 .vsel_mask
= DVS_BUCK_RUN_MASK
,
731 .enable_reg
= BD71837_REG_BUCK4_CTRL
,
732 .enable_mask
= BD718XX_BUCK_EN
,
733 .owner
= THIS_MODULE
,
736 .reg
= BD71837_REG_BUCK4_CTRL
,
737 .mask
= BD718XX_BUCK_SEL
,
738 .val
= BD718XX_BUCK_SEL
,
744 .of_match
= of_match_ptr("BUCK5"),
745 .regulators_node
= of_match_ptr("regulators"),
747 .ops
= &bd718xx_pickable_range_buck_ops
,
748 .type
= REGULATOR_VOLTAGE
,
749 .n_voltages
= BD71837_BUCK5_VOLTAGE_NUM
,
750 .linear_ranges
= bd71837_buck5_volts
,
752 ARRAY_SIZE(bd71837_buck5_volts
),
753 .vsel_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
754 .vsel_mask
= BD71837_BUCK5_MASK
,
755 .vsel_range_reg
= BD718XX_REG_1ST_NODVS_BUCK_VOLT
,
756 .vsel_range_mask
= BD71837_BUCK5_RANGE_MASK
,
757 .linear_range_selectors
= bd71837_buck5_volt_range_sel
,
758 .enable_reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
759 .enable_mask
= BD718XX_BUCK_EN
,
760 .owner
= THIS_MODULE
,
763 .reg
= BD718XX_REG_1ST_NODVS_BUCK_CTRL
,
764 .mask
= BD718XX_BUCK_SEL
,
765 .val
= BD718XX_BUCK_SEL
,
771 .of_match
= of_match_ptr("BUCK6"),
772 .regulators_node
= of_match_ptr("regulators"),
774 .ops
= &bd718xx_buck_regulator_ops
,
775 .type
= REGULATOR_VOLTAGE
,
776 .n_voltages
= BD71837_BUCK6_VOLTAGE_NUM
,
777 .linear_ranges
= bd71837_buck6_volts
,
779 ARRAY_SIZE(bd71837_buck6_volts
),
780 .vsel_reg
= BD718XX_REG_2ND_NODVS_BUCK_VOLT
,
781 .vsel_mask
= BD71837_BUCK6_MASK
,
782 .enable_reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
783 .enable_mask
= BD718XX_BUCK_EN
,
784 .owner
= THIS_MODULE
,
787 .reg
= BD718XX_REG_2ND_NODVS_BUCK_CTRL
,
788 .mask
= BD718XX_BUCK_SEL
,
789 .val
= BD718XX_BUCK_SEL
,
795 .of_match
= of_match_ptr("BUCK7"),
796 .regulators_node
= of_match_ptr("regulators"),
798 .ops
= &bd718xx_buck_regulator_nolinear_ops
,
799 .type
= REGULATOR_VOLTAGE
,
800 .volt_table
= &bd718xx_3rd_nodvs_buck_volts
[0],
801 .n_voltages
= ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts
),
802 .vsel_reg
= BD718XX_REG_3RD_NODVS_BUCK_VOLT
,
803 .vsel_mask
= BD718XX_3RD_NODVS_BUCK_MASK
,
804 .enable_reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
805 .enable_mask
= BD718XX_BUCK_EN
,
806 .owner
= THIS_MODULE
,
809 .reg
= BD718XX_REG_3RD_NODVS_BUCK_CTRL
,
810 .mask
= BD718XX_BUCK_SEL
,
811 .val
= BD718XX_BUCK_SEL
,
817 .of_match
= of_match_ptr("BUCK8"),
818 .regulators_node
= of_match_ptr("regulators"),
820 .ops
= &bd718xx_buck_regulator_ops
,
821 .type
= REGULATOR_VOLTAGE
,
822 .n_voltages
= BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM
,
823 .linear_ranges
= bd718xx_4th_nodvs_buck_volts
,
825 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts
),
826 .vsel_reg
= BD718XX_REG_4TH_NODVS_BUCK_VOLT
,
827 .vsel_mask
= BD718XX_4TH_NODVS_BUCK_MASK
,
828 .enable_reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
829 .enable_mask
= BD718XX_BUCK_EN
,
830 .owner
= THIS_MODULE
,
833 .reg
= BD718XX_REG_4TH_NODVS_BUCK_CTRL
,
834 .mask
= BD718XX_BUCK_SEL
,
835 .val
= BD718XX_BUCK_SEL
,
841 .of_match
= of_match_ptr("LDO1"),
842 .regulators_node
= of_match_ptr("regulators"),
844 .ops
= &bd718xx_pickable_range_ldo_ops
,
845 .type
= REGULATOR_VOLTAGE
,
846 .n_voltages
= BD718XX_LDO1_VOLTAGE_NUM
,
847 .linear_ranges
= bd718xx_ldo1_volts
,
848 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo1_volts
),
849 .vsel_reg
= BD718XX_REG_LDO1_VOLT
,
850 .vsel_mask
= BD718XX_LDO1_MASK
,
851 .vsel_range_reg
= BD718XX_REG_LDO1_VOLT
,
852 .vsel_range_mask
= BD718XX_LDO1_RANGE_MASK
,
853 .linear_range_selectors
= bd718xx_ldo1_volt_range_sel
,
854 .enable_reg
= BD718XX_REG_LDO1_VOLT
,
855 .enable_mask
= BD718XX_LDO_EN
,
856 .owner
= THIS_MODULE
,
859 .reg
= BD718XX_REG_LDO1_VOLT
,
860 .mask
= BD718XX_LDO_SEL
,
861 .val
= BD718XX_LDO_SEL
,
867 .of_match
= of_match_ptr("LDO2"),
868 .regulators_node
= of_match_ptr("regulators"),
870 .ops
= &bd718xx_ldo_regulator_nolinear_ops
,
871 .type
= REGULATOR_VOLTAGE
,
872 .volt_table
= &ldo_2_volts
[0],
873 .vsel_reg
= BD718XX_REG_LDO2_VOLT
,
874 .vsel_mask
= BD718XX_LDO2_MASK
,
875 .n_voltages
= ARRAY_SIZE(ldo_2_volts
),
876 .enable_reg
= BD718XX_REG_LDO2_VOLT
,
877 .enable_mask
= BD718XX_LDO_EN
,
878 .owner
= THIS_MODULE
,
881 .reg
= BD718XX_REG_LDO2_VOLT
,
882 .mask
= BD718XX_LDO_SEL
,
883 .val
= BD718XX_LDO_SEL
,
889 .of_match
= of_match_ptr("LDO3"),
890 .regulators_node
= of_match_ptr("regulators"),
892 .ops
= &bd718xx_ldo_regulator_ops
,
893 .type
= REGULATOR_VOLTAGE
,
894 .n_voltages
= BD718XX_LDO3_VOLTAGE_NUM
,
895 .linear_ranges
= bd718xx_ldo3_volts
,
896 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo3_volts
),
897 .vsel_reg
= BD718XX_REG_LDO3_VOLT
,
898 .vsel_mask
= BD718XX_LDO3_MASK
,
899 .enable_reg
= BD718XX_REG_LDO3_VOLT
,
900 .enable_mask
= BD718XX_LDO_EN
,
901 .owner
= THIS_MODULE
,
904 .reg
= BD718XX_REG_LDO3_VOLT
,
905 .mask
= BD718XX_LDO_SEL
,
906 .val
= BD718XX_LDO_SEL
,
912 .of_match
= of_match_ptr("LDO4"),
913 .regulators_node
= of_match_ptr("regulators"),
915 .ops
= &bd718xx_ldo_regulator_ops
,
916 .type
= REGULATOR_VOLTAGE
,
917 .n_voltages
= BD718XX_LDO4_VOLTAGE_NUM
,
918 .linear_ranges
= bd718xx_ldo4_volts
,
919 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo4_volts
),
920 .vsel_reg
= BD718XX_REG_LDO4_VOLT
,
921 .vsel_mask
= BD718XX_LDO4_MASK
,
922 .enable_reg
= BD718XX_REG_LDO4_VOLT
,
923 .enable_mask
= BD718XX_LDO_EN
,
924 .owner
= THIS_MODULE
,
927 .reg
= BD718XX_REG_LDO4_VOLT
,
928 .mask
= BD718XX_LDO_SEL
,
929 .val
= BD718XX_LDO_SEL
,
935 .of_match
= of_match_ptr("LDO5"),
936 .regulators_node
= of_match_ptr("regulators"),
938 .ops
= &bd718xx_ldo_regulator_ops
,
939 .type
= REGULATOR_VOLTAGE
,
940 .n_voltages
= BD71837_LDO5_VOLTAGE_NUM
,
941 .linear_ranges
= bd71837_ldo5_volts
,
942 .n_linear_ranges
= ARRAY_SIZE(bd71837_ldo5_volts
),
943 /* LDO5 is supplied by buck6 */
944 .supply_name
= "buck6",
945 .vsel_reg
= BD718XX_REG_LDO5_VOLT
,
946 .vsel_mask
= BD71837_LDO5_MASK
,
947 .enable_reg
= BD718XX_REG_LDO5_VOLT
,
948 .enable_mask
= BD718XX_LDO_EN
,
949 .owner
= THIS_MODULE
,
952 .reg
= BD718XX_REG_LDO5_VOLT
,
953 .mask
= BD718XX_LDO_SEL
,
954 .val
= BD718XX_LDO_SEL
,
956 .additional_inits
= bd71837_ldo5_inits
,
957 .additional_init_amnt
= ARRAY_SIZE(bd71837_ldo5_inits
),
962 .of_match
= of_match_ptr("LDO6"),
963 .regulators_node
= of_match_ptr("regulators"),
965 .ops
= &bd718xx_ldo_regulator_ops
,
966 .type
= REGULATOR_VOLTAGE
,
967 .n_voltages
= BD718XX_LDO6_VOLTAGE_NUM
,
968 .linear_ranges
= bd718xx_ldo6_volts
,
969 .n_linear_ranges
= ARRAY_SIZE(bd718xx_ldo6_volts
),
970 /* LDO6 is supplied by buck7 */
971 .supply_name
= "buck7",
972 .vsel_reg
= BD718XX_REG_LDO6_VOLT
,
973 .vsel_mask
= BD718XX_LDO6_MASK
,
974 .enable_reg
= BD718XX_REG_LDO6_VOLT
,
975 .enable_mask
= BD718XX_LDO_EN
,
976 .owner
= THIS_MODULE
,
979 .reg
= BD718XX_REG_LDO6_VOLT
,
980 .mask
= BD718XX_LDO_SEL
,
981 .val
= BD718XX_LDO_SEL
,
983 .additional_inits
= bd71837_ldo6_inits
,
984 .additional_init_amnt
= ARRAY_SIZE(bd71837_ldo6_inits
),
989 .of_match
= of_match_ptr("LDO7"),
990 .regulators_node
= of_match_ptr("regulators"),
992 .ops
= &bd718xx_ldo_regulator_ops
,
993 .type
= REGULATOR_VOLTAGE
,
994 .n_voltages
= BD71837_LDO7_VOLTAGE_NUM
,
995 .linear_ranges
= bd71837_ldo7_volts
,
996 .n_linear_ranges
= ARRAY_SIZE(bd71837_ldo7_volts
),
997 .vsel_reg
= BD71837_REG_LDO7_VOLT
,
998 .vsel_mask
= BD71837_LDO7_MASK
,
999 .enable_reg
= BD71837_REG_LDO7_VOLT
,
1000 .enable_mask
= BD718XX_LDO_EN
,
1001 .owner
= THIS_MODULE
,
1004 .reg
= BD71837_REG_LDO7_VOLT
,
1005 .mask
= BD718XX_LDO_SEL
,
1006 .val
= BD718XX_LDO_SEL
,
1011 struct bd718xx_pmic_inits
{
1012 const struct bd718xx_regulator_data
*r_datas
;
1013 unsigned int r_amount
;
1016 static int bd718xx_probe(struct platform_device
*pdev
)
1018 struct bd718xx
*mfd
;
1019 struct regulator_config config
= { 0 };
1020 struct bd718xx_pmic_inits pmic_regulators
[] = {
1021 [BD718XX_TYPE_BD71837
] = {
1022 .r_datas
= bd71837_regulators
,
1023 .r_amount
= ARRAY_SIZE(bd71837_regulators
),
1025 [BD718XX_TYPE_BD71847
] = {
1026 .r_datas
= bd71847_regulators
,
1027 .r_amount
= ARRAY_SIZE(bd71847_regulators
),
1033 mfd
= dev_get_drvdata(pdev
->dev
.parent
);
1035 dev_err(&pdev
->dev
, "No MFD driver data\n");
1040 if (mfd
->chip_type
>= BD718XX_TYPE_AMOUNT
||
1041 !pmic_regulators
[mfd
->chip_type
].r_datas
) {
1042 dev_err(&pdev
->dev
, "Unsupported chip type\n");
1047 /* Register LOCK release */
1048 err
= regmap_update_bits(mfd
->regmap
, BD718XX_REG_REGLOCK
,
1049 (REGLOCK_PWRSEQ
| REGLOCK_VREG
), 0);
1051 dev_err(&pdev
->dev
, "Failed to unlock PMIC (%d)\n", err
);
1054 dev_dbg(&pdev
->dev
, "Unlocked lock register 0x%x\n",
1055 BD718XX_REG_REGLOCK
);
1058 /* At poweroff transition PMIC HW disables EN bit for regulators but
1059 * leaves SEL bit untouched. So if state transition from POWEROFF
1060 * is done to SNVS - then all power rails controlled by SW (having
1061 * SEL bit set) stay disabled as EN is cleared. This may result boot
1062 * failure if any crucial systems are powered by these rails.
1064 * Change the next stage from poweroff to be READY instead of SNVS
1065 * for all reset types because OTP loading at READY will clear SEL
1066 * bit allowing HW defaults for power rails to be used
1068 err
= regmap_update_bits(mfd
->regmap
, BD718XX_REG_TRANS_COND1
,
1069 BD718XX_ON_REQ_POWEROFF_MASK
|
1070 BD718XX_SWRESET_POWEROFF_MASK
|
1071 BD718XX_WDOG_POWEROFF_MASK
|
1072 BD718XX_KEY_L_POWEROFF_MASK
,
1073 BD718XX_POWOFF_TO_RDY
);
1075 dev_err(&pdev
->dev
, "Failed to change reset target\n");
1078 dev_dbg(&pdev
->dev
, "Changed all resets from SVNS to READY\n");
1081 for (i
= 0; i
< pmic_regulators
[mfd
->chip_type
].r_amount
; i
++) {
1083 const struct regulator_desc
*desc
;
1084 struct regulator_dev
*rdev
;
1085 const struct bd718xx_regulator_data
*r
;
1087 r
= &pmic_regulators
[mfd
->chip_type
].r_datas
[i
];
1090 config
.dev
= pdev
->dev
.parent
;
1091 config
.regmap
= mfd
->regmap
;
1093 rdev
= devm_regulator_register(&pdev
->dev
, desc
, &config
);
1096 "failed to register %s regulator\n",
1098 err
= PTR_ERR(rdev
);
1101 /* Regulator register gets the regulator constraints and
1102 * applies them (set_machine_constraints). This should have
1103 * turned the control register(s) to correct values and we
1104 * can now switch the control from PMIC state machine to the
1105 * register interface
1107 err
= regmap_update_bits(mfd
->regmap
, r
->init
.reg
,
1108 r
->init
.mask
, r
->init
.val
);
1111 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1115 for (j
= 0; j
< r
->additional_init_amnt
; j
++) {
1116 err
= regmap_update_bits(mfd
->regmap
,
1117 r
->additional_inits
[j
].reg
,
1118 r
->additional_inits
[j
].mask
,
1119 r
->additional_inits
[j
].val
);
1122 "Buck (%s) initialization failed\n",
1133 static struct platform_driver bd718xx_regulator
= {
1135 .name
= "bd718xx-pmic",
1137 .probe
= bd718xx_probe
,
1140 module_platform_driver(bd718xx_regulator
);
1142 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
1143 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
1144 MODULE_LICENSE("GPL");