regulator: bd718x7: Remove struct bd718xx_pmic
[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>
ba08799e
MV
12#include <linux/platform_device.h>
13#include <linux/regulator/driver.h>
14#include <linux/regulator/machine.h>
ba08799e 15#include <linux/regulator/of_regulator.h>
c9dc4cfa 16#include <linux/slab.h>
ba08799e 17
ba08799e
MV
18/*
19 * BUCK1/2/3/4
20 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
21 * 00: 10.00mV/usec 10mV 1uS
22 * 01: 5.00mV/usec 10mV 2uS
23 * 10: 2.50mV/usec 10mV 4uS
24 * 11: 1.25mV/usec 10mV 8uS
25 */
dd2be639 26static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
ba08799e
MV
27 int ramp_delay)
28{
ba08799e
MV
29 int id = rdev->desc->id;
30 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
31
bcb047eb 32 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
ba08799e
MV
33 ramp_delay);
34 switch (ramp_delay) {
35 case 1 ... 1250:
36 ramp_value = BUCK_RAMPRATE_1P25MV;
37 break;
38 case 1251 ... 2500:
39 ramp_value = BUCK_RAMPRATE_2P50MV;
40 break;
41 case 2501 ... 5000:
42 ramp_value = BUCK_RAMPRATE_5P00MV;
43 break;
44 case 5001 ... 10000:
45 ramp_value = BUCK_RAMPRATE_10P00MV;
46 break;
47 default:
48 ramp_value = BUCK_RAMPRATE_10P00MV;
bcb047eb 49 dev_err(&rdev->dev,
ba08799e
MV
50 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
51 rdev->desc->name, ramp_delay);
52 }
53
bcb047eb 54 return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
ba08799e
MV
55 BUCK_RAMPRATE_MASK, ramp_value << 6);
56}
57
58/* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
59 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
60 * is changed. Hence we return -EBUSY for these if voltage is changed
61 * when BUCK/LDO is enabled.
62 */
494edd26 63static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
ba08799e
MV
64 unsigned int sel)
65{
ffdc4984
AL
66 if (regulator_is_enabled_regmap(rdev))
67 return -EBUSY;
ba08799e 68
ffdc4984 69 return regulator_set_voltage_sel_regmap(rdev, sel);
ba08799e
MV
70}
71
a4bfc2c2
MV
72static int bd718xx_set_voltage_sel_pickable_restricted(
73 struct regulator_dev *rdev, unsigned int sel)
74{
75 if (regulator_is_enabled_regmap(rdev))
76 return -EBUSY;
77
78 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
79}
80
81static struct regulator_ops bd718xx_pickable_range_ldo_ops = {
82 .enable = regulator_enable_regmap,
83 .disable = regulator_disable_regmap,
84 .is_enabled = regulator_is_enabled_regmap,
85 .list_voltage = regulator_list_voltage_pickable_linear_range,
86 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
87 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
88};
89
90static struct regulator_ops bd718xx_pickable_range_buck_ops = {
91 .enable = regulator_enable_regmap,
92 .disable = regulator_disable_regmap,
93 .is_enabled = regulator_is_enabled_regmap,
94 .list_voltage = regulator_list_voltage_pickable_linear_range,
95 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
96 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
97 .set_voltage_time_sel = regulator_set_voltage_time_sel,
98};
99
494edd26 100static struct regulator_ops bd718xx_ldo_regulator_ops = {
ba08799e
MV
101 .enable = regulator_enable_regmap,
102 .disable = regulator_disable_regmap,
103 .is_enabled = regulator_is_enabled_regmap,
104 .list_voltage = regulator_list_voltage_linear_range,
494edd26 105 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
106 .get_voltage_sel = regulator_get_voltage_sel_regmap,
107};
108
494edd26 109static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
ba08799e
MV
110 .enable = regulator_enable_regmap,
111 .disable = regulator_disable_regmap,
112 .is_enabled = regulator_is_enabled_regmap,
113 .list_voltage = regulator_list_voltage_table,
494edd26 114 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
115 .get_voltage_sel = regulator_get_voltage_sel_regmap,
116};
117
494edd26 118static struct regulator_ops bd718xx_buck_regulator_ops = {
ba08799e
MV
119 .enable = regulator_enable_regmap,
120 .disable = regulator_disable_regmap,
121 .is_enabled = regulator_is_enabled_regmap,
122 .list_voltage = regulator_list_voltage_linear_range,
494edd26 123 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
124 .get_voltage_sel = regulator_get_voltage_sel_regmap,
125 .set_voltage_time_sel = regulator_set_voltage_time_sel,
126};
127
494edd26 128static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
ba08799e
MV
129 .enable = regulator_enable_regmap,
130 .disable = regulator_disable_regmap,
131 .is_enabled = regulator_is_enabled_regmap,
132 .list_voltage = regulator_list_voltage_table,
494edd26 133 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
ba08799e
MV
134 .get_voltage_sel = regulator_get_voltage_sel_regmap,
135 .set_voltage_time_sel = regulator_set_voltage_time_sel,
136};
137
494edd26 138static struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
ba08799e
MV
139 .enable = regulator_enable_regmap,
140 .disable = regulator_disable_regmap,
141 .is_enabled = regulator_is_enabled_regmap,
142 .list_voltage = regulator_list_voltage_linear_range,
143 .set_voltage_sel = regulator_set_voltage_sel_regmap,
144 .get_voltage_sel = regulator_get_voltage_sel_regmap,
145 .set_voltage_time_sel = regulator_set_voltage_time_sel,
dd2be639 146 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
ba08799e
MV
147};
148
149/*
494edd26
MV
150 * BD71837 BUCK1/2/3/4
151 * BD71847 BUCK1/2
ba08799e
MV
152 * 0.70 to 1.30V (10mV step)
153 */
494edd26 154static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
ba08799e
MV
155 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
156 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
157};
158
159/*
494edd26 160 * BD71837 BUCK5
a4bfc2c2
MV
161 * 0.7V to 1.35V (range 0)
162 * and
163 * 0.675 to 1.325 (range 1)
164 */
165static const struct regulator_linear_range bd71837_buck5_volts[] = {
166 /* Ranges when VOLT_SEL bit is 0 */
167 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
168 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
169 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
170 /* Ranges when VOLT_SEL bit is 1 */
171 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
172 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
173 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
174};
175
176/*
177 * Range selector for first 3 linear ranges is 0x0
178 * and 0x1 for last 3 ranges.
179 */
180static const unsigned int bd71837_buck5_volt_range_sel[] = {
181 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
182};
183
184/*
494edd26 185 * BD71847 BUCK3
ba08799e 186 */
a4bfc2c2
MV
187static const struct regulator_linear_range bd71847_buck3_volts[] = {
188 /* Ranges when VOLT_SEL bits are 00 */
ba08799e
MV
189 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
190 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
191 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
a4bfc2c2
MV
192 /* Ranges when VOLT_SEL bits are 01 */
193 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
194 /* Ranges when VOLT_SEL bits are 11 */
195 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
196 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
197 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
198};
199
200static const unsigned int bd71847_buck3_volt_range_sel[] = {
201 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
ba08799e
MV
202};
203
a4bfc2c2 204static const struct regulator_linear_range bd71847_buck4_volts[] = {
494edd26 205 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c2 206 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
494edd26
MV
207};
208
a4bfc2c2
MV
209static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
210
ba08799e
MV
211/*
212 * BUCK6
213 * 3.0V to 3.3V (step 100mV)
214 */
a4bfc2c2 215static const struct regulator_linear_range bd71837_buck6_volts[] = {
ba08799e
MV
216 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
217};
218
219/*
494edd26
MV
220 * BD71837 BUCK7
221 * BD71847 BUCK5
ba08799e
MV
222 * 000 = 1.605V
223 * 001 = 1.695V
224 * 010 = 1.755V
225 * 011 = 1.8V (Initial)
226 * 100 = 1.845V
227 * 101 = 1.905V
228 * 110 = 1.95V
229 * 111 = 1.995V
230 */
494edd26 231static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
ba08799e
MV
232 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
233};
234
235/*
236 * BUCK8
237 * 0.8V to 1.40V (step 10mV)
238 */
494edd26 239static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
ba08799e 240 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
ba08799e
MV
241};
242
243/*
244 * LDO1
245 * 3.0 to 3.3V (100mV step)
246 */
494edd26 247static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
ba08799e 248 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c2 249 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
ba08799e
MV
250};
251
a4bfc2c2
MV
252static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
253
ba08799e
MV
254/*
255 * LDO2
256 * 0.8 or 0.9V
257 */
adb78a8e 258static const unsigned int ldo_2_volts[] = {
ba08799e
MV
259 900000, 800000
260};
261
262/*
263 * LDO3
264 * 1.8 to 3.3V (100mV step)
265 */
494edd26 266static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
ba08799e
MV
267 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
268};
269
270/*
271 * LDO4
272 * 0.9 to 1.8V (100mV step)
273 */
494edd26 274static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
ba08799e 275 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e
MV
276};
277
278/*
494edd26 279 * LDO5 for BD71837
ba08799e
MV
280 * 1.8 to 3.3V (100mV step)
281 */
a4bfc2c2 282static const struct regulator_linear_range bd71837_ldo5_volts[] = {
ba08799e
MV
283 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
284};
285
a4bfc2c2
MV
286/*
287 * LDO5 for BD71837
288 * 1.8 to 3.3V (100mV step)
289 */
290static const struct regulator_linear_range bd71847_ldo5_volts[] = {
291 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
292 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
293};
294
295static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
296
ba08799e
MV
297/*
298 * LDO6
299 * 0.9 to 1.8V (100mV step)
300 */
494edd26 301static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
ba08799e 302 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e
MV
303};
304
305/*
306 * LDO7
307 * 1.8 to 3.3V (100mV step)
308 */
494edd26 309static const struct regulator_linear_range bd71837_ldo7_volts[] = {
ba08799e
MV
310 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
311};
312
494edd26
MV
313struct reg_init {
314 unsigned int reg;
315 unsigned int mask;
316 unsigned int val;
317};
318struct bd718xx_regulator_data {
319 struct regulator_desc desc;
320 const struct reg_init init;
321 const struct reg_init *additional_inits;
322 int additional_init_amnt;
323};
324
325/*
326 * There is a HW quirk in BD71837. The shutdown sequence timings for
327 * bucks/LDOs which are controlled via register interface are changed.
328 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
329 * beginning of shut-down sequence. As bucks 6 and 7 are parent
330 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
331 * monitoring to errorneously detect under voltage and force PMIC to
332 * emergency state instead of poweroff. In order to avoid this we
333 * disable voltage monitoring for LDO5 and LDO6
334 */
335static const struct reg_init bd71837_ldo5_inits[] = {
336 {
337 .reg = BD718XX_REG_MVRFLTMASK2,
338 .mask = BD718XX_LDO5_VRMON80,
339 .val = BD718XX_LDO5_VRMON80,
340 },
341};
342
343static const struct reg_init bd71837_ldo6_inits[] = {
344 {
345 .reg = BD718XX_REG_MVRFLTMASK2,
346 .mask = BD718XX_LDO6_VRMON80,
347 .val = BD718XX_LDO6_VRMON80,
348 },
349};
350
351static const struct bd718xx_regulator_data bd71847_regulators[] = {
352 {
353 .desc = {
354 .name = "buck1",
355 .of_match = of_match_ptr("BUCK1"),
356 .regulators_node = of_match_ptr("regulators"),
357 .id = BD718XX_BUCK1,
358 .ops = &bd718xx_dvs_buck_regulator_ops,
359 .type = REGULATOR_VOLTAGE,
360 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
361 .linear_ranges = bd718xx_dvs_buck_volts,
362 .n_linear_ranges =
363 ARRAY_SIZE(bd718xx_dvs_buck_volts),
364 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
365 .vsel_mask = DVS_BUCK_RUN_MASK,
366 .enable_reg = BD718XX_REG_BUCK1_CTRL,
367 .enable_mask = BD718XX_BUCK_EN,
368 .owner = THIS_MODULE,
369 },
370 .init = {
371 .reg = BD718XX_REG_BUCK1_CTRL,
372 .mask = BD718XX_BUCK_SEL,
373 .val = BD718XX_BUCK_SEL,
374 },
375 },
ba08799e 376 {
494edd26
MV
377 .desc = {
378 .name = "buck2",
379 .of_match = of_match_ptr("BUCK2"),
380 .regulators_node = of_match_ptr("regulators"),
381 .id = BD718XX_BUCK2,
382 .ops = &bd718xx_dvs_buck_regulator_ops,
383 .type = REGULATOR_VOLTAGE,
384 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
385 .linear_ranges = bd718xx_dvs_buck_volts,
386 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
387 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
388 .vsel_mask = DVS_BUCK_RUN_MASK,
389 .enable_reg = BD718XX_REG_BUCK2_CTRL,
390 .enable_mask = BD718XX_BUCK_EN,
391 .owner = THIS_MODULE,
392 },
393 .init = {
394 .reg = BD718XX_REG_BUCK2_CTRL,
395 .mask = BD718XX_BUCK_SEL,
396 .val = BD718XX_BUCK_SEL,
397 },
ba08799e
MV
398 },
399 {
494edd26
MV
400 .desc = {
401 .name = "buck3",
402 .of_match = of_match_ptr("BUCK3"),
403 .regulators_node = of_match_ptr("regulators"),
404 .id = BD718XX_BUCK3,
a4bfc2c2 405 .ops = &bd718xx_pickable_range_buck_ops,
494edd26 406 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
407 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
408 .linear_ranges = bd71847_buck3_volts,
494edd26 409 .n_linear_ranges =
a4bfc2c2 410 ARRAY_SIZE(bd71847_buck3_volts),
494edd26
MV
411 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
412 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
a4bfc2c2
MV
413 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
414 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
415 .linear_range_selectors = bd71847_buck3_volt_range_sel,
494edd26
MV
416 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
417 .enable_mask = BD718XX_BUCK_EN,
418 .owner = THIS_MODULE,
419 },
420 .init = {
421 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
422 .mask = BD718XX_BUCK_SEL,
423 .val = BD718XX_BUCK_SEL,
424 },
ba08799e
MV
425 },
426 {
494edd26
MV
427 .desc = {
428 .name = "buck4",
429 .of_match = of_match_ptr("BUCK4"),
430 .regulators_node = of_match_ptr("regulators"),
431 .id = BD718XX_BUCK4,
a4bfc2c2 432 .ops = &bd718xx_pickable_range_buck_ops,
494edd26
MV
433 .type = REGULATOR_VOLTAGE,
434 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
a4bfc2c2 435 .linear_ranges = bd71847_buck4_volts,
494edd26 436 .n_linear_ranges =
a4bfc2c2 437 ARRAY_SIZE(bd71847_buck4_volts),
494edd26
MV
438 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
439 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
440 .vsel_mask = BD71847_BUCK4_MASK,
a4bfc2c2
MV
441 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
442 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
443 .linear_range_selectors = bd71847_buck4_volt_range_sel,
494edd26
MV
444 .enable_mask = BD718XX_BUCK_EN,
445 .owner = THIS_MODULE,
446 },
447 .init = {
448 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
449 .mask = BD718XX_BUCK_SEL,
450 .val = BD718XX_BUCK_SEL,
451 },
ba08799e
MV
452 },
453 {
494edd26
MV
454 .desc = {
455 .name = "buck5",
456 .of_match = of_match_ptr("BUCK5"),
dd2be639 457 .regulators_node = of_match_ptr("regulators"),
494edd26
MV
458 .id = BD718XX_BUCK5,
459 .ops = &bd718xx_buck_regulator_nolinear_ops,
460 .type = REGULATOR_VOLTAGE,
461 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
462 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
463 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
464 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
465 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
466 .enable_mask = BD718XX_BUCK_EN,
467 .owner = THIS_MODULE,
468 },
469 .init = {
470 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
471 .mask = BD718XX_BUCK_SEL,
472 .val = BD718XX_BUCK_SEL,
473 },
ba08799e
MV
474 },
475 {
494edd26
MV
476 .desc = {
477 .name = "buck6",
478 .of_match = of_match_ptr("BUCK6"),
479 .regulators_node = of_match_ptr("regulators"),
480 .id = BD718XX_BUCK6,
481 .ops = &bd718xx_buck_regulator_ops,
482 .type = REGULATOR_VOLTAGE,
dd2be639 483 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd26
MV
484 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
485 .n_linear_ranges =
486 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
487 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
488 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
489 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
490 .enable_mask = BD718XX_BUCK_EN,
491 .owner = THIS_MODULE,
492 },
493 .init = {
494 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
495 .mask = BD718XX_BUCK_SEL,
496 .val = BD718XX_BUCK_SEL,
497 },
ba08799e
MV
498 },
499 {
494edd26
MV
500 .desc = {
501 .name = "ldo1",
502 .of_match = of_match_ptr("LDO1"),
503 .regulators_node = of_match_ptr("regulators"),
504 .id = BD718XX_LDO1,
a4bfc2c2 505 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26
MV
506 .type = REGULATOR_VOLTAGE,
507 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
508 .linear_ranges = bd718xx_ldo1_volts,
509 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
510 .vsel_reg = BD718XX_REG_LDO1_VOLT,
511 .vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c2
MV
512 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
513 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
514 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd26
MV
515 .enable_reg = BD718XX_REG_LDO1_VOLT,
516 .enable_mask = BD718XX_LDO_EN,
517 .owner = THIS_MODULE,
518 },
519 .init = {
520 .reg = BD718XX_REG_LDO1_VOLT,
521 .mask = BD718XX_LDO_SEL,
522 .val = BD718XX_LDO_SEL,
523 },
ba08799e
MV
524 },
525 {
494edd26
MV
526 .desc = {
527 .name = "ldo2",
528 .of_match = of_match_ptr("LDO2"),
529 .regulators_node = of_match_ptr("regulators"),
530 .id = BD718XX_LDO2,
531 .ops = &bd718xx_ldo_regulator_nolinear_ops,
532 .type = REGULATOR_VOLTAGE,
533 .volt_table = &ldo_2_volts[0],
534 .vsel_reg = BD718XX_REG_LDO2_VOLT,
535 .vsel_mask = BD718XX_LDO2_MASK,
536 .n_voltages = ARRAY_SIZE(ldo_2_volts),
537 .enable_reg = BD718XX_REG_LDO2_VOLT,
538 .enable_mask = BD718XX_LDO_EN,
539 .owner = THIS_MODULE,
540 },
541 .init = {
542 .reg = BD718XX_REG_LDO2_VOLT,
543 .mask = BD718XX_LDO_SEL,
544 .val = BD718XX_LDO_SEL,
545 },
ba08799e
MV
546 },
547 {
494edd26
MV
548 .desc = {
549 .name = "ldo3",
550 .of_match = of_match_ptr("LDO3"),
551 .regulators_node = of_match_ptr("regulators"),
552 .id = BD718XX_LDO3,
553 .ops = &bd718xx_ldo_regulator_ops,
554 .type = REGULATOR_VOLTAGE,
555 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
556 .linear_ranges = bd718xx_ldo3_volts,
557 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
558 .vsel_reg = BD718XX_REG_LDO3_VOLT,
559 .vsel_mask = BD718XX_LDO3_MASK,
560 .enable_reg = BD718XX_REG_LDO3_VOLT,
561 .enable_mask = BD718XX_LDO_EN,
562 .owner = THIS_MODULE,
563 },
564 .init = {
565 .reg = BD718XX_REG_LDO3_VOLT,
566 .mask = BD718XX_LDO_SEL,
567 .val = BD718XX_LDO_SEL,
568 },
ba08799e
MV
569 },
570 {
494edd26
MV
571 .desc = {
572 .name = "ldo4",
573 .of_match = of_match_ptr("LDO4"),
574 .regulators_node = of_match_ptr("regulators"),
575 .id = BD718XX_LDO4,
576 .ops = &bd718xx_ldo_regulator_ops,
577 .type = REGULATOR_VOLTAGE,
578 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
579 .linear_ranges = bd718xx_ldo4_volts,
580 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
581 .vsel_reg = BD718XX_REG_LDO4_VOLT,
582 .vsel_mask = BD718XX_LDO4_MASK,
583 .enable_reg = BD718XX_REG_LDO4_VOLT,
584 .enable_mask = BD718XX_LDO_EN,
585 .owner = THIS_MODULE,
586 },
587 .init = {
588 .reg = BD718XX_REG_LDO4_VOLT,
589 .mask = BD718XX_LDO_SEL,
590 .val = BD718XX_LDO_SEL,
591 },
ba08799e
MV
592 },
593 {
494edd26
MV
594 .desc = {
595 .name = "ldo5",
596 .of_match = of_match_ptr("LDO5"),
597 .regulators_node = of_match_ptr("regulators"),
598 .id = BD718XX_LDO5,
a4bfc2c2 599 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26 600 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
601 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
602 .linear_ranges = bd71847_ldo5_volts,
603 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
494edd26
MV
604 .vsel_reg = BD718XX_REG_LDO5_VOLT,
605 .vsel_mask = BD71847_LDO5_MASK,
a4bfc2c2
MV
606 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
607 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
608 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
494edd26
MV
609 .enable_reg = BD718XX_REG_LDO5_VOLT,
610 .enable_mask = BD718XX_LDO_EN,
611 .owner = THIS_MODULE,
612 },
613 .init = {
614 .reg = BD718XX_REG_LDO5_VOLT,
615 .mask = BD718XX_LDO_SEL,
616 .val = BD718XX_LDO_SEL,
617 },
ba08799e
MV
618 },
619 {
494edd26
MV
620 .desc = {
621 .name = "ldo6",
622 .of_match = of_match_ptr("LDO6"),
623 .regulators_node = of_match_ptr("regulators"),
624 .id = BD718XX_LDO6,
625 .ops = &bd718xx_ldo_regulator_ops,
626 .type = REGULATOR_VOLTAGE,
627 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
628 .linear_ranges = bd718xx_ldo6_volts,
629 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
630 /* LDO6 is supplied by buck5 */
631 .supply_name = "buck5",
632 .vsel_reg = BD718XX_REG_LDO6_VOLT,
633 .vsel_mask = BD718XX_LDO6_MASK,
634 .enable_reg = BD718XX_REG_LDO6_VOLT,
635 .enable_mask = BD718XX_LDO_EN,
636 .owner = THIS_MODULE,
637 },
638 .init = {
639 .reg = BD718XX_REG_LDO6_VOLT,
640 .mask = BD718XX_LDO_SEL,
641 .val = BD718XX_LDO_SEL,
642 },
643 },
644};
645
646static const struct bd718xx_regulator_data bd71837_regulators[] = {
647 {
648 .desc = {
649 .name = "buck1",
650 .of_match = of_match_ptr("BUCK1"),
651 .regulators_node = of_match_ptr("regulators"),
652 .id = BD718XX_BUCK1,
653 .ops = &bd718xx_dvs_buck_regulator_ops,
654 .type = REGULATOR_VOLTAGE,
655 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
656 .linear_ranges = bd718xx_dvs_buck_volts,
657 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
658 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
659 .vsel_mask = DVS_BUCK_RUN_MASK,
660 .enable_reg = BD718XX_REG_BUCK1_CTRL,
661 .enable_mask = BD718XX_BUCK_EN,
662 .owner = THIS_MODULE,
663 },
664 .init = {
665 .reg = BD718XX_REG_BUCK1_CTRL,
666 .mask = BD718XX_BUCK_SEL,
667 .val = BD718XX_BUCK_SEL,
668 },
669 },
670 {
671 .desc = {
672 .name = "buck2",
673 .of_match = of_match_ptr("BUCK2"),
674 .regulators_node = of_match_ptr("regulators"),
675 .id = BD718XX_BUCK2,
676 .ops = &bd718xx_dvs_buck_regulator_ops,
677 .type = REGULATOR_VOLTAGE,
678 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
679 .linear_ranges = bd718xx_dvs_buck_volts,
680 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
681 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
682 .vsel_mask = DVS_BUCK_RUN_MASK,
683 .enable_reg = BD718XX_REG_BUCK2_CTRL,
684 .enable_mask = BD718XX_BUCK_EN,
685 .owner = THIS_MODULE,
686 },
687 .init = {
688 .reg = BD718XX_REG_BUCK2_CTRL,
689 .mask = BD718XX_BUCK_SEL,
690 .val = BD718XX_BUCK_SEL,
691 },
692 },
693 {
694 .desc = {
695 .name = "buck3",
696 .of_match = of_match_ptr("BUCK3"),
697 .regulators_node = of_match_ptr("regulators"),
698 .id = BD718XX_BUCK3,
699 .ops = &bd718xx_dvs_buck_regulator_ops,
700 .type = REGULATOR_VOLTAGE,
701 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
702 .linear_ranges = bd718xx_dvs_buck_volts,
703 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
704 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
705 .vsel_mask = DVS_BUCK_RUN_MASK,
706 .enable_reg = BD71837_REG_BUCK3_CTRL,
707 .enable_mask = BD718XX_BUCK_EN,
708 .owner = THIS_MODULE,
709 },
710 .init = {
711 .reg = BD71837_REG_BUCK3_CTRL,
712 .mask = BD718XX_BUCK_SEL,
713 .val = BD718XX_BUCK_SEL,
714 },
715 },
716 {
717 .desc = {
718 .name = "buck4",
719 .of_match = of_match_ptr("BUCK4"),
720 .regulators_node = of_match_ptr("regulators"),
721 .id = BD718XX_BUCK4,
722 .ops = &bd718xx_dvs_buck_regulator_ops,
723 .type = REGULATOR_VOLTAGE,
724 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
725 .linear_ranges = bd718xx_dvs_buck_volts,
726 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
727 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
728 .vsel_mask = DVS_BUCK_RUN_MASK,
729 .enable_reg = BD71837_REG_BUCK4_CTRL,
730 .enable_mask = BD718XX_BUCK_EN,
731 .owner = THIS_MODULE,
732 },
733 .init = {
734 .reg = BD71837_REG_BUCK4_CTRL,
735 .mask = BD718XX_BUCK_SEL,
736 .val = BD718XX_BUCK_SEL,
737 },
ba08799e
MV
738 },
739 {
494edd26
MV
740 .desc = {
741 .name = "buck5",
742 .of_match = of_match_ptr("BUCK5"),
743 .regulators_node = of_match_ptr("regulators"),
744 .id = BD718XX_BUCK5,
a4bfc2c2 745 .ops = &bd718xx_pickable_range_buck_ops,
494edd26 746 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
747 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
748 .linear_ranges = bd71837_buck5_volts,
494edd26 749 .n_linear_ranges =
a4bfc2c2 750 ARRAY_SIZE(bd71837_buck5_volts),
494edd26 751 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
a4bfc2c2
MV
752 .vsel_mask = BD71837_BUCK5_MASK,
753 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
754 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
755 .linear_range_selectors = bd71837_buck5_volt_range_sel,
494edd26
MV
756 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
757 .enable_mask = BD718XX_BUCK_EN,
758 .owner = THIS_MODULE,
759 },
760 .init = {
761 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
762 .mask = BD718XX_BUCK_SEL,
763 .val = BD718XX_BUCK_SEL,
764 },
ba08799e
MV
765 },
766 {
494edd26
MV
767 .desc = {
768 .name = "buck6",
769 .of_match = of_match_ptr("BUCK6"),
770 .regulators_node = of_match_ptr("regulators"),
771 .id = BD718XX_BUCK6,
772 .ops = &bd718xx_buck_regulator_ops,
773 .type = REGULATOR_VOLTAGE,
774 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
a4bfc2c2 775 .linear_ranges = bd71837_buck6_volts,
494edd26 776 .n_linear_ranges =
a4bfc2c2 777 ARRAY_SIZE(bd71837_buck6_volts),
494edd26
MV
778 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
779 .vsel_mask = BD71837_BUCK6_MASK,
780 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
781 .enable_mask = BD718XX_BUCK_EN,
782 .owner = THIS_MODULE,
783 },
784 .init = {
785 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
786 .mask = BD718XX_BUCK_SEL,
787 .val = BD718XX_BUCK_SEL,
788 },
ba08799e
MV
789 },
790 {
494edd26
MV
791 .desc = {
792 .name = "buck7",
793 .of_match = of_match_ptr("BUCK7"),
794 .regulators_node = of_match_ptr("regulators"),
795 .id = BD718XX_BUCK7,
796 .ops = &bd718xx_buck_regulator_nolinear_ops,
797 .type = REGULATOR_VOLTAGE,
798 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
799 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
800 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
801 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
802 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
803 .enable_mask = BD718XX_BUCK_EN,
804 .owner = THIS_MODULE,
805 },
806 .init = {
807 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
808 .mask = BD718XX_BUCK_SEL,
809 .val = BD718XX_BUCK_SEL,
810 },
ba08799e
MV
811 },
812 {
494edd26
MV
813 .desc = {
814 .name = "buck8",
815 .of_match = of_match_ptr("BUCK8"),
816 .regulators_node = of_match_ptr("regulators"),
817 .id = BD718XX_BUCK8,
818 .ops = &bd718xx_buck_regulator_ops,
819 .type = REGULATOR_VOLTAGE,
dd2be639 820 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd26
MV
821 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
822 .n_linear_ranges =
823 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
824 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
825 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
826 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
827 .enable_mask = BD718XX_BUCK_EN,
828 .owner = THIS_MODULE,
829 },
830 .init = {
831 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
832 .mask = BD718XX_BUCK_SEL,
833 .val = BD718XX_BUCK_SEL,
834 },
835 },
836 {
837 .desc = {
838 .name = "ldo1",
839 .of_match = of_match_ptr("LDO1"),
840 .regulators_node = of_match_ptr("regulators"),
841 .id = BD718XX_LDO1,
a4bfc2c2 842 .ops = &bd718xx_pickable_range_ldo_ops,
494edd26
MV
843 .type = REGULATOR_VOLTAGE,
844 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
845 .linear_ranges = bd718xx_ldo1_volts,
846 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
847 .vsel_reg = BD718XX_REG_LDO1_VOLT,
848 .vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c2
MV
849 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
850 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
851 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd26
MV
852 .enable_reg = BD718XX_REG_LDO1_VOLT,
853 .enable_mask = BD718XX_LDO_EN,
854 .owner = THIS_MODULE,
855 },
856 .init = {
857 .reg = BD718XX_REG_LDO1_VOLT,
858 .mask = BD718XX_LDO_SEL,
859 .val = BD718XX_LDO_SEL,
860 },
861 },
862 {
863 .desc = {
864 .name = "ldo2",
865 .of_match = of_match_ptr("LDO2"),
866 .regulators_node = of_match_ptr("regulators"),
867 .id = BD718XX_LDO2,
868 .ops = &bd718xx_ldo_regulator_nolinear_ops,
869 .type = REGULATOR_VOLTAGE,
870 .volt_table = &ldo_2_volts[0],
871 .vsel_reg = BD718XX_REG_LDO2_VOLT,
872 .vsel_mask = BD718XX_LDO2_MASK,
873 .n_voltages = ARRAY_SIZE(ldo_2_volts),
874 .enable_reg = BD718XX_REG_LDO2_VOLT,
875 .enable_mask = BD718XX_LDO_EN,
876 .owner = THIS_MODULE,
877 },
878 .init = {
879 .reg = BD718XX_REG_LDO2_VOLT,
880 .mask = BD718XX_LDO_SEL,
881 .val = BD718XX_LDO_SEL,
882 },
883 },
884 {
885 .desc = {
886 .name = "ldo3",
887 .of_match = of_match_ptr("LDO3"),
888 .regulators_node = of_match_ptr("regulators"),
889 .id = BD718XX_LDO3,
890 .ops = &bd718xx_ldo_regulator_ops,
891 .type = REGULATOR_VOLTAGE,
892 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
893 .linear_ranges = bd718xx_ldo3_volts,
894 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
895 .vsel_reg = BD718XX_REG_LDO3_VOLT,
896 .vsel_mask = BD718XX_LDO3_MASK,
897 .enable_reg = BD718XX_REG_LDO3_VOLT,
898 .enable_mask = BD718XX_LDO_EN,
899 .owner = THIS_MODULE,
900 },
901 .init = {
902 .reg = BD718XX_REG_LDO3_VOLT,
903 .mask = BD718XX_LDO_SEL,
904 .val = BD718XX_LDO_SEL,
905 },
906 },
907 {
908 .desc = {
909 .name = "ldo4",
910 .of_match = of_match_ptr("LDO4"),
911 .regulators_node = of_match_ptr("regulators"),
912 .id = BD718XX_LDO4,
913 .ops = &bd718xx_ldo_regulator_ops,
914 .type = REGULATOR_VOLTAGE,
915 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
916 .linear_ranges = bd718xx_ldo4_volts,
917 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
918 .vsel_reg = BD718XX_REG_LDO4_VOLT,
919 .vsel_mask = BD718XX_LDO4_MASK,
920 .enable_reg = BD718XX_REG_LDO4_VOLT,
921 .enable_mask = BD718XX_LDO_EN,
922 .owner = THIS_MODULE,
923 },
924 .init = {
925 .reg = BD718XX_REG_LDO4_VOLT,
926 .mask = BD718XX_LDO_SEL,
927 .val = BD718XX_LDO_SEL,
928 },
929 },
930 {
931 .desc = {
932 .name = "ldo5",
933 .of_match = of_match_ptr("LDO5"),
934 .regulators_node = of_match_ptr("regulators"),
935 .id = BD718XX_LDO5,
936 .ops = &bd718xx_ldo_regulator_ops,
937 .type = REGULATOR_VOLTAGE,
a4bfc2c2
MV
938 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
939 .linear_ranges = bd71837_ldo5_volts,
940 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
494edd26
MV
941 /* LDO5 is supplied by buck6 */
942 .supply_name = "buck6",
943 .vsel_reg = BD718XX_REG_LDO5_VOLT,
944 .vsel_mask = BD71837_LDO5_MASK,
945 .enable_reg = BD718XX_REG_LDO5_VOLT,
946 .enable_mask = BD718XX_LDO_EN,
947 .owner = THIS_MODULE,
948 },
949 .init = {
950 .reg = BD718XX_REG_LDO5_VOLT,
951 .mask = BD718XX_LDO_SEL,
952 .val = BD718XX_LDO_SEL,
953 },
954 .additional_inits = bd71837_ldo5_inits,
955 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
956 },
957 {
958 .desc = {
959 .name = "ldo6",
960 .of_match = of_match_ptr("LDO6"),
961 .regulators_node = of_match_ptr("regulators"),
962 .id = BD718XX_LDO6,
963 .ops = &bd718xx_ldo_regulator_ops,
964 .type = REGULATOR_VOLTAGE,
965 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
966 .linear_ranges = bd718xx_ldo6_volts,
967 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
968 /* LDO6 is supplied by buck7 */
969 .supply_name = "buck7",
970 .vsel_reg = BD718XX_REG_LDO6_VOLT,
971 .vsel_mask = BD718XX_LDO6_MASK,
972 .enable_reg = BD718XX_REG_LDO6_VOLT,
973 .enable_mask = BD718XX_LDO_EN,
974 .owner = THIS_MODULE,
975 },
976 .init = {
977 .reg = BD718XX_REG_LDO6_VOLT,
978 .mask = BD718XX_LDO_SEL,
979 .val = BD718XX_LDO_SEL,
980 },
981 .additional_inits = bd71837_ldo6_inits,
982 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
983 },
984 {
985 .desc = {
986 .name = "ldo7",
987 .of_match = of_match_ptr("LDO7"),
988 .regulators_node = of_match_ptr("regulators"),
989 .id = BD718XX_LDO7,
990 .ops = &bd718xx_ldo_regulator_ops,
991 .type = REGULATOR_VOLTAGE,
992 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
993 .linear_ranges = bd71837_ldo7_volts,
994 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
995 .vsel_reg = BD71837_REG_LDO7_VOLT,
996 .vsel_mask = BD71837_LDO7_MASK,
997 .enable_reg = BD71837_REG_LDO7_VOLT,
998 .enable_mask = BD718XX_LDO_EN,
999 .owner = THIS_MODULE,
1000 },
1001 .init = {
1002 .reg = BD71837_REG_LDO7_VOLT,
1003 .mask = BD718XX_LDO_SEL,
1004 .val = BD718XX_LDO_SEL,
1005 },
ba08799e
MV
1006 },
1007};
1008
494edd26
MV
1009struct bd718xx_pmic_inits {
1010 const struct bd718xx_regulator_data (*r_datas)[];
1011 unsigned int r_amount;
ba08799e
MV
1012};
1013
dd2be639 1014static int bd718xx_probe(struct platform_device *pdev)
ba08799e 1015{
bcb047eb 1016 struct bd718xx *mfd;
ba08799e 1017 struct regulator_config config = { 0 };
494edd26
MV
1018 struct bd718xx_pmic_inits pmic_regulators[] = {
1019 [BD718XX_TYPE_BD71837] = {
1020 .r_datas = &bd71837_regulators,
1021 .r_amount = ARRAY_SIZE(bd71837_regulators),
1022 },
1023 [BD718XX_TYPE_BD71847] = {
1024 .r_datas = &bd71847_regulators,
1025 .r_amount = ARRAY_SIZE(bd71847_regulators),
1026 },
ba08799e
MV
1027 };
1028
494edd26 1029 int i, j, err;
ba08799e 1030
bcb047eb
AL
1031 mfd = dev_get_drvdata(pdev->dev.parent);
1032 if (!mfd) {
ba08799e
MV
1033 dev_err(&pdev->dev, "No MFD driver data\n");
1034 err = -EINVAL;
1035 goto err;
1036 }
bcb047eb
AL
1037
1038 if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1039 !pmic_regulators[mfd->chip_type].r_datas) {
494edd26
MV
1040 dev_err(&pdev->dev, "Unsupported chip type\n");
1041 err = -EINVAL;
1042 goto err;
1043 }
1044
ba08799e 1045 /* Register LOCK release */
bcb047eb 1046 err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
ba08799e
MV
1047 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1048 if (err) {
bcb047eb 1049 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
ba08799e
MV
1050 goto err;
1051 } else {
bcb047eb 1052 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
494edd26 1053 BD718XX_REG_REGLOCK);
823f18f8
MV
1054 }
1055
bcb047eb 1056 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
ba08799e 1057
494edd26 1058 const struct regulator_desc *desc;
ba08799e 1059 struct regulator_dev *rdev;
494edd26 1060 const struct bd718xx_regulator_data *r;
ba08799e 1061
bcb047eb 1062 r = &(*pmic_regulators[mfd->chip_type].r_datas)[i];
494edd26 1063 desc = &r->desc;
ba08799e 1064
ba08799e 1065 config.dev = pdev->dev.parent;
bcb047eb 1066 config.regmap = mfd->regmap;
ba08799e
MV
1067
1068 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1069 if (IS_ERR(rdev)) {
bcb047eb 1070 dev_err(&pdev->dev,
ba08799e
MV
1071 "failed to register %s regulator\n",
1072 desc->name);
1073 err = PTR_ERR(rdev);
1074 goto err;
1075 }
1076 /* Regulator register gets the regulator constraints and
1077 * applies them (set_machine_constraints). This should have
1078 * turned the control register(s) to correct values and we
1079 * can now switch the control from PMIC state machine to the
1080 * register interface
1081 */
bcb047eb 1082 err = regmap_update_bits(mfd->regmap, r->init.reg,
494edd26 1083 r->init.mask, r->init.val);
ba08799e 1084 if (err) {
bcb047eb 1085 dev_err(&pdev->dev,
ba08799e
MV
1086 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1087 desc->name);
1088 goto err;
1089 }
494edd26 1090 for (j = 0; j < r->additional_init_amnt; j++) {
bcb047eb 1091 err = regmap_update_bits(mfd->regmap,
494edd26
MV
1092 r->additional_inits[j].reg,
1093 r->additional_inits[j].mask,
1094 r->additional_inits[j].val);
1095 if (err) {
bcb047eb 1096 dev_err(&pdev->dev,
494edd26
MV
1097 "Buck (%s) initialization failed\n",
1098 desc->name);
1099 goto err;
1100 }
1101 }
ba08799e
MV
1102 }
1103
ba08799e
MV
1104err:
1105 return err;
1106}
1107
dd2be639 1108static struct platform_driver bd718xx_regulator = {
ba08799e 1109 .driver = {
494edd26 1110 .name = "bd718xx-pmic",
ba08799e 1111 },
dd2be639 1112 .probe = bd718xx_probe,
ba08799e
MV
1113};
1114
dd2be639 1115module_platform_driver(bd718xx_regulator);
ba08799e
MV
1116
1117MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
dd2be639 1118MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
ba08799e 1119MODULE_LICENSE("GPL");