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