regulator: twl: fix twl6030 regulator is_enabled
[linux-3.10.git] / drivers / regulator / twl-regulator.c
1 /*
2  * twl-regulator.c -- support regulators in twl4030/twl6030 family chips
3  *
4  * Copyright (C) 2008 David Brownell
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/err.h>
15 #include <linux/delay.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/i2c/twl.h>
20
21
22 /*
23  * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
24  * USB OTG transceiver, an RTC, ADC, PWM, and lots more.  Some versions
25  * include an audio codec, battery charger, and more voltage regulators.
26  * These chips are often used in OMAP-based systems.
27  *
28  * This driver implements software-based resource control for various
29  * voltage regulators.  This is usually augmented with state machine
30  * based control.
31  */
32
33 struct twlreg_info {
34         /* start of regulator's PM_RECEIVER control register bank */
35         u8                      base;
36
37         /* twl resource ID, for resource control state machine */
38         u8                      id;
39
40         /* voltage in mV = table[VSEL]; table_len must be a power-of-two */
41         u8                      table_len;
42         const u16               *table;
43
44         /* regulator specific turn-on delay */
45         u16                     delay;
46
47         /* State REMAP default configuration */
48         u8                      remap;
49
50         /* chip constraints on regulator behavior */
51         u16                     min_mV;
52         u16                     max_mV;
53
54         /* used by regulator core */
55         struct regulator_desc   desc;
56 };
57
58
59 /* LDO control registers ... offset is from the base of its register bank.
60  * The first three registers of all power resource banks help hardware to
61  * manage the various resource groups.
62  */
63 /* Common offset in TWL4030/6030 */
64 #define VREG_GRP                0
65 /* TWL4030 register offsets */
66 #define VREG_TYPE               1
67 #define VREG_REMAP              2
68 #define VREG_DEDICATED          3       /* LDO control */
69 /* TWL6030 register offsets */
70 #define VREG_TRANS              1
71 #define VREG_STATE              2
72 #define VREG_VOLTAGE            3
73 /* TWL6030 Misc register offsets */
74 #define VREG_BC_ALL             1
75 #define VREG_BC_REF             2
76 #define VREG_BC_PROC            3
77 #define VREG_BC_CLK_RST         4
78
79 /* TWL6030 LDO register values for CFG_STATE */
80 #define TWL6030_CFG_STATE_OFF   0x00
81 #define TWL6030_CFG_STATE_ON    0x01
82 #define TWL6030_CFG_STATE_GRP_SHIFT     5
83 #define TWL6030_CFG_STATE_APP_SHIFT     2
84 #define TWL6030_CFG_STATE_APP_MASK      (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
85 #define TWL6030_CFG_STATE_APP(v)        (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
86                                                 TWL6030_CFG_STATE_APP_SHIFT)
87
88 static inline int
89 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
90 {
91         u8 value;
92         int status;
93
94         status = twl_i2c_read_u8(slave_subgp,
95                         &value, info->base + offset);
96         return (status < 0) ? status : value;
97 }
98
99 static inline int
100 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
101                                                  u8 value)
102 {
103         return twl_i2c_write_u8(slave_subgp,
104                         value, info->base + offset);
105 }
106
107 /*----------------------------------------------------------------------*/
108
109 /* generic power resource operations, which work on all regulators */
110
111 static int twlreg_grp(struct regulator_dev *rdev)
112 {
113         return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
114                                                                  VREG_GRP);
115 }
116
117 /*
118  * Enable/disable regulators by joining/leaving the P1 (processor) group.
119  * We assume nobody else is updating the DEV_GRP registers.
120  */
121 /* definition for 4030 family */
122 #define P3_GRP_4030     BIT(7)          /* "peripherals" */
123 #define P2_GRP_4030     BIT(6)          /* secondary processor, modem, etc */
124 #define P1_GRP_4030     BIT(5)          /* CPU/Linux */
125 /* definition for 6030 family */
126 #define P3_GRP_6030     BIT(2)          /* secondary processor, modem, etc */
127 #define P2_GRP_6030     BIT(1)          /* "peripherals" */
128 #define P1_GRP_6030     BIT(0)          /* CPU/Linux */
129
130 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
131 {
132         int     state = twlreg_grp(rdev);
133
134         if (state < 0)
135                 return state;
136
137         return state & P1_GRP_4030;
138 }
139
140 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
141 {
142         struct twlreg_info      *info = rdev_get_drvdata(rdev);
143         int                     grp, val;
144
145         grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
146         if (grp < 0)
147                 return grp;
148
149         grp &= P1_GRP_6030;
150
151         val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
152         val = TWL6030_CFG_STATE_APP(val);
153
154         return grp && (val == TWL6030_CFG_STATE_ON);
155 }
156
157 static int twlreg_enable(struct regulator_dev *rdev)
158 {
159         struct twlreg_info      *info = rdev_get_drvdata(rdev);
160         int                     grp;
161         int                     ret;
162
163         grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
164         if (grp < 0)
165                 return grp;
166
167         if (twl_class_is_4030())
168                 grp |= P1_GRP_4030;
169         else
170                 grp |= P1_GRP_6030;
171
172         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
173
174         if (!ret && twl_class_is_6030())
175                 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
176                                 grp << TWL6030_CFG_STATE_GRP_SHIFT |
177                                 TWL6030_CFG_STATE_ON);
178
179         udelay(info->delay);
180
181         return ret;
182 }
183
184 static int twlreg_disable(struct regulator_dev *rdev)
185 {
186         struct twlreg_info      *info = rdev_get_drvdata(rdev);
187         int                     grp;
188         int                     ret;
189
190         grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
191         if (grp < 0)
192                 return grp;
193
194         /* For 6030, set the off state for all grps enabled */
195         if (twl_class_is_6030()) {
196                 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
197                         (grp & (P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030)) <<
198                                 TWL6030_CFG_STATE_GRP_SHIFT |
199                         TWL6030_CFG_STATE_OFF);
200                 if (ret)
201                         return ret;
202         }
203
204         if (twl_class_is_4030())
205                 grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
206         else
207                 grp &= ~(P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030);
208
209         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
210
211         /* Next, associate cleared grp in state register */
212         if (!ret && twl_class_is_6030())
213                 ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
214                                 grp << TWL6030_CFG_STATE_GRP_SHIFT |
215                                 TWL6030_CFG_STATE_OFF);
216
217         return ret;
218 }
219
220 static int twlreg_get_status(struct regulator_dev *rdev)
221 {
222         int     state = twlreg_grp(rdev);
223
224         if (twl_class_is_6030())
225                 return 0; /* FIXME return for 6030 regulator */
226
227         if (state < 0)
228                 return state;
229         state &= 0x0f;
230
231         /* assume state != WARM_RESET; we'd not be running...  */
232         if (!state)
233                 return REGULATOR_STATUS_OFF;
234         return (state & BIT(3))
235                 ? REGULATOR_STATUS_NORMAL
236                 : REGULATOR_STATUS_STANDBY;
237 }
238
239 static int twlreg_set_mode(struct regulator_dev *rdev, unsigned mode)
240 {
241         struct twlreg_info      *info = rdev_get_drvdata(rdev);
242         unsigned                message;
243         int                     status;
244
245         if (twl_class_is_6030())
246                 return 0; /* FIXME return for 6030 regulator */
247
248         /* We can only set the mode through state machine commands... */
249         switch (mode) {
250         case REGULATOR_MODE_NORMAL:
251                 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
252                 break;
253         case REGULATOR_MODE_STANDBY:
254                 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
255                 break;
256         default:
257                 return -EINVAL;
258         }
259
260         /* Ensure the resource is associated with some group */
261         status = twlreg_grp(rdev);
262         if (status < 0)
263                 return status;
264         if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
265                 return -EACCES;
266
267         status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
268                         message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
269         if (status < 0)
270                 return status;
271
272         return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
273                         message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
274 }
275
276 /*----------------------------------------------------------------------*/
277
278 /*
279  * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
280  * select field in its control register.   We use tables indexed by VSEL
281  * to record voltages in milliVolts.  (Accuracy is about three percent.)
282  *
283  * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
284  * currently handled by listing two slightly different VAUX2 regulators,
285  * only one of which will be configured.
286  *
287  * VSEL values documented as "TI cannot support these values" are flagged
288  * in these tables as UNSUP() values; we normally won't assign them.
289  *
290  * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
291  * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
292  */
293 #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
294 #define UNSUP_MASK      0x0000
295 #else
296 #define UNSUP_MASK      0x8000
297 #endif
298
299 #define UNSUP(x)        (UNSUP_MASK | (x))
300 #define IS_UNSUP(x)     (UNSUP_MASK & (x))
301 #define LDO_MV(x)       (~UNSUP_MASK & (x))
302
303
304 static const u16 VAUX1_VSEL_table[] = {
305         UNSUP(1500), UNSUP(1800), 2500, 2800,
306         3000, 3000, 3000, 3000,
307 };
308 static const u16 VAUX2_4030_VSEL_table[] = {
309         UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
310         1500, 1800, UNSUP(1850), 2500,
311         UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
312         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
313 };
314 static const u16 VAUX2_VSEL_table[] = {
315         1700, 1700, 1900, 1300,
316         1500, 1800, 2000, 2500,
317         2100, 2800, 2200, 2300,
318         2400, 2400, 2400, 2400,
319 };
320 static const u16 VAUX3_VSEL_table[] = {
321         1500, 1800, 2500, 2800,
322         3000, 3000, 3000, 3000,
323 };
324 static const u16 VAUX4_VSEL_table[] = {
325         700, 1000, 1200, UNSUP(1300),
326         1500, 1800, UNSUP(1850), 2500,
327         UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
328         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
329 };
330 static const u16 VMMC1_VSEL_table[] = {
331         1850, 2850, 3000, 3150,
332 };
333 static const u16 VMMC2_VSEL_table[] = {
334         UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
335         UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
336         2600, 2800, 2850, 3000,
337         3150, 3150, 3150, 3150,
338 };
339 static const u16 VPLL1_VSEL_table[] = {
340         1000, 1200, 1300, 1800,
341         UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
342 };
343 static const u16 VPLL2_VSEL_table[] = {
344         700, 1000, 1200, 1300,
345         UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
346         UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
347         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
348 };
349 static const u16 VSIM_VSEL_table[] = {
350         UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
351         2800, 3000, 3000, 3000,
352 };
353 static const u16 VDAC_VSEL_table[] = {
354         1200, 1300, 1800, 1800,
355 };
356 static const u16 VDD1_VSEL_table[] = {
357         800, 1450,
358 };
359 static const u16 VDD2_VSEL_table[] = {
360         800, 1450, 1500,
361 };
362 static const u16 VIO_VSEL_table[] = {
363         1800, 1850,
364 };
365 static const u16 VINTANA2_VSEL_table[] = {
366         2500, 2750,
367 };
368
369 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
370 {
371         struct twlreg_info      *info = rdev_get_drvdata(rdev);
372         int                     mV = info->table[index];
373
374         return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
375 }
376
377 static int
378 twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
379                        unsigned *selector)
380 {
381         struct twlreg_info      *info = rdev_get_drvdata(rdev);
382         int                     vsel;
383
384         for (vsel = 0; vsel < info->table_len; vsel++) {
385                 int mV = info->table[vsel];
386                 int uV;
387
388                 if (IS_UNSUP(mV))
389                         continue;
390                 uV = LDO_MV(mV) * 1000;
391
392                 /* REVISIT for VAUX2, first match may not be best/lowest */
393
394                 /* use the first in-range value */
395                 if (min_uV <= uV && uV <= max_uV) {
396                         *selector = vsel;
397                         return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
398                                                         VREG_VOLTAGE, vsel);
399                 }
400         }
401
402         return -EDOM;
403 }
404
405 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
406 {
407         struct twlreg_info      *info = rdev_get_drvdata(rdev);
408         int             vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
409                                                                 VREG_VOLTAGE);
410
411         if (vsel < 0)
412                 return vsel;
413
414         vsel &= info->table_len - 1;
415         return LDO_MV(info->table[vsel]) * 1000;
416 }
417
418 static struct regulator_ops twl4030ldo_ops = {
419         .list_voltage   = twl4030ldo_list_voltage,
420
421         .set_voltage    = twl4030ldo_set_voltage,
422         .get_voltage    = twl4030ldo_get_voltage,
423
424         .enable         = twlreg_enable,
425         .disable        = twlreg_disable,
426         .is_enabled     = twl4030reg_is_enabled,
427
428         .set_mode       = twlreg_set_mode,
429
430         .get_status     = twlreg_get_status,
431 };
432
433 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
434 {
435         struct twlreg_info      *info = rdev_get_drvdata(rdev);
436
437         return ((info->min_mV + (index * 100)) * 1000);
438 }
439
440 static int
441 twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
442                        unsigned *selector)
443 {
444         struct twlreg_info      *info = rdev_get_drvdata(rdev);
445         int                     vsel;
446
447         if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
448                 return -EDOM;
449
450         /*
451          * Use the below formula to calculate vsel
452          * mV = 1000mv + 100mv * (vsel - 1)
453          */
454         vsel = (min_uV/1000 - 1000)/100 + 1;
455         *selector = vsel;
456         return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
457
458 }
459
460 static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
461 {
462         struct twlreg_info      *info = rdev_get_drvdata(rdev);
463         int             vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
464                                                                 VREG_VOLTAGE);
465
466         if (vsel < 0)
467                 return vsel;
468
469         /*
470          * Use the below formula to calculate vsel
471          * mV = 1000mv + 100mv * (vsel - 1)
472          */
473         return (1000 + (100 * (vsel - 1))) * 1000;
474 }
475
476 static struct regulator_ops twl6030ldo_ops = {
477         .list_voltage   = twl6030ldo_list_voltage,
478
479         .set_voltage    = twl6030ldo_set_voltage,
480         .get_voltage    = twl6030ldo_get_voltage,
481
482         .enable         = twlreg_enable,
483         .disable        = twlreg_disable,
484         .is_enabled     = twl6030reg_is_enabled,
485
486         .set_mode       = twlreg_set_mode,
487
488         .get_status     = twlreg_get_status,
489 };
490
491 /*----------------------------------------------------------------------*/
492
493 /*
494  * Fixed voltage LDOs don't have a VSEL field to update.
495  */
496 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
497 {
498         struct twlreg_info      *info = rdev_get_drvdata(rdev);
499
500         return info->min_mV * 1000;
501 }
502
503 static int twlfixed_get_voltage(struct regulator_dev *rdev)
504 {
505         struct twlreg_info      *info = rdev_get_drvdata(rdev);
506
507         return info->min_mV * 1000;
508 }
509
510 static struct regulator_ops twl4030fixed_ops = {
511         .list_voltage   = twlfixed_list_voltage,
512
513         .get_voltage    = twlfixed_get_voltage,
514
515         .enable         = twlreg_enable,
516         .disable        = twlreg_disable,
517         .is_enabled     = twl4030reg_is_enabled,
518
519         .set_mode       = twlreg_set_mode,
520
521         .get_status     = twlreg_get_status,
522 };
523
524 static struct regulator_ops twl6030fixed_ops = {
525         .list_voltage   = twlfixed_list_voltage,
526
527         .get_voltage    = twlfixed_get_voltage,
528
529         .enable         = twlreg_enable,
530         .disable        = twlreg_disable,
531         .is_enabled     = twl6030reg_is_enabled,
532
533         .set_mode       = twlreg_set_mode,
534
535         .get_status     = twlreg_get_status,
536 };
537
538 static struct regulator_ops twl6030_fixed_resource = {
539         .enable         = twlreg_enable,
540         .disable        = twlreg_disable,
541         .is_enabled     = twl6030reg_is_enabled,
542         .get_status     = twlreg_get_status,
543 };
544
545 /*----------------------------------------------------------------------*/
546
547 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
548                         remap_conf) \
549                 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
550                         remap_conf, TWL4030, twl4030fixed_ops)
551 #define TWL6030_FIXED_LDO(label, offset, mVolts, num, turnon_delay) \
552                 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
553                         0x0, TWL6030, twl6030fixed_ops)
554
555 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
556         .base = offset, \
557         .id = num, \
558         .table_len = ARRAY_SIZE(label##_VSEL_table), \
559         .table = label##_VSEL_table, \
560         .delay = turnon_delay, \
561         .remap = remap_conf, \
562         .desc = { \
563                 .name = #label, \
564                 .id = TWL4030_REG_##label, \
565                 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
566                 .ops = &twl4030ldo_ops, \
567                 .type = REGULATOR_VOLTAGE, \
568                 .owner = THIS_MODULE, \
569                 }, \
570         }
571
572 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts, num) { \
573         .base = offset, \
574         .id = num, \
575         .min_mV = min_mVolts, \
576         .max_mV = max_mVolts, \
577         .desc = { \
578                 .name = #label, \
579                 .id = TWL6030_REG_##label, \
580                 .n_voltages = (max_mVolts - min_mVolts)/100, \
581                 .ops = &twl6030ldo_ops, \
582                 .type = REGULATOR_VOLTAGE, \
583                 .owner = THIS_MODULE, \
584                 }, \
585         }
586
587
588 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
589                 family, operations) { \
590         .base = offset, \
591         .id = num, \
592         .min_mV = mVolts, \
593         .delay = turnon_delay, \
594         .remap = remap_conf, \
595         .desc = { \
596                 .name = #label, \
597                 .id = family##_REG_##label, \
598                 .n_voltages = 1, \
599                 .ops = &operations, \
600                 .type = REGULATOR_VOLTAGE, \
601                 .owner = THIS_MODULE, \
602                 }, \
603         }
604
605 #define TWL6030_FIXED_RESOURCE(label, offset, num, turnon_delay) { \
606         .base = offset, \
607         .id = num, \
608         .delay = turnon_delay, \
609         .desc = { \
610                 .name = #label, \
611                 .id = TWL6030_REG_##label, \
612                 .ops = &twl6030_fixed_resource, \
613                 .type = REGULATOR_VOLTAGE, \
614                 .owner = THIS_MODULE, \
615                 }, \
616         }
617
618 /*
619  * We list regulators here if systems need some level of
620  * software control over them after boot.
621  */
622 static struct twlreg_info twl_regs[] = {
623         TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
624         TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
625         TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
626         TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
627         TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
628         TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
629         TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
630         TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
631         TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
632         TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
633         TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
634         TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
635         TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
636         TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
637         TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
638         TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
639         TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
640         TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
641         TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
642         TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
643         /* VUSBCP is managed *only* by the USB subchip */
644
645         /* 6030 REG with base as PMC Slave Misc : 0x0030 */
646         /* Turnon-delay and remap configuration values for 6030 are not
647            verified since the specification is not public */
648         TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300, 1),
649         TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300, 2),
650         TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300, 3),
651         TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300, 4),
652         TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300, 5),
653         TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300, 7),
654         TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0),
655         TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0),
656         TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0),
657         TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0),
658         TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 48, 0),
659 };
660
661 static int __devinit twlreg_probe(struct platform_device *pdev)
662 {
663         int                             i;
664         struct twlreg_info              *info;
665         struct regulator_init_data      *initdata;
666         struct regulation_constraints   *c;
667         struct regulator_dev            *rdev;
668
669         for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
670                 if (twl_regs[i].desc.id != pdev->id)
671                         continue;
672                 info = twl_regs + i;
673                 break;
674         }
675         if (!info)
676                 return -ENODEV;
677
678         initdata = pdev->dev.platform_data;
679         if (!initdata)
680                 return -EINVAL;
681
682         /* Constrain board-specific capabilities according to what
683          * this driver and the chip itself can actually do.
684          */
685         c = &initdata->constraints;
686         c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
687         c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
688                                 | REGULATOR_CHANGE_MODE
689                                 | REGULATOR_CHANGE_STATUS;
690         switch (pdev->id) {
691         case TWL4030_REG_VIO:
692         case TWL4030_REG_VDD1:
693         case TWL4030_REG_VDD2:
694         case TWL4030_REG_VPLL1:
695         case TWL4030_REG_VINTANA1:
696         case TWL4030_REG_VINTANA2:
697         case TWL4030_REG_VINTDIG:
698                 c->always_on = true;
699                 break;
700         default:
701                 break;
702         }
703
704         rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
705         if (IS_ERR(rdev)) {
706                 dev_err(&pdev->dev, "can't register %s, %ld\n",
707                                 info->desc.name, PTR_ERR(rdev));
708                 return PTR_ERR(rdev);
709         }
710         platform_set_drvdata(pdev, rdev);
711
712         if (twl_class_is_4030())
713                 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
714                                                 info->remap);
715
716         /* NOTE:  many regulators support short-circuit IRQs (presentable
717          * as REGULATOR_OVER_CURRENT notifications?) configured via:
718          *  - SC_CONFIG
719          *  - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
720          *  - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
721          *  - IT_CONFIG
722          */
723
724         return 0;
725 }
726
727 static int __devexit twlreg_remove(struct platform_device *pdev)
728 {
729         regulator_unregister(platform_get_drvdata(pdev));
730         return 0;
731 }
732
733 MODULE_ALIAS("platform:twl_reg");
734
735 static struct platform_driver twlreg_driver = {
736         .probe          = twlreg_probe,
737         .remove         = __devexit_p(twlreg_remove),
738         /* NOTE: short name, to work around driver model truncation of
739          * "twl_regulator.12" (and friends) to "twl_regulator.1".
740          */
741         .driver.name    = "twl_reg",
742         .driver.owner   = THIS_MODULE,
743 };
744
745 static int __init twlreg_init(void)
746 {
747         return platform_driver_register(&twlreg_driver);
748 }
749 subsys_initcall(twlreg_init);
750
751 static void __exit twlreg_exit(void)
752 {
753         platform_driver_unregister(&twlreg_driver);
754 }
755 module_exit(twlreg_exit)
756
757 MODULE_DESCRIPTION("TWL regulator driver");
758 MODULE_LICENSE("GPL");