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>
17 #include <linux/gpio/consumer.h>
18 #include <linux/regulator/driver.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/mfd/rohm-generic.h>
22 #include <linux/mfd/rohm-bd71815.h>
23 #include <linux/regulator/of_regulator.h>
25 struct bd71815_regulator
{
26 struct regulator_desc desc
;
27 const struct rohm_dvs_config
*dvs
;
30 static const int bd7181x_wled_currents
[] = {
31 10, 20, 30, 50, 70, 100, 200, 300, 500, 700, 1000, 2000, 3000, 4000,
32 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000,
33 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000,
36 static const struct rohm_dvs_config buck1_dvs
= {
37 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
38 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
39 .run_reg
= BD71815_REG_BUCK1_VOLT_H
,
40 .run_mask
= BD71815_VOLT_MASK
,
41 .run_on_mask
= BD71815_BUCK_RUN_ON
,
42 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
43 .suspend_reg
= BD71815_REG_BUCK1_VOLT_L
,
44 .suspend_mask
= BD71815_VOLT_MASK
,
45 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
46 .lpsr_reg
= BD71815_REG_BUCK1_VOLT_L
,
47 .lpsr_mask
= BD71815_VOLT_MASK
,
48 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
51 static const struct rohm_dvs_config buck2_dvs
= {
52 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
53 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
54 .run_reg
= BD71815_REG_BUCK2_VOLT_H
,
55 .run_mask
= BD71815_VOLT_MASK
,
56 .run_on_mask
= BD71815_BUCK_RUN_ON
,
57 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
58 .suspend_reg
= BD71815_REG_BUCK2_VOLT_L
,
59 .suspend_mask
= BD71815_VOLT_MASK
,
60 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
61 .lpsr_reg
= BD71815_REG_BUCK2_VOLT_L
,
62 .lpsr_mask
= BD71815_VOLT_MASK
,
63 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
66 static const struct rohm_dvs_config buck3_dvs
= {
67 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
68 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
69 .run_reg
= BD71815_REG_BUCK3_VOLT
,
70 .run_mask
= BD71815_VOLT_MASK
,
71 .run_on_mask
= BD71815_BUCK_RUN_ON
,
72 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
73 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
74 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
77 static const struct rohm_dvs_config buck4_dvs
= {
78 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
79 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
80 .run_reg
= BD71815_REG_BUCK4_VOLT
,
81 .run_mask
= BD71815_VOLT_MASK
,
82 .run_on_mask
= BD71815_BUCK_RUN_ON
,
83 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
84 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
85 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
88 static const struct rohm_dvs_config ldo1_dvs
= {
89 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
90 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
91 .run_reg
= BD71815_REG_LDO_MODE1
,
92 .run_mask
= BD71815_VOLT_MASK
,
93 .run_on_mask
= LDO1_RUN_ON
,
94 .snvs_on_mask
= LDO1_SNVS_ON
,
95 .suspend_on_mask
= LDO1_SUSP_ON
,
96 .lpsr_on_mask
= LDO1_LPSR_ON
,
99 static const struct rohm_dvs_config ldo2_dvs
= {
100 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
101 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
102 .run_reg
= BD71815_REG_LDO_MODE2
,
103 .run_mask
= BD71815_VOLT_MASK
,
104 .run_on_mask
= LDO2_RUN_ON
,
105 .snvs_on_mask
= LDO2_SNVS_ON
,
106 .suspend_on_mask
= LDO2_SUSP_ON
,
107 .lpsr_on_mask
= LDO2_LPSR_ON
,
110 static const struct rohm_dvs_config ldo3_dvs
= {
111 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
112 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
113 .run_reg
= BD71815_REG_LDO_MODE2
,
114 .run_mask
= BD71815_VOLT_MASK
,
115 .run_on_mask
= LDO3_RUN_ON
,
116 .snvs_on_mask
= LDO3_SNVS_ON
,
117 .suspend_on_mask
= LDO3_SUSP_ON
,
118 .lpsr_on_mask
= LDO3_LPSR_ON
,
121 static const struct rohm_dvs_config ldo4_dvs
= {
122 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
123 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
124 .run_reg
= BD71815_REG_LDO_MODE3
,
125 .run_mask
= BD71815_VOLT_MASK
,
126 .run_on_mask
= LDO4_RUN_ON
,
127 .snvs_on_mask
= LDO4_SNVS_ON
,
128 .suspend_on_mask
= LDO4_SUSP_ON
,
129 .lpsr_on_mask
= LDO4_LPSR_ON
,
132 static const struct rohm_dvs_config ldo5_dvs
= {
133 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
134 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
135 .run_reg
= BD71815_REG_LDO_MODE3
,
136 .run_mask
= BD71815_VOLT_MASK
,
137 .run_on_mask
= LDO5_RUN_ON
,
138 .snvs_on_mask
= LDO5_SNVS_ON
,
139 .suspend_on_mask
= LDO5_SUSP_ON
,
140 .lpsr_on_mask
= LDO5_LPSR_ON
,
143 static const struct rohm_dvs_config dvref_dvs
= {
144 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
145 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
146 .run_on_mask
= DVREF_RUN_ON
,
147 .snvs_on_mask
= DVREF_SNVS_ON
,
148 .suspend_on_mask
= DVREF_SUSP_ON
,
149 .lpsr_on_mask
= DVREF_LPSR_ON
,
152 static const struct rohm_dvs_config ldolpsr_dvs
= {
153 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
154 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
155 .run_on_mask
= DVREF_RUN_ON
,
156 .snvs_on_mask
= DVREF_SNVS_ON
,
157 .suspend_on_mask
= DVREF_SUSP_ON
,
158 .lpsr_on_mask
= DVREF_LPSR_ON
,
161 static const struct rohm_dvs_config buck5_dvs
= {
162 .level_map
= ROHM_DVS_LEVEL_RUN
| ROHM_DVS_LEVEL_SNVS
|
163 ROHM_DVS_LEVEL_SUSPEND
| ROHM_DVS_LEVEL_LPSR
,
164 .run_reg
= BD71815_REG_BUCK5_VOLT
,
165 .run_mask
= BD71815_VOLT_MASK
,
166 .run_on_mask
= BD71815_BUCK_RUN_ON
,
167 .snvs_on_mask
= BD71815_BUCK_SNVS_ON
,
168 .suspend_on_mask
= BD71815_BUCK_SUSP_ON
,
169 .lpsr_on_mask
= BD71815_BUCK_LPSR_ON
,
172 static int set_hw_dvs_levels(struct device_node
*np
,
173 const struct regulator_desc
*desc
,
174 struct regulator_config
*cfg
)
176 struct bd71815_regulator
*data
;
178 data
= container_of(desc
, struct bd71815_regulator
, desc
);
179 return rohm_regulator_set_dvs_levels(data
->dvs
, np
, desc
, cfg
->regmap
);
183 * Bucks 1 and 2 have two voltage selection registers where selected
184 * voltage can be set. Which of the registers is used can be either controlled
185 * by a control bit in register - or by HW state. If HW state specific voltages
186 * are given - then we assume HW state based control should be used.
188 * If volatge value is updated to currently selected register - then output
189 * voltage is immediately changed no matter what is set as ramp rate. Thus we
190 * default changing voltage by writing new value to inactive register and
191 * then updating the 'register selection' bit. This naturally only works when
192 * HW state machine is not used to select the voltage.
194 static int buck12_set_hw_dvs_levels(struct device_node
*np
,
195 const struct regulator_desc
*desc
,
196 struct regulator_config
*cfg
)
198 struct bd71815_regulator
*data
;
201 data
= container_of(desc
, struct bd71815_regulator
, desc
);
203 if (of_property_present(np
, "rohm,dvs-run-voltage") ||
204 of_property_present(np
, "rohm,dvs-suspend-voltage") ||
205 of_property_present(np
, "rohm,dvs-lpsr-voltage") ||
206 of_property_present(np
, "rohm,dvs-snvs-voltage")) {
207 ret
= regmap_read(cfg
->regmap
, desc
->vsel_reg
, &val
);
211 if (!(BD71815_BUCK_STBY_DVS
& val
) &&
212 !(BD71815_BUCK_DVSSEL
& val
)) {
216 * We are currently using voltage from _L.
217 * We'd better copy it to _H and switch to it to
218 * avoid shutting us down if LPSR or SUSPEND is set to
219 * disabled. _L value is at reg _H + 1
221 ret
= regmap_read(cfg
->regmap
, desc
->vsel_reg
+ 1,
226 ret
= regmap_update_bits(cfg
->regmap
, desc
->vsel_reg
,
229 val2
| BD71815_BUCK_DVSSEL
);
233 ret
= rohm_regulator_set_dvs_levels(data
->dvs
, np
, desc
,
238 * DVS levels were given => use HW-state machine for voltage
239 * controls. NOTE: AFAIK, This means that if voltage is changed
240 * by SW the ramp-rate is not respected. Should we disable
241 * SW voltage control when the HW state machine is used?
243 ret
= regmap_update_bits(cfg
->regmap
, desc
->vsel_reg
,
244 BD71815_BUCK_STBY_DVS
,
245 BD71815_BUCK_STBY_DVS
);
253 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
254 * 00: 10.00mV/usec 10mV 1uS
255 * 01: 5.00mV/usec 10mV 2uS
256 * 10: 2.50mV/usec 10mV 4uS
257 * 11: 1.25mV/usec 10mV 8uS
259 static const unsigned int bd7181x_ramp_table
[] = { 10000, 5000, 2500, 1250 };
261 static int bd7181x_led_set_current_limit(struct regulator_dev
*rdev
,
262 int min_uA
, int max_uA
)
267 onstatus
= regulator_is_enabled_regmap(rdev
);
269 ret
= regulator_set_current_limit_regmap(rdev
, min_uA
, max_uA
);
273 newstatus
= regulator_is_enabled_regmap(rdev
);
274 if (onstatus
!= newstatus
) {
276 * HW FIX: spurious led status change detected. Toggle
277 * state as a workaround
280 ret
= regulator_enable_regmap(rdev
);
282 ret
= regulator_disable_regmap(rdev
);
285 dev_err(rdev_get_dev(rdev
),
286 "failed to revert the LED state (%d)\n",
294 static int bd7181x_buck12_get_voltage_sel(struct regulator_dev
*rdev
)
296 int rid
= rdev_get_id(rdev
);
297 int ret
, regh
, regl
, val
;
299 regh
= BD71815_REG_BUCK1_VOLT_H
+ rid
* 0x2;
300 regl
= BD71815_REG_BUCK1_VOLT_L
+ rid
* 0x2;
302 ret
= regmap_read(rdev
->regmap
, regh
, &val
);
307 * If we use HW state machine based voltage reg selection - then we
308 * return BD71815_REG_BUCK1_VOLT_H which is used at RUN.
309 * Else we do return the BD71815_REG_BUCK1_VOLT_H or
310 * BD71815_REG_BUCK1_VOLT_L depending on which is selected to be used
311 * by BD71815_BUCK_DVSSEL bit
313 if ((!(val
& BD71815_BUCK_STBY_DVS
)) && (!(val
& BD71815_BUCK_DVSSEL
)))
314 ret
= regmap_read(rdev
->regmap
, regl
, &val
);
319 return val
& BD71815_VOLT_MASK
;
325 static int bd7181x_buck12_set_voltage_sel(struct regulator_dev
*rdev
,
328 int rid
= rdev_get_id(rdev
);
329 int ret
, val
, reg
, regh
, regl
;
331 regh
= BD71815_REG_BUCK1_VOLT_H
+ rid
*0x2;
332 regl
= BD71815_REG_BUCK1_VOLT_L
+ rid
*0x2;
334 ret
= regmap_read(rdev
->regmap
, regh
, &val
);
339 * If bucks 1 & 2 are controlled by state machine - then the RUN state
340 * voltage is set to BD71815_REG_BUCK1_VOLT_H. Changing SUSPEND/LPSR
341 * voltages at runtime is not supported by this driver.
343 if (((val
& BD71815_BUCK_STBY_DVS
))) {
344 return regmap_update_bits(rdev
->regmap
, regh
, BD71815_VOLT_MASK
,
347 /* Update new voltage to the register which is not selected now */
348 if (val
& BD71815_BUCK_DVSSEL
)
353 ret
= regmap_update_bits(rdev
->regmap
, reg
, BD71815_VOLT_MASK
, sel
);
357 /* Select the other DVS register to be used */
358 return regmap_update_bits(rdev
->regmap
, regh
, BD71815_BUCK_DVSSEL
,
362 static const struct regulator_ops bd7181x_ldo_regulator_ops
= {
363 .enable
= regulator_enable_regmap
,
364 .disable
= regulator_disable_regmap
,
365 .is_enabled
= regulator_is_enabled_regmap
,
366 .list_voltage
= regulator_list_voltage_linear
,
367 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
368 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
371 static const struct regulator_ops bd7181x_fixed_regulator_ops
= {
372 .enable
= regulator_enable_regmap
,
373 .disable
= regulator_disable_regmap
,
374 .is_enabled
= regulator_is_enabled_regmap
,
375 .list_voltage
= regulator_list_voltage_linear
,
378 static const struct regulator_ops bd7181x_buck_regulator_ops
= {
379 .enable
= regulator_enable_regmap
,
380 .disable
= regulator_disable_regmap
,
381 .is_enabled
= regulator_is_enabled_regmap
,
382 .list_voltage
= regulator_list_voltage_linear
,
383 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
384 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
385 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
388 static const struct regulator_ops bd7181x_buck12_regulator_ops
= {
389 .enable
= regulator_enable_regmap
,
390 .disable
= regulator_disable_regmap
,
391 .is_enabled
= regulator_is_enabled_regmap
,
392 .list_voltage
= regulator_list_voltage_linear
,
393 .set_voltage_sel
= bd7181x_buck12_set_voltage_sel
,
394 .get_voltage_sel
= bd7181x_buck12_get_voltage_sel
,
395 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
396 .set_ramp_delay
= regulator_set_ramp_delay_regmap
,
399 static const struct regulator_ops bd7181x_led_regulator_ops
= {
400 .enable
= regulator_enable_regmap
,
401 .disable
= regulator_disable_regmap
,
402 .is_enabled
= regulator_is_enabled_regmap
,
403 .set_current_limit
= bd7181x_led_set_current_limit
,
404 .get_current_limit
= regulator_get_current_limit_regmap
,
407 #define BD71815_FIXED_REG(_name, _id, ereg, emsk, voltage, _dvs) \
411 .of_match = of_match_ptr(#_name), \
412 .regulators_node = of_match_ptr("regulators"), \
414 .ops = &bd7181x_fixed_regulator_ops, \
415 .type = REGULATOR_VOLTAGE, \
417 .owner = THIS_MODULE, \
418 .min_uV = (voltage), \
419 .enable_reg = (ereg), \
420 .enable_mask = (emsk), \
421 .of_parse_cb = set_hw_dvs_levels, \
426 #define BD71815_BUCK_REG(_name, _id, vsel, ereg, min, max, step, _dvs) \
430 .of_match = of_match_ptr(#_name), \
431 .regulators_node = of_match_ptr("regulators"), \
432 .n_voltages = ((max) - (min)) / (step) + 1, \
433 .ops = &bd7181x_buck_regulator_ops, \
434 .type = REGULATOR_VOLTAGE, \
436 .owner = THIS_MODULE, \
439 .vsel_reg = (vsel), \
440 .vsel_mask = BD71815_VOLT_MASK, \
441 .enable_reg = (ereg), \
442 .enable_mask = BD71815_BUCK_RUN_ON, \
443 .of_parse_cb = set_hw_dvs_levels, \
448 #define BD71815_BUCK12_REG(_name, _id, vsel, ereg, min, max, step, \
453 .of_match = of_match_ptr(#_name), \
454 .regulators_node = of_match_ptr("regulators"), \
455 .n_voltages = ((max) - (min)) / (step) + 1, \
456 .ops = &bd7181x_buck12_regulator_ops, \
457 .type = REGULATOR_VOLTAGE, \
459 .owner = THIS_MODULE, \
462 .vsel_reg = (vsel), \
463 .vsel_mask = BD71815_VOLT_MASK, \
464 .enable_reg = (ereg), \
465 .enable_mask = BD71815_BUCK_RUN_ON, \
466 .ramp_reg = (ereg), \
467 .ramp_mask = BD71815_BUCK_RAMPRATE_MASK, \
468 .ramp_delay_table = bd7181x_ramp_table, \
469 .n_ramp_values = ARRAY_SIZE(bd7181x_ramp_table),\
470 .of_parse_cb = buck12_set_hw_dvs_levels, \
475 #define BD71815_LED_REG(_name, _id, csel, mask, ereg, emsk, currents) \
479 .of_match = of_match_ptr(#_name), \
480 .regulators_node = of_match_ptr("regulators"), \
481 .n_current_limits = ARRAY_SIZE(currents), \
482 .ops = &bd7181x_led_regulator_ops, \
483 .type = REGULATOR_CURRENT, \
485 .owner = THIS_MODULE, \
486 .curr_table = currents, \
487 .csel_reg = (csel), \
488 .csel_mask = (mask), \
489 .enable_reg = (ereg), \
490 .enable_mask = (emsk), \
494 #define BD71815_LDO_REG(_name, _id, vsel, ereg, emsk, min, max, step, \
499 .of_match = of_match_ptr(#_name), \
500 .regulators_node = of_match_ptr("regulators"), \
501 .n_voltages = ((max) - (min)) / (step) + 1, \
502 .ops = &bd7181x_ldo_regulator_ops, \
503 .type = REGULATOR_VOLTAGE, \
505 .owner = THIS_MODULE, \
508 .vsel_reg = (vsel), \
509 .vsel_mask = BD71815_VOLT_MASK, \
510 .enable_reg = (ereg), \
511 .enable_mask = (emsk), \
512 .of_parse_cb = set_hw_dvs_levels, \
517 static const struct bd71815_regulator bd71815_regulators
[] = {
518 BD71815_BUCK12_REG(buck1
, BD71815_BUCK1
, BD71815_REG_BUCK1_VOLT_H
,
519 BD71815_REG_BUCK1_MODE
, 800000, 2000000, 25000,
521 BD71815_BUCK12_REG(buck2
, BD71815_BUCK2
, BD71815_REG_BUCK2_VOLT_H
,
522 BD71815_REG_BUCK2_MODE
, 800000, 2000000, 25000,
524 BD71815_BUCK_REG(buck3
, BD71815_BUCK3
, BD71815_REG_BUCK3_VOLT
,
525 BD71815_REG_BUCK3_MODE
, 1200000, 2700000, 50000,
527 BD71815_BUCK_REG(buck4
, BD71815_BUCK4
, BD71815_REG_BUCK4_VOLT
,
528 BD71815_REG_BUCK4_MODE
, 1100000, 1850000, 25000,
530 BD71815_BUCK_REG(buck5
, BD71815_BUCK5
, BD71815_REG_BUCK5_VOLT
,
531 BD71815_REG_BUCK5_MODE
, 1800000, 3300000, 50000,
533 BD71815_LDO_REG(ldo1
, BD71815_LDO1
, BD71815_REG_LDO1_VOLT
,
534 BD71815_REG_LDO_MODE1
, LDO1_RUN_ON
, 800000, 3300000,
536 BD71815_LDO_REG(ldo2
, BD71815_LDO2
, BD71815_REG_LDO2_VOLT
,
537 BD71815_REG_LDO_MODE2
, LDO2_RUN_ON
, 800000, 3300000,
540 * Let's default LDO3 to be enabled by SW. We can override ops if DT
541 * says LDO3 should be enabled by HW when DCIN is connected.
543 BD71815_LDO_REG(ldo3
, BD71815_LDO3
, BD71815_REG_LDO3_VOLT
,
544 BD71815_REG_LDO_MODE2
, LDO3_RUN_ON
, 800000, 3300000,
546 BD71815_LDO_REG(ldo4
, BD71815_LDO4
, BD71815_REG_LDO4_VOLT
,
547 BD71815_REG_LDO_MODE3
, LDO4_RUN_ON
, 800000, 3300000,
549 BD71815_LDO_REG(ldo5
, BD71815_LDO5
, BD71815_REG_LDO5_VOLT_H
,
550 BD71815_REG_LDO_MODE3
, LDO5_RUN_ON
, 800000, 3300000,
552 BD71815_FIXED_REG(ldodvref
, BD71815_LDODVREF
, BD71815_REG_LDO_MODE4
,
553 DVREF_RUN_ON
, 3000000, &dvref_dvs
),
554 BD71815_FIXED_REG(ldolpsr
, BD71815_LDOLPSR
, BD71815_REG_LDO_MODE4
,
555 LDO_LPSR_RUN_ON
, 1800000, &ldolpsr_dvs
),
556 BD71815_LED_REG(wled
, BD71815_WLED
, BD71815_REG_LED_DIMM
, LED_DIMM_MASK
,
557 BD71815_REG_LED_CTRL
, LED_RUN_ON
,
558 bd7181x_wled_currents
),
561 static int bd7181x_probe(struct platform_device
*pdev
)
563 struct regulator_config config
= {};
565 struct gpio_desc
*ldo4_en
;
566 struct regmap
*regmap
;
568 regmap
= dev_get_regmap(pdev
->dev
.parent
, NULL
);
570 dev_err(&pdev
->dev
, "No parent regmap\n");
574 ldo4_en
= devm_fwnode_gpiod_get(&pdev
->dev
,
575 dev_fwnode(pdev
->dev
.parent
),
576 "rohm,vsel", GPIOD_ASIS
, "ldo4-en");
577 if (IS_ERR(ldo4_en
)) {
578 ret
= PTR_ERR(ldo4_en
);
584 /* Disable to go to ship-mode */
585 ret
= regmap_update_bits(regmap
, BD71815_REG_PWRCTRL
, RESTARTEN
, 0);
589 config
.dev
= pdev
->dev
.parent
;
590 config
.regmap
= regmap
;
592 for (i
= 0; i
< BD71815_REGULATOR_CNT
; i
++) {
593 const struct regulator_desc
*desc
;
594 struct regulator_dev
*rdev
;
596 desc
= &bd71815_regulators
[i
].desc
;
598 if (i
== BD71815_LDO4
)
599 config
.ena_gpiod
= ldo4_en
;
601 config
.ena_gpiod
= NULL
;
603 rdev
= devm_regulator_register(&pdev
->dev
, desc
, &config
);
605 return dev_err_probe(&pdev
->dev
, PTR_ERR(rdev
),
606 "failed to register %s regulator\n",
612 static const struct platform_device_id bd7181x_pmic_id
[] = {
613 { "bd71815-pmic", ROHM_CHIP_TYPE_BD71815
},
616 MODULE_DEVICE_TABLE(platform
, bd7181x_pmic_id
);
618 static struct platform_driver bd7181x_regulator
= {
620 .name
= "bd7181x-pmic",
621 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
623 .probe
= bd7181x_probe
,
624 .id_table
= bd7181x_pmic_id
,
626 module_platform_driver(bd7181x_regulator
);
628 MODULE_AUTHOR("Tony Luo <luofc@embedinfo.com>");
629 MODULE_DESCRIPTION("BD71815 voltage regulator driver");
630 MODULE_LICENSE("GPL v2");
631 MODULE_ALIAS("platform:bd7181x-pmic");