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