1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (C) 2019 ROHM Semiconductors
3 // bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
6 #include <linux/delay.h>
8 #include <linux/gpio.h>
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/mfd/rohm-bd71828.h>
12 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/regulator/machine.h>
18 #include <linux/regulator/of_regulator.h>
25 struct bd71828_regulator_data {
26 struct regulator_desc desc;
27 const struct rohm_dvs_config dvs;
28 const struct reg_init *reg_inits;
32 static const struct reg_init buck1_inits[] = {
34 * DVS Buck voltages can be changed by register values or via GPIO.
35 * Use register accesses by default.
38 .reg = BD71828_REG_PS_CTRL_1,
39 .mask = BD71828_MASK_DVS_BUCK1_CTRL,
40 .val = BD71828_DVS_BUCK1_CTRL_I2C,
44 static const struct reg_init buck2_inits[] = {
46 .reg = BD71828_REG_PS_CTRL_1,
47 .mask = BD71828_MASK_DVS_BUCK2_CTRL,
48 .val = BD71828_DVS_BUCK2_CTRL_I2C,
52 static const struct reg_init buck6_inits[] = {
54 .reg = BD71828_REG_PS_CTRL_1,
55 .mask = BD71828_MASK_DVS_BUCK6_CTRL,
56 .val = BD71828_DVS_BUCK6_CTRL_I2C,
60 static const struct reg_init buck7_inits[] = {
62 .reg = BD71828_REG_PS_CTRL_1,
63 .mask = BD71828_MASK_DVS_BUCK7_CTRL,
64 .val = BD71828_DVS_BUCK7_CTRL_I2C,
68 static const struct linear_range bd71828_buck1267_volts[] = {
69 REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
70 REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
73 static const struct linear_range bd71828_buck3_volts[] = {
74 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
75 REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
78 static const struct linear_range bd71828_buck4_volts[] = {
79 REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
80 REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
83 static const struct linear_range bd71828_buck5_volts[] = {
84 REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
85 REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
88 static const struct linear_range bd71828_ldo_volts[] = {
89 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
90 REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
93 static const unsigned int bd71828_ramp_delay[] = { 2500, 5000, 10000, 20000 };
95 static int buck_set_hw_dvs_levels(struct device_node *np,
96 const struct regulator_desc *desc,
97 struct regulator_config *cfg)
99 struct bd71828_regulator_data *data;
101 data = container_of(desc, struct bd71828_regulator_data, desc);
103 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
106 static int ldo6_parse_dt(struct device_node *np,
107 const struct regulator_desc *desc,
108 struct regulator_config *cfg)
113 struct regmap *regmap = cfg->regmap;
114 static const char * const props[] = { "rohm,dvs-run-voltage",
115 "rohm,dvs-idle-voltage",
116 "rohm,dvs-suspend-voltage",
117 "rohm,dvs-lpsr-voltage" };
118 unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
119 BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
121 for (i = 0; i < ARRAY_SIZE(props); i++) {
122 ret = of_property_read_u32(np, props[i], &uv);
133 ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
140 static const struct regulator_ops bd71828_buck_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,
149 static const struct regulator_ops bd71828_dvs_buck_ops = {
150 .enable = regulator_enable_regmap,
151 .disable = regulator_disable_regmap,
152 .is_enabled = regulator_is_enabled_regmap,
153 .list_voltage = regulator_list_voltage_linear_range,
154 .set_voltage_sel = regulator_set_voltage_sel_regmap,
155 .get_voltage_sel = regulator_get_voltage_sel_regmap,
156 .set_voltage_time_sel = regulator_set_voltage_time_sel,
157 .set_ramp_delay = regulator_set_ramp_delay_regmap,
160 static const struct regulator_ops bd71828_ldo_ops = {
161 .enable = regulator_enable_regmap,
162 .disable = regulator_disable_regmap,
163 .is_enabled = regulator_is_enabled_regmap,
164 .list_voltage = regulator_list_voltage_linear_range,
165 .set_voltage_sel = regulator_set_voltage_sel_regmap,
166 .get_voltage_sel = regulator_get_voltage_sel_regmap,
169 static const struct regulator_ops bd71828_ldo6_ops = {
170 .enable = regulator_enable_regmap,
171 .disable = regulator_disable_regmap,
172 .is_enabled = regulator_is_enabled_regmap,
175 static const struct bd71828_regulator_data bd71828_rdata[] = {
179 .of_match = of_match_ptr("BUCK1"),
180 .regulators_node = of_match_ptr("regulators"),
182 .ops = &bd71828_dvs_buck_ops,
183 .type = REGULATOR_VOLTAGE,
184 .linear_ranges = bd71828_buck1267_volts,
185 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
186 .n_voltages = BD71828_BUCK1267_VOLTS,
187 .enable_reg = BD71828_REG_BUCK1_EN,
188 .enable_mask = BD71828_MASK_RUN_EN,
189 .vsel_reg = BD71828_REG_BUCK1_VOLT,
190 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
191 .ramp_delay_table = bd71828_ramp_delay,
192 .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
193 .ramp_reg = BD71828_REG_BUCK1_MODE,
194 .ramp_mask = BD71828_MASK_RAMP_DELAY,
195 .owner = THIS_MODULE,
196 .of_parse_cb = buck_set_hw_dvs_levels,
199 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
200 ROHM_DVS_LEVEL_SUSPEND |
202 .run_reg = BD71828_REG_BUCK1_VOLT,
203 .run_mask = BD71828_MASK_BUCK1267_VOLT,
204 .idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
205 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
206 .idle_on_mask = BD71828_MASK_IDLE_EN,
207 .suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
208 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
209 .suspend_on_mask = BD71828_MASK_SUSP_EN,
210 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
212 * LPSR voltage is same as SUSPEND voltage. Allow
213 * setting it so that regulator can be set enabled at
216 .lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
217 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
219 .reg_inits = buck1_inits,
220 .reg_init_amnt = ARRAY_SIZE(buck1_inits),
225 .of_match = of_match_ptr("BUCK2"),
226 .regulators_node = of_match_ptr("regulators"),
228 .ops = &bd71828_dvs_buck_ops,
229 .type = REGULATOR_VOLTAGE,
230 .linear_ranges = bd71828_buck1267_volts,
231 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
232 .n_voltages = BD71828_BUCK1267_VOLTS,
233 .enable_reg = BD71828_REG_BUCK2_EN,
234 .enable_mask = BD71828_MASK_RUN_EN,
235 .vsel_reg = BD71828_REG_BUCK2_VOLT,
236 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
237 .ramp_delay_table = bd71828_ramp_delay,
238 .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
239 .ramp_reg = BD71828_REG_BUCK2_MODE,
240 .ramp_mask = BD71828_MASK_RAMP_DELAY,
241 .owner = THIS_MODULE,
242 .of_parse_cb = buck_set_hw_dvs_levels,
245 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
246 ROHM_DVS_LEVEL_SUSPEND |
248 .run_reg = BD71828_REG_BUCK2_VOLT,
249 .run_mask = BD71828_MASK_BUCK1267_VOLT,
250 .idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
251 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
252 .idle_on_mask = BD71828_MASK_IDLE_EN,
253 .suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
254 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
255 .suspend_on_mask = BD71828_MASK_SUSP_EN,
256 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
257 .lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
258 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
260 .reg_inits = buck2_inits,
261 .reg_init_amnt = ARRAY_SIZE(buck2_inits),
266 .of_match = of_match_ptr("BUCK3"),
267 .regulators_node = of_match_ptr("regulators"),
269 .ops = &bd71828_buck_ops,
270 .type = REGULATOR_VOLTAGE,
271 .linear_ranges = bd71828_buck3_volts,
272 .n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
273 .n_voltages = BD71828_BUCK3_VOLTS,
274 .enable_reg = BD71828_REG_BUCK3_EN,
275 .enable_mask = BD71828_MASK_RUN_EN,
276 .vsel_reg = BD71828_REG_BUCK3_VOLT,
277 .vsel_mask = BD71828_MASK_BUCK3_VOLT,
278 .owner = THIS_MODULE,
279 .of_parse_cb = buck_set_hw_dvs_levels,
283 * BUCK3 only supports single voltage for all states.
284 * voltage can be individually enabled for each state
285 * though => allow setting all states to support
286 * enabling power rail on different states.
288 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
289 ROHM_DVS_LEVEL_SUSPEND |
291 .run_reg = BD71828_REG_BUCK3_VOLT,
292 .idle_reg = BD71828_REG_BUCK3_VOLT,
293 .suspend_reg = BD71828_REG_BUCK3_VOLT,
294 .lpsr_reg = BD71828_REG_BUCK3_VOLT,
295 .run_mask = BD71828_MASK_BUCK3_VOLT,
296 .idle_mask = BD71828_MASK_BUCK3_VOLT,
297 .suspend_mask = BD71828_MASK_BUCK3_VOLT,
298 .lpsr_mask = BD71828_MASK_BUCK3_VOLT,
299 .idle_on_mask = BD71828_MASK_IDLE_EN,
300 .suspend_on_mask = BD71828_MASK_SUSP_EN,
301 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
307 .of_match = of_match_ptr("BUCK4"),
308 .regulators_node = of_match_ptr("regulators"),
310 .ops = &bd71828_buck_ops,
311 .type = REGULATOR_VOLTAGE,
312 .linear_ranges = bd71828_buck4_volts,
313 .n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
314 .n_voltages = BD71828_BUCK4_VOLTS,
315 .enable_reg = BD71828_REG_BUCK4_EN,
316 .enable_mask = BD71828_MASK_RUN_EN,
317 .vsel_reg = BD71828_REG_BUCK4_VOLT,
318 .vsel_mask = BD71828_MASK_BUCK4_VOLT,
319 .owner = THIS_MODULE,
320 .of_parse_cb = buck_set_hw_dvs_levels,
324 * BUCK4 only supports single voltage for all states.
325 * voltage can be individually enabled for each state
326 * though => allow setting all states to support
327 * enabling power rail on different states.
329 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
330 ROHM_DVS_LEVEL_SUSPEND |
332 .run_reg = BD71828_REG_BUCK4_VOLT,
333 .idle_reg = BD71828_REG_BUCK4_VOLT,
334 .suspend_reg = BD71828_REG_BUCK4_VOLT,
335 .lpsr_reg = BD71828_REG_BUCK4_VOLT,
336 .run_mask = BD71828_MASK_BUCK4_VOLT,
337 .idle_mask = BD71828_MASK_BUCK4_VOLT,
338 .suspend_mask = BD71828_MASK_BUCK4_VOLT,
339 .lpsr_mask = BD71828_MASK_BUCK4_VOLT,
340 .idle_on_mask = BD71828_MASK_IDLE_EN,
341 .suspend_on_mask = BD71828_MASK_SUSP_EN,
342 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
348 .of_match = of_match_ptr("BUCK5"),
349 .regulators_node = of_match_ptr("regulators"),
351 .ops = &bd71828_buck_ops,
352 .type = REGULATOR_VOLTAGE,
353 .linear_ranges = bd71828_buck5_volts,
354 .n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
355 .n_voltages = BD71828_BUCK5_VOLTS,
356 .enable_reg = BD71828_REG_BUCK5_EN,
357 .enable_mask = BD71828_MASK_RUN_EN,
358 .vsel_reg = BD71828_REG_BUCK5_VOLT,
359 .vsel_mask = BD71828_MASK_BUCK5_VOLT,
360 .owner = THIS_MODULE,
361 .of_parse_cb = buck_set_hw_dvs_levels,
365 * BUCK5 only supports single voltage for all states.
366 * voltage can be individually enabled for each state
367 * though => allow setting all states to support
368 * enabling power rail on different states.
370 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
371 ROHM_DVS_LEVEL_SUSPEND |
373 .run_reg = BD71828_REG_BUCK5_VOLT,
374 .idle_reg = BD71828_REG_BUCK5_VOLT,
375 .suspend_reg = BD71828_REG_BUCK5_VOLT,
376 .lpsr_reg = BD71828_REG_BUCK5_VOLT,
377 .run_mask = BD71828_MASK_BUCK5_VOLT,
378 .idle_mask = BD71828_MASK_BUCK5_VOLT,
379 .suspend_mask = BD71828_MASK_BUCK5_VOLT,
380 .lpsr_mask = BD71828_MASK_BUCK5_VOLT,
381 .idle_on_mask = BD71828_MASK_IDLE_EN,
382 .suspend_on_mask = BD71828_MASK_SUSP_EN,
383 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
389 .of_match = of_match_ptr("BUCK6"),
390 .regulators_node = of_match_ptr("regulators"),
392 .ops = &bd71828_dvs_buck_ops,
393 .type = REGULATOR_VOLTAGE,
394 .linear_ranges = bd71828_buck1267_volts,
395 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
396 .n_voltages = BD71828_BUCK1267_VOLTS,
397 .enable_reg = BD71828_REG_BUCK6_EN,
398 .enable_mask = BD71828_MASK_RUN_EN,
399 .vsel_reg = BD71828_REG_BUCK6_VOLT,
400 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
401 .ramp_delay_table = bd71828_ramp_delay,
402 .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
403 .ramp_reg = BD71828_REG_BUCK6_MODE,
404 .ramp_mask = BD71828_MASK_RAMP_DELAY,
405 .owner = THIS_MODULE,
406 .of_parse_cb = buck_set_hw_dvs_levels,
409 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
410 ROHM_DVS_LEVEL_SUSPEND |
412 .run_reg = BD71828_REG_BUCK6_VOLT,
413 .run_mask = BD71828_MASK_BUCK1267_VOLT,
414 .idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
415 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
416 .idle_on_mask = BD71828_MASK_IDLE_EN,
417 .suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
418 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
419 .suspend_on_mask = BD71828_MASK_SUSP_EN,
420 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
421 .lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
422 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
424 .reg_inits = buck6_inits,
425 .reg_init_amnt = ARRAY_SIZE(buck6_inits),
430 .of_match = of_match_ptr("BUCK7"),
431 .regulators_node = of_match_ptr("regulators"),
433 .ops = &bd71828_dvs_buck_ops,
434 .type = REGULATOR_VOLTAGE,
435 .linear_ranges = bd71828_buck1267_volts,
436 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
437 .n_voltages = BD71828_BUCK1267_VOLTS,
438 .enable_reg = BD71828_REG_BUCK7_EN,
439 .enable_mask = BD71828_MASK_RUN_EN,
440 .vsel_reg = BD71828_REG_BUCK7_VOLT,
441 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
442 .ramp_delay_table = bd71828_ramp_delay,
443 .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
444 .ramp_reg = BD71828_REG_BUCK7_MODE,
445 .ramp_mask = BD71828_MASK_RAMP_DELAY,
446 .owner = THIS_MODULE,
447 .of_parse_cb = buck_set_hw_dvs_levels,
450 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
451 ROHM_DVS_LEVEL_SUSPEND |
453 .run_reg = BD71828_REG_BUCK7_VOLT,
454 .run_mask = BD71828_MASK_BUCK1267_VOLT,
455 .idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
456 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
457 .idle_on_mask = BD71828_MASK_IDLE_EN,
458 .suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
459 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
460 .suspend_on_mask = BD71828_MASK_SUSP_EN,
461 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
462 .lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
463 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
465 .reg_inits = buck7_inits,
466 .reg_init_amnt = ARRAY_SIZE(buck7_inits),
471 .of_match = of_match_ptr("LDO1"),
472 .regulators_node = of_match_ptr("regulators"),
474 .ops = &bd71828_ldo_ops,
475 .type = REGULATOR_VOLTAGE,
476 .linear_ranges = bd71828_ldo_volts,
477 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
478 .n_voltages = BD71828_LDO_VOLTS,
479 .enable_reg = BD71828_REG_LDO1_EN,
480 .enable_mask = BD71828_MASK_RUN_EN,
481 .vsel_reg = BD71828_REG_LDO1_VOLT,
482 .vsel_mask = BD71828_MASK_LDO_VOLT,
483 .owner = THIS_MODULE,
484 .of_parse_cb = buck_set_hw_dvs_levels,
488 * LDO1 only supports single voltage for all states.
489 * voltage can be individually enabled for each state
490 * though => allow setting all states to support
491 * enabling power rail on different states.
493 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
494 ROHM_DVS_LEVEL_SUSPEND |
496 .run_reg = BD71828_REG_LDO1_VOLT,
497 .idle_reg = BD71828_REG_LDO1_VOLT,
498 .suspend_reg = BD71828_REG_LDO1_VOLT,
499 .lpsr_reg = BD71828_REG_LDO1_VOLT,
500 .run_mask = BD71828_MASK_LDO_VOLT,
501 .idle_mask = BD71828_MASK_LDO_VOLT,
502 .suspend_mask = BD71828_MASK_LDO_VOLT,
503 .lpsr_mask = BD71828_MASK_LDO_VOLT,
504 .idle_on_mask = BD71828_MASK_IDLE_EN,
505 .suspend_on_mask = BD71828_MASK_SUSP_EN,
506 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
511 .of_match = of_match_ptr("LDO2"),
512 .regulators_node = of_match_ptr("regulators"),
514 .ops = &bd71828_ldo_ops,
515 .type = REGULATOR_VOLTAGE,
516 .linear_ranges = bd71828_ldo_volts,
517 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
518 .n_voltages = BD71828_LDO_VOLTS,
519 .enable_reg = BD71828_REG_LDO2_EN,
520 .enable_mask = BD71828_MASK_RUN_EN,
521 .vsel_reg = BD71828_REG_LDO2_VOLT,
522 .vsel_mask = BD71828_MASK_LDO_VOLT,
523 .owner = THIS_MODULE,
524 .of_parse_cb = buck_set_hw_dvs_levels,
528 * LDO2 only supports single voltage for all states.
529 * voltage can be individually enabled for each state
530 * though => allow setting all states to support
531 * enabling power rail on different states.
533 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
534 ROHM_DVS_LEVEL_SUSPEND |
536 .run_reg = BD71828_REG_LDO2_VOLT,
537 .idle_reg = BD71828_REG_LDO2_VOLT,
538 .suspend_reg = BD71828_REG_LDO2_VOLT,
539 .lpsr_reg = BD71828_REG_LDO2_VOLT,
540 .run_mask = BD71828_MASK_LDO_VOLT,
541 .idle_mask = BD71828_MASK_LDO_VOLT,
542 .suspend_mask = BD71828_MASK_LDO_VOLT,
543 .lpsr_mask = BD71828_MASK_LDO_VOLT,
544 .idle_on_mask = BD71828_MASK_IDLE_EN,
545 .suspend_on_mask = BD71828_MASK_SUSP_EN,
546 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
551 .of_match = of_match_ptr("LDO3"),
552 .regulators_node = of_match_ptr("regulators"),
554 .ops = &bd71828_ldo_ops,
555 .type = REGULATOR_VOLTAGE,
556 .linear_ranges = bd71828_ldo_volts,
557 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
558 .n_voltages = BD71828_LDO_VOLTS,
559 .enable_reg = BD71828_REG_LDO3_EN,
560 .enable_mask = BD71828_MASK_RUN_EN,
561 .vsel_reg = BD71828_REG_LDO3_VOLT,
562 .vsel_mask = BD71828_MASK_LDO_VOLT,
563 .owner = THIS_MODULE,
564 .of_parse_cb = buck_set_hw_dvs_levels,
568 * LDO3 only supports single voltage for all states.
569 * voltage can be individually enabled for each state
570 * though => allow setting all states to support
571 * enabling power rail on different states.
573 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
574 ROHM_DVS_LEVEL_SUSPEND |
576 .run_reg = BD71828_REG_LDO3_VOLT,
577 .idle_reg = BD71828_REG_LDO3_VOLT,
578 .suspend_reg = BD71828_REG_LDO3_VOLT,
579 .lpsr_reg = BD71828_REG_LDO3_VOLT,
580 .run_mask = BD71828_MASK_LDO_VOLT,
581 .idle_mask = BD71828_MASK_LDO_VOLT,
582 .suspend_mask = BD71828_MASK_LDO_VOLT,
583 .lpsr_mask = BD71828_MASK_LDO_VOLT,
584 .idle_on_mask = BD71828_MASK_IDLE_EN,
585 .suspend_on_mask = BD71828_MASK_SUSP_EN,
586 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
592 .of_match = of_match_ptr("LDO4"),
593 .regulators_node = of_match_ptr("regulators"),
595 .ops = &bd71828_ldo_ops,
596 .type = REGULATOR_VOLTAGE,
597 .linear_ranges = bd71828_ldo_volts,
598 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
599 .n_voltages = BD71828_LDO_VOLTS,
600 .enable_reg = BD71828_REG_LDO4_EN,
601 .enable_mask = BD71828_MASK_RUN_EN,
602 .vsel_reg = BD71828_REG_LDO4_VOLT,
603 .vsel_mask = BD71828_MASK_LDO_VOLT,
604 .owner = THIS_MODULE,
605 .of_parse_cb = buck_set_hw_dvs_levels,
609 * LDO1 only supports single voltage for all states.
610 * voltage can be individually enabled for each state
611 * though => allow setting all states to support
612 * enabling power rail on different states.
614 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
615 ROHM_DVS_LEVEL_SUSPEND |
617 .run_reg = BD71828_REG_LDO4_VOLT,
618 .idle_reg = BD71828_REG_LDO4_VOLT,
619 .suspend_reg = BD71828_REG_LDO4_VOLT,
620 .lpsr_reg = BD71828_REG_LDO4_VOLT,
621 .run_mask = BD71828_MASK_LDO_VOLT,
622 .idle_mask = BD71828_MASK_LDO_VOLT,
623 .suspend_mask = BD71828_MASK_LDO_VOLT,
624 .lpsr_mask = BD71828_MASK_LDO_VOLT,
625 .idle_on_mask = BD71828_MASK_IDLE_EN,
626 .suspend_on_mask = BD71828_MASK_SUSP_EN,
627 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
632 .of_match = of_match_ptr("LDO5"),
633 .regulators_node = of_match_ptr("regulators"),
635 .ops = &bd71828_ldo_ops,
636 .type = REGULATOR_VOLTAGE,
637 .linear_ranges = bd71828_ldo_volts,
638 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
639 .n_voltages = BD71828_LDO_VOLTS,
640 .enable_reg = BD71828_REG_LDO5_EN,
641 .enable_mask = BD71828_MASK_RUN_EN,
642 .vsel_reg = BD71828_REG_LDO5_VOLT,
643 .vsel_mask = BD71828_MASK_LDO_VOLT,
644 .of_parse_cb = buck_set_hw_dvs_levels,
645 .owner = THIS_MODULE,
648 * LDO5 is special. It can choose vsel settings to be configured
649 * from 2 different registers (by GPIO).
651 * This driver supports only configuration where
652 * BD71828_REG_LDO5_VOLT_L is used.
655 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
656 ROHM_DVS_LEVEL_SUSPEND |
658 .run_reg = BD71828_REG_LDO5_VOLT,
659 .idle_reg = BD71828_REG_LDO5_VOLT,
660 .suspend_reg = BD71828_REG_LDO5_VOLT,
661 .lpsr_reg = BD71828_REG_LDO5_VOLT,
662 .run_mask = BD71828_MASK_LDO_VOLT,
663 .idle_mask = BD71828_MASK_LDO_VOLT,
664 .suspend_mask = BD71828_MASK_LDO_VOLT,
665 .lpsr_mask = BD71828_MASK_LDO_VOLT,
666 .idle_on_mask = BD71828_MASK_IDLE_EN,
667 .suspend_on_mask = BD71828_MASK_SUSP_EN,
668 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
674 .of_match = of_match_ptr("LDO6"),
675 .regulators_node = of_match_ptr("regulators"),
677 .ops = &bd71828_ldo6_ops,
678 .type = REGULATOR_VOLTAGE,
679 .fixed_uV = BD71828_LDO_6_VOLTAGE,
681 .enable_reg = BD71828_REG_LDO6_EN,
682 .enable_mask = BD71828_MASK_RUN_EN,
683 .owner = THIS_MODULE,
685 * LDO6 only supports enable/disable for all states.
686 * Voltage for LDO6 is fixed.
688 .of_parse_cb = ldo6_parse_dt,
692 /* SNVS LDO in data-sheet */
694 .of_match = of_match_ptr("LDO7"),
695 .regulators_node = of_match_ptr("regulators"),
696 .id = BD71828_LDO_SNVS,
697 .ops = &bd71828_ldo_ops,
698 .type = REGULATOR_VOLTAGE,
699 .linear_ranges = bd71828_ldo_volts,
700 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
701 .n_voltages = BD71828_LDO_VOLTS,
702 .enable_reg = BD71828_REG_LDO7_EN,
703 .enable_mask = BD71828_MASK_RUN_EN,
704 .vsel_reg = BD71828_REG_LDO7_VOLT,
705 .vsel_mask = BD71828_MASK_LDO_VOLT,
706 .owner = THIS_MODULE,
707 .of_parse_cb = buck_set_hw_dvs_levels,
711 * LDO7 only supports single voltage for all states.
712 * voltage can be individually enabled for each state
713 * though => allow setting all states to support
714 * enabling power rail on different states.
716 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
717 ROHM_DVS_LEVEL_SUSPEND |
719 .run_reg = BD71828_REG_LDO7_VOLT,
720 .idle_reg = BD71828_REG_LDO7_VOLT,
721 .suspend_reg = BD71828_REG_LDO7_VOLT,
722 .lpsr_reg = BD71828_REG_LDO7_VOLT,
723 .run_mask = BD71828_MASK_LDO_VOLT,
724 .idle_mask = BD71828_MASK_LDO_VOLT,
725 .suspend_mask = BD71828_MASK_LDO_VOLT,
726 .lpsr_mask = BD71828_MASK_LDO_VOLT,
727 .idle_on_mask = BD71828_MASK_IDLE_EN,
728 .suspend_on_mask = BD71828_MASK_SUSP_EN,
729 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
735 static int bd71828_probe(struct platform_device *pdev)
738 struct regulator_config config = {
739 .dev = pdev->dev.parent,
742 config.regmap = dev_get_regmap(pdev->dev.parent, NULL);
746 for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
747 struct regulator_dev *rdev;
748 const struct bd71828_regulator_data *rd;
750 rd = &bd71828_rdata[i];
751 rdev = devm_regulator_register(&pdev->dev,
755 "failed to register %s regulator\n",
757 return PTR_ERR(rdev);
759 for (j = 0; j < rd->reg_init_amnt; j++) {
760 ret = regmap_update_bits(config.regmap,
761 rd->reg_inits[j].reg,
762 rd->reg_inits[j].mask,
763 rd->reg_inits[j].val);
766 "regulator %s init failed\n",
775 static struct platform_driver bd71828_regulator = {
777 .name = "bd71828-pmic"
779 .probe = bd71828_probe,
782 module_platform_driver(bd71828_regulator);
784 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
785 MODULE_DESCRIPTION("BD71828 voltage regulator driver");
786 MODULE_LICENSE("GPL");
787 MODULE_ALIAS("platform:bd71828-pmic");