Merge tag 'sound-5.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-block.git] / drivers / regulator / bd718x7-regulator.c
CommitLineData
ba08799e
MV
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 ROHM Semiconductors
dd2be639 3// bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
ba08799e 4
c9dc4cfa 5#include <linux/delay.h>
ba08799e 6#include <linux/err.h>
c9dc4cfa 7#include <linux/gpio.h>
ba08799e 8#include <linux/interrupt.h>
c9dc4cfa 9#include <linux/kernel.h>
410e8b4f 10#include <linux/mfd/rohm-bd718x7.h>
c9dc4cfa 11#include <linux/module.h>
9cce7244 12#include <linux/of.h>
ba08799e
MV
13#include <linux/platform_device.h>
14#include <linux/regulator/driver.h>
15#include <linux/regulator/machine.h>
ba08799e 16#include <linux/regulator/of_regulator.h>
c9dc4cfa 17#include <linux/slab.h>
ba08799e 18
ba08799e
MV
19/*
20 * BUCK1/2/3/4
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
26 */
dd2be639 27static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
ba08799e
MV
28 int ramp_delay)
29{
ba08799e
MV
30 int id = rdev->desc->id;
31 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
32
bcb047eb 33 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
ba08799e
MV
34 ramp_delay);
35 switch (ramp_delay) {
36 case 1 ... 1250:
37 ramp_value = BUCK_RAMPRATE_1P25MV;
38 break;
39 case 1251 ... 2500:
40 ramp_value = BUCK_RAMPRATE_2P50MV;
41 break;
42 case 2501 ... 5000:
43 ramp_value = BUCK_RAMPRATE_5P00MV;
44 break;
45 case 5001 ... 10000:
46 ramp_value = BUCK_RAMPRATE_10P00MV;
47 break;
48 default:
49 ramp_value = BUCK_RAMPRATE_10P00MV;
bcb047eb 50 dev_err(&rdev->dev,
ba08799e
MV
51 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
52 rdev->desc->name, ramp_delay);
53 }
54
bcb047eb 55 return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
ba08799e
MV
56 BUCK_RAMPRATE_MASK, ramp_value << 6);
57}
58
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.
63 */
494edd26 64static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
ba08799e
MV
65 unsigned int sel)
66{
ffdc4984
AL
67 if (regulator_is_enabled_regmap(rdev))
68 return -EBUSY;
ba08799e 69
ffdc4984 70 return regulator_set_voltage_sel_regmap(rdev, sel);
ba08799e
MV
71}
72
a4bfc2c2
MV
73static int bd718xx_set_voltage_sel_pickable_restricted(
74 struct regulator_dev *rdev, unsigned int sel)
75{
76 if (regulator_is_enabled_regmap(rdev))
77 return -EBUSY;
78
79 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
80}
81
704c5c01 82static const struct regulator_ops bd718xx_pickable_range_ldo_ops = {
a4bfc2c2
MV
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,
89};
90
704c5c01 91static const struct regulator_ops bd718xx_pickable_range_buck_ops = {
a4bfc2c2
MV
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,
99};
100
704c5c01 101static const struct regulator_ops bd718xx_ldo_regulator_ops = {
ba08799e
MV
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,
494edd26 106 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
107 .get_voltage_sel = regulator_get_voltage_sel_regmap,
108};
109
704c5c01 110static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
ba08799e
MV
111 .enable = regulator_enable_regmap,
112 .disable = regulator_disable_regmap,
113 .is_enabled = regulator_is_enabled_regmap,
114 .list_voltage = regulator_list_voltage_table,
494edd26 115 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
116 .get_voltage_sel = regulator_get_voltage_sel_regmap,
117};
118
704c5c01 119static const struct regulator_ops bd718xx_buck_regulator_ops = {
ba08799e
MV
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,
494edd26 124 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
125 .get_voltage_sel = regulator_get_voltage_sel_regmap,
126 .set_voltage_time_sel = regulator_set_voltage_time_sel,
127};
128
704c5c01 129static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
ba08799e
MV
130 .enable = regulator_enable_regmap,
131 .disable = regulator_disable_regmap,
132 .is_enabled = regulator_is_enabled_regmap,
133 .list_voltage = regulator_list_voltage_table,
2e61286d 134 .map_voltage = regulator_map_voltage_ascend,
494edd26 135 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
136 .get_voltage_sel = regulator_get_voltage_sel_regmap,
137 .set_voltage_time_sel = regulator_set_voltage_time_sel,
138};
139
704c5c01 140static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
ba08799e
MV
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,
dd2be639 148 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
ba08799e
MV
149};
150
151/*
494edd26
MV
152 * BD71837 BUCK1/2/3/4
153 * BD71847 BUCK1/2
ba08799e
MV
154 * 0.70 to 1.30V (10mV step)
155 */
494edd26 156static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
ba08799e
MV
157 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
158 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
159};
160
161/*
494edd26 162 * BD71837 BUCK5
a4bfc2c2
MV
163 * 0.7V to 1.35V (range 0)
164 * and
165 * 0.675 to 1.325 (range 1)
166 */
167static 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),
176};
177
178/*
179 * Range selector for first 3 linear ranges is 0x0
180 * and 0x1 for last 3 ranges.
181 */
182static const unsigned int bd71837_buck5_volt_range_sel[] = {
183 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
184};
185
186/*
494edd26 187 * BD71847 BUCK3
ba08799e 188 */
a4bfc2c2
MV
189static const struct regulator_linear_range bd71847_buck3_volts[] = {
190 /* Ranges when VOLT_SEL bits are 00 */
ba08799e
MV
191 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
192 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
193 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
a4bfc2c2
MV
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),
200};
201
202static const unsigned int bd71847_buck3_volt_range_sel[] = {
203 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
ba08799e
MV
204};
205
a4bfc2c2 206static const struct regulator_linear_range bd71847_buck4_volts[] = {
494edd26 207 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c2 208 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
494edd26
MV
209};
210
a4bfc2c2
MV
211static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
212
ba08799e
MV
213/*
214 * BUCK6
215 * 3.0V to 3.3V (step 100mV)
216 */
a4bfc2c2 217static const struct regulator_linear_range bd71837_buck6_volts[] = {
ba08799e
MV
218 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
219};
220
221/*
494edd26
MV
222 * BD71837 BUCK7
223 * BD71847 BUCK5
ba08799e
MV
224 * 000 = 1.605V
225 * 001 = 1.695V
226 * 010 = 1.755V
227 * 011 = 1.8V (Initial)
228 * 100 = 1.845V
229 * 101 = 1.905V
230 * 110 = 1.95V
231 * 111 = 1.995V
232 */
494edd26 233static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
ba08799e
MV
234 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
235};
236
237/*
238 * BUCK8
239 * 0.8V to 1.40V (step 10mV)
240 */
494edd26 241static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
ba08799e 242 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
ba08799e
MV
243};
244
245/*
246 * LDO1
247 * 3.0 to 3.3V (100mV step)
248 */
494edd26 249static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
ba08799e 250 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c2 251 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
ba08799e
MV
252};
253
a4bfc2c2
MV
254static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
255
ba08799e
MV
256/*
257 * LDO2
258 * 0.8 or 0.9V
259 */
adb78a8e 260static const unsigned int ldo_2_volts[] = {
ba08799e
MV
261 900000, 800000
262};
263
264/*
265 * LDO3
266 * 1.8 to 3.3V (100mV step)
267 */
494edd26 268static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
ba08799e
MV
269 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
270};
271
272/*
273 * LDO4
274 * 0.9 to 1.8V (100mV step)
275 */
494edd26 276static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
ba08799e 277 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e
MV
278};
279
280/*
494edd26 281 * LDO5 for BD71837
ba08799e
MV
282 * 1.8 to 3.3V (100mV step)
283 */
a4bfc2c2 284static const struct regulator_linear_range bd71837_ldo5_volts[] = {
ba08799e
MV
285 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
286};
287
a4bfc2c2
MV
288/*
289 * LDO5 for BD71837
290 * 1.8 to 3.3V (100mV step)
291 */
292static const struct regulator_linear_range bd71847_ldo5_volts[] = {
293 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
294 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
295};
296
297static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
298
ba08799e
MV
299/*
300 * LDO6
301 * 0.9 to 1.8V (100mV step)
302 */
494edd26 303static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
ba08799e 304 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e
MV
305};
306
307/*
308 * LDO7
309 * 1.8 to 3.3V (100mV step)
310 */
494edd26 311static const struct regulator_linear_range bd71837_ldo7_volts[] = {
ba08799e
MV
312 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
313};
314
494edd26
MV
315struct reg_init {
316 unsigned int reg;
317 unsigned int mask;
318 unsigned int val;
319};
320struct 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;
325};
326
327/*
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
336 */
337static const struct reg_init bd71837_ldo5_inits[] = {
338 {
339 .reg = BD718XX_REG_MVRFLTMASK2,
340 .mask = BD718XX_LDO5_VRMON80,
341 .val = BD718XX_LDO5_VRMON80,
342 },
343};
344
345static const struct reg_init bd71837_ldo6_inits[] = {
346 {
347 .reg = BD718XX_REG_MVRFLTMASK2,
348 .mask = BD718XX_LDO6_VRMON80,
349 .val = BD718XX_LDO6_VRMON80,
350 },
351};
352
049369d4
MV
353#define NUM_DVS_BUCKS 4
354
355struct of_dvs_setting {
356 const char *prop;
357 unsigned int reg;
358};
359
360static int set_dvs_levels(const struct of_dvs_setting *dvs,
361 struct device_node *np,
362 const struct regulator_desc *desc,
363 struct regmap *regmap)
364{
365 int ret, i;
366 unsigned int uv;
367
368 ret = of_property_read_u32(np, dvs->prop, &uv);
369 if (ret) {
370 if (ret != -EINVAL)
371 return ret;
372 return 0;
373 }
374
375 for (i = 0; i < desc->n_voltages; i++) {
376 ret = regulator_desc_list_voltage_linear_range(desc, i);
377 if (ret < 0)
378 continue;
379 if (ret == uv) {
380 i <<= ffs(desc->vsel_mask) - 1;
381 ret = regmap_update_bits(regmap, dvs->reg,
382 DVS_BUCK_RUN_MASK, i);
383 break;
384 }
385 }
386 return ret;
387}
388
389static int buck4_set_hw_dvs_levels(struct device_node *np,
390 const struct regulator_desc *desc,
391 struct regulator_config *cfg)
392{
393 int ret, i;
394 const struct of_dvs_setting dvs[] = {
395 {
396 .prop = "rohm,dvs-run-voltage",
397 .reg = BD71837_REG_BUCK4_VOLT_RUN,
398 },
399 };
400
401 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
402 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
403 if (ret)
404 break;
405 }
406 return ret;
407}
408static int buck3_set_hw_dvs_levels(struct device_node *np,
409 const struct regulator_desc *desc,
410 struct regulator_config *cfg)
411{
412 int ret, i;
413 const struct of_dvs_setting dvs[] = {
414 {
415 .prop = "rohm,dvs-run-voltage",
416 .reg = BD71837_REG_BUCK3_VOLT_RUN,
417 },
418 };
419
420 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
421 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
422 if (ret)
423 break;
424 }
425 return ret;
426}
427
428static int buck2_set_hw_dvs_levels(struct device_node *np,
429 const struct regulator_desc *desc,
430 struct regulator_config *cfg)
431{
432 int ret, i;
433 const struct of_dvs_setting dvs[] = {
434 {
435 .prop = "rohm,dvs-run-voltage",
436 .reg = BD718XX_REG_BUCK2_VOLT_RUN,
437 },
438 {
439 .prop = "rohm,dvs-idle-voltage",
440 .reg = BD718XX_REG_BUCK2_VOLT_IDLE,
441 },
442 };
443
444
445
446 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
447 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
448 if (ret)
449 break;
450 }
451 return ret;
452}
453
454static int buck1_set_hw_dvs_levels(struct device_node *np,
455 const struct regulator_desc *desc,
456 struct regulator_config *cfg)
457{
458 int ret, i;
459 const struct of_dvs_setting dvs[] = {
460 {
461 .prop = "rohm,dvs-run-voltage",
462 .reg = BD718XX_REG_BUCK1_VOLT_RUN,
463 },
464 {
465 .prop = "rohm,dvs-idle-voltage",
466 .reg = BD718XX_REG_BUCK1_VOLT_IDLE,
467 },
468 {
469 .prop = "rohm,dvs-suspend-voltage",
470 .reg = BD718XX_REG_BUCK1_VOLT_SUSP,
471 },
472 };
473
474 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
475 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
476 if (ret)
477 break;
478 }
479 return ret;
480}
481
494edd26
MV
482static const struct bd718xx_regulator_data bd71847_regulators[] = {
483 {
484 .desc = {
485 .name = "buck1",
486 .of_match = of_match_ptr("BUCK1"),
487 .regulators_node = of_match_ptr("regulators"),
488 .id = BD718XX_BUCK1,
489 .ops = &bd718xx_dvs_buck_regulator_ops,
490 .type = REGULATOR_VOLTAGE,
491 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
492 .linear_ranges = bd718xx_dvs_buck_volts,
493 .n_linear_ranges =
494 ARRAY_SIZE(bd718xx_dvs_buck_volts),
495 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
496 .vsel_mask = DVS_BUCK_RUN_MASK,
497 .enable_reg = BD718XX_REG_BUCK1_CTRL,
498 .enable_mask = BD718XX_BUCK_EN,
499 .owner = THIS_MODULE,
049369d4 500 .of_parse_cb = buck1_set_hw_dvs_levels,
494edd26
MV
501 },
502 .init = {
503 .reg = BD718XX_REG_BUCK1_CTRL,
504 .mask = BD718XX_BUCK_SEL,
505 .val = BD718XX_BUCK_SEL,
506 },
507 },
ba08799e 508 {
494edd26
MV
509 .desc = {
510 .name = "buck2",
511 .of_match = of_match_ptr("BUCK2"),
512 .regulators_node = of_match_ptr("regulators"),
513 .id = BD718XX_BUCK2,
514 .ops = &bd718xx_dvs_buck_regulator_ops,
515 .type = REGULATOR_VOLTAGE,
516 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
517 .linear_ranges = bd718xx_dvs_buck_volts,
518 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
519 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
520 .vsel_mask = DVS_BUCK_RUN_MASK,
521 .enable_reg = BD718XX_REG_BUCK2_CTRL,
522 .enable_mask = BD718XX_BUCK_EN,
523 .owner = THIS_MODULE,
049369d4 524 .of_parse_cb = buck2_set_hw_dvs_levels,
494edd26
MV
525 },
526 .init = {
527 .reg = BD718XX_REG_BUCK2_CTRL,
528 .mask = BD718XX_BUCK_SEL,
529 .val = BD718XX_BUCK_SEL,
530 },
ba08799e
MV
531 },
532 {
494edd26
MV
533 .desc = {
534 .name = "buck3",
535 .of_match = of_match_ptr("BUCK3"),
536 .regulators_node = of_match_ptr("regulators"),
537 .id = BD718XX_BUCK3,
a4bfc2c2 538 .ops = &bd718xx_pickable_range_buck_ops,
494edd26 539 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
540 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
541 .linear_ranges = bd71847_buck3_volts,
494edd26 542 .n_linear_ranges =
a4bfc2c2 543 ARRAY_SIZE(bd71847_buck3_volts),
494edd26
MV
544 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
545 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
a4bfc2c2
MV
546 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
547 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
548 .linear_range_selectors = bd71847_buck3_volt_range_sel,
494edd26
MV
549 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
550 .enable_mask = BD718XX_BUCK_EN,
551 .owner = THIS_MODULE,
552 },
553 .init = {
554 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
555 .mask = BD718XX_BUCK_SEL,
556 .val = BD718XX_BUCK_SEL,
557 },
ba08799e
MV
558 },
559 {
494edd26
MV
560 .desc = {
561 .name = "buck4",
562 .of_match = of_match_ptr("BUCK4"),
563 .regulators_node = of_match_ptr("regulators"),
564 .id = BD718XX_BUCK4,
a4bfc2c2 565 .ops = &bd718xx_pickable_range_buck_ops,
494edd26
MV
566 .type = REGULATOR_VOLTAGE,
567 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
a4bfc2c2 568 .linear_ranges = bd71847_buck4_volts,
494edd26 569 .n_linear_ranges =
a4bfc2c2 570 ARRAY_SIZE(bd71847_buck4_volts),
494edd26
MV
571 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
572 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
573 .vsel_mask = BD71847_BUCK4_MASK,
a4bfc2c2
MV
574 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
575 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
576 .linear_range_selectors = bd71847_buck4_volt_range_sel,
494edd26
MV
577 .enable_mask = BD718XX_BUCK_EN,
578 .owner = THIS_MODULE,
579 },
580 .init = {
581 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
582 .mask = BD718XX_BUCK_SEL,
583 .val = BD718XX_BUCK_SEL,
584 },
ba08799e
MV
585 },
586 {
494edd26
MV
587 .desc = {
588 .name = "buck5",
589 .of_match = of_match_ptr("BUCK5"),
dd2be639 590 .regulators_node = of_match_ptr("regulators"),
494edd26
MV
591 .id = BD718XX_BUCK5,
592 .ops = &bd718xx_buck_regulator_nolinear_ops,
593 .type = REGULATOR_VOLTAGE,
594 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
595 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
596 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
597 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
598 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
599 .enable_mask = BD718XX_BUCK_EN,
600 .owner = THIS_MODULE,
601 },
602 .init = {
603 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
604 .mask = BD718XX_BUCK_SEL,
605 .val = BD718XX_BUCK_SEL,
606 },
ba08799e
MV
607 },
608 {
494edd26
MV
609 .desc = {
610 .name = "buck6",
611 .of_match = of_match_ptr("BUCK6"),
612 .regulators_node = of_match_ptr("regulators"),
613 .id = BD718XX_BUCK6,
614 .ops = &bd718xx_buck_regulator_ops,
615 .type = REGULATOR_VOLTAGE,
dd2be639 616 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd26
MV
617 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
618 .n_linear_ranges =
619 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
620 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
621 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
622 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
623 .enable_mask = BD718XX_BUCK_EN,
624 .owner = THIS_MODULE,
625 },
626 .init = {
627 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
628 .mask = BD718XX_BUCK_SEL,
629 .val = BD718XX_BUCK_SEL,
630 },
ba08799e
MV
631 },
632 {
494edd26
MV
633 .desc = {
634 .name = "ldo1",
635 .of_match = of_match_ptr("LDO1"),
636 .regulators_node = of_match_ptr("regulators"),
637 .id = BD718XX_LDO1,
a4bfc2c2 638 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26
MV
639 .type = REGULATOR_VOLTAGE,
640 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
641 .linear_ranges = bd718xx_ldo1_volts,
642 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
643 .vsel_reg = BD718XX_REG_LDO1_VOLT,
644 .vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c2
MV
645 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
646 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
647 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd26
MV
648 .enable_reg = BD718XX_REG_LDO1_VOLT,
649 .enable_mask = BD718XX_LDO_EN,
650 .owner = THIS_MODULE,
651 },
652 .init = {
653 .reg = BD718XX_REG_LDO1_VOLT,
654 .mask = BD718XX_LDO_SEL,
655 .val = BD718XX_LDO_SEL,
656 },
ba08799e
MV
657 },
658 {
494edd26
MV
659 .desc = {
660 .name = "ldo2",
661 .of_match = of_match_ptr("LDO2"),
662 .regulators_node = of_match_ptr("regulators"),
663 .id = BD718XX_LDO2,
664 .ops = &bd718xx_ldo_regulator_nolinear_ops,
665 .type = REGULATOR_VOLTAGE,
666 .volt_table = &ldo_2_volts[0],
667 .vsel_reg = BD718XX_REG_LDO2_VOLT,
668 .vsel_mask = BD718XX_LDO2_MASK,
669 .n_voltages = ARRAY_SIZE(ldo_2_volts),
670 .enable_reg = BD718XX_REG_LDO2_VOLT,
671 .enable_mask = BD718XX_LDO_EN,
672 .owner = THIS_MODULE,
673 },
674 .init = {
675 .reg = BD718XX_REG_LDO2_VOLT,
676 .mask = BD718XX_LDO_SEL,
677 .val = BD718XX_LDO_SEL,
678 },
ba08799e
MV
679 },
680 {
494edd26
MV
681 .desc = {
682 .name = "ldo3",
683 .of_match = of_match_ptr("LDO3"),
684 .regulators_node = of_match_ptr("regulators"),
685 .id = BD718XX_LDO3,
686 .ops = &bd718xx_ldo_regulator_ops,
687 .type = REGULATOR_VOLTAGE,
688 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
689 .linear_ranges = bd718xx_ldo3_volts,
690 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
691 .vsel_reg = BD718XX_REG_LDO3_VOLT,
692 .vsel_mask = BD718XX_LDO3_MASK,
693 .enable_reg = BD718XX_REG_LDO3_VOLT,
694 .enable_mask = BD718XX_LDO_EN,
695 .owner = THIS_MODULE,
696 },
697 .init = {
698 .reg = BD718XX_REG_LDO3_VOLT,
699 .mask = BD718XX_LDO_SEL,
700 .val = BD718XX_LDO_SEL,
701 },
ba08799e
MV
702 },
703 {
494edd26
MV
704 .desc = {
705 .name = "ldo4",
706 .of_match = of_match_ptr("LDO4"),
707 .regulators_node = of_match_ptr("regulators"),
708 .id = BD718XX_LDO4,
709 .ops = &bd718xx_ldo_regulator_ops,
710 .type = REGULATOR_VOLTAGE,
711 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
712 .linear_ranges = bd718xx_ldo4_volts,
713 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
714 .vsel_reg = BD718XX_REG_LDO4_VOLT,
715 .vsel_mask = BD718XX_LDO4_MASK,
716 .enable_reg = BD718XX_REG_LDO4_VOLT,
717 .enable_mask = BD718XX_LDO_EN,
718 .owner = THIS_MODULE,
719 },
720 .init = {
721 .reg = BD718XX_REG_LDO4_VOLT,
722 .mask = BD718XX_LDO_SEL,
723 .val = BD718XX_LDO_SEL,
724 },
ba08799e
MV
725 },
726 {
494edd26
MV
727 .desc = {
728 .name = "ldo5",
729 .of_match = of_match_ptr("LDO5"),
730 .regulators_node = of_match_ptr("regulators"),
731 .id = BD718XX_LDO5,
a4bfc2c2 732 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26 733 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
734 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
735 .linear_ranges = bd71847_ldo5_volts,
736 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
494edd26
MV
737 .vsel_reg = BD718XX_REG_LDO5_VOLT,
738 .vsel_mask = BD71847_LDO5_MASK,
a4bfc2c2
MV
739 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
740 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
741 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
494edd26
MV
742 .enable_reg = BD718XX_REG_LDO5_VOLT,
743 .enable_mask = BD718XX_LDO_EN,
744 .owner = THIS_MODULE,
745 },
746 .init = {
747 .reg = BD718XX_REG_LDO5_VOLT,
748 .mask = BD718XX_LDO_SEL,
749 .val = BD718XX_LDO_SEL,
750 },
ba08799e
MV
751 },
752 {
494edd26
MV
753 .desc = {
754 .name = "ldo6",
755 .of_match = of_match_ptr("LDO6"),
756 .regulators_node = of_match_ptr("regulators"),
757 .id = BD718XX_LDO6,
758 .ops = &bd718xx_ldo_regulator_ops,
759 .type = REGULATOR_VOLTAGE,
760 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
761 .linear_ranges = bd718xx_ldo6_volts,
762 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
763 /* LDO6 is supplied by buck5 */
764 .supply_name = "buck5",
765 .vsel_reg = BD718XX_REG_LDO6_VOLT,
766 .vsel_mask = BD718XX_LDO6_MASK,
767 .enable_reg = BD718XX_REG_LDO6_VOLT,
768 .enable_mask = BD718XX_LDO_EN,
769 .owner = THIS_MODULE,
770 },
771 .init = {
772 .reg = BD718XX_REG_LDO6_VOLT,
773 .mask = BD718XX_LDO_SEL,
774 .val = BD718XX_LDO_SEL,
775 },
776 },
777};
778
779static const struct bd718xx_regulator_data bd71837_regulators[] = {
780 {
781 .desc = {
782 .name = "buck1",
783 .of_match = of_match_ptr("BUCK1"),
784 .regulators_node = of_match_ptr("regulators"),
785 .id = BD718XX_BUCK1,
786 .ops = &bd718xx_dvs_buck_regulator_ops,
787 .type = REGULATOR_VOLTAGE,
788 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
789 .linear_ranges = bd718xx_dvs_buck_volts,
790 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
791 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
792 .vsel_mask = DVS_BUCK_RUN_MASK,
793 .enable_reg = BD718XX_REG_BUCK1_CTRL,
794 .enable_mask = BD718XX_BUCK_EN,
795 .owner = THIS_MODULE,
049369d4 796 .of_parse_cb = buck1_set_hw_dvs_levels,
494edd26
MV
797 },
798 .init = {
799 .reg = BD718XX_REG_BUCK1_CTRL,
800 .mask = BD718XX_BUCK_SEL,
801 .val = BD718XX_BUCK_SEL,
802 },
803 },
804 {
805 .desc = {
806 .name = "buck2",
807 .of_match = of_match_ptr("BUCK2"),
808 .regulators_node = of_match_ptr("regulators"),
809 .id = BD718XX_BUCK2,
810 .ops = &bd718xx_dvs_buck_regulator_ops,
811 .type = REGULATOR_VOLTAGE,
812 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
813 .linear_ranges = bd718xx_dvs_buck_volts,
814 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
815 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
816 .vsel_mask = DVS_BUCK_RUN_MASK,
817 .enable_reg = BD718XX_REG_BUCK2_CTRL,
818 .enable_mask = BD718XX_BUCK_EN,
819 .owner = THIS_MODULE,
049369d4 820 .of_parse_cb = buck2_set_hw_dvs_levels,
494edd26
MV
821 },
822 .init = {
823 .reg = BD718XX_REG_BUCK2_CTRL,
824 .mask = BD718XX_BUCK_SEL,
825 .val = BD718XX_BUCK_SEL,
826 },
827 },
828 {
829 .desc = {
830 .name = "buck3",
831 .of_match = of_match_ptr("BUCK3"),
832 .regulators_node = of_match_ptr("regulators"),
833 .id = BD718XX_BUCK3,
834 .ops = &bd718xx_dvs_buck_regulator_ops,
835 .type = REGULATOR_VOLTAGE,
836 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
837 .linear_ranges = bd718xx_dvs_buck_volts,
838 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
839 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
840 .vsel_mask = DVS_BUCK_RUN_MASK,
841 .enable_reg = BD71837_REG_BUCK3_CTRL,
842 .enable_mask = BD718XX_BUCK_EN,
843 .owner = THIS_MODULE,
049369d4 844 .of_parse_cb = buck3_set_hw_dvs_levels,
494edd26
MV
845 },
846 .init = {
847 .reg = BD71837_REG_BUCK3_CTRL,
848 .mask = BD718XX_BUCK_SEL,
849 .val = BD718XX_BUCK_SEL,
850 },
851 },
852 {
853 .desc = {
854 .name = "buck4",
855 .of_match = of_match_ptr("BUCK4"),
856 .regulators_node = of_match_ptr("regulators"),
857 .id = BD718XX_BUCK4,
858 .ops = &bd718xx_dvs_buck_regulator_ops,
859 .type = REGULATOR_VOLTAGE,
860 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
861 .linear_ranges = bd718xx_dvs_buck_volts,
862 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
863 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
864 .vsel_mask = DVS_BUCK_RUN_MASK,
865 .enable_reg = BD71837_REG_BUCK4_CTRL,
866 .enable_mask = BD718XX_BUCK_EN,
867 .owner = THIS_MODULE,
049369d4 868 .of_parse_cb = buck4_set_hw_dvs_levels,
494edd26
MV
869 },
870 .init = {
871 .reg = BD71837_REG_BUCK4_CTRL,
872 .mask = BD718XX_BUCK_SEL,
873 .val = BD718XX_BUCK_SEL,
874 },
ba08799e
MV
875 },
876 {
494edd26
MV
877 .desc = {
878 .name = "buck5",
879 .of_match = of_match_ptr("BUCK5"),
880 .regulators_node = of_match_ptr("regulators"),
881 .id = BD718XX_BUCK5,
a4bfc2c2 882 .ops = &bd718xx_pickable_range_buck_ops,
494edd26 883 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
884 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
885 .linear_ranges = bd71837_buck5_volts,
494edd26 886 .n_linear_ranges =
a4bfc2c2 887 ARRAY_SIZE(bd71837_buck5_volts),
494edd26 888 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
a4bfc2c2
MV
889 .vsel_mask = BD71837_BUCK5_MASK,
890 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
891 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
892 .linear_range_selectors = bd71837_buck5_volt_range_sel,
494edd26
MV
893 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
894 .enable_mask = BD718XX_BUCK_EN,
895 .owner = THIS_MODULE,
896 },
897 .init = {
898 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
899 .mask = BD718XX_BUCK_SEL,
900 .val = BD718XX_BUCK_SEL,
901 },
ba08799e
MV
902 },
903 {
494edd26
MV
904 .desc = {
905 .name = "buck6",
906 .of_match = of_match_ptr("BUCK6"),
907 .regulators_node = of_match_ptr("regulators"),
908 .id = BD718XX_BUCK6,
909 .ops = &bd718xx_buck_regulator_ops,
910 .type = REGULATOR_VOLTAGE,
911 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
a4bfc2c2 912 .linear_ranges = bd71837_buck6_volts,
494edd26 913 .n_linear_ranges =
a4bfc2c2 914 ARRAY_SIZE(bd71837_buck6_volts),
494edd26
MV
915 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
916 .vsel_mask = BD71837_BUCK6_MASK,
917 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
918 .enable_mask = BD718XX_BUCK_EN,
919 .owner = THIS_MODULE,
920 },
921 .init = {
922 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
923 .mask = BD718XX_BUCK_SEL,
924 .val = BD718XX_BUCK_SEL,
925 },
ba08799e
MV
926 },
927 {
494edd26
MV
928 .desc = {
929 .name = "buck7",
930 .of_match = of_match_ptr("BUCK7"),
931 .regulators_node = of_match_ptr("regulators"),
932 .id = BD718XX_BUCK7,
933 .ops = &bd718xx_buck_regulator_nolinear_ops,
934 .type = REGULATOR_VOLTAGE,
935 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
936 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
937 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
938 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
939 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
940 .enable_mask = BD718XX_BUCK_EN,
941 .owner = THIS_MODULE,
942 },
943 .init = {
944 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
945 .mask = BD718XX_BUCK_SEL,
946 .val = BD718XX_BUCK_SEL,
947 },
ba08799e
MV
948 },
949 {
494edd26
MV
950 .desc = {
951 .name = "buck8",
952 .of_match = of_match_ptr("BUCK8"),
953 .regulators_node = of_match_ptr("regulators"),
954 .id = BD718XX_BUCK8,
955 .ops = &bd718xx_buck_regulator_ops,
956 .type = REGULATOR_VOLTAGE,
dd2be639 957 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd26
MV
958 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
959 .n_linear_ranges =
960 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
961 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
962 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
963 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
964 .enable_mask = BD718XX_BUCK_EN,
965 .owner = THIS_MODULE,
966 },
967 .init = {
968 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
969 .mask = BD718XX_BUCK_SEL,
970 .val = BD718XX_BUCK_SEL,
971 },
972 },
973 {
974 .desc = {
975 .name = "ldo1",
976 .of_match = of_match_ptr("LDO1"),
977 .regulators_node = of_match_ptr("regulators"),
978 .id = BD718XX_LDO1,
a4bfc2c2 979 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26
MV
980 .type = REGULATOR_VOLTAGE,
981 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
982 .linear_ranges = bd718xx_ldo1_volts,
983 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
984 .vsel_reg = BD718XX_REG_LDO1_VOLT,
985 .vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c2
MV
986 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
987 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
988 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd26
MV
989 .enable_reg = BD718XX_REG_LDO1_VOLT,
990 .enable_mask = BD718XX_LDO_EN,
991 .owner = THIS_MODULE,
992 },
993 .init = {
994 .reg = BD718XX_REG_LDO1_VOLT,
995 .mask = BD718XX_LDO_SEL,
996 .val = BD718XX_LDO_SEL,
997 },
998 },
999 {
1000 .desc = {
1001 .name = "ldo2",
1002 .of_match = of_match_ptr("LDO2"),
1003 .regulators_node = of_match_ptr("regulators"),
1004 .id = BD718XX_LDO2,
1005 .ops = &bd718xx_ldo_regulator_nolinear_ops,
1006 .type = REGULATOR_VOLTAGE,
1007 .volt_table = &ldo_2_volts[0],
1008 .vsel_reg = BD718XX_REG_LDO2_VOLT,
1009 .vsel_mask = BD718XX_LDO2_MASK,
1010 .n_voltages = ARRAY_SIZE(ldo_2_volts),
1011 .enable_reg = BD718XX_REG_LDO2_VOLT,
1012 .enable_mask = BD718XX_LDO_EN,
1013 .owner = THIS_MODULE,
1014 },
1015 .init = {
1016 .reg = BD718XX_REG_LDO2_VOLT,
1017 .mask = BD718XX_LDO_SEL,
1018 .val = BD718XX_LDO_SEL,
1019 },
1020 },
1021 {
1022 .desc = {
1023 .name = "ldo3",
1024 .of_match = of_match_ptr("LDO3"),
1025 .regulators_node = of_match_ptr("regulators"),
1026 .id = BD718XX_LDO3,
1027 .ops = &bd718xx_ldo_regulator_ops,
1028 .type = REGULATOR_VOLTAGE,
1029 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
1030 .linear_ranges = bd718xx_ldo3_volts,
1031 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
1032 .vsel_reg = BD718XX_REG_LDO3_VOLT,
1033 .vsel_mask = BD718XX_LDO3_MASK,
1034 .enable_reg = BD718XX_REG_LDO3_VOLT,
1035 .enable_mask = BD718XX_LDO_EN,
1036 .owner = THIS_MODULE,
1037 },
1038 .init = {
1039 .reg = BD718XX_REG_LDO3_VOLT,
1040 .mask = BD718XX_LDO_SEL,
1041 .val = BD718XX_LDO_SEL,
1042 },
1043 },
1044 {
1045 .desc = {
1046 .name = "ldo4",
1047 .of_match = of_match_ptr("LDO4"),
1048 .regulators_node = of_match_ptr("regulators"),
1049 .id = BD718XX_LDO4,
1050 .ops = &bd718xx_ldo_regulator_ops,
1051 .type = REGULATOR_VOLTAGE,
1052 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
1053 .linear_ranges = bd718xx_ldo4_volts,
1054 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
1055 .vsel_reg = BD718XX_REG_LDO4_VOLT,
1056 .vsel_mask = BD718XX_LDO4_MASK,
1057 .enable_reg = BD718XX_REG_LDO4_VOLT,
1058 .enable_mask = BD718XX_LDO_EN,
1059 .owner = THIS_MODULE,
1060 },
1061 .init = {
1062 .reg = BD718XX_REG_LDO4_VOLT,
1063 .mask = BD718XX_LDO_SEL,
1064 .val = BD718XX_LDO_SEL,
1065 },
1066 },
1067 {
1068 .desc = {
1069 .name = "ldo5",
1070 .of_match = of_match_ptr("LDO5"),
1071 .regulators_node = of_match_ptr("regulators"),
1072 .id = BD718XX_LDO5,
1073 .ops = &bd718xx_ldo_regulator_ops,
1074 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
1075 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
1076 .linear_ranges = bd71837_ldo5_volts,
1077 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
494edd26
MV
1078 /* LDO5 is supplied by buck6 */
1079 .supply_name = "buck6",
1080 .vsel_reg = BD718XX_REG_LDO5_VOLT,
1081 .vsel_mask = BD71837_LDO5_MASK,
1082 .enable_reg = BD718XX_REG_LDO5_VOLT,
1083 .enable_mask = BD718XX_LDO_EN,
1084 .owner = THIS_MODULE,
1085 },
1086 .init = {
1087 .reg = BD718XX_REG_LDO5_VOLT,
1088 .mask = BD718XX_LDO_SEL,
1089 .val = BD718XX_LDO_SEL,
1090 },
1091 .additional_inits = bd71837_ldo5_inits,
1092 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
1093 },
1094 {
1095 .desc = {
1096 .name = "ldo6",
1097 .of_match = of_match_ptr("LDO6"),
1098 .regulators_node = of_match_ptr("regulators"),
1099 .id = BD718XX_LDO6,
1100 .ops = &bd718xx_ldo_regulator_ops,
1101 .type = REGULATOR_VOLTAGE,
1102 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
1103 .linear_ranges = bd718xx_ldo6_volts,
1104 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
1105 /* LDO6 is supplied by buck7 */
1106 .supply_name = "buck7",
1107 .vsel_reg = BD718XX_REG_LDO6_VOLT,
1108 .vsel_mask = BD718XX_LDO6_MASK,
1109 .enable_reg = BD718XX_REG_LDO6_VOLT,
1110 .enable_mask = BD718XX_LDO_EN,
1111 .owner = THIS_MODULE,
1112 },
1113 .init = {
1114 .reg = BD718XX_REG_LDO6_VOLT,
1115 .mask = BD718XX_LDO_SEL,
1116 .val = BD718XX_LDO_SEL,
1117 },
1118 .additional_inits = bd71837_ldo6_inits,
1119 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
1120 },
1121 {
1122 .desc = {
1123 .name = "ldo7",
1124 .of_match = of_match_ptr("LDO7"),
1125 .regulators_node = of_match_ptr("regulators"),
1126 .id = BD718XX_LDO7,
1127 .ops = &bd718xx_ldo_regulator_ops,
1128 .type = REGULATOR_VOLTAGE,
1129 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1130 .linear_ranges = bd71837_ldo7_volts,
1131 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1132 .vsel_reg = BD71837_REG_LDO7_VOLT,
1133 .vsel_mask = BD71837_LDO7_MASK,
1134 .enable_reg = BD71837_REG_LDO7_VOLT,
1135 .enable_mask = BD718XX_LDO_EN,
1136 .owner = THIS_MODULE,
1137 },
1138 .init = {
1139 .reg = BD71837_REG_LDO7_VOLT,
1140 .mask = BD718XX_LDO_SEL,
1141 .val = BD718XX_LDO_SEL,
1142 },
ba08799e
MV
1143 },
1144};
1145
494edd26 1146struct bd718xx_pmic_inits {
de226ebd 1147 const struct bd718xx_regulator_data *r_datas;
494edd26 1148 unsigned int r_amount;
ba08799e
MV
1149};
1150
dd2be639 1151static int bd718xx_probe(struct platform_device *pdev)
ba08799e 1152{
bcb047eb 1153 struct bd718xx *mfd;
ba08799e 1154 struct regulator_config config = { 0 };
494edd26
MV
1155 struct bd718xx_pmic_inits pmic_regulators[] = {
1156 [BD718XX_TYPE_BD71837] = {
de226ebd 1157 .r_datas = bd71837_regulators,
494edd26
MV
1158 .r_amount = ARRAY_SIZE(bd71837_regulators),
1159 },
1160 [BD718XX_TYPE_BD71847] = {
de226ebd 1161 .r_datas = bd71847_regulators,
494edd26
MV
1162 .r_amount = ARRAY_SIZE(bd71847_regulators),
1163 },
ba08799e
MV
1164 };
1165
494edd26 1166 int i, j, err;
049369d4 1167 bool use_snvs;
ba08799e 1168
bcb047eb
AL
1169 mfd = dev_get_drvdata(pdev->dev.parent);
1170 if (!mfd) {
ba08799e
MV
1171 dev_err(&pdev->dev, "No MFD driver data\n");
1172 err = -EINVAL;
1173 goto err;
1174 }
bcb047eb
AL
1175
1176 if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1177 !pmic_regulators[mfd->chip_type].r_datas) {
494edd26
MV
1178 dev_err(&pdev->dev, "Unsupported chip type\n");
1179 err = -EINVAL;
1180 goto err;
1181 }
1182
ba08799e 1183 /* Register LOCK release */
bcb047eb 1184 err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
ba08799e
MV
1185 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1186 if (err) {
bcb047eb 1187 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
ba08799e
MV
1188 goto err;
1189 } else {
bcb047eb 1190 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
494edd26 1191 BD718XX_REG_REGLOCK);
823f18f8
MV
1192 }
1193
049369d4
MV
1194 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1195 "rohm,reset-snvs-powered");
1196
1197 /*
e770b18b
MV
1198 * Change the next stage from poweroff to be READY instead of SNVS
1199 * for all reset types because OTP loading at READY will clear SEL
1200 * bit allowing HW defaults for power rails to be used
1201 */
049369d4
MV
1202 if (!use_snvs) {
1203 err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1,
1204 BD718XX_ON_REQ_POWEROFF_MASK |
1205 BD718XX_SWRESET_POWEROFF_MASK |
1206 BD718XX_WDOG_POWEROFF_MASK |
1207 BD718XX_KEY_L_POWEROFF_MASK,
1208 BD718XX_POWOFF_TO_RDY);
1209 if (err) {
1210 dev_err(&pdev->dev, "Failed to change reset target\n");
1211 goto err;
1212 } else {
1213 dev_dbg(&pdev->dev,
1214 "Changed all resets from SVNS to READY\n");
1215 }
e770b18b
MV
1216 }
1217
bcb047eb 1218 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
ba08799e 1219
494edd26 1220 const struct regulator_desc *desc;
ba08799e 1221 struct regulator_dev *rdev;
494edd26 1222 const struct bd718xx_regulator_data *r;
ba08799e 1223
de226ebd 1224 r = &pmic_regulators[mfd->chip_type].r_datas[i];
494edd26 1225 desc = &r->desc;
ba08799e 1226
ba08799e 1227 config.dev = pdev->dev.parent;
bcb047eb 1228 config.regmap = mfd->regmap;
ba08799e
MV
1229
1230 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1231 if (IS_ERR(rdev)) {
bcb047eb 1232 dev_err(&pdev->dev,
ba08799e
MV
1233 "failed to register %s regulator\n",
1234 desc->name);
1235 err = PTR_ERR(rdev);
1236 goto err;
1237 }
049369d4
MV
1238
1239 /*
1240 * Regulator register gets the regulator constraints and
ba08799e
MV
1241 * applies them (set_machine_constraints). This should have
1242 * turned the control register(s) to correct values and we
1243 * can now switch the control from PMIC state machine to the
1244 * register interface
049369d4
MV
1245 *
1246 * At poweroff transition PMIC HW disables EN bit for
1247 * regulators but leaves SEL bit untouched. So if state
1248 * transition from POWEROFF is done to SNVS - then all power
1249 * rails controlled by SW (having SEL bit set) stay disabled
1250 * as EN is cleared. This will result boot failure if any
1251 * crucial systems are powered by these rails. We don't
1252 * enable SW control for crucial regulators if snvs state is
1253 * used
ba08799e 1254 */
049369d4
MV
1255 if (!use_snvs || !rdev->constraints->always_on ||
1256 !rdev->constraints->boot_on) {
1257 err = regmap_update_bits(mfd->regmap, r->init.reg,
1258 r->init.mask, r->init.val);
1259 if (err) {
1260 dev_err(&pdev->dev,
1261 "Failed to take control for (%s)\n",
1262 desc->name);
1263 goto err;
1264 }
ba08799e 1265 }
494edd26 1266 for (j = 0; j < r->additional_init_amnt; j++) {
bcb047eb 1267 err = regmap_update_bits(mfd->regmap,
494edd26
MV
1268 r->additional_inits[j].reg,
1269 r->additional_inits[j].mask,
1270 r->additional_inits[j].val);
1271 if (err) {
bcb047eb 1272 dev_err(&pdev->dev,
494edd26
MV
1273 "Buck (%s) initialization failed\n",
1274 desc->name);
1275 goto err;
1276 }
1277 }
ba08799e
MV
1278 }
1279
ba08799e
MV
1280err:
1281 return err;
1282}
1283
dd2be639 1284static struct platform_driver bd718xx_regulator = {
ba08799e 1285 .driver = {
494edd26 1286 .name = "bd718xx-pmic",
ba08799e 1287 },
dd2be639 1288 .probe = bd718xx_probe,
ba08799e
MV
1289};
1290
dd2be639 1291module_platform_driver(bd718xx_regulator);
ba08799e
MV
1292
1293MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
dd2be639 1294MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
ba08799e 1295MODULE_LICENSE("GPL");