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 * @update_bank: bank to control on/off
34 * @update_reg: register to control on/off
35 * @update_mask: mask to enable/disable regulator
36 * @update_val_enable: bits to enable the regulator in normal (high power) mode
37 * @voltage_bank: bank to control regulator voltage
38 * @voltage_reg: register to control regulator voltage
39 * @voltage_mask: mask to control regulator voltage
40 * @delay: startup/set voltage delay in us
42 struct ab8500_regulator_info {
44 struct regulator_desc desc;
45 struct regulator_dev *regulator;
56 /* voltage tables for the vauxn/vintcore supplies */
57 static const unsigned int ldo_vauxn_voltages[] = {
76 static const unsigned int ldo_vaux3_voltages[] = {
87 static const unsigned int ldo_vintcore_voltages[] = {
97 static int ab8500_regulator_enable(struct regulator_dev *rdev)
100 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
103 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
107 ret = abx500_mask_and_set_register_interruptible(info->dev,
108 info->update_bank, info->update_reg,
109 info->update_mask, info->update_val_enable);
111 dev_err(rdev_get_dev(rdev),
112 "couldn't set enable bits for regulator\n");
114 dev_vdbg(rdev_get_dev(rdev),
115 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
116 info->desc.name, info->update_bank, info->update_reg,
117 info->update_mask, info->update_val_enable);
122 static int ab8500_regulator_disable(struct regulator_dev *rdev)
125 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
128 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
132 ret = abx500_mask_and_set_register_interruptible(info->dev,
133 info->update_bank, info->update_reg,
134 info->update_mask, 0x0);
136 dev_err(rdev_get_dev(rdev),
137 "couldn't set disable bits for regulator\n");
139 dev_vdbg(rdev_get_dev(rdev),
140 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
141 info->desc.name, info->update_bank, info->update_reg,
142 info->update_mask, 0x0);
147 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
150 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
154 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
158 ret = abx500_get_register_interruptible(info->dev,
159 info->update_bank, info->update_reg, ®val);
161 dev_err(rdev_get_dev(rdev),
162 "couldn't read 0x%x register\n", info->update_reg);
166 dev_vdbg(rdev_get_dev(rdev),
167 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
169 info->desc.name, info->update_bank, info->update_reg,
170 info->update_mask, regval);
172 if (regval & info->update_mask)
178 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
181 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
185 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
189 ret = abx500_get_register_interruptible(info->dev,
190 info->voltage_bank, info->voltage_reg, ®val);
192 dev_err(rdev_get_dev(rdev),
193 "couldn't read voltage reg for regulator\n");
197 dev_vdbg(rdev_get_dev(rdev),
198 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
200 info->desc.name, info->voltage_bank, info->voltage_reg,
201 info->voltage_mask, regval);
203 /* vintcore has a different layout */
204 val = regval & info->voltage_mask;
205 if (info->desc.id == AB8500_LDO_INTCORE)
211 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
215 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
219 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
223 /* set the registers for the request */
224 regval = (u8)selector;
225 ret = abx500_mask_and_set_register_interruptible(info->dev,
226 info->voltage_bank, info->voltage_reg,
227 info->voltage_mask, regval);
229 dev_err(rdev_get_dev(rdev),
230 "couldn't set voltage reg for regulator\n");
232 dev_vdbg(rdev_get_dev(rdev),
233 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
235 info->desc.name, info->voltage_bank, info->voltage_reg,
236 info->voltage_mask, regval);
241 static int ab8500_regulator_enable_time(struct regulator_dev *rdev)
243 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
248 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
249 unsigned int old_sel,
250 unsigned int new_sel)
252 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
257 static struct regulator_ops ab8500_regulator_ops = {
258 .enable = ab8500_regulator_enable,
259 .disable = ab8500_regulator_disable,
260 .is_enabled = ab8500_regulator_is_enabled,
261 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
262 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
263 .list_voltage = regulator_list_voltage_table,
264 .enable_time = ab8500_regulator_enable_time,
265 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
268 static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
270 return rdev->desc->min_uV;
273 static struct regulator_ops ab8500_regulator_fixed_ops = {
274 .enable = ab8500_regulator_enable,
275 .disable = ab8500_regulator_disable,
276 .is_enabled = ab8500_regulator_is_enabled,
277 .get_voltage = ab8500_fixed_get_voltage,
278 .list_voltage = regulator_list_voltage_linear,
279 .enable_time = ab8500_regulator_enable_time,
282 static struct ab8500_regulator_info
283 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
285 * Variable Voltage Regulators
286 * name, min mV, max mV,
287 * update bank, reg, mask, enable val
288 * volt bank, reg, mask
290 [AB8500_LDO_AUX1] = {
293 .ops = &ab8500_regulator_ops,
294 .type = REGULATOR_VOLTAGE,
295 .id = AB8500_LDO_AUX1,
296 .owner = THIS_MODULE,
297 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
298 .volt_table = ldo_vauxn_voltages,
303 .update_val_enable = 0x01,
304 .voltage_bank = 0x04,
306 .voltage_mask = 0x0f,
308 [AB8500_LDO_AUX2] = {
311 .ops = &ab8500_regulator_ops,
312 .type = REGULATOR_VOLTAGE,
313 .id = AB8500_LDO_AUX2,
314 .owner = THIS_MODULE,
315 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
316 .volt_table = ldo_vauxn_voltages,
321 .update_val_enable = 0x04,
322 .voltage_bank = 0x04,
324 .voltage_mask = 0x0f,
326 [AB8500_LDO_AUX3] = {
329 .ops = &ab8500_regulator_ops,
330 .type = REGULATOR_VOLTAGE,
331 .id = AB8500_LDO_AUX3,
332 .owner = THIS_MODULE,
333 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
334 .volt_table = ldo_vaux3_voltages,
339 .update_val_enable = 0x01,
340 .voltage_bank = 0x04,
342 .voltage_mask = 0x07,
344 [AB8500_LDO_INTCORE] = {
346 .name = "LDO-INTCORE",
347 .ops = &ab8500_regulator_ops,
348 .type = REGULATOR_VOLTAGE,
349 .id = AB8500_LDO_INTCORE,
350 .owner = THIS_MODULE,
351 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
352 .volt_table = ldo_vintcore_voltages,
357 .update_val_enable = 0x04,
358 .voltage_bank = 0x03,
360 .voltage_mask = 0x38,
364 * Fixed Voltage Regulators
366 * update bank, reg, mask, enable val
368 [AB8500_LDO_TVOUT] = {
371 .ops = &ab8500_regulator_fixed_ops,
372 .type = REGULATOR_VOLTAGE,
373 .id = AB8500_LDO_TVOUT,
374 .owner = THIS_MODULE,
382 .update_val_enable = 0x02,
387 .ops = &ab8500_regulator_fixed_ops,
388 .type = REGULATOR_VOLTAGE,
389 .id = AB8500_LDO_USB,
390 .owner = THIS_MODULE,
397 .update_val_enable = 0x01,
399 [AB8500_LDO_AUDIO] = {
402 .ops = &ab8500_regulator_fixed_ops,
403 .type = REGULATOR_VOLTAGE,
404 .id = AB8500_LDO_AUDIO,
405 .owner = THIS_MODULE,
412 .update_val_enable = 0x02,
414 [AB8500_LDO_ANAMIC1] = {
416 .name = "LDO-ANAMIC1",
417 .ops = &ab8500_regulator_fixed_ops,
418 .type = REGULATOR_VOLTAGE,
419 .id = AB8500_LDO_ANAMIC1,
420 .owner = THIS_MODULE,
427 .update_val_enable = 0x08,
429 [AB8500_LDO_ANAMIC2] = {
431 .name = "LDO-ANAMIC2",
432 .ops = &ab8500_regulator_fixed_ops,
433 .type = REGULATOR_VOLTAGE,
434 .id = AB8500_LDO_ANAMIC2,
435 .owner = THIS_MODULE,
442 .update_val_enable = 0x10,
444 [AB8500_LDO_DMIC] = {
447 .ops = &ab8500_regulator_fixed_ops,
448 .type = REGULATOR_VOLTAGE,
449 .id = AB8500_LDO_DMIC,
450 .owner = THIS_MODULE,
457 .update_val_enable = 0x04,
462 .ops = &ab8500_regulator_fixed_ops,
463 .type = REGULATOR_VOLTAGE,
464 .id = AB8500_LDO_ANA,
465 .owner = THIS_MODULE,
472 .update_val_enable = 0x04,
478 struct ab8500_reg_init {
484 #define REG_INIT(_id, _bank, _addr, _mask) \
491 static struct ab8500_reg_init ab8500_reg_init[] = {
493 * 0x30, VanaRequestCtrl
494 * 0x0C, VpllRequestCtrl
495 * 0xc0, VextSupply1RequestCtrl
497 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
499 * 0x03, VextSupply2RequestCtrl
500 * 0x0c, VextSupply3RequestCtrl
501 * 0x30, Vaux1RequestCtrl
502 * 0xc0, Vaux2RequestCtrl
504 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
506 * 0x03, Vaux3RequestCtrl
509 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
511 * 0x08, VanaSysClkReq1HPValid
512 * 0x20, Vaux1SysClkReq1HPValid
513 * 0x40, Vaux2SysClkReq1HPValid
514 * 0x80, Vaux3SysClkReq1HPValid
516 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
518 * 0x10, VextSupply1SysClkReq1HPValid
519 * 0x20, VextSupply2SysClkReq1HPValid
520 * 0x40, VextSupply3SysClkReq1HPValid
522 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
524 * 0x08, VanaHwHPReq1Valid
525 * 0x20, Vaux1HwHPReq1Valid
526 * 0x40, Vaux2HwHPReq1Valid
527 * 0x80, Vaux3HwHPReq1Valid
529 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
531 * 0x01, VextSupply1HwHPReq1Valid
532 * 0x02, VextSupply2HwHPReq1Valid
533 * 0x04, VextSupply3HwHPReq1Valid
535 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
537 * 0x08, VanaHwHPReq2Valid
538 * 0x20, Vaux1HwHPReq2Valid
539 * 0x40, Vaux2HwHPReq2Valid
540 * 0x80, Vaux3HwHPReq2Valid
542 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
544 * 0x01, VextSupply1HwHPReq2Valid
545 * 0x02, VextSupply2HwHPReq2Valid
546 * 0x04, VextSupply3HwHPReq2Valid
548 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
550 * 0x20, VanaSwHPReqValid
551 * 0x80, Vaux1SwHPReqValid
553 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
555 * 0x01, Vaux2SwHPReqValid
556 * 0x02, Vaux3SwHPReqValid
557 * 0x04, VextSupply1SwHPReqValid
558 * 0x08, VextSupply2SwHPReqValid
559 * 0x10, VextSupply3SwHPReqValid
561 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
563 * 0x02, SysClkReq2Valid1
565 * 0x80, SysClkReq8Valid1
567 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
569 * 0x02, SysClkReq2Valid2
571 * 0x80, SysClkReq8Valid2
573 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
576 * 0x04, Vintcore12Ena
577 * 0x38, Vintcore12Sel
581 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
588 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
593 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
598 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
601 * 0x02, VrefDDRSleepMode
603 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
605 * 0x03, VextSupply1Regu
606 * 0x0c, VextSupply2Regu
607 * 0x30, VextSupply3Regu
608 * 0x40, ExtSupply2Bypass
609 * 0x80, ExtSupply3Bypass
611 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
616 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
620 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
624 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
628 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
632 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
636 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
638 * 0x01, VextSupply12LP
640 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
645 * 0x20, Vintcore12Disch
649 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
652 * 0x04, VdmicPullDownEna
655 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
659 ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
663 if (value & ~ab8500_reg_init[id].mask) {
665 "Configuration error: value outside mask.\n");
669 err = abx500_mask_and_set_register_interruptible(
671 ab8500_reg_init[id].bank,
672 ab8500_reg_init[id].addr,
673 ab8500_reg_init[id].mask,
677 "Failed to initialize 0x%02x, 0x%02x.\n",
678 ab8500_reg_init[id].bank,
679 ab8500_reg_init[id].addr);
684 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
685 ab8500_reg_init[id].bank,
686 ab8500_reg_init[id].addr,
687 ab8500_reg_init[id].mask,
693 static __devinit int ab8500_regulator_register(struct platform_device *pdev,
694 struct regulator_init_data *init_data,
696 struct device_node *np)
698 struct ab8500_regulator_info *info = NULL;
699 struct regulator_config config = { };
702 /* assign per-regulator data */
703 info = &ab8500_regulator_info[id];
704 info->dev = &pdev->dev;
706 config.dev = &pdev->dev;
707 config.init_data = init_data;
708 config.driver_data = info;
711 /* fix for hardware before ab8500v2.0 */
712 if (abx500_get_chip_id(info->dev) < 0x20) {
713 if (info->desc.id == AB8500_LDO_AUX3) {
714 info->desc.n_voltages =
715 ARRAY_SIZE(ldo_vauxn_voltages);
716 info->desc.volt_table = ldo_vauxn_voltages;
717 info->voltage_mask = 0xf;
721 /* register regulator with framework */
722 info->regulator = regulator_register(&info->desc, &config);
723 if (IS_ERR(info->regulator)) {
724 err = PTR_ERR(info->regulator);
725 dev_err(&pdev->dev, "failed to register regulator %s\n",
727 /* when we fail, un-register all earlier regulators */
729 info = &ab8500_regulator_info[id];
730 regulator_unregister(info->regulator);
738 static struct of_regulator_match ab8500_regulator_matches[] = {
739 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
740 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
741 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
742 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
743 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
744 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
745 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
746 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
747 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
748 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
749 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
753 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
757 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
758 err = ab8500_regulator_register(
759 pdev, ab8500_regulator_matches[i].init_data,
760 i, ab8500_regulator_matches[i].of_node);
768 static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
770 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
771 struct ab8500_platform_data *pdata;
772 struct device_node *np = pdev->dev.of_node;
776 err = of_regulator_match(&pdev->dev, np,
777 ab8500_regulator_matches,
778 ARRAY_SIZE(ab8500_regulator_matches));
781 "Error parsing regulator init data: %d\n", err);
785 err = ab8500_regulator_of_probe(pdev, np);
790 dev_err(&pdev->dev, "null mfd parent\n");
793 pdata = dev_get_platdata(ab8500->dev);
795 dev_err(&pdev->dev, "null pdata\n");
799 /* make sure the platform data has the correct size */
800 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
801 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
805 /* initialize registers */
806 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
809 id = pdata->regulator_reg_init[i].id;
810 value = pdata->regulator_reg_init[i].value;
812 /* check for configuration errors */
813 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
815 "Configuration error: id outside range.\n");
819 err = ab8500_regulator_init_registers(pdev, id, value);
824 /* register all regulators */
825 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
826 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
834 static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
838 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
839 struct ab8500_regulator_info *info = NULL;
840 info = &ab8500_regulator_info[i];
842 dev_vdbg(rdev_get_dev(info->regulator),
843 "%s-remove\n", info->desc.name);
845 regulator_unregister(info->regulator);
851 static struct platform_driver ab8500_regulator_driver = {
852 .probe = ab8500_regulator_probe,
853 .remove = __devexit_p(ab8500_regulator_remove),
855 .name = "ab8500-regulator",
856 .owner = THIS_MODULE,
860 static int __init ab8500_regulator_init(void)
864 ret = platform_driver_register(&ab8500_regulator_driver);
866 pr_err("Failed to register ab8500 regulator: %d\n", ret);
870 subsys_initcall(ab8500_regulator_init);
872 static void __exit ab8500_regulator_exit(void)
874 platform_driver_unregister(&ab8500_regulator_driver);
876 module_exit(ab8500_regulator_exit);
878 MODULE_LICENSE("GPL v2");
879 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
880 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
881 MODULE_ALIAS("platform:ab8500-regulator");