2 * Copyright (C) ST-Ericsson SA 2010
4 * License Terms: GNU General Public License v2
10 * AB8500 peripheral regulators
12 * AB8500 supports the following regulators:
13 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
15 * AB8505 supports the following regulators:
16 * VAUX1/2/3/4/5/6, VINTCORE, VADC, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/err.h>
22 #include <linux/platform_device.h>
23 #include <linux/mfd/abx500.h>
24 #include <linux/mfd/abx500/ab8500.h>
26 #include <linux/regulator/of_regulator.h>
27 #include <linux/regulator/driver.h>
28 #include <linux/regulator/machine.h>
29 #include <linux/regulator/ab8500.h>
30 #include <linux/slab.h>
33 * struct ab8500_shared_mode - is used when mode is shared between
35 * @shared_regulator: pointer to the other sharing regulator
36 * @lp_mode_req: low power mode requested by this regulator
38 struct ab8500_shared_mode {
39 struct ab8500_regulator_info *shared_regulator;
44 * struct ab8500_regulator_info - ab8500 regulator information
45 * @dev: device pointer
46 * @desc: regulator description
47 * @shared_mode: used when mode is shared between two regulators
48 * @load_lp_uA: maximum load in idle (low power) mode
49 * @update_bank: bank to control on/off
50 * @update_reg: register to control on/off
51 * @update_mask: mask to enable/disable and set mode of regulator
52 * @update_val: bits holding the regulator current mode
53 * @update_val_idle: bits to enable the regulator in idle (low power) mode
54 * @update_val_normal: bits to enable the regulator in normal (high power) mode
55 * @mode_bank: bank with location of mode register
56 * @mode_reg: mode register
57 * @mode_mask: mask for setting mode
58 * @mode_val_idle: mode setting for low power
59 * @mode_val_normal: mode setting for normal power
60 * @voltage_bank: bank to control regulator voltage
61 * @voltage_reg: register to control regulator voltage
62 * @voltage_mask: mask to control regulator voltage
64 struct ab8500_regulator_info {
66 struct regulator_desc desc;
67 struct ab8500_shared_mode *shared_mode;
91 /* voltage tables for the vauxn/vintcore supplies */
92 static const unsigned int ldo_vauxn_voltages[] = {
111 static const unsigned int ldo_vaux3_voltages[] = {
122 static const unsigned int ldo_vaux56_voltages[] = {
133 static const unsigned int ldo_vintcore_voltages[] = {
143 static const unsigned int ldo_sdio_voltages[] = {
154 static const unsigned int fixed_1200000_voltage[] = {
158 static const unsigned int fixed_1800000_voltage[] = {
162 static const unsigned int fixed_2000000_voltage[] = {
166 static const unsigned int fixed_2050000_voltage[] = {
170 static const unsigned int fixed_3300000_voltage[] = {
174 static const unsigned int ldo_vana_voltages[] = {
185 static const unsigned int ldo_vaudio_voltages[] = {
193 2600000, /* Duplicated in Vaudio and IsoUicc Control register. */
196 static const unsigned int ldo_vdmic_voltages[] = {
203 static DEFINE_MUTEX(shared_mode_mutex);
204 static struct ab8500_shared_mode ldo_anamic1_shared;
205 static struct ab8500_shared_mode ldo_anamic2_shared;
207 static int ab8500_regulator_enable(struct regulator_dev *rdev)
210 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
213 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
217 ret = abx500_mask_and_set_register_interruptible(info->dev,
218 info->update_bank, info->update_reg,
219 info->update_mask, info->update_val);
221 dev_err(rdev_get_dev(rdev),
222 "couldn't set enable bits for regulator\n");
226 dev_vdbg(rdev_get_dev(rdev),
227 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
228 info->desc.name, info->update_bank, info->update_reg,
229 info->update_mask, info->update_val);
234 static int ab8500_regulator_disable(struct regulator_dev *rdev)
237 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
240 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
244 ret = abx500_mask_and_set_register_interruptible(info->dev,
245 info->update_bank, info->update_reg,
246 info->update_mask, 0x0);
248 dev_err(rdev_get_dev(rdev),
249 "couldn't set disable bits for regulator\n");
253 dev_vdbg(rdev_get_dev(rdev),
254 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
255 info->desc.name, info->update_bank, info->update_reg,
256 info->update_mask, 0x0);
261 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
264 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
268 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
272 ret = abx500_get_register_interruptible(info->dev,
273 info->update_bank, info->update_reg, ®val);
275 dev_err(rdev_get_dev(rdev),
276 "couldn't read 0x%x register\n", info->update_reg);
280 dev_vdbg(rdev_get_dev(rdev),
281 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
283 info->desc.name, info->update_bank, info->update_reg,
284 info->update_mask, regval);
286 if (regval & info->update_mask)
292 static unsigned int ab8500_regulator_get_optimum_mode(
293 struct regulator_dev *rdev, int input_uV,
294 int output_uV, int load_uA)
298 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
301 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
305 if (load_uA <= info->load_lp_uA)
306 mode = REGULATOR_MODE_IDLE;
308 mode = REGULATOR_MODE_NORMAL;
313 static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
317 u8 bank, reg, mask, val;
318 bool lp_mode_req = false;
319 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
322 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
326 if (info->mode_mask) {
327 bank = info->mode_bank;
328 reg = info->mode_reg;
329 mask = info->mode_mask;
331 bank = info->update_bank;
332 reg = info->update_reg;
333 mask = info->update_mask;
336 if (info->shared_mode)
337 mutex_lock(&shared_mode_mutex);
340 case REGULATOR_MODE_NORMAL:
341 if (info->shared_mode)
345 val = info->mode_val_normal;
347 val = info->update_val_normal;
349 case REGULATOR_MODE_IDLE:
350 if (info->shared_mode) {
351 struct ab8500_regulator_info *shared_regulator;
353 shared_regulator = info->shared_mode->shared_regulator;
354 if (!shared_regulator->shared_mode->lp_mode_req) {
355 /* Other regulator prevent LP mode */
356 info->shared_mode->lp_mode_req = true;
364 val = info->mode_val_idle;
366 val = info->update_val_idle;
373 if (info->mode_mask || ab8500_regulator_is_enabled(rdev)) {
374 ret = abx500_mask_and_set_register_interruptible(info->dev,
375 bank, reg, mask, val);
377 dev_err(rdev_get_dev(rdev),
378 "couldn't set regulator mode\n");
382 dev_vdbg(rdev_get_dev(rdev),
383 "%s-set_mode (bank, reg, mask, value): "
384 "0x%x, 0x%x, 0x%x, 0x%x\n",
385 info->desc.name, bank, reg,
389 if (!info->mode_mask)
390 info->update_val = val;
392 if (info->shared_mode)
393 info->shared_mode->lp_mode_req = lp_mode_req;
396 if (info->shared_mode)
397 mutex_unlock(&shared_mode_mutex);
402 static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
404 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
411 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
415 /* Need special handling for shared mode */
416 if (info->shared_mode) {
417 if (info->shared_mode->lp_mode_req)
418 return REGULATOR_MODE_IDLE;
420 return REGULATOR_MODE_NORMAL;
423 if (info->mode_mask) {
424 /* Dedicated register for handling mode */
425 ret = abx500_get_register_interruptible(info->dev,
426 info->mode_bank, info->mode_reg, &val);
427 val = val & info->mode_mask;
429 val_normal = info->mode_val_normal;
430 val_idle = info->mode_val_idle;
432 /* Mode register same as enable register */
433 val = info->update_val;
434 val_normal = info->update_val_normal;
435 val_idle = info->update_val_idle;
438 if (val == val_normal)
439 ret = REGULATOR_MODE_NORMAL;
440 else if (val == val_idle)
441 ret = REGULATOR_MODE_IDLE;
448 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
450 int ret, voltage_shift;
451 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
455 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
459 voltage_shift = ffs(info->voltage_mask) - 1;
461 ret = abx500_get_register_interruptible(info->dev,
462 info->voltage_bank, info->voltage_reg, ®val);
464 dev_err(rdev_get_dev(rdev),
465 "couldn't read voltage reg for regulator\n");
469 dev_vdbg(rdev_get_dev(rdev),
470 "%s-get_voltage (bank, reg, mask, shift, value): "
471 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
472 info->desc.name, info->voltage_bank,
473 info->voltage_reg, info->voltage_mask,
474 voltage_shift, regval);
476 return (regval & info->voltage_mask) >> voltage_shift;
479 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
482 int ret, voltage_shift;
483 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
487 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
491 voltage_shift = ffs(info->voltage_mask) - 1;
493 /* set the registers for the request */
494 regval = (u8)selector << voltage_shift;
495 ret = abx500_mask_and_set_register_interruptible(info->dev,
496 info->voltage_bank, info->voltage_reg,
497 info->voltage_mask, regval);
499 dev_err(rdev_get_dev(rdev),
500 "couldn't set voltage reg for regulator\n");
502 dev_vdbg(rdev_get_dev(rdev),
503 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
505 info->desc.name, info->voltage_bank, info->voltage_reg,
506 info->voltage_mask, regval);
511 static const struct regulator_ops ab8500_regulator_volt_mode_ops = {
512 .enable = ab8500_regulator_enable,
513 .disable = ab8500_regulator_disable,
514 .is_enabled = ab8500_regulator_is_enabled,
515 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
516 .set_mode = ab8500_regulator_set_mode,
517 .get_mode = ab8500_regulator_get_mode,
518 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
519 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
520 .list_voltage = regulator_list_voltage_table,
523 static const struct regulator_ops ab8500_regulator_volt_ops = {
524 .enable = ab8500_regulator_enable,
525 .disable = ab8500_regulator_disable,
526 .is_enabled = ab8500_regulator_is_enabled,
527 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
528 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
529 .list_voltage = regulator_list_voltage_table,
532 static const struct regulator_ops ab8500_regulator_mode_ops = {
533 .enable = ab8500_regulator_enable,
534 .disable = ab8500_regulator_disable,
535 .is_enabled = ab8500_regulator_is_enabled,
536 .get_optimum_mode = ab8500_regulator_get_optimum_mode,
537 .set_mode = ab8500_regulator_set_mode,
538 .get_mode = ab8500_regulator_get_mode,
539 .list_voltage = regulator_list_voltage_table,
542 static const struct regulator_ops ab8500_regulator_ops = {
543 .enable = ab8500_regulator_enable,
544 .disable = ab8500_regulator_disable,
545 .is_enabled = ab8500_regulator_is_enabled,
546 .list_voltage = regulator_list_voltage_table,
549 static const struct regulator_ops ab8500_regulator_anamic_mode_ops = {
550 .enable = ab8500_regulator_enable,
551 .disable = ab8500_regulator_disable,
552 .is_enabled = ab8500_regulator_is_enabled,
553 .set_mode = ab8500_regulator_set_mode,
554 .get_mode = ab8500_regulator_get_mode,
555 .list_voltage = regulator_list_voltage_table,
558 /* AB8500 regulator information */
559 static struct ab8500_regulator_info
560 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
562 * Variable Voltage Regulators
563 * name, min mV, max mV,
564 * update bank, reg, mask, enable val
565 * volt bank, reg, mask
567 [AB8500_LDO_AUX1] = {
570 .ops = &ab8500_regulator_volt_mode_ops,
571 .type = REGULATOR_VOLTAGE,
572 .id = AB8500_LDO_AUX1,
573 .owner = THIS_MODULE,
574 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
575 .volt_table = ldo_vauxn_voltages,
577 .supply_name = "vin",
584 .update_val_idle = 0x03,
585 .update_val_normal = 0x01,
586 .voltage_bank = 0x04,
588 .voltage_mask = 0x0f,
590 [AB8500_LDO_AUX2] = {
593 .ops = &ab8500_regulator_volt_mode_ops,
594 .type = REGULATOR_VOLTAGE,
595 .id = AB8500_LDO_AUX2,
596 .owner = THIS_MODULE,
597 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
598 .volt_table = ldo_vauxn_voltages,
600 .supply_name = "vin",
607 .update_val_idle = 0x0c,
608 .update_val_normal = 0x04,
609 .voltage_bank = 0x04,
611 .voltage_mask = 0x0f,
613 [AB8500_LDO_AUX3] = {
616 .ops = &ab8500_regulator_volt_mode_ops,
617 .type = REGULATOR_VOLTAGE,
618 .id = AB8500_LDO_AUX3,
619 .owner = THIS_MODULE,
620 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
621 .volt_table = ldo_vaux3_voltages,
623 .supply_name = "vin",
630 .update_val_idle = 0x03,
631 .update_val_normal = 0x01,
632 .voltage_bank = 0x04,
634 .voltage_mask = 0x07,
636 [AB8500_LDO_INTCORE] = {
638 .name = "LDO-INTCORE",
639 .ops = &ab8500_regulator_volt_mode_ops,
640 .type = REGULATOR_VOLTAGE,
641 .id = AB8500_LDO_INTCORE,
642 .owner = THIS_MODULE,
643 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
644 .volt_table = ldo_vintcore_voltages,
652 .update_val_idle = 0x44,
653 .update_val_normal = 0x04,
654 .voltage_bank = 0x03,
656 .voltage_mask = 0x38,
660 * Fixed Voltage Regulators
662 * update bank, reg, mask, enable val
664 [AB8500_LDO_TVOUT] = {
667 .ops = &ab8500_regulator_mode_ops,
668 .type = REGULATOR_VOLTAGE,
669 .id = AB8500_LDO_TVOUT,
670 .owner = THIS_MODULE,
672 .volt_table = fixed_2000000_voltage,
680 .update_val_idle = 0x82,
681 .update_val_normal = 0x02,
683 [AB8500_LDO_AUDIO] = {
686 .ops = &ab8500_regulator_ops,
687 .type = REGULATOR_VOLTAGE,
688 .id = AB8500_LDO_AUDIO,
689 .owner = THIS_MODULE,
692 .volt_table = fixed_2000000_voltage,
699 [AB8500_LDO_ANAMIC1] = {
701 .name = "LDO-ANAMIC1",
702 .ops = &ab8500_regulator_ops,
703 .type = REGULATOR_VOLTAGE,
704 .id = AB8500_LDO_ANAMIC1,
705 .owner = THIS_MODULE,
708 .volt_table = fixed_2050000_voltage,
715 [AB8500_LDO_ANAMIC2] = {
717 .name = "LDO-ANAMIC2",
718 .ops = &ab8500_regulator_ops,
719 .type = REGULATOR_VOLTAGE,
720 .id = AB8500_LDO_ANAMIC2,
721 .owner = THIS_MODULE,
724 .volt_table = fixed_2050000_voltage,
731 [AB8500_LDO_DMIC] = {
734 .ops = &ab8500_regulator_ops,
735 .type = REGULATOR_VOLTAGE,
736 .id = AB8500_LDO_DMIC,
737 .owner = THIS_MODULE,
740 .volt_table = fixed_1800000_voltage,
749 * Regulators with fixed voltage and normal/idle modes
754 .ops = &ab8500_regulator_mode_ops,
755 .type = REGULATOR_VOLTAGE,
756 .id = AB8500_LDO_ANA,
757 .owner = THIS_MODULE,
760 .volt_table = fixed_1200000_voltage,
767 .update_val_idle = 0x0c,
768 .update_val_normal = 0x04,
772 /* AB8505 regulator information */
773 static struct ab8500_regulator_info
774 ab8505_regulator_info[AB8505_NUM_REGULATORS] = {
776 * Variable Voltage Regulators
777 * name, min mV, max mV,
778 * update bank, reg, mask, enable val
779 * volt bank, reg, mask
781 [AB8505_LDO_AUX1] = {
784 .ops = &ab8500_regulator_volt_mode_ops,
785 .type = REGULATOR_VOLTAGE,
786 .id = AB8505_LDO_AUX1,
787 .owner = THIS_MODULE,
788 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
789 .volt_table = ldo_vauxn_voltages,
796 .update_val_idle = 0x03,
797 .update_val_normal = 0x01,
798 .voltage_bank = 0x04,
800 .voltage_mask = 0x0f,
802 [AB8505_LDO_AUX2] = {
805 .ops = &ab8500_regulator_volt_mode_ops,
806 .type = REGULATOR_VOLTAGE,
807 .id = AB8505_LDO_AUX2,
808 .owner = THIS_MODULE,
809 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
810 .volt_table = ldo_vauxn_voltages,
817 .update_val_idle = 0x0c,
818 .update_val_normal = 0x04,
819 .voltage_bank = 0x04,
821 .voltage_mask = 0x0f,
823 [AB8505_LDO_AUX3] = {
826 .ops = &ab8500_regulator_volt_mode_ops,
827 .type = REGULATOR_VOLTAGE,
828 .id = AB8505_LDO_AUX3,
829 .owner = THIS_MODULE,
830 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
831 .volt_table = ldo_vaux3_voltages,
838 .update_val_idle = 0x03,
839 .update_val_normal = 0x01,
840 .voltage_bank = 0x04,
842 .voltage_mask = 0x07,
844 [AB8505_LDO_AUX4] = {
847 .ops = &ab8500_regulator_volt_mode_ops,
848 .type = REGULATOR_VOLTAGE,
849 .id = AB8505_LDO_AUX4,
850 .owner = THIS_MODULE,
851 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
852 .volt_table = ldo_vauxn_voltages,
855 /* values for Vaux4Regu register */
860 .update_val_idle = 0x03,
861 .update_val_normal = 0x01,
862 /* values for Vaux4SEL register */
863 .voltage_bank = 0x04,
865 .voltage_mask = 0x0f,
867 [AB8505_LDO_AUX5] = {
870 .ops = &ab8500_regulator_volt_mode_ops,
871 .type = REGULATOR_VOLTAGE,
872 .id = AB8505_LDO_AUX5,
873 .owner = THIS_MODULE,
874 .n_voltages = ARRAY_SIZE(ldo_vaux56_voltages),
875 .volt_table = ldo_vaux56_voltages,
878 /* values for CtrlVaux5 register */
883 .update_val_idle = 0x18,
884 .update_val_normal = 0x10,
885 .voltage_bank = 0x01,
887 .voltage_mask = 0x07,
889 [AB8505_LDO_AUX6] = {
892 .ops = &ab8500_regulator_volt_mode_ops,
893 .type = REGULATOR_VOLTAGE,
894 .id = AB8505_LDO_AUX6,
895 .owner = THIS_MODULE,
896 .n_voltages = ARRAY_SIZE(ldo_vaux56_voltages),
897 .volt_table = ldo_vaux56_voltages,
900 /* values for CtrlVaux6 register */
905 .update_val_idle = 0x18,
906 .update_val_normal = 0x10,
907 .voltage_bank = 0x01,
909 .voltage_mask = 0x07,
911 [AB8505_LDO_INTCORE] = {
913 .name = "LDO-INTCORE",
914 .ops = &ab8500_regulator_volt_mode_ops,
915 .type = REGULATOR_VOLTAGE,
916 .id = AB8505_LDO_INTCORE,
917 .owner = THIS_MODULE,
918 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
919 .volt_table = ldo_vintcore_voltages,
926 .update_val_idle = 0x44,
927 .update_val_normal = 0x04,
928 .voltage_bank = 0x03,
930 .voltage_mask = 0x38,
934 * Fixed Voltage Regulators
936 * update bank, reg, mask, enable val
941 .ops = &ab8500_regulator_mode_ops,
942 .type = REGULATOR_VOLTAGE,
943 .id = AB8505_LDO_ADC,
944 .owner = THIS_MODULE,
946 .volt_table = fixed_2000000_voltage,
947 .enable_time = 10000,
954 .update_val_idle = 0x82,
955 .update_val_normal = 0x02,
960 .ops = &ab8500_regulator_mode_ops,
961 .type = REGULATOR_VOLTAGE,
962 .id = AB8505_LDO_USB,
963 .owner = THIS_MODULE,
965 .volt_table = fixed_3300000_voltage,
971 .update_val_idle = 0x03,
972 .update_val_normal = 0x01,
974 [AB8505_LDO_AUDIO] = {
977 .ops = &ab8500_regulator_volt_ops,
978 .type = REGULATOR_VOLTAGE,
979 .id = AB8505_LDO_AUDIO,
980 .owner = THIS_MODULE,
981 .n_voltages = ARRAY_SIZE(ldo_vaudio_voltages),
982 .volt_table = ldo_vaudio_voltages,
988 .voltage_bank = 0x01,
990 .voltage_mask = 0x70,
992 [AB8505_LDO_ANAMIC1] = {
994 .name = "LDO-ANAMIC1",
995 .ops = &ab8500_regulator_anamic_mode_ops,
996 .type = REGULATOR_VOLTAGE,
997 .id = AB8505_LDO_ANAMIC1,
998 .owner = THIS_MODULE,
1000 .volt_table = fixed_2050000_voltage,
1002 .shared_mode = &ldo_anamic1_shared,
1003 .update_bank = 0x03,
1005 .update_mask = 0x08,
1010 .mode_val_idle = 0x04,
1011 .mode_val_normal = 0x00,
1013 [AB8505_LDO_ANAMIC2] = {
1015 .name = "LDO-ANAMIC2",
1016 .ops = &ab8500_regulator_anamic_mode_ops,
1017 .type = REGULATOR_VOLTAGE,
1018 .id = AB8505_LDO_ANAMIC2,
1019 .owner = THIS_MODULE,
1021 .volt_table = fixed_2050000_voltage,
1023 .shared_mode = &ldo_anamic2_shared,
1024 .update_bank = 0x03,
1026 .update_mask = 0x10,
1031 .mode_val_idle = 0x04,
1032 .mode_val_normal = 0x00,
1034 [AB8505_LDO_AUX8] = {
1037 .ops = &ab8500_regulator_ops,
1038 .type = REGULATOR_VOLTAGE,
1039 .id = AB8505_LDO_AUX8,
1040 .owner = THIS_MODULE,
1042 .volt_table = fixed_1800000_voltage,
1044 .update_bank = 0x03,
1046 .update_mask = 0x04,
1050 * Regulators with fixed voltage and normal/idle modes
1052 [AB8505_LDO_ANA] = {
1055 .ops = &ab8500_regulator_volt_mode_ops,
1056 .type = REGULATOR_VOLTAGE,
1057 .id = AB8505_LDO_ANA,
1058 .owner = THIS_MODULE,
1059 .n_voltages = ARRAY_SIZE(ldo_vana_voltages),
1060 .volt_table = ldo_vana_voltages,
1063 .update_bank = 0x04,
1065 .update_mask = 0x0c,
1067 .update_val_idle = 0x0c,
1068 .update_val_normal = 0x04,
1069 .voltage_bank = 0x04,
1070 .voltage_reg = 0x29,
1071 .voltage_mask = 0x7,
1075 static struct ab8500_shared_mode ldo_anamic1_shared = {
1076 .shared_regulator = &ab8505_regulator_info[AB8505_LDO_ANAMIC2],
1079 static struct ab8500_shared_mode ldo_anamic2_shared = {
1080 .shared_regulator = &ab8505_regulator_info[AB8505_LDO_ANAMIC1],
1083 struct ab8500_reg_init {
1089 #define REG_INIT(_id, _bank, _addr, _mask) \
1096 /* AB8500 register init */
1097 static struct ab8500_reg_init ab8500_reg_init[] = {
1099 * 0x30, VanaRequestCtrl
1100 * 0xc0, VextSupply1RequestCtrl
1102 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xf0),
1104 * 0x03, VextSupply2RequestCtrl
1105 * 0x0c, VextSupply3RequestCtrl
1106 * 0x30, Vaux1RequestCtrl
1107 * 0xc0, Vaux2RequestCtrl
1109 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
1111 * 0x03, Vaux3RequestCtrl
1114 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
1116 * 0x08, VanaSysClkReq1HPValid
1117 * 0x20, Vaux1SysClkReq1HPValid
1118 * 0x40, Vaux2SysClkReq1HPValid
1119 * 0x80, Vaux3SysClkReq1HPValid
1121 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
1123 * 0x10, VextSupply1SysClkReq1HPValid
1124 * 0x20, VextSupply2SysClkReq1HPValid
1125 * 0x40, VextSupply3SysClkReq1HPValid
1127 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
1129 * 0x08, VanaHwHPReq1Valid
1130 * 0x20, Vaux1HwHPReq1Valid
1131 * 0x40, Vaux2HwHPReq1Valid
1132 * 0x80, Vaux3HwHPReq1Valid
1134 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
1136 * 0x01, VextSupply1HwHPReq1Valid
1137 * 0x02, VextSupply2HwHPReq1Valid
1138 * 0x04, VextSupply3HwHPReq1Valid
1140 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
1142 * 0x08, VanaHwHPReq2Valid
1143 * 0x20, Vaux1HwHPReq2Valid
1144 * 0x40, Vaux2HwHPReq2Valid
1145 * 0x80, Vaux3HwHPReq2Valid
1147 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
1149 * 0x01, VextSupply1HwHPReq2Valid
1150 * 0x02, VextSupply2HwHPReq2Valid
1151 * 0x04, VextSupply3HwHPReq2Valid
1153 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
1155 * 0x20, VanaSwHPReqValid
1156 * 0x80, Vaux1SwHPReqValid
1158 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
1160 * 0x01, Vaux2SwHPReqValid
1161 * 0x02, Vaux3SwHPReqValid
1162 * 0x04, VextSupply1SwHPReqValid
1163 * 0x08, VextSupply2SwHPReqValid
1164 * 0x10, VextSupply3SwHPReqValid
1166 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
1168 * 0x02, SysClkReq2Valid1
1169 * 0x04, SysClkReq3Valid1
1170 * 0x08, SysClkReq4Valid1
1171 * 0x10, SysClkReq5Valid1
1172 * 0x20, SysClkReq6Valid1
1173 * 0x40, SysClkReq7Valid1
1174 * 0x80, SysClkReq8Valid1
1176 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
1178 * 0x02, SysClkReq2Valid2
1179 * 0x04, SysClkReq3Valid2
1180 * 0x08, SysClkReq4Valid2
1181 * 0x10, SysClkReq5Valid2
1182 * 0x20, SysClkReq6Valid2
1183 * 0x40, SysClkReq7Valid2
1184 * 0x80, SysClkReq8Valid2
1186 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
1189 * 0x04, Vintcore12Ena
1190 * 0x38, Vintcore12Sel
1191 * 0x40, Vintcore12LP
1194 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
1201 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
1203 * 0x01, Vamic1_dzout
1204 * 0x02, Vamic2_dzout
1206 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
1208 * 0x03, VpllRegu (NOTE! PRCMU register bits)
1211 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
1214 * 0x02, VrefDDRSleepMode
1216 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
1218 * 0x03, VextSupply1Regu
1219 * 0x0c, VextSupply2Regu
1220 * 0x30, VextSupply3Regu
1221 * 0x40, ExtSupply2Bypass
1222 * 0x80, ExtSupply3Bypass
1224 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
1229 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
1233 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
1237 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
1241 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
1245 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
1247 * 0x01, VextSupply12LP
1249 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
1254 * 0x20, Vintcore12Disch
1258 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
1261 * 0x04, VdmicPullDownEna
1264 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
1267 /* AB8505 register init */
1268 static struct ab8500_reg_init ab8505_reg_init[] = {
1270 * 0x03, VarmRequestCtrl
1271 * 0x0c, VsmpsCRequestCtrl
1272 * 0x30, VsmpsARequestCtrl
1273 * 0xc0, VsmpsBRequestCtrl
1275 REG_INIT(AB8505_REGUREQUESTCTRL1, 0x03, 0x03, 0xff),
1277 * 0x03, VsafeRequestCtrl
1278 * 0x0c, VpllRequestCtrl
1279 * 0x30, VanaRequestCtrl
1281 REG_INIT(AB8505_REGUREQUESTCTRL2, 0x03, 0x04, 0x3f),
1283 * 0x30, Vaux1RequestCtrl
1284 * 0xc0, Vaux2RequestCtrl
1286 REG_INIT(AB8505_REGUREQUESTCTRL3, 0x03, 0x05, 0xf0),
1288 * 0x03, Vaux3RequestCtrl
1291 REG_INIT(AB8505_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
1293 * 0x01, VsmpsASysClkReq1HPValid
1294 * 0x02, VsmpsBSysClkReq1HPValid
1295 * 0x04, VsafeSysClkReq1HPValid
1296 * 0x08, VanaSysClkReq1HPValid
1297 * 0x10, VpllSysClkReq1HPValid
1298 * 0x20, Vaux1SysClkReq1HPValid
1299 * 0x40, Vaux2SysClkReq1HPValid
1300 * 0x80, Vaux3SysClkReq1HPValid
1302 REG_INIT(AB8505_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff),
1304 * 0x01, VsmpsCSysClkReq1HPValid
1305 * 0x02, VarmSysClkReq1HPValid
1306 * 0x04, VbbSysClkReq1HPValid
1307 * 0x08, VsmpsMSysClkReq1HPValid
1309 REG_INIT(AB8505_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x0f),
1311 * 0x01, VsmpsAHwHPReq1Valid
1312 * 0x02, VsmpsBHwHPReq1Valid
1313 * 0x04, VsafeHwHPReq1Valid
1314 * 0x08, VanaHwHPReq1Valid
1315 * 0x10, VpllHwHPReq1Valid
1316 * 0x20, Vaux1HwHPReq1Valid
1317 * 0x40, Vaux2HwHPReq1Valid
1318 * 0x80, Vaux3HwHPReq1Valid
1320 REG_INIT(AB8505_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xff),
1322 * 0x08, VsmpsMHwHPReq1Valid
1324 REG_INIT(AB8505_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x08),
1326 * 0x01, VsmpsAHwHPReq2Valid
1327 * 0x02, VsmpsBHwHPReq2Valid
1328 * 0x04, VsafeHwHPReq2Valid
1329 * 0x08, VanaHwHPReq2Valid
1330 * 0x10, VpllHwHPReq2Valid
1331 * 0x20, Vaux1HwHPReq2Valid
1332 * 0x40, Vaux2HwHPReq2Valid
1333 * 0x80, Vaux3HwHPReq2Valid
1335 REG_INIT(AB8505_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xff),
1337 * 0x08, VsmpsMHwHPReq2Valid
1339 REG_INIT(AB8505_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x08),
1341 * 0x01, VsmpsCSwHPReqValid
1342 * 0x02, VarmSwHPReqValid
1343 * 0x04, VsmpsASwHPReqValid
1344 * 0x08, VsmpsBSwHPReqValid
1345 * 0x10, VsafeSwHPReqValid
1346 * 0x20, VanaSwHPReqValid
1347 * 0x40, VpllSwHPReqValid
1348 * 0x80, Vaux1SwHPReqValid
1350 REG_INIT(AB8505_REGUSWHPREQVALID1, 0x03, 0x0d, 0xff),
1352 * 0x01, Vaux2SwHPReqValid
1353 * 0x02, Vaux3SwHPReqValid
1354 * 0x20, VsmpsMSwHPReqValid
1356 REG_INIT(AB8505_REGUSWHPREQVALID2, 0x03, 0x0e, 0x23),
1358 * 0x02, SysClkReq2Valid1
1359 * 0x04, SysClkReq3Valid1
1360 * 0x08, SysClkReq4Valid1
1362 REG_INIT(AB8505_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0x0e),
1364 * 0x02, SysClkReq2Valid2
1365 * 0x04, SysClkReq3Valid2
1366 * 0x08, SysClkReq4Valid2
1368 REG_INIT(AB8505_REGUSYSCLKREQVALID2, 0x03, 0x10, 0x0e),
1370 * 0x01, Vaux4SwHPReqValid
1371 * 0x02, Vaux4HwHPReq2Valid
1372 * 0x04, Vaux4HwHPReq1Valid
1373 * 0x08, Vaux4SysClkReq1HPValid
1375 REG_INIT(AB8505_REGUVAUX4REQVALID, 0x03, 0x11, 0x0f),
1378 * 0x04, VintCore12Ena
1379 * 0x38, VintCore12Sel
1380 * 0x40, VintCore12LP
1383 REG_INIT(AB8505_REGUMISC1, 0x03, 0x80, 0xfe),
1390 REG_INIT(AB8505_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
1392 * 0x01, Vamic1_dzout
1393 * 0x02, Vamic2_dzout
1395 REG_INIT(AB8505_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
1398 * 0x0c, VsmpsASelCtrl
1399 * 0x10, VsmpsAAutoMode
1400 * 0x20, VsmpsAPWMMode
1402 REG_INIT(AB8505_VSMPSAREGU, 0x04, 0x03, 0x3f),
1405 * 0x0c, VsmpsBSelCtrl
1406 * 0x10, VsmpsBAutoMode
1407 * 0x20, VsmpsBPWMMode
1409 REG_INIT(AB8505_VSMPSBREGU, 0x04, 0x04, 0x3f),
1412 * 0x0c, VsafeSelCtrl
1413 * 0x10, VsafeAutoMode
1414 * 0x20, VsafePWMMode
1416 REG_INIT(AB8505_VSAFEREGU, 0x04, 0x05, 0x3f),
1418 * 0x03, VpllRegu (NOTE! PRCMU register bits)
1421 REG_INIT(AB8505_VPLLVANAREGU, 0x04, 0x06, 0x0f),
1423 * 0x03, VextSupply1Regu
1424 * 0x0c, VextSupply2Regu
1425 * 0x30, VextSupply3Regu
1426 * 0x40, ExtSupply2Bypass
1427 * 0x80, ExtSupply3Bypass
1429 REG_INIT(AB8505_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
1434 REG_INIT(AB8505_VAUX12REGU, 0x04, 0x09, 0x0f),
1438 REG_INIT(AB8505_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f),
1442 REG_INIT(AB8505_VSMPSASEL1, 0x04, 0x13, 0x3f),
1446 REG_INIT(AB8505_VSMPSASEL2, 0x04, 0x14, 0x3f),
1450 REG_INIT(AB8505_VSMPSASEL3, 0x04, 0x15, 0x3f),
1454 REG_INIT(AB8505_VSMPSBSEL1, 0x04, 0x17, 0x3f),
1458 REG_INIT(AB8505_VSMPSBSEL2, 0x04, 0x18, 0x3f),
1462 REG_INIT(AB8505_VSMPSBSEL3, 0x04, 0x19, 0x3f),
1466 REG_INIT(AB8505_VSAFESEL1, 0x04, 0x1b, 0x7f),
1470 REG_INIT(AB8505_VSAFESEL2, 0x04, 0x1c, 0x7f),
1474 REG_INIT(AB8505_VSAFESEL3, 0x04, 0x1d, 0x7f),
1478 REG_INIT(AB8505_VAUX1SEL, 0x04, 0x1f, 0x0f),
1482 REG_INIT(AB8505_VAUX2SEL, 0x04, 0x20, 0x0f),
1487 REG_INIT(AB8505_VRF1VAUX3SEL, 0x04, 0x21, 0x37),
1489 * 0x03, Vaux4RequestCtrl
1491 REG_INIT(AB8505_VAUX4REQCTRL, 0x04, 0x2d, 0x03),
1495 REG_INIT(AB8505_VAUX4REGU, 0x04, 0x2e, 0x03),
1499 REG_INIT(AB8505_VAUX4SEL, 0x04, 0x2f, 0x0f),
1504 * 0x20, Vintcore12Disch
1508 REG_INIT(AB8505_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
1511 * 0x04, VdmicPullDownEna
1514 REG_INIT(AB8505_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
1518 REG_INIT(AB8505_REGUCTRLDISCH3, 0x04, 0x48, 0x01),
1524 * 0x40, Vaux5DisSfst
1525 * 0x80, Vaux5DisPulld
1527 REG_INIT(AB8505_CTRLVAUX5, 0x01, 0x55, 0xff),
1532 * 0x80, Vaux6DisPulld
1534 REG_INIT(AB8505_CTRLVAUX6, 0x01, 0x56, 0x9f),
1537 static struct of_regulator_match ab8500_regulator_match[] = {
1538 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
1539 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
1540 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
1541 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
1542 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
1543 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
1544 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
1545 { .name = "ab8500_ldo_anamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
1546 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
1547 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
1550 static struct of_regulator_match ab8505_regulator_match[] = {
1551 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8505_LDO_AUX1, },
1552 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8505_LDO_AUX2, },
1553 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8505_LDO_AUX3, },
1554 { .name = "ab8500_ldo_aux4", .driver_data = (void *) AB8505_LDO_AUX4, },
1555 { .name = "ab8500_ldo_aux5", .driver_data = (void *) AB8505_LDO_AUX5, },
1556 { .name = "ab8500_ldo_aux6", .driver_data = (void *) AB8505_LDO_AUX6, },
1557 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8505_LDO_INTCORE, },
1558 { .name = "ab8500_ldo_adc", .driver_data = (void *) AB8505_LDO_ADC, },
1559 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8505_LDO_AUDIO, },
1560 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8505_LDO_ANAMIC1, },
1561 { .name = "ab8500_ldo_anamic2", .driver_data = (void *) AB8505_LDO_ANAMIC2, },
1562 { .name = "ab8500_ldo_aux8", .driver_data = (void *) AB8505_LDO_AUX8, },
1563 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8505_LDO_ANA, },
1567 struct ab8500_regulator_info *info;
1569 struct ab8500_reg_init *init;
1571 struct of_regulator_match *match;
1575 static void abx500_get_regulator_info(struct ab8500 *ab8500)
1577 if (is_ab8505(ab8500)) {
1578 abx500_regulator.info = ab8505_regulator_info;
1579 abx500_regulator.info_size = ARRAY_SIZE(ab8505_regulator_info);
1580 abx500_regulator.init = ab8505_reg_init;
1581 abx500_regulator.init_size = AB8505_NUM_REGULATOR_REGISTERS;
1582 abx500_regulator.match = ab8505_regulator_match;
1583 abx500_regulator.match_size = ARRAY_SIZE(ab8505_regulator_match);
1585 abx500_regulator.info = ab8500_regulator_info;
1586 abx500_regulator.info_size = ARRAY_SIZE(ab8500_regulator_info);
1587 abx500_regulator.init = ab8500_reg_init;
1588 abx500_regulator.init_size = AB8500_NUM_REGULATOR_REGISTERS;
1589 abx500_regulator.match = ab8500_regulator_match;
1590 abx500_regulator.match_size = ARRAY_SIZE(ab8500_regulator_match);
1594 static int ab8500_regulator_register(struct platform_device *pdev,
1595 struct regulator_init_data *init_data,
1596 int id, struct device_node *np)
1598 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1599 struct ab8500_regulator_info *info = NULL;
1600 struct regulator_config config = { };
1601 struct regulator_dev *rdev;
1603 /* assign per-regulator data */
1604 info = &abx500_regulator.info[id];
1605 info->dev = &pdev->dev;
1607 config.dev = &pdev->dev;
1608 config.init_data = init_data;
1609 config.driver_data = info;
1610 config.of_node = np;
1612 /* fix for hardware before ab8500v2.0 */
1613 if (is_ab8500_1p1_or_earlier(ab8500)) {
1614 if (info->desc.id == AB8500_LDO_AUX3) {
1615 info->desc.n_voltages =
1616 ARRAY_SIZE(ldo_vauxn_voltages);
1617 info->desc.volt_table = ldo_vauxn_voltages;
1618 info->voltage_mask = 0xf;
1622 /* register regulator with framework */
1623 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
1625 dev_err(&pdev->dev, "failed to register regulator %s\n",
1627 return PTR_ERR(rdev);
1633 static int ab8500_regulator_probe(struct platform_device *pdev)
1635 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
1636 struct device_node *np = pdev->dev.of_node;
1637 struct of_regulator_match *match;
1641 dev_err(&pdev->dev, "null mfd parent\n");
1645 abx500_get_regulator_info(ab8500);
1647 err = of_regulator_match(&pdev->dev, np,
1648 abx500_regulator.match,
1649 abx500_regulator.match_size);
1652 "Error parsing regulator init data: %d\n", err);
1656 match = abx500_regulator.match;
1657 for (i = 0; i < abx500_regulator.info_size; i++) {
1658 err = ab8500_regulator_register(pdev, match[i].init_data, i,
1667 static struct platform_driver ab8500_regulator_driver = {
1668 .probe = ab8500_regulator_probe,
1670 .name = "ab8500-regulator",
1674 static int __init ab8500_regulator_init(void)
1678 ret = platform_driver_register(&ab8500_regulator_driver);
1680 pr_err("Failed to register ab8500 regulator: %d\n", ret);
1684 subsys_initcall(ab8500_regulator_init);
1686 static void __exit ab8500_regulator_exit(void)
1688 platform_driver_unregister(&ab8500_regulator_driver);
1690 module_exit(ab8500_regulator_exit);
1692 MODULE_LICENSE("GPL v2");
1696 MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
1697 MODULE_ALIAS("platform:ab8500-regulator");