12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/slab.h>
84 #define VREG_DEDICATED 3
85 #define VREG_VOLTAGE_SMPS_4030 9
89 #define VREG_VOLTAGE 3
90 #define VREG_VOLTAGE_SMPS 4
94 #define VREG_BC_PROC 3
95 #define VREG_BC_CLK_RST 4
98 #define TWL6030_CFG_STATE_OFF 0x00
99 #define TWL6030_CFG_STATE_ON 0x01
100 #define TWL6030_CFG_STATE_OFF2 0x02
101 #define TWL6030_CFG_STATE_SLEEP 0x03
102 #define TWL6030_CFG_STATE_GRP_SHIFT 5
103 #define TWL6030_CFG_STATE_APP_SHIFT 2
104 #define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
105 #define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
106 TWL6030_CFG_STATE_APP_SHIFT)
109 #define SMPS_OFFSET_EN BIT(0)
110 #define SMPS_EXTENDED_EN BIT(1)
113 #define TWL6030_SMPS_OFFSET 0xB0
114 #define TWL6030_SMPS_MULT 0xB3
115 #define SMPS_MULTOFFSET_SMPS4 BIT(0)
116 #define SMPS_MULTOFFSET_VIO BIT(1)
117 #define SMPS_MULTOFFSET_SMPS3 BIT(6)
126 &value, info->
base + offset);
127 return (status < 0) ? status :
value;
135 value, info->
base + offset);
153 #define P3_GRP_4030 BIT(7)
154 #define P2_GRP_4030 BIT(6)
155 #define P1_GRP_4030 BIT(5)
157 #define P3_GRP_6030 BIT(2)
158 #define P2_GRP_6030 BIT(1)
159 #define P1_GRP_6030 BIT(0)
163 int state = twlreg_grp(rdev);
177 grp = twlreg_grp(rdev);
197 grp = twlreg_grp(rdev);
215 grp = twlreg_grp(rdev);
231 grp = twlreg_grp(rdev);
261 int state = twlreg_grp(rdev);
270 return (state &
BIT(3))
280 val = twlreg_grp(rdev);
321 status = twlreg_grp(rdev);
336 static int twl6030reg_set_mode(
struct regulator_dev *rdev,
unsigned mode)
343 grp = twlreg_grp(rdev);
383 #define UNSUP_MASK 0x8000
385 #define UNSUP(x) (UNSUP_MASK | (x))
386 #define IS_UNSUP(info, x) \
387 ((UNSUP_MASK & (x)) && \
388 !((info)->features & TWL4030_ALLOW_UNSUPPORTED))
389 #define LDO_MV(x) (~UNSUP_MASK & (x))
392 static const u16 VAUX1_VSEL_table[] = {
394 3000, 3000, 3000, 3000,
396 static const u16 VAUX2_4030_VSEL_table[] = {
398 1500, 1800,
UNSUP(1850), 2500,
402 static const u16 VAUX2_VSEL_table[] = {
403 1700, 1700, 1900, 1300,
404 1500, 1800, 2000, 2500,
405 2100, 2800, 2200, 2300,
406 2400, 2400, 2400, 2400,
408 static const u16 VAUX3_VSEL_table[] = {
409 1500, 1800, 2500, 2800,
410 3000, 3000, 3000, 3000,
412 static const u16 VAUX4_VSEL_table[] = {
413 700, 1000, 1200,
UNSUP(1300),
414 1500, 1800,
UNSUP(1850), 2500,
418 static const u16 VMMC1_VSEL_table[] = {
419 1850, 2850, 3000, 3150,
421 static const u16 VMMC2_VSEL_table[] = {
424 2600, 2800, 2850, 3000,
425 3150, 3150, 3150, 3150,
427 static const u16 VPLL1_VSEL_table[] = {
428 1000, 1200, 1300, 1800,
431 static const u16 VPLL2_VSEL_table[] = {
432 700, 1000, 1200, 1300,
437 static const u16 VSIM_VSEL_table[] = {
439 2800, 3000, 3000, 3000,
441 static const u16 VDAC_VSEL_table[] = {
442 1200, 1300, 1800, 1800,
444 static const u16 VDD1_VSEL_table[] = {
447 static const u16 VDD2_VSEL_table[] = {
450 static const u16 VIO_VSEL_table[] = {
453 static const u16 VINTANA2_VSEL_table[] = {
474 static int twl4030ldo_get_voltage(
struct regulator_dev *rdev)
488 .list_voltage = twl4030ldo_list_voltage,
490 .set_voltage_sel = twl4030ldo_set_voltage_sel,
491 .get_voltage = twl4030ldo_get_voltage,
493 .enable = twl4030reg_enable,
494 .disable = twl4030reg_disable,
495 .is_enabled = twl4030reg_is_enabled,
497 .set_mode = twl4030reg_set_mode,
499 .get_status = twl4030reg_get_status,
503 twl4030smps_set_voltage(
struct regulator_dev *rdev,
int min_uV,
int max_uV,
519 static int twl4030smps_get_voltage(
struct regulator_dev *rdev)
530 return vsel * 12500 + 600000;
534 .set_voltage = twl4030smps_set_voltage,
535 .get_voltage = twl4030smps_get_voltage,
538 static int twl6030coresmps_set_voltage(
struct regulator_dev *rdev,
int min_uV,
539 int max_uV,
unsigned *selector)
549 static int twl6030coresmps_get_voltage(
struct regulator_dev *rdev)
560 .set_voltage = twl6030coresmps_set_voltage,
561 .get_voltage = twl6030coresmps_get_voltage,
564 static int twl6030ldo_list_voltage(
struct regulator_dev *rdev,
unsigned sel)
575 return (info->
min_mV + 100 * (sel - 1)) * 1000;
586 twl6030ldo_set_voltage_sel(
struct regulator_dev *rdev,
unsigned selector)
594 static int twl6030ldo_get_voltage_sel(
struct regulator_dev *rdev)
603 .list_voltage = twl6030ldo_list_voltage,
605 .set_voltage_sel = twl6030ldo_set_voltage_sel,
606 .get_voltage_sel = twl6030ldo_get_voltage_sel,
608 .enable = twl6030reg_enable,
609 .disable = twl6030reg_disable,
610 .is_enabled = twl6030reg_is_enabled,
612 .set_mode = twl6030reg_set_mode,
614 .get_status = twl6030reg_get_status,
626 return info->
min_mV * 1000;
630 .list_voltage = twlfixed_list_voltage,
632 .enable = twl4030reg_enable,
633 .disable = twl4030reg_disable,
634 .is_enabled = twl4030reg_is_enabled,
636 .set_mode = twl4030reg_set_mode,
638 .get_status = twl4030reg_get_status,
642 .list_voltage = twlfixed_list_voltage,
644 .enable = twl6030reg_enable,
645 .disable = twl6030reg_disable,
646 .is_enabled = twl6030reg_is_enabled,
648 .set_mode = twl6030reg_set_mode,
650 .get_status = twl6030reg_get_status,
663 switch (info->
flags) {
673 voltage = 1350 * 1000;
676 voltage = 1500 * 1000;
679 voltage = 1800 * 1000;
682 voltage = 1900 * 1000;
685 voltage = 2100 * 1000;
688 voltage += (600000 + (12500 * (index - 1)));
697 voltage = 2084 * 1000;
700 voltage = 2315 * 1000;
703 voltage = 2778 * 1000;
706 voltage = 2932 * 1000;
709 voltage = 3241 * 1000;
712 voltage = (1852000 + (38600 * (index - 1)));
721 voltage = 4167 * 1000;
724 voltage = 2315 * 1000;
727 voltage = 2778 * 1000;
730 voltage = 2932 * 1000;
733 voltage = 3241 * 1000;
736 voltage = (2161000 + (38600 * (index - 1)));
744 static int twl6030smps_map_voltage(
struct regulator_dev *rdev,
int min_uV,
750 switch (info->
flags) {
754 else if ((min_uV >= 600000) && (min_uV <= 1300000)) {
761 else if ((min_uV > 1900000) && (min_uV <= 2100000))
763 else if ((min_uV > 1800000) && (min_uV <= 1900000))
765 else if ((min_uV > 1500000) && (min_uV <= 1800000))
767 else if ((min_uV > 1350000) && (min_uV <= 1500000))
769 else if ((min_uV > 1300000) && (min_uV <= 1350000))
777 else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
784 else if ((min_uV > 1900000) && (min_uV <= 2100000))
786 else if ((min_uV > 1800000) && (min_uV <= 1900000))
788 else if ((min_uV > 1350000) && (min_uV <= 1800000))
790 else if ((min_uV > 1350000) && (min_uV <= 1500000))
792 else if ((min_uV > 1300000) && (min_uV <= 1350000))
800 }
else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
808 }
else if ((min_uV >= 2161000) && (min_uV <= 4321000)) {
818 static int twl6030smps_set_voltage_sel(
struct regulator_dev *rdev,
819 unsigned int selector)
827 static int twl6030smps_get_voltage_sel(
struct regulator_dev *rdev)
835 .list_voltage = twl6030smps_list_voltage,
836 .map_voltage = twl6030smps_map_voltage,
838 .set_voltage_sel = twl6030smps_set_voltage_sel,
839 .get_voltage_sel = twl6030smps_get_voltage_sel,
841 .enable = twl6030reg_enable,
842 .disable = twl6030reg_disable,
843 .is_enabled = twl6030reg_is_enabled,
845 .set_mode = twl6030reg_set_mode,
847 .get_status = twl6030reg_get_status,
852 #define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
854 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
855 remap_conf, TWL4030, twl4030fixed_ops)
856 #define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
857 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
858 0x0, TWL6030, twl6030fixed_ops)
860 #define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
861 static const struct twlreg_info TWL4030_INFO_##label = { \
864 .table_len = ARRAY_SIZE(label##_VSEL_table), \
865 .table = label##_VSEL_table, \
866 .remap = remap_conf, \
869 .id = TWL4030_REG_##label, \
870 .n_voltages = ARRAY_SIZE(label##_VSEL_table), \
871 .ops = &twl4030ldo_ops, \
872 .type = REGULATOR_VOLTAGE, \
873 .owner = THIS_MODULE, \
874 .enable_time = turnon_delay, \
878 #define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
879 static const struct twlreg_info TWL4030_INFO_##label = { \
882 .remap = remap_conf, \
885 .id = TWL4030_REG_##label, \
886 .ops = &twl4030smps_ops, \
887 .type = REGULATOR_VOLTAGE, \
888 .owner = THIS_MODULE, \
889 .enable_time = turnon_delay, \
893 #define TWL6030_ADJUSTABLE_SMPS(label) \
894 static const struct twlreg_info TWL6030_INFO_##label = { \
897 .id = TWL6030_REG_##label, \
898 .ops = &twl6030coresmps_ops, \
899 .type = REGULATOR_VOLTAGE, \
900 .owner = THIS_MODULE, \
904 #define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
905 static const struct twlreg_info TWL6030_INFO_##label = { \
907 .min_mV = min_mVolts, \
908 .max_mV = max_mVolts, \
911 .id = TWL6030_REG_##label, \
913 .ops = &twl6030ldo_ops, \
914 .type = REGULATOR_VOLTAGE, \
915 .owner = THIS_MODULE, \
919 #define TWL6025_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) \
920 static const struct twlreg_info TWL6025_INFO_##label = { \
922 .min_mV = min_mVolts, \
923 .max_mV = max_mVolts, \
926 .id = TWL6025_REG_##label, \
928 .ops = &twl6030ldo_ops, \
929 .type = REGULATOR_VOLTAGE, \
930 .owner = THIS_MODULE, \
934 #define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
935 family, operations) \
936 static const struct twlreg_info TWLFIXED_INFO_##label = { \
940 .remap = remap_conf, \
943 .id = family##_REG_##label, \
945 .ops = &operations, \
946 .type = REGULATOR_VOLTAGE, \
947 .owner = THIS_MODULE, \
948 .enable_time = turnon_delay, \
952 #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
953 static struct twlreg_info TWLRES_INFO_##label = { \
957 .id = TWL6030_REG_##label, \
958 .ops = &twl6030_fixed_resource, \
959 .type = REGULATOR_VOLTAGE, \
960 .owner = THIS_MODULE, \
961 .enable_time = turnon_delay, \
965 #define TWL6025_ADJUSTABLE_SMPS(label, offset) \
966 static const struct twlreg_info TWLSMPS_INFO_##label = { \
972 .id = TWL6025_REG_##label, \
974 .ops = &twlsmps_ops, \
975 .type = REGULATOR_VOLTAGE, \
976 .owner = THIS_MODULE, \
1037 static u8 twl_get_smps_offset(
void)
1046 static u8 twl_get_smps_mult(
void)
1055 #define TWL_OF_MATCH(comp, family, label) \
1057 .compatible = comp, \
1058 .data = &family##_INFO_##label, \
1061 #define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label)
1062 #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label)
1063 #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label)
1064 #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label)
1065 #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label)
1133 template = match->
data;
1134 id =
template->desc.id;
1140 initdata = pdev->
dev.platform_data;
1141 for (i = 0,
template =
NULL; i <
ARRAY_SIZE(twl_of_match); i++) {
1142 template = twl_of_match[
i].data;
1143 if (
template &&
template->desc.id ==
id)
1222 dev_err(&pdev->
dev,
"can't register %s, %ld\n",
1223 info->
desc.name, PTR_ERR(rdev));
1225 return PTR_ERR(rdev);
1227 platform_set_drvdata(pdev, rdev);
1229 if (twl_class_is_4030())
1257 .probe = twlreg_probe,
1269 static int __init twlreg_init(
void)
1275 static void __exit twlreg_exit(
void)