2 * Copyright (C) ST-Ericsson SA 2010
4 * License Terms: GNU General Public License v2
6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
9 * AB8500 peripheral regulators
11 * AB8500 supports the following regulators:
12 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/err.h>
18 #include <linux/platform_device.h>
19 #include <linux/mfd/abx500.h>
20 #include <linux/mfd/abx500/ab8500.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/machine.h>
25 #include <linux/regulator/ab8500.h>
26 #include <linux/slab.h>
29 * struct ab8500_regulator_info - ab8500 regulator information
30 * @dev: device pointer
31 * @desc: regulator description
32 * @regulator_dev: regulator device
33 * @is_enabled: status of regulator (on/off)
34 * @load_lp_uA: maximum load in idle (low power) mode
35 * @update_bank: bank to control on/off
36 * @update_reg: register to control on/off
37 * @update_mask: mask to enable/disable and set mode of regulator
38 * @update_val: bits holding the regulator current mode
39 * @update_val_idle: bits to enable the regulator in idle (low power) mode
40 * @update_val_normal: bits to enable the regulator in normal (high power) mode
41 * @voltage_bank: bank to control regulator voltage
42 * @voltage_reg: register to control regulator voltage
43 * @voltage_mask: mask to control regulator voltage
44 * @voltage_shift: shift to control regulator voltage
45 * @delay: startup/set voltage delay in us
47 struct ab8500_regulator_info {
49 struct regulator_desc desc;
50 struct regulator_dev *regulator;
66 /* voltage tables for the vauxn/vintcore supplies */
67 static const unsigned int ldo_vauxn_voltages[] = {
86 static const unsigned int ldo_vaux3_voltages[] = {
97 static const unsigned int ldo_vintcore_voltages[] = {
107 static int ab8500_regulator_enable(struct regulator_dev *rdev)
110 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
113 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
117 ret = abx500_mask_and_set_register_interruptible(info->dev,
118 info->update_bank, info->update_reg,
119 info->update_mask, info->update_val);
121 dev_err(rdev_get_dev(rdev),
122 "couldn't set enable bits for regulator\n");
124 info->is_enabled = true;
126 dev_vdbg(rdev_get_dev(rdev),
127 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
128 info->desc.name, info->update_bank, info->update_reg,
129 info->update_mask, info->update_val);
134 static int ab8500_regulator_disable(struct regulator_dev *rdev)
137 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
140 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
144 ret = abx500_mask_and_set_register_interruptible(info->dev,
145 info->update_bank, info->update_reg,
146 info->update_mask, 0x0);
148 dev_err(rdev_get_dev(rdev),
149 "couldn't set disable bits for regulator\n");
151 info->is_enabled = false;
153 dev_vdbg(rdev_get_dev(rdev),
154 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
155 info->desc.name, info->update_bank, info->update_reg,
156 info->update_mask, 0x0);
161 static unsigned int ab8500_regulator_get_optimum_mode(
162 struct regulator_dev *rdev, int input_uV,
163 int output_uV, int load_uA)
167 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
170 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
174 if (load_uA <= info->load_lp_uA)
175 mode = REGULATOR_MODE_IDLE;
177 mode = REGULATOR_MODE_NORMAL;
182 static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
187 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
190 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
195 case REGULATOR_MODE_NORMAL:
196 info->update_val = info->update_val_normal;
198 case REGULATOR_MODE_IDLE:
199 info->update_val = info->update_val_idle;
205 if (info->is_enabled) {
206 ret = abx500_mask_and_set_register_interruptible(info->dev,
207 info->update_bank, info->update_reg,
208 info->update_mask, info->update_val);
210 dev_err(rdev_get_dev(rdev),
211 "couldn't set regulator mode\n");
213 dev_vdbg(rdev_get_dev(rdev),
214 "%s-set_mode (bank, reg, mask, value): "
215 "0x%x, 0x%x, 0x%x, 0x%x\n",
216 info->desc.name, info->update_bank, info->update_reg,
217 info->update_mask, info->update_val);
223 static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
225 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
229 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
233 if (info->update_val == info->update_val_normal)
234 ret = REGULATOR_MODE_NORMAL;
235 else if (info->update_val == info->update_val_idle)
236 ret = REGULATOR_MODE_IDLE;
243 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
246 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
250 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
254 ret = abx500_get_register_interruptible(info->dev,
255 info->update_bank, info->update_reg, ®val);
257 dev_err(rdev_get_dev(rdev),
258 "couldn't read 0x%x register\n", info->update_reg);
262 dev_vdbg(rdev_get_dev(rdev),
263 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
265 info->desc.name, info->update_bank, info->update_reg,
266 info->update_mask, regval);
268 if (regval & info->update_mask)
269 info->is_enabled = true;
271 info->is_enabled = false;
273 return info->is_enabled;
276 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
279 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
283 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
287 ret = abx500_get_register_interruptible(info->dev,
288 info->voltage_bank, info->voltage_reg, ®val);
290 dev_err(rdev_get_dev(rdev),
291 "couldn't read voltage reg for regulator\n");
295 dev_vdbg(rdev_get_dev(rdev),
296 "%s-get_voltage (bank, reg, mask, shift, value): "
297 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
298 info->desc.name, info->voltage_bank,
299 info->voltage_reg, info->voltage_mask,
300 info->voltage_shift, regval);
302 val = regval & info->voltage_mask;
303 return val >> info->voltage_shift;
306 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
310 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
314 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
318 /* set the registers for the request */
319 regval = (u8)selector << info->voltage_shift;
320 ret = abx500_mask_and_set_register_interruptible(info->dev,
321 info->voltage_bank, info->voltage_reg,
322 info->voltage_mask, regval);
324 dev_err(rdev_get_dev(rdev),
325 "couldn't set voltage reg for regulator\n");
327 dev_vdbg(rdev_get_dev(rdev),
328 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
330 info->desc.name, info->voltage_bank, info->voltage_reg,
331 info->voltage_mask, regval);
336 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
337 unsigned int old_sel,
338 unsigned int new_sel)
340 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
345 static struct regulator_ops ab8500_regulator_volt_mode_ops = {
346 .enable = ab8500_regulator_enable,
347 .disable = ab8500_regulator_disable,
348 .is_enabled = ab8500_regulator_is_enabled,
349 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
350 .set_mode = ab8500_regulator_set_mode,
351 .get_mode = ab8500_regulator_get_mode,
352 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
353 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
354 .list_voltage = regulator_list_voltage_table,
355 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
358 static struct regulator_ops ab8500_regulator_mode_ops = {
359 .enable = ab8500_regulator_enable,
360 .disable = ab8500_regulator_disable,
361 .is_enabled = ab8500_regulator_is_enabled,
362 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
363 .set_mode = ab8500_regulator_set_mode,
364 .get_mode = ab8500_regulator_get_mode,
365 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
366 .list_voltage = regulator_list_voltage_table,
367 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
370 static struct regulator_ops ab8500_regulator_ops = {
371 .enable = ab8500_regulator_enable,
372 .disable = ab8500_regulator_disable,
373 .is_enabled = ab8500_regulator_is_enabled,
374 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
375 .list_voltage = regulator_list_voltage_table,
378 static struct ab8500_regulator_info
379 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
381 * Variable Voltage Regulators
382 * name, min mV, max mV,
383 * update bank, reg, mask, enable val
384 * volt bank, reg, mask
386 [AB8500_LDO_AUX1] = {
389 .ops = &ab8500_regulator_volt_mode_ops,
390 .type = REGULATOR_VOLTAGE,
391 .id = AB8500_LDO_AUX1,
392 .owner = THIS_MODULE,
393 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
394 .volt_table = ldo_vauxn_voltages,
401 .update_val_idle = 0x03,
402 .update_val_normal = 0x01,
403 .voltage_bank = 0x04,
405 .voltage_mask = 0x0f,
407 [AB8500_LDO_AUX2] = {
410 .ops = &ab8500_regulator_volt_mode_ops,
411 .type = REGULATOR_VOLTAGE,
412 .id = AB8500_LDO_AUX2,
413 .owner = THIS_MODULE,
414 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
415 .volt_table = ldo_vauxn_voltages,
422 .update_val_idle = 0x0c,
423 .update_val_normal = 0x04,
424 .voltage_bank = 0x04,
426 .voltage_mask = 0x0f,
428 [AB8500_LDO_AUX3] = {
431 .ops = &ab8500_regulator_volt_mode_ops,
432 .type = REGULATOR_VOLTAGE,
433 .id = AB8500_LDO_AUX3,
434 .owner = THIS_MODULE,
435 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
436 .volt_table = ldo_vaux3_voltages,
443 .update_val_idle = 0x03,
444 .update_val_normal = 0x01,
445 .voltage_bank = 0x04,
447 .voltage_mask = 0x07,
449 [AB8500_LDO_INTCORE] = {
451 .name = "LDO-INTCORE",
452 .ops = &ab8500_regulator_volt_mode_ops,
453 .type = REGULATOR_VOLTAGE,
454 .id = AB8500_LDO_INTCORE,
455 .owner = THIS_MODULE,
456 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
457 .volt_table = ldo_vintcore_voltages,
464 .update_val_idle = 0x44,
465 .update_val_normal = 0x04,
466 .voltage_bank = 0x03,
468 .voltage_mask = 0x38,
473 * Fixed Voltage Regulators
475 * update bank, reg, mask, enable val
477 [AB8500_LDO_TVOUT] = {
480 .ops = &ab8500_regulator_mode_ops,
481 .type = REGULATOR_VOLTAGE,
482 .id = AB8500_LDO_TVOUT,
483 .owner = THIS_MODULE,
486 .enable_time = 10000,
494 .update_val_idle = 0x82,
495 .update_val_normal = 0x02,
500 .ops = &ab8500_regulator_fixed_ops,
501 .type = REGULATOR_VOLTAGE,
502 .id = AB8500_LDO_USB,
503 .owner = THIS_MODULE,
513 * Regulators with fixed voltage and normal mode
515 [AB8500_LDO_AUDIO] = {
518 .ops = &ab8500_regulator_ops,
519 .type = REGULATOR_VOLTAGE,
520 .id = AB8500_LDO_AUDIO,
521 .owner = THIS_MODULE,
530 [AB8500_LDO_ANAMIC1] = {
532 .name = "LDO-ANAMIC1",
533 .ops = &ab8500_regulator_ops,
534 .type = REGULATOR_VOLTAGE,
535 .id = AB8500_LDO_ANAMIC1,
536 .owner = THIS_MODULE,
545 [AB8500_LDO_ANAMIC2] = {
547 .name = "LDO-ANAMIC2",
548 .ops = &ab8500_regulator_ops,
549 .type = REGULATOR_VOLTAGE,
550 .id = AB8500_LDO_ANAMIC2,
551 .owner = THIS_MODULE,
560 [AB8500_LDO_DMIC] = {
563 .ops = &ab8500_regulator_ops,
564 .type = REGULATOR_VOLTAGE,
565 .id = AB8500_LDO_DMIC,
566 .owner = THIS_MODULE,
577 * Regulators with fixed voltage and normal/idle modes
582 .ops = &ab8500_regulator_mode_ops,
583 .type = REGULATOR_VOLTAGE,
584 .id = AB8500_LDO_ANA,
585 .owner = THIS_MODULE,
594 .update_val_idle = 0x0c,
595 .update_val_normal = 0x04,
601 struct ab8500_reg_init {
607 #define REG_INIT(_id, _bank, _addr, _mask) \
614 static struct ab8500_reg_init ab8500_reg_init[] = {
616 * 0x30, VanaRequestCtrl
617 * 0x0c, VpllRequestCtrl
618 * 0xc0, VextSupply1RequestCtrl
620 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
622 * 0x03, VextSupply2RequestCtrl
623 * 0x0c, VextSupply3RequestCtrl
624 * 0x30, Vaux1RequestCtrl
625 * 0xc0, Vaux2RequestCtrl
627 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
629 * 0x03, Vaux3RequestCtrl
632 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
634 * 0x01, Vsmps1SysClkReq1HPValid
635 * 0x02, Vsmps2SysClkReq1HPValid
636 * 0x04, Vsmps3SysClkReq1HPValid
637 * 0x08, VanaSysClkReq1HPValid
638 * 0x10, VpllSysClkReq1HPValid
639 * 0x20, Vaux1SysClkReq1HPValid
640 * 0x40, Vaux2SysClkReq1HPValid
641 * 0x80, Vaux3SysClkReq1HPValid
643 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff),
645 * 0x10, VextSupply1SysClkReq1HPValid
646 * 0x20, VextSupply2SysClkReq1HPValid
647 * 0x40, VextSupply3SysClkReq1HPValid
649 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
651 * 0x08, VanaHwHPReq1Valid
652 * 0x20, Vaux1HwHPReq1Valid
653 * 0x40, Vaux2HwHPReq1Valid
654 * 0x80, Vaux3HwHPReq1Valid
656 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
658 * 0x01, VextSupply1HwHPReq1Valid
659 * 0x02, VextSupply2HwHPReq1Valid
660 * 0x04, VextSupply3HwHPReq1Valid
662 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
664 * 0x08, VanaHwHPReq2Valid
665 * 0x20, Vaux1HwHPReq2Valid
666 * 0x40, Vaux2HwHPReq2Valid
667 * 0x80, Vaux3HwHPReq2Valid
669 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
671 * 0x01, VextSupply1HwHPReq2Valid
672 * 0x02, VextSupply2HwHPReq2Valid
673 * 0x04, VextSupply3HwHPReq2Valid
675 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
677 * 0x20, VanaSwHPReqValid
678 * 0x80, Vaux1SwHPReqValid
680 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
682 * 0x01, Vaux2SwHPReqValid
683 * 0x02, Vaux3SwHPReqValid
684 * 0x04, VextSupply1SwHPReqValid
685 * 0x08, VextSupply2SwHPReqValid
686 * 0x10, VextSupply3SwHPReqValid
688 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
690 * 0x02, SysClkReq2Valid1
692 * 0x80, SysClkReq8Valid1
694 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
696 * 0x02, SysClkReq2Valid2
698 * 0x80, SysClkReq8Valid2
700 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
703 * 0x04, Vintcore12Ena
704 * 0x38, Vintcore12Sel
708 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
715 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
720 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
724 * NOTE! PRCMU register
726 REG_INIT(AB8500_ARMREGU2, 0x04, 0x01, 0x0f),
730 * NOTE! PRCMU register
732 REG_INIT(AB8500_VBBSEL1, 0x04, 0x11, 0x0f),
736 * NOTE! PRCMU register
738 REG_INIT(AB8500_VBBSEL2, 0x04, 0x12, 0x0f),
741 * 0x0c, Vsmps1SelCtrl
743 REG_INIT(AB8500_VSMPS1REGU, 0x04, 0x03, 0x0f),
746 * 0x0c, Vsmps2SelCtrl
748 REG_INIT(AB8500_VSMPS2REGU, 0x04, 0x04, 0x0f),
753 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
756 * 0x02, VrefDDRSleepMode
758 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
760 * 0x03, VextSupply1Regu
761 * 0x0c, VextSupply2Regu
762 * 0x30, VextSupply3Regu
763 * 0x40, ExtSupply2Bypass
764 * 0x80, ExtSupply3Bypass
766 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
771 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
776 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f),
780 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
784 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
788 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
792 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
794 * 0x01, VextSupply12LP
796 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
801 * 0x20, Vintcore12Disch
805 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
808 * 0x04, VdmicPullDownEna
811 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
815 ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
819 if (value & ~ab8500_reg_init[id].mask) {
821 "Configuration error: value outside mask.\n");
825 err = abx500_mask_and_set_register_interruptible(
827 ab8500_reg_init[id].bank,
828 ab8500_reg_init[id].addr,
829 ab8500_reg_init[id].mask,
833 "Failed to initialize 0x%02x, 0x%02x.\n",
834 ab8500_reg_init[id].bank,
835 ab8500_reg_init[id].addr);
840 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
841 ab8500_reg_init[id].bank,
842 ab8500_reg_init[id].addr,
843 ab8500_reg_init[id].mask,
849 static int ab8500_regulator_register(struct platform_device *pdev,
850 struct regulator_init_data *init_data,
852 struct device_node *np)
854 struct ab8500_regulator_info *info = NULL;
855 struct regulator_config config = { };
858 /* assign per-regulator data */
859 info = &ab8500_regulator_info[id];
860 info->dev = &pdev->dev;
862 config.dev = &pdev->dev;
863 config.init_data = init_data;
864 config.driver_data = info;
867 /* fix for hardware before ab8500v2.0 */
868 if (abx500_get_chip_id(info->dev) < 0x20) {
869 if (info->desc.id == AB8500_LDO_AUX3) {
870 info->desc.n_voltages =
871 ARRAY_SIZE(ldo_vauxn_voltages);
872 info->desc.volt_table = ldo_vauxn_voltages;
873 info->voltage_mask = 0xf;
877 /* register regulator with framework */
878 info->regulator = regulator_register(&info->desc, &config);
879 if (IS_ERR(info->regulator)) {
880 err = PTR_ERR(info->regulator);
881 dev_err(&pdev->dev, "failed to register regulator %s\n",
883 /* when we fail, un-register all earlier regulators */
885 info = &ab8500_regulator_info[id];
886 regulator_unregister(info->regulator);
894 static struct of_regulator_match ab8500_regulator_matches[] = {
895 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
896 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
897 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
898 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
899 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
900 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
901 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
902 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
903 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
904 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
905 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
909 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
913 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
914 err = ab8500_regulator_register(
915 pdev, ab8500_regulator_matches[i].init_data,
916 i, ab8500_regulator_matches[i].of_node);
924 static int ab8500_regulator_probe(struct platform_device *pdev)
926 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
927 struct ab8500_platform_data *pdata;
928 struct device_node *np = pdev->dev.of_node;
932 err = of_regulator_match(&pdev->dev, np,
933 ab8500_regulator_matches,
934 ARRAY_SIZE(ab8500_regulator_matches));
937 "Error parsing regulator init data: %d\n", err);
941 err = ab8500_regulator_of_probe(pdev, np);
946 dev_err(&pdev->dev, "null mfd parent\n");
949 pdata = dev_get_platdata(ab8500->dev);
951 dev_err(&pdev->dev, "null pdata\n");
955 /* make sure the platform data has the correct size */
956 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
957 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
961 /* initialize registers */
962 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
965 id = pdata->regulator_reg_init[i].id;
966 value = pdata->regulator_reg_init[i].value;
968 /* check for configuration errors */
969 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
971 "Configuration error: id outside range.\n");
975 err = ab8500_regulator_init_registers(pdev, id, value);
980 /* register all regulators */
981 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
982 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
990 static int ab8500_regulator_remove(struct platform_device *pdev)
994 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
995 struct ab8500_regulator_info *info = NULL;
996 info = &ab8500_regulator_info[i];
998 dev_vdbg(rdev_get_dev(info->regulator),
999 "%s-remove\n", info->desc.name);
1001 regulator_unregister(info->regulator);
1007 static struct platform_driver ab8500_regulator_driver = {
1008 .probe = ab8500_regulator_probe,
1009 .remove = ab8500_regulator_remove,
1011 .name = "ab8500-regulator",
1012 .owner = THIS_MODULE,
1016 static int __init ab8500_regulator_init(void)
1020 ret = platform_driver_register(&ab8500_regulator_driver);
1022 pr_err("Failed to register ab8500 regulator: %d\n", ret);
1026 subsys_initcall(ab8500_regulator_init);
1028 static void __exit ab8500_regulator_exit(void)
1030 platform_driver_unregister(&ab8500_regulator_driver);
1032 module_exit(ab8500_regulator_exit);
1034 MODULE_LICENSE("GPL v2");
1035 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
1036 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
1037 MODULE_ALIAS("platform:ab8500-regulator");