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 update_val = info->update_val_normal;
200 case REGULATOR_MODE_IDLE:
201 update_val = info->update_val_idle;
207 /* ab8500 regulators share mode and enable in the same register bits.
210 full powermode = 0b01
211 (HW control mode = 0b10)
212 Thus we don't write to the register when regulator is disabled.
214 if (info->is_enabled) {
215 ret = abx500_mask_and_set_register_interruptible(info->dev,
216 info->update_bank, info->update_reg,
217 info->update_mask, update_val);
219 dev_err(rdev_get_dev(rdev),
220 "couldn't set regulator mode\n");
224 dev_vdbg(rdev_get_dev(rdev),
225 "%s-set_mode (bank, reg, mask, value): "
226 "0x%x, 0x%x, 0x%x, 0x%x\n",
227 info->desc.name, info->update_bank, info->update_reg,
228 info->update_mask, update_val);
231 info->update_val = update_val;
236 static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
238 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
242 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
246 if (info->update_val == info->update_val_normal)
247 ret = REGULATOR_MODE_NORMAL;
248 else if (info->update_val == info->update_val_idle)
249 ret = REGULATOR_MODE_IDLE;
256 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
259 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
263 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
267 ret = abx500_get_register_interruptible(info->dev,
268 info->update_bank, info->update_reg, ®val);
270 dev_err(rdev_get_dev(rdev),
271 "couldn't read 0x%x register\n", info->update_reg);
275 dev_vdbg(rdev_get_dev(rdev),
276 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
278 info->desc.name, info->update_bank, info->update_reg,
279 info->update_mask, regval);
281 if (regval & info->update_mask)
282 info->is_enabled = true;
284 info->is_enabled = false;
286 return info->is_enabled;
289 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
292 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
296 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
300 ret = abx500_get_register_interruptible(info->dev,
301 info->voltage_bank, info->voltage_reg, ®val);
303 dev_err(rdev_get_dev(rdev),
304 "couldn't read voltage reg for regulator\n");
308 dev_vdbg(rdev_get_dev(rdev),
309 "%s-get_voltage (bank, reg, mask, shift, value): "
310 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
311 info->desc.name, info->voltage_bank,
312 info->voltage_reg, info->voltage_mask,
313 info->voltage_shift, regval);
315 val = regval & info->voltage_mask;
316 return val >> info->voltage_shift;
319 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
323 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
327 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
331 /* set the registers for the request */
332 regval = (u8)selector << info->voltage_shift;
333 ret = abx500_mask_and_set_register_interruptible(info->dev,
334 info->voltage_bank, info->voltage_reg,
335 info->voltage_mask, regval);
337 dev_err(rdev_get_dev(rdev),
338 "couldn't set voltage reg for regulator\n");
340 dev_vdbg(rdev_get_dev(rdev),
341 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
343 info->desc.name, info->voltage_bank, info->voltage_reg,
344 info->voltage_mask, regval);
349 static struct regulator_ops ab8500_regulator_volt_mode_ops = {
350 .enable = ab8500_regulator_enable,
351 .disable = ab8500_regulator_disable,
352 .is_enabled = ab8500_regulator_is_enabled,
353 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
354 .set_mode = ab8500_regulator_set_mode,
355 .get_mode = ab8500_regulator_get_mode,
356 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
357 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
358 .list_voltage = regulator_list_voltage_table,
361 static struct regulator_ops ab8500_regulator_mode_ops = {
362 .enable = ab8500_regulator_enable,
363 .disable = ab8500_regulator_disable,
364 .is_enabled = ab8500_regulator_is_enabled,
365 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
366 .set_mode = ab8500_regulator_set_mode,
367 .get_mode = ab8500_regulator_get_mode,
368 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
369 .list_voltage = regulator_list_voltage_linear,
372 static struct regulator_ops ab8500_regulator_ops = {
373 .enable = ab8500_regulator_enable,
374 .disable = ab8500_regulator_disable,
375 .is_enabled = ab8500_regulator_is_enabled,
376 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
377 .list_voltage = regulator_list_voltage_linear,
380 /* AB8500 regulator information */
381 static struct ab8500_regulator_info
382 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
384 * Variable Voltage Regulators
385 * name, min mV, max mV,
386 * update bank, reg, mask, enable val
387 * volt bank, reg, mask
389 [AB8500_LDO_AUX1] = {
392 .ops = &ab8500_regulator_volt_mode_ops,
393 .type = REGULATOR_VOLTAGE,
394 .id = AB8500_LDO_AUX1,
395 .owner = THIS_MODULE,
396 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
397 .volt_table = ldo_vauxn_voltages,
405 .update_val_idle = 0x03,
406 .update_val_normal = 0x01,
407 .voltage_bank = 0x04,
409 .voltage_mask = 0x0f,
411 [AB8500_LDO_AUX2] = {
414 .ops = &ab8500_regulator_volt_mode_ops,
415 .type = REGULATOR_VOLTAGE,
416 .id = AB8500_LDO_AUX2,
417 .owner = THIS_MODULE,
418 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
419 .volt_table = ldo_vauxn_voltages,
427 .update_val_idle = 0x0c,
428 .update_val_normal = 0x04,
429 .voltage_bank = 0x04,
431 .voltage_mask = 0x0f,
433 [AB8500_LDO_AUX3] = {
436 .ops = &ab8500_regulator_volt_mode_ops,
437 .type = REGULATOR_VOLTAGE,
438 .id = AB8500_LDO_AUX3,
439 .owner = THIS_MODULE,
440 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
441 .volt_table = ldo_vaux3_voltages,
449 .update_val_idle = 0x03,
450 .update_val_normal = 0x01,
451 .voltage_bank = 0x04,
453 .voltage_mask = 0x07,
455 [AB8500_LDO_INTCORE] = {
457 .name = "LDO-INTCORE",
458 .ops = &ab8500_regulator_volt_mode_ops,
459 .type = REGULATOR_VOLTAGE,
460 .id = AB8500_LDO_INTCORE,
461 .owner = THIS_MODULE,
462 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
463 .volt_table = ldo_vintcore_voltages,
471 .update_val_idle = 0x44,
472 .update_val_normal = 0x04,
473 .voltage_bank = 0x03,
475 .voltage_mask = 0x38,
480 * Fixed Voltage Regulators
482 * update bank, reg, mask, enable val
484 [AB8500_LDO_TVOUT] = {
487 .ops = &ab8500_regulator_mode_ops,
488 .type = REGULATOR_VOLTAGE,
489 .id = AB8500_LDO_TVOUT,
490 .owner = THIS_MODULE,
500 .update_val_idle = 0x82,
501 .update_val_normal = 0x02,
503 [AB8500_LDO_AUDIO] = {
506 .ops = &ab8500_regulator_ops,
507 .type = REGULATOR_VOLTAGE,
508 .id = AB8500_LDO_AUDIO,
509 .owner = THIS_MODULE,
519 [AB8500_LDO_ANAMIC1] = {
521 .name = "LDO-ANAMIC1",
522 .ops = &ab8500_regulator_ops,
523 .type = REGULATOR_VOLTAGE,
524 .id = AB8500_LDO_ANAMIC1,
525 .owner = THIS_MODULE,
535 [AB8500_LDO_ANAMIC2] = {
537 .name = "LDO-ANAMIC2",
538 .ops = &ab8500_regulator_ops,
539 .type = REGULATOR_VOLTAGE,
540 .id = AB8500_LDO_ANAMIC2,
541 .owner = THIS_MODULE,
551 [AB8500_LDO_DMIC] = {
554 .ops = &ab8500_regulator_ops,
555 .type = REGULATOR_VOLTAGE,
556 .id = AB8500_LDO_DMIC,
557 .owner = THIS_MODULE,
569 * Regulators with fixed voltage and normal/idle modes
574 .ops = &ab8500_regulator_mode_ops,
575 .type = REGULATOR_VOLTAGE,
576 .id = AB8500_LDO_ANA,
577 .owner = THIS_MODULE,
587 .update_val_idle = 0x0c,
588 .update_val_normal = 0x04,
592 /* AB9540 regulator information */
593 static struct ab8500_regulator_info
594 ab9540_regulator_info[AB9540_NUM_REGULATORS] = {
596 * Variable Voltage Regulators
597 * name, min mV, max mV,
598 * update bank, reg, mask, enable val
599 * volt bank, reg, mask, table, table length
601 [AB9540_LDO_AUX1] = {
604 .ops = &ab8500_regulator_volt_mode_ops,
605 .type = REGULATOR_VOLTAGE,
606 .id = AB8500_LDO_AUX1,
607 .owner = THIS_MODULE,
608 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
617 .update_val_idle = 0x03,
618 .update_val_normal = 0x01,
619 .voltage_bank = 0x04,
621 .voltage_mask = 0x0f,
622 .voltages = ldo_vauxn_voltages,
623 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
625 [AB9540_LDO_AUX2] = {
628 .ops = &ab8500_regulator_volt_mode_ops,
629 .type = REGULATOR_VOLTAGE,
630 .id = AB8500_LDO_AUX2,
631 .owner = THIS_MODULE,
632 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
641 .update_val_idle = 0x0c,
642 .update_val_normal = 0x04,
643 .voltage_bank = 0x04,
645 .voltage_mask = 0x0f,
646 .voltages = ldo_vauxn_voltages,
647 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
649 [AB9540_LDO_AUX3] = {
652 .ops = &ab8500_regulator_volt_mode_ops,
653 .type = REGULATOR_VOLTAGE,
654 .id = AB8500_LDO_AUX3,
655 .owner = THIS_MODULE,
656 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
665 .update_val_idle = 0x03,
666 .update_val_normal = 0x01,
667 .voltage_bank = 0x04,
669 .voltage_mask = 0x07,
670 .voltages = ldo_vaux3_voltages,
671 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
673 [AB9540_LDO_AUX4] = {
676 .ops = &ab8500_regulator_volt_mode_ops,
677 .type = REGULATOR_VOLTAGE,
678 .id = AB9540_LDO_AUX4,
679 .owner = THIS_MODULE,
680 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
685 /* values for Vaux4Regu register */
690 .update_val_idle = 0x03,
691 .update_val_normal = 0x01,
692 /* values for Vaux4SEL register */
693 .voltage_bank = 0x04,
695 .voltage_mask = 0x0f,
696 .voltages = ldo_vauxn_voltages,
697 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
699 [AB9540_LDO_INTCORE] = {
701 .name = "LDO-INTCORE",
702 .ops = &ab8500_regulator_volt_mode_ops,
703 .type = REGULATOR_VOLTAGE,
704 .id = AB8500_LDO_INTCORE,
705 .owner = THIS_MODULE,
706 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
715 .update_val_idle = 0x44,
716 .update_val_normal = 0x04,
717 .voltage_bank = 0x03,
719 .voltage_mask = 0x38,
720 .voltages = ldo_vintcore_voltages,
721 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
726 * Fixed Voltage Regulators
728 * update bank, reg, mask, enable val
730 [AB9540_LDO_TVOUT] = {
733 .ops = &ab8500_regulator_mode_ops,
734 .type = REGULATOR_VOLTAGE,
735 .id = AB8500_LDO_TVOUT,
736 .owner = THIS_MODULE,
746 .update_val_idle = 0x82,
747 .update_val_normal = 0x02,
752 .ops = &ab8500_regulator_ops,
753 .type = REGULATOR_VOLTAGE,
754 .id = AB9540_LDO_USB,
755 .owner = THIS_MODULE,
763 .update_val_idle = 0x03,
764 .update_val_normal = 0x01,
766 [AB9540_LDO_AUDIO] = {
769 .ops = &ab8500_regulator_ops,
770 .type = REGULATOR_VOLTAGE,
771 .id = AB8500_LDO_AUDIO,
772 .owner = THIS_MODULE,
781 [AB9540_LDO_ANAMIC1] = {
783 .name = "LDO-ANAMIC1",
784 .ops = &ab8500_regulator_ops,
785 .type = REGULATOR_VOLTAGE,
786 .id = AB8500_LDO_ANAMIC1,
787 .owner = THIS_MODULE,
796 [AB9540_LDO_ANAMIC2] = {
798 .name = "LDO-ANAMIC2",
799 .ops = &ab8500_regulator_ops,
800 .type = REGULATOR_VOLTAGE,
801 .id = AB8500_LDO_ANAMIC2,
802 .owner = THIS_MODULE,
811 [AB9540_LDO_DMIC] = {
814 .ops = &ab8500_regulator_ops,
815 .type = REGULATOR_VOLTAGE,
816 .id = AB8500_LDO_DMIC,
817 .owner = THIS_MODULE,
828 * Regulators with fixed voltage and normal/idle modes
833 .ops = &ab8500_regulator_mode_ops,
834 .type = REGULATOR_VOLTAGE,
835 .id = AB8500_LDO_ANA,
836 .owner = THIS_MODULE,
845 .update_val_idle = 0x0c,
846 .update_val_normal = 0x08,
850 struct ab8500_reg_init {
856 #define REG_INIT(_id, _bank, _addr, _mask) \
863 /* AB8500 register init */
864 static struct ab8500_reg_init ab8500_reg_init[] = {
866 * 0x30, VanaRequestCtrl
867 * 0xc0, VextSupply1RequestCtrl
869 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xf0),
871 * 0x03, VextSupply2RequestCtrl
872 * 0x0c, VextSupply3RequestCtrl
873 * 0x30, Vaux1RequestCtrl
874 * 0xc0, Vaux2RequestCtrl
876 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
878 * 0x03, Vaux3RequestCtrl
881 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
883 * 0x08, VanaSysClkReq1HPValid
884 * 0x20, Vaux1SysClkReq1HPValid
885 * 0x40, Vaux2SysClkReq1HPValid
886 * 0x80, Vaux3SysClkReq1HPValid
888 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
890 * 0x10, VextSupply1SysClkReq1HPValid
891 * 0x20, VextSupply2SysClkReq1HPValid
892 * 0x40, VextSupply3SysClkReq1HPValid
894 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
896 * 0x08, VanaHwHPReq1Valid
897 * 0x20, Vaux1HwHPReq1Valid
898 * 0x40, Vaux2HwHPReq1Valid
899 * 0x80, Vaux3HwHPReq1Valid
901 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
903 * 0x01, VextSupply1HwHPReq1Valid
904 * 0x02, VextSupply2HwHPReq1Valid
905 * 0x04, VextSupply3HwHPReq1Valid
907 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
909 * 0x08, VanaHwHPReq2Valid
910 * 0x20, Vaux1HwHPReq2Valid
911 * 0x40, Vaux2HwHPReq2Valid
912 * 0x80, Vaux3HwHPReq2Valid
914 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
916 * 0x01, VextSupply1HwHPReq2Valid
917 * 0x02, VextSupply2HwHPReq2Valid
918 * 0x04, VextSupply3HwHPReq2Valid
920 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
922 * 0x20, VanaSwHPReqValid
923 * 0x80, Vaux1SwHPReqValid
925 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
927 * 0x01, Vaux2SwHPReqValid
928 * 0x02, Vaux3SwHPReqValid
929 * 0x04, VextSupply1SwHPReqValid
930 * 0x08, VextSupply2SwHPReqValid
931 * 0x10, VextSupply3SwHPReqValid
933 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
935 * 0x02, SysClkReq2Valid1
936 * 0x04, SysClkReq3Valid1
937 * 0x08, SysClkReq4Valid1
938 * 0x10, SysClkReq5Valid1
939 * 0x20, SysClkReq6Valid1
940 * 0x40, SysClkReq7Valid1
941 * 0x80, SysClkReq8Valid1
943 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
945 * 0x02, SysClkReq2Valid2
946 * 0x04, SysClkReq3Valid2
947 * 0x08, SysClkReq4Valid2
948 * 0x10, SysClkReq5Valid2
949 * 0x20, SysClkReq6Valid2
950 * 0x40, SysClkReq7Valid2
951 * 0x80, SysClkReq8Valid2
953 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
956 * 0x04, Vintcore12Ena
957 * 0x38, Vintcore12Sel
961 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
968 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
973 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
975 * 0x03, VpllRegu (NOTE! PRCMU register bits)
978 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
981 * 0x02, VrefDDRSleepMode
983 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
985 * 0x03, VextSupply1Regu
986 * 0x0c, VextSupply2Regu
987 * 0x30, VextSupply3Regu
988 * 0x40, ExtSupply2Bypass
989 * 0x80, ExtSupply3Bypass
991 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
996 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
1000 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
1004 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
1008 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
1012 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
1014 * 0x01, VextSupply12LP
1016 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
1021 * 0x20, Vintcore12Disch
1025 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
1028 * 0x04, VdmicPullDownEna
1031 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
1034 /* AB9540 register init */
1035 static struct ab8500_reg_init ab9540_reg_init[] = {
1037 * 0x03, VarmRequestCtrl
1038 * 0x0c, VapeRequestCtrl
1039 * 0x30, Vsmps1RequestCtrl
1040 * 0xc0, Vsmps2RequestCtrl
1042 REG_INIT(AB9540_REGUREQUESTCTRL1, 0x03, 0x03, 0xff),
1044 * 0x03, Vsmps3RequestCtrl
1045 * 0x0c, VpllRequestCtrl
1046 * 0x30, VanaRequestCtrl
1047 * 0xc0, VextSupply1RequestCtrl
1049 REG_INIT(AB9540_REGUREQUESTCTRL2, 0x03, 0x04, 0xff),
1051 * 0x03, VextSupply2RequestCtrl
1052 * 0x0c, VextSupply3RequestCtrl
1053 * 0x30, Vaux1RequestCtrl
1054 * 0xc0, Vaux2RequestCtrl
1056 REG_INIT(AB9540_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
1058 * 0x03, Vaux3RequestCtrl
1061 REG_INIT(AB9540_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
1063 * 0x01, Vsmps1SysClkReq1HPValid
1064 * 0x02, Vsmps2SysClkReq1HPValid
1065 * 0x04, Vsmps3SysClkReq1HPValid
1066 * 0x08, VanaSysClkReq1HPValid
1067 * 0x10, VpllSysClkReq1HPValid
1068 * 0x20, Vaux1SysClkReq1HPValid
1069 * 0x40, Vaux2SysClkReq1HPValid
1070 * 0x80, Vaux3SysClkReq1HPValid
1072 REG_INIT(AB9540_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff),
1074 * 0x01, VapeSysClkReq1HPValid
1075 * 0x02, VarmSysClkReq1HPValid
1076 * 0x04, VbbSysClkReq1HPValid
1077 * 0x08, VmodSysClkReq1HPValid
1078 * 0x10, VextSupply1SysClkReq1HPValid
1079 * 0x20, VextSupply2SysClkReq1HPValid
1080 * 0x40, VextSupply3SysClkReq1HPValid
1082 REG_INIT(AB9540_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x7f),
1084 * 0x01, Vsmps1HwHPReq1Valid
1085 * 0x02, Vsmps2HwHPReq1Valid
1086 * 0x04, Vsmps3HwHPReq1Valid
1087 * 0x08, VanaHwHPReq1Valid
1088 * 0x10, VpllHwHPReq1Valid
1089 * 0x20, Vaux1HwHPReq1Valid
1090 * 0x40, Vaux2HwHPReq1Valid
1091 * 0x80, Vaux3HwHPReq1Valid
1093 REG_INIT(AB9540_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xff),
1095 * 0x01, VextSupply1HwHPReq1Valid
1096 * 0x02, VextSupply2HwHPReq1Valid
1097 * 0x04, VextSupply3HwHPReq1Valid
1098 * 0x08, VmodHwHPReq1Valid
1100 REG_INIT(AB9540_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x0f),
1102 * 0x01, Vsmps1HwHPReq2Valid
1103 * 0x02, Vsmps2HwHPReq2Valid
1104 * 0x03, Vsmps3HwHPReq2Valid
1105 * 0x08, VanaHwHPReq2Valid
1106 * 0x10, VpllHwHPReq2Valid
1107 * 0x20, Vaux1HwHPReq2Valid
1108 * 0x40, Vaux2HwHPReq2Valid
1109 * 0x80, Vaux3HwHPReq2Valid
1111 REG_INIT(AB9540_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xff),
1113 * 0x01, VextSupply1HwHPReq2Valid
1114 * 0x02, VextSupply2HwHPReq2Valid
1115 * 0x04, VextSupply3HwHPReq2Valid
1116 * 0x08, VmodHwHPReq2Valid
1118 REG_INIT(AB9540_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x0f),
1120 * 0x01, VapeSwHPReqValid
1121 * 0x02, VarmSwHPReqValid
1122 * 0x04, Vsmps1SwHPReqValid
1123 * 0x08, Vsmps2SwHPReqValid
1124 * 0x10, Vsmps3SwHPReqValid
1125 * 0x20, VanaSwHPReqValid
1126 * 0x40, VpllSwHPReqValid
1127 * 0x80, Vaux1SwHPReqValid
1129 REG_INIT(AB9540_REGUSWHPREQVALID1, 0x03, 0x0d, 0xff),
1131 * 0x01, Vaux2SwHPReqValid
1132 * 0x02, Vaux3SwHPReqValid
1133 * 0x04, VextSupply1SwHPReqValid
1134 * 0x08, VextSupply2SwHPReqValid
1135 * 0x10, VextSupply3SwHPReqValid
1136 * 0x20, VmodSwHPReqValid
1138 REG_INIT(AB9540_REGUSWHPREQVALID2, 0x03, 0x0e, 0x3f),
1140 * 0x02, SysClkReq2Valid1
1142 * 0x80, SysClkReq8Valid1
1144 REG_INIT(AB9540_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
1146 * 0x02, SysClkReq2Valid2
1148 * 0x80, SysClkReq8Valid2
1150 REG_INIT(AB9540_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
1152 * 0x01, Vaux4SwHPReqValid
1153 * 0x02, Vaux4HwHPReq2Valid
1154 * 0x04, Vaux4HwHPReq1Valid
1155 * 0x08, Vaux4SysClkReq1HPValid
1157 REG_INIT(AB9540_REGUVAUX4REQVALID, 0x03, 0x11, 0x0f),
1160 * 0x04, Vintcore12Ena
1161 * 0x38, Vintcore12Sel
1162 * 0x40, Vintcore12LP
1165 REG_INIT(AB9540_REGUMISC1, 0x03, 0x80, 0xfe),
1172 REG_INIT(AB9540_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
1174 * 0x01, Vamic1_dzout
1175 * 0x02, Vamic2_dzout
1177 REG_INIT(AB9540_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
1180 * 0x0c, Vsmps1SelCtrl
1181 * 0x10, Vsmps1AutoMode
1182 * 0x20, Vsmps1PWMMode
1184 REG_INIT(AB9540_VSMPS1REGU, 0x04, 0x03, 0x3f),
1187 * 0x0c, Vsmps2SelCtrl
1188 * 0x10, Vsmps2AutoMode
1189 * 0x20, Vsmps2PWMMode
1191 REG_INIT(AB9540_VSMPS2REGU, 0x04, 0x04, 0x3f),
1194 * 0x0c, Vsmps3SelCtrl
1195 * NOTE! PRCMU register
1197 REG_INIT(AB9540_VSMPS3REGU, 0x04, 0x05, 0x0f),
1202 REG_INIT(AB9540_VPLLVANAREGU, 0x04, 0x06, 0x0f),
1204 * 0x03, VextSupply1Regu
1205 * 0x0c, VextSupply2Regu
1206 * 0x30, VextSupply3Regu
1207 * 0x40, ExtSupply2Bypass
1208 * 0x80, ExtSupply3Bypass
1210 REG_INIT(AB9540_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
1215 REG_INIT(AB9540_VAUX12REGU, 0x04, 0x09, 0x0f),
1220 REG_INIT(AB9540_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f),
1224 REG_INIT(AB9540_VSMPS1SEL1, 0x04, 0x13, 0x3f),
1228 REG_INIT(AB9540_VSMPS1SEL2, 0x04, 0x14, 0x3f),
1232 REG_INIT(AB9540_VSMPS1SEL3, 0x04, 0x15, 0x3f),
1236 REG_INIT(AB9540_VSMPS2SEL1, 0x04, 0x17, 0x3f),
1240 REG_INIT(AB9540_VSMPS2SEL2, 0x04, 0x18, 0x3f),
1244 REG_INIT(AB9540_VSMPS2SEL3, 0x04, 0x19, 0x3f),
1247 * NOTE! PRCMU register
1249 REG_INIT(AB9540_VSMPS3SEL1, 0x04, 0x1b, 0x7f),
1252 * NOTE! PRCMU register
1254 REG_INIT(AB9540_VSMPS3SEL2, 0x04, 0x1c, 0x7f),
1258 REG_INIT(AB9540_VAUX1SEL, 0x04, 0x1f, 0x0f),
1262 REG_INIT(AB9540_VAUX2SEL, 0x04, 0x20, 0x0f),
1267 REG_INIT(AB9540_VRF1VAUX3SEL, 0x04, 0x21, 0x37),
1269 * 0x01, VextSupply12LP
1271 REG_INIT(AB9540_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
1273 * 0x03, Vaux4RequestCtrl
1275 REG_INIT(AB9540_VAUX4REQCTRL, 0x04, 0x2d, 0x03),
1279 REG_INIT(AB9540_VAUX4REGU, 0x04, 0x2e, 0x03),
1283 REG_INIT(AB9540_VAUX4SEL, 0x04, 0x2f, 0x0f),
1290 * 0x20, Vintcore12Disch
1294 REG_INIT(AB9540_REGUCTRLDISCH, 0x04, 0x43, 0xff),
1298 * 0x04, VdmicPullDownEna
1299 * 0x08, VpllPullDownEna
1302 REG_INIT(AB9540_REGUCTRLDISCH2, 0x04, 0x44, 0x1f),
1306 REG_INIT(AB9540_REGUCTRLDISCH3, 0x04, 0x48, 0x01),
1309 static int ab8500_regulator_init_registers(struct platform_device *pdev,
1310 struct ab8500_reg_init *reg_init,
1311 int id, int mask, int value)
1315 BUG_ON(value & ~mask);
1316 BUG_ON(mask & ~reg_init[id].mask);
1318 /* initialize register */
1319 err = abx500_mask_and_set_register_interruptible(
1326 "Failed to initialize 0x%02x, 0x%02x.\n",
1331 dev_vdbg(&pdev->dev,
1332 " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
1340 static int ab8500_regulator_register(struct platform_device *pdev,
1341 struct regulator_init_data *init_data,
1342 struct ab8500_regulator_info *regulator_info,
1343 int id, struct device_node *np)
1345 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1346 struct ab8500_regulator_info *info = NULL;
1347 struct regulator_config config = { };
1350 /* assign per-regulator data */
1351 info = ®ulator_info[id];
1352 info->dev = &pdev->dev;
1354 config.dev = &pdev->dev;
1355 config.init_data = init_data;
1356 config.driver_data = info;
1357 config.of_node = np;
1359 /* fix for hardware before ab8500v2.0 */
1360 if (is_ab8500_1p1_or_earlier(ab8500)) {
1361 if (info->desc.id == AB8500_LDO_AUX3) {
1362 info->desc.n_voltages =
1363 ARRAY_SIZE(ldo_vauxn_voltages);
1364 info->desc.volt_table = ldo_vauxn_voltages;
1365 info->voltage_mask = 0xf;
1369 /* register regulator with framework */
1370 info->regulator = regulator_register(&info->desc, &config);
1371 if (IS_ERR(info->regulator)) {
1372 err = PTR_ERR(info->regulator);
1373 dev_err(&pdev->dev, "failed to register regulator %s\n",
1375 /* when we fail, un-register all earlier regulators */
1377 info = ®ulator_info[id];
1378 regulator_unregister(info->regulator);
1386 static struct of_regulator_match ab8500_regulator_match[] = {
1387 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
1388 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
1389 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
1390 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
1391 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
1392 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
1393 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
1394 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
1395 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
1396 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
1399 static struct of_regulator_match ab9540_regulator_match[] = {
1400 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB9540_LDO_AUX1, },
1401 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB9540_LDO_AUX2, },
1402 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB9540_LDO_AUX3, },
1403 { .name = "ab8500_ldo_aux4", .driver_data = (void *) AB9540_LDO_AUX4, },
1404 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB9540_LDO_INTCORE, },
1405 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB9540_LDO_TVOUT, },
1406 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB9540_LDO_AUDIO, },
1407 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB9540_LDO_ANAMIC1, },
1408 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB9540_LDO_ANAMIC2, },
1409 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB9540_LDO_DMIC, },
1410 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB9540_LDO_ANA, },
1414 ab8500_regulator_of_probe(struct platform_device *pdev,
1415 struct ab8500_regulator_info *regulator_info,
1416 int regulator_info_size,
1417 struct of_regulator_match *match,
1418 struct device_node *np)
1422 for (i = 0; i < regulator_info_size; i++) {
1423 err = ab8500_regulator_register(
1424 pdev, match[i].init_data, regulator_info,
1425 i, match[i].of_node);
1433 static int ab8500_regulator_probe(struct platform_device *pdev)
1435 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1436 struct device_node *np = pdev->dev.of_node;
1437 struct of_regulator_match *match;
1438 struct ab8500_platform_data *ppdata;
1439 struct ab8500_regulator_platform_data *pdata;
1441 struct ab8500_regulator_info *regulator_info;
1442 int regulator_info_size;
1443 struct ab8500_reg_init *reg_init;
1446 if (is_ab9540(ab8500)) {
1447 regulator_info = ab9540_regulator_info;
1448 regulator_info_size = ARRAY_SIZE(ab9540_regulator_info);
1449 reg_init = ab9540_reg_init;
1450 reg_init_size = AB9540_NUM_REGULATOR_REGISTERS;
1451 match = ab9540_regulator_match;
1452 match_size = ARRAY_SIZE(ab9540_regulator_match)
1454 regulator_info = ab8500_regulator_info;
1455 regulator_info_size = ARRAY_SIZE(ab8500_regulator_info);
1456 reg_init = ab8500_reg_init;
1457 reg_init_size = AB8500_NUM_REGULATOR_REGISTERS;
1458 match = ab8500_regulator_match;
1459 match_size = ARRAY_SIZE(ab8500_regulator_match)
1463 err = of_regulator_match(&pdev->dev, np, match, match_size);
1466 "Error parsing regulator init data: %d\n", err);
1470 err = ab8500_regulator_of_probe(pdev, regulator_info,
1471 regulator_info_size, match, np);
1476 dev_err(&pdev->dev, "null mfd parent\n");
1480 ppdata = dev_get_platdata(ab8500->dev);
1482 dev_err(&pdev->dev, "null parent pdata\n");
1486 pdata = ppdata->regulator;
1488 dev_err(&pdev->dev, "null pdata\n");
1492 /* make sure the platform data has the correct size */
1493 if (pdata->num_regulator != regulator_info_size) {
1494 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
1498 /* initialize debug (initial state is recorded with this call) */
1499 err = ab8500_regulator_debug_init(pdev);
1503 /* initialize registers */
1504 for (i = 0; i < pdata->num_reg_init; i++) {
1505 int id, mask, value;
1507 id = pdata->reg_init[i].id;
1508 mask = pdata->reg_init[i].mask;
1509 value = pdata->reg_init[i].value;
1511 /* check for configuration errors */
1512 BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS);
1514 err = ab8500_regulator_init_registers(pdev, reg_init, id, mask, value);
1519 /* register external regulators (before Vaux1, 2 and 3) */
1520 err = ab8500_ext_regulator_init(pdev);
1524 /* register all regulators */
1525 for (i = 0; i < regulator_info_size; i++) {
1526 err = ab8500_regulator_register(pdev, &pdata->regulator[i],
1527 regulator_info, i, NULL);
1535 static int ab8500_regulator_remove(struct platform_device *pdev)
1538 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1539 struct ab8500_regulator_info *regulator_info;
1540 int regulator_info_size;
1543 if (is_ab9540(ab8500)) {
1544 regulator_info = ab9540_regulator_info;
1545 regulator_info_size = ARRAY_SIZE(ab9540_regulator_info);
1547 regulator_info = ab8500_regulator_info;
1548 regulator_info_size = ARRAY_SIZE(ab8500_regulator_info);
1551 for (i = 0; i < regulator_info_size; i++) {
1552 struct ab8500_regulator_info *info = NULL;
1553 info = ®ulator_info[i];
1555 dev_vdbg(rdev_get_dev(info->regulator),
1556 "%s-remove\n", info->desc.name);
1558 regulator_unregister(info->regulator);
1561 /* remove external regulators (after Vaux1, 2 and 3) */
1562 err = ab8500_ext_regulator_exit(pdev);
1566 /* remove regulator debug */
1567 err = ab8500_regulator_debug_exit(pdev);
1574 static struct platform_driver ab8500_regulator_driver = {
1575 .probe = ab8500_regulator_probe,
1576 .remove = ab8500_regulator_remove,
1578 .name = "ab8500-regulator",
1579 .owner = THIS_MODULE,
1583 static int __init ab8500_regulator_init(void)
1587 ret = platform_driver_register(&ab8500_regulator_driver);
1589 pr_err("Failed to register ab8500 regulator: %d\n", ret);
1593 subsys_initcall(ab8500_regulator_init);
1595 static void __exit ab8500_regulator_exit(void)
1597 platform_driver_unregister(&ab8500_regulator_driver);
1599 module_exit(ab8500_regulator_exit);
1601 MODULE_LICENSE("GPL v2");
1602 MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
1603 MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
1604 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
1605 MODULE_ALIAS("platform:ab8500-regulator");