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 * @voltage_shift: shift to control regulator voltage
41 * @delay: startup/set voltage delay in us
43 struct ab8500_regulator_info {
45 struct regulator_desc desc;
46 struct regulator_dev *regulator;
58 /* voltage tables for the vauxn/vintcore supplies */
59 static const unsigned int ldo_vauxn_voltages[] = {
78 static const unsigned int ldo_vaux3_voltages[] = {
89 static const unsigned int ldo_vintcore_voltages[] = {
99 static int ab8500_regulator_enable(struct regulator_dev *rdev)
102 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
105 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
109 ret = abx500_mask_and_set_register_interruptible(info->dev,
110 info->update_bank, info->update_reg,
111 info->update_mask, info->update_val_enable);
113 dev_err(rdev_get_dev(rdev),
114 "couldn't set enable bits for regulator\n");
116 dev_vdbg(rdev_get_dev(rdev),
117 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
118 info->desc.name, info->update_bank, info->update_reg,
119 info->update_mask, info->update_val_enable);
124 static int ab8500_regulator_disable(struct regulator_dev *rdev)
127 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
130 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
134 ret = abx500_mask_and_set_register_interruptible(info->dev,
135 info->update_bank, info->update_reg,
136 info->update_mask, 0x0);
138 dev_err(rdev_get_dev(rdev),
139 "couldn't set disable bits for regulator\n");
141 dev_vdbg(rdev_get_dev(rdev),
142 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
143 info->desc.name, info->update_bank, info->update_reg,
144 info->update_mask, 0x0);
149 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
152 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
156 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
160 ret = abx500_get_register_interruptible(info->dev,
161 info->update_bank, info->update_reg, ®val);
163 dev_err(rdev_get_dev(rdev),
164 "couldn't read 0x%x register\n", info->update_reg);
168 dev_vdbg(rdev_get_dev(rdev),
169 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
171 info->desc.name, info->update_bank, info->update_reg,
172 info->update_mask, regval);
174 if (regval & info->update_mask)
180 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
183 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
187 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
191 ret = abx500_get_register_interruptible(info->dev,
192 info->voltage_bank, info->voltage_reg, ®val);
194 dev_err(rdev_get_dev(rdev),
195 "couldn't read voltage reg for regulator\n");
199 dev_vdbg(rdev_get_dev(rdev),
200 "%s-get_voltage (bank, reg, mask, shift, value): "
201 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
202 info->desc.name, info->voltage_bank,
203 info->voltage_reg, info->voltage_mask,
204 info->voltage_shift, regval);
206 val = regval & info->voltage_mask;
207 return val >> info->voltage_shift;
210 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
214 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
218 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
222 /* set the registers for the request */
223 regval = (u8)selector << info->voltage_shift;
224 ret = abx500_mask_and_set_register_interruptible(info->dev,
225 info->voltage_bank, info->voltage_reg,
226 info->voltage_mask, regval);
228 dev_err(rdev_get_dev(rdev),
229 "couldn't set voltage reg for regulator\n");
231 dev_vdbg(rdev_get_dev(rdev),
232 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
234 info->desc.name, info->voltage_bank, info->voltage_reg,
235 info->voltage_mask, regval);
240 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
241 unsigned int old_sel,
242 unsigned int new_sel)
244 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
249 static struct regulator_ops ab8500_regulator_ops = {
250 .enable = ab8500_regulator_enable,
251 .disable = ab8500_regulator_disable,
252 .is_enabled = ab8500_regulator_is_enabled,
253 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
254 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
255 .list_voltage = regulator_list_voltage_table,
256 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
259 static struct regulator_ops ab8500_regulator_fixed_ops = {
260 .enable = ab8500_regulator_enable,
261 .disable = ab8500_regulator_disable,
262 .is_enabled = ab8500_regulator_is_enabled,
263 .list_voltage = regulator_list_voltage_linear,
266 static struct ab8500_regulator_info
267 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
269 * Variable Voltage Regulators
270 * name, min mV, max mV,
271 * update bank, reg, mask, enable val
272 * volt bank, reg, mask
274 [AB8500_LDO_AUX1] = {
277 .ops = &ab8500_regulator_ops,
278 .type = REGULATOR_VOLTAGE,
279 .id = AB8500_LDO_AUX1,
280 .owner = THIS_MODULE,
281 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
282 .volt_table = ldo_vauxn_voltages,
287 .update_val_enable = 0x01,
288 .voltage_bank = 0x04,
290 .voltage_mask = 0x0f,
292 [AB8500_LDO_AUX2] = {
295 .ops = &ab8500_regulator_ops,
296 .type = REGULATOR_VOLTAGE,
297 .id = AB8500_LDO_AUX2,
298 .owner = THIS_MODULE,
299 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
300 .volt_table = ldo_vauxn_voltages,
305 .update_val_enable = 0x04,
306 .voltage_bank = 0x04,
308 .voltage_mask = 0x0f,
310 [AB8500_LDO_AUX3] = {
313 .ops = &ab8500_regulator_ops,
314 .type = REGULATOR_VOLTAGE,
315 .id = AB8500_LDO_AUX3,
316 .owner = THIS_MODULE,
317 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
318 .volt_table = ldo_vaux3_voltages,
323 .update_val_enable = 0x01,
324 .voltage_bank = 0x04,
326 .voltage_mask = 0x07,
328 [AB8500_LDO_INTCORE] = {
330 .name = "LDO-INTCORE",
331 .ops = &ab8500_regulator_ops,
332 .type = REGULATOR_VOLTAGE,
333 .id = AB8500_LDO_INTCORE,
334 .owner = THIS_MODULE,
335 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
336 .volt_table = ldo_vintcore_voltages,
341 .update_val_enable = 0x04,
342 .voltage_bank = 0x03,
344 .voltage_mask = 0x38,
349 * Fixed Voltage Regulators
351 * update bank, reg, mask, enable val
353 [AB8500_LDO_TVOUT] = {
356 .ops = &ab8500_regulator_fixed_ops,
357 .type = REGULATOR_VOLTAGE,
358 .id = AB8500_LDO_TVOUT,
359 .owner = THIS_MODULE,
362 .enable_time = 10000,
368 .update_val_enable = 0x02,
373 .ops = &ab8500_regulator_fixed_ops,
374 .type = REGULATOR_VOLTAGE,
375 .id = AB8500_LDO_USB,
376 .owner = THIS_MODULE,
383 .update_val_enable = 0x01,
385 [AB8500_LDO_AUDIO] = {
388 .ops = &ab8500_regulator_fixed_ops,
389 .type = REGULATOR_VOLTAGE,
390 .id = AB8500_LDO_AUDIO,
391 .owner = THIS_MODULE,
398 .update_val_enable = 0x02,
400 [AB8500_LDO_ANAMIC1] = {
402 .name = "LDO-ANAMIC1",
403 .ops = &ab8500_regulator_fixed_ops,
404 .type = REGULATOR_VOLTAGE,
405 .id = AB8500_LDO_ANAMIC1,
406 .owner = THIS_MODULE,
413 .update_val_enable = 0x08,
415 [AB8500_LDO_ANAMIC2] = {
417 .name = "LDO-ANAMIC2",
418 .ops = &ab8500_regulator_fixed_ops,
419 .type = REGULATOR_VOLTAGE,
420 .id = AB8500_LDO_ANAMIC2,
421 .owner = THIS_MODULE,
428 .update_val_enable = 0x10,
430 [AB8500_LDO_DMIC] = {
433 .ops = &ab8500_regulator_fixed_ops,
434 .type = REGULATOR_VOLTAGE,
435 .id = AB8500_LDO_DMIC,
436 .owner = THIS_MODULE,
443 .update_val_enable = 0x04,
448 .ops = &ab8500_regulator_fixed_ops,
449 .type = REGULATOR_VOLTAGE,
450 .id = AB8500_LDO_ANA,
451 .owner = THIS_MODULE,
458 .update_val_enable = 0x04,
464 struct ab8500_reg_init {
470 #define REG_INIT(_id, _bank, _addr, _mask) \
477 static struct ab8500_reg_init ab8500_reg_init[] = {
479 * 0x30, VanaRequestCtrl
480 * 0x0C, VpllRequestCtrl
481 * 0xc0, VextSupply1RequestCtrl
483 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
485 * 0x03, VextSupply2RequestCtrl
486 * 0x0c, VextSupply3RequestCtrl
487 * 0x30, Vaux1RequestCtrl
488 * 0xc0, Vaux2RequestCtrl
490 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
492 * 0x03, Vaux3RequestCtrl
495 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
497 * 0x08, VanaSysClkReq1HPValid
498 * 0x20, Vaux1SysClkReq1HPValid
499 * 0x40, Vaux2SysClkReq1HPValid
500 * 0x80, Vaux3SysClkReq1HPValid
502 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
504 * 0x10, VextSupply1SysClkReq1HPValid
505 * 0x20, VextSupply2SysClkReq1HPValid
506 * 0x40, VextSupply3SysClkReq1HPValid
508 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
510 * 0x08, VanaHwHPReq1Valid
511 * 0x20, Vaux1HwHPReq1Valid
512 * 0x40, Vaux2HwHPReq1Valid
513 * 0x80, Vaux3HwHPReq1Valid
515 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
517 * 0x01, VextSupply1HwHPReq1Valid
518 * 0x02, VextSupply2HwHPReq1Valid
519 * 0x04, VextSupply3HwHPReq1Valid
521 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
523 * 0x08, VanaHwHPReq2Valid
524 * 0x20, Vaux1HwHPReq2Valid
525 * 0x40, Vaux2HwHPReq2Valid
526 * 0x80, Vaux3HwHPReq2Valid
528 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
530 * 0x01, VextSupply1HwHPReq2Valid
531 * 0x02, VextSupply2HwHPReq2Valid
532 * 0x04, VextSupply3HwHPReq2Valid
534 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
536 * 0x20, VanaSwHPReqValid
537 * 0x80, Vaux1SwHPReqValid
539 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
541 * 0x01, Vaux2SwHPReqValid
542 * 0x02, Vaux3SwHPReqValid
543 * 0x04, VextSupply1SwHPReqValid
544 * 0x08, VextSupply2SwHPReqValid
545 * 0x10, VextSupply3SwHPReqValid
547 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
549 * 0x02, SysClkReq2Valid1
551 * 0x80, SysClkReq8Valid1
553 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
555 * 0x02, SysClkReq2Valid2
557 * 0x80, SysClkReq8Valid2
559 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
562 * 0x04, Vintcore12Ena
563 * 0x38, Vintcore12Sel
567 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
574 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
579 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
584 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
587 * 0x02, VrefDDRSleepMode
589 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
591 * 0x03, VextSupply1Regu
592 * 0x0c, VextSupply2Regu
593 * 0x30, VextSupply3Regu
594 * 0x40, ExtSupply2Bypass
595 * 0x80, ExtSupply3Bypass
597 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
602 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
606 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
610 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
614 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
618 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
622 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
624 * 0x01, VextSupply12LP
626 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
631 * 0x20, Vintcore12Disch
635 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
638 * 0x04, VdmicPullDownEna
641 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
645 ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
649 if (value & ~ab8500_reg_init[id].mask) {
651 "Configuration error: value outside mask.\n");
655 err = abx500_mask_and_set_register_interruptible(
657 ab8500_reg_init[id].bank,
658 ab8500_reg_init[id].addr,
659 ab8500_reg_init[id].mask,
663 "Failed to initialize 0x%02x, 0x%02x.\n",
664 ab8500_reg_init[id].bank,
665 ab8500_reg_init[id].addr);
670 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
671 ab8500_reg_init[id].bank,
672 ab8500_reg_init[id].addr,
673 ab8500_reg_init[id].mask,
679 static __devinit int ab8500_regulator_register(struct platform_device *pdev,
680 struct regulator_init_data *init_data,
682 struct device_node *np)
684 struct ab8500_regulator_info *info = NULL;
685 struct regulator_config config = { };
688 /* assign per-regulator data */
689 info = &ab8500_regulator_info[id];
690 info->dev = &pdev->dev;
692 config.dev = &pdev->dev;
693 config.init_data = init_data;
694 config.driver_data = info;
697 /* fix for hardware before ab8500v2.0 */
698 if (abx500_get_chip_id(info->dev) < 0x20) {
699 if (info->desc.id == AB8500_LDO_AUX3) {
700 info->desc.n_voltages =
701 ARRAY_SIZE(ldo_vauxn_voltages);
702 info->desc.volt_table = ldo_vauxn_voltages;
703 info->voltage_mask = 0xf;
707 /* register regulator with framework */
708 info->regulator = regulator_register(&info->desc, &config);
709 if (IS_ERR(info->regulator)) {
710 err = PTR_ERR(info->regulator);
711 dev_err(&pdev->dev, "failed to register regulator %s\n",
713 /* when we fail, un-register all earlier regulators */
715 info = &ab8500_regulator_info[id];
716 regulator_unregister(info->regulator);
724 static struct of_regulator_match ab8500_regulator_matches[] = {
725 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
726 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
727 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
728 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
729 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
730 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
731 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
732 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
733 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
734 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
735 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
739 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
743 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
744 err = ab8500_regulator_register(
745 pdev, ab8500_regulator_matches[i].init_data,
746 i, ab8500_regulator_matches[i].of_node);
754 static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
756 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
757 struct ab8500_platform_data *pdata;
758 struct device_node *np = pdev->dev.of_node;
762 err = of_regulator_match(&pdev->dev, np,
763 ab8500_regulator_matches,
764 ARRAY_SIZE(ab8500_regulator_matches));
767 "Error parsing regulator init data: %d\n", err);
771 err = ab8500_regulator_of_probe(pdev, np);
776 dev_err(&pdev->dev, "null mfd parent\n");
779 pdata = dev_get_platdata(ab8500->dev);
781 dev_err(&pdev->dev, "null pdata\n");
785 /* make sure the platform data has the correct size */
786 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
787 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
791 /* initialize registers */
792 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
795 id = pdata->regulator_reg_init[i].id;
796 value = pdata->regulator_reg_init[i].value;
798 /* check for configuration errors */
799 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
801 "Configuration error: id outside range.\n");
805 err = ab8500_regulator_init_registers(pdev, id, value);
810 /* register all regulators */
811 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
812 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
820 static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
824 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
825 struct ab8500_regulator_info *info = NULL;
826 info = &ab8500_regulator_info[i];
828 dev_vdbg(rdev_get_dev(info->regulator),
829 "%s-remove\n", info->desc.name);
831 regulator_unregister(info->regulator);
837 static struct platform_driver ab8500_regulator_driver = {
838 .probe = ab8500_regulator_probe,
839 .remove = __devexit_p(ab8500_regulator_remove),
841 .name = "ab8500-regulator",
842 .owner = THIS_MODULE,
846 static int __init ab8500_regulator_init(void)
850 ret = platform_driver_register(&ab8500_regulator_driver);
852 pr_err("Failed to register ab8500 regulator: %d\n", ret);
856 subsys_initcall(ab8500_regulator_init);
858 static void __exit ab8500_regulator_exit(void)
860 platform_driver_unregister(&ab8500_regulator_driver);
862 module_exit(ab8500_regulator_exit);
864 MODULE_LICENSE("GPL v2");
865 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
866 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
867 MODULE_ALIAS("platform:ab8500-regulator");