blob: edba51da56619501dc5a7830538259579eac28b1 [file] [log] [blame]
Matti Vaittinen522498f2019-12-11 11:46:11 +02001// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (C) 2019 ROHM Semiconductors
3// bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
4//
5
6#include <linux/delay.h>
7#include <linux/err.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>
13#include <linux/of.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>
19
20struct reg_init {
21 unsigned int reg;
22 unsigned int mask;
23 unsigned int val;
24};
25struct bd71828_regulator_data {
26 struct regulator_desc desc;
27 const struct rohm_dvs_config dvs;
28 const struct reg_init *reg_inits;
29 int reg_init_amnt;
30};
31
32static const struct reg_init buck1_inits[] = {
33 /*
34 * DVS Buck voltages can be changed by register values or via GPIO.
35 * Use register accesses by default.
36 */
37 {
38 .reg = BD71828_REG_PS_CTRL_1,
39 .mask = BD71828_MASK_DVS_BUCK1_CTRL,
40 .val = BD71828_DVS_BUCK1_CTRL_I2C,
41 },
42};
43
44static const struct reg_init buck2_inits[] = {
45 {
46 .reg = BD71828_REG_PS_CTRL_1,
47 .mask = BD71828_MASK_DVS_BUCK2_CTRL,
48 .val = BD71828_DVS_BUCK2_CTRL_I2C,
49 },
50};
51
52static const struct reg_init buck6_inits[] = {
53 {
54 .reg = BD71828_REG_PS_CTRL_1,
55 .mask = BD71828_MASK_DVS_BUCK6_CTRL,
56 .val = BD71828_DVS_BUCK6_CTRL_I2C,
57 },
58};
59
60static const struct reg_init buck7_inits[] = {
61 {
62 .reg = BD71828_REG_PS_CTRL_1,
63 .mask = BD71828_MASK_DVS_BUCK7_CTRL,
64 .val = BD71828_DVS_BUCK7_CTRL_I2C,
65 },
66};
67
68static const struct regulator_linear_range bd71828_buck1267_volts[] = {
69 REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
70 REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
71};
72
73static const struct regulator_linear_range bd71828_buck3_volts[] = {
74 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
75 REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
76};
77
78static const struct regulator_linear_range bd71828_buck4_volts[] = {
79 REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
80 REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
81};
82
83static const struct regulator_linear_range bd71828_buck5_volts[] = {
84 REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
85 REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
86};
87
88static const struct regulator_linear_range bd71828_ldo_volts[] = {
89 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
90 REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
91};
92
93static int bd71828_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
94{
95 unsigned int val;
96
97 switch (ramp_delay) {
98 case 1 ... 2500:
99 val = 0;
100 break;
101 case 2501 ... 5000:
102 val = 1;
103 break;
104 case 5001 ... 10000:
105 val = 2;
106 break;
107 case 10001 ... 20000:
108 val = 3;
109 break;
110 default:
111 val = 3;
112 dev_err(&rdev->dev,
113 "ramp_delay: %d not supported, setting 20mV/uS",
114 ramp_delay);
115 }
116
117 /*
118 * On BD71828 the ramp delay level control reg is at offset +2 to
119 * enable reg
120 */
121 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg + 2,
122 BD71828_MASK_RAMP_DELAY,
123 val << (ffs(BD71828_MASK_RAMP_DELAY) - 1));
124}
125
126static int buck_set_hw_dvs_levels(struct device_node *np,
127 const struct regulator_desc *desc,
128 struct regulator_config *cfg)
129{
130 struct bd71828_regulator_data *data;
131
132 data = container_of(desc, struct bd71828_regulator_data, desc);
133
134 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
135}
136
137static int ldo6_parse_dt(struct device_node *np,
138 const struct regulator_desc *desc,
139 struct regulator_config *cfg)
140{
141 int ret, i;
142 uint32_t uv = 0;
143 unsigned int en;
144 struct regmap *regmap = cfg->regmap;
145 static const char * const props[] = { "rohm,dvs-run-voltage",
146 "rohm,dvs-idle-voltage",
147 "rohm,dvs-suspend-voltage",
148 "rohm,dvs-lpsr-voltage" };
149 unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
150 BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
151
152 for (i = 0; i < ARRAY_SIZE(props); i++) {
153 ret = of_property_read_u32(np, props[i], &uv);
154 if (ret) {
155 if (ret != -EINVAL)
156 return ret;
157 continue;
158 }
159 if (uv)
160 en = 0xffffffff;
161 else
162 en = 0;
163
164 ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
165 if (ret)
166 return ret;
167 }
168 return 0;
169}
170
171static const struct regulator_ops bd71828_buck_ops = {
172 .enable = regulator_enable_regmap,
173 .disable = regulator_disable_regmap,
174 .is_enabled = regulator_is_enabled_regmap,
175 .list_voltage = regulator_list_voltage_linear_range,
176 .set_voltage_sel = regulator_set_voltage_sel_regmap,
177 .get_voltage_sel = regulator_get_voltage_sel_regmap,
178};
179
180static const struct regulator_ops bd71828_dvs_buck_ops = {
181 .enable = regulator_enable_regmap,
182 .disable = regulator_disable_regmap,
183 .is_enabled = regulator_is_enabled_regmap,
184 .list_voltage = regulator_list_voltage_linear_range,
185 .set_voltage_sel = regulator_set_voltage_sel_regmap,
186 .get_voltage_sel = regulator_get_voltage_sel_regmap,
187 .set_voltage_time_sel = regulator_set_voltage_time_sel,
188 .set_ramp_delay = bd71828_set_ramp_delay,
189};
190
191static const struct regulator_ops bd71828_ldo_ops = {
192 .enable = regulator_enable_regmap,
193 .disable = regulator_disable_regmap,
194 .is_enabled = regulator_is_enabled_regmap,
195 .list_voltage = regulator_list_voltage_linear_range,
196 .set_voltage_sel = regulator_set_voltage_sel_regmap,
197 .get_voltage_sel = regulator_get_voltage_sel_regmap,
198};
199
200static int bd71828_ldo6_get_voltage(struct regulator_dev *rdev)
201{
202 return BD71828_LDO_6_VOLTAGE;
203}
204
205static const struct regulator_ops bd71828_ldo6_ops = {
206 .enable = regulator_enable_regmap,
207 .disable = regulator_disable_regmap,
208 .get_voltage = bd71828_ldo6_get_voltage,
209 .is_enabled = regulator_is_enabled_regmap,
210};
211
212static const struct bd71828_regulator_data bd71828_rdata[] = {
213 {
214 .desc = {
215 .name = "buck1",
216 .of_match = of_match_ptr("BUCK1"),
217 .regulators_node = of_match_ptr("regulators"),
218 .id = BD71828_BUCK1,
219 .ops = &bd71828_dvs_buck_ops,
220 .type = REGULATOR_VOLTAGE,
221 .linear_ranges = bd71828_buck1267_volts,
222 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
223 .n_voltages = BD71828_BUCK1267_VOLTS,
224 .enable_reg = BD71828_REG_BUCK1_EN,
225 .enable_mask = BD71828_MASK_RUN_EN,
226 .vsel_reg = BD71828_REG_BUCK1_VOLT,
227 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
228 .owner = THIS_MODULE,
229 .of_parse_cb = buck_set_hw_dvs_levels,
230 },
231 .dvs = {
232 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
233 ROHM_DVS_LEVEL_SUSPEND |
234 ROHM_DVS_LEVEL_LPSR,
235 .run_reg = BD71828_REG_BUCK1_VOLT,
236 .run_mask = BD71828_MASK_BUCK1267_VOLT,
237 .idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
238 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
239 .idle_on_mask = BD71828_MASK_IDLE_EN,
240 .suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
241 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
242 .suspend_on_mask = BD71828_MASK_SUSP_EN,
243 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
244 /*
245 * LPSR voltage is same as SUSPEND voltage. Allow
246 * setting it so that regulator can be set enabled at
247 * LPSR state
248 */
249 .lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
250 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
251 },
252 .reg_inits = buck1_inits,
253 .reg_init_amnt = ARRAY_SIZE(buck1_inits),
254 },
255 {
256 .desc = {
257 .name = "buck2",
258 .of_match = of_match_ptr("BUCK2"),
259 .regulators_node = of_match_ptr("regulators"),
260 .id = BD71828_BUCK2,
261 .ops = &bd71828_dvs_buck_ops,
262 .type = REGULATOR_VOLTAGE,
263 .linear_ranges = bd71828_buck1267_volts,
264 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
265 .n_voltages = BD71828_BUCK1267_VOLTS,
266 .enable_reg = BD71828_REG_BUCK2_EN,
267 .enable_mask = BD71828_MASK_RUN_EN,
268 .vsel_reg = BD71828_REG_BUCK2_VOLT,
269 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
270 .owner = THIS_MODULE,
271 .of_parse_cb = buck_set_hw_dvs_levels,
272 },
273 .dvs = {
274 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
275 ROHM_DVS_LEVEL_SUSPEND |
276 ROHM_DVS_LEVEL_LPSR,
277 .run_reg = BD71828_REG_BUCK2_VOLT,
278 .run_mask = BD71828_MASK_BUCK1267_VOLT,
279 .idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
280 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
281 .idle_on_mask = BD71828_MASK_IDLE_EN,
282 .suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
283 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
284 .suspend_on_mask = BD71828_MASK_SUSP_EN,
285 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
286 .lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
287 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
288 },
289 .reg_inits = buck2_inits,
290 .reg_init_amnt = ARRAY_SIZE(buck2_inits),
291 },
292 {
293 .desc = {
294 .name = "buck3",
295 .of_match = of_match_ptr("BUCK3"),
296 .regulators_node = of_match_ptr("regulators"),
297 .id = BD71828_BUCK3,
298 .ops = &bd71828_buck_ops,
299 .type = REGULATOR_VOLTAGE,
300 .linear_ranges = bd71828_buck3_volts,
301 .n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
302 .n_voltages = BD71828_BUCK3_VOLTS,
303 .enable_reg = BD71828_REG_BUCK3_EN,
304 .enable_mask = BD71828_MASK_RUN_EN,
305 .vsel_reg = BD71828_REG_BUCK3_VOLT,
306 .vsel_mask = BD71828_MASK_BUCK3_VOLT,
307 .owner = THIS_MODULE,
308 .of_parse_cb = buck_set_hw_dvs_levels,
309 },
310 .dvs = {
311 /*
312 * BUCK3 only supports single voltage for all states.
313 * voltage can be individually enabled for each state
314 * though => allow setting all states to support
315 * enabling power rail on different states.
316 */
317 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
318 ROHM_DVS_LEVEL_SUSPEND |
319 ROHM_DVS_LEVEL_LPSR,
320 .run_reg = BD71828_REG_BUCK3_VOLT,
321 .idle_reg = BD71828_REG_BUCK3_VOLT,
322 .suspend_reg = BD71828_REG_BUCK3_VOLT,
323 .lpsr_reg = BD71828_REG_BUCK3_VOLT,
324 .run_mask = BD71828_MASK_BUCK3_VOLT,
325 .idle_mask = BD71828_MASK_BUCK3_VOLT,
326 .suspend_mask = BD71828_MASK_BUCK3_VOLT,
327 .lpsr_mask = BD71828_MASK_BUCK3_VOLT,
328 .idle_on_mask = BD71828_MASK_IDLE_EN,
329 .suspend_on_mask = BD71828_MASK_SUSP_EN,
330 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
331 },
332 },
333 {
334 .desc = {
335 .name = "buck4",
336 .of_match = of_match_ptr("BUCK4"),
337 .regulators_node = of_match_ptr("regulators"),
338 .id = BD71828_BUCK4,
339 .ops = &bd71828_buck_ops,
340 .type = REGULATOR_VOLTAGE,
341 .linear_ranges = bd71828_buck4_volts,
342 .n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
343 .n_voltages = BD71828_BUCK4_VOLTS,
344 .enable_reg = BD71828_REG_BUCK4_EN,
345 .enable_mask = BD71828_MASK_RUN_EN,
346 .vsel_reg = BD71828_REG_BUCK4_VOLT,
347 .vsel_mask = BD71828_MASK_BUCK4_VOLT,
348 .owner = THIS_MODULE,
349 .of_parse_cb = buck_set_hw_dvs_levels,
350 },
351 .dvs = {
352 /*
353 * BUCK4 only supports single voltage for all states.
354 * voltage can be individually enabled for each state
355 * though => allow setting all states to support
356 * enabling power rail on different states.
357 */
358 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
359 ROHM_DVS_LEVEL_SUSPEND |
360 ROHM_DVS_LEVEL_LPSR,
361 .run_reg = BD71828_REG_BUCK4_VOLT,
362 .idle_reg = BD71828_REG_BUCK4_VOLT,
363 .suspend_reg = BD71828_REG_BUCK4_VOLT,
364 .lpsr_reg = BD71828_REG_BUCK4_VOLT,
365 .run_mask = BD71828_MASK_BUCK4_VOLT,
366 .idle_mask = BD71828_MASK_BUCK4_VOLT,
367 .suspend_mask = BD71828_MASK_BUCK4_VOLT,
368 .lpsr_mask = BD71828_MASK_BUCK4_VOLT,
369 .idle_on_mask = BD71828_MASK_IDLE_EN,
370 .suspend_on_mask = BD71828_MASK_SUSP_EN,
371 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
372 },
373 },
374 {
375 .desc = {
376 .name = "buck5",
377 .of_match = of_match_ptr("BUCK5"),
378 .regulators_node = of_match_ptr("regulators"),
379 .id = BD71828_BUCK5,
380 .ops = &bd71828_buck_ops,
381 .type = REGULATOR_VOLTAGE,
382 .linear_ranges = bd71828_buck5_volts,
383 .n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
384 .n_voltages = BD71828_BUCK5_VOLTS,
385 .enable_reg = BD71828_REG_BUCK5_EN,
386 .enable_mask = BD71828_MASK_RUN_EN,
387 .vsel_reg = BD71828_REG_BUCK5_VOLT,
388 .vsel_mask = BD71828_MASK_BUCK5_VOLT,
389 .owner = THIS_MODULE,
390 .of_parse_cb = buck_set_hw_dvs_levels,
391 },
392 .dvs = {
393 /*
394 * BUCK5 only supports single voltage for all states.
395 * voltage can be individually enabled for each state
396 * though => allow setting all states to support
397 * enabling power rail on different states.
398 */
399 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
400 ROHM_DVS_LEVEL_SUSPEND |
401 ROHM_DVS_LEVEL_LPSR,
402 .run_reg = BD71828_REG_BUCK5_VOLT,
403 .idle_reg = BD71828_REG_BUCK5_VOLT,
404 .suspend_reg = BD71828_REG_BUCK5_VOLT,
405 .lpsr_reg = BD71828_REG_BUCK5_VOLT,
406 .run_mask = BD71828_MASK_BUCK5_VOLT,
407 .idle_mask = BD71828_MASK_BUCK5_VOLT,
408 .suspend_mask = BD71828_MASK_BUCK5_VOLT,
409 .lpsr_mask = BD71828_MASK_BUCK5_VOLT,
410 .idle_on_mask = BD71828_MASK_IDLE_EN,
411 .suspend_on_mask = BD71828_MASK_SUSP_EN,
412 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
413 },
414 },
415 {
416 .desc = {
417 .name = "buck6",
418 .of_match = of_match_ptr("BUCK6"),
419 .regulators_node = of_match_ptr("regulators"),
420 .id = BD71828_BUCK6,
421 .ops = &bd71828_dvs_buck_ops,
422 .type = REGULATOR_VOLTAGE,
423 .linear_ranges = bd71828_buck1267_volts,
424 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
425 .n_voltages = BD71828_BUCK1267_VOLTS,
426 .enable_reg = BD71828_REG_BUCK6_EN,
427 .enable_mask = BD71828_MASK_RUN_EN,
428 .vsel_reg = BD71828_REG_BUCK6_VOLT,
429 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
430 .owner = THIS_MODULE,
431 .of_parse_cb = buck_set_hw_dvs_levels,
432 },
433 .dvs = {
434 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
435 ROHM_DVS_LEVEL_SUSPEND |
436 ROHM_DVS_LEVEL_LPSR,
437 .run_reg = BD71828_REG_BUCK6_VOLT,
438 .run_mask = BD71828_MASK_BUCK1267_VOLT,
439 .idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
440 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
441 .idle_on_mask = BD71828_MASK_IDLE_EN,
442 .suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
443 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
444 .suspend_on_mask = BD71828_MASK_SUSP_EN,
445 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
446 .lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
447 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
448 },
449 .reg_inits = buck6_inits,
450 .reg_init_amnt = ARRAY_SIZE(buck6_inits),
451 },
452 {
453 .desc = {
454 .name = "buck7",
455 .of_match = of_match_ptr("BUCK7"),
456 .regulators_node = of_match_ptr("regulators"),
457 .id = BD71828_BUCK7,
458 .ops = &bd71828_dvs_buck_ops,
459 .type = REGULATOR_VOLTAGE,
460 .linear_ranges = bd71828_buck1267_volts,
461 .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
462 .n_voltages = BD71828_BUCK1267_VOLTS,
463 .enable_reg = BD71828_REG_BUCK7_EN,
464 .enable_mask = BD71828_MASK_RUN_EN,
465 .vsel_reg = BD71828_REG_BUCK7_VOLT,
466 .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
467 .owner = THIS_MODULE,
468 .of_parse_cb = buck_set_hw_dvs_levels,
469 },
470 .dvs = {
471 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
472 ROHM_DVS_LEVEL_SUSPEND |
473 ROHM_DVS_LEVEL_LPSR,
474 .run_reg = BD71828_REG_BUCK7_VOLT,
475 .run_mask = BD71828_MASK_BUCK1267_VOLT,
476 .idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
477 .idle_mask = BD71828_MASK_BUCK1267_VOLT,
478 .idle_on_mask = BD71828_MASK_IDLE_EN,
479 .suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
480 .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
481 .suspend_on_mask = BD71828_MASK_SUSP_EN,
482 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
483 .lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
484 .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
485 },
486 .reg_inits = buck7_inits,
487 .reg_init_amnt = ARRAY_SIZE(buck7_inits),
488 },
489 {
490 .desc = {
491 .name = "ldo1",
492 .of_match = of_match_ptr("LDO1"),
493 .regulators_node = of_match_ptr("regulators"),
494 .id = BD71828_LDO1,
495 .ops = &bd71828_ldo_ops,
496 .type = REGULATOR_VOLTAGE,
497 .linear_ranges = bd71828_ldo_volts,
498 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
499 .n_voltages = BD71828_LDO_VOLTS,
500 .enable_reg = BD71828_REG_LDO1_EN,
501 .enable_mask = BD71828_MASK_RUN_EN,
502 .vsel_reg = BD71828_REG_LDO1_VOLT,
503 .vsel_mask = BD71828_MASK_LDO_VOLT,
504 .owner = THIS_MODULE,
505 .of_parse_cb = buck_set_hw_dvs_levels,
506 },
507 .dvs = {
508 /*
509 * LDO1 only supports single voltage for all states.
510 * voltage can be individually enabled for each state
511 * though => allow setting all states to support
512 * enabling power rail on different states.
513 */
514 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
515 ROHM_DVS_LEVEL_SUSPEND |
516 ROHM_DVS_LEVEL_LPSR,
517 .run_reg = BD71828_REG_LDO1_VOLT,
518 .idle_reg = BD71828_REG_LDO1_VOLT,
519 .suspend_reg = BD71828_REG_LDO1_VOLT,
520 .lpsr_reg = BD71828_REG_LDO1_VOLT,
521 .run_mask = BD71828_MASK_LDO_VOLT,
522 .idle_mask = BD71828_MASK_LDO_VOLT,
523 .suspend_mask = BD71828_MASK_LDO_VOLT,
524 .lpsr_mask = BD71828_MASK_LDO_VOLT,
525 .idle_on_mask = BD71828_MASK_IDLE_EN,
526 .suspend_on_mask = BD71828_MASK_SUSP_EN,
527 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
528 },
529 }, {
530 .desc = {
531 .name = "ldo2",
532 .of_match = of_match_ptr("LDO2"),
533 .regulators_node = of_match_ptr("regulators"),
534 .id = BD71828_LDO2,
535 .ops = &bd71828_ldo_ops,
536 .type = REGULATOR_VOLTAGE,
537 .linear_ranges = bd71828_ldo_volts,
538 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
539 .n_voltages = BD71828_LDO_VOLTS,
540 .enable_reg = BD71828_REG_LDO2_EN,
541 .enable_mask = BD71828_MASK_RUN_EN,
542 .vsel_reg = BD71828_REG_LDO2_VOLT,
543 .vsel_mask = BD71828_MASK_LDO_VOLT,
544 .owner = THIS_MODULE,
545 .of_parse_cb = buck_set_hw_dvs_levels,
546 },
547 .dvs = {
548 /*
549 * LDO2 only supports single voltage for all states.
550 * voltage can be individually enabled for each state
551 * though => allow setting all states to support
552 * enabling power rail on different states.
553 */
554 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
555 ROHM_DVS_LEVEL_SUSPEND |
556 ROHM_DVS_LEVEL_LPSR,
557 .run_reg = BD71828_REG_LDO2_VOLT,
558 .idle_reg = BD71828_REG_LDO2_VOLT,
559 .suspend_reg = BD71828_REG_LDO2_VOLT,
560 .lpsr_reg = BD71828_REG_LDO2_VOLT,
561 .run_mask = BD71828_MASK_LDO_VOLT,
562 .idle_mask = BD71828_MASK_LDO_VOLT,
563 .suspend_mask = BD71828_MASK_LDO_VOLT,
564 .lpsr_mask = BD71828_MASK_LDO_VOLT,
565 .idle_on_mask = BD71828_MASK_IDLE_EN,
566 .suspend_on_mask = BD71828_MASK_SUSP_EN,
567 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
568 },
569 }, {
570 .desc = {
571 .name = "ldo3",
572 .of_match = of_match_ptr("LDO3"),
573 .regulators_node = of_match_ptr("regulators"),
574 .id = BD71828_LDO3,
575 .ops = &bd71828_ldo_ops,
576 .type = REGULATOR_VOLTAGE,
577 .linear_ranges = bd71828_ldo_volts,
578 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
579 .n_voltages = BD71828_LDO_VOLTS,
580 .enable_reg = BD71828_REG_LDO3_EN,
581 .enable_mask = BD71828_MASK_RUN_EN,
582 .vsel_reg = BD71828_REG_LDO3_VOLT,
583 .vsel_mask = BD71828_MASK_LDO_VOLT,
584 .owner = THIS_MODULE,
585 .of_parse_cb = buck_set_hw_dvs_levels,
586 },
587 .dvs = {
588 /*
589 * LDO3 only supports single voltage for all states.
590 * voltage can be individually enabled for each state
591 * though => allow setting all states to support
592 * enabling power rail on different states.
593 */
594 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
595 ROHM_DVS_LEVEL_SUSPEND |
596 ROHM_DVS_LEVEL_LPSR,
597 .run_reg = BD71828_REG_LDO3_VOLT,
598 .idle_reg = BD71828_REG_LDO3_VOLT,
599 .suspend_reg = BD71828_REG_LDO3_VOLT,
600 .lpsr_reg = BD71828_REG_LDO3_VOLT,
601 .run_mask = BD71828_MASK_LDO_VOLT,
602 .idle_mask = BD71828_MASK_LDO_VOLT,
603 .suspend_mask = BD71828_MASK_LDO_VOLT,
604 .lpsr_mask = BD71828_MASK_LDO_VOLT,
605 .idle_on_mask = BD71828_MASK_IDLE_EN,
606 .suspend_on_mask = BD71828_MASK_SUSP_EN,
607 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
608 },
609
610 }, {
611 .desc = {
612 .name = "ldo4",
613 .of_match = of_match_ptr("LDO4"),
614 .regulators_node = of_match_ptr("regulators"),
615 .id = BD71828_LDO4,
616 .ops = &bd71828_ldo_ops,
617 .type = REGULATOR_VOLTAGE,
618 .linear_ranges = bd71828_ldo_volts,
619 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
620 .n_voltages = BD71828_LDO_VOLTS,
621 .enable_reg = BD71828_REG_LDO4_EN,
622 .enable_mask = BD71828_MASK_RUN_EN,
623 .vsel_reg = BD71828_REG_LDO4_VOLT,
624 .vsel_mask = BD71828_MASK_LDO_VOLT,
625 .owner = THIS_MODULE,
626 .of_parse_cb = buck_set_hw_dvs_levels,
627 },
628 .dvs = {
629 /*
630 * LDO1 only supports single voltage for all states.
631 * voltage can be individually enabled for each state
632 * though => allow setting all states to support
633 * enabling power rail on different states.
634 */
635 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
636 ROHM_DVS_LEVEL_SUSPEND |
637 ROHM_DVS_LEVEL_LPSR,
638 .run_reg = BD71828_REG_LDO4_VOLT,
639 .idle_reg = BD71828_REG_LDO4_VOLT,
640 .suspend_reg = BD71828_REG_LDO4_VOLT,
641 .lpsr_reg = BD71828_REG_LDO4_VOLT,
642 .run_mask = BD71828_MASK_LDO_VOLT,
643 .idle_mask = BD71828_MASK_LDO_VOLT,
644 .suspend_mask = BD71828_MASK_LDO_VOLT,
645 .lpsr_mask = BD71828_MASK_LDO_VOLT,
646 .idle_on_mask = BD71828_MASK_IDLE_EN,
647 .suspend_on_mask = BD71828_MASK_SUSP_EN,
648 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
649 },
650 }, {
651 .desc = {
652 .name = "ldo5",
653 .of_match = of_match_ptr("LDO5"),
654 .regulators_node = of_match_ptr("regulators"),
655 .id = BD71828_LDO5,
656 .ops = &bd71828_ldo_ops,
657 .type = REGULATOR_VOLTAGE,
658 .linear_ranges = bd71828_ldo_volts,
659 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
660 .n_voltages = BD71828_LDO_VOLTS,
661 .enable_reg = BD71828_REG_LDO5_EN,
662 .enable_mask = BD71828_MASK_RUN_EN,
663 .vsel_reg = BD71828_REG_LDO5_VOLT,
664 .vsel_mask = BD71828_MASK_LDO_VOLT,
665 .of_parse_cb = buck_set_hw_dvs_levels,
666 .owner = THIS_MODULE,
667 },
668 /*
669 * LDO5 is special. It can choose vsel settings to be configured
670 * from 2 different registers (by GPIO).
671 *
672 * This driver supports only configuration where
673 * BD71828_REG_LDO5_VOLT_L is used.
674 */
675 .dvs = {
676 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
677 ROHM_DVS_LEVEL_SUSPEND |
678 ROHM_DVS_LEVEL_LPSR,
679 .run_reg = BD71828_REG_LDO5_VOLT,
680 .idle_reg = BD71828_REG_LDO5_VOLT,
681 .suspend_reg = BD71828_REG_LDO5_VOLT,
682 .lpsr_reg = BD71828_REG_LDO5_VOLT,
683 .run_mask = BD71828_MASK_LDO_VOLT,
684 .idle_mask = BD71828_MASK_LDO_VOLT,
685 .suspend_mask = BD71828_MASK_LDO_VOLT,
686 .lpsr_mask = BD71828_MASK_LDO_VOLT,
687 .idle_on_mask = BD71828_MASK_IDLE_EN,
688 .suspend_on_mask = BD71828_MASK_SUSP_EN,
689 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
690 },
691
692 }, {
693 .desc = {
694 .name = "ldo6",
695 .of_match = of_match_ptr("LDO6"),
696 .regulators_node = of_match_ptr("regulators"),
697 .id = BD71828_LDO6,
698 .ops = &bd71828_ldo6_ops,
699 .type = REGULATOR_VOLTAGE,
700 .n_voltages = 1,
701 .enable_reg = BD71828_REG_LDO6_EN,
702 .enable_mask = BD71828_MASK_RUN_EN,
703 .owner = THIS_MODULE,
704 /*
705 * LDO6 only supports enable/disable for all states.
706 * Voltage for LDO6 is fixed.
707 */
708 .of_parse_cb = ldo6_parse_dt,
709 },
710 }, {
711 .desc = {
712 /* SNVS LDO in data-sheet */
713 .name = "ldo7",
714 .of_match = of_match_ptr("LDO7"),
715 .regulators_node = of_match_ptr("regulators"),
716 .id = BD71828_LDO_SNVS,
717 .ops = &bd71828_ldo_ops,
718 .type = REGULATOR_VOLTAGE,
719 .linear_ranges = bd71828_ldo_volts,
720 .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
721 .n_voltages = BD71828_LDO_VOLTS,
722 .enable_reg = BD71828_REG_LDO7_EN,
723 .enable_mask = BD71828_MASK_RUN_EN,
724 .vsel_reg = BD71828_REG_LDO7_VOLT,
725 .vsel_mask = BD71828_MASK_LDO_VOLT,
726 .owner = THIS_MODULE,
727 .of_parse_cb = buck_set_hw_dvs_levels,
728 },
729 .dvs = {
730 /*
731 * LDO7 only supports single voltage for all states.
732 * voltage can be individually enabled for each state
733 * though => allow setting all states to support
734 * enabling power rail on different states.
735 */
736 .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
737 ROHM_DVS_LEVEL_SUSPEND |
738 ROHM_DVS_LEVEL_LPSR,
739 .run_reg = BD71828_REG_LDO7_VOLT,
740 .idle_reg = BD71828_REG_LDO7_VOLT,
741 .suspend_reg = BD71828_REG_LDO7_VOLT,
742 .lpsr_reg = BD71828_REG_LDO7_VOLT,
743 .run_mask = BD71828_MASK_LDO_VOLT,
744 .idle_mask = BD71828_MASK_LDO_VOLT,
745 .suspend_mask = BD71828_MASK_LDO_VOLT,
746 .lpsr_mask = BD71828_MASK_LDO_VOLT,
747 .idle_on_mask = BD71828_MASK_IDLE_EN,
748 .suspend_on_mask = BD71828_MASK_SUSP_EN,
749 .lpsr_on_mask = BD71828_MASK_LPSR_EN,
750 },
751
752 },
753};
754
755static int bd71828_probe(struct platform_device *pdev)
756{
757 struct rohm_regmap_dev *bd71828;
758 int i, j, ret;
759 struct regulator_config config = {
760 .dev = pdev->dev.parent,
761 };
762
763 bd71828 = dev_get_drvdata(pdev->dev.parent);
764 if (!bd71828) {
765 dev_err(&pdev->dev, "No MFD driver data\n");
766 return -EINVAL;
767 }
768
769 config.regmap = bd71828->regmap;
770
771 for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
772 struct regulator_dev *rdev;
773 const struct bd71828_regulator_data *rd;
774
775 rd = &bd71828_rdata[i];
776 rdev = devm_regulator_register(&pdev->dev,
777 &rd->desc, &config);
778 if (IS_ERR(rdev)) {
779 dev_err(&pdev->dev,
780 "failed to register %s regulator\n",
781 rd->desc.name);
782 return PTR_ERR(rdev);
783 }
784 for (j = 0; j < rd->reg_init_amnt; j++) {
785 ret = regmap_update_bits(bd71828->regmap,
786 rd->reg_inits[j].reg,
787 rd->reg_inits[j].mask,
788 rd->reg_inits[j].val);
789 if (ret) {
790 dev_err(&pdev->dev,
791 "regulator %s init failed\n",
792 rd->desc.name);
793 return ret;
794 }
795 }
796 }
797 return 0;
798}
799
800static struct platform_driver bd71828_regulator = {
801 .driver = {
802 .name = "bd71828-pmic"
803 },
804 .probe = bd71828_probe,
805};
806
807module_platform_driver(bd71828_regulator);
808
809MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
810MODULE_DESCRIPTION("BD71828 voltage regulator driver");
811MODULE_LICENSE("GPL");
812MODULE_ALIAS("platform:bd71828-pmic");