1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright 2014 Embest Technology Co. Ltd. Inc.
4 // bd71815-regulator.c ROHM BD71815 regulator driver
6 // Author: Tony Luo <luofc@embedinfo.com>
8 // Partially rewritten at 2021 by
9 // Matti Vaittinen <matti.vaitinen@fi.rohmeurope.com>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/err.h>
15 #include <linux/platform_device.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/delay.h>
18 #include <linux/slab.h>
19 #include <linux/gpio.h>
20 #include <linux/mfd/rohm-generic.h>
21 #include <linux/mfd/rohm-bd71815.h>
22 #include <linux/regulator/of_regulator.h>
24 struct bd71815_regulator
{
25 struct regulator_desc desc
;
26 const struct rohm_dvs_config
*dvs
;
30 struct bd71815_regulator descs
[BD71815_REGULATOR_CNT
];
31 struct regmap
*regmap
;
33 struct gpio_descs
*gps
;
34 struct regulator_dev
*rdev
[BD71815_REGULATOR_CNT
];
37 static const int bd7181x_wled_currents
[] = {
38 10, 20, 30, 50, 70, 100, 200, 300, 500, 700, 1000, 2000, 3000, 4000,
39 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000,
40 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000,
43 static const struct rohm_dvs_config buck1_dvs
= {
44 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
45 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
46 .run_reg
= BD71815_REG_BUCK1_VOLT_H
,
47 .run_mask
= BD71815_VOLT_MASK
,
48 .run_on_mask
= BD71815_BUCK_RUN_ON
,
49 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
50 .suspend_reg
= BD71815_REG_BUCK1_VOLT_L
,
51 .suspend_mask
= BD71815_VOLT_MASK
,
52 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
53 .lpsr_reg
= BD71815_REG_BUCK1_VOLT_L
,
54 .lpsr_mask
= BD71815_VOLT_MASK
,
55 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
58 static const struct rohm_dvs_config buck2_dvs
= {
59 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
60 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
61 .run_reg
= BD71815_REG_BUCK2_VOLT_H
,
62 .run_mask
= BD71815_VOLT_MASK
,
63 .run_on_mask
= BD71815_BUCK_RUN_ON
,
64 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
65 .suspend_reg
= BD71815_REG_BUCK2_VOLT_L
,
66 .suspend_mask
= BD71815_VOLT_MASK
,
67 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
68 .lpsr_reg
= BD71815_REG_BUCK2_VOLT_L
,
69 .lpsr_mask
= BD71815_VOLT_MASK
,
70 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
73 static const struct rohm_dvs_config buck3_dvs
= {
74 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
75 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
76 .run_reg
= BD71815_REG_BUCK3_VOLT
,
77 .run_mask
= BD71815_VOLT_MASK
,
78 .run_on_mask
= BD71815_BUCK_RUN_ON
,
79 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
80 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
81 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
84 static const struct rohm_dvs_config buck4_dvs
= {
85 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
86 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
87 .run_reg
= BD71815_REG_BUCK4_VOLT
,
88 .run_mask
= BD71815_VOLT_MASK
,
89 .run_on_mask
= BD71815_BUCK_RUN_ON
,
90 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
91 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
92 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
95 static const struct rohm_dvs_config ldo1_dvs
= {
96 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
97 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
98 .run_reg
= BD71815_REG_LDO_MODE1
,
99 .run_mask
= BD71815_VOLT_MASK
,
100 .run_on_mask
= LDO1_RUN_ON
,
101 .snvs_on_mask
= LDO1_SNVS_ON
,
102 .suspend_on_mask
= LDO1_SUSP_ON
,
103 .lpsr_on_mask
= LDO1_LPSR_ON
,
106 static const struct rohm_dvs_config ldo2_dvs
= {
107 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
108 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
109 .run_reg
= BD71815_REG_LDO_MODE2
,
110 .run_mask
= BD71815_VOLT_MASK
,
111 .run_on_mask
= LDO2_RUN_ON
,
112 .snvs_on_mask
= LDO2_SNVS_ON
,
113 .suspend_on_mask
= LDO2_SUSP_ON
,
114 .lpsr_on_mask
= LDO2_LPSR_ON
,
117 static const struct rohm_dvs_config ldo3_dvs
= {
118 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
119 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
120 .run_reg
= BD71815_REG_LDO_MODE2
,
121 .run_mask
= BD71815_VOLT_MASK
,
122 .run_on_mask
= LDO3_RUN_ON
,
123 .snvs_on_mask
= LDO3_SNVS_ON
,
124 .suspend_on_mask
= LDO3_SUSP_ON
,
125 .lpsr_on_mask
= LDO3_LPSR_ON
,
128 static const struct rohm_dvs_config ldo4_dvs
= {
129 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
130 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
131 .run_reg
= BD71815_REG_LDO_MODE3
,
132 .run_mask
= BD71815_VOLT_MASK
,
133 .run_on_mask
= LDO4_RUN_ON
,
134 .snvs_on_mask
= LDO4_SNVS_ON
,
135 .suspend_on_mask
= LDO4_SUSP_ON
,
136 .lpsr_on_mask
= LDO4_LPSR_ON
,
139 static const struct rohm_dvs_config ldo5_dvs
= {
140 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
141 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
142 .run_reg
= BD71815_REG_LDO_MODE3
,
143 .run_mask
= BD71815_VOLT_MASK
,
144 .run_on_mask
= LDO5_RUN_ON
,
145 .snvs_on_mask
= LDO5_SNVS_ON
,
146 .suspend_on_mask
= LDO5_SUSP_ON
,
147 .lpsr_on_mask
= LDO5_LPSR_ON
,
150 static const struct rohm_dvs_config dvref_dvs
= {
151 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
152 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
153 .run_on_mask
= DVREF_RUN_ON
,
154 .snvs_on_mask
= DVREF_SNVS_ON
,
155 .suspend_on_mask
= DVREF_SUSP_ON
,
156 .lpsr_on_mask
= DVREF_LPSR_ON
,
159 static const struct rohm_dvs_config ldolpsr_dvs
= {
160 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
161 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
162 .run_on_mask
= DVREF_RUN_ON
,
163 .snvs_on_mask
= DVREF_SNVS_ON
,
164 .suspend_on_mask
= DVREF_SUSP_ON
,
165 .lpsr_on_mask
= DVREF_LPSR_ON
,
168 static const struct rohm_dvs_config buck5_dvs
= {
169 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
170 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
171 .run_reg
= BD71815_REG_BUCK5_VOLT
,
172 .run_mask
= BD71815_VOLT_MASK
,
173 .run_on_mask
= BD71815_BUCK_RUN_ON
,
174 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
175 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
176 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
179 static int set_hw_dvs_levels(struct device_node
*np
,
180 const struct regulator_desc
*desc
,
181 struct regulator_config
*cfg
)
183 struct bd71815_regulator
*data
;
185 data
= container_of(desc
, struct bd71815_regulator
, desc
);
186 return rohm_regulator_set_dvs_levels(data
->dvs
, np
, desc
, cfg
->regmap
);
190 * Bucks 1 and 2 have two voltage selection registers where selected
191 * voltage can be set. Which of the registers is used can be either controlled
192 * by a control bit in register - or by HW state. If HW state specific voltages
193 * are given - then we assume HW state based control should be used.
195 * If volatge value is updated to currently selected register - then output
196 * voltage is immediately changed no matter what is set as ramp rate. Thus we
197 * default changing voltage by writing new value to inactive register and
198 * then updating the 'register selection' bit. This naturally only works when
199 * HW state machine is not used to select the voltage.
201 static int buck12_set_hw_dvs_levels(struct device_node
*np
,
202 const struct regulator_desc
*desc
,
203 struct regulator_config
*cfg
)
205 struct bd71815_regulator
*data
;
208 data
= container_of(desc
, struct bd71815_regulator
, desc
);
210 if (of_find_property(np
, "rohm,dvs-run-voltage", NULL
) ||
211 of_find_property(np
, "rohm,dvs-suspend-voltage", NULL
) ||
212 of_find_property(np
, "rohm,dvs-lpsr-voltage", NULL
) ||
213 of_find_property(np
, "rohm,dvs-snvs-voltage", NULL
)) {
214 ret
= regmap_read(cfg
->regmap
, desc
->vsel_reg
, &val
);
218 if (!(BD71815_BUCK_STBY_DVS
& val
) &&
219 !(BD71815_BUCK_DVSSEL
& val
)) {
223 * We are currently using voltage from _L.
224 * We'd better copy it to _H and switch to it to
225 * avoid shutting us down if LPSR or SUSPEND is set to
226 * disabled. _L value is at reg _H + 1
228 ret
= regmap_read(cfg
->regmap
, desc
->vsel_reg
+ 1,
233 ret
= regmap_update_bits(cfg
->regmap
, desc
->vsel_reg
,
236 val2
| BD71815_BUCK_DVSSEL
);
240 ret
= rohm_regulator_set_dvs_levels(data
->dvs
, np
, desc
,
245 * DVS levels were given => use HW-state machine for voltage
246 * controls. NOTE: AFAIK, This means that if voltage is changed
247 * by SW the ramp-rate is not respected. Should we disable
248 * SW voltage control when the HW state machine is used?
250 ret
= regmap_update_bits(cfg
->regmap
, desc
->vsel_reg
,
251 BD71815_BUCK_STBY_DVS
,
252 BD71815_BUCK_STBY_DVS
);
260 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
261 * 00: 10.00mV/usec 10mV 1uS
262 * 01: 5.00mV/usec 10mV 2uS
263 * 10: 2.50mV/usec 10mV 4uS
264 * 11: 1.25mV/usec 10mV 8uS
266 static const unsigned int bd7181x_ramp_table
[] = { 1250, 2500, 5000, 10000 };
268 static int bd7181x_led_set_current_limit(struct regulator_dev
*rdev
,
269 int min_uA
, int max_uA
)
274 onstatus
= regulator_is_enabled_regmap(rdev
);
276 ret
= regulator_set_current_limit_regmap(rdev
, min_uA
, max_uA
);
280 newstatus
= regulator_is_enabled_regmap(rdev
);
281 if (onstatus
!= newstatus
) {
283 * HW FIX: spurious led status change detected. Toggle
284 * state as a workaround
287 ret
= regulator_enable_regmap(rdev
);
289 ret
= regulator_disable_regmap(rdev
);
292 dev_err(rdev_get_dev(rdev
),
293 "failed to revert the LED state (%d)\n",
301 static int bd7181x_buck12_get_voltage_sel(struct regulator_dev
*rdev
)
303 struct bd71815_pmic
*pmic
= rdev_get_drvdata(rdev
);
304 int rid
= rdev_get_id(rdev
);
305 int ret
, regh
, regl
, val
;
307 regh
= BD71815_REG_BUCK1_VOLT_H
+ rid
* 0x2;
308 regl
= BD71815_REG_BUCK1_VOLT_L
+ rid
* 0x2;
310 ret
= regmap_read(pmic
->regmap
, regh
, &val
);
315 * If we use HW state machine based voltage reg selection - then we
316 * return BD71815_REG_BUCK1_VOLT_H which is used at RUN.
317 * Else we do return the BD71815_REG_BUCK1_VOLT_H or
318 * BD71815_REG_BUCK1_VOLT_L depending on which is selected to be used
319 * by BD71815_BUCK_DVSSEL bit
321 if ((!(val
& BD71815_BUCK_STBY_DVS
)) && (!(val
& BD71815_BUCK_DVSSEL
)))
322 ret
= regmap_read(pmic
->regmap
, regl
, &val
);
327 return val
& BD71815_VOLT_MASK
;
333 static int bd7181x_buck12_set_voltage_sel(struct regulator_dev
*rdev
,
336 struct bd71815_pmic
*pmic
= rdev_get_drvdata(rdev
);
337 int rid
= rdev_get_id(rdev
);
338 int ret
, val
, reg
, regh
, regl
;
340 regh
= BD71815_REG_BUCK1_VOLT_H
+ rid
*0x2;
341 regl
= BD71815_REG_BUCK1_VOLT_L
+ rid
*0x2;
343 ret
= regmap_read(pmic
->regmap
, regh
, &val
);
348 * If bucks 1 & 2 are controlled by state machine - then the RUN state
349 * voltage is set to BD71815_REG_BUCK1_VOLT_H. Changing SUSPEND/LPSR
350 * voltages at runtime is not supported by this driver.
352 if (((val
& BD71815_BUCK_STBY_DVS
))) {
353 return regmap_update_bits(pmic
->regmap
, regh
, BD71815_VOLT_MASK
,
356 /* Update new voltage to the register which is not selected now */
357 if (val
& BD71815_BUCK_DVSSEL
)
362 ret
= regmap_update_bits(pmic
->regmap
, reg
, BD71815_VOLT_MASK
, sel
);
366 /* Select the other DVS register to be used */
367 return regmap_update_bits(pmic
->regmap
, regh
, BD71815_BUCK_DVSSEL
, ~val
);
370 static const struct regulator_ops bd7181x_ldo_regulator_ops
= {
371 .enable
= regulator_enable_regmap
,
372 .disable
= regulator_disable_regmap
,
373 .is_enabled
= regulator_is_enabled_regmap
,
374 .list_voltage
= regulator_list_voltage_linear
,
375 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
376 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
379 static const struct regulator_ops bd7181x_fixed_regulator_ops
= {
380 .enable
= regulator_enable_regmap
,
381 .disable
= regulator_disable_regmap
,
382 .is_enabled
= regulator_is_enabled_regmap
,
383 .list_voltage
= regulator_list_voltage_linear
,
386 static const struct regulator_ops bd7181x_buck_regulator_ops
= {
387 .enable
= regulator_enable_regmap
,
388 .disable
= regulator_disable_regmap
,
389 .is_enabled
= regulator_is_enabled_regmap
,
390 .list_voltage
= regulator_list_voltage_linear
,
391 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
392 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
393 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
396 static const struct regulator_ops bd7181x_buck12_regulator_ops
= {
397 .enable
= regulator_enable_regmap
,
398 .disable
= regulator_disable_regmap
,
399 .is_enabled
= regulator_is_enabled_regmap
,
400 .list_voltage
= regulator_list_voltage_linear
,
401 .set_voltage_sel
= bd7181x_buck12_set_voltage_sel
,
402 .get_voltage_sel
= bd7181x_buck12_get_voltage_sel
,
403 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
404 .set_ramp_delay
= regulator_set_ramp_delay_regmap
,
407 static const struct regulator_ops bd7181x_led_regulator_ops
= {
408 .enable
= regulator_enable_regmap
,
409 .disable
= regulator_disable_regmap
,
410 .is_enabled
= regulator_is_enabled_regmap
,
411 .set_current_limit
= bd7181x_led_set_current_limit
,
412 .get_current_limit
= regulator_get_current_limit_regmap
,
415 #define BD71815_FIXED_REG(_name, _id, ereg, emsk, voltage, _dvs) \
419 .of_match = of_match_ptr(#_name), \
420 .regulators_node = of_match_ptr("regulators"), \
422 .ops = &bd7181x_fixed_regulator_ops, \
423 .type = REGULATOR_VOLTAGE, \
425 .owner = THIS_MODULE, \
426 .min_uV = (voltage), \
427 .enable_reg = (ereg), \
428 .enable_mask = (emsk), \
429 .of_parse_cb = set_hw_dvs_levels, \
434 #define BD71815_BUCK_REG(_name, _id, vsel, ereg, min, max, step, _dvs) \
438 .of_match = of_match_ptr(#_name), \
439 .regulators_node = of_match_ptr("regulators"), \
440 .n_voltages = ((max) - (min)) / (step) + 1, \
441 .ops = &bd7181x_buck_regulator_ops, \
442 .type = REGULATOR_VOLTAGE, \
444 .owner = THIS_MODULE, \
447 .vsel_reg = (vsel), \
448 .vsel_mask = BD71815_VOLT_MASK, \
449 .enable_reg = (ereg), \
450 .enable_mask = BD71815_BUCK_RUN_ON, \
451 .of_parse_cb = set_hw_dvs_levels, \
456 #define BD71815_BUCK12_REG(_name, _id, vsel, ereg, min, max, step, \
461 .of_match = of_match_ptr(#_name), \
462 .regulators_node = of_match_ptr("regulators"), \
463 .n_voltages = ((max) - (min)) / (step) + 1, \
464 .ops = &bd7181x_buck12_regulator_ops, \
465 .type = REGULATOR_VOLTAGE, \
467 .owner = THIS_MODULE, \
470 .vsel_reg = (vsel), \
472 .enable_reg = (ereg), \
473 .enable_mask = 0x04, \
474 .ramp_reg = (ereg), \
475 .ramp_mask = BD71815_BUCK_RAMPRATE_MASK, \
476 .ramp_delay_table = bd7181x_ramp_table, \
477 .n_ramp_values = ARRAY_SIZE(bd7181x_ramp_table),\
478 .of_parse_cb = buck12_set_hw_dvs_levels, \
483 #define BD71815_LED_REG(_name, _id, csel, mask, ereg, emsk, currents) \
487 .of_match = of_match_ptr(#_name), \
488 .regulators_node = of_match_ptr("regulators"), \
489 .n_current_limits = ARRAY_SIZE(currents), \
490 .ops = &bd7181x_led_regulator_ops, \
491 .type = REGULATOR_CURRENT, \
493 .owner = THIS_MODULE, \
494 .curr_table = currents, \
495 .csel_reg = (csel), \
496 .csel_mask = (mask), \
497 .enable_reg = (ereg), \
498 .enable_mask = (emsk), \
502 #define BD71815_LDO_REG(_name, _id, vsel, ereg, emsk, min, max, step, \
507 .of_match = of_match_ptr(#_name), \
508 .regulators_node = of_match_ptr("regulators"), \
509 .n_voltages = ((max) - (min)) / (step) + 1, \
510 .ops = &bd7181x_ldo_regulator_ops, \
511 .type = REGULATOR_VOLTAGE, \
513 .owner = THIS_MODULE, \
516 .vsel_reg = (vsel), \
517 .vsel_mask = BD71815_VOLT_MASK, \
518 .enable_reg = (ereg), \
519 .enable_mask = (emsk), \
520 .of_parse_cb = set_hw_dvs_levels, \
525 static struct bd71815_regulator bd71815_regulators
[] = {
526 BD71815_BUCK12_REG(buck1
, BD71815_BUCK1
, BD71815_REG_BUCK1_VOLT_H
,
527 BD71815_REG_BUCK1_MODE
, 800000, 2000000, 25000,
529 BD71815_BUCK12_REG(buck2
, BD71815_BUCK2
, BD71815_REG_BUCK2_VOLT_H
,
530 BD71815_REG_BUCK2_MODE
, 800000, 2000000, 25000,
532 BD71815_BUCK_REG(buck3
, BD71815_BUCK3
, BD71815_REG_BUCK3_VOLT
,
533 BD71815_REG_BUCK3_MODE
, 1200000, 2700000, 50000,
535 BD71815_BUCK_REG(buck4
, BD71815_BUCK4
, BD71815_REG_BUCK4_VOLT
,
536 BD71815_REG_BUCK4_MODE
, 1100000, 1850000, 25000,
538 BD71815_BUCK_REG(buck5
, BD71815_BUCK5
, BD71815_REG_BUCK5_VOLT
,
539 BD71815_REG_BUCK5_MODE
, 1800000, 3300000, 50000,
541 BD71815_LDO_REG(ldo1
, BD71815_LDO1
, BD71815_REG_LDO1_VOLT
,
542 BD71815_REG_LDO_MODE1
, LDO1_RUN_ON
, 800000, 3300000,
544 BD71815_LDO_REG(ldo2
, BD71815_LDO2
, BD71815_REG_LDO2_VOLT
,
545 BD71815_REG_LDO_MODE2
, LDO2_RUN_ON
, 800000, 3300000,
548 * Let's default LDO3 to be enabled by SW. We can override ops if DT
549 * says LDO3 should be enabled by HW when DCIN is connected.
551 BD71815_LDO_REG(ldo3
, BD71815_LDO3
, BD71815_REG_LDO3_VOLT
,
552 BD71815_REG_LDO_MODE2
, LDO3_RUN_ON
, 800000, 3300000,
554 BD71815_LDO_REG(ldo4
, BD71815_LDO4
, BD71815_REG_LDO4_VOLT
,
555 BD71815_REG_LDO_MODE3
, LDO4_RUN_ON
, 800000, 3300000,
557 BD71815_LDO_REG(ldo5
, BD71815_LDO5
, BD71815_REG_LDO5_VOLT_H
,
558 BD71815_REG_LDO_MODE3
, LDO5_RUN_ON
, 800000, 3300000,
560 BD71815_FIXED_REG(ldodvref
, BD71815_LDODVREF
, BD71815_REG_LDO_MODE4
,
561 DVREF_RUN_ON
, 3000000, &dvref_dvs
),
562 BD71815_FIXED_REG(ldolpsr
, BD71815_LDOLPSR
, BD71815_REG_LDO_MODE4
,
563 LDO_LPSR_RUN_ON
, 1800000, &ldolpsr_dvs
),
564 BD71815_LED_REG(wled
, BD71815_WLED
, BD71815_REG_LED_DIMM
, LED_DIMM_MASK
,
565 BD71815_REG_LED_CTRL
, LED_RUN_ON
,
566 bd7181x_wled_currents
),
569 static int bd7181x_probe(struct platform_device
*pdev
)
571 struct bd71815_pmic
*pmic
;
572 struct regulator_config config
= {};
574 struct gpio_desc
*ldo4_en
;
576 pmic
= devm_kzalloc(&pdev
->dev
, sizeof(*pmic
), GFP_KERNEL
);
580 memcpy(pmic
->descs
, bd71815_regulators
, sizeof(pmic
->descs
));
582 pmic
->dev
= &pdev
->dev
;
583 pmic
->regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
585 dev_err(pmic
->dev
, "No parent regmap\n");
588 platform_set_drvdata(pdev
, pmic
);
589 ldo4_en
= devm_gpiod_get_from_of_node(&pdev
->dev
,
590 pdev
->dev
.parent
->of_node
,
591 "rohm,vsel-gpios", 0,
592 GPIOD_ASIS
, "ldo4-en");
594 if (IS_ERR(ldo4_en
)) {
595 ret
= PTR_ERR(ldo4_en
);
601 /* Disable to go to ship-mode */
602 ret
= regmap_update_bits(pmic
->regmap
, BD71815_REG_PWRCTRL
,
607 config
.dev
= pdev
->dev
.parent
;
608 config
.regmap
= pmic
->regmap
;
610 for (i
= 0; i
< BD71815_REGULATOR_CNT
; i
++) {
611 struct regulator_desc
*desc
;
612 struct regulator_dev
*rdev
;
614 desc
= &pmic
->descs
[i
].desc
;
615 if (i
== BD71815_LDO4
)
616 config
.ena_gpiod
= ldo4_en
;
618 config
.driver_data
= pmic
;
620 rdev
= devm_regulator_register(&pdev
->dev
, desc
, &config
);
623 "failed to register %s regulator\n",
625 return PTR_ERR(rdev
);
627 config
.ena_gpiod
= NULL
;
628 pmic
->rdev
[i
] = rdev
;
633 static const struct platform_device_id bd7181x_pmic_id
[] = {
634 { "bd71815-pmic", ROHM_CHIP_TYPE_BD71815
},
637 MODULE_DEVICE_TABLE(platform
, bd7181x_pmic_id
);
639 static struct platform_driver bd7181x_regulator
= {
641 .name
= "bd7181x-pmic",
642 .owner
= THIS_MODULE
,
644 .probe
= bd7181x_probe
,
645 .id_table
= bd7181x_pmic_id
,
647 module_platform_driver(bd7181x_regulator
);
649 MODULE_AUTHOR("Tony Luo <luofc@embedinfo.com>");
650 MODULE_DESCRIPTION("BD71815 voltage regulator driver");
651 MODULE_LICENSE("GPL v2");
652 MODULE_ALIAS("platform:bd7181x-pmic");