USB: do not call disconnect callback func in dwc_otg_hcd_enable
[firefly-linux-kernel-4.4.55.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         u8                      flags;
55
56         /* used by regulator core */
57         struct regulator_desc   desc;
58
59         /* chip specific features */
60         unsigned long           features;
61 };
62
63
64 /* LDO control registers ... offset is from the base of its register bank.
65  * The first three registers of all power resource banks help hardware to
66  * manage the various resource groups.
67  */
68 /* Common offset in TWL4030/6030 */
69 #define VREG_GRP                0
70 /* TWL4030 register offsets */
71 #define VREG_TYPE               1
72 #define VREG_REMAP              2
73 #define VREG_DEDICATED          3       /* LDO control */
74 /* TWL6030 register offsets */
75 #define VREG_TRANS              1
76 #define VREG_STATE              2
77 #define VREG_VOLTAGE            3
78 #define VREG_VOLTAGE_SMPS       4
79 #define VREG_VOLTAGE_DVS_SMPS 3      //add
80 /* TWL6030 Misc register offsets */
81 #define VREG_BC_ALL             1
82 #define VREG_BC_REF             2
83 #define VREG_BC_PROC            3
84 #define VREG_BC_CLK_RST         4
85
86 /* TWL6030 LDO register values for CFG_TRANS */
87 #define TWL6030_CFG_TRANS_STATE_MASK    0x03
88 #define TWL6030_CFG_TRANS_STATE_OFF     0x00
89 /*
90  * Auto means the following:
91  * SMPS:        AUTO(PWM/PFM)
92  * LDO:         AMS(SLP/ACT)
93  * resource:    ON
94  */
95 #define TWL6030_CFG_TRANS_STATE_AUTO    0x01
96 #define TWL6030_CFG_TRANS_SLEEP_SHIFT   2
97
98 /* TWL6030 LDO register values for CFG_STATE */
99 #define TWL6030_CFG_STATE_OFF   0x00
100 #define TWL6030_CFG_STATE_ON    0x01
101 #define TWL6030_CFG_STATE_OFF2  0x02
102 #define TWL6030_CFG_STATE_SLEEP 0x03
103 #define TWL6030_CFG_STATE_GRP_SHIFT     5
104 #define TWL6030_CFG_STATE_APP_SHIFT     2
105 #define TWL6030_CFG_STATE_MASK          0x03
106 #define TWL6030_CFG_STATE_APP_MASK      (TWL6030_CFG_STATE_MASK << \
107                                                 TWL6030_CFG_STATE_APP_SHIFT)
108 #define TWL6030_CFG_STATE_APP(v)        (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
109                                                 TWL6030_CFG_STATE_APP_SHIFT)
110
111 /* Flags for SMPS Voltage reading */
112 #define SMPS_OFFSET_EN          BIT(0)
113 #define SMPS_EXTENDED_EN        BIT(1)
114
115 /* twl6032 SMPS EPROM values */
116 #define TWL6030_SMPS_OFFSET             0xB0
117 #define TWL6030_SMPS_MULT               0xB3
118 #define SMPS_MULTOFFSET_SMPS4   BIT(0)
119 #define SMPS_MULTOFFSET_VIO     BIT(1)
120 #define SMPS_MULTOFFSET_SMPS3   BIT(6)
121
122
123
124 /* TWL6030 VUSB supplemental config registers */
125 #define TWL6030_MISC2           0xE5
126 #define TWL6030_CFG_LDO_PD2     0xF5
127
128 /*
129  * TWL603X SMPS has 6 bits xxxx_CFG_VOLTAGE.VSEL[5:0] to configure voltages and
130  * each bit combination corresponds to a particular voltage (value 63 is
131  * reserved).
132  */
133 #define TWL603X_SMPS_VSEL_MASK  0x3F
134 #define TWL603X_SMPS_NUMBER_VOLTAGES TWL603X_SMPS_VSEL_MASK
135
136 static inline int
137 twlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset)
138 {
139         u8 value;
140         int status;
141         status = twl_i2c_read_u8(slave_subgp,
142                         &value, info->base + offset);
143         return (status < 0) ? status : value;
144 }
145
146 static inline int
147 twlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset,
148                                                  u8 value)
149 {
150         return twl_i2c_write_u8(slave_subgp,
151                         value, info->base + offset);
152 }
153
154 /*----------------------------------------------------------------------*/
155
156 /* generic power resource operations, which work on all regulators */
157
158 static int twlreg_grp(struct regulator_dev *rdev)
159 {
160         return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER,
161                                                                  VREG_GRP);
162 }
163
164 /*
165  * Enable/disable regulators by joining/leaving the P1 (processor) group.
166  * We assume nobody else is updating the DEV_GRP registers.
167  */
168 /* definition for 4030 family */
169 #define P3_GRP_4030     BIT(7)          /* "peripherals" */
170 #define P2_GRP_4030     BIT(6)          /* secondary processor, modem, etc */
171 #define P1_GRP_4030     BIT(5)          /* CPU/Linux */
172 /* definition for 6030 family */
173 #define P3_GRP_6030     BIT(2)          /* secondary processor, modem, etc */
174 #define P2_GRP_6030     BIT(1)          /* "peripherals" */
175 #define P1_GRP_6030     BIT(0)          /* CPU/Linux */
176
177 static int twl4030reg_is_enabled(struct regulator_dev *rdev)
178 {
179         int     state = twlreg_grp(rdev);
180
181         if (state < 0)
182                 return state;
183
184         return state & P1_GRP_4030;
185 }
186
187 static int twl6030reg_is_enabled(struct regulator_dev *rdev)
188 {
189         struct twlreg_info      *info = rdev_get_drvdata(rdev);
190         int                     grp = 0, val;
191
192         if (!(info->features & TWL6032_SUBCLASS)) {
193                 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
194                 if (grp < 0)
195                         return grp;
196
197                 grp &= P1_GRP_6030;
198                 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
199                 val = TWL6030_CFG_STATE_APP(val);
200         } else {
201                 val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
202                 val &= TWL6030_CFG_STATE_MASK;
203                 grp = 1;
204         }
205
206         return grp && (val == TWL6030_CFG_STATE_ON);
207 }
208
209 static int twl6030reg_set_trans_state(struct regulator_dev *rdev,
210                                       u8 shift, u8 val)
211 {
212         struct twlreg_info      *info = rdev_get_drvdata(rdev);
213         int                     rval;
214         u8                      mask;
215
216         /* Read CFG_TRANS register of TWL6030 */
217         rval = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_TRANS);
218
219         if (rval < 0)
220                 return rval;
221
222         mask = TWL6030_CFG_TRANS_STATE_MASK << shift;
223         val = (val << shift) & mask;
224
225         /* If value is already set, no need to write to reg */
226         if (val == (rval & mask))
227                 return 0;
228
229         rval &= ~mask;
230         rval |= val;
231
232         return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_TRANS, rval);
233 }
234
235 static int twl4030reg_enable(struct regulator_dev *rdev)
236 {
237         struct twlreg_info      *info = rdev_get_drvdata(rdev);
238         int                     grp;
239         int                     ret;
240
241         grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
242         if (grp < 0)
243                 return grp;
244
245         grp |= P1_GRP_4030;
246
247         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
248
249         udelay(info->delay);
250
251         return ret;
252 }
253
254 static int twl6030reg_enable(struct regulator_dev *rdev)
255 {
256         struct twlreg_info      *info = rdev_get_drvdata(rdev);
257         int                     grp = 0;
258         int                     ret;
259
260         if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
261                 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
262         if (grp < 0)
263                 return grp;
264
265         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
266                         grp << TWL6030_CFG_STATE_GRP_SHIFT |
267                         TWL6030_CFG_STATE_ON);
268         /*
269          * Ensure it stays in Auto mode when we enter suspend state.
270          * (TWL6030 in sleep mode).
271          */
272         if (!ret)
273                 ret = twl6030reg_set_trans_state(rdev,
274                                 TWL6030_CFG_TRANS_SLEEP_SHIFT,
275                                 TWL6030_CFG_TRANS_STATE_AUTO);
276         udelay(info->delay);
277
278         return ret;
279 }
280
281 static int twl4030reg_disable(struct regulator_dev *rdev)
282 {
283         struct twlreg_info      *info = rdev_get_drvdata(rdev);
284         int                     grp;
285         int                     ret;
286
287         grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
288         if (grp < 0)
289                 return grp;
290
291         grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030);
292
293         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp);
294
295         return ret;
296 }
297
298 static int twl6030reg_disable(struct regulator_dev *rdev)
299 {
300         struct twlreg_info      *info = rdev_get_drvdata(rdev);
301         int                     grp = 0;
302         int                     ret;
303
304         if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
305                 grp = P1_GRP_6030 | P2_GRP_6030 | P3_GRP_6030;
306
307         /* For 6030, set the off state for all grps enabled */
308         ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE,
309                         (grp) << TWL6030_CFG_STATE_GRP_SHIFT |
310                         TWL6030_CFG_STATE_OFF);
311
312         /* Ensure it remains OFF when we enter suspend (TWL6030 in sleep). */
313         if (!ret)
314                 ret = twl6030reg_set_trans_state(rdev,
315                                 TWL6030_CFG_TRANS_SLEEP_SHIFT,
316                                 TWL6030_CFG_TRANS_STATE_OFF);
317         return ret;
318 }
319
320 static int twl4030reg_get_status(struct regulator_dev *rdev)
321 {
322         int     state = twlreg_grp(rdev);
323
324         if (state < 0)
325                 return state;
326         state &= 0x0f;
327
328         /* assume state != WARM_RESET; we'd not be running...  */
329         if (!state)
330                 return REGULATOR_STATUS_OFF;
331         return (state & BIT(3))
332                 ? REGULATOR_STATUS_NORMAL
333                 : REGULATOR_STATUS_STANDBY;
334 }
335
336 static int twl6030reg_get_status(struct regulator_dev *rdev)
337 {
338         struct twlreg_info      *info = rdev_get_drvdata(rdev);
339         int                     val;
340
341         val = twlreg_grp(rdev);
342         if (val < 0)
343                 return val;
344
345         val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE);
346
347         if (info->features & TWL6032_SUBCLASS)
348                 val &= TWL6030_CFG_STATE_MASK;
349         else
350                 val = TWL6030_CFG_STATE_APP(val);
351
352         switch (val) {
353         case TWL6030_CFG_STATE_ON:
354                 return REGULATOR_STATUS_NORMAL;
355
356         case TWL6030_CFG_STATE_SLEEP:
357                 return REGULATOR_STATUS_STANDBY;
358
359         case TWL6030_CFG_STATE_OFF:
360         case TWL6030_CFG_STATE_OFF2:
361         default:
362                 break;
363         }
364
365         return REGULATOR_STATUS_OFF;
366 }
367
368 static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
369 {
370         struct twlreg_info      *info = rdev_get_drvdata(rdev);
371         unsigned                message;
372         int                     status;
373
374         /* We can only set the mode through state machine commands... */
375         switch (mode) {
376         case REGULATOR_MODE_NORMAL:
377                 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE);
378                 break;
379         case REGULATOR_MODE_STANDBY:
380                 message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP);
381                 break;
382         default:
383                 return -EINVAL;
384         }
385
386         /* Ensure the resource is associated with some group */
387         status = twlreg_grp(rdev);
388         if (status < 0)
389                 return status;
390         if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
391                 return -EACCES;
392
393         status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
394                         message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
395         if (status < 0)
396                 return status;
397
398         return twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
399                         message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB);
400 }
401
402 static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
403 {
404         struct twlreg_info      *info = rdev_get_drvdata(rdev);
405         int grp = 0;
406         int val;
407
408         if (!(twl_class_is_6030() && (info->features & TWL6032_SUBCLASS)))
409                 grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP);
410
411         if (grp < 0)
412                 return grp;
413
414         /* Compose the state register settings */
415         val = grp << TWL6030_CFG_STATE_GRP_SHIFT;
416         /* We can only set the mode through state machine commands... */
417         switch (mode) {
418         case REGULATOR_MODE_NORMAL:
419                 val |= TWL6030_CFG_STATE_ON;
420                 break;
421         case REGULATOR_MODE_STANDBY:
422                 val |= TWL6030_CFG_STATE_SLEEP;
423                 break;
424
425         default:
426                 return -EINVAL;
427         }
428
429         return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, val);
430 }
431
432 static int twl6030ldo_suspend_enable(struct regulator_dev *rdev)
433 {
434         return twl6030reg_set_trans_state(rdev, TWL6030_CFG_TRANS_SLEEP_SHIFT,
435                                         TWL6030_CFG_TRANS_STATE_AUTO);
436 }
437
438 static int twl6030ldo_suspend_disable(struct regulator_dev *rdev)
439 {
440         return twl6030reg_set_trans_state(rdev, TWL6030_CFG_TRANS_SLEEP_SHIFT,
441                                         TWL6030_CFG_TRANS_STATE_OFF);
442 }
443
444 /*----------------------------------------------------------------------*/
445
446 /*
447  * Support for adjustable-voltage LDOs uses a four bit (or less) voltage
448  * select field in its control register.   We use tables indexed by VSEL
449  * to record voltages in milliVolts.  (Accuracy is about three percent.)
450  *
451  * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon;
452  * currently handled by listing two slightly different VAUX2 regulators,
453  * only one of which will be configured.
454  *
455  * VSEL values documented as "TI cannot support these values" are flagged
456  * in these tables as UNSUP() values; we normally won't assign them.
457  *
458  * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported.
459  * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting.
460  */
461 #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED
462 #define UNSUP_MASK      0x0000
463 #else
464 #define UNSUP_MASK      0x8000
465 #endif
466
467 #define UNSUP(x)        (UNSUP_MASK | (x))
468 #define IS_UNSUP(x)     (UNSUP_MASK & (x))
469 #define LDO_MV(x)       (~UNSUP_MASK & (x))
470
471
472 static const u16 VAUX1_VSEL_table[] = {
473         UNSUP(1500), UNSUP(1800), 2500, 2800,
474         3000, 3000, 3000, 3000,
475 };
476 static const u16 VAUX2_4030_VSEL_table[] = {
477         UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300,
478         1500, 1800, UNSUP(1850), 2500,
479         UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
480         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
481 };
482 static const u16 VAUX2_VSEL_table[] = {
483         1700, 1700, 1900, 1300,
484         1500, 1800, 2000, 2500,
485         2100, 2800, 2200, 2300,
486         2400, 2400, 2400, 2400,
487 };
488 static const u16 VAUX3_VSEL_table[] = {
489         1500, 1800, 2500, 2800,
490         3000, 3000, 3000, 3000,
491 };
492 static const u16 VAUX4_VSEL_table[] = {
493         700, 1000, 1200, UNSUP(1300),
494         1500, 1800, UNSUP(1850), 2500,
495         UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000),
496         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
497 };
498 static const u16 VMMC1_VSEL_table[] = {
499         1850, 2850, 3000, 3150,
500 };
501 static const u16 VMMC2_VSEL_table[] = {
502         UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300),
503         UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500),
504         2600, 2800, 2850, 3000,
505         3150, 3150, 3150, 3150,
506 };
507 static const u16 VPLL1_VSEL_table[] = {
508         1000, 1200, 1300, 1800,
509         UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000),
510 };
511 static const u16 VPLL2_VSEL_table[] = {
512         700, 1000, 1200, 1300,
513         UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500),
514         UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000),
515         UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150),
516 };
517 static const u16 VSIM_VSEL_table[] = {
518         UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800,
519         2800, 3000, 3000, 3000,
520 };
521 static const u16 VDAC_VSEL_table[] = {
522         1200, 1300, 1800, 1800,
523 };
524 static const u16 VDD1_VSEL_table[] = {
525         800, 1450,
526 };
527 static const u16 VDD2_VSEL_table[] = {
528         800, 1450, 1500,
529 };
530 static const u16 VIO_VSEL_table[] = {
531         1800, 1850,
532 };
533 static const u16 VINTANA2_VSEL_table[] = {
534         2500, 2750,
535 };
536
537 static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
538 {
539         struct twlreg_info      *info = rdev_get_drvdata(rdev);
540         int                     mV = info->table[index];
541
542         return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000);
543 }
544
545 static int
546 twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
547                        unsigned *selector)
548 {
549         struct twlreg_info      *info = rdev_get_drvdata(rdev);
550         int                     vsel;
551
552         for (vsel = 0; vsel < info->table_len; vsel++) {
553                 int mV = info->table[vsel];
554                 int uV;
555
556                 if (IS_UNSUP(mV))
557                         continue;
558                 uV = LDO_MV(mV) * 1000;
559
560                 /* REVISIT for VAUX2, first match may not be best/lowest */
561
562                 /* use the first in-range value */
563                 if (min_uV <= uV && uV <= max_uV) {
564                         *selector = vsel;
565                         return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
566                                                         VREG_VOLTAGE, vsel);
567                 }
568         }
569
570         return -EDOM;
571 }
572
573 static int twl4030ldo_get_voltage(struct regulator_dev *rdev)
574 {
575         struct twlreg_info      *info = rdev_get_drvdata(rdev);
576         int             vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
577                                                                 VREG_VOLTAGE);
578
579         if (vsel < 0)
580                 return vsel;
581
582         vsel &= info->table_len - 1;
583         return LDO_MV(info->table[vsel]) * 1000;
584 }
585
586 static struct regulator_ops twl4030ldo_ops = {
587         .list_voltage   = twl4030ldo_list_voltage,
588
589         .set_voltage    = twl4030ldo_set_voltage,
590         .get_voltage    = twl4030ldo_get_voltage,
591
592         .enable         = twl4030reg_enable,
593         .disable        = twl4030reg_disable,
594         .is_enabled     = twl4030reg_is_enabled,
595
596         .set_mode       = twl4030reg_set_mode,
597
598         .get_status     = twl4030reg_get_status,
599 };
600
601 static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
602 {
603         struct twlreg_info      *info = rdev_get_drvdata(rdev);
604
605         return ((info->min_mV + (index * 100)) * 1000);
606 }
607
608 static int
609 twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
610                        unsigned *selector)
611 {
612         struct twlreg_info      *info = rdev_get_drvdata(rdev);
613         int                     vsel;
614
615         if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
616                 return -EDOM;
617
618         /*
619          * Use the below formula to calculate vsel
620          * mV = 1000mv + 100mv * (vsel - 1)
621          */
622         vsel = (min_uV/1000 - 1000)/100 + 1;
623         *selector = vsel;
624         return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
625
626 }
627
628 static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
629 {
630         struct twlreg_info      *info = rdev_get_drvdata(rdev);
631         int             vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
632                                                                 VREG_VOLTAGE);
633
634         if (vsel < 0)
635                 return vsel;
636
637         /*
638          * Use the below formula to calculate vsel
639          * mV = 1000mv + 100mv * (vsel - 1)
640          */
641         return (1000 + (100 * (vsel - 1))) * 1000;
642 }
643
644 static struct regulator_ops twl6030ldo_ops = {
645         .list_voltage   = twl6030ldo_list_voltage,
646
647         .set_voltage    = twl6030ldo_set_voltage,
648         .get_voltage    = twl6030ldo_get_voltage,
649
650         .enable         = twl6030reg_enable,
651         .disable        = twl6030reg_disable,
652         .is_enabled     = twl6030reg_is_enabled,
653
654         .set_mode       = twl6030reg_set_mode,
655
656         .get_status     = twl6030reg_get_status,
657
658         .set_suspend_enable     = twl6030ldo_suspend_enable,
659         .set_suspend_disable    = twl6030ldo_suspend_disable,
660 };
661
662 /*----------------------------------------------------------------------*/
663
664 /*
665  * Fixed voltage LDOs don't have a VSEL field to update.
666  */
667 static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
668 {
669         struct twlreg_info      *info = rdev_get_drvdata(rdev);
670
671         return info->min_mV * 1000;
672 }
673
674 static int twlfixed_get_voltage(struct regulator_dev *rdev)
675 {
676         struct twlreg_info      *info = rdev_get_drvdata(rdev);
677
678         return info->min_mV * 1000;
679 }
680
681 static struct regulator_ops twl4030fixed_ops = {
682         .list_voltage   = twlfixed_list_voltage,
683
684         .get_voltage    = twlfixed_get_voltage,
685
686         .enable         = twl4030reg_enable,
687         .disable        = twl4030reg_disable,
688         .is_enabled     = twl4030reg_is_enabled,
689
690         .set_mode       = twl4030reg_set_mode,
691
692         .get_status     = twl4030reg_get_status,
693 };
694
695 static struct regulator_ops twl6030fixed_ops = {
696         .list_voltage   = twlfixed_list_voltage,
697
698         .get_voltage    = twlfixed_get_voltage,
699
700         .enable         = twl6030reg_enable,
701         .disable        = twl6030reg_disable,
702         .is_enabled     = twl6030reg_is_enabled,
703
704         .set_mode       = twl6030reg_set_mode,
705
706         .get_status     = twl6030reg_get_status,
707
708         .set_suspend_enable     = twl6030ldo_suspend_enable,
709         .set_suspend_disable    = twl6030ldo_suspend_disable,
710 };
711
712 static struct regulator_ops twl6030_fixed_resource = {
713         .enable         = twl6030reg_enable,
714         .disable        = twl6030reg_disable,
715         .is_enabled     = twl6030reg_is_enabled,
716         .get_status     = twl6030reg_get_status,
717 };
718
719 /*
720  * SMPS status and control
721  */
722
723 static int twl6030smps_list_voltage(struct regulator_dev *rdev, unsigned index)
724 {
725         struct twlreg_info      *info = rdev_get_drvdata(rdev);
726
727         int voltage = 0;
728
729         switch (info->flags) {
730         case SMPS_OFFSET_EN:
731                 voltage = 100000;
732                 /* fall through */
733         case 0:
734                 switch (index) {
735                 case 0:
736                         voltage = 0;
737                         break;
738                 case 58:
739                         voltage = 1350 * 1000;
740                         break;
741                 case 59:
742                         voltage = 1500 * 1000;
743                         break;
744                 case 60:
745                         voltage = 1800 * 1000;
746                         break;
747                 case 61:
748                         voltage = 1900 * 1000;
749                         break;
750                 case 62:
751                         voltage = 2100 * 1000;
752                         break;
753                 default:
754                         voltage += (600000 + (12500 * (index - 1)));
755                 }
756                 break;
757         case SMPS_EXTENDED_EN:
758                 switch (index) {
759                 case 0:
760                         voltage = 0;
761                         break;
762                 case 58:
763                         voltage = 2084 * 1000;
764                         break;
765                 case 59:
766                         voltage = 2315 * 1000;
767                         break;
768                 case 60:
769                         voltage = 2778 * 1000;
770                         break;
771                 case 61:
772                         voltage = 2932 * 1000;
773                         break;
774                 case 62:
775                         voltage = 3241 * 1000;
776                         break;
777                 default:
778                         voltage = (1852000 + (38600 * (index - 1)));
779                 }
780                 break;
781         case SMPS_OFFSET_EN | SMPS_EXTENDED_EN:
782                 switch (index) {
783                 case 0:
784                         voltage = 0;
785                         break;
786                 case 58:
787                         voltage = 4167 * 1000;
788                         break;
789                 case 59:
790                         voltage = 2315 * 1000;
791                         break;
792                 case 60:
793                         voltage = 2778 * 1000;
794                         break;
795                 case 61:
796                         voltage = 2932 * 1000;
797                         break;
798                 case 62:
799                         voltage = 3241 * 1000;
800                         break;
801                 default:
802                         voltage = (2161000 + (38600 * (index - 1)));
803                 }
804                 break;
805         }
806
807         return voltage;
808 }
809
810 static int
811 twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
812                         unsigned int *selector)
813 {
814         struct twlreg_info      *info = rdev_get_drvdata(rdev);
815         int     vsel = 0;
816
817         switch (info->flags) {
818         case 0:
819                 if (min_uV == 0)
820                         vsel = 0;
821                 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
822                         vsel = (min_uV - 600000) / 125;
823                         if (vsel % 100)
824                                 vsel += 100;
825                         vsel /= 100;
826                         vsel++;
827                 }
828                 /* Values 1..57 for vsel are linear and can be calculated
829                  * values 58..62 are non linear.
830                  */
831                 else if ((min_uV > 1900000) && (max_uV >= 2100000))
832                         vsel = 62;
833                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
834                         vsel = 61;
835                 else if ((min_uV > 1500000) && (max_uV >= 1800000))
836                         vsel = 60;
837                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
838                         vsel = 59;
839                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
840                         vsel = 58;
841                 else
842                         return -EINVAL;
843                 break;
844         case SMPS_OFFSET_EN:
845                 if (min_uV == 0)
846                         vsel = 0;
847                 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
848                         vsel = (min_uV - 700000) / 125;
849                         if (vsel % 100)
850                                 vsel += 100;
851                         vsel /= 100;
852                         vsel++;
853                 }
854                 /* Values 1..57 for vsel are linear and can be calculated
855                  * values 58..62 are non linear.
856                  */
857                 else if ((min_uV > 1900000) && (max_uV >= 2100000))
858                         vsel = 62;
859                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
860                         vsel = 61;
861                 else if ((min_uV > 1350000) && (max_uV >= 1800000))
862                         vsel = 60;
863                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
864                         vsel = 59;
865                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
866                         vsel = 58;
867                 else
868                         return -EINVAL;
869                 break;
870         case SMPS_EXTENDED_EN:
871                 if (min_uV == 0)
872                         vsel = 0;
873                 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
874                         vsel = (min_uV - 1852000) / 386;
875                         if (vsel % 100)
876                                 vsel += 100;
877                         vsel /= 100;
878                         vsel++;
879                 }
880                 break;
881         case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
882                 if (min_uV == 0)
883                         vsel = 0;
884                 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
885                         vsel = (min_uV - 1852000) / 386;
886                         if (vsel % 100)
887                                 vsel += 100;
888                         vsel /= 100;
889                         vsel++;
890                 }
891                 break;
892         }
893
894         *selector = vsel;
895
896         return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS,
897                                                         vsel);
898 }
899 //add
900 #if 1
901 static int twl6030dvssmps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
902                         unsigned int *selector)
903 {
904         struct twlreg_info      *info = rdev_get_drvdata(rdev);
905         int     vsel = 0;
906
907         switch (info->flags) {
908         case 0:
909                 if (min_uV == 0)
910                         vsel = 0;
911                 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
912                         vsel = (min_uV - 600000) / 125;
913                         if (vsel % 100)
914                                 vsel += 100;
915                         vsel /= 100;
916                         vsel++;
917                 }
918                 /* Values 1..57 for vsel are linear and can be calculated
919                  * values 58..62 are non linear.
920                  */
921                 else if ((min_uV > 1900000) && (max_uV >= 2100000))
922                         vsel = 62;
923                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
924                         vsel = 61;
925                 else if ((min_uV > 1500000) && (max_uV >= 1800000))
926                         vsel = 60;
927                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
928                         vsel = 59;
929                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
930                         vsel = 58;
931                 else
932                         return -EINVAL;
933                 break;
934         case SMPS_OFFSET_EN:
935                 if (min_uV == 0)
936                         vsel = 0;
937                 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
938                         vsel = (min_uV - 700000) / 125;
939                         if (vsel % 100)
940                                 vsel += 100;
941                         vsel /= 100;
942                         vsel++;
943                 }
944                 /* Values 1..57 for vsel are linear and can be calculated
945                  * values 58..62 are non linear.
946                  */
947                 else if ((min_uV > 1900000) && (max_uV >= 2100000))
948                         vsel = 62;
949                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
950                         vsel = 61;
951                 else if ((min_uV > 1350000) && (max_uV >= 1800000))
952                         vsel = 60;
953                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
954                         vsel = 59;
955                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
956                         vsel = 58;
957                 else
958                         return -EINVAL;
959                 break;
960         case SMPS_EXTENDED_EN:
961                 if (min_uV == 0)
962                         vsel = 0;
963                 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
964                         vsel = (min_uV - 1852000) / 386;
965                         if (vsel % 100)
966                                 vsel += 100;
967                         vsel /= 100;
968                         vsel++;
969                 }
970                 break;
971         case SMPS_OFFSET_EN|SMPS_EXTENDED_EN:
972                 if (min_uV == 0)
973                         vsel = 0;
974                 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
975                         vsel = (min_uV - 1852000) / 386;
976                         if (vsel % 100)
977                                 vsel += 100;
978                         vsel /= 100;
979                         vsel++;
980                 }
981                 break;
982         }
983
984         *selector = vsel;
985
986         return twlreg_write(info, TWL_MODULE_PM_DVS, VREG_VOLTAGE_DVS_SMPS,
987                                                         vsel);
988 }
989
990 static int twl6030dvssmps_get_voltage_sel(struct regulator_dev *rdev)
991 {
992         struct twlreg_info      *info = rdev_get_drvdata(rdev);
993
994         return twlreg_read(info, TWL_MODULE_PM_DVS, VREG_VOLTAGE_DVS_SMPS);
995 }
996 #endif
997 static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
998 {
999         struct twlreg_info      *info = rdev_get_drvdata(rdev);
1000
1001         return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
1002 }
1003
1004 static struct regulator_ops twlsmps_ops = {
1005         .list_voltage           = twl6030smps_list_voltage,
1006
1007         .set_voltage            = twl6030smps_set_voltage,
1008         .get_voltage_sel        = twl6030smps_get_voltage_sel,
1009
1010         .enable                 = twl6030reg_enable,
1011         .disable                = twl6030reg_disable,
1012         .is_enabled             = twl6030reg_is_enabled,
1013
1014         .set_mode               = twl6030reg_set_mode,
1015
1016         .get_status             = twl6030reg_get_status,
1017
1018         .set_suspend_enable     = twl6030ldo_suspend_enable,
1019         .set_suspend_disable    = twl6030ldo_suspend_disable,
1020 };
1021
1022 static struct regulator_ops twl6030_external_control_pin_ops = {
1023         .enable                 = twl6030reg_enable,
1024         .disable                = twl6030reg_disable,
1025         .is_enabled             = twl6030reg_is_enabled,
1026
1027         .set_mode               = twl6030reg_set_mode,
1028
1029         .get_status             = twl6030reg_get_status,
1030
1031         .set_suspend_enable     = twl6030ldo_suspend_enable,
1032         .set_suspend_disable    = twl6030ldo_suspend_disable,
1033 };
1034 //add
1035 static struct regulator_ops twldvssmps_ops = {
1036         .list_voltage           = twl6030smps_list_voltage,
1037
1038         .set_voltage            = twl6030dvssmps_set_voltage,
1039         .get_voltage_sel        = twl6030dvssmps_get_voltage_sel,
1040
1041         .enable                 = twl6030reg_enable,
1042         .disable                = twl6030reg_disable,
1043         .is_enabled             = twl6030reg_is_enabled,
1044
1045         .set_mode               = twl6030reg_set_mode,
1046
1047         .get_status             = twl6030reg_get_status,
1048
1049         .set_suspend_enable     = twl6030ldo_suspend_enable,
1050         .set_suspend_disable    = twl6030ldo_suspend_disable,
1051 };
1052 /*----------------------------------------------------------------------*/
1053
1054 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
1055                         remap_conf) \
1056                 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
1057                         remap_conf, TWL4030, twl4030fixed_ops)
1058 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
1059                 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
1060                         0x0, TWL6030, twl6030fixed_ops)
1061
1062 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) { \
1063         .base = offset, \
1064         .id = num, \
1065         .table_len = ARRAY_SIZE(label##_VSEL_table), \
1066         .table = label##_VSEL_table, \
1067         .delay = turnon_delay, \
1068         .remap = remap_conf, \
1069         .desc = { \
1070                 .name = #label, \
1071                 .id = TWL4030_REG_##label, \
1072                 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
1073                 .ops = &twl4030ldo_ops, \
1074                 .type = REGULATOR_VOLTAGE, \
1075                 .owner = THIS_MODULE, \
1076                 }, \
1077         }
1078
1079 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
1080         .base = offset, \
1081         .min_mV = min_mVolts, \
1082         .max_mV = max_mVolts, \
1083         .desc = { \
1084                 .name = #label, \
1085                 .id = TWL6030_REG_##label, \
1086                 .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \
1087                 .ops = &twl6030ldo_ops, \
1088                 .type = REGULATOR_VOLTAGE, \
1089                 .owner = THIS_MODULE, \
1090                 }, \
1091         }
1092
1093 #define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
1094         .base = offset, \
1095         .min_mV = min_mVolts, \
1096         .max_mV = max_mVolts, \
1097         .desc = { \
1098                 .name = #label, \
1099                 .id = TWL6032_REG_##label, \
1100                 .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \
1101                 .ops = &twl6030ldo_ops, \
1102                 .type = REGULATOR_VOLTAGE, \
1103                 .owner = THIS_MODULE, \
1104                 }, \
1105         }
1106
1107 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
1108                 family, operations) { \
1109         .base = offset, \
1110         .id = num, \
1111         .min_mV = mVolts, \
1112         .delay = turnon_delay, \
1113         .remap = remap_conf, \
1114         .desc = { \
1115                 .name = #label, \
1116                 .id = family##_REG_##label, \
1117                 .n_voltages = 1, \
1118                 .ops = &operations, \
1119                 .type = REGULATOR_VOLTAGE, \
1120                 .owner = THIS_MODULE, \
1121                 }, \
1122         }
1123
1124 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) { \
1125         .base = offset, \
1126         .delay = turnon_delay, \
1127         .desc = { \
1128                 .name = #label, \
1129                 .id = TWL6030_REG_##label, \
1130                 .ops = &twl6030_fixed_resource, \
1131                 .type = REGULATOR_VOLTAGE, \
1132                 .owner = THIS_MODULE, \
1133                 }, \
1134         }
1135
1136 #define TWL6030_ADJUSTABLE_SMPS(label, offset, min_mVolts, max_mVolts) { \
1137         .base = offset, \
1138         .min_mV = min_mVolts, \
1139         .max_mV = max_mVolts, \
1140         .desc = { \
1141                 .name = #label, \
1142                 .id = TWL6030_REG_##label, \
1143                 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1144                 .ops = &twlsmps_ops, \
1145                 .type = REGULATOR_VOLTAGE, \
1146                 .owner = THIS_MODULE, \
1147                 }, \
1148         }
1149
1150 #define TWL6032_ADJUSTABLE_SMPS(label, offset) { \
1151         .base = offset, \
1152         .min_mV = 600, \
1153         .max_mV = 2100, \
1154         .desc = { \
1155                 .name = #label, \
1156                 .id = TWL6032_REG_##label, \
1157                 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1158                 .ops = &twlsmps_ops, \
1159                 .type = REGULATOR_VOLTAGE, \
1160                 .owner = THIS_MODULE, \
1161                 }, \
1162         }
1163
1164 #define TWL6030_EXTERNAL_CONTROL_PIN(label, offset, turnon_delay) { \
1165         .base = offset, \
1166         .delay = turnon_delay, \
1167         .desc = { \
1168                 .name = #label, \
1169                 .id = TWL6030_REG_##label, \
1170                 .ops = &twl6030_external_control_pin_ops, \
1171                 .type = REGULATOR_VOLTAGE, \
1172                 .owner = THIS_MODULE, \
1173                 }, \
1174         }
1175         
1176         //add
1177 #define TWL6032_ADJUSTABLE_DVSSMPS(label, offset) { \
1178         .base = offset, \
1179         .min_mV = 600, \
1180         .max_mV = 2100, \
1181         .desc = { \
1182                 .name = #label, \
1183                 .id = TWL6032_REG_##label, \
1184                 .n_voltages = TWL603X_SMPS_NUMBER_VOLTAGES, \
1185                 .ops = &twldvssmps_ops, \
1186                 .type = REGULATOR_VOLTAGE, \
1187                 .owner = THIS_MODULE, \
1188                 }, \
1189         }
1190
1191 /*
1192  * We list regulators here if systems need some level of
1193  * software control over them after boot.
1194  */
1195 static struct twlreg_info twl_regs[] = {
1196         TWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08),
1197         TWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08),
1198         TWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08),
1199         TWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08),
1200         TWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08),
1201         TWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08),
1202         TWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08),
1203         TWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00),
1204         TWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08),
1205         TWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00),
1206         TWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08),
1207         TWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08),
1208         TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
1209         TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
1210         TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
1211         TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
1212         TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
1213         TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
1214         TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
1215         TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),
1216         /* VUSBCP is managed *only* by the USB subchip */
1217
1218         /* 6030 REG with base as PMC Slave Misc : 0x0030 */
1219         /* Turnon-delay and remap configuration values for 6030 are not
1220            verified since the specification is not public */
1221         TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000, 3300),
1222         TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000, 3300),
1223         TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000, 3300),
1224         TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000, 3300),
1225         TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000, 3300),
1226         TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000, 3300),
1227         TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0),
1228         TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0),
1229         TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0),
1230         TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 0),
1231         TWL6030_FIXED_RESOURCE(CLK32KG, 0x8C, 0),
1232         TWL6030_FIXED_RESOURCE(CLK32KAUDIO, 0x8F, 0),
1233         TWL6030_ADJUSTABLE_SMPS(VDD1, 0x22, 600, 4000),
1234         TWL6030_ADJUSTABLE_SMPS(VDD2, 0x28, 600, 4000),
1235         TWL6030_ADJUSTABLE_SMPS(VDD3, 0x2e, 600, 4000),
1236         TWL6030_ADJUSTABLE_SMPS(VMEM, 0x34, 600, 4000),
1237         TWL6030_ADJUSTABLE_SMPS(V2V1, 0x1c, 1800, 2100),
1238
1239         /* 6032 are renamed compared to 6030 versions */
1240         TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000, 3300),
1241         TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000, 3300),
1242         TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000, 3300),
1243         TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000, 3300),
1244         TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000, 3300),
1245         TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000, 3300),
1246         TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000, 3300),
1247         TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000, 3300),
1248         TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000, 3300),
1249
1250         TWL6032_ADJUSTABLE_SMPS(SMPS3, 0x34),
1251         TWL6032_ADJUSTABLE_SMPS(SMPS4, 0x10),
1252         TWL6032_ADJUSTABLE_SMPS(VIO, 0x16),
1253         
1254         TWL6032_ADJUSTABLE_DVSSMPS(SMPS1, 0x22),
1255         TWL6032_ADJUSTABLE_DVSSMPS(SMPS2, 0x28),
1256         TWL6032_ADJUSTABLE_DVSSMPS(SMPS5, 0x16),
1257         
1258         TWL6030_EXTERNAL_CONTROL_PIN(SYSEN, 0x83, 0),
1259         TWL6030_EXTERNAL_CONTROL_PIN(REGEN1, 0x7d, 0),
1260
1261 };
1262
1263 static u8 twl_get_smps_offset(void)
1264 {
1265         u8 value;
1266
1267         twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1268                         TWL6030_SMPS_OFFSET);
1269         return value;
1270 }
1271
1272 static u8 twl_get_smps_mult(void)
1273 {
1274         u8 value;
1275
1276         twl_i2c_read_u8(TWL_MODULE_PM_RECEIVER, &value,
1277                         TWL6030_SMPS_MULT);
1278         return value;
1279 }
1280
1281 static int __devinit twlreg_probe(struct platform_device *pdev)
1282 {
1283         int                             i;
1284         struct twlreg_info              *info;
1285         struct regulator_init_data      *initdata;
1286         struct regulation_constraints   *c;
1287         struct regulator_dev            *rdev;
1288         int ret;
1289
1290         for (i = 0, info = NULL; i < ARRAY_SIZE(twl_regs); i++) {
1291                 if (twl_regs[i].desc.id != pdev->id)
1292                         continue;
1293                 info = twl_regs + i;
1294                 break;
1295         }
1296         if (!info)
1297                 return -ENODEV;
1298
1299         initdata = pdev->dev.platform_data;
1300         if (!initdata)
1301                 return -EINVAL;
1302
1303         /* copy the features into regulator data */
1304         info->features = (unsigned long)initdata->driver_data;
1305
1306         /* Constrain board-specific capabilities according to what
1307          * this driver and the chip itself can actually do.
1308          */
1309         c = &initdata->constraints;
1310         c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1311         c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE
1312                                 | REGULATOR_CHANGE_MODE
1313                                 | REGULATOR_CHANGE_STATUS;
1314         switch (pdev->id) {
1315         case TWL4030_REG_VIO:
1316         case TWL4030_REG_VDD1:
1317         case TWL4030_REG_VDD2:
1318         case TWL4030_REG_VPLL1:
1319         case TWL4030_REG_VINTANA1:
1320         case TWL4030_REG_VINTANA2:
1321         case TWL4030_REG_VINTDIG:
1322                 c->always_on = true;
1323                 break;
1324         case TWL6030_REG_VUSB:
1325                 /* Program CFG_LDO_PD2 register and set VUSB bit */
1326                 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, 0x1,
1327                                 TWL6030_CFG_LDO_PD2);
1328                 if (ret < 0)
1329                         return ret;
1330
1331                 /* Program MISC2 register and set bit VUSB_IN_VBAT */
1332                 ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, 0x10, TWL6030_MISC2);
1333                 if (ret < 0)
1334                         return ret;
1335                 break;
1336         default:
1337                 break;
1338         }
1339
1340         switch (pdev->id) {
1341         case TWL6032_REG_SMPS3:
1342                 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS3)
1343                         info->flags |= SMPS_EXTENDED_EN;
1344                 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS3)
1345                         info->flags |= SMPS_OFFSET_EN;
1346                 break;
1347         case TWL6032_REG_SMPS4:
1348                 if (twl_get_smps_mult() & SMPS_MULTOFFSET_SMPS4)
1349                         info->flags |= SMPS_EXTENDED_EN;
1350                 if (twl_get_smps_offset() & SMPS_MULTOFFSET_SMPS4)
1351                         info->flags |= SMPS_OFFSET_EN;
1352                 break;
1353         
1354         case TWL6032_REG_VIO:
1355                 if (twl_get_smps_mult() & SMPS_MULTOFFSET_VIO)
1356                         info->flags |= SMPS_EXTENDED_EN;
1357                 if (twl_get_smps_offset() & SMPS_MULTOFFSET_VIO)
1358                         info->flags |= SMPS_OFFSET_EN;
1359                 break;
1360         }
1361
1362         rdev = regulator_register(&info->desc, &pdev->dev, initdata, info);
1363         if (IS_ERR(rdev)) {
1364                 dev_err(&pdev->dev, "can't register %s, %ld\n",
1365                                 info->desc.name, PTR_ERR(rdev));
1366                 return PTR_ERR(rdev);
1367         }
1368         platform_set_drvdata(pdev, rdev);
1369
1370         if (twl_class_is_4030())
1371                 twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP,
1372                                                 info->remap);
1373
1374         /* NOTE:  many regulators support short-circuit IRQs (presentable
1375          * as REGULATOR_OVER_CURRENT notifications?) configured via:
1376          *  - SC_CONFIG
1377          *  - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4)
1378          *  - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2)
1379          *  - IT_CONFIG
1380          */
1381
1382         return 0;
1383 }
1384
1385 static int __devexit twlreg_remove(struct platform_device *pdev)
1386 {
1387         regulator_unregister(platform_get_drvdata(pdev));
1388         return 0;
1389 }
1390
1391 MODULE_ALIAS("platform:twl_reg");
1392
1393 static struct platform_driver twlreg_driver = {
1394         .probe          = twlreg_probe,
1395         .remove         = __devexit_p(twlreg_remove),
1396         /* NOTE: short name, to work around driver model truncation of
1397          * "twl_regulator.12" (and friends) to "twl_regulator.1".
1398          */
1399         .driver.name    = "twl_reg",
1400         .driver.owner   = THIS_MODULE,
1401 };
1402
1403 static int __init twlreg_init(void)
1404 {
1405         return platform_driver_register(&twlreg_driver);
1406 }
1407 subsys_initcall_sync(twlreg_init);
1408
1409 static void __exit twlreg_exit(void)
1410 {
1411         platform_driver_unregister(&twlreg_driver);
1412 }
1413 module_exit(twlreg_exit)
1414
1415 MODULE_DESCRIPTION("TWL regulator driver");
1416 MODULE_LICENSE("GPL");