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
46 struct ab8500_regulator_info {
48 struct regulator_desc desc;
49 struct regulator_dev *regulator;
64 /* voltage tables for the vauxn/vintcore supplies */
65 static const unsigned int ldo_vauxn_voltages[] = {
84 static const unsigned int ldo_vaux3_voltages[] = {
95 static const unsigned int ldo_vintcore_voltages[] = {
105 static int ab8500_regulator_enable(struct regulator_dev *rdev)
108 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
111 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
115 ret = abx500_mask_and_set_register_interruptible(info->dev,
116 info->update_bank, info->update_reg,
117 info->update_mask, info->update_val);
119 dev_err(rdev_get_dev(rdev),
120 "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");
153 info->is_enabled = false;
155 dev_vdbg(rdev_get_dev(rdev),
156 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
157 info->desc.name, info->update_bank, info->update_reg,
158 info->update_mask, 0x0);
163 static unsigned int ab8500_regulator_get_optimum_mode(
164 struct regulator_dev *rdev, int input_uV,
165 int output_uV, int load_uA)
169 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
172 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
176 if (load_uA <= info->load_lp_uA)
177 mode = REGULATOR_MODE_IDLE;
179 mode = REGULATOR_MODE_NORMAL;
184 static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
189 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
192 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
197 case REGULATOR_MODE_NORMAL:
198 info->update_val = info->update_val_normal;
200 case REGULATOR_MODE_IDLE:
201 info->update_val = info->update_val_idle;
207 if (info->is_enabled) {
208 ret = abx500_mask_and_set_register_interruptible(info->dev,
209 info->update_bank, info->update_reg,
210 info->update_mask, info->update_val);
212 dev_err(rdev_get_dev(rdev),
213 "couldn't set regulator mode\n");
215 dev_vdbg(rdev_get_dev(rdev),
216 "%s-set_mode (bank, reg, mask, value): "
217 "0x%x, 0x%x, 0x%x, 0x%x\n",
218 info->desc.name, info->update_bank, info->update_reg,
219 info->update_mask, info->update_val);
225 static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
227 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
231 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
235 if (info->update_val == info->update_val_normal)
236 ret = REGULATOR_MODE_NORMAL;
237 else if (info->update_val == info->update_val_idle)
238 ret = REGULATOR_MODE_IDLE;
245 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
248 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
252 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
256 ret = abx500_get_register_interruptible(info->dev,
257 info->update_bank, info->update_reg, ®val);
259 dev_err(rdev_get_dev(rdev),
260 "couldn't read 0x%x register\n", info->update_reg);
264 dev_vdbg(rdev_get_dev(rdev),
265 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
267 info->desc.name, info->update_bank, info->update_reg,
268 info->update_mask, regval);
270 if (regval & info->update_mask)
271 info->is_enabled = true;
273 info->is_enabled = false;
275 return info->is_enabled;
278 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
281 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
285 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
289 ret = abx500_get_register_interruptible(info->dev,
290 info->voltage_bank, info->voltage_reg, ®val);
292 dev_err(rdev_get_dev(rdev),
293 "couldn't read voltage reg for regulator\n");
297 dev_vdbg(rdev_get_dev(rdev),
298 "%s-get_voltage (bank, reg, mask, shift, value): "
299 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
300 info->desc.name, info->voltage_bank,
301 info->voltage_reg, info->voltage_mask,
302 info->voltage_shift, regval);
304 val = regval & info->voltage_mask;
305 return val >> info->voltage_shift;
308 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
312 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
316 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
320 /* set the registers for the request */
321 regval = (u8)selector << info->voltage_shift;
322 ret = abx500_mask_and_set_register_interruptible(info->dev,
323 info->voltage_bank, info->voltage_reg,
324 info->voltage_mask, regval);
326 dev_err(rdev_get_dev(rdev),
327 "couldn't set voltage reg for regulator\n");
329 dev_vdbg(rdev_get_dev(rdev),
330 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
332 info->desc.name, info->voltage_bank, info->voltage_reg,
333 info->voltage_mask, regval);
338 static struct regulator_ops ab8500_regulator_volt_mode_ops = {
339 .enable = ab8500_regulator_enable,
340 .disable = ab8500_regulator_disable,
341 .is_enabled = ab8500_regulator_is_enabled,
342 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
343 .set_mode = ab8500_regulator_set_mode,
344 .get_mode = ab8500_regulator_get_mode,
345 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
346 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
347 .list_voltage = regulator_list_voltage_table,
350 static struct regulator_ops ab8500_regulator_mode_ops = {
351 .enable = ab8500_regulator_enable,
352 .disable = ab8500_regulator_disable,
353 .is_enabled = ab8500_regulator_is_enabled,
354 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
355 .set_mode = ab8500_regulator_set_mode,
356 .get_mode = ab8500_regulator_get_mode,
357 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
358 .list_voltage = regulator_list_voltage_linear,
361 static struct regulator_ops ab8500_regulator_ops = {
362 .enable = ab8500_regulator_enable,
363 .disable = ab8500_regulator_disable,
364 .is_enabled = ab8500_regulator_is_enabled,
365 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
366 .list_voltage = regulator_list_voltage_linear,
369 static struct ab8500_regulator_info
370 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
372 * Variable Voltage Regulators
373 * name, min mV, max mV,
374 * update bank, reg, mask, enable val
375 * volt bank, reg, mask
377 [AB8500_LDO_AUX1] = {
380 .ops = &ab8500_regulator_volt_mode_ops,
381 .type = REGULATOR_VOLTAGE,
382 .id = AB8500_LDO_AUX1,
383 .owner = THIS_MODULE,
384 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
385 .volt_table = ldo_vauxn_voltages,
393 .update_val_idle = 0x03,
394 .update_val_normal = 0x01,
395 .voltage_bank = 0x04,
397 .voltage_mask = 0x0f,
399 [AB8500_LDO_AUX2] = {
402 .ops = &ab8500_regulator_volt_mode_ops,
403 .type = REGULATOR_VOLTAGE,
404 .id = AB8500_LDO_AUX2,
405 .owner = THIS_MODULE,
406 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
407 .volt_table = ldo_vauxn_voltages,
415 .update_val_idle = 0x0c,
416 .update_val_normal = 0x04,
417 .voltage_bank = 0x04,
419 .voltage_mask = 0x0f,
421 [AB8500_LDO_AUX3] = {
424 .ops = &ab8500_regulator_volt_mode_ops,
425 .type = REGULATOR_VOLTAGE,
426 .id = AB8500_LDO_AUX3,
427 .owner = THIS_MODULE,
428 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
429 .volt_table = ldo_vaux3_voltages,
437 .update_val_idle = 0x03,
438 .update_val_normal = 0x01,
439 .voltage_bank = 0x04,
441 .voltage_mask = 0x07,
443 [AB8500_LDO_INTCORE] = {
445 .name = "LDO-INTCORE",
446 .ops = &ab8500_regulator_volt_mode_ops,
447 .type = REGULATOR_VOLTAGE,
448 .id = AB8500_LDO_INTCORE,
449 .owner = THIS_MODULE,
450 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
451 .volt_table = ldo_vintcore_voltages,
459 .update_val_idle = 0x44,
460 .update_val_normal = 0x04,
461 .voltage_bank = 0x03,
463 .voltage_mask = 0x38,
468 * Fixed Voltage Regulators
470 * update bank, reg, mask, enable val
472 [AB8500_LDO_TVOUT] = {
475 .ops = &ab8500_regulator_mode_ops,
476 .type = REGULATOR_VOLTAGE,
477 .id = AB8500_LDO_TVOUT,
478 .owner = THIS_MODULE,
481 .enable_time = 10000,
488 .update_val_idle = 0x82,
489 .update_val_normal = 0x02,
493 * Regulators with fixed voltage and normal mode
498 .ops = &ab8500_regulator_ops,
499 .type = REGULATOR_VOLTAGE,
500 .id = AB8500_LDO_USB,
501 .owner = THIS_MODULE,
510 [AB8500_LDO_AUDIO] = {
513 .ops = &ab8500_regulator_ops,
514 .type = REGULATOR_VOLTAGE,
515 .id = AB8500_LDO_AUDIO,
516 .owner = THIS_MODULE,
526 [AB8500_LDO_ANAMIC1] = {
528 .name = "LDO-ANAMIC1",
529 .ops = &ab8500_regulator_ops,
530 .type = REGULATOR_VOLTAGE,
531 .id = AB8500_LDO_ANAMIC1,
532 .owner = THIS_MODULE,
542 [AB8500_LDO_ANAMIC2] = {
544 .name = "LDO-ANAMIC2",
545 .ops = &ab8500_regulator_ops,
546 .type = REGULATOR_VOLTAGE,
547 .id = AB8500_LDO_ANAMIC2,
548 .owner = THIS_MODULE,
558 [AB8500_LDO_DMIC] = {
561 .ops = &ab8500_regulator_ops,
562 .type = REGULATOR_VOLTAGE,
563 .id = AB8500_LDO_DMIC,
564 .owner = THIS_MODULE,
576 * Regulators with fixed voltage and normal/idle modes
581 .ops = &ab8500_regulator_mode_ops,
582 .type = REGULATOR_VOLTAGE,
583 .id = AB8500_LDO_ANA,
584 .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 * 0x03, VarmRequestCtrl
617 * 0x0c, VapeRequestCtrl
618 * 0x30, Vsmps1RequestCtrl
619 * 0xc0, Vsmps2RequestCtrl
621 REG_INIT(AB8500_REGUREQUESTCTRL1, 0x03, 0x03, 0xff),
623 * 0x03, Vsmps3RequestCtrl
624 * 0x0c, VpllRequestCtrl
625 * 0x30, VanaRequestCtrl
626 * 0xc0, VextSupply1RequestCtrl
628 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xff),
630 * 0x03, VextSupply2RequestCtrl
631 * 0x0c, VextSupply3RequestCtrl
632 * 0x30, Vaux1RequestCtrl
633 * 0xc0, Vaux2RequestCtrl
635 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
637 * 0x03, Vaux3RequestCtrl
640 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
642 * 0x01, Vsmps1SysClkReq1HPValid
643 * 0x02, Vsmps2SysClkReq1HPValid
644 * 0x04, Vsmps3SysClkReq1HPValid
645 * 0x08, VanaSysClkReq1HPValid
646 * 0x10, VpllSysClkReq1HPValid
647 * 0x20, Vaux1SysClkReq1HPValid
648 * 0x40, Vaux2SysClkReq1HPValid
649 * 0x80, Vaux3SysClkReq1HPValid
651 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff),
653 * 0x01, VapeSysClkReq1HPValid
654 * 0x02, VarmSysClkReq1HPValid
655 * 0x04, VbbSysClkReq1HPValid
656 * 0x08, VmodSysClkReq1HPValid
657 * 0x10, VextSupply1SysClkReq1HPValid
658 * 0x20, VextSupply2SysClkReq1HPValid
659 * 0x40, VextSupply3SysClkReq1HPValid
661 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x7f),
663 * 0x01, Vsmps1HwHPReq1Valid
664 * 0x02, Vsmps2HwHPReq1Valid
665 * 0x04, Vsmps3HwHPReq1Valid
666 * 0x08, VanaHwHPReq1Valid
667 * 0x10, VpllHwHPReq1Valid
668 * 0x20, Vaux1HwHPReq1Valid
669 * 0x40, Vaux2HwHPReq1Valid
670 * 0x80, Vaux3HwHPReq1Valid
672 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xff),
674 * 0x01, VextSupply1HwHPReq1Valid
675 * 0x02, VextSupply2HwHPReq1Valid
676 * 0x04, VextSupply3HwHPReq1Valid
677 * 0x08, VmodHwHPReq1Valid
679 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x0f),
681 * 0x01, Vsmps1HwHPReq2Valid
682 * 0x02, Vsmps2HwHPReq2Valid
683 * 0x03, Vsmps3HwHPReq2Valid
684 * 0x08, VanaHwHPReq2Valid
685 * 0x10, VpllHwHPReq2Valid
686 * 0x20, Vaux1HwHPReq2Valid
687 * 0x40, Vaux2HwHPReq2Valid
688 * 0x80, Vaux3HwHPReq2Valid
690 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xff),
692 * 0x01, VextSupply1HwHPReq2Valid
693 * 0x02, VextSupply2HwHPReq2Valid
694 * 0x04, VextSupply3HwHPReq2Valid
695 * 0x08, VmodHwHPReq2Valid
697 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x0f),
699 * 0x01, VapeSwHPReqValid
700 * 0x02, VarmSwHPReqValid
701 * 0x04, Vsmps1SwHPReqValid
702 * 0x08, Vsmps2SwHPReqValid
703 * 0x10, Vsmps3SwHPReqValid
704 * 0x20, VanaSwHPReqValid
705 * 0x40, VpllSwHPReqValid
706 * 0x80, Vaux1SwHPReqValid
708 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xff),
710 * 0x01, Vaux2SwHPReqValid
711 * 0x02, Vaux3SwHPReqValid
712 * 0x04, VextSupply1SwHPReqValid
713 * 0x08, VextSupply2SwHPReqValid
714 * 0x10, VextSupply3SwHPReqValid
715 * 0x20, VmodSwHPReqValid
717 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x3f),
719 * 0x02, SysClkReq2Valid1
721 * 0x80, SysClkReq8Valid1
723 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
725 * 0x02, SysClkReq2Valid2
727 * 0x80, SysClkReq8Valid2
729 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
732 * 0x04, Vintcore12Ena
733 * 0x38, Vintcore12Sel
737 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
744 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
749 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
752 * 0x0c, Vsmps1SelCtrl
753 * 0x10, Vsmps1AutoMode
754 * 0x20, Vsmps1PWMMode
756 REG_INIT(AB8500_VSMPS1REGU, 0x04, 0x03, 0x3f),
759 * 0x0c, Vsmps2SelCtrl
760 * 0x10, Vsmps2AutoMode
761 * 0x20, Vsmps2PWMMode
763 REG_INIT(AB8500_VSMPS2REGU, 0x04, 0x04, 0x3f),
768 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
771 * 0x02, VrefDDRSleepMode
773 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
775 * 0x03, VextSupply1Regu
776 * 0x0c, VextSupply2Regu
777 * 0x30, VextSupply3Regu
778 * 0x40, ExtSupply2Bypass
779 * 0x80, ExtSupply3Bypass
781 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
786 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
791 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f),
795 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
799 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
803 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
808 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x37),
810 * 0x01, VextSupply12LP
812 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
819 * 0x20, Vintcore12Disch
823 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xff),
827 * 0x04, VdmicPullDownEna
828 * 0x08, VpllPullDownEna
831 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x1f),
834 static int ab8500_regulator_init_registers(struct platform_device *pdev,
835 int id, int mask, int value)
839 BUG_ON(value & ~mask);
840 BUG_ON(mask & ~ab8500_reg_init[id].mask);
842 /* initialize register */
843 err = abx500_mask_and_set_register_interruptible(
845 ab8500_reg_init[id].bank,
846 ab8500_reg_init[id].addr,
850 "Failed to initialize 0x%02x, 0x%02x.\n",
851 ab8500_reg_init[id].bank,
852 ab8500_reg_init[id].addr);
856 " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
857 ab8500_reg_init[id].bank,
858 ab8500_reg_init[id].addr,
864 static int ab8500_regulator_register(struct platform_device *pdev,
865 struct regulator_init_data *init_data,
867 struct device_node *np)
869 struct ab8500_regulator_info *info = NULL;
870 struct regulator_config config = { };
873 /* assign per-regulator data */
874 info = &ab8500_regulator_info[id];
875 info->dev = &pdev->dev;
877 config.dev = &pdev->dev;
878 config.init_data = init_data;
879 config.driver_data = info;
882 /* fix for hardware before ab8500v2.0 */
883 if (abx500_get_chip_id(info->dev) < 0x20) {
884 if (info->desc.id == AB8500_LDO_AUX3) {
885 info->desc.n_voltages =
886 ARRAY_SIZE(ldo_vauxn_voltages);
887 info->desc.volt_table = ldo_vauxn_voltages;
888 info->voltage_mask = 0xf;
892 /* register regulator with framework */
893 info->regulator = regulator_register(&info->desc, &config);
894 if (IS_ERR(info->regulator)) {
895 err = PTR_ERR(info->regulator);
896 dev_err(&pdev->dev, "failed to register regulator %s\n",
898 /* when we fail, un-register all earlier regulators */
900 info = &ab8500_regulator_info[id];
901 regulator_unregister(info->regulator);
909 static struct of_regulator_match ab8500_regulator_matches[] = {
910 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
911 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
912 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
913 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
914 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
915 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
916 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
917 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
918 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
919 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
920 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
924 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
928 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
929 err = ab8500_regulator_register(
930 pdev, ab8500_regulator_matches[i].init_data,
931 i, ab8500_regulator_matches[i].of_node);
939 static int ab8500_regulator_probe(struct platform_device *pdev)
941 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
942 struct device_node *np = pdev->dev.of_node;
943 struct ab8500_platform_data *ppdata;
944 struct ab8500_regulator_platform_data *pdata;
948 err = of_regulator_match(&pdev->dev, np,
949 ab8500_regulator_matches,
950 ARRAY_SIZE(ab8500_regulator_matches));
953 "Error parsing regulator init data: %d\n", err);
957 err = ab8500_regulator_of_probe(pdev, np);
962 dev_err(&pdev->dev, "null mfd parent\n");
966 ppdata = dev_get_platdata(ab8500->dev);
968 dev_err(&pdev->dev, "null parent pdata\n");
972 pdata = ppdata->regulator;
974 dev_err(&pdev->dev, "null pdata\n");
978 /* make sure the platform data has the correct size */
979 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
980 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
984 /* initialize registers */
985 for (i = 0; i < pdata->num_reg_init; i++) {
988 id = pdata->reg_init[i].id;
989 mask = pdata->reg_init[i].mask;
990 value = pdata->reg_init[i].value;
992 /* check for configuration errors */
993 BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS);
995 err = ab8500_regulator_init_registers(pdev, id, mask, value);
1000 /* register all regulators */
1001 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
1002 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
1010 static int ab8500_regulator_remove(struct platform_device *pdev)
1014 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
1015 struct ab8500_regulator_info *info = NULL;
1016 info = &ab8500_regulator_info[i];
1018 dev_vdbg(rdev_get_dev(info->regulator),
1019 "%s-remove\n", info->desc.name);
1021 regulator_unregister(info->regulator);
1027 static struct platform_driver ab8500_regulator_driver = {
1028 .probe = ab8500_regulator_probe,
1029 .remove = ab8500_regulator_remove,
1031 .name = "ab8500-regulator",
1032 .owner = THIS_MODULE,
1036 static int __init ab8500_regulator_init(void)
1040 ret = platform_driver_register(&ab8500_regulator_driver);
1042 pr_err("Failed to register ab8500 regulator: %d\n", ret);
1046 subsys_initcall(ab8500_regulator_init);
1048 static void __exit ab8500_regulator_exit(void)
1050 platform_driver_unregister(&ab8500_regulator_driver);
1052 module_exit(ab8500_regulator_exit);
1054 MODULE_LICENSE("GPL v2");
1055 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
1056 MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
1057 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
1058 MODULE_ALIAS("platform:ab8500-regulator");