aboutsummaryrefslogtreecommitdiff
path: root/drivers/regulator/ab8500-regulator.c
blob: e0efa87404a7269cb79cb4b8c71db169dbf432bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/*
 * Copyright (C) STMicroelectronics 2009
 * Copyright (C) ST-Ericsson SA 2010
 *
 * License Terms: GNU General Public License v2
 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
 *
 * AB8500 peripheral regulators
 *
 * the AB8500 supports the following regulators,
 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VUSB, VINTCORE12, VTVOUT, VRTC,
 *	  VAUX1/2/3, VSIM/VRF1, VPLL, VANA, VRefDDR
 * Charge pumps - VCHPS, VBBN
 *
 * Based on the regulator to be accessed, the AB8500 client will use
 * either normal SPI/I2C or APE_I2C to access the regulator controls.
 *
 * FIXME : Regulator IDs constants are defined here until the ab8500 driver
 *	   is made into a mfd compliant code.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/consumer.h>

#include <mach/prcmu-fw-api.h>
#include <mach/ab8500.h>

#define AB8500_NUM_REGULATORS	(11)

#define AB8500_LDO_VAUX1        (1)
#define AB8500_LDO_VAUX2        (2)
#define AB8500_LDO_VTVOUT	(3)
#define AB8500_DCDC_VBUS	(4)
#define AB8500_LDO_VAUDIO	(5)
#define AB8500_LDO_VAMIC1	(6)
#define AB8500_LDO_VAMIC2	(7)
#define AB8500_LDO_VDMIC	(8)
#define AB8500_LDO_VINTCORE	(9)
#define AB8500_LDO_VAUX3	(10)

/* defines for regulator masks */
#define MASK_ENABLE		(0x1)
#define MASK_DISABLE		(0x0)

/* audio supplies */
#define MASK_LDO_VAUDIO		(0x2)
#define MASK_LDO_VDMIC 		(0x4)
#define MASK_LDO_VAMIC1 	(0x8)
#define MASK_LDO_VAMIC2		(0x10)

/* misc. supplies */
#define MASK_LDO_VTVOUT		(0x2)
#define MASK_LDO_VINTCORE	(0x4)

/* aux supplies */
#define MASK_LDO_VAUX1		(0x3)
#define MASK_LDO_VAUX2		(0xc)
#define MASK_LDO_VAUX3		(0x3)

#define MASK_LDO_VAUX1_SHIFT	(0x0)
#define MASK_LDO_VAUX2_SHIFT    (0x2)
#define MASK_LDO_VAUX3_SHIFT    (0x0)

/* regulator voltages */
#define VAUX1_VOLTAGE_2_5V	(0x8)
#define VAUX2_VOLTAGE_2_9V	(0xd)
#define VAUX3_VOLTAGE_2_9V	(0xd)


static int ab8500_ldo_enable(struct regulator_dev *rdev)
{
	int regulator_id, ret, val;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	if (!cpu_is_u8500v11()) {
		/* FIXME : as reads from regulator bank are not supported yet
		 *         enable both the VAUX1/2 by default. Add appropriate
		 *         read calls when I2C_APE support is available
		 */
		if ((regulator_id == AB8500_LDO_VAUX1) ||
				(regulator_id == AB8500_LDO_VAUX2))
			ab8500_write(AB8500_REGU_CTRL2,
					AB8500_REGU_VAUX12_REGU_REG, 0x5);
	}

	switch (regulator_id) {
	case AB8500_LDO_VAUX1:
		if (!cpu_is_u8500v11()) {
			ab8500_write(AB8500_REGU_CTRL2,
					AB8500_REGU_VAUX1_SEL_REG,
						VAUX1_VOLTAGE_2_5V);
			break;
		}
		val = ab8500_read(AB8500_REGU_CTRL2,
			AB8500_REGU_VAUX12_REGU_REG);
		val = val & ~MASK_LDO_VAUX1;
		val = val | (1 << MASK_LDO_VAUX1_SHIFT);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG, val);
		break;
	case AB8500_LDO_VAUX2:
		if (!cpu_is_u8500v11()) {
			ab8500_write(AB8500_REGU_CTRL2,
					AB8500_REGU_VAUX2_SEL_REG,
					VAUX2_VOLTAGE_2_9V);
			break;
		}
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG);
		val = val & ~MASK_LDO_VAUX2;
		val = val | (1 << MASK_LDO_VAUX2_SHIFT);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG, val);
		break;
	case AB8500_LDO_VAUX3:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_REGU_REG);
		val = val & ~MASK_LDO_VAUX3;
		val = val | (1 << MASK_LDO_VAUX1_SHIFT);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_REGU_REG, val);
		break;
	case AB8500_LDO_VTVOUT:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_MISC1_REG,
				(val | MASK_LDO_VTVOUT));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable TVOUT LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAUDIO:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
				(val | MASK_LDO_VAUDIO));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable TVOUT LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VDMIC:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
				(val | MASK_LDO_VDMIC));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable VDMIC LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAMIC1:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
				(val | MASK_LDO_VAMIC1));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable VAMIC1 LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAMIC2:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
				(val | MASK_LDO_VAMIC2));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable VAMIC2 LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VINTCORE:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_MISC1_REG,
				(val | MASK_LDO_VINTCORE));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable VINTCORE12 LDO\n");
			return -EINVAL;
		}
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}
	return 0;
}

static int ab8500_ldo_disable(struct regulator_dev *rdev)
{
	int regulator_id, ret, val;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	if (!cpu_is_u8500v11()) {
		/* FIXME : as reads from regulator bank are not supported yet
		 *         disable both the VAUX1/2 by default. Add appropriate
		 *         read calls when I2C_APE support is available
		 */
		if ((regulator_id == AB8500_LDO_VAUX1) ||
				(regulator_id == AB8500_LDO_VAUX2)) {
			ab8500_write(AB8500_REGU_CTRL2,
					AB8500_REGU_VAUX12_REGU_REG,
						MASK_DISABLE);
			return 0;
		}
	}

	switch (regulator_id) {
	case AB8500_LDO_VAUX1:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG,
					val & ~MASK_LDO_VAUX1);
		break;
	case AB8500_LDO_VAUX2:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG,
					val & ~MASK_LDO_VAUX2);
		break;
	case AB8500_LDO_VAUX3:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_REGU_REG);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_REGU_REG,
					val & ~MASK_LDO_VAUX3);
		break;
	case AB8500_LDO_VTVOUT:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_MISC1_REG,
					(val & ~MASK_LDO_VTVOUT));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable TVOUT LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VINTCORE:
		/* FIXME : allow voltage control using set_voltage helpers */
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_MISC1_REG,
					(val & ~MASK_LDO_VINTCORE));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable VINTCORE12 LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAUDIO:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
					(val & ~MASK_LDO_VAUDIO));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable VAUDIO LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VDMIC:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
					(val & ~MASK_LDO_VDMIC));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable VDMIC LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAMIC1:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
					(val & ~MASK_LDO_VAMIC1));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disble VAMIC1 LDO\n");
			return -EINVAL;
		}
		break;
	case AB8500_LDO_VAMIC2:
		val = ab8500_read(AB8500_REGU_CTRL1,
					AB8500_REGU_VAUDIO_SUPPLY_REG);
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG,
					(val & ~MASK_LDO_VAMIC2));
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable VAMIC2 LDO\n");
			return -EINVAL;
		}
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}
	return 0;
}

static int ab8500_ldo_is_enabled(struct regulator_dev *rdev)
{
	int regulator_id, val;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	switch (regulator_id) {
	case AB8500_LDO_VAUX1:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG);
		if (val & MASK_LDO_VAUX1)
			return true;
		break;
	case AB8500_LDO_VAUX2:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX12_REGU_REG);
		if (val & MASK_LDO_VAUX2)
			return true;
		break;
	case AB8500_LDO_VAUX3:
		val = ab8500_read(AB8500_REGU_CTRL2,
					AB8500_REGU_VRF1VAUX3_REGU_REG);
		if (val & MASK_LDO_VAUX3)
			return true;
		break;
	case AB8500_LDO_VTVOUT:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		if (val & MASK_LDO_VTVOUT)
			return true;
		break;
	case AB8500_LDO_VINTCORE:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		if (val & MASK_LDO_VINTCORE)
			return true;
		break;
	case AB8500_LDO_VAUDIO:
		val = ab8500_read(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG);
		if (val & MASK_LDO_VAUDIO)
			return true;
		break;
	case AB8500_LDO_VDMIC:
		val = ab8500_read(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG);
		if (val & MASK_LDO_VDMIC)
			return true;
		break;
	case AB8500_LDO_VAMIC1:
		val = ab8500_read(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG);
		if (val & MASK_LDO_VAMIC1)
			return true;
		break;
	case AB8500_LDO_VAMIC2:
		val = ab8500_read(AB8500_REGU_CTRL1,
				AB8500_REGU_VAUDIO_SUPPLY_REG);
		if (val & MASK_LDO_VAMIC2)
			return true;
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}
	return 0;
}

/*
 * regulator layout
 * @voltage: supported voltage
 * @regval: register value to be written
 */
static struct regulator_voltage {
	int voltage;
	int regval;
};

/* voltage table for VAUXn regulators */
static struct regulator_voltage vauxn_table[] = {
	{ .voltage = 1100000, .regval  = 0x0, },
	{ .voltage = 1200000, .regval  = 0x1, },
	{ .voltage = 1300000, .regval  = 0x2, },
	{ .voltage = 1400000, .regval  = 0x3, },
	{ .voltage = 1500000, .regval  = 0x4, },
	{ .voltage = 1800000, .regval  = 0x5, },
	{ .voltage = 1850000, .regval  = 0x6, },
	{ .voltage = 1900000, .regval  = 0x7, },
	{ .voltage = 2500000, .regval  = 0x8, },
	{ .voltage = 2650000, .regval  = 0x9, },
	{ .voltage = 2700000, .regval  = 0xa, },
	{ .voltage = 2750000, .regval  = 0xb, },
	{ .voltage = 2800000, .regval  = 0xc, },
	{ .voltage = 2900000, .regval  = 0xd, },
	{ .voltage = 3000000, .regval  = 0xe, },
	{ .voltage = 3300000, .regval  = 0xf, },
};

/* voltage table for VINTCORE12 regulator */
static struct regulator_voltage vintcore_table[] = {
	{ .voltage = 1200000, .regval  = 0x0, },
	{ .voltage = 1225000, .regval  = 0x1, },
	{ .voltage = 1250000, .regval  = 0x2, },
	{ .voltage = 1275000, .regval  = 0x3, },
	{ .voltage = 1300000, .regval  = 0x4, },
	{ .voltage = 1325000, .regval  = 0x5, },
	{ .voltage = 1350000, .regval  = 0x6, },
};

/*
 * get the supported voltage from the associated regulator table
 * and return the corresponding register masks.
 * In case of the un-supported voltage, return error
 */
static int ab8500_get_best_voltage(struct regulator_voltage *voltage_table,
				int table_len, int min_uV, int max_uV)
{
	int i;
	int bestmatch = INT_MAX;

	/* check the supported voltage */
	for (i = 0; i < table_len; i++) {
		if ((voltage_table[i].voltage >= min_uV) &&
		    (voltage_table[i].voltage <= max_uV) &&
		    (voltage_table[i].voltage < bestmatch))
			return i;
	}

	return -EINVAL;
}

static int ab8500_ldo_set_voltage(struct regulator_dev *rdev,
					int min_uV, int max_uV)
{
	int regulator_id, val, val1, i;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	switch (regulator_id) {
	case AB8500_LDO_VAUX1:
		val = ab8500_get_best_voltage(vauxn_table,
				ARRAY_SIZE(vauxn_table), min_uV, max_uV);
		if (val < 0) {
			dev_dbg(rdev_get_dev(rdev), "%dvolts not supported\n",
					max_uV);
			return -EINVAL;
		}
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX1_SEL_REG,
				vauxn_table[val].regval);
		break;
	case AB8500_LDO_VAUX2:
		val = ab8500_get_best_voltage(vauxn_table,
				ARRAY_SIZE(vauxn_table), min_uV, max_uV);
		if (val < 0) {
			dev_dbg(rdev_get_dev(rdev), "%dvolts not supported\n",
					max_uV);
			return -EINVAL;
		}
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX2_SEL_REG,
				vauxn_table[val].regval);
		break;
	case AB8500_LDO_VAUX3:
		val = ab8500_get_best_voltage(vauxn_table,
				ARRAY_SIZE(vauxn_table), min_uV, max_uV);
		if (val < 0) {
			dev_dbg(rdev_get_dev(rdev), "%dvolts not supported\n",
					max_uV);
			return -EINVAL;
		}
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_SEL_REG,
				vauxn_table[val].regval);
		break;
	case AB8500_LDO_VINTCORE:
		val = ab8500_get_best_voltage(vintcore_table,
				ARRAY_SIZE(vintcore_table), min_uV, max_uV);
		if (val < 0) {
			dev_dbg(rdev_get_dev(rdev), "%dvolts not supported\n",
					max_uV);
			return -EINVAL;
		}
		val1 = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		val1 = val | (vintcore_table[val].regval << 0x3);
		ab8500_write(AB8500_REGU_CTRL2,
				AB8500_REGU_MISC1_REG, val1);
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}

	return 0;
}

/* fixed typical voltages */
#define LDO_VTVOUT_VOLTAGE	(2000000) /* 2.0v typical */
#define LDO_VAUDIO_VOLTAGE	(2000000) /* 2.0v typical */
#define LDO_VDMIC_VOLTAGE	(1800000) /* 1.8V typical */
#define LDO_VAMIC1_VOLTAGE	(2050000) /* 2.05V typical */
#define LDO_VAMIC2_VOLTAGE	(2050000) /* 2.05V typical */

/* masks for reading the regulator voltages */
#define VAUXSEL_VOLTAGE_MASK	(0xf)
#define VINTCORE_VOLTAGE_MASK	(0x38)

static int ab8500_ldo_get_voltage(struct regulator_dev *rdev)
{
	int regulator_id, val;
	struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	/*
	 * for VAUXn/VINTCORE regulators, we read the configuration.
	 * for the rest, we return the typical voltage for the LDOs
	 */
	switch (regulator_id) {
	case AB8500_LDO_VAUX1:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX1_SEL_REG);
		return vauxn_table[val & VAUXSEL_VOLTAGE_MASK].voltage;
		break;
	case AB8500_LDO_VAUX2:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX2_SEL_REG);
		return vauxn_table[val & VAUXSEL_VOLTAGE_MASK].voltage;
		break;
	case AB8500_LDO_VAUX3:
		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VRF1VAUX3_SEL_REG);
		return vauxn_table[val & VAUXSEL_VOLTAGE_MASK].voltage;
		break;
	case AB8500_LDO_VTVOUT:
		return LDO_VTVOUT_VOLTAGE;
		break;
	case AB8500_LDO_VINTCORE:
		val = ab8500_read(AB8500_REGU_CTRL1, AB8500_REGU_MISC1_REG);
		return vintcore_table[val & VINTCORE_VOLTAGE_MASK].voltage;
		break;
	case AB8500_LDO_VAUDIO:
		return LDO_VAUDIO_VOLTAGE;
		break;
	case AB8500_LDO_VDMIC:
		return LDO_VDMIC_VOLTAGE;
		break;
	case AB8500_LDO_VAMIC1:
		return LDO_VAMIC1_VOLTAGE;
		break;
	case AB8500_LDO_VAMIC2:
		return LDO_VAMIC2_VOLTAGE;
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}

	return 0;
}

static struct regulator_ops ab8500_ldo_ops = {
	.enable			= ab8500_ldo_enable,
	.disable		= ab8500_ldo_disable,
	.is_enabled		= ab8500_ldo_is_enabled,
	.set_voltage		= ab8500_ldo_set_voltage,
	.get_voltage		= ab8500_ldo_get_voltage,
};

static int ab8500_dcdc_enable(struct regulator_dev *rdev)
{
	int regulator_id, ret;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	switch (regulator_id) {
	case AB8500_DCDC_VBUS:
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VUSB_CTRL_REG, MASK_ENABLE);
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot enable VBUS\n");
			return -EINVAL;
		}
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}
	return 0;
}

static int ab8500_dcdc_disable(struct regulator_dev *rdev)
{
	int regulator_id, ret;

	regulator_id = rdev_get_id(rdev);
	if (regulator_id >= AB8500_NUM_REGULATORS)
		return -EINVAL;

	switch (regulator_id) {
	case AB8500_DCDC_VBUS:
		ret = ab8500_write(AB8500_REGU_CTRL1,
				AB8500_REGU_VUSB_CTRL_REG, MASK_DISABLE);
		if (ret < 0) {
			dev_dbg(rdev_get_dev(rdev),
					"cannot disable VBUS\n");
			return -EINVAL;
		}
		break;
	default:
		dev_dbg(rdev_get_dev(rdev), "unknown regulator id\n");
		return -EINVAL;
	}
	return 0;
}


/* operations for DC-DC convertor supplies (VBUS, VSMPS1/2) */
static struct regulator_ops ab8500_dcdc_ops = {
	.enable		= ab8500_dcdc_enable,
	.disable	= ab8500_dcdc_disable,
};

static struct regulator_desc ab8500_desc[AB8500_NUM_REGULATORS] = {
	{
		.name   = "LDO-VAUX1",
		.id     = AB8500_LDO_VAUX1,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name  	= "LDO-VAUX2",
		.id 	= AB8500_LDO_VAUX2,
		.ops   	= &ab8500_ldo_ops,
		.type  	= REGULATOR_VOLTAGE,
		.owner 	= THIS_MODULE,
	},
	{
		.name   = "LDO-VTVOUT",
		.id     = AB8500_LDO_VTVOUT,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "DCDC-VBUS",
		.id     = AB8500_DCDC_VBUS,
		.ops    = &ab8500_dcdc_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VAUDIO",
		.id     = AB8500_LDO_VAUDIO,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VAMIC1",
		.id     = AB8500_LDO_VAMIC1,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VAMIC2",
		.id     = AB8500_LDO_VAMIC2,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VDMIC",
		.id     = AB8500_LDO_VDMIC,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VINTCORE",
		.id     = AB8500_LDO_VINTCORE,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},
	{
		.name   = "LDO-VAUX3",
		.id     = AB8500_LDO_VAUX3,
		.ops    = &ab8500_ldo_ops,
		.type   = REGULATOR_VOLTAGE,
		.owner  = THIS_MODULE,
	},

};

static int __devinit ab8500_regulator_probe(struct platform_device *pdev)
{
	struct regulator_dev *rdev;
	struct regulator_init_data *init_data = pdev->dev.platform_data;

	rdev = regulator_register(&ab8500_desc[pdev->id], &pdev->dev, init_data, NULL);
	if (IS_ERR(rdev)) {
		dev_dbg(&pdev->dev, "couldn't register regulator\n");
		return PTR_ERR(rdev);
	}

	platform_set_drvdata(pdev, rdev);

	return 0;
}

static int __devexit ab8500_regulator_remove(struct platform_device *pdev)
{
	struct regulator_dev *reg_dev = platform_get_drvdata(pdev);

	regulator_unregister(reg_dev);

	return 0;
}

static struct platform_driver ab8500_regulator_driver = {
	.driver = {
		.name = "ab8500-regulator",
	},
	.probe	= ab8500_regulator_probe,
	.remove = __devexit_p(ab8500_regulator_remove),
};

static int __init ab8500_regulator_init(void)
{
	int ret = 0;

	ret = platform_driver_register(&ab8500_regulator_driver);
	if (ret) {
		printk(KERN_INFO
		 "ab8500_regulator : platform_driver_register fails\n");
		return -ENODEV;
	}

	return 0;
}

static void __exit ab8500_regulator_exit(void)
{
	platform_driver_unregister(&ab8500_regulator_driver);
}

/* replacing subsys_call as we want amba devices to be "powered" on */
arch_initcall(ab8500_regulator_init);
module_exit(ab8500_regulator_exit);

MODULE_AUTHOR("STMicroelectronics/ST-Ericsson");
MODULE_DESCRIPTION("AB8500 Voltage Framework");
MODULE_LICENSE("GPL");