This source file includes following definitions.
- ab8500_ext_regulator_enable
- ab8500_ext_regulator_disable
- ab8500_ext_regulator_is_enabled
- ab8500_ext_regulator_set_mode
- ab8500_ext_regulator_get_mode
- ab8500_ext_set_voltage
- ab8500_ext_list_voltage
- ab8500_ext_regulator_probe
- ab8500_ext_regulator_init
- ab8500_ext_regulator_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/err.h>
17 #include <linux/module.h>
18 #include <linux/of.h>
19 #include <linux/platform_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/mfd/abx500.h>
24 #include <linux/mfd/abx500/ab8500.h>
25 #include <linux/regulator/ab8500.h>
26
27 static struct regulator_consumer_supply ab8500_vaux1_consumers[] = {
28
29 REGULATOR_SUPPLY("vddi", "mcde_disp_sony_acx424akp.0"),
30
31 REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.0"),
32
33 REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.1"),
34
35 REGULATOR_SUPPLY("vcc", "gpio-keys.0"),
36
37 REGULATOR_SUPPLY("vcc", "2-0029"),
38
39 REGULATOR_SUPPLY("vdd", "2-0018"),
40
41 REGULATOR_SUPPLY("vdd", "2-0019"),
42
43 REGULATOR_SUPPLY("vdd", "2-001e"),
44
45 REGULATOR_SUPPLY("avdd", "3-005c"),
46 REGULATOR_SUPPLY("avdd", "3-005d"),
47
48 REGULATOR_SUPPLY("vdd", "3-004b"),
49
50 REGULATOR_SUPPLY("vdd", "2-0068"),
51
52 REGULATOR_SUPPLY("vdd", "3-0029"),
53
54 REGULATOR_SUPPLY("vdd", "2-005c"),
55
56 REGULATOR_SUPPLY("vcpin", "spi8.0"),
57
58 REGULATOR_SUPPLY("vaux12v5", "mmio_camera"),
59 };
60
61 static struct regulator_consumer_supply ab8500_vaux2_consumers[] = {
62
63 REGULATOR_SUPPLY("vmmc", "sdi4"),
64
65 REGULATOR_SUPPLY("vcc-N2158", "ab8500-codec.0"),
66
67 REGULATOR_SUPPLY("vcc-N2158", "ab8500-acc-det.0"),
68
69 REGULATOR_SUPPLY("vcc-N2158", "mcde_tv_ab8500.4"),
70
71 REGULATOR_SUPPLY("vcc-N2158", "av8100_hdmi.3"),
72 };
73
74 static struct regulator_consumer_supply ab8500_vaux3_consumers[] = {
75 REGULATOR_SUPPLY("v-SD-STM", "stm"),
76
77 REGULATOR_SUPPLY("vmmc", "sdi0"),
78 };
79
80 static struct regulator_consumer_supply ab8500_vtvout_consumers[] = {
81
82 REGULATOR_SUPPLY("vtvout", "ab8500-denc.0"),
83
84 REGULATOR_SUPPLY("vddadc", "ab8500-gpadc.0"),
85
86 REGULATOR_SUPPLY("vddadc", "ab8500-charger.0"),
87
88 REGULATOR_SUPPLY("vtvout", "mcde_tv_ab8500.4"),
89 };
90
91 static struct regulator_consumer_supply ab8500_vaud_consumers[] = {
92
93 REGULATOR_SUPPLY("vaud", "ab8500-codec.0"),
94 };
95
96 static struct regulator_consumer_supply ab8500_vamic1_consumers[] = {
97
98 REGULATOR_SUPPLY("vamic1", "ab8500-codec.0"),
99 };
100
101 static struct regulator_consumer_supply ab8500_vamic2_consumers[] = {
102
103 REGULATOR_SUPPLY("vamic2", "ab8500-codec.0"),
104 };
105
106 static struct regulator_consumer_supply ab8500_vdmic_consumers[] = {
107
108 REGULATOR_SUPPLY("vdmic", "ab8500-codec.0"),
109 };
110
111 static struct regulator_consumer_supply ab8500_vintcore_consumers[] = {
112
113 REGULATOR_SUPPLY("v-intcore", NULL),
114
115 REGULATOR_SUPPLY("vddulpivio18", "ab8500-usb.0"),
116
117 REGULATOR_SUPPLY("v-intcore", "abx500-clk.0"),
118 };
119
120 static struct regulator_consumer_supply ab8500_vana_consumers[] = {
121
122 REGULATOR_SUPPLY("vdddsi1v2", "mcde"),
123 REGULATOR_SUPPLY("vdddsi1v2", "b2r2_core"),
124 REGULATOR_SUPPLY("vdddsi1v2", "b2r2_1_core"),
125 REGULATOR_SUPPLY("vdddsi1v2", "dsilink.0"),
126 REGULATOR_SUPPLY("vdddsi1v2", "dsilink.1"),
127 REGULATOR_SUPPLY("vdddsi1v2", "dsilink.2"),
128
129 REGULATOR_SUPPLY("vddcsi1v2", "mmio_camera"),
130 };
131
132
133 static struct ab8500_regulator_reg_init ab8500_reg_init[] = {
134
135
136
137
138 INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL2, 0xf0, 0x00),
139
140
141
142
143
144
145 INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL3, 0xff, 0x00),
146
147
148
149
150 INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL4, 0x07, 0x00),
151
152
153
154
155
156
157 INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID1, 0xe8, 0x00),
158
159
160
161
162
163 INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID2, 0x70, 0x40),
164
165
166
167
168
169
170 INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID1, 0xe8, 0x00),
171
172
173
174
175
176 INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID2, 0x07, 0x00),
177
178
179
180
181
182
183 INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID1, 0xe8, 0x00),
184
185
186
187
188
189 INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID2, 0x07, 0x04),
190
191
192
193
194 INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID1, 0xa0, 0x00),
195
196
197
198
199
200
201
202 INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID2, 0x1f, 0x00),
203
204
205
206
207
208
209
210
211
212 INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID1, 0xfe, 0x2a),
213
214
215
216
217
218
219
220
221
222 INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID2, 0xfe, 0x20),
223
224
225
226
227
228
229
230 INIT_REGULATOR_REGISTER(AB8500_REGUMISC1, 0xfe, 0x10),
231
232
233
234
235
236
237 INIT_REGULATOR_REGISTER(AB8500_VAUDIOSUPPLY, 0x1e, 0x00),
238
239
240
241
242 INIT_REGULATOR_REGISTER(AB8500_REGUCTRL1VAMIC, 0x03, 0x00),
243
244
245
246
247 INIT_REGULATOR_REGISTER(AB8500_VPLLVANAREGU, 0x0f, 0x02),
248
249
250
251
252 INIT_REGULATOR_REGISTER(AB8500_VREFDDR, 0x03, 0x00),
253
254
255
256
257
258
259
260 INIT_REGULATOR_REGISTER(AB8500_EXTSUPPLYREGU, 0xff, 0x13),
261
262
263
264
265 INIT_REGULATOR_REGISTER(AB8500_VAUX12REGU, 0x0f, 0x01),
266
267
268
269 INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3REGU, 0x03, 0x00),
270
271
272
273 INIT_REGULATOR_REGISTER(AB8500_VAUX1SEL, 0x0f, 0x0C),
274
275
276
277 INIT_REGULATOR_REGISTER(AB8500_VAUX2SEL, 0x0f, 0x0d),
278
279
280
281 INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3SEL, 0x07, 0x07),
282
283
284
285 INIT_REGULATOR_REGISTER(AB8500_REGUCTRL2SPARE, 0x01, 0x00),
286
287
288
289
290
291
292
293
294 INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH, 0xfc, 0x00),
295
296
297
298
299
300 INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH2, 0x16, 0x00),
301 };
302
303
304 static struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS] = {
305
306 [AB8500_LDO_AUX1] = {
307 .supply_regulator = "ab8500-ext-supply3",
308 .constraints = {
309 .name = "V-DISPLAY",
310 .min_uV = 2800000,
311 .max_uV = 3300000,
312 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
313 REGULATOR_CHANGE_STATUS,
314 .boot_on = 1,
315 },
316 .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux1_consumers),
317 .consumer_supplies = ab8500_vaux1_consumers,
318 },
319
320 [AB8500_LDO_AUX2] = {
321 .supply_regulator = "ab8500-ext-supply3",
322 .constraints = {
323 .name = "V-eMMC1",
324 .min_uV = 1100000,
325 .max_uV = 3300000,
326 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
327 REGULATOR_CHANGE_STATUS |
328 REGULATOR_CHANGE_MODE,
329 .valid_modes_mask = REGULATOR_MODE_NORMAL |
330 REGULATOR_MODE_IDLE,
331 },
332 .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux2_consumers),
333 .consumer_supplies = ab8500_vaux2_consumers,
334 },
335
336 [AB8500_LDO_AUX3] = {
337 .supply_regulator = "ab8500-ext-supply3",
338 .constraints = {
339 .name = "V-MMC-SD",
340 .min_uV = 1100000,
341 .max_uV = 3300000,
342 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
343 REGULATOR_CHANGE_STATUS |
344 REGULATOR_CHANGE_MODE,
345 .valid_modes_mask = REGULATOR_MODE_NORMAL |
346 REGULATOR_MODE_IDLE,
347 },
348 .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux3_consumers),
349 .consumer_supplies = ab8500_vaux3_consumers,
350 },
351
352 [AB8500_LDO_TVOUT] = {
353 .constraints = {
354 .name = "V-TVOUT",
355 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
356 },
357 .num_consumer_supplies = ARRAY_SIZE(ab8500_vtvout_consumers),
358 .consumer_supplies = ab8500_vtvout_consumers,
359 },
360
361 [AB8500_LDO_AUDIO] = {
362 .constraints = {
363 .name = "V-AUD",
364 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
365 },
366 .num_consumer_supplies = ARRAY_SIZE(ab8500_vaud_consumers),
367 .consumer_supplies = ab8500_vaud_consumers,
368 },
369
370 [AB8500_LDO_ANAMIC1] = {
371 .constraints = {
372 .name = "V-AMIC1",
373 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
374 },
375 .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic1_consumers),
376 .consumer_supplies = ab8500_vamic1_consumers,
377 },
378
379 [AB8500_LDO_ANAMIC2] = {
380 .constraints = {
381 .name = "V-AMIC2",
382 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
383 },
384 .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic2_consumers),
385 .consumer_supplies = ab8500_vamic2_consumers,
386 },
387
388 [AB8500_LDO_DMIC] = {
389 .constraints = {
390 .name = "V-DMIC",
391 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
392 },
393 .num_consumer_supplies = ARRAY_SIZE(ab8500_vdmic_consumers),
394 .consumer_supplies = ab8500_vdmic_consumers,
395 },
396
397 [AB8500_LDO_INTCORE] = {
398 .constraints = {
399 .name = "V-INTCORE",
400 .min_uV = 1250000,
401 .max_uV = 1350000,
402 .input_uV = 1800000,
403 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
404 REGULATOR_CHANGE_STATUS |
405 REGULATOR_CHANGE_MODE |
406 REGULATOR_CHANGE_DRMS,
407 .valid_modes_mask = REGULATOR_MODE_NORMAL |
408 REGULATOR_MODE_IDLE,
409 },
410 .num_consumer_supplies = ARRAY_SIZE(ab8500_vintcore_consumers),
411 .consumer_supplies = ab8500_vintcore_consumers,
412 },
413
414 [AB8500_LDO_ANA] = {
415 .constraints = {
416 .name = "V-CSI-DSI",
417 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
418 },
419 .num_consumer_supplies = ARRAY_SIZE(ab8500_vana_consumers),
420 .consumer_supplies = ab8500_vana_consumers,
421 },
422 };
423
424
425 static struct regulator_consumer_supply ab8500_ext_supply3_consumers[] = {
426
427 REGULATOR_SUPPLY("vinvsim", "sim-detect.0"),
428 };
429
430
431
432
433 static struct regulator_init_data ab8500_ext_regulators[] = {
434
435 [AB8500_EXT_SUPPLY1] = {
436 .constraints = {
437 .name = "ab8500-ext-supply1",
438 .min_uV = 1800000,
439 .max_uV = 1800000,
440 .initial_mode = REGULATOR_MODE_IDLE,
441 .boot_on = 1,
442 .always_on = 1,
443 },
444 },
445
446 [AB8500_EXT_SUPPLY2] = {
447 .constraints = {
448 .name = "ab8500-ext-supply2",
449 .min_uV = 1360000,
450 .max_uV = 1360000,
451 },
452 },
453
454 [AB8500_EXT_SUPPLY3] = {
455 .constraints = {
456 .name = "ab8500-ext-supply3",
457 .min_uV = 3400000,
458 .max_uV = 3400000,
459 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
460 .boot_on = 1,
461 },
462 .num_consumer_supplies =
463 ARRAY_SIZE(ab8500_ext_supply3_consumers),
464 .consumer_supplies = ab8500_ext_supply3_consumers,
465 },
466 };
467
468 static struct ab8500_regulator_platform_data ab8500_regulator_plat_data = {
469 .reg_init = ab8500_reg_init,
470 .num_reg_init = ARRAY_SIZE(ab8500_reg_init),
471 .regulator = ab8500_regulators,
472 .num_regulator = ARRAY_SIZE(ab8500_regulators),
473 .ext_regulator = ab8500_ext_regulators,
474 .num_ext_regulator = ARRAY_SIZE(ab8500_ext_regulators),
475 };
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493 struct ab8500_ext_regulator_info {
494 struct device *dev;
495 struct regulator_desc desc;
496 struct ab8500_ext_regulator_cfg *cfg;
497 u8 update_bank;
498 u8 update_reg;
499 u8 update_mask;
500 u8 update_val;
501 u8 update_val_hp;
502 u8 update_val_lp;
503 u8 update_val_hw;
504 };
505
506 static int ab8500_ext_regulator_enable(struct regulator_dev *rdev)
507 {
508 int ret;
509 struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
510 u8 regval;
511
512 if (info == NULL) {
513 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
514 return -EINVAL;
515 }
516
517
518
519
520
521 if (info->cfg && info->cfg->hwreq)
522 regval = info->update_val_hp;
523 else
524 regval = info->update_val;
525
526 ret = abx500_mask_and_set_register_interruptible(info->dev,
527 info->update_bank, info->update_reg,
528 info->update_mask, regval);
529 if (ret < 0) {
530 dev_err(rdev_get_dev(rdev),
531 "couldn't set enable bits for regulator\n");
532 return ret;
533 }
534
535 dev_dbg(rdev_get_dev(rdev),
536 "%s-enable (bank, reg, mask, value): 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
537 info->desc.name, info->update_bank, info->update_reg,
538 info->update_mask, regval);
539
540 return 0;
541 }
542
543 static int ab8500_ext_regulator_disable(struct regulator_dev *rdev)
544 {
545 int ret;
546 struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
547 u8 regval;
548
549 if (info == NULL) {
550 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
551 return -EINVAL;
552 }
553
554
555
556
557 if (info->cfg && info->cfg->hwreq)
558 regval = info->update_val_hw;
559 else
560 regval = 0;
561
562 ret = abx500_mask_and_set_register_interruptible(info->dev,
563 info->update_bank, info->update_reg,
564 info->update_mask, regval);
565 if (ret < 0) {
566 dev_err(rdev_get_dev(rdev),
567 "couldn't set disable bits for regulator\n");
568 return ret;
569 }
570
571 dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):"
572 " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
573 info->desc.name, info->update_bank, info->update_reg,
574 info->update_mask, regval);
575
576 return 0;
577 }
578
579 static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev)
580 {
581 int ret;
582 struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
583 u8 regval;
584
585 if (info == NULL) {
586 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
587 return -EINVAL;
588 }
589
590 ret = abx500_get_register_interruptible(info->dev,
591 info->update_bank, info->update_reg, ®val);
592 if (ret < 0) {
593 dev_err(rdev_get_dev(rdev),
594 "couldn't read 0x%x register\n", info->update_reg);
595 return ret;
596 }
597
598 dev_dbg(rdev_get_dev(rdev), "%s-is_enabled (bank, reg, mask, value):"
599 " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
600 info->desc.name, info->update_bank, info->update_reg,
601 info->update_mask, regval);
602
603 if (((regval & info->update_mask) == info->update_val_lp) ||
604 ((regval & info->update_mask) == info->update_val_hp))
605 return 1;
606 else
607 return 0;
608 }
609
610 static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,
611 unsigned int mode)
612 {
613 int ret = 0;
614 struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
615 u8 regval;
616
617 if (info == NULL) {
618 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
619 return -EINVAL;
620 }
621
622 switch (mode) {
623 case REGULATOR_MODE_NORMAL:
624 regval = info->update_val_hp;
625 break;
626 case REGULATOR_MODE_IDLE:
627 regval = info->update_val_lp;
628 break;
629
630 default:
631 return -EINVAL;
632 }
633
634
635
636
637
638 if (ab8500_ext_regulator_is_enabled(rdev) &&
639 !(info->cfg && info->cfg->hwreq)) {
640 ret = abx500_mask_and_set_register_interruptible(info->dev,
641 info->update_bank, info->update_reg,
642 info->update_mask, regval);
643 if (ret < 0) {
644 dev_err(rdev_get_dev(rdev),
645 "Could not set regulator mode.\n");
646 return ret;
647 }
648
649 dev_dbg(rdev_get_dev(rdev),
650 "%s-set_mode (bank, reg, mask, value): "
651 "0x%x, 0x%x, 0x%x, 0x%x\n",
652 info->desc.name, info->update_bank, info->update_reg,
653 info->update_mask, regval);
654 }
655
656 info->update_val = regval;
657
658 return 0;
659 }
660
661 static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev)
662 {
663 struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
664 int ret;
665
666 if (info == NULL) {
667 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
668 return -EINVAL;
669 }
670
671 if (info->update_val == info->update_val_hp)
672 ret = REGULATOR_MODE_NORMAL;
673 else if (info->update_val == info->update_val_lp)
674 ret = REGULATOR_MODE_IDLE;
675 else
676 ret = -EINVAL;
677
678 return ret;
679 }
680
681 static int ab8500_ext_set_voltage(struct regulator_dev *rdev, int min_uV,
682 int max_uV, unsigned *selector)
683 {
684 struct regulation_constraints *regu_constraints = rdev->constraints;
685
686 if (!regu_constraints) {
687 dev_err(rdev_get_dev(rdev), "No regulator constraints\n");
688 return -EINVAL;
689 }
690
691 if (regu_constraints->min_uV == min_uV &&
692 regu_constraints->max_uV == max_uV)
693 return 0;
694
695 dev_err(rdev_get_dev(rdev),
696 "Requested min %duV max %duV != constrained min %duV max %duV\n",
697 min_uV, max_uV,
698 regu_constraints->min_uV, regu_constraints->max_uV);
699
700 return -EINVAL;
701 }
702
703 static int ab8500_ext_list_voltage(struct regulator_dev *rdev,
704 unsigned selector)
705 {
706 struct regulation_constraints *regu_constraints = rdev->constraints;
707
708 if (regu_constraints == NULL) {
709 dev_err(rdev_get_dev(rdev), "regulator constraints null pointer\n");
710 return -EINVAL;
711 }
712
713 if (regu_constraints->min_uV && regu_constraints->max_uV) {
714 if (regu_constraints->min_uV == regu_constraints->max_uV)
715 return regu_constraints->min_uV;
716 }
717 return -EINVAL;
718 }
719
720 static const struct regulator_ops ab8500_ext_regulator_ops = {
721 .enable = ab8500_ext_regulator_enable,
722 .disable = ab8500_ext_regulator_disable,
723 .is_enabled = ab8500_ext_regulator_is_enabled,
724 .set_mode = ab8500_ext_regulator_set_mode,
725 .get_mode = ab8500_ext_regulator_get_mode,
726 .set_voltage = ab8500_ext_set_voltage,
727 .list_voltage = ab8500_ext_list_voltage,
728 };
729
730 static struct ab8500_ext_regulator_info
731 ab8500_ext_regulator_info[AB8500_NUM_EXT_REGULATORS] = {
732 [AB8500_EXT_SUPPLY1] = {
733 .desc = {
734 .name = "VEXTSUPPLY1",
735 .of_match = of_match_ptr("ab8500_ext1"),
736 .ops = &ab8500_ext_regulator_ops,
737 .type = REGULATOR_VOLTAGE,
738 .id = AB8500_EXT_SUPPLY1,
739 .owner = THIS_MODULE,
740 .n_voltages = 1,
741 },
742 .update_bank = 0x04,
743 .update_reg = 0x08,
744 .update_mask = 0x03,
745 .update_val = 0x01,
746 .update_val_hp = 0x01,
747 .update_val_lp = 0x03,
748 .update_val_hw = 0x02,
749 },
750 [AB8500_EXT_SUPPLY2] = {
751 .desc = {
752 .name = "VEXTSUPPLY2",
753 .of_match = of_match_ptr("ab8500_ext2"),
754 .ops = &ab8500_ext_regulator_ops,
755 .type = REGULATOR_VOLTAGE,
756 .id = AB8500_EXT_SUPPLY2,
757 .owner = THIS_MODULE,
758 .n_voltages = 1,
759 },
760 .update_bank = 0x04,
761 .update_reg = 0x08,
762 .update_mask = 0x0c,
763 .update_val = 0x04,
764 .update_val_hp = 0x04,
765 .update_val_lp = 0x0c,
766 .update_val_hw = 0x08,
767 },
768 [AB8500_EXT_SUPPLY3] = {
769 .desc = {
770 .name = "VEXTSUPPLY3",
771 .of_match = of_match_ptr("ab8500_ext3"),
772 .ops = &ab8500_ext_regulator_ops,
773 .type = REGULATOR_VOLTAGE,
774 .id = AB8500_EXT_SUPPLY3,
775 .owner = THIS_MODULE,
776 .n_voltages = 1,
777 },
778 .update_bank = 0x04,
779 .update_reg = 0x08,
780 .update_mask = 0x30,
781 .update_val = 0x10,
782 .update_val_hp = 0x10,
783 .update_val_lp = 0x30,
784 .update_val_hw = 0x20,
785 },
786 };
787
788 static int ab8500_ext_regulator_probe(struct platform_device *pdev)
789 {
790 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
791 struct ab8500_regulator_platform_data *pdata = &ab8500_regulator_plat_data;
792 struct regulator_config config = { };
793 struct regulator_dev *rdev;
794 int i;
795
796 if (!ab8500) {
797 dev_err(&pdev->dev, "null mfd parent\n");
798 return -EINVAL;
799 }
800
801
802 if (pdata->num_ext_regulator != ARRAY_SIZE(ab8500_ext_regulator_info)) {
803 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
804 return -EINVAL;
805 }
806
807
808 if (is_ab8500_2p0_or_earlier(ab8500)) {
809 struct ab8500_ext_regulator_info *info;
810
811
812 info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3];
813 info->update_val = 0x30;
814 info->update_val_hp = 0x30;
815 info->update_val_lp = 0x10;
816 }
817
818
819 for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) {
820 struct ab8500_ext_regulator_info *info = NULL;
821
822
823 info = &ab8500_ext_regulator_info[i];
824 info->dev = &pdev->dev;
825 info->cfg = (struct ab8500_ext_regulator_cfg *)
826 pdata->ext_regulator[i].driver_data;
827
828 config.dev = &pdev->dev;
829 config.driver_data = info;
830 config.init_data = &pdata->ext_regulator[i];
831
832
833 rdev = devm_regulator_register(&pdev->dev, &info->desc,
834 &config);
835 if (IS_ERR(rdev)) {
836 dev_err(&pdev->dev, "failed to register regulator %s\n",
837 info->desc.name);
838 return PTR_ERR(rdev);
839 }
840
841 dev_dbg(&pdev->dev, "%s-probed\n", info->desc.name);
842 }
843
844 return 0;
845 }
846
847 static struct platform_driver ab8500_ext_regulator_driver = {
848 .probe = ab8500_ext_regulator_probe,
849 .driver = {
850 .name = "ab8500-ext-regulator",
851 },
852 };
853
854 static int __init ab8500_ext_regulator_init(void)
855 {
856 int ret;
857
858 ret = platform_driver_register(&ab8500_ext_regulator_driver);
859 if (ret)
860 pr_err("Failed to register ab8500 ext regulator: %d\n", ret);
861
862 return ret;
863 }
864 subsys_initcall(ab8500_ext_regulator_init);
865
866 static void __exit ab8500_ext_regulator_exit(void)
867 {
868 platform_driver_unregister(&ab8500_ext_regulator_driver);
869 }
870 module_exit(ab8500_ext_regulator_exit);
871
872 MODULE_LICENSE("GPL v2");
873 MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
874 MODULE_DESCRIPTION("AB8500 external regulator driver");
875 MODULE_ALIAS("platform:ab8500-ext-regulator");