arm: mfd/regulator: Adding driver for tps80031
[linux-2.6.git] / drivers / regulator / tps80031-regulator.c
1 /*
2  * driver/regulator/tps80031-regulator.c
3  *
4  * Regulator driver for TI TPS80031
5  *
6  * Copyright (C) 2011 NVIDIA Corporation
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16  * more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  *
22  */
23
24 #include <linux/kernel.h>
25 #include <linux/delay.h>
26 #include <linux/init.h>
27 #include <linux/err.h>
28 #include <linux/slab.h>
29 #include <linux/platform_device.h>
30 #include <linux/regulator/driver.h>
31 #include <linux/regulator/machine.h>
32 #include <linux/regulator/tps80031-regulator.h>
33 #include <linux/mfd/tps80031.h>
34
35 #define TPS80031ID_VIO_BASE_ADD         0x47
36 #define TPS80031ID_SMPS1_BASE_ADD       0x53
37 #define TPS80031ID_SMPS2_BASE_ADD       0x59
38 #define TPS80031ID_SMPS3_BASE_ADD       0x65
39 #define TPS80031ID_SMPS4_BASE_ADD       0x41
40 #define TPS80031ID_VANA_BASE_ADD        0x81
41 #define TPS80031ID_VRTC_BASE_ADD        0xC3
42 #define TPS80031ID_LDO1_BASE_ADD        0x9D
43 #define TPS80031ID_LDO2_BASE_ADD        0x85
44 #define TPS80031ID_LDO3_BASE_ADD        0x8D
45 #define TPS80031ID_LDO4_BASE_ADD        0x89
46 #define TPS80031ID_LDO5_BASE_ADD        0x99
47 #define TPS80031ID_LDO6_BASE_ADD        0x91
48 #define TPS80031ID_LDO7_BASE_ADD        0xA5
49 #define TPS80031ID_LDOLN_BASE_ADD       0x95
50 #define TPS80031ID_LDOUSB_BASE_ADD      0xA1
51
52 #define VREG_GRP                0
53
54 /* Register offsets */
55 #define VREG_TRANS              0
56 #define VREG_STATE              1
57 #define VREG_VOLTAGE            2
58 #define VREG_VOLTAGE_DCDC       3
59
60 /* Flags for DCDC Voltage reading */
61 #define DCDC_OFFSET_EN          BIT(0)
62 #define DCDC_EXTENDED_EN        BIT(1)
63
64 #define SMPS_MULTOFFSET_VIO     BIT(1)
65 #define SMPS_MULTOFFSET_SMPS1   BIT(3)
66 #define SMPS_MULTOFFSET_SMPS2   BIT(4)
67 #define SMPS_MULTOFFSET_SMPS3   BIT(6)
68 #define SMPS_MULTOFFSET_SMPS4   BIT(0)
69
70 #define PMC_SMPS_OFFSET_ADD     0xE0
71 #define PMC_SMPS_MULT_ADD       0xE3
72
73 #define STATE_OFF       0x00
74 #define STATE_ON        0x01
75 #define STATE_MASK      0x03
76
77 struct tps80031_regulator {
78
79         /* start of regulator's PM_RECEIVER control register bank */
80         u8                      base;
81
82         /* twl resource ID, for resource control state machine */
83         u8                      id;
84
85         /* chip constraints on regulator behavior */
86         u16                     min_mV;
87         u16                     max_mV;
88
89         /* regulator specific turn-on delay */
90         u16                     delay;
91
92         u8                      flags;
93
94         /* used by regulator core */
95         struct regulator_desc   desc;
96
97         /* Device */
98         struct device           *dev;
99 };
100
101 static inline struct device *to_tps80031_dev(struct regulator_dev *rdev)
102 {
103         return rdev_get_dev(rdev)->parent->parent;
104 }
105
106 static int tps80031_regulator_enable_time(struct regulator_dev *rdev)
107 {
108         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
109
110         return ri->delay;
111 }
112
113 static u8 tps80031_get_smps_offset(struct device *parent)
114 {
115         u8 value;
116         int ret;
117
118         ret = tps80031_read(parent, PMC_SMPS_OFFSET_ADD, &value);
119         if (ret < 0) {
120                 dev_err(parent, "Error in reading smps offset register\n");
121                 return 0;
122         }
123         return value;
124 }
125
126 static u8 tps80031_get_smps_mult(struct device *parent)
127 {
128         u8 value;
129         int ret;
130
131         ret = tps80031_read(parent, PMC_SMPS_MULT_ADD, &value);
132         if (ret < 0) {
133                 dev_err(parent, "Error in reading smps mult register\n");
134                 return 0;
135         }
136         return value;
137 }
138
139 static int tps80031_reg_is_enabled(struct regulator_dev *rdev)
140 {
141         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
142         struct device *parent = to_tps80031_dev(rdev);
143         uint8_t state;
144         int ret;
145
146         ret = tps80031_read(parent, ri->base + VREG_STATE, &state);
147         if (ret < 0) {
148                 dev_err(&rdev->dev, "Error in reading the STATE register\n");
149                 return ret;
150         }
151         return ((state & STATE_MASK) == STATE_ON);
152 }
153
154 static int tps80031_reg_enable(struct regulator_dev *rdev)
155 {
156         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
157         struct device *parent = to_tps80031_dev(rdev);
158         int ret;
159
160         ret = tps80031_update(parent, ri->base + VREG_STATE, STATE_ON,
161                                         STATE_MASK);
162         if (ret < 0) {
163                 dev_err(&rdev->dev, "Error in updating the STATE register\n");
164                 return ret;
165         }
166         udelay(ri->delay);
167         return ret;
168 }
169
170 static int tps80031_reg_disable(struct regulator_dev *rdev)
171 {
172         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
173         struct device *parent = to_tps80031_dev(rdev);
174         int ret;
175
176         ret = tps80031_update(parent, ri->base + VREG_STATE, STATE_OFF,
177                                         STATE_MASK);
178         if (ret < 0)
179                 dev_err(&rdev->dev, "Error in updating the STATE register\n");
180
181         return ret;
182 }
183
184 /*
185  * DCDC status and control
186  */
187 static int tps80031dcdc_list_voltage(struct regulator_dev *rdev, unsigned index)
188 {
189         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
190         int voltage = 0;
191
192         switch (ri->flags) {
193         case 0:
194                 if (index == 0)
195                         voltage = 0;
196                 else if (index < 58)
197                         voltage = (600000 + (12500 * (index - 1)));
198                 else if (index == 58)
199                         voltage = 1350 * 1000;
200                 else if (index == 59)
201                         voltage = 1500 * 1000;
202                 else if (index == 60)
203                         voltage = 1800 * 1000;
204                 else if (index == 61)
205                         voltage = 1900 * 1000;
206                 else if (index == 62)
207                         voltage = 2100 * 1000;
208                 break;
209
210         case DCDC_OFFSET_EN:
211                 if (index == 0)
212                         voltage = 0;
213                 else if (index < 58)
214                         voltage = (700000 + (12500 * (index - 1)));
215                 else if (index == 58)
216                         voltage = 1350 * 1000;
217                 else if (index == 59)
218                         voltage = 1500 * 1000;
219                 else if (index == 60)
220                         voltage = 1800 * 1000;
221                 else if (index == 61)
222                         voltage = 1900 * 1000;
223                 else if (index == 62)
224                         voltage = 2100 * 1000;
225                 break;
226
227         case DCDC_EXTENDED_EN:
228                 if (index == 0)
229                         voltage = 0;
230                 else if (index < 58)
231                         voltage = (1852000 + (38600 * (index - 1)));
232                 else if (index == 58)
233                         voltage = 2084 * 1000;
234                 else if (index == 59)
235                         voltage = 2315 * 1000;
236                 else if (index == 60)
237                         voltage = 2778 * 1000;
238                 else if (index == 61)
239                         voltage = 2932 * 1000;
240                 else if (index == 62)
241                         voltage = 3241 * 1000;
242                 break;
243
244         case DCDC_OFFSET_EN|DCDC_EXTENDED_EN:
245                 if (index == 0)
246                         voltage = 0;
247                 else if (index < 58)
248                         voltage = (2161000 + (38600 * (index - 1)));
249                 else if (index == 58)
250                         voltage = 4167 * 1000;
251                 else if (index == 59)
252                         voltage = 2315 * 1000;
253                 else if (index == 60)
254                         voltage = 2778 * 1000;
255                 else if (index == 61)
256                         voltage = 2932 * 1000;
257                 else if (index == 62)
258                         voltage = 3241 * 1000;
259                 break;
260         }
261
262         return voltage;
263 }
264
265 static int __tps80031_dcdc_set_voltage(struct device *parent,
266                 struct tps80031_regulator *ri, int min_uV, int max_uV)
267 {
268         int vsel = 0;
269         int ret;
270
271         switch (ri->flags) {
272         case 0:
273                 if (min_uV == 0)
274                         vsel = 0;
275                 else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
276                         vsel = (min_uV - 600000) / 125;
277                         if (vsel % 100)
278                                 vsel += 100;
279                         vsel /= 100;
280                         vsel++;
281                 } else if ((min_uV > 1900000) && (max_uV >= 2100000))
282                         vsel = 62;
283                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
284                         vsel = 61;
285                 else if ((min_uV > 1500000) && (max_uV >= 1800000))
286                         vsel = 60;
287                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
288                         vsel = 59;
289                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
290                         vsel = 58;
291                 else
292                         return -EINVAL;
293                 break;
294
295         case DCDC_OFFSET_EN:
296                 if (min_uV == 0)
297                         vsel = 0;
298                 else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
299                         vsel = (min_uV - 600000) / 125;
300                         if (vsel % 100)
301                                 vsel += 100;
302                         vsel /= 100;
303                         vsel++;
304                 } else if ((min_uV > 1900000) && (max_uV >= 2100000))
305                         vsel = 62;
306                 else if ((min_uV > 1800000) && (max_uV >= 1900000))
307                         vsel = 61;
308                 else if ((min_uV > 1350000) && (max_uV >= 1800000))
309                         vsel = 60;
310                 else if ((min_uV > 1350000) && (max_uV >= 1500000))
311                         vsel = 59;
312                 else if ((min_uV > 1300000) && (max_uV >= 1350000))
313                         vsel = 58;
314                 else
315                         return -EINVAL;
316                 break;
317
318         case DCDC_EXTENDED_EN:
319                 if (min_uV == 0)
320                         vsel = 0;
321                 else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
322                         vsel = (min_uV - 1852000) / 386;
323                         if (vsel % 100)
324                                 vsel += 100;
325                         vsel /= 100;
326                         vsel++;
327                 }
328                 break;
329
330         case DCDC_OFFSET_EN|DCDC_EXTENDED_EN:
331                 if (min_uV == 0)
332                         vsel = 0;
333                 else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
334                         vsel = (min_uV - 1852000) / 386;
335                         if (vsel % 100)
336                                 vsel += 100;
337                         vsel /= 100;
338                         vsel++;
339                 }
340                 break;
341         }
342
343         ret = tps80031_write(parent, ri->base + VREG_VOLTAGE_DCDC, vsel);
344         if (ret < 0)
345                 dev_err(ri->dev, "Error in updating the Voltage register\n");
346         return ret;
347 }
348
349 static int tps80031dcdc_set_voltage(struct regulator_dev *rdev,
350                         int min_uV, int max_uV)
351 {
352         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
353         struct device *parent = to_tps80031_dev(rdev);
354         return __tps80031_dcdc_set_voltage(parent, ri, min_uV, max_uV);
355 }
356
357 static int tps80031dcdc_get_voltage(struct regulator_dev *rdev)
358 {
359         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
360         struct device *parent = to_tps80031_dev(rdev);
361         uint8_t vsel = 0;
362         int ret;
363         int voltage = 0;
364
365         ret = tps80031_read(parent, ri->base + VREG_VOLTAGE_DCDC, &vsel);
366         if (ret < 0) {
367                 dev_err(&rdev->dev, "Error in reading the Voltage register\n");
368                 return ret;
369         }
370
371         switch (ri->flags) {
372         case 0:
373                 if (vsel == 0)
374                         voltage = 0;
375                 else if (vsel < 58)
376                         voltage = (600000 + (12500 * (vsel - 1)));
377                 else if (vsel == 58)
378                         voltage = 1350 * 1000;
379                 else if (vsel == 59)
380                         voltage = 1500 * 1000;
381                 else if (vsel == 60)
382                         voltage = 1800 * 1000;
383                 else if (vsel == 61)
384                         voltage = 1900 * 1000;
385                 else if (vsel == 62)
386                         voltage = 2100 * 1000;
387                 break;
388
389         case DCDC_OFFSET_EN:
390                 if (vsel == 0)
391                         voltage = 0;
392                 else if (vsel < 58)
393                         voltage = (700000 + (12500 * (vsel - 1)));
394                 else if (vsel == 58)
395                         voltage = 1350 * 1000;
396                 else if (vsel == 59)
397                         voltage = 1500 * 1000;
398                 else if (vsel == 60)
399                         voltage = 1800 * 1000;
400                 else if (vsel == 61)
401                         voltage = 1900 * 1000;
402                 else if (vsel == 62)
403                         voltage = 2100 * 1000;
404                 break;
405
406         case DCDC_EXTENDED_EN:
407                 if (vsel == 0)
408                         voltage = 0;
409                 else if (vsel < 58)
410                         voltage = (1852000 + (38600 * (vsel - 1)));
411                 else if (vsel == 58)
412                         voltage = 2084 * 1000;
413                 else if (vsel == 59)
414                         voltage = 2315 * 1000;
415                 else if (vsel == 60)
416                         voltage = 2778 * 1000;
417                 else if (vsel == 61)
418                         voltage = 2932 * 1000;
419                 else if (vsel == 62)
420                         voltage = 3241 * 1000;
421                 break;
422
423         case DCDC_EXTENDED_EN|DCDC_OFFSET_EN:
424                 if (vsel == 0)
425                         voltage = 0;
426                 else if (vsel < 58)
427                         voltage = (2161000 + (38600 * (vsel - 1)));
428                 else if (vsel == 58)
429                         voltage = 4167 * 1000;
430                 else if (vsel == 59)
431                         voltage = 2315 * 1000;
432                 else if (vsel == 60)
433                         voltage = 2778 * 1000;
434                 else if (vsel == 61)
435                         voltage = 2932 * 1000;
436                 else if (vsel == 62)
437                         voltage = 3241 * 1000;
438                 break;
439         }
440
441         return voltage;
442 }
443
444 static int tps80031ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
445 {
446         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
447
448         if (index == 0)
449                 return 0;
450
451         return (ri->min_mV + (index * 100)) * 1000;
452 }
453
454 static int __tps80031_ldo_set_voltage(struct device *parent,
455                 struct tps80031_regulator *ri, int min_uV, int max_uV)
456 {
457         int vsel;
458         int ret;
459
460         if ((min_uV/1000 < ri->min_mV) || (max_uV/1000 > ri->max_mV))
461                 return -EDOM;
462
463         /*
464          * Use the below formula to calculate vsel
465          * mV = 1000mv + 100mv * (vsel - 1)
466          */
467         vsel = (min_uV/1000 - 1000)/100 + 1;
468         ret = tps80031_write(parent, ri->base + VREG_VOLTAGE, vsel);
469         if (ret < 0)
470                 dev_err(ri->dev, "Error in writing the Voltage register\n");
471         return ret;
472 }
473
474 static int tps80031ldo_set_voltage(struct regulator_dev *rdev,
475                 int min_uV, int max_uV)
476 {
477         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
478         struct device *parent = to_tps80031_dev(rdev);
479
480         return __tps80031_ldo_set_voltage(parent, ri, min_uV, max_uV);
481 }
482
483 static int tps80031ldo_get_voltage(struct regulator_dev *rdev)
484 {
485         struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
486         struct device *parent = to_tps80031_dev(rdev);
487         uint8_t vsel;
488         int ret;
489
490         ret = tps80031_read(parent, ri->base + VREG_VOLTAGE, &vsel);
491         if (ret < 0) {
492                 dev_err(&rdev->dev, "Error in reading the Voltage register\n");
493                 return ret;
494         }
495         /*
496          * Use the below formula to calculate vsel
497          * mV = 1000mv + 100mv * (vsel - 1)
498          */
499         return (1000 + (100 * (vsel - 1))) * 1000;
500 }
501
502 static struct regulator_ops tps80031dcdc_ops = {
503         .list_voltage   = tps80031dcdc_list_voltage,
504         .set_voltage    = tps80031dcdc_set_voltage,
505         .get_voltage    = tps80031dcdc_get_voltage,
506         .enable         = tps80031_reg_enable,
507         .disable        = tps80031_reg_disable,
508         .is_enabled     = tps80031_reg_is_enabled,
509         .enable_time    = tps80031_regulator_enable_time,
510 };
511
512 static struct regulator_ops tps80031ldo_ops = {
513         .list_voltage   = tps80031ldo_list_voltage,
514         .set_voltage    = tps80031ldo_set_voltage,
515         .get_voltage    = tps80031ldo_get_voltage,
516         .enable         = tps80031_reg_enable,
517         .disable        = tps80031_reg_disable,
518         .is_enabled     = tps80031_reg_is_enabled,
519         .enable_time    = tps80031_regulator_enable_time,
520 };
521
522 #define TPS80031_REG(_id, min_mVolts, max_mVolts, _ops, _n_volt, _delay) \
523 {                                                               \
524         .base = TPS80031ID_##_id##_BASE_ADD,                    \
525         .id = TPS80031_ID_##_id,                                \
526         .min_mV = min_mVolts,                                   \
527         .max_mV = max_mVolts,                                   \
528         .desc = {                                               \
529                 .name = tps80031_rails(_id),                    \
530                 .id = TPS80031_ID_##_id,                        \
531                 .n_voltages = _n_volt,                          \
532                 .ops = &_ops,                                   \
533                 .type = REGULATOR_VOLTAGE,                      \
534                 .owner = THIS_MODULE,                           \
535         },                                                      \
536         .delay = _delay,                                        \
537 }
538
539 static struct tps80031_regulator tps80031_regulator[] = {
540         TPS80031_REG(VIO,   600, 2100, tps80031dcdc_ops, 63, 500),
541         TPS80031_REG(SMPS1, 600, 2100, tps80031dcdc_ops, 63, 500),
542         TPS80031_REG(SMPS2, 600, 2100, tps80031dcdc_ops, 63, 500),
543         TPS80031_REG(SMPS3, 600, 2100, tps80031dcdc_ops, 63, 500),
544         TPS80031_REG(SMPS4, 600, 2100, tps80031dcdc_ops, 63, 500),
545
546         TPS80031_REG(LDO1,   1100, 3300, tps80031ldo_ops, 24, 500),
547         TPS80031_REG(LDO2,   1100, 3300, tps80031ldo_ops, 24, 500),
548         TPS80031_REG(LDO3,   1100, 3300, tps80031ldo_ops, 24, 500),
549         TPS80031_REG(LDO4,   1100, 3300, tps80031ldo_ops, 24, 500),
550         TPS80031_REG(LDO5,   1100, 3300, tps80031ldo_ops, 24, 500),
551         TPS80031_REG(LDO6,   1100, 3300, tps80031ldo_ops, 24, 500),
552         TPS80031_REG(LDO7,   1100, 3300, tps80031ldo_ops, 24, 500),
553         TPS80031_REG(LDOUSB, 1100, 3300, tps80031ldo_ops, 24, 500),
554         TPS80031_REG(LDOLN,  1100, 3300, tps80031ldo_ops, 24, 500),
555         TPS80031_REG(VANA,   1100, 3300, tps80031ldo_ops, 24, 500),
556 };
557
558
559 static inline int tps80031_regulator_preinit(struct device *parent,
560                 struct tps80031_regulator *ri,
561                 struct tps80031_regulator_platform_data *tps80031_pdata)
562 {
563         int ret;
564
565         if (!tps80031_pdata->init_apply)
566                 return 0;
567
568         if (tps80031_pdata->init_uV >= 0) {
569                 switch (ri->desc.id) {
570                 case TPS80031_ID_VIO:
571                 case TPS80031_ID_SMPS1:
572                 case TPS80031_ID_SMPS2:
573                 case TPS80031_ID_SMPS3:
574                 case TPS80031_ID_SMPS4:
575                         ret = __tps80031_dcdc_set_voltage(parent, ri,
576                                         tps80031_pdata->init_uV,
577                                         tps80031_pdata->init_uV);
578                         break;
579
580                 case TPS80031_ID_LDO1:
581                 case TPS80031_ID_LDO2:
582                 case TPS80031_ID_LDO3:
583                 case TPS80031_ID_LDO4:
584                 case TPS80031_ID_LDO5:
585                 case TPS80031_ID_LDO6:
586                 case TPS80031_ID_LDO7:
587                 case TPS80031_ID_LDOUSB:
588                 case TPS80031_ID_LDOLN:
589                 case TPS80031_ID_VANA:
590                         ret = __tps80031_ldo_set_voltage(parent, ri,
591                                         tps80031_pdata->init_uV,
592                                         tps80031_pdata->init_uV);
593                         break;
594                 default:
595                         ret = -EINVAL;
596                         break;
597                 }
598
599                 if (ret < 0) {
600                         dev_err(ri->dev, "Not able to initialize voltage %d "
601                                 "for rail %d err %d\n", tps80031_pdata->init_uV,
602                                 ri->desc.id, ret);
603                         return ret;
604                 }
605         }
606
607         if (tps80031_pdata->init_enable)
608                 ret = tps80031_update(parent, ri->base + VREG_STATE, STATE_ON,
609                                                                 STATE_MASK);
610         else
611                 ret = tps80031_update(parent, ri->base + VREG_STATE, STATE_OFF,
612                                                                 STATE_MASK);
613         if (ret < 0)
614                 dev_err(ri->dev, "Not able to %s rail %d err %d\n",
615                         (tps80031_pdata->init_enable) ? "enable" : "disable",
616                         ri->desc.id, ret);
617         return ret;
618 }
619
620 static inline struct tps80031_regulator *find_regulator_info(int id)
621 {
622         struct tps80031_regulator *ri;
623         int i;
624
625         for (i = 0; i < ARRAY_SIZE(tps80031_regulator); i++) {
626                 ri = &tps80031_regulator[i];
627                 if (ri->desc.id == id)
628                         return ri;
629         }
630         return NULL;
631 }
632 static void check_smps_mode_mult(struct device *parent,
633         struct tps80031_regulator *ri)
634 {
635         int mult_offset;
636         switch (ri->desc.id) {
637         case TPS80031_ID_VIO:
638                 mult_offset = SMPS_MULTOFFSET_VIO;
639                 break;
640         case TPS80031_ID_SMPS1:
641                 mult_offset = SMPS_MULTOFFSET_SMPS1;
642                 break;
643         case TPS80031_ID_SMPS2:
644                 mult_offset = SMPS_MULTOFFSET_SMPS2;
645                 break;
646         case TPS80031_ID_SMPS3:
647                 mult_offset = SMPS_MULTOFFSET_SMPS3;
648                 break;
649         case TPS80031_ID_SMPS4:
650                 mult_offset = SMPS_MULTOFFSET_SMPS4;
651                 break;
652         default:
653                 return;
654         }
655
656         ri->flags = (tps80031_get_smps_offset(parent) & mult_offset) ?
657                                                 DCDC_OFFSET_EN : 0;
658         ri->flags |= (tps80031_get_smps_mult(parent) & mult_offset) ?
659                                                 DCDC_EXTENDED_EN : 0;
660         return;
661 }
662
663 static int __devinit tps80031_regulator_probe(struct platform_device *pdev)
664 {
665         struct tps80031_regulator *ri = NULL;
666         struct regulator_dev *rdev;
667         struct tps80031_regulator_platform_data *tps_pdata;
668         int id = pdev->id;
669         int err;
670
671         dev_dbg(&pdev->dev, "Probing reulator %d\n", id);
672
673         ri = find_regulator_info(id);
674         if (ri == NULL) {
675                 dev_err(&pdev->dev, "invalid regulator ID specified\n");
676                 return -EINVAL;
677         }
678         tps_pdata = pdev->dev.platform_data;
679         ri->dev = &pdev->dev;
680
681         check_smps_mode_mult(pdev->dev.parent, ri);
682
683         err = tps80031_regulator_preinit(pdev->dev.parent, ri, tps_pdata);
684         if (err)
685                 return err;
686
687         rdev = regulator_register(&ri->desc, &pdev->dev,
688                                 &tps_pdata->regulator, ri);
689         if (IS_ERR_OR_NULL(rdev)) {
690                 dev_err(&pdev->dev, "failed to register regulator %s\n",
691                                 ri->desc.name);
692                 return PTR_ERR(rdev);
693         }
694
695         platform_set_drvdata(pdev, rdev);
696
697         return 0;
698 }
699
700 static int __devexit tps80031_regulator_remove(struct platform_device *pdev)
701 {
702         struct regulator_dev *rdev = platform_get_drvdata(pdev);
703
704         regulator_unregister(rdev);
705         return 0;
706 }
707
708 static struct platform_driver tps80031_regulator_driver = {
709         .driver = {
710                 .name   = "tps80031-regulator",
711                 .owner  = THIS_MODULE,
712         },
713         .probe          = tps80031_regulator_probe,
714         .remove         = __devexit_p(tps80031_regulator_remove),
715 };
716
717 static int __init tps80031_regulator_init(void)
718 {
719         return platform_driver_register(&tps80031_regulator_driver);
720 }
721 subsys_initcall(tps80031_regulator_init);
722
723 static void __exit tps80031_regulator_exit(void)
724 {
725         platform_driver_unregister(&tps80031_regulator_driver);
726 }
727 module_exit(tps80031_regulator_exit);
728
729 MODULE_LICENSE("GPL");
730 MODULE_DESCRIPTION("Regulator Driver for TI TPS80031 PMIC");
731 MODULE_ALIAS("platform:tps80031-regulator");