initial commit with v3.6.7
[linux-3.6.7-moxart.git] / drivers / regulator / palmas-regulator.c
blob46c7e88f8381910004a4e46b0a3a722a1bcd7f28
1 /*
2 * Driver for Regulator part of Palmas PMIC Chips
4 * Copyright 2011-2012 Texas Instruments Inc.
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
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.
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>
26 struct regs_info {
27 char *name;
28 u8 vsel_addr;
29 u8 ctrl_addr;
30 u8 tstep_addr;
33 static const struct regs_info palmas_regs_info[] = {
35 .name = "SMPS12",
36 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
37 .ctrl_addr = PALMAS_SMPS12_CTRL,
38 .tstep_addr = PALMAS_SMPS12_TSTEP,
41 .name = "SMPS123",
42 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
43 .ctrl_addr = PALMAS_SMPS12_CTRL,
44 .tstep_addr = PALMAS_SMPS12_TSTEP,
47 .name = "SMPS3",
48 .vsel_addr = PALMAS_SMPS3_VOLTAGE,
49 .ctrl_addr = PALMAS_SMPS3_CTRL,
52 .name = "SMPS45",
53 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
54 .ctrl_addr = PALMAS_SMPS45_CTRL,
55 .tstep_addr = PALMAS_SMPS45_TSTEP,
58 .name = "SMPS457",
59 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
60 .ctrl_addr = PALMAS_SMPS45_CTRL,
61 .tstep_addr = PALMAS_SMPS45_TSTEP,
64 .name = "SMPS6",
65 .vsel_addr = PALMAS_SMPS6_VOLTAGE,
66 .ctrl_addr = PALMAS_SMPS6_CTRL,
67 .tstep_addr = PALMAS_SMPS6_TSTEP,
70 .name = "SMPS7",
71 .vsel_addr = PALMAS_SMPS7_VOLTAGE,
72 .ctrl_addr = PALMAS_SMPS7_CTRL,
75 .name = "SMPS8",
76 .vsel_addr = PALMAS_SMPS8_VOLTAGE,
77 .ctrl_addr = PALMAS_SMPS8_CTRL,
78 .tstep_addr = PALMAS_SMPS8_TSTEP,
81 .name = "SMPS9",
82 .vsel_addr = PALMAS_SMPS9_VOLTAGE,
83 .ctrl_addr = PALMAS_SMPS9_CTRL,
86 .name = "SMPS10",
89 .name = "LDO1",
90 .vsel_addr = PALMAS_LDO1_VOLTAGE,
91 .ctrl_addr = PALMAS_LDO1_CTRL,
94 .name = "LDO2",
95 .vsel_addr = PALMAS_LDO2_VOLTAGE,
96 .ctrl_addr = PALMAS_LDO2_CTRL,
99 .name = "LDO3",
100 .vsel_addr = PALMAS_LDO3_VOLTAGE,
101 .ctrl_addr = PALMAS_LDO3_CTRL,
104 .name = "LDO4",
105 .vsel_addr = PALMAS_LDO4_VOLTAGE,
106 .ctrl_addr = PALMAS_LDO4_CTRL,
109 .name = "LDO5",
110 .vsel_addr = PALMAS_LDO5_VOLTAGE,
111 .ctrl_addr = PALMAS_LDO5_CTRL,
114 .name = "LDO6",
115 .vsel_addr = PALMAS_LDO6_VOLTAGE,
116 .ctrl_addr = PALMAS_LDO6_CTRL,
119 .name = "LDO7",
120 .vsel_addr = PALMAS_LDO7_VOLTAGE,
121 .ctrl_addr = PALMAS_LDO7_CTRL,
124 .name = "LDO8",
125 .vsel_addr = PALMAS_LDO8_VOLTAGE,
126 .ctrl_addr = PALMAS_LDO8_CTRL,
129 .name = "LDO9",
130 .vsel_addr = PALMAS_LDO9_VOLTAGE,
131 .ctrl_addr = PALMAS_LDO9_CTRL,
134 .name = "LDOLN",
135 .vsel_addr = PALMAS_LDOLN_VOLTAGE,
136 .ctrl_addr = PALMAS_LDOLN_CTRL,
139 .name = "LDOUSB",
140 .vsel_addr = PALMAS_LDOUSB_VOLTAGE,
141 .ctrl_addr = PALMAS_LDOUSB_CTRL,
145 #define SMPS_CTRL_MODE_OFF 0x00
146 #define SMPS_CTRL_MODE_ON 0x01
147 #define SMPS_CTRL_MODE_ECO 0x02
148 #define SMPS_CTRL_MODE_PWM 0x03
150 /* These values are derived from the data sheet. And are the number of steps
151 * where there is a voltage change, the ranges at beginning and end of register
152 * max/min values where there are no change are ommitted.
154 * So they are basically (maxV-minV)/stepV
156 #define PALMAS_SMPS_NUM_VOLTAGES 116
157 #define PALMAS_SMPS10_NUM_VOLTAGES 2
158 #define PALMAS_LDO_NUM_VOLTAGES 50
160 #define SMPS10_VSEL (1<<3)
161 #define SMPS10_BOOST_EN (1<<2)
162 #define SMPS10_BYPASS_EN (1<<1)
163 #define SMPS10_SWITCH_EN (1<<0)
165 #define REGULATOR_SLAVE 0
167 static int palmas_smps_read(struct palmas *palmas, unsigned int reg,
168 unsigned int *dest)
170 unsigned int addr;
172 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
174 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
177 static int palmas_smps_write(struct palmas *palmas, unsigned int reg,
178 unsigned int value)
180 unsigned int addr;
182 addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg);
184 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
187 static int palmas_ldo_read(struct palmas *palmas, unsigned int reg,
188 unsigned int *dest)
190 unsigned int addr;
192 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
194 return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest);
197 static int palmas_ldo_write(struct palmas *palmas, unsigned int reg,
198 unsigned int value)
200 unsigned int addr;
202 addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg);
204 return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value);
207 static int palmas_is_enabled_smps(struct regulator_dev *dev)
209 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
210 int id = rdev_get_id(dev);
211 unsigned int reg;
213 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
215 reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
216 reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
218 return !!(reg);
221 static int palmas_enable_smps(struct regulator_dev *dev)
223 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
224 int id = rdev_get_id(dev);
225 unsigned int reg;
227 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
229 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
230 reg |= SMPS_CTRL_MODE_ON;
232 palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
234 return 0;
237 static int palmas_disable_smps(struct regulator_dev *dev)
239 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
240 int id = rdev_get_id(dev);
241 unsigned int reg;
243 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
245 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
247 palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
249 return 0;
253 static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode)
255 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
256 int id = rdev_get_id(dev);
257 unsigned int reg;
259 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
260 reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
262 switch (mode) {
263 case REGULATOR_MODE_NORMAL:
264 reg |= SMPS_CTRL_MODE_ON;
265 break;
266 case REGULATOR_MODE_IDLE:
267 reg |= SMPS_CTRL_MODE_ECO;
268 break;
269 case REGULATOR_MODE_FAST:
270 reg |= SMPS_CTRL_MODE_PWM;
271 break;
272 default:
273 return -EINVAL;
275 palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg);
277 return 0;
280 static unsigned int palmas_get_mode_smps(struct regulator_dev *dev)
282 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
283 int id = rdev_get_id(dev);
284 unsigned int reg;
286 palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
287 reg &= PALMAS_SMPS12_CTRL_STATUS_MASK;
288 reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT;
290 switch (reg) {
291 case SMPS_CTRL_MODE_ON:
292 return REGULATOR_MODE_NORMAL;
293 case SMPS_CTRL_MODE_ECO:
294 return REGULATOR_MODE_IDLE;
295 case SMPS_CTRL_MODE_PWM:
296 return REGULATOR_MODE_FAST;
299 return 0;
302 static int palmas_list_voltage_smps(struct regulator_dev *dev,
303 unsigned selector)
305 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
306 int id = rdev_get_id(dev);
307 int mult = 1;
309 if (!selector)
310 return 0;
312 /* Read the multiplier set in VSEL register to return
313 * the correct voltage.
315 if (pmic->range[id])
316 mult = 2;
318 /* Voltage is (0.49V + (selector * 0.01V)) * RANGE
319 * as defined in data sheet. RANGE is either x1 or x2
321 return (490000 + (selector * 10000)) * mult;
324 static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
326 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
327 int id = rdev_get_id(dev);
328 int selector;
329 unsigned int reg;
330 unsigned int addr;
332 addr = palmas_regs_info[id].vsel_addr;
334 palmas_smps_read(pmic->palmas, addr, &reg);
336 selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
338 /* Adjust selector to match list_voltage ranges */
339 if ((selector > 0) && (selector < 6))
340 selector = 6;
341 if (!selector)
342 selector = 5;
343 if (selector > 121)
344 selector = 121;
345 selector -= 5;
347 return selector;
350 static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
351 unsigned selector)
353 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
354 int id = rdev_get_id(dev);
355 unsigned int reg = 0;
356 unsigned int addr;
358 addr = palmas_regs_info[id].vsel_addr;
360 /* Make sure we don't change the value of RANGE */
361 if (pmic->range[id])
362 reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
364 /* Adjust the linux selector into range used in VSEL register */
365 if (selector)
366 reg |= selector + 5;
368 palmas_smps_write(pmic->palmas, addr, reg);
370 return 0;
373 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
374 int min_uV, int max_uV)
376 struct palmas_pmic *pmic = rdev_get_drvdata(rdev);
377 int id = rdev_get_id(rdev);
378 int ret, voltage;
380 if (min_uV == 0)
381 return 0;
383 if (pmic->range[id]) { /* RANGE is x2 */
384 if (min_uV < 1000000)
385 min_uV = 1000000;
386 ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
387 } else { /* RANGE is x1 */
388 if (min_uV < 500000)
389 min_uV = 500000;
390 ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
393 /* Map back into a voltage to verify we're still in bounds */
394 voltage = palmas_list_voltage_smps(rdev, ret);
395 if (voltage < min_uV || voltage > max_uV)
396 return -EINVAL;
398 return ret;
401 static struct regulator_ops palmas_ops_smps = {
402 .is_enabled = palmas_is_enabled_smps,
403 .enable = palmas_enable_smps,
404 .disable = palmas_disable_smps,
405 .set_mode = palmas_set_mode_smps,
406 .get_mode = palmas_get_mode_smps,
407 .get_voltage_sel = palmas_get_voltage_smps_sel,
408 .set_voltage_sel = palmas_set_voltage_smps_sel,
409 .list_voltage = palmas_list_voltage_smps,
410 .map_voltage = palmas_map_voltage_smps,
413 static struct regulator_ops palmas_ops_smps10 = {
414 .is_enabled = regulator_is_enabled_regmap,
415 .enable = regulator_enable_regmap,
416 .disable = regulator_disable_regmap,
417 .get_voltage_sel = regulator_get_voltage_sel_regmap,
418 .set_voltage_sel = regulator_set_voltage_sel_regmap,
419 .list_voltage = regulator_list_voltage_linear,
420 .map_voltage = regulator_map_voltage_linear,
423 static int palmas_is_enabled_ldo(struct regulator_dev *dev)
425 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
426 int id = rdev_get_id(dev);
427 unsigned int reg;
429 palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, &reg);
431 reg &= PALMAS_LDO1_CTRL_STATUS;
433 return !!(reg);
436 static int palmas_list_voltage_ldo(struct regulator_dev *dev,
437 unsigned selector)
439 if (!selector)
440 return 0;
442 /* voltage is 0.85V + (selector * 0.05v) */
443 return 850000 + (selector * 50000);
446 static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev)
448 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
449 int id = rdev_get_id(dev);
450 int selector;
451 unsigned int reg;
452 unsigned int addr;
454 addr = palmas_regs_info[id].vsel_addr;
456 palmas_ldo_read(pmic->palmas, addr, &reg);
458 selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK;
460 /* Adjust selector to match list_voltage ranges */
461 if (selector > 49)
462 selector = 49;
464 return selector;
467 static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev,
468 unsigned selector)
470 struct palmas_pmic *pmic = rdev_get_drvdata(dev);
471 int id = rdev_get_id(dev);
472 unsigned int reg = 0;
473 unsigned int addr;
475 addr = palmas_regs_info[id].vsel_addr;
477 reg = selector;
479 palmas_ldo_write(pmic->palmas, addr, reg);
481 return 0;
484 static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
485 int min_uV, int max_uV)
487 int ret, voltage;
489 if (min_uV == 0)
490 return 0;
492 if (min_uV < 900000)
493 min_uV = 900000;
494 ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1;
496 /* Map back into a voltage to verify we're still in bounds */
497 voltage = palmas_list_voltage_ldo(rdev, ret);
498 if (voltage < min_uV || voltage > max_uV)
499 return -EINVAL;
501 return ret;
504 static struct regulator_ops palmas_ops_ldo = {
505 .is_enabled = palmas_is_enabled_ldo,
506 .enable = regulator_enable_regmap,
507 .disable = regulator_disable_regmap,
508 .get_voltage_sel = palmas_get_voltage_ldo_sel,
509 .set_voltage_sel = palmas_set_voltage_ldo_sel,
510 .list_voltage = palmas_list_voltage_ldo,
511 .map_voltage = palmas_map_voltage_ldo,
515 * setup the hardware based sleep configuration of the SMPS/LDO regulators
516 * from the platform data. This is different to the software based control
517 * supported by the regulator framework as it is controlled by toggling
518 * pins on the PMIC such as PREQ, SYSEN, ...
520 static int palmas_smps_init(struct palmas *palmas, int id,
521 struct palmas_reg_init *reg_init)
523 unsigned int reg;
524 unsigned int addr;
525 int ret;
527 addr = palmas_regs_info[id].ctrl_addr;
529 ret = palmas_smps_read(palmas, addr, &reg);
530 if (ret)
531 return ret;
533 switch (id) {
534 case PALMAS_REG_SMPS10:
535 if (reg_init->mode_sleep) {
536 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
537 reg |= reg_init->mode_sleep <<
538 PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT;
540 break;
541 default:
542 if (reg_init->warm_reset)
543 reg |= PALMAS_SMPS12_CTRL_WR_S;
545 if (reg_init->roof_floor)
546 reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN;
548 if (reg_init->mode_sleep) {
549 reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK;
550 reg |= reg_init->mode_sleep <<
551 PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT;
555 ret = palmas_smps_write(palmas, addr, reg);
556 if (ret)
557 return ret;
559 if (palmas_regs_info[id].tstep_addr && reg_init->tstep) {
560 addr = palmas_regs_info[id].tstep_addr;
562 reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK;
564 ret = palmas_smps_write(palmas, addr, reg);
565 if (ret)
566 return ret;
569 if (palmas_regs_info[id].vsel_addr && reg_init->vsel) {
570 addr = palmas_regs_info[id].vsel_addr;
572 reg = reg_init->vsel;
574 ret = palmas_smps_write(palmas, addr, reg);
575 if (ret)
576 return ret;
580 return 0;
583 static int palmas_ldo_init(struct palmas *palmas, int id,
584 struct palmas_reg_init *reg_init)
586 unsigned int reg;
587 unsigned int addr;
588 int ret;
590 addr = palmas_regs_info[id].ctrl_addr;
592 ret = palmas_ldo_read(palmas, addr, &reg);
593 if (ret)
594 return ret;
596 if (reg_init->warm_reset)
597 reg |= PALMAS_LDO1_CTRL_WR_S;
599 if (reg_init->mode_sleep)
600 reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
602 ret = palmas_ldo_write(palmas, addr, reg);
603 if (ret)
604 return ret;
606 return 0;
609 static __devinit int palmas_probe(struct platform_device *pdev)
611 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
612 struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data;
613 struct regulator_dev *rdev;
614 struct regulator_config config = { };
615 struct palmas_pmic *pmic;
616 struct palmas_reg_init *reg_init;
617 int id = 0, ret;
618 unsigned int addr, reg;
620 if (!pdata)
621 return -EINVAL;
622 if (!pdata->reg_data)
623 return -EINVAL;
625 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
626 if (!pmic)
627 return -ENOMEM;
629 pmic->dev = &pdev->dev;
630 pmic->palmas = palmas;
631 palmas->pmic = pmic;
632 platform_set_drvdata(pdev, pmic);
634 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
635 if (ret)
636 return ret;
638 if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN)
639 pmic->smps123 = 1;
641 if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN)
642 pmic->smps457 = 1;
644 config.regmap = palmas->regmap[REGULATOR_SLAVE];
645 config.dev = &pdev->dev;
646 config.driver_data = pmic;
648 for (id = 0; id < PALMAS_REG_LDO1; id++) {
651 * Miss out regulators which are not available due
652 * to slaving configurations.
654 switch (id) {
655 case PALMAS_REG_SMPS12:
656 case PALMAS_REG_SMPS3:
657 if (pmic->smps123)
658 continue;
659 break;
660 case PALMAS_REG_SMPS123:
661 if (!pmic->smps123)
662 continue;
663 break;
664 case PALMAS_REG_SMPS45:
665 case PALMAS_REG_SMPS7:
666 if (pmic->smps457)
667 continue;
668 break;
669 case PALMAS_REG_SMPS457:
670 if (!pmic->smps457)
671 continue;
674 /* Register the regulators */
675 pmic->desc[id].name = palmas_regs_info[id].name;
676 pmic->desc[id].id = id;
678 switch (id) {
679 case PALMAS_REG_SMPS10:
680 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
681 pmic->desc[id].ops = &palmas_ops_smps10;
682 pmic->desc[id].vsel_reg =
683 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
684 PALMAS_SMPS10_CTRL);
685 pmic->desc[id].vsel_mask = SMPS10_VSEL;
686 pmic->desc[id].enable_reg =
687 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
688 PALMAS_SMPS10_STATUS);
689 pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
690 pmic->desc[id].min_uV = 3750000;
691 pmic->desc[id].uV_step = 1250000;
692 break;
693 default:
694 pmic->desc[id].ops = &palmas_ops_smps;
695 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
698 pmic->desc[id].type = REGULATOR_VOLTAGE;
699 pmic->desc[id].owner = THIS_MODULE;
701 /* Initialise sleep/init values from platform data */
702 if (pdata && pdata->reg_init) {
703 reg_init = pdata->reg_init[id];
704 if (reg_init) {
705 ret = palmas_smps_init(palmas, id, reg_init);
706 if (ret)
707 goto err_unregister_regulator;
712 * read and store the RANGE bit for later use
713 * This must be done before regulator is probed otherwise
714 * we error in probe with unsuportable ranges.
716 if (id != PALMAS_REG_SMPS10) {
717 addr = palmas_regs_info[id].vsel_addr;
719 ret = palmas_smps_read(pmic->palmas, addr, &reg);
720 if (ret)
721 goto err_unregister_regulator;
722 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
723 pmic->range[id] = 1;
726 if (pdata && pdata->reg_data)
727 config.init_data = pdata->reg_data[id];
728 else
729 config.init_data = NULL;
731 rdev = regulator_register(&pmic->desc[id], &config);
732 if (IS_ERR(rdev)) {
733 dev_err(&pdev->dev,
734 "failed to register %s regulator\n",
735 pdev->name);
736 ret = PTR_ERR(rdev);
737 goto err_unregister_regulator;
740 /* Save regulator for cleanup */
741 pmic->rdev[id] = rdev;
744 /* Start this loop from the id left from previous loop */
745 for (; id < PALMAS_NUM_REGS; id++) {
747 /* Miss out regulators which are not available due
748 * to alternate functions.
751 /* Register the regulators */
752 pmic->desc[id].name = palmas_regs_info[id].name;
753 pmic->desc[id].id = id;
754 pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES;
756 pmic->desc[id].ops = &palmas_ops_ldo;
758 pmic->desc[id].type = REGULATOR_VOLTAGE;
759 pmic->desc[id].owner = THIS_MODULE;
760 pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
761 palmas_regs_info[id].ctrl_addr);
762 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
764 if (pdata && pdata->reg_data)
765 config.init_data = pdata->reg_data[id];
766 else
767 config.init_data = NULL;
769 rdev = regulator_register(&pmic->desc[id], &config);
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;
778 /* Save regulator for cleanup */
779 pmic->rdev[id] = rdev;
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 regulator_unregister(pmic->rdev[id]);
788 goto err_unregister_regulator;
794 return 0;
796 err_unregister_regulator:
797 while (--id >= 0)
798 regulator_unregister(pmic->rdev[id]);
799 return ret;
802 static int __devexit palmas_remove(struct platform_device *pdev)
804 struct palmas_pmic *pmic = platform_get_drvdata(pdev);
805 int id;
807 for (id = 0; id < PALMAS_NUM_REGS; id++)
808 regulator_unregister(pmic->rdev[id]);
809 return 0;
812 static struct platform_driver palmas_driver = {
813 .driver = {
814 .name = "palmas-pmic",
815 .owner = THIS_MODULE,
817 .probe = palmas_probe,
818 .remove = __devexit_p(palmas_remove),
821 static int __init palmas_init(void)
823 return platform_driver_register(&palmas_driver);
825 subsys_initcall(palmas_init);
827 static void __exit palmas_exit(void)
829 platform_driver_unregister(&palmas_driver);
831 module_exit(palmas_exit);
833 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
834 MODULE_DESCRIPTION("Palmas voltage regulator driver");
835 MODULE_LICENSE("GPL");
836 MODULE_ALIAS("platform:palmas-pmic");