regulator: max8998 BUCK1/2 internal voltages and indexes defined
[linux-2.6.git] / drivers / regulator / max8998.c
1 /*
2  * max8998.c - Voltage regulator driver for the Maxim 8998
3  *
4  *  Copyright (C) 2009-2010 Samsung Electronics
5  *  Kyungmin Park <kyungmin.park@samsung.com>
6  *  Marek Szyprowski <m.szyprowski@samsung.com>
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,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/i2c.h>
26 #include <linux/err.h>
27 #include <linux/gpio.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/mutex.h>
31 #include <linux/delay.h>
32 #include <linux/platform_device.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/mfd/max8998.h>
35 #include <linux/mfd/max8998-private.h>
36
37 struct max8998_data {
38         struct device           *dev;
39         struct max8998_dev      *iodev;
40         int                     num_regulators;
41         struct regulator_dev    **rdev;
42         u8                      buck1_vol[4]; /* voltages for selection */
43         u8                      buck2_vol[2];
44         unsigned int            buck1_idx; /* index to last changed voltage */
45                                            /* value in a set */
46         unsigned int            buck2_idx;
47 };
48
49 struct voltage_map_desc {
50         int min;
51         int max;
52         int step;
53 };
54
55 /* Voltage maps */
56 static const struct voltage_map_desc ldo23_voltage_map_desc = {
57         .min = 800,     .step = 50,     .max = 1300,
58 };
59 static const struct voltage_map_desc ldo456711_voltage_map_desc = {
60         .min = 1600,    .step = 100,    .max = 3600,
61 };
62 static const struct voltage_map_desc ldo8_voltage_map_desc = {
63         .min = 3000,    .step = 100,    .max = 3600,
64 };
65 static const struct voltage_map_desc ldo9_voltage_map_desc = {
66         .min = 2800,    .step = 100,    .max = 3100,
67 };
68 static const struct voltage_map_desc ldo10_voltage_map_desc = {
69         .min = 950,     .step = 50,     .max = 1300,
70 };
71 static const struct voltage_map_desc ldo1213_voltage_map_desc = {
72         .min = 800,     .step = 100,    .max = 3300,
73 };
74 static const struct voltage_map_desc ldo1415_voltage_map_desc = {
75         .min = 1200,    .step = 100,    .max = 3300,
76 };
77 static const struct voltage_map_desc ldo1617_voltage_map_desc = {
78         .min = 1600,    .step = 100,    .max = 3600,
79 };
80 static const struct voltage_map_desc buck12_voltage_map_desc = {
81         .min = 750,     .step = 25,     .max = 1525,
82 };
83 static const struct voltage_map_desc buck3_voltage_map_desc = {
84         .min = 1600,    .step = 100,    .max = 3600,
85 };
86 static const struct voltage_map_desc buck4_voltage_map_desc = {
87         .min = 800,     .step = 100,    .max = 2300,
88 };
89
90 static const struct voltage_map_desc *ldo_voltage_map[] = {
91         NULL,
92         NULL,
93         &ldo23_voltage_map_desc,        /* LDO2 */
94         &ldo23_voltage_map_desc,        /* LDO3 */
95         &ldo456711_voltage_map_desc,    /* LDO4 */
96         &ldo456711_voltage_map_desc,    /* LDO5 */
97         &ldo456711_voltage_map_desc,    /* LDO6 */
98         &ldo456711_voltage_map_desc,    /* LDO7 */
99         &ldo8_voltage_map_desc,         /* LDO8 */
100         &ldo9_voltage_map_desc,         /* LDO9 */
101         &ldo10_voltage_map_desc,        /* LDO10 */
102         &ldo456711_voltage_map_desc,    /* LDO11 */
103         &ldo1213_voltage_map_desc,      /* LDO12 */
104         &ldo1213_voltage_map_desc,      /* LDO13 */
105         &ldo1415_voltage_map_desc,      /* LDO14 */
106         &ldo1415_voltage_map_desc,      /* LDO15 */
107         &ldo1617_voltage_map_desc,      /* LDO16 */
108         &ldo1617_voltage_map_desc,      /* LDO17 */
109         &buck12_voltage_map_desc,       /* BUCK1 */
110         &buck12_voltage_map_desc,       /* BUCK2 */
111         &buck3_voltage_map_desc,        /* BUCK3 */
112         &buck4_voltage_map_desc,        /* BUCK4 */
113 };
114
115 static inline int max8998_get_ldo(struct regulator_dev *rdev)
116 {
117         return rdev_get_id(rdev);
118 }
119
120 static int max8998_list_voltage(struct regulator_dev *rdev,
121                                 unsigned int selector)
122 {
123         const struct voltage_map_desc *desc;
124         int ldo = max8998_get_ldo(rdev);
125         int val;
126
127         if (ldo >= ARRAY_SIZE(ldo_voltage_map))
128                 return -EINVAL;
129
130         desc = ldo_voltage_map[ldo];
131         if (desc == NULL)
132                 return -EINVAL;
133
134         val = desc->min + desc->step * selector;
135         if (val > desc->max)
136                 return -EINVAL;
137
138         return val * 1000;
139 }
140
141 static int max8998_get_enable_register(struct regulator_dev *rdev,
142                                         int *reg, int *shift)
143 {
144         int ldo = max8998_get_ldo(rdev);
145
146         switch (ldo) {
147         case MAX8998_LDO2 ... MAX8998_LDO5:
148                 *reg = MAX8998_REG_ONOFF1;
149                 *shift = 3 - (ldo - MAX8998_LDO2);
150                 break;
151         case MAX8998_LDO6 ... MAX8998_LDO13:
152                 *reg = MAX8998_REG_ONOFF2;
153                 *shift = 7 - (ldo - MAX8998_LDO6);
154                 break;
155         case MAX8998_LDO14 ... MAX8998_LDO17:
156                 *reg = MAX8998_REG_ONOFF3;
157                 *shift = 7 - (ldo - MAX8998_LDO14);
158                 break;
159         case MAX8998_BUCK1 ... MAX8998_BUCK4:
160                 *reg = MAX8998_REG_ONOFF1;
161                 *shift = 7 - (ldo - MAX8998_BUCK1);
162                 break;
163         case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG:
164                 *reg = MAX8998_REG_ONOFF4;
165                 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP);
166                 break;
167         case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2:
168                 *reg = MAX8998_REG_CHGR2;
169                 *shift = 7 - (ldo - MAX8998_ESAFEOUT1);
170                 break;
171         default:
172                 return -EINVAL;
173         }
174
175         return 0;
176 }
177
178 static int max8998_ldo_is_enabled(struct regulator_dev *rdev)
179 {
180         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
181         struct i2c_client *i2c = max8998->iodev->i2c;
182         int ret, reg, shift = 8;
183         u8 val;
184
185         ret = max8998_get_enable_register(rdev, &reg, &shift);
186         if (ret)
187                 return ret;
188
189         ret = max8998_read_reg(i2c, reg, &val);
190         if (ret)
191                 return ret;
192
193         return val & (1 << shift);
194 }
195
196 static int max8998_ldo_enable(struct regulator_dev *rdev)
197 {
198         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
199         struct i2c_client *i2c = max8998->iodev->i2c;
200         int reg, shift = 8, ret;
201
202         ret = max8998_get_enable_register(rdev, &reg, &shift);
203         if (ret)
204                 return ret;
205
206         return max8998_update_reg(i2c, reg, 1<<shift, 1<<shift);
207 }
208
209 static int max8998_ldo_disable(struct regulator_dev *rdev)
210 {
211         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
212         struct i2c_client *i2c = max8998->iodev->i2c;
213         int reg, shift = 8, ret;
214
215         ret = max8998_get_enable_register(rdev, &reg, &shift);
216         if (ret)
217                 return ret;
218
219         return max8998_update_reg(i2c, reg, 0, 1<<shift);
220 }
221
222 static int max8998_get_voltage_register(struct regulator_dev *rdev,
223                                 int *_reg, int *_shift, int *_mask)
224 {
225         int ldo = max8998_get_ldo(rdev);
226         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
227         int reg, shift = 0, mask = 0xff;
228
229         switch (ldo) {
230         case MAX8998_LDO2 ... MAX8998_LDO3:
231                 reg = MAX8998_REG_LDO2_LDO3;
232                 mask = 0xf;
233                 if (ldo == MAX8998_LDO2)
234                         shift = 4;
235                 else
236                         shift = 0;
237                 break;
238         case MAX8998_LDO4 ... MAX8998_LDO7:
239                 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4);
240                 break;
241         case MAX8998_LDO8 ... MAX8998_LDO9:
242                 reg = MAX8998_REG_LDO8_LDO9;
243                 mask = 0xf;
244                 if (ldo == MAX8998_LDO8)
245                         shift = 4;
246                 else
247                         shift = 0;
248                 break;
249         case MAX8998_LDO10 ... MAX8998_LDO11:
250                 reg = MAX8998_REG_LDO10_LDO11;
251                 if (ldo == MAX8998_LDO10) {
252                         shift = 5;
253                         mask = 0x7;
254                 } else {
255                         shift = 0;
256                         mask = 0x1f;
257                 }
258                 break;
259         case MAX8998_LDO12 ... MAX8998_LDO17:
260                 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12);
261                 break;
262         case MAX8998_BUCK1:
263                 reg = MAX8998_REG_BUCK1_VOLTAGE1 + max8998->buck1_idx;
264                 break;
265         case MAX8998_BUCK2:
266                 reg = MAX8998_REG_BUCK2_VOLTAGE1 + max8998->buck2_idx;
267                 break;
268         case MAX8998_BUCK3:
269                 reg = MAX8998_REG_BUCK3;
270                 break;
271         case MAX8998_BUCK4:
272                 reg = MAX8998_REG_BUCK4;
273                 break;
274         default:
275                 return -EINVAL;
276         }
277
278         *_reg = reg;
279         *_shift = shift;
280         *_mask = mask;
281
282         return 0;
283 }
284
285 static int max8998_get_voltage(struct regulator_dev *rdev)
286 {
287         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
288         struct i2c_client *i2c = max8998->iodev->i2c;
289         int reg, shift = 0, mask, ret;
290         u8 val;
291
292         ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
293         if (ret)
294                 return ret;
295
296         ret = max8998_read_reg(i2c, reg, &val);
297         if (ret)
298                 return ret;
299
300         val >>= shift;
301         val &= mask;
302
303         return max8998_list_voltage(rdev, val);
304 }
305
306 static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
307                                 int min_uV, int max_uV)
308 {
309         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
310         struct i2c_client *i2c = max8998->iodev->i2c;
311         int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
312         const struct voltage_map_desc *desc;
313         int ldo = max8998_get_ldo(rdev);
314         int reg, shift = 0, mask, ret;
315         int i = 0;
316
317         if (ldo >= ARRAY_SIZE(ldo_voltage_map))
318                 return -EINVAL;
319
320         desc = ldo_voltage_map[ldo];
321         if (desc == NULL)
322                 return -EINVAL;
323
324         if (max_vol < desc->min || min_vol > desc->max)
325                 return -EINVAL;
326
327         while (desc->min + desc->step*i < min_vol &&
328                desc->min + desc->step*i < desc->max)
329                 i++;
330
331         if (desc->min + desc->step*i > max_vol)
332                 return -EINVAL;
333
334         ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
335         if (ret)
336                 return ret;
337
338         ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift);
339
340         return ret;
341 }
342
343 static int max8998_set_voltage_buck(struct regulator_dev *rdev,
344                                 int min_uV, int max_uV)
345 {
346         struct max8998_data *max8998 = rdev_get_drvdata(rdev);
347         struct i2c_client *i2c = max8998->iodev->i2c;
348         int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
349         int previous_vol = 0;
350         const struct voltage_map_desc *desc;
351         int ldo = max8998_get_ldo(rdev);
352         int reg, shift = 0, mask, ret;
353         int i = 0;
354         u8 val;
355         bool en_ramp = false;
356
357         if (ldo >= ARRAY_SIZE(ldo_voltage_map))
358                 return -EINVAL;
359
360         desc = ldo_voltage_map[ldo];
361         if (desc == NULL)
362                 return -EINVAL;
363
364         if (max_vol < desc->min || min_vol > desc->max)
365                 return -EINVAL;
366
367         while (desc->min + desc->step*i < min_vol &&
368                desc->min + desc->step*i < desc->max)
369                 i++;
370
371         if (desc->min + desc->step*i > max_vol)
372                 return -EINVAL;
373
374         ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
375         if (ret)
376                 return ret;
377
378         /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and
379          * ENRAMP is ON */
380         if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) {
381                 max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
382                 if (val & (1 << 4)) {
383                         en_ramp = true;
384                         previous_vol = max8998_get_voltage(rdev);
385                 }
386         }
387
388         ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift);
389
390         if (en_ramp == true) {
391                 int difference = desc->min + desc->step*i - previous_vol/1000;
392                 if (difference > 0)
393                         udelay(difference / ((val & 0x0f) + 1));
394         }
395
396         return ret;
397 }
398
399 static struct regulator_ops max8998_ldo_ops = {
400         .list_voltage           = max8998_list_voltage,
401         .is_enabled             = max8998_ldo_is_enabled,
402         .enable                 = max8998_ldo_enable,
403         .disable                = max8998_ldo_disable,
404         .get_voltage            = max8998_get_voltage,
405         .set_voltage            = max8998_set_voltage_ldo,
406         .set_suspend_enable     = max8998_ldo_enable,
407         .set_suspend_disable    = max8998_ldo_disable,
408 };
409
410 static struct regulator_ops max8998_buck_ops = {
411         .list_voltage           = max8998_list_voltage,
412         .is_enabled             = max8998_ldo_is_enabled,
413         .enable                 = max8998_ldo_enable,
414         .disable                = max8998_ldo_disable,
415         .get_voltage            = max8998_get_voltage,
416         .set_voltage            = max8998_set_voltage_buck,
417         .set_suspend_enable     = max8998_ldo_enable,
418         .set_suspend_disable    = max8998_ldo_disable,
419 };
420
421 static struct regulator_ops max8998_others_ops = {
422         .is_enabled             = max8998_ldo_is_enabled,
423         .enable                 = max8998_ldo_enable,
424         .disable                = max8998_ldo_disable,
425         .set_suspend_enable     = max8998_ldo_enable,
426         .set_suspend_disable    = max8998_ldo_disable,
427 };
428
429 static struct regulator_desc regulators[] = {
430         {
431                 .name           = "LDO2",
432                 .id             = MAX8998_LDO2,
433                 .ops            = &max8998_ldo_ops,
434                 .type           = REGULATOR_VOLTAGE,
435                 .owner          = THIS_MODULE,
436         }, {
437                 .name           = "LDO3",
438                 .id             = MAX8998_LDO3,
439                 .ops            = &max8998_ldo_ops,
440                 .type           = REGULATOR_VOLTAGE,
441                 .owner          = THIS_MODULE,
442         }, {
443                 .name           = "LDO4",
444                 .id             = MAX8998_LDO4,
445                 .ops            = &max8998_ldo_ops,
446                 .type           = REGULATOR_VOLTAGE,
447                 .owner          = THIS_MODULE,
448         }, {
449                 .name           = "LDO5",
450                 .id             = MAX8998_LDO5,
451                 .ops            = &max8998_ldo_ops,
452                 .type           = REGULATOR_VOLTAGE,
453                 .owner          = THIS_MODULE,
454         }, {
455                 .name           = "LDO6",
456                 .id             = MAX8998_LDO6,
457                 .ops            = &max8998_ldo_ops,
458                 .type           = REGULATOR_VOLTAGE,
459                 .owner          = THIS_MODULE,
460         }, {
461                 .name           = "LDO7",
462                 .id             = MAX8998_LDO7,
463                 .ops            = &max8998_ldo_ops,
464                 .type           = REGULATOR_VOLTAGE,
465                 .owner          = THIS_MODULE,
466         }, {
467                 .name           = "LDO8",
468                 .id             = MAX8998_LDO8,
469                 .ops            = &max8998_ldo_ops,
470                 .type           = REGULATOR_VOLTAGE,
471                 .owner          = THIS_MODULE,
472         }, {
473                 .name           = "LDO9",
474                 .id             = MAX8998_LDO9,
475                 .ops            = &max8998_ldo_ops,
476                 .type           = REGULATOR_VOLTAGE,
477                 .owner          = THIS_MODULE,
478         }, {
479                 .name           = "LDO10",
480                 .id             = MAX8998_LDO10,
481                 .ops            = &max8998_ldo_ops,
482                 .type           = REGULATOR_VOLTAGE,
483                 .owner          = THIS_MODULE,
484         }, {
485                 .name           = "LDO11",
486                 .id             = MAX8998_LDO11,
487                 .ops            = &max8998_ldo_ops,
488                 .type           = REGULATOR_VOLTAGE,
489                 .owner          = THIS_MODULE,
490         }, {
491                 .name           = "LDO12",
492                 .id             = MAX8998_LDO12,
493                 .ops            = &max8998_ldo_ops,
494                 .type           = REGULATOR_VOLTAGE,
495                 .owner          = THIS_MODULE,
496         }, {
497                 .name           = "LDO13",
498                 .id             = MAX8998_LDO13,
499                 .ops            = &max8998_ldo_ops,
500                 .type           = REGULATOR_VOLTAGE,
501                 .owner          = THIS_MODULE,
502         }, {
503                 .name           = "LDO14",
504                 .id             = MAX8998_LDO14,
505                 .ops            = &max8998_ldo_ops,
506                 .type           = REGULATOR_VOLTAGE,
507                 .owner          = THIS_MODULE,
508         }, {
509                 .name           = "LDO15",
510                 .id             = MAX8998_LDO15,
511                 .ops            = &max8998_ldo_ops,
512                 .type           = REGULATOR_VOLTAGE,
513                 .owner          = THIS_MODULE,
514         }, {
515                 .name           = "LDO16",
516                 .id             = MAX8998_LDO16,
517                 .ops            = &max8998_ldo_ops,
518                 .type           = REGULATOR_VOLTAGE,
519                 .owner          = THIS_MODULE,
520         }, {
521                 .name           = "LDO17",
522                 .id             = MAX8998_LDO17,
523                 .ops            = &max8998_ldo_ops,
524                 .type           = REGULATOR_VOLTAGE,
525                 .owner          = THIS_MODULE,
526         }, {
527                 .name           = "BUCK1",
528                 .id             = MAX8998_BUCK1,
529                 .ops            = &max8998_buck_ops,
530                 .type           = REGULATOR_VOLTAGE,
531                 .owner          = THIS_MODULE,
532         }, {
533                 .name           = "BUCK2",
534                 .id             = MAX8998_BUCK2,
535                 .ops            = &max8998_buck_ops,
536                 .type           = REGULATOR_VOLTAGE,
537                 .owner          = THIS_MODULE,
538         }, {
539                 .name           = "BUCK3",
540                 .id             = MAX8998_BUCK3,
541                 .ops            = &max8998_buck_ops,
542                 .type           = REGULATOR_VOLTAGE,
543                 .owner          = THIS_MODULE,
544         }, {
545                 .name           = "BUCK4",
546                 .id             = MAX8998_BUCK4,
547                 .ops            = &max8998_buck_ops,
548                 .type           = REGULATOR_VOLTAGE,
549                 .owner          = THIS_MODULE,
550         }, {
551                 .name           = "EN32KHz AP",
552                 .id             = MAX8998_EN32KHZ_AP,
553                 .ops            = &max8998_others_ops,
554                 .type           = REGULATOR_VOLTAGE,
555                 .owner          = THIS_MODULE,
556         }, {
557                 .name           = "EN32KHz CP",
558                 .id             = MAX8998_EN32KHZ_CP,
559                 .ops            = &max8998_others_ops,
560                 .type           = REGULATOR_VOLTAGE,
561                 .owner          = THIS_MODULE,
562         }, {
563                 .name           = "ENVICHG",
564                 .id             = MAX8998_ENVICHG,
565                 .ops            = &max8998_others_ops,
566                 .type           = REGULATOR_VOLTAGE,
567                 .owner          = THIS_MODULE,
568         }, {
569                 .name           = "ESAFEOUT1",
570                 .id             = MAX8998_ESAFEOUT1,
571                 .ops            = &max8998_others_ops,
572                 .type           = REGULATOR_VOLTAGE,
573                 .owner          = THIS_MODULE,
574         }, {
575                 .name           = "ESAFEOUT2",
576                 .id             = MAX8998_ESAFEOUT2,
577                 .ops            = &max8998_others_ops,
578                 .type           = REGULATOR_VOLTAGE,
579                 .owner          = THIS_MODULE,
580         }
581 };
582
583 static __devinit int max8998_pmic_probe(struct platform_device *pdev)
584 {
585         struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
586         struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
587         struct regulator_dev **rdev;
588         struct max8998_data *max8998;
589         int i, ret, size;
590
591         if (!pdata) {
592                 dev_err(pdev->dev.parent, "No platform init data supplied\n");
593                 return -ENODEV;
594         }
595
596         max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL);
597         if (!max8998)
598                 return -ENOMEM;
599
600         size = sizeof(struct regulator_dev *) * pdata->num_regulators;
601         max8998->rdev = kzalloc(size, GFP_KERNEL);
602         if (!max8998->rdev) {
603                 kfree(max8998);
604                 return -ENOMEM;
605         }
606
607         rdev = max8998->rdev;
608         max8998->dev = &pdev->dev;
609         max8998->iodev = iodev;
610         max8998->num_regulators = pdata->num_regulators;
611         platform_set_drvdata(pdev, max8998);
612
613         for (i = 0; i < pdata->num_regulators; i++) {
614                 const struct voltage_map_desc *desc;
615                 int id = pdata->regulators[i].id;
616                 int index = id - MAX8998_LDO2;
617
618                 desc = ldo_voltage_map[id];
619                 if (desc && regulators[index].ops != &max8998_others_ops) {
620                         int count = (desc->max - desc->min) / desc->step + 1;
621                         regulators[index].n_voltages = count;
622                 }
623                 rdev[i] = regulator_register(&regulators[index], max8998->dev,
624                                 pdata->regulators[i].initdata, max8998);
625                 if (IS_ERR(rdev[i])) {
626                         ret = PTR_ERR(rdev[i]);
627                         dev_err(max8998->dev, "regulator init failed\n");
628                         rdev[i] = NULL;
629                         goto err;
630                 }
631         }
632
633
634         return 0;
635 err:
636         for (i = 0; i < max8998->num_regulators; i++)
637                 if (rdev[i])
638                         regulator_unregister(rdev[i]);
639
640         kfree(max8998->rdev);
641         kfree(max8998);
642
643         return ret;
644 }
645
646 static int __devexit max8998_pmic_remove(struct platform_device *pdev)
647 {
648         struct max8998_data *max8998 = platform_get_drvdata(pdev);
649         struct regulator_dev **rdev = max8998->rdev;
650         int i;
651
652         for (i = 0; i < max8998->num_regulators; i++)
653                 if (rdev[i])
654                         regulator_unregister(rdev[i]);
655
656         kfree(max8998->rdev);
657         kfree(max8998);
658
659         return 0;
660 }
661
662 static struct platform_driver max8998_pmic_driver = {
663         .driver = {
664                 .name = "max8998-pmic",
665                 .owner = THIS_MODULE,
666         },
667         .probe = max8998_pmic_probe,
668         .remove = __devexit_p(max8998_pmic_remove),
669 };
670
671 static int __init max8998_pmic_init(void)
672 {
673         return platform_driver_register(&max8998_pmic_driver);
674 }
675 subsys_initcall(max8998_pmic_init);
676
677 static void __exit max8998_pmic_cleanup(void)
678 {
679         platform_driver_unregister(&max8998_pmic_driver);
680 }
681 module_exit(max8998_pmic_cleanup);
682
683 MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
684 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
685 MODULE_LICENSE("GPL");