regulator: palmas: Fix compilation failures
[linux-2.6.git] / drivers / regulator / palmas-regulator.c
1 /*
2  * Driver for Regulator part of Palmas PMIC Chips
3  *
4  * Copyright 2011-2012 Texas Instruments Inc.
5  *
6  * Author: Graeme Gregory <gg@slimlogic.co.uk>
7  *
8  *  This program is free software; you can redistribute it and/or modify it
9  *  under  the terms of the GNU General  Public License as published by the
10  *  Free Software Foundation;  either version 2 of the License, or (at your
11  *  option) any later version.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/regulator/driver.h>
21 #include <linux/regulator/machine.h>
22 #include <linux/slab.h>
23 #include <linux/regmap.h>
24 #include <linux/mfd/palmas.h>
25
26 struct regs_info {
27         char    *name;
28         u8      vsel_addr;
29         u8      ctrl_addr;
30         u8      tstep_addr;
31 };
32
33 static const struct regs_info palmas_regs_info[] = {
34         {
35                 .name           = "SMPS12",
36                 .vsel_addr      = PALMAS_SMPS12_VOLTAGE,
37                 .ctrl_addr      = PALMAS_SMPS12_CTRL,
38                 .tstep_addr     = PALMAS_SMPS12_TSTEP,
39         },
40         {
41                 .name           = "SMPS123",
42                 .vsel_addr      = PALMAS_SMPS12_VOLTAGE,
43                 .ctrl_addr      = PALMAS_SMPS12_CTRL,
44                 .tstep_addr     = PALMAS_SMPS12_TSTEP,
45         },
46         {
47                 .name           = "SMPS3",
48                 .vsel_addr      = PALMAS_SMPS3_VOLTAGE,
49                 .ctrl_addr      = PALMAS_SMPS3_CTRL,
50         },
51         {
52                 .name           = "SMPS45",
53                 .vsel_addr      = PALMAS_SMPS45_VOLTAGE,
54                 .ctrl_addr      = PALMAS_SMPS45_CTRL,
55                 .tstep_addr     = PALMAS_SMPS45_TSTEP,
56         },
57         {
58                 .name           = "SMPS457",
59                 .vsel_addr      = PALMAS_SMPS45_VOLTAGE,
60                 .ctrl_addr      = PALMAS_SMPS45_CTRL,
61                 .tstep_addr     = PALMAS_SMPS45_TSTEP,
62         },
63         {
64                 .name           = "SMPS6",
65                 .vsel_addr      = PALMAS_SMPS6_VOLTAGE,
66                 .ctrl_addr      = PALMAS_SMPS6_CTRL,
67                 .tstep_addr     = PALMAS_SMPS6_TSTEP,
68         },
69         {
70                 .name           = "SMPS7",
71                 .vsel_addr      = PALMAS_SMPS7_VOLTAGE,
72                 .ctrl_addr      = PALMAS_SMPS7_CTRL,
73         },
74         {
75                 .name           = "SMPS8",
76                 .vsel_addr      = PALMAS_SMPS8_VOLTAGE,
77                 .ctrl_addr      = PALMAS_SMPS8_CTRL,
78                 .tstep_addr     = PALMAS_SMPS8_TSTEP,
79         },
80         {
81                 .name           = "SMPS9",
82                 .vsel_addr      = PALMAS_SMPS9_VOLTAGE,
83                 .ctrl_addr      = PALMAS_SMPS9_CTRL,
84         },
85         {
86                 .name           = "SMPS10",
87                 .ctrl_addr      = PALMAS_SMPS10_CTRL,
88         },
89         {
90                 .name           = "LDO1",
91                 .vsel_addr      = PALMAS_LDO1_VOLTAGE,
92                 .ctrl_addr      = PALMAS_LDO1_CTRL,
93         },
94         {
95                 .name           = "LDO2",
96                 .vsel_addr      = PALMAS_LDO2_VOLTAGE,
97                 .ctrl_addr      = PALMAS_LDO2_CTRL,
98         },
99         {
100                 .name           = "LDO3",
101                 .vsel_addr      = PALMAS_LDO3_VOLTAGE,
102                 .ctrl_addr      = PALMAS_LDO3_CTRL,
103         },
104         {
105                 .name           = "LDO4",
106                 .vsel_addr      = PALMAS_LDO4_VOLTAGE,
107                 .ctrl_addr      = PALMAS_LDO4_CTRL,
108         },
109         {
110                 .name           = "LDO5",
111                 .vsel_addr      = PALMAS_LDO5_VOLTAGE,
112                 .ctrl_addr      = PALMAS_LDO5_CTRL,
113         },
114         {
115                 .name           = "LDO6",
116                 .vsel_addr      = PALMAS_LDO6_VOLTAGE,
117                 .ctrl_addr      = PALMAS_LDO6_CTRL,
118         },
119         {
120                 .name           = "LDO7",
121                 .vsel_addr      = PALMAS_LDO7_VOLTAGE,
122                 .ctrl_addr      = PALMAS_LDO7_CTRL,
123         },
124         {
125                 .name           = "LDO8",
126                 .vsel_addr      = PALMAS_LDO8_VOLTAGE,
127                 .ctrl_addr      = PALMAS_LDO8_CTRL,
128         },
129         {
130                 .name           = "LDO9",
131                 .vsel_addr      = PALMAS_LDO9_VOLTAGE,
132                 .ctrl_addr      = PALMAS_LDO9_CTRL,
133         },
134         {
135                 .name           = "LDOLN",
136                 .vsel_addr      = PALMAS_LDOLN_VOLTAGE,
137                 .ctrl_addr      = PALMAS_LDOLN_CTRL,
138         },
139         {
140                 .name           = "LDOUSB",
141                 .vsel_addr      = PALMAS_LDOUSB_VOLTAGE,
142                 .ctrl_addr      = PALMAS_LDOUSB_CTRL,
143         },
144 };
145
146 #define SMPS_CTRL_MODE_OFF              0x00
147 #define SMPS_CTRL_MODE_ON               0x01
148 #define SMPS_CTRL_MODE_ECO              0x02
149 #define SMPS_CTRL_MODE_PWM              0x03
150
151 /* These values are derived from the data sheet. And are the number of steps
152  * where there is a voltage change, the ranges at beginning and end of register
153  * max/min values where there are no change are ommitted.
154  *
155  * So they are basically (maxV-minV)/stepV
156  */
157 #define PALMAS_SMPS_NUM_VOLTAGES        116
158 #define PALMAS_SMPS10_NUM_VOLTAGES      2
159 #define PALMAS_LDO_NUM_VOLTAGES         50
160
161 #define SMPS10_VSEL                     (1<<3)
162 #define SMPS10_BOOST_EN                 (1<<2)
163 #define SMPS10_BYPASS_EN                (1<<1)
164 #define SMPS10_SWITCH_EN                (1<<0)
165
166 #define REGULATOR_SLAVE                 0
167
168 static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
169                 unsigned int *dest)
170 {
171         unsigned int addr;
172
173         addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
174
175         return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
176 }
177
178 static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
179                 unsigned int value)
180 {
181         unsigned int addr;
182
183         addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
184
185         return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
186 }
187
188 static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
189                 unsigned int *dest)
190 {
191         unsigned int addr;
192
193         addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
194
195         return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
196 }
197
198 static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
199                 unsigned int value)
200 {
201         unsigned int addr;
202
203         addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
204
205         return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
206 }
207
208 static int palmas_is_enabled_smps(struct regulator_dev *dev)
209 {
210         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
211         int id = rdev_get_id(dev);
212         unsigned int reg;
213
214         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
215
216         reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
217         reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
218
219         return !!(reg);
220 }
221
222 static int palmas_enable_smps(struct regulator_dev *dev)
223 {
224         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
225         int id = rdev_get_id(dev);
226         unsigned int reg;
227
228         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
229
230         reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
231         reg |= SMPS_CTRL_MODE_ON;
232
233         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
234
235         return 0;
236 }
237
238 static int palmas_disable_smps(struct regulator_dev *dev)
239 {
240         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
241         int id = rdev_get_id(dev);
242         unsigned int reg;
243
244         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
245
246         reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
247
248         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
249
250         return 0;
251 }
252
253
254 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
255 {
256         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
257         int id = rdev_get_id(dev);
258         unsigned int reg;
259
260         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
261         reg &= ~PALMAS_SMPS12_CTRL_STATUS_MASK;
262         reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
263
264         switch (mode) {
265         case REGULATOR_MODE_NORMAL:
266                 reg |= SMPS_CTRL_MODE_ON;
267                 break;
268         case REGULATOR_MODE_IDLE:
269                 reg |= SMPS_CTRL_MODE_ECO;
270                 break;
271         case REGULATOR_MODE_FAST:
272                 reg |= SMPS_CTRL_MODE_PWM;
273                 break;
274         default:
275                 return -EINVAL;
276         }
277         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
278
279         return 0;
280 }
281
282 static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
283 {
284         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
285         int id = rdev_get_id(dev);
286         unsigned int reg;
287
288         palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
289         reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
290         reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
291
292         switch (reg) {
293         case SMPS_CTRL_MODE_ON:
294                 return REGULATOR_MODE_NORMAL;
295         case SMPS_CTRL_MODE_ECO:
296                 return REGULATOR_MODE_IDLE;
297         case SMPS_CTRL_MODE_PWM:
298                 return REGULATOR_MODE_FAST;
299         }
300
301         return 0;
302 }
303
304 static int palmas_list_voltage_smps(struct regulator_dev *dev,
305                                         unsigned selector)
306 {
307         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
308         int id = rdev_get_id(dev);
309         int mult = 1;
310
311         if (!selector)
312                 return 0;
313
314         /* Read the multiplier set in VSEL register to return
315          * the correct voltage.
316          */
317         if (pmic->range[id])
318                 mult = 2;
319
320         /* Voltage is (0.49V + (selector * 0.01V)) * RANGE
321          * as defined in data sheet. RANGE is either x1 or x2
322          */
323         return  (490000 + (selector * 10000)) * mult;
324 }
325
326 static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
327 {
328         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
329         int id = rdev_get_id(dev);
330         int selector;
331         unsigned int reg;
332         unsigned int addr;
333
334         addr = palmas_regs_info[id].vsel_addr;
335
336         palmas_smps_read(pmic->palmas, addr, &reg);
337
338         selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
339
340         /* Adjust selector to match list_voltage ranges */
341         if ((selector > 0) && (selector < 6))
342                 selector = 6;
343         if (!selector)
344                 selector = 5;
345         if (selector > 121)
346                 selector = 121;
347         selector -= 5;
348
349         return selector;
350 }
351
352 static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
353                 unsigned selector)
354 {
355         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
356         int id = rdev_get_id(dev);
357         unsigned int reg = 0;
358         unsigned int addr;
359
360         addr = palmas_regs_info[id].vsel_addr;
361
362         /* Make sure we don't change the value of RANGE */
363         if (pmic->range[id])
364                 reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
365
366         /* Adjust the linux selector into range used in VSEL register */
367         if (selector)
368                 reg |= selector + 5;
369
370         palmas_smps_write(pmic->palmas, addr, reg);
371
372         return 0;
373 }
374
375 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
376                 int min_uV, int max_uV)
377 {
378         int ret, voltage;
379
380         ret = ((min_uV - 500000) / 10000) + 1;
381         if (ret < 0)
382                 return ret;
383
384         /* Map back into a voltage to verify we're still in bounds */
385         voltage = palmas_list_voltage_smps(rdev, ret);
386         if (voltage < min_uV || voltage > max_uV)
387                 return -EINVAL;
388
389         return ret;
390 }
391
392 static struct regulator_ops palmas_ops_smps = {
393         .is_enabled             = palmas_is_enabled_smps,
394         .enable                 = palmas_enable_smps,
395         .disable                = palmas_disable_smps,
396         .set_mode               = palmas_set_mode_smps,
397         .get_mode               = palmas_get_mode_smps,
398         .get_voltage_sel        = palmas_get_voltage_smps_sel,
399         .set_voltage_sel        = palmas_set_voltage_smps_sel,
400         .list_voltage           = palmas_list_voltage_smps,
401 };
402
403 static int palmas_list_voltage_smps10(struct regulator_dev *dev,
404                                         unsigned selector)
405 {
406         return 3750000 + (selector * 1250000);
407 }
408
409 static struct regulator_ops palmas_ops_smps10 = {
410         .is_enabled             = palmas_is_enabled_smps,
411         .enable                 = palmas_enable_smps,
412         .disable                = palmas_disable_smps,
413         .list_voltage           = palmas_list_voltage_smps10,
414 };
415
416 static int palmas_is_enabled_ldo(struct regulator_dev *dev)
417 {
418         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
419         int id = rdev_get_id(dev);
420         unsigned int reg;
421
422         palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
423
424         reg &= PALMAS_LDO1_CTRL_STATUS;
425
426         return !!(reg);
427 }
428
429 static int palmas_enable_ldo(struct regulator_dev *dev)
430 {
431         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
432         int id = rdev_get_id(dev);
433         unsigned int reg;
434
435         palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
436
437         reg |= SMPS_CTRL_MODE_ON;
438
439         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
440
441         return 0;
442 }
443
444 static int palmas_disable_ldo(struct regulator_dev *dev)
445 {
446         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
447         int id = rdev_get_id(dev);
448         unsigned int reg;
449
450         palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
451
452         reg &= ~SMPS_CTRL_MODE_ON;
453
454         palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
455
456         return 0;
457 }
458
459 static int palmas_list_voltage_ldo(struct regulator_dev *dev,
460                                         unsigned selector)
461 {
462         if (!selector)
463                 return 0;
464
465         /* voltage is 0.85V + (selector * 0.05v) */
466         return  850000 + (selector * 50000);
467 }
468
469 static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev)
470 {
471         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
472         int id = rdev_get_id(dev);
473         int selector;
474         unsigned int reg;
475         unsigned int addr;
476
477         addr = palmas_regs_info[id].vsel_addr;
478
479         palmas_ldo_read(pmic->palmas, addr, &reg);
480
481         selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK;
482
483         /* Adjust selector to match list_voltage ranges */
484         if (selector > 49)
485                 selector = 49;
486
487         return selector;
488 }
489
490 static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev,
491                 unsigned selector)
492 {
493         struct palmas_pmic *pmic = rdev_get_drvdata(dev);
494         int id = rdev_get_id(dev);
495         unsigned int reg = 0;
496         unsigned int addr;
497
498         addr = palmas_regs_info[id].vsel_addr;
499
500         reg = selector;
501
502         palmas_ldo_write(pmic->palmas, addr, reg);
503
504         return 0;
505 }
506
507 static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
508                 int min_uV, int max_uV)
509 {
510         int ret, voltage;
511
512         ret = ((min_uV - 900000) / 50000) + 1;
513         if (ret < 0)
514                 return ret;
515
516         /* Map back into a voltage to verify we're still in bounds */
517         voltage = palmas_list_voltage_ldo(rdev, ret);
518         if (voltage < min_uV || voltage > max_uV)
519                 return -EINVAL;
520
521         return ret;
522 }
523
524 static struct regulator_ops palmas_ops_ldo = {
525         .is_enabled             = palmas_is_enabled_ldo,
526         .enable                 = palmas_enable_ldo,
527         .disable                = palmas_disable_ldo,
528         .get_voltage_sel        = palmas_get_voltage_ldo_sel,
529         .set_voltage_sel        = palmas_set_voltage_ldo_sel,
530         .list_voltage           = palmas_list_voltage_ldo,
531 };
532
533 /*
534  * setup the hardware based sleep configuration of the SMPS/LDO regulators
535  * from the platform data. This is different to the software based control
536  * supported by the regulator framework as it is controlled by toggling
537  * pins on the PMIC such as PREQ, SYSEN, ...
538  */
539 static int palmas_smps_init(struct palmas *palmas, int id,
540                 struct palmas_reg_init *reg_init)
541 {
542         unsigned int reg;
543         unsigned int addr;
544         int ret;
545
546         addr = palmas_regs_info[id].ctrl_addr;
547
548         ret = palmas_smps_read(palmas, addr, &reg);
549         if (ret)
550                 return ret;
551
552         if (id != PALMAS_REG_SMPS10) {
553                 if (reg_init->warm_reset)
554                         reg |= PALMAS_SMPS12_CTRL_WR_S;
555
556                 if (reg_init->roof_floor)
557                         reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
558
559                 if (reg_init->mode_sleep) {
560                         reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
561                         reg |= reg_init->mode_sleep <<
562                                         PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
563                 }
564         } else {
565                 if (reg_init->mode_sleep) {
566                         reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
567                         reg |= reg_init->mode_sleep <<
568                                         PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
569                 }
570
571         }
572         ret = palmas_smps_write(palmas, addr, reg);
573         if (ret)
574                 return ret;
575
576         if (palmas_regs_info[id].tstep_addr && reg_init->tstep) {
577                 addr = palmas_regs_info[id].tstep_addr;
578
579                 reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK;
580
581                 ret = palmas_smps_write(palmas, addr, reg);
582                 if (ret)
583                         return ret;
584         }
585
586         if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
587                 addr = palmas_regs_info[id].vsel_addr;
588
589                 reg = reg_init->vsel;
590
591                 ret = palmas_smps_write(palmas, addr, reg);
592                 if (ret)
593                         return ret;
594         }
595
596
597         return 0;
598 }
599
600 static int palmas_ldo_init(struct palmas *palmas, int id,
601                 struct palmas_reg_init *reg_init)
602 {
603         unsigned int reg;
604         unsigned int addr;
605         int ret;
606
607         addr = palmas_regs_info[id].ctrl_addr;
608
609         ret = palmas_smps_read(palmas, addr, &reg);
610         if (ret)
611                 return ret;
612
613         if (reg_init->warm_reset)
614                 reg |= PALMAS_LDO1_CTRL_WR_S;
615
616         if (reg_init->mode_sleep)
617                 reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
618
619         ret = palmas_smps_write(palmas, addr, reg);
620         if (ret)
621                 return ret;
622
623         return 0;
624 }
625
626 static __devinit int palmas_probe(struct platform_device *pdev)
627 {
628         struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
629         struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data;
630         struct regulator_dev *rdev;
631         struct palmas_pmic *pmic;
632         struct palmas_reg_init *reg_init;
633         struct regulator_init_data *reg_data;
634         int id = 0, ret;
635         unsigned int addr, reg;
636
637         if (!pdata)
638                 return -EINVAL;
639         if (!pdata->reg_data)
640                 return -EINVAL;
641
642         pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
643         if (!pmic)
644                 return -ENOMEM;
645
646         pmic->dev = &pdev->dev;
647         pmic->palmas = palmas;
648         palmas->pmic = pmic;
649         platform_set_drvdata(pdev, pmic);
650
651         ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
652         if (ret)
653                 goto err_unregister_regulator;
654
655         if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN)
656                 pmic->smps123 = 1;
657
658         if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
659                 pmic->smps457 = 1;
660
661         for (id = 0; id < PALMAS_REG_LDO1; id++) {
662                 reg_data = pdata->reg_data[id];
663
664                 /*
665                  * Miss out regulators which are not available due
666                  * to slaving configurations.
667                  */
668                 switch (id) {
669                 case PALMAS_REG_SMPS12:
670                 case PALMAS_REG_SMPS3:
671                         if (pmic->smps123)
672                                 continue;
673                         break;
674                 case PALMAS_REG_SMPS123:
675                         if (!pmic->smps123)
676                                 continue;
677                         break;
678                 case PALMAS_REG_SMPS45:
679                 case PALMAS_REG_SMPS7:
680                         if (pmic->smps457)
681                                 continue;
682                         break;
683                 case PALMAS_REG_SMPS457:
684                         if (!pmic->smps457)
685                                 continue;
686                 }
687
688                 /* Register the regulators */
689                 pmic->desc[id].name = palmas_regs_info[id].name;
690                 pmic->desc[id].id = id;
691
692                 if (id != PALMAS_REG_SMPS10) {
693                         pmic->desc[id].ops = &palmas_ops_smps;
694                         pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
695                 } else {
696                         pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
697                         pmic->desc[id].ops = &palmas_ops_smps10;
698                         pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL;
699                         pmic->desc[id].vsel_mask = SMPS10_VSEL;
700                         pmic->desc[id].enable_reg = PALMAS_SMPS10_STATUS;
701                         pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
702                 }
703
704                 pmic->desc[id].type = REGULATOR_VOLTAGE;
705                 pmic->desc[id].owner = THIS_MODULE;
706
707                 /* Initialise sleep/init values from platform data */
708                 if (pdata && pdata->reg_init) {
709                         reg_init = pdata->reg_init[id];
710                         if (reg_init) {
711                                 ret = palmas_smps_init(palmas, id, reg_init);
712                                 if (ret)
713                                         goto err_unregister_regulator;
714                         }
715                 }
716
717                 /*
718                  * read and store the RANGE bit for later use
719                  * This must be done before regulator is probed otherwise
720                  * we error in probe with unsuportable ranges.
721                  */
722                 if (id != PALMAS_REG_SMPS10) {
723                         addr = palmas_regs_info[id].vsel_addr;
724
725                         ret = palmas_smps_read(pmic->palmas, addr, &reg);
726                         if (ret)
727                                 goto err_unregister_regulator;
728                         if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
729                                 pmic->range[id] = 1;
730                 }
731
732                 rdev = regulator_register(&pmic->desc[id],
733                         palmas->dev, reg_data, pmic, NULL);
734
735                 if (IS_ERR(rdev)) {
736                         dev_err(&pdev->dev,
737                                 "failed to register %s regulator\n",
738                                 pdev->name);
739                         ret = PTR_ERR(rdev);
740                         goto err_unregister_regulator;
741                 }
742
743                 /* Save regulator for cleanup */
744                 pmic->rdev[id] = rdev;
745         }
746
747         /* Start this loop from the id left from previous loop */
748         for (; id < PALMAS_NUM_REGS; id++) {
749
750                 reg_data = pdata->reg_data[id];
751                 /* Miss out regulators which are not available due
752                  * to alternate functions.
753                  */
754
755                 /* Register the regulators */
756                 pmic->desc[id].name = palmas_regs_info[id].name;
757                 pmic->desc[id].id = id;
758                 pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES;
759
760                 pmic->desc[id].ops = &palmas_ops_ldo;
761
762                 pmic->desc[id].type = REGULATOR_VOLTAGE;
763                 pmic->desc[id].owner = THIS_MODULE;
764                 pmic->desc[id].enable_reg = palmas_regs_info[id].ctrl_addr;
765                 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
766
767                 rdev = regulator_register(&pmic->desc[id],
768                         palmas->dev, reg_data, pmic, NULL);
769
770                 if (IS_ERR(rdev)) {
771                         dev_err(&pdev->dev,
772                                 "failed to register %s regulator\n",
773                                 pdev->name);
774                         ret = PTR_ERR(rdev);
775                         goto err_unregister_regulator;
776                 }
777
778                 /* Save regulator for cleanup */
779                 pmic->rdev[id] = rdev;
780
781                 /* Initialise sleep/init values from platform data */
782                 if (pdata->reg_init) {
783                         reg_init = pdata->reg_init[id];
784                         if (reg_init) {
785                                 ret = palmas_ldo_init(palmas, id, reg_init);
786                                 if (ret)
787                                         goto err_unregister_regulator;
788                         }
789                 }
790         }
791
792         return 0;
793
794 err_unregister_regulator:
795         while (--id >= 0)
796                 regulator_unregister(pmic->rdev[id]);
797         kfree(pmic->rdev);
798         kfree(pmic->desc);
799         kfree(pmic);
800         return ret;
801 }
802
803 static int __devexit palmas_remove(struct platform_device *pdev)
804 {
805         struct palmas_pmic *pmic = platform_get_drvdata(pdev);
806         int id;
807
808         for (id = 0; id < PALMAS_NUM_REGS; id++)
809                 regulator_unregister(pmic->rdev[id]);
810
811         kfree(pmic->rdev);
812         kfree(pmic->desc);
813         kfree(pmic);
814         return 0;
815 }
816
817 static struct platform_driver palmas_driver = {
818         .driver = {
819                 .name = "palmas-pmic",
820                 .owner = THIS_MODULE,
821         },
822         .probe = palmas_probe,
823         .remove = __devexit_p(palmas_remove),
824 };
825
826 static int __init palmas_init(void)
827 {
828         return platform_driver_register(&palmas_driver);
829 }
830 subsys_initcall(palmas_init);
831
832 static void __exit palmas_exit(void)
833 {
834         platform_driver_unregister(&palmas_driver);
835 }
836 module_exit(palmas_exit);
837
838 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
839 MODULE_DESCRIPTION("Palmas voltage regulator driver");
840 MODULE_LICENSE("GPL");
841 MODULE_ALIAS("platform:palmas-pmic");