diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-22 14:32:00 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-22 14:32:00 -0400 |
commit | 3384fb98845dc014770caa224d61a2effd258ca5 (patch) | |
tree | 8189134a4938632e2d06e93af04c9fc1f3c2d4c9 /drivers/regulator | |
parent | 8cfc545e0e3e6cc82acfdc79321b41eeeab0ca45 (diff) | |
parent | ade7515fefad9af13f6dd469f35bb413b6a5b473 (diff) |
Merge branch 'regulator-drivers' into regulator-next
Diffstat (limited to 'drivers/regulator')
50 files changed, 4930 insertions, 2505 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index c86b8864e411..f34c3be6c9fe 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -20,6 +20,7 @@ menuconfig REGULATOR | |||
20 | 20 | ||
21 | If unsure, say no. | 21 | If unsure, say no. |
22 | 22 | ||
23 | |||
23 | if REGULATOR | 24 | if REGULATOR |
24 | 25 | ||
25 | config REGULATOR_DEBUG | 26 | config REGULATOR_DEBUG |
@@ -88,6 +89,13 @@ config REGULATOR_AAT2870 | |||
88 | If you have a AnalogicTech AAT2870 say Y to enable the | 89 | If you have a AnalogicTech AAT2870 say Y to enable the |
89 | regulator driver. | 90 | regulator driver. |
90 | 91 | ||
92 | config REGULATOR_ARIZONA | ||
93 | tristate "Wolfson Arizona class devices" | ||
94 | depends on MFD_ARIZONA | ||
95 | help | ||
96 | Support for the regulators found on Wolfson Arizona class | ||
97 | devices. | ||
98 | |||
91 | config REGULATOR_DA903X | 99 | config REGULATOR_DA903X |
92 | tristate "Dialog Semiconductor DA9030/DA9034 regulators" | 100 | tristate "Dialog Semiconductor DA9030/DA9034 regulators" |
93 | depends on PMIC_DA903X | 101 | depends on PMIC_DA903X |
@@ -195,6 +203,14 @@ config REGULATOR_MAX8998 | |||
195 | via I2C bus. The provided regulator is suitable for S3C6410 | 203 | via I2C bus. The provided regulator is suitable for S3C6410 |
196 | and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. | 204 | and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. |
197 | 205 | ||
206 | config REGULATOR_MAX77686 | ||
207 | tristate "Maxim 77686 regulator" | ||
208 | depends on MFD_MAX77686 | ||
209 | help | ||
210 | This driver controls a Maxim 77686 regulator | ||
211 | via I2C bus. The provided regulator is suitable for | ||
212 | Exynos-4 chips to control VARM and VINT voltages. | ||
213 | |||
198 | config REGULATOR_PCAP | 214 | config REGULATOR_PCAP |
199 | tristate "Motorola PCAP2 regulator driver" | 215 | tristate "Motorola PCAP2 regulator driver" |
200 | depends on EZX_PCAP | 216 | depends on EZX_PCAP |
@@ -216,6 +232,19 @@ config REGULATOR_LP3972 | |||
216 | Say Y here to support the voltage regulators and convertors | 232 | Say Y here to support the voltage regulators and convertors |
217 | on National Semiconductors LP3972 PMIC | 233 | on National Semiconductors LP3972 PMIC |
218 | 234 | ||
235 | config REGULATOR_LP872X | ||
236 | bool "TI/National Semiconductor LP8720/LP8725 voltage regulators" | ||
237 | depends on I2C=y | ||
238 | select REGMAP_I2C | ||
239 | help | ||
240 | This driver supports LP8720/LP8725 PMIC | ||
241 | |||
242 | config REGULATOR_LP8788 | ||
243 | bool "TI LP8788 Power Regulators" | ||
244 | depends on MFD_LP8788 | ||
245 | help | ||
246 | This driver supports LP8788 voltage regulator chip. | ||
247 | |||
219 | config REGULATOR_PCF50633 | 248 | config REGULATOR_PCF50633 |
220 | tristate "NXP PCF50633 regulator driver" | 249 | tristate "NXP PCF50633 regulator driver" |
221 | depends on MFD_PCF50633 | 250 | depends on MFD_PCF50633 |
@@ -233,6 +262,14 @@ config REGULATOR_RC5T583 | |||
233 | through regulator interface. The device supports multiple DCDC/LDO | 262 | through regulator interface. The device supports multiple DCDC/LDO |
234 | outputs which can be controlled by i2c communication. | 263 | outputs which can be controlled by i2c communication. |
235 | 264 | ||
265 | config REGULATOR_S2MPS11 | ||
266 | tristate "Samsung S2MPS11 voltage regulator" | ||
267 | depends on MFD_SEC_CORE | ||
268 | help | ||
269 | This driver supports a Samsung S2MPS11 voltage output regulator | ||
270 | via I2C bus. S2MPS11 is comprised of high efficient Buck converters | ||
271 | including Dual-Phase Buck converter, Buck-Boost converter, various LDOs. | ||
272 | |||
236 | config REGULATOR_S5M8767 | 273 | config REGULATOR_S5M8767 |
237 | tristate "Samsung S5M8767A voltage regulator" | 274 | tristate "Samsung S5M8767A voltage regulator" |
238 | depends on MFD_S5M_CORE | 275 | depends on MFD_S5M_CORE |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 977fd46909ab..3342615cf25e 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -15,6 +15,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o | |||
15 | obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o | 15 | obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o |
16 | obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o | 16 | obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o |
17 | obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o | 17 | obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o |
18 | obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o | ||
18 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o | 19 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o |
19 | obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o | 20 | obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o |
20 | obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o | 21 | obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o |
@@ -23,6 +24,9 @@ obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o | |||
23 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o | 24 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o |
24 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o | 25 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o |
25 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o | 26 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o |
27 | obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o | ||
28 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o | ||
29 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o | ||
26 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o | 30 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o |
27 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o | 31 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o |
28 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o | 32 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o |
@@ -30,6 +34,7 @@ obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o | |||
30 | obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o | 34 | obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o |
31 | obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o | 35 | obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o |
32 | obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o | 36 | obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o |
37 | obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o | ||
33 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | 38 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o |
34 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 39 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
35 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 40 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
@@ -37,6 +42,7 @@ obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o | |||
37 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o | 42 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o |
38 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o | 43 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o |
39 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o | 44 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o |
45 | obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o | ||
40 | obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o | 46 | obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o |
41 | obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o | 47 | obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o |
42 | obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o | 48 | obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o |
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c index 06776ca945f2..6f45bfd22e83 100644 --- a/drivers/regulator/aat2870-regulator.c +++ b/drivers/regulator/aat2870-regulator.c | |||
@@ -33,11 +33,6 @@ struct aat2870_regulator { | |||
33 | struct aat2870_data *aat2870; | 33 | struct aat2870_data *aat2870; |
34 | struct regulator_desc desc; | 34 | struct regulator_desc desc; |
35 | 35 | ||
36 | const int *voltages; /* uV */ | ||
37 | |||
38 | int min_uV; | ||
39 | int max_uV; | ||
40 | |||
41 | u8 enable_addr; | 36 | u8 enable_addr; |
42 | u8 enable_shift; | 37 | u8 enable_shift; |
43 | u8 enable_mask; | 38 | u8 enable_mask; |
@@ -47,14 +42,6 @@ struct aat2870_regulator { | |||
47 | u8 voltage_mask; | 42 | u8 voltage_mask; |
48 | }; | 43 | }; |
49 | 44 | ||
50 | static int aat2870_ldo_list_voltage(struct regulator_dev *rdev, | ||
51 | unsigned selector) | ||
52 | { | ||
53 | struct aat2870_regulator *ri = rdev_get_drvdata(rdev); | ||
54 | |||
55 | return ri->voltages[selector]; | ||
56 | } | ||
57 | |||
58 | static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev, | 45 | static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev, |
59 | unsigned selector) | 46 | unsigned selector) |
60 | { | 47 | { |
@@ -111,7 +98,7 @@ static int aat2870_ldo_is_enabled(struct regulator_dev *rdev) | |||
111 | } | 98 | } |
112 | 99 | ||
113 | static struct regulator_ops aat2870_ldo_ops = { | 100 | static struct regulator_ops aat2870_ldo_ops = { |
114 | .list_voltage = aat2870_ldo_list_voltage, | 101 | .list_voltage = regulator_list_voltage_table, |
115 | .set_voltage_sel = aat2870_ldo_set_voltage_sel, | 102 | .set_voltage_sel = aat2870_ldo_set_voltage_sel, |
116 | .get_voltage_sel = aat2870_ldo_get_voltage_sel, | 103 | .get_voltage_sel = aat2870_ldo_get_voltage_sel, |
117 | .enable = aat2870_ldo_enable, | 104 | .enable = aat2870_ldo_enable, |
@@ -119,7 +106,7 @@ static struct regulator_ops aat2870_ldo_ops = { | |||
119 | .is_enabled = aat2870_ldo_is_enabled, | 106 | .is_enabled = aat2870_ldo_is_enabled, |
120 | }; | 107 | }; |
121 | 108 | ||
122 | static const int aat2870_ldo_voltages[] = { | 109 | static const unsigned int aat2870_ldo_voltages[] = { |
123 | 1200000, 1300000, 1500000, 1600000, | 110 | 1200000, 1300000, 1500000, 1600000, |
124 | 1800000, 2000000, 2200000, 2500000, | 111 | 1800000, 2000000, 2200000, 2500000, |
125 | 2600000, 2700000, 2800000, 2900000, | 112 | 2600000, 2700000, 2800000, 2900000, |
@@ -132,13 +119,11 @@ static const int aat2870_ldo_voltages[] = { | |||
132 | .name = #ids, \ | 119 | .name = #ids, \ |
133 | .id = AAT2870_ID_##ids, \ | 120 | .id = AAT2870_ID_##ids, \ |
134 | .n_voltages = ARRAY_SIZE(aat2870_ldo_voltages), \ | 121 | .n_voltages = ARRAY_SIZE(aat2870_ldo_voltages), \ |
122 | .volt_table = aat2870_ldo_voltages, \ | ||
135 | .ops = &aat2870_ldo_ops, \ | 123 | .ops = &aat2870_ldo_ops, \ |
136 | .type = REGULATOR_VOLTAGE, \ | 124 | .type = REGULATOR_VOLTAGE, \ |
137 | .owner = THIS_MODULE, \ | 125 | .owner = THIS_MODULE, \ |
138 | }, \ | 126 | }, \ |
139 | .voltages = aat2870_ldo_voltages, \ | ||
140 | .min_uV = 1200000, \ | ||
141 | .max_uV = 3300000, \ | ||
142 | } | 127 | } |
143 | 128 | ||
144 | static struct aat2870_regulator aat2870_regulators[] = { | 129 | static struct aat2870_regulator aat2870_regulators[] = { |
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index 03f4d9c604ec..182b553059c9 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c | |||
@@ -43,20 +43,12 @@ | |||
43 | * @dev: handle to the device | 43 | * @dev: handle to the device |
44 | * @plfdata: AB3100 platform data passed in at probe time | 44 | * @plfdata: AB3100 platform data passed in at probe time |
45 | * @regreg: regulator register number in the AB3100 | 45 | * @regreg: regulator register number in the AB3100 |
46 | * @fixed_voltage: a fixed voltage for this regulator, if this | ||
47 | * 0 the voltages array is used instead. | ||
48 | * @typ_voltages: an array of available typical voltages for | ||
49 | * this regulator | ||
50 | * @voltages_len: length of the array of available voltages | ||
51 | */ | 46 | */ |
52 | struct ab3100_regulator { | 47 | struct ab3100_regulator { |
53 | struct regulator_dev *rdev; | 48 | struct regulator_dev *rdev; |
54 | struct device *dev; | 49 | struct device *dev; |
55 | struct ab3100_platform_data *plfdata; | 50 | struct ab3100_platform_data *plfdata; |
56 | u8 regreg; | 51 | u8 regreg; |
57 | int fixed_voltage; | ||
58 | int const *typ_voltages; | ||
59 | u8 voltages_len; | ||
60 | }; | 52 | }; |
61 | 53 | ||
62 | /* The order in which registers are initialized */ | 54 | /* The order in which registers are initialized */ |
@@ -80,7 +72,7 @@ static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = { | |||
80 | #define LDO_C_VOLTAGE 2650000 | 72 | #define LDO_C_VOLTAGE 2650000 |
81 | #define LDO_D_VOLTAGE 2650000 | 73 | #define LDO_D_VOLTAGE 2650000 |
82 | 74 | ||
83 | static const int ldo_e_buck_typ_voltages[] = { | 75 | static const unsigned int ldo_e_buck_typ_voltages[] = { |
84 | 1800000, | 76 | 1800000, |
85 | 1400000, | 77 | 1400000, |
86 | 1300000, | 78 | 1300000, |
@@ -90,7 +82,7 @@ static const int ldo_e_buck_typ_voltages[] = { | |||
90 | 900000, | 82 | 900000, |
91 | }; | 83 | }; |
92 | 84 | ||
93 | static const int ldo_f_typ_voltages[] = { | 85 | static const unsigned int ldo_f_typ_voltages[] = { |
94 | 1800000, | 86 | 1800000, |
95 | 1400000, | 87 | 1400000, |
96 | 1300000, | 88 | 1300000, |
@@ -101,21 +93,21 @@ static const int ldo_f_typ_voltages[] = { | |||
101 | 2650000, | 93 | 2650000, |
102 | }; | 94 | }; |
103 | 95 | ||
104 | static const int ldo_g_typ_voltages[] = { | 96 | static const unsigned int ldo_g_typ_voltages[] = { |
105 | 2850000, | 97 | 2850000, |
106 | 2750000, | 98 | 2750000, |
107 | 1800000, | 99 | 1800000, |
108 | 1500000, | 100 | 1500000, |
109 | }; | 101 | }; |
110 | 102 | ||
111 | static const int ldo_h_typ_voltages[] = { | 103 | static const unsigned int ldo_h_typ_voltages[] = { |
112 | 2750000, | 104 | 2750000, |
113 | 1800000, | 105 | 1800000, |
114 | 1500000, | 106 | 1500000, |
115 | 1200000, | 107 | 1200000, |
116 | }; | 108 | }; |
117 | 109 | ||
118 | static const int ldo_k_typ_voltages[] = { | 110 | static const unsigned int ldo_k_typ_voltages[] = { |
119 | 2750000, | 111 | 2750000, |
120 | 1800000, | 112 | 1800000, |
121 | }; | 113 | }; |
@@ -126,40 +118,27 @@ static struct ab3100_regulator | |||
126 | ab3100_regulators[AB3100_NUM_REGULATORS] = { | 118 | ab3100_regulators[AB3100_NUM_REGULATORS] = { |
127 | { | 119 | { |
128 | .regreg = AB3100_LDO_A, | 120 | .regreg = AB3100_LDO_A, |
129 | .fixed_voltage = LDO_A_VOLTAGE, | ||
130 | }, | 121 | }, |
131 | { | 122 | { |
132 | .regreg = AB3100_LDO_C, | 123 | .regreg = AB3100_LDO_C, |
133 | .fixed_voltage = LDO_C_VOLTAGE, | ||
134 | }, | 124 | }, |
135 | { | 125 | { |
136 | .regreg = AB3100_LDO_D, | 126 | .regreg = AB3100_LDO_D, |
137 | .fixed_voltage = LDO_D_VOLTAGE, | ||
138 | }, | 127 | }, |
139 | { | 128 | { |
140 | .regreg = AB3100_LDO_E, | 129 | .regreg = AB3100_LDO_E, |
141 | .typ_voltages = ldo_e_buck_typ_voltages, | ||
142 | .voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages), | ||
143 | }, | 130 | }, |
144 | { | 131 | { |
145 | .regreg = AB3100_LDO_F, | 132 | .regreg = AB3100_LDO_F, |
146 | .typ_voltages = ldo_f_typ_voltages, | ||
147 | .voltages_len = ARRAY_SIZE(ldo_f_typ_voltages), | ||
148 | }, | 133 | }, |
149 | { | 134 | { |
150 | .regreg = AB3100_LDO_G, | 135 | .regreg = AB3100_LDO_G, |
151 | .typ_voltages = ldo_g_typ_voltages, | ||
152 | .voltages_len = ARRAY_SIZE(ldo_g_typ_voltages), | ||
153 | }, | 136 | }, |
154 | { | 137 | { |
155 | .regreg = AB3100_LDO_H, | 138 | .regreg = AB3100_LDO_H, |
156 | .typ_voltages = ldo_h_typ_voltages, | ||
157 | .voltages_len = ARRAY_SIZE(ldo_h_typ_voltages), | ||
158 | }, | 139 | }, |
159 | { | 140 | { |
160 | .regreg = AB3100_LDO_K, | 141 | .regreg = AB3100_LDO_K, |
161 | .typ_voltages = ldo_k_typ_voltages, | ||
162 | .voltages_len = ARRAY_SIZE(ldo_k_typ_voltages), | ||
163 | }, | 142 | }, |
164 | { | 143 | { |
165 | .regreg = AB3100_LDO_EXT, | 144 | .regreg = AB3100_LDO_EXT, |
@@ -167,8 +146,6 @@ ab3100_regulators[AB3100_NUM_REGULATORS] = { | |||
167 | }, | 146 | }, |
168 | { | 147 | { |
169 | .regreg = AB3100_BUCK, | 148 | .regreg = AB3100_BUCK, |
170 | .typ_voltages = ldo_e_buck_typ_voltages, | ||
171 | .voltages_len = ARRAY_SIZE(ldo_e_buck_typ_voltages), | ||
172 | }, | 149 | }, |
173 | }; | 150 | }; |
174 | 151 | ||
@@ -178,7 +155,7 @@ ab3100_regulators[AB3100_NUM_REGULATORS] = { | |||
178 | */ | 155 | */ |
179 | static int ab3100_enable_regulator(struct regulator_dev *reg) | 156 | static int ab3100_enable_regulator(struct regulator_dev *reg) |
180 | { | 157 | { |
181 | struct ab3100_regulator *abreg = reg->reg_data; | 158 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
182 | int err; | 159 | int err; |
183 | u8 regval; | 160 | u8 regval; |
184 | 161 | ||
@@ -209,7 +186,7 @@ static int ab3100_enable_regulator(struct regulator_dev *reg) | |||
209 | 186 | ||
210 | static int ab3100_disable_regulator(struct regulator_dev *reg) | 187 | static int ab3100_disable_regulator(struct regulator_dev *reg) |
211 | { | 188 | { |
212 | struct ab3100_regulator *abreg = reg->reg_data; | 189 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
213 | int err; | 190 | int err; |
214 | u8 regval; | 191 | u8 regval; |
215 | 192 | ||
@@ -242,7 +219,7 @@ static int ab3100_disable_regulator(struct regulator_dev *reg) | |||
242 | 219 | ||
243 | static int ab3100_is_enabled_regulator(struct regulator_dev *reg) | 220 | static int ab3100_is_enabled_regulator(struct regulator_dev *reg) |
244 | { | 221 | { |
245 | struct ab3100_regulator *abreg = reg->reg_data; | 222 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
246 | u8 regval; | 223 | u8 regval; |
247 | int err; | 224 | int err; |
248 | 225 | ||
@@ -257,26 +234,12 @@ static int ab3100_is_enabled_regulator(struct regulator_dev *reg) | |||
257 | return regval & AB3100_REG_ON_MASK; | 234 | return regval & AB3100_REG_ON_MASK; |
258 | } | 235 | } |
259 | 236 | ||
260 | static int ab3100_list_voltage_regulator(struct regulator_dev *reg, | ||
261 | unsigned selector) | ||
262 | { | ||
263 | struct ab3100_regulator *abreg = reg->reg_data; | ||
264 | |||
265 | if (selector >= abreg->voltages_len) | ||
266 | return -EINVAL; | ||
267 | return abreg->typ_voltages[selector]; | ||
268 | } | ||
269 | |||
270 | static int ab3100_get_voltage_regulator(struct regulator_dev *reg) | 237 | static int ab3100_get_voltage_regulator(struct regulator_dev *reg) |
271 | { | 238 | { |
272 | struct ab3100_regulator *abreg = reg->reg_data; | 239 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
273 | u8 regval; | 240 | u8 regval; |
274 | int err; | 241 | int err; |
275 | 242 | ||
276 | /* Return the voltage for fixed regulators immediately */ | ||
277 | if (abreg->fixed_voltage) | ||
278 | return abreg->fixed_voltage; | ||
279 | |||
280 | /* | 243 | /* |
281 | * For variable types, read out setting and index into | 244 | * For variable types, read out setting and index into |
282 | * supplied voltage list. | 245 | * supplied voltage list. |
@@ -294,20 +257,20 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg) | |||
294 | regval &= 0xE0; | 257 | regval &= 0xE0; |
295 | regval >>= 5; | 258 | regval >>= 5; |
296 | 259 | ||
297 | if (regval >= abreg->voltages_len) { | 260 | if (regval >= reg->desc->n_voltages) { |
298 | dev_err(®->dev, | 261 | dev_err(®->dev, |
299 | "regulator register %02x contains an illegal voltage setting\n", | 262 | "regulator register %02x contains an illegal voltage setting\n", |
300 | abreg->regreg); | 263 | abreg->regreg); |
301 | return -EINVAL; | 264 | return -EINVAL; |
302 | } | 265 | } |
303 | 266 | ||
304 | return abreg->typ_voltages[regval]; | 267 | return reg->desc->volt_table[regval]; |
305 | } | 268 | } |
306 | 269 | ||
307 | static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, | 270 | static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, |
308 | unsigned selector) | 271 | unsigned selector) |
309 | { | 272 | { |
310 | struct ab3100_regulator *abreg = reg->reg_data; | 273 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
311 | u8 regval; | 274 | u8 regval; |
312 | int err; | 275 | int err; |
313 | 276 | ||
@@ -336,7 +299,7 @@ static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, | |||
336 | static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, | 299 | static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, |
337 | int uV) | 300 | int uV) |
338 | { | 301 | { |
339 | struct ab3100_regulator *abreg = reg->reg_data; | 302 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
340 | u8 regval; | 303 | u8 regval; |
341 | int err; | 304 | int err; |
342 | int bestindex; | 305 | int bestindex; |
@@ -379,42 +342,22 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, | |||
379 | */ | 342 | */ |
380 | static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg) | 343 | static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg) |
381 | { | 344 | { |
382 | struct ab3100_regulator *abreg = reg->reg_data; | 345 | struct ab3100_regulator *abreg = rdev_get_drvdata(reg); |
383 | 346 | ||
384 | return abreg->plfdata->external_voltage; | 347 | return abreg->plfdata->external_voltage; |
385 | } | 348 | } |
386 | 349 | ||
387 | static int ab3100_enable_time_regulator(struct regulator_dev *reg) | 350 | static int ab3100_get_fixed_voltage_regulator(struct regulator_dev *reg) |
388 | { | 351 | { |
389 | struct ab3100_regulator *abreg = reg->reg_data; | 352 | return reg->desc->min_uV; |
390 | |||
391 | /* Per-regulator power on delay from spec */ | ||
392 | switch (abreg->regreg) { | ||
393 | case AB3100_LDO_A: /* Fallthrough */ | ||
394 | case AB3100_LDO_C: /* Fallthrough */ | ||
395 | case AB3100_LDO_D: /* Fallthrough */ | ||
396 | case AB3100_LDO_E: /* Fallthrough */ | ||
397 | case AB3100_LDO_H: /* Fallthrough */ | ||
398 | case AB3100_LDO_K: | ||
399 | return 200; | ||
400 | case AB3100_LDO_F: | ||
401 | return 600; | ||
402 | case AB3100_LDO_G: | ||
403 | return 400; | ||
404 | case AB3100_BUCK: | ||
405 | return 1000; | ||
406 | default: | ||
407 | break; | ||
408 | } | ||
409 | return 0; | ||
410 | } | 353 | } |
411 | 354 | ||
412 | static struct regulator_ops regulator_ops_fixed = { | 355 | static struct regulator_ops regulator_ops_fixed = { |
356 | .list_voltage = regulator_list_voltage_linear, | ||
413 | .enable = ab3100_enable_regulator, | 357 | .enable = ab3100_enable_regulator, |
414 | .disable = ab3100_disable_regulator, | 358 | .disable = ab3100_disable_regulator, |
415 | .is_enabled = ab3100_is_enabled_regulator, | 359 | .is_enabled = ab3100_is_enabled_regulator, |
416 | .get_voltage = ab3100_get_voltage_regulator, | 360 | .get_voltage = ab3100_get_fixed_voltage_regulator, |
417 | .enable_time = ab3100_enable_time_regulator, | ||
418 | }; | 361 | }; |
419 | 362 | ||
420 | static struct regulator_ops regulator_ops_variable = { | 363 | static struct regulator_ops regulator_ops_variable = { |
@@ -423,8 +366,7 @@ static struct regulator_ops regulator_ops_variable = { | |||
423 | .is_enabled = ab3100_is_enabled_regulator, | 366 | .is_enabled = ab3100_is_enabled_regulator, |
424 | .get_voltage = ab3100_get_voltage_regulator, | 367 | .get_voltage = ab3100_get_voltage_regulator, |
425 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, | 368 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, |
426 | .list_voltage = ab3100_list_voltage_regulator, | 369 | .list_voltage = regulator_list_voltage_table, |
427 | .enable_time = ab3100_enable_time_regulator, | ||
428 | }; | 370 | }; |
429 | 371 | ||
430 | static struct regulator_ops regulator_ops_variable_sleepable = { | 372 | static struct regulator_ops regulator_ops_variable_sleepable = { |
@@ -434,8 +376,7 @@ static struct regulator_ops regulator_ops_variable_sleepable = { | |||
434 | .get_voltage = ab3100_get_voltage_regulator, | 376 | .get_voltage = ab3100_get_voltage_regulator, |
435 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, | 377 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, |
436 | .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, | 378 | .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, |
437 | .list_voltage = ab3100_list_voltage_regulator, | 379 | .list_voltage = regulator_list_voltage_table, |
438 | .enable_time = ab3100_enable_time_regulator, | ||
439 | }; | 380 | }; |
440 | 381 | ||
441 | /* | 382 | /* |
@@ -457,62 +398,81 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { | |||
457 | .name = "LDO_A", | 398 | .name = "LDO_A", |
458 | .id = AB3100_LDO_A, | 399 | .id = AB3100_LDO_A, |
459 | .ops = ®ulator_ops_fixed, | 400 | .ops = ®ulator_ops_fixed, |
401 | .n_voltages = 1, | ||
460 | .type = REGULATOR_VOLTAGE, | 402 | .type = REGULATOR_VOLTAGE, |
461 | .owner = THIS_MODULE, | 403 | .owner = THIS_MODULE, |
404 | .min_uV = LDO_A_VOLTAGE, | ||
405 | .enable_time = 200, | ||
462 | }, | 406 | }, |
463 | { | 407 | { |
464 | .name = "LDO_C", | 408 | .name = "LDO_C", |
465 | .id = AB3100_LDO_C, | 409 | .id = AB3100_LDO_C, |
466 | .ops = ®ulator_ops_fixed, | 410 | .ops = ®ulator_ops_fixed, |
411 | .n_voltages = 1, | ||
467 | .type = REGULATOR_VOLTAGE, | 412 | .type = REGULATOR_VOLTAGE, |
468 | .owner = THIS_MODULE, | 413 | .owner = THIS_MODULE, |
414 | .min_uV = LDO_C_VOLTAGE, | ||
415 | .enable_time = 200, | ||
469 | }, | 416 | }, |
470 | { | 417 | { |
471 | .name = "LDO_D", | 418 | .name = "LDO_D", |
472 | .id = AB3100_LDO_D, | 419 | .id = AB3100_LDO_D, |
473 | .ops = ®ulator_ops_fixed, | 420 | .ops = ®ulator_ops_fixed, |
421 | .n_voltages = 1, | ||
474 | .type = REGULATOR_VOLTAGE, | 422 | .type = REGULATOR_VOLTAGE, |
475 | .owner = THIS_MODULE, | 423 | .owner = THIS_MODULE, |
424 | .min_uV = LDO_D_VOLTAGE, | ||
425 | .enable_time = 200, | ||
476 | }, | 426 | }, |
477 | { | 427 | { |
478 | .name = "LDO_E", | 428 | .name = "LDO_E", |
479 | .id = AB3100_LDO_E, | 429 | .id = AB3100_LDO_E, |
480 | .ops = ®ulator_ops_variable_sleepable, | 430 | .ops = ®ulator_ops_variable_sleepable, |
481 | .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), | 431 | .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), |
432 | .volt_table = ldo_e_buck_typ_voltages, | ||
482 | .type = REGULATOR_VOLTAGE, | 433 | .type = REGULATOR_VOLTAGE, |
483 | .owner = THIS_MODULE, | 434 | .owner = THIS_MODULE, |
435 | .enable_time = 200, | ||
484 | }, | 436 | }, |
485 | { | 437 | { |
486 | .name = "LDO_F", | 438 | .name = "LDO_F", |
487 | .id = AB3100_LDO_F, | 439 | .id = AB3100_LDO_F, |
488 | .ops = ®ulator_ops_variable, | 440 | .ops = ®ulator_ops_variable, |
489 | .n_voltages = ARRAY_SIZE(ldo_f_typ_voltages), | 441 | .n_voltages = ARRAY_SIZE(ldo_f_typ_voltages), |
442 | .volt_table = ldo_f_typ_voltages, | ||
490 | .type = REGULATOR_VOLTAGE, | 443 | .type = REGULATOR_VOLTAGE, |
491 | .owner = THIS_MODULE, | 444 | .owner = THIS_MODULE, |
445 | .enable_time = 600, | ||
492 | }, | 446 | }, |
493 | { | 447 | { |
494 | .name = "LDO_G", | 448 | .name = "LDO_G", |
495 | .id = AB3100_LDO_G, | 449 | .id = AB3100_LDO_G, |
496 | .ops = ®ulator_ops_variable, | 450 | .ops = ®ulator_ops_variable, |
497 | .n_voltages = ARRAY_SIZE(ldo_g_typ_voltages), | 451 | .n_voltages = ARRAY_SIZE(ldo_g_typ_voltages), |
452 | .volt_table = ldo_g_typ_voltages, | ||
498 | .type = REGULATOR_VOLTAGE, | 453 | .type = REGULATOR_VOLTAGE, |
499 | .owner = THIS_MODULE, | 454 | .owner = THIS_MODULE, |
455 | .enable_time = 400, | ||
500 | }, | 456 | }, |
501 | { | 457 | { |
502 | .name = "LDO_H", | 458 | .name = "LDO_H", |
503 | .id = AB3100_LDO_H, | 459 | .id = AB3100_LDO_H, |
504 | .ops = ®ulator_ops_variable, | 460 | .ops = ®ulator_ops_variable, |
505 | .n_voltages = ARRAY_SIZE(ldo_h_typ_voltages), | 461 | .n_voltages = ARRAY_SIZE(ldo_h_typ_voltages), |
462 | .volt_table = ldo_h_typ_voltages, | ||
506 | .type = REGULATOR_VOLTAGE, | 463 | .type = REGULATOR_VOLTAGE, |
507 | .owner = THIS_MODULE, | 464 | .owner = THIS_MODULE, |
465 | .enable_time = 200, | ||
508 | }, | 466 | }, |
509 | { | 467 | { |
510 | .name = "LDO_K", | 468 | .name = "LDO_K", |
511 | .id = AB3100_LDO_K, | 469 | .id = AB3100_LDO_K, |
512 | .ops = ®ulator_ops_variable, | 470 | .ops = ®ulator_ops_variable, |
513 | .n_voltages = ARRAY_SIZE(ldo_k_typ_voltages), | 471 | .n_voltages = ARRAY_SIZE(ldo_k_typ_voltages), |
472 | .volt_table = ldo_k_typ_voltages, | ||
514 | .type = REGULATOR_VOLTAGE, | 473 | .type = REGULATOR_VOLTAGE, |
515 | .owner = THIS_MODULE, | 474 | .owner = THIS_MODULE, |
475 | .enable_time = 200, | ||
516 | }, | 476 | }, |
517 | { | 477 | { |
518 | .name = "LDO_EXT", | 478 | .name = "LDO_EXT", |
@@ -528,6 +488,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { | |||
528 | .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), | 488 | .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages), |
529 | .type = REGULATOR_VOLTAGE, | 489 | .type = REGULATOR_VOLTAGE, |
530 | .owner = THIS_MODULE, | 490 | .owner = THIS_MODULE, |
491 | .enable_time = 1000, | ||
531 | }, | 492 | }, |
532 | }; | 493 | }; |
533 | 494 | ||
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index a739f5ca936a..13d424fc1c14 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c | |||
@@ -30,9 +30,6 @@ | |||
30 | * @dev: device pointer | 30 | * @dev: device pointer |
31 | * @desc: regulator description | 31 | * @desc: regulator description |
32 | * @regulator_dev: regulator device | 32 | * @regulator_dev: regulator device |
33 | * @max_uV: maximum voltage (for variable voltage supplies) | ||
34 | * @min_uV: minimum voltage (for variable voltage supplies) | ||
35 | * @fixed_uV: typical voltage (for fixed voltage supplies) | ||
36 | * @update_bank: bank to control on/off | 33 | * @update_bank: bank to control on/off |
37 | * @update_reg: register to control on/off | 34 | * @update_reg: register to control on/off |
38 | * @update_mask: mask to enable/disable regulator | 35 | * @update_mask: mask to enable/disable regulator |
@@ -40,17 +37,12 @@ | |||
40 | * @voltage_bank: bank to control regulator voltage | 37 | * @voltage_bank: bank to control regulator voltage |
41 | * @voltage_reg: register to control regulator voltage | 38 | * @voltage_reg: register to control regulator voltage |
42 | * @voltage_mask: mask to control regulator voltage | 39 | * @voltage_mask: mask to control regulator voltage |
43 | * @voltages: supported voltage table | ||
44 | * @voltages_len: number of supported voltages for the regulator | ||
45 | * @delay: startup/set voltage delay in us | 40 | * @delay: startup/set voltage delay in us |
46 | */ | 41 | */ |
47 | struct ab8500_regulator_info { | 42 | struct ab8500_regulator_info { |
48 | struct device *dev; | 43 | struct device *dev; |
49 | struct regulator_desc desc; | 44 | struct regulator_desc desc; |
50 | struct regulator_dev *regulator; | 45 | struct regulator_dev *regulator; |
51 | int max_uV; | ||
52 | int min_uV; | ||
53 | int fixed_uV; | ||
54 | u8 update_bank; | 46 | u8 update_bank; |
55 | u8 update_reg; | 47 | u8 update_reg; |
56 | u8 update_mask; | 48 | u8 update_mask; |
@@ -58,13 +50,11 @@ struct ab8500_regulator_info { | |||
58 | u8 voltage_bank; | 50 | u8 voltage_bank; |
59 | u8 voltage_reg; | 51 | u8 voltage_reg; |
60 | u8 voltage_mask; | 52 | u8 voltage_mask; |
61 | int const *voltages; | ||
62 | int voltages_len; | ||
63 | unsigned int delay; | 53 | unsigned int delay; |
64 | }; | 54 | }; |
65 | 55 | ||
66 | /* voltage tables for the vauxn/vintcore supplies */ | 56 | /* voltage tables for the vauxn/vintcore supplies */ |
67 | static const int ldo_vauxn_voltages[] = { | 57 | static const unsigned int ldo_vauxn_voltages[] = { |
68 | 1100000, | 58 | 1100000, |
69 | 1200000, | 59 | 1200000, |
70 | 1300000, | 60 | 1300000, |
@@ -83,7 +73,7 @@ static const int ldo_vauxn_voltages[] = { | |||
83 | 3300000, | 73 | 3300000, |
84 | }; | 74 | }; |
85 | 75 | ||
86 | static const int ldo_vaux3_voltages[] = { | 76 | static const unsigned int ldo_vaux3_voltages[] = { |
87 | 1200000, | 77 | 1200000, |
88 | 1500000, | 78 | 1500000, |
89 | 1800000, | 79 | 1800000, |
@@ -94,7 +84,7 @@ static const int ldo_vaux3_voltages[] = { | |||
94 | 2910000, | 84 | 2910000, |
95 | }; | 85 | }; |
96 | 86 | ||
97 | static const int ldo_vintcore_voltages[] = { | 87 | static const unsigned int ldo_vintcore_voltages[] = { |
98 | 1200000, | 88 | 1200000, |
99 | 1225000, | 89 | 1225000, |
100 | 1250000, | 90 | 1250000, |
@@ -185,25 +175,6 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) | |||
185 | return false; | 175 | return false; |
186 | } | 176 | } |
187 | 177 | ||
188 | static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) | ||
189 | { | ||
190 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); | ||
191 | |||
192 | if (info == NULL) { | ||
193 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); | ||
194 | return -EINVAL; | ||
195 | } | ||
196 | |||
197 | /* return the uV for the fixed regulators */ | ||
198 | if (info->fixed_uV) | ||
199 | return info->fixed_uV; | ||
200 | |||
201 | if (selector >= info->voltages_len) | ||
202 | return -EINVAL; | ||
203 | |||
204 | return info->voltages[selector]; | ||
205 | } | ||
206 | |||
207 | static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) | 178 | static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) |
208 | { | 179 | { |
209 | int ret, val; | 180 | int ret, val; |
@@ -279,14 +250,7 @@ static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, | |||
279 | unsigned int new_sel) | 250 | unsigned int new_sel) |
280 | { | 251 | { |
281 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); | 252 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
282 | int ret; | ||
283 | 253 | ||
284 | /* If the regulator isn't on, it won't take time here */ | ||
285 | ret = ab8500_regulator_is_enabled(rdev); | ||
286 | if (ret < 0) | ||
287 | return ret; | ||
288 | if (!ret) | ||
289 | return 0; | ||
290 | return info->delay; | 254 | return info->delay; |
291 | } | 255 | } |
292 | 256 | ||
@@ -296,21 +260,14 @@ static struct regulator_ops ab8500_regulator_ops = { | |||
296 | .is_enabled = ab8500_regulator_is_enabled, | 260 | .is_enabled = ab8500_regulator_is_enabled, |
297 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, | 261 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
298 | .set_voltage_sel = ab8500_regulator_set_voltage_sel, | 262 | .set_voltage_sel = ab8500_regulator_set_voltage_sel, |
299 | .list_voltage = ab8500_list_voltage, | 263 | .list_voltage = regulator_list_voltage_table, |
300 | .enable_time = ab8500_regulator_enable_time, | 264 | .enable_time = ab8500_regulator_enable_time, |
301 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, | 265 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
302 | }; | 266 | }; |
303 | 267 | ||
304 | static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) | 268 | static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) |
305 | { | 269 | { |
306 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); | 270 | return rdev->desc->min_uV; |
307 | |||
308 | if (info == NULL) { | ||
309 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); | ||
310 | return -EINVAL; | ||
311 | } | ||
312 | |||
313 | return info->fixed_uV; | ||
314 | } | 271 | } |
315 | 272 | ||
316 | static struct regulator_ops ab8500_regulator_fixed_ops = { | 273 | static struct regulator_ops ab8500_regulator_fixed_ops = { |
@@ -318,9 +275,8 @@ static struct regulator_ops ab8500_regulator_fixed_ops = { | |||
318 | .disable = ab8500_regulator_disable, | 275 | .disable = ab8500_regulator_disable, |
319 | .is_enabled = ab8500_regulator_is_enabled, | 276 | .is_enabled = ab8500_regulator_is_enabled, |
320 | .get_voltage = ab8500_fixed_get_voltage, | 277 | .get_voltage = ab8500_fixed_get_voltage, |
321 | .list_voltage = ab8500_list_voltage, | 278 | .list_voltage = regulator_list_voltage_linear, |
322 | .enable_time = ab8500_regulator_enable_time, | 279 | .enable_time = ab8500_regulator_enable_time, |
323 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, | ||
324 | }; | 280 | }; |
325 | 281 | ||
326 | static struct ab8500_regulator_info | 282 | static struct ab8500_regulator_info |
@@ -329,7 +285,7 @@ static struct ab8500_regulator_info | |||
329 | * Variable Voltage Regulators | 285 | * Variable Voltage Regulators |
330 | * name, min mV, max mV, | 286 | * name, min mV, max mV, |
331 | * update bank, reg, mask, enable val | 287 | * update bank, reg, mask, enable val |
332 | * volt bank, reg, mask, table, table length | 288 | * volt bank, reg, mask |
333 | */ | 289 | */ |
334 | [AB8500_LDO_AUX1] = { | 290 | [AB8500_LDO_AUX1] = { |
335 | .desc = { | 291 | .desc = { |
@@ -339,9 +295,8 @@ static struct ab8500_regulator_info | |||
339 | .id = AB8500_LDO_AUX1, | 295 | .id = AB8500_LDO_AUX1, |
340 | .owner = THIS_MODULE, | 296 | .owner = THIS_MODULE, |
341 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), | 297 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
298 | .volt_table = ldo_vauxn_voltages, | ||
342 | }, | 299 | }, |
343 | .min_uV = 1100000, | ||
344 | .max_uV = 3300000, | ||
345 | .update_bank = 0x04, | 300 | .update_bank = 0x04, |
346 | .update_reg = 0x09, | 301 | .update_reg = 0x09, |
347 | .update_mask = 0x03, | 302 | .update_mask = 0x03, |
@@ -349,8 +304,6 @@ static struct ab8500_regulator_info | |||
349 | .voltage_bank = 0x04, | 304 | .voltage_bank = 0x04, |
350 | .voltage_reg = 0x1f, | 305 | .voltage_reg = 0x1f, |
351 | .voltage_mask = 0x0f, | 306 | .voltage_mask = 0x0f, |
352 | .voltages = ldo_vauxn_voltages, | ||
353 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), | ||
354 | }, | 307 | }, |
355 | [AB8500_LDO_AUX2] = { | 308 | [AB8500_LDO_AUX2] = { |
356 | .desc = { | 309 | .desc = { |
@@ -360,9 +313,8 @@ static struct ab8500_regulator_info | |||
360 | .id = AB8500_LDO_AUX2, | 313 | .id = AB8500_LDO_AUX2, |
361 | .owner = THIS_MODULE, | 314 | .owner = THIS_MODULE, |
362 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), | 315 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
316 | .volt_table = ldo_vauxn_voltages, | ||
363 | }, | 317 | }, |
364 | .min_uV = 1100000, | ||
365 | .max_uV = 3300000, | ||
366 | .update_bank = 0x04, | 318 | .update_bank = 0x04, |
367 | .update_reg = 0x09, | 319 | .update_reg = 0x09, |
368 | .update_mask = 0x0c, | 320 | .update_mask = 0x0c, |
@@ -370,8 +322,6 @@ static struct ab8500_regulator_info | |||
370 | .voltage_bank = 0x04, | 322 | .voltage_bank = 0x04, |
371 | .voltage_reg = 0x20, | 323 | .voltage_reg = 0x20, |
372 | .voltage_mask = 0x0f, | 324 | .voltage_mask = 0x0f, |
373 | .voltages = ldo_vauxn_voltages, | ||
374 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), | ||
375 | }, | 325 | }, |
376 | [AB8500_LDO_AUX3] = { | 326 | [AB8500_LDO_AUX3] = { |
377 | .desc = { | 327 | .desc = { |
@@ -381,9 +331,8 @@ static struct ab8500_regulator_info | |||
381 | .id = AB8500_LDO_AUX3, | 331 | .id = AB8500_LDO_AUX3, |
382 | .owner = THIS_MODULE, | 332 | .owner = THIS_MODULE, |
383 | .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), | 333 | .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), |
334 | .volt_table = ldo_vaux3_voltages, | ||
384 | }, | 335 | }, |
385 | .min_uV = 1100000, | ||
386 | .max_uV = 3300000, | ||
387 | .update_bank = 0x04, | 336 | .update_bank = 0x04, |
388 | .update_reg = 0x0a, | 337 | .update_reg = 0x0a, |
389 | .update_mask = 0x03, | 338 | .update_mask = 0x03, |
@@ -391,8 +340,6 @@ static struct ab8500_regulator_info | |||
391 | .voltage_bank = 0x04, | 340 | .voltage_bank = 0x04, |
392 | .voltage_reg = 0x21, | 341 | .voltage_reg = 0x21, |
393 | .voltage_mask = 0x07, | 342 | .voltage_mask = 0x07, |
394 | .voltages = ldo_vaux3_voltages, | ||
395 | .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages), | ||
396 | }, | 343 | }, |
397 | [AB8500_LDO_INTCORE] = { | 344 | [AB8500_LDO_INTCORE] = { |
398 | .desc = { | 345 | .desc = { |
@@ -402,9 +349,8 @@ static struct ab8500_regulator_info | |||
402 | .id = AB8500_LDO_INTCORE, | 349 | .id = AB8500_LDO_INTCORE, |
403 | .owner = THIS_MODULE, | 350 | .owner = THIS_MODULE, |
404 | .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), | 351 | .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), |
352 | .volt_table = ldo_vintcore_voltages, | ||
405 | }, | 353 | }, |
406 | .min_uV = 1100000, | ||
407 | .max_uV = 3300000, | ||
408 | .update_bank = 0x03, | 354 | .update_bank = 0x03, |
409 | .update_reg = 0x80, | 355 | .update_reg = 0x80, |
410 | .update_mask = 0x44, | 356 | .update_mask = 0x44, |
@@ -412,8 +358,6 @@ static struct ab8500_regulator_info | |||
412 | .voltage_bank = 0x03, | 358 | .voltage_bank = 0x03, |
413 | .voltage_reg = 0x80, | 359 | .voltage_reg = 0x80, |
414 | .voltage_mask = 0x38, | 360 | .voltage_mask = 0x38, |
415 | .voltages = ldo_vintcore_voltages, | ||
416 | .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages), | ||
417 | }, | 361 | }, |
418 | 362 | ||
419 | /* | 363 | /* |
@@ -429,9 +373,9 @@ static struct ab8500_regulator_info | |||
429 | .id = AB8500_LDO_TVOUT, | 373 | .id = AB8500_LDO_TVOUT, |
430 | .owner = THIS_MODULE, | 374 | .owner = THIS_MODULE, |
431 | .n_voltages = 1, | 375 | .n_voltages = 1, |
376 | .min_uV = 2000000, | ||
432 | }, | 377 | }, |
433 | .delay = 10000, | 378 | .delay = 10000, |
434 | .fixed_uV = 2000000, | ||
435 | .update_bank = 0x03, | 379 | .update_bank = 0x03, |
436 | .update_reg = 0x80, | 380 | .update_reg = 0x80, |
437 | .update_mask = 0x82, | 381 | .update_mask = 0x82, |
@@ -445,8 +389,8 @@ static struct ab8500_regulator_info | |||
445 | .id = AB8500_LDO_USB, | 389 | .id = AB8500_LDO_USB, |
446 | .owner = THIS_MODULE, | 390 | .owner = THIS_MODULE, |
447 | .n_voltages = 1, | 391 | .n_voltages = 1, |
392 | .min_uV = 3300000, | ||
448 | }, | 393 | }, |
449 | .fixed_uV = 3300000, | ||
450 | .update_bank = 0x03, | 394 | .update_bank = 0x03, |
451 | .update_reg = 0x82, | 395 | .update_reg = 0x82, |
452 | .update_mask = 0x03, | 396 | .update_mask = 0x03, |
@@ -460,8 +404,8 @@ static struct ab8500_regulator_info | |||
460 | .id = AB8500_LDO_AUDIO, | 404 | .id = AB8500_LDO_AUDIO, |
461 | .owner = THIS_MODULE, | 405 | .owner = THIS_MODULE, |
462 | .n_voltages = 1, | 406 | .n_voltages = 1, |
407 | .min_uV = 2000000, | ||
463 | }, | 408 | }, |
464 | .fixed_uV = 2000000, | ||
465 | .update_bank = 0x03, | 409 | .update_bank = 0x03, |
466 | .update_reg = 0x83, | 410 | .update_reg = 0x83, |
467 | .update_mask = 0x02, | 411 | .update_mask = 0x02, |
@@ -475,8 +419,8 @@ static struct ab8500_regulator_info | |||
475 | .id = AB8500_LDO_ANAMIC1, | 419 | .id = AB8500_LDO_ANAMIC1, |
476 | .owner = THIS_MODULE, | 420 | .owner = THIS_MODULE, |
477 | .n_voltages = 1, | 421 | .n_voltages = 1, |
422 | .min_uV = 2050000, | ||
478 | }, | 423 | }, |
479 | .fixed_uV = 2050000, | ||
480 | .update_bank = 0x03, | 424 | .update_bank = 0x03, |
481 | .update_reg = 0x83, | 425 | .update_reg = 0x83, |
482 | .update_mask = 0x08, | 426 | .update_mask = 0x08, |
@@ -490,8 +434,8 @@ static struct ab8500_regulator_info | |||
490 | .id = AB8500_LDO_ANAMIC2, | 434 | .id = AB8500_LDO_ANAMIC2, |
491 | .owner = THIS_MODULE, | 435 | .owner = THIS_MODULE, |
492 | .n_voltages = 1, | 436 | .n_voltages = 1, |
437 | .min_uV = 2050000, | ||
493 | }, | 438 | }, |
494 | .fixed_uV = 2050000, | ||
495 | .update_bank = 0x03, | 439 | .update_bank = 0x03, |
496 | .update_reg = 0x83, | 440 | .update_reg = 0x83, |
497 | .update_mask = 0x10, | 441 | .update_mask = 0x10, |
@@ -505,8 +449,8 @@ static struct ab8500_regulator_info | |||
505 | .id = AB8500_LDO_DMIC, | 449 | .id = AB8500_LDO_DMIC, |
506 | .owner = THIS_MODULE, | 450 | .owner = THIS_MODULE, |
507 | .n_voltages = 1, | 451 | .n_voltages = 1, |
452 | .min_uV = 1800000, | ||
508 | }, | 453 | }, |
509 | .fixed_uV = 1800000, | ||
510 | .update_bank = 0x03, | 454 | .update_bank = 0x03, |
511 | .update_reg = 0x83, | 455 | .update_reg = 0x83, |
512 | .update_mask = 0x04, | 456 | .update_mask = 0x04, |
@@ -520,8 +464,8 @@ static struct ab8500_regulator_info | |||
520 | .id = AB8500_LDO_ANA, | 464 | .id = AB8500_LDO_ANA, |
521 | .owner = THIS_MODULE, | 465 | .owner = THIS_MODULE, |
522 | .n_voltages = 1, | 466 | .n_voltages = 1, |
467 | .min_uV = 1200000, | ||
523 | }, | 468 | }, |
524 | .fixed_uV = 1200000, | ||
525 | .update_bank = 0x04, | 469 | .update_bank = 0x04, |
526 | .update_reg = 0x06, | 470 | .update_reg = 0x06, |
527 | .update_mask = 0x0c, | 471 | .update_mask = 0x0c, |
@@ -769,9 +713,7 @@ static __devinit int ab8500_regulator_register(struct platform_device *pdev, | |||
769 | if (info->desc.id == AB8500_LDO_AUX3) { | 713 | if (info->desc.id == AB8500_LDO_AUX3) { |
770 | info->desc.n_voltages = | 714 | info->desc.n_voltages = |
771 | ARRAY_SIZE(ldo_vauxn_voltages); | 715 | ARRAY_SIZE(ldo_vauxn_voltages); |
772 | info->voltages = ldo_vauxn_voltages; | 716 | info->desc.volt_table = ldo_vauxn_voltages; |
773 | info->voltages_len = | ||
774 | ARRAY_SIZE(ldo_vauxn_voltages); | ||
775 | info->voltage_mask = 0xf; | 717 | info->voltage_mask = 0xf; |
776 | } | 718 | } |
777 | } | 719 | } |
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 46d05f38baf8..f123f7e3b752 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c | |||
@@ -89,9 +89,12 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int | |||
89 | unsigned short data; | 89 | unsigned short data; |
90 | int ret; | 90 | int ret; |
91 | 91 | ||
92 | if (min_uA > chip->max_uA || min_uA < chip->min_uA) | 92 | if (min_uA < chip->min_uA) |
93 | return -EINVAL; | 93 | min_uA = chip->min_uA; |
94 | if (max_uA > chip->max_uA || max_uA < chip->min_uA) | 94 | if (max_uA > chip->max_uA) |
95 | max_uA = chip->max_uA; | ||
96 | |||
97 | if (min_uA > chip->max_uA || max_uA < chip->min_uA) | ||
95 | return -EINVAL; | 98 | return -EINVAL; |
96 | 99 | ||
97 | selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, | 100 | selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level, |
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index e82e7eaac0f1..e9c2085f9dfb 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c | |||
@@ -43,33 +43,15 @@ struct anatop_regulator { | |||
43 | struct regulator_init_data *initdata; | 43 | struct regulator_init_data *initdata; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | static int anatop_set_voltage(struct regulator_dev *reg, int min_uV, | 46 | static int anatop_set_voltage_sel(struct regulator_dev *reg, unsigned selector) |
47 | int max_uV, unsigned *selector) | ||
48 | { | 47 | { |
49 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); | 48 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
50 | u32 val, sel, mask; | 49 | u32 val, mask; |
51 | int uv; | ||
52 | |||
53 | uv = min_uV; | ||
54 | dev_dbg(®->dev, "%s: uv %d, min %d, max %d\n", __func__, | ||
55 | uv, anatop_reg->min_voltage, | ||
56 | anatop_reg->max_voltage); | ||
57 | |||
58 | if (uv < anatop_reg->min_voltage) { | ||
59 | if (max_uV > anatop_reg->min_voltage) | ||
60 | uv = anatop_reg->min_voltage; | ||
61 | else | ||
62 | return -EINVAL; | ||
63 | } | ||
64 | 50 | ||
65 | if (!anatop_reg->control_reg) | 51 | if (!anatop_reg->control_reg) |
66 | return -ENOTSUPP; | 52 | return -ENOTSUPP; |
67 | 53 | ||
68 | sel = DIV_ROUND_UP(uv - anatop_reg->min_voltage, 25000); | 54 | val = anatop_reg->min_bit_val + selector; |
69 | if (sel * 25000 + anatop_reg->min_voltage > anatop_reg->max_voltage) | ||
70 | return -EINVAL; | ||
71 | val = anatop_reg->min_bit_val + sel; | ||
72 | *selector = sel; | ||
73 | dev_dbg(®->dev, "%s: calculated val %d\n", __func__, val); | 55 | dev_dbg(®->dev, "%s: calculated val %d\n", __func__, val); |
74 | mask = ((1 << anatop_reg->vol_bit_width) - 1) << | 56 | mask = ((1 << anatop_reg->vol_bit_width) - 1) << |
75 | anatop_reg->vol_bit_shift; | 57 | anatop_reg->vol_bit_shift; |
@@ -94,21 +76,11 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg) | |||
94 | return val - anatop_reg->min_bit_val; | 76 | return val - anatop_reg->min_bit_val; |
95 | } | 77 | } |
96 | 78 | ||
97 | static int anatop_list_voltage(struct regulator_dev *reg, unsigned selector) | ||
98 | { | ||
99 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); | ||
100 | int uv; | ||
101 | |||
102 | uv = anatop_reg->min_voltage + selector * 25000; | ||
103 | dev_dbg(®->dev, "vddio = %d, selector = %u\n", uv, selector); | ||
104 | |||
105 | return uv; | ||
106 | } | ||
107 | |||
108 | static struct regulator_ops anatop_rops = { | 79 | static struct regulator_ops anatop_rops = { |
109 | .set_voltage = anatop_set_voltage, | 80 | .set_voltage_sel = anatop_set_voltage_sel, |
110 | .get_voltage_sel = anatop_get_voltage_sel, | 81 | .get_voltage_sel = anatop_get_voltage_sel, |
111 | .list_voltage = anatop_list_voltage, | 82 | .list_voltage = regulator_list_voltage_linear, |
83 | .map_voltage = regulator_map_voltage_linear, | ||
112 | }; | 84 | }; |
113 | 85 | ||
114 | static int __devinit anatop_regulator_probe(struct platform_device *pdev) | 86 | static int __devinit anatop_regulator_probe(struct platform_device *pdev) |
@@ -176,6 +148,8 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev) | |||
176 | 148 | ||
177 | rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) | 149 | rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) |
178 | / 25000 + 1; | 150 | / 25000 + 1; |
151 | rdesc->min_uV = sreg->min_voltage; | ||
152 | rdesc->uV_step = 25000; | ||
179 | 153 | ||
180 | config.dev = &pdev->dev; | 154 | config.dev = &pdev->dev; |
181 | config.init_data = initdata; | 155 | config.init_data = initdata; |
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c new file mode 100644 index 000000000000..c8f95c07adb6 --- /dev/null +++ b/drivers/regulator/arizona-ldo1.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | * arizona-ldo1.c -- LDO1 supply for Arizona devices | ||
3 | * | ||
4 | * Copyright 2012 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/moduleparam.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/bitops.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/regulator/driver.h> | ||
21 | #include <linux/regulator/machine.h> | ||
22 | #include <linux/gpio.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | #include <linux/mfd/arizona/core.h> | ||
26 | #include <linux/mfd/arizona/pdata.h> | ||
27 | #include <linux/mfd/arizona/registers.h> | ||
28 | |||
29 | struct arizona_ldo1 { | ||
30 | struct regulator_dev *regulator; | ||
31 | struct arizona *arizona; | ||
32 | |||
33 | struct regulator_consumer_supply supply; | ||
34 | struct regulator_init_data init_data; | ||
35 | }; | ||
36 | |||
37 | static struct regulator_ops arizona_ldo1_ops = { | ||
38 | .list_voltage = regulator_list_voltage_linear, | ||
39 | .map_voltage = regulator_map_voltage_linear, | ||
40 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
41 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
42 | }; | ||
43 | |||
44 | static const struct regulator_desc arizona_ldo1 = { | ||
45 | .name = "LDO1", | ||
46 | .supply_name = "LDOVDD", | ||
47 | .type = REGULATOR_VOLTAGE, | ||
48 | .ops = &arizona_ldo1_ops, | ||
49 | |||
50 | .vsel_reg = ARIZONA_LDO1_CONTROL_1, | ||
51 | .vsel_mask = ARIZONA_LDO1_VSEL_MASK, | ||
52 | .min_uV = 900000, | ||
53 | .uV_step = 50000, | ||
54 | .n_voltages = 7, | ||
55 | |||
56 | .owner = THIS_MODULE, | ||
57 | }; | ||
58 | |||
59 | static const struct regulator_init_data arizona_ldo1_default = { | ||
60 | .constraints = { | ||
61 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, | ||
62 | }, | ||
63 | .num_consumer_supplies = 1, | ||
64 | }; | ||
65 | |||
66 | static __devinit int arizona_ldo1_probe(struct platform_device *pdev) | ||
67 | { | ||
68 | struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); | ||
69 | struct regulator_config config = { }; | ||
70 | struct arizona_ldo1 *ldo1; | ||
71 | int ret; | ||
72 | |||
73 | ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL); | ||
74 | if (ldo1 == NULL) { | ||
75 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | ||
76 | return -ENOMEM; | ||
77 | } | ||
78 | |||
79 | ldo1->arizona = arizona; | ||
80 | |||
81 | /* | ||
82 | * Since the chip usually supplies itself we provide some | ||
83 | * default init_data for it. This will be overridden with | ||
84 | * platform data if provided. | ||
85 | */ | ||
86 | ldo1->init_data = arizona_ldo1_default; | ||
87 | ldo1->init_data.consumer_supplies = &ldo1->supply; | ||
88 | ldo1->supply.supply = "DCVDD"; | ||
89 | ldo1->supply.dev_name = dev_name(arizona->dev); | ||
90 | |||
91 | config.dev = arizona->dev; | ||
92 | config.driver_data = ldo1; | ||
93 | config.regmap = arizona->regmap; | ||
94 | config.ena_gpio = arizona->pdata.ldoena; | ||
95 | |||
96 | if (arizona->pdata.ldo1) | ||
97 | config.init_data = arizona->pdata.ldo1; | ||
98 | else | ||
99 | config.init_data = &ldo1->init_data; | ||
100 | |||
101 | ldo1->regulator = regulator_register(&arizona_ldo1, &config); | ||
102 | if (IS_ERR(ldo1->regulator)) { | ||
103 | ret = PTR_ERR(ldo1->regulator); | ||
104 | dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", | ||
105 | ret); | ||
106 | return ret; | ||
107 | } | ||
108 | |||
109 | platform_set_drvdata(pdev, ldo1); | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static __devexit int arizona_ldo1_remove(struct platform_device *pdev) | ||
115 | { | ||
116 | struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev); | ||
117 | |||
118 | regulator_unregister(ldo1->regulator); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static struct platform_driver arizona_ldo1_driver = { | ||
124 | .probe = arizona_ldo1_probe, | ||
125 | .remove = __devexit_p(arizona_ldo1_remove), | ||
126 | .driver = { | ||
127 | .name = "arizona-ldo1", | ||
128 | .owner = THIS_MODULE, | ||
129 | }, | ||
130 | }; | ||
131 | |||
132 | module_platform_driver(arizona_ldo1_driver); | ||
133 | |||
134 | /* Module information */ | ||
135 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
136 | MODULE_DESCRIPTION("Arizona LDO1 driver"); | ||
137 | MODULE_LICENSE("GPL"); | ||
138 | MODULE_ALIAS("platform:arizona-ldo1"); | ||
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c new file mode 100644 index 000000000000..450a069aa9b6 --- /dev/null +++ b/drivers/regulator/arizona-micsupp.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | * arizona-micsupp.c -- Microphone supply for Arizona devices | ||
3 | * | ||
4 | * Copyright 2012 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/moduleparam.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/bitops.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/regulator/driver.h> | ||
21 | #include <linux/regulator/machine.h> | ||
22 | #include <linux/gpio.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | #include <linux/mfd/arizona/core.h> | ||
26 | #include <linux/mfd/arizona/pdata.h> | ||
27 | #include <linux/mfd/arizona/registers.h> | ||
28 | |||
29 | #define ARIZONA_MICSUPP_MAX_SELECTOR 0x1f | ||
30 | |||
31 | struct arizona_micsupp { | ||
32 | struct regulator_dev *regulator; | ||
33 | struct arizona *arizona; | ||
34 | |||
35 | struct regulator_consumer_supply supply; | ||
36 | struct regulator_init_data init_data; | ||
37 | }; | ||
38 | |||
39 | static int arizona_micsupp_list_voltage(struct regulator_dev *rdev, | ||
40 | unsigned int selector) | ||
41 | { | ||
42 | if (selector > ARIZONA_MICSUPP_MAX_SELECTOR) | ||
43 | return -EINVAL; | ||
44 | |||
45 | if (selector == ARIZONA_MICSUPP_MAX_SELECTOR) | ||
46 | return 3300000; | ||
47 | else | ||
48 | return (selector * 50000) + 1700000; | ||
49 | } | ||
50 | |||
51 | static int arizona_micsupp_map_voltage(struct regulator_dev *rdev, | ||
52 | int min_uV, int max_uV) | ||
53 | { | ||
54 | unsigned int voltage; | ||
55 | int selector; | ||
56 | |||
57 | if (min_uV < 1700000) | ||
58 | min_uV = 1700000; | ||
59 | |||
60 | if (min_uV > 3200000) | ||
61 | selector = ARIZONA_MICSUPP_MAX_SELECTOR; | ||
62 | else | ||
63 | selector = DIV_ROUND_UP(min_uV - 1700000, 50000); | ||
64 | |||
65 | if (selector < 0) | ||
66 | return -EINVAL; | ||
67 | |||
68 | voltage = arizona_micsupp_list_voltage(rdev, selector); | ||
69 | if (voltage < min_uV || voltage > max_uV) | ||
70 | return -EINVAL; | ||
71 | |||
72 | return selector; | ||
73 | } | ||
74 | |||
75 | static struct regulator_ops arizona_micsupp_ops = { | ||
76 | .enable = regulator_enable_regmap, | ||
77 | .disable = regulator_disable_regmap, | ||
78 | .is_enabled = regulator_is_enabled_regmap, | ||
79 | |||
80 | .list_voltage = arizona_micsupp_list_voltage, | ||
81 | .map_voltage = arizona_micsupp_map_voltage, | ||
82 | |||
83 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
84 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
85 | }; | ||
86 | |||
87 | static const struct regulator_desc arizona_micsupp = { | ||
88 | .name = "MICVDD", | ||
89 | .supply_name = "CPVDD", | ||
90 | .type = REGULATOR_VOLTAGE, | ||
91 | .n_voltages = ARIZONA_MICSUPP_MAX_SELECTOR + 1, | ||
92 | .ops = &arizona_micsupp_ops, | ||
93 | |||
94 | .vsel_reg = ARIZONA_LDO2_CONTROL_1, | ||
95 | .vsel_mask = ARIZONA_LDO2_VSEL_MASK, | ||
96 | .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1, | ||
97 | .enable_mask = ARIZONA_CPMIC_ENA, | ||
98 | |||
99 | .owner = THIS_MODULE, | ||
100 | }; | ||
101 | |||
102 | static const struct regulator_init_data arizona_micsupp_default = { | ||
103 | .constraints = { | ||
104 | .valid_ops_mask = REGULATOR_CHANGE_STATUS | | ||
105 | REGULATOR_CHANGE_VOLTAGE, | ||
106 | .min_uV = 1700000, | ||
107 | .max_uV = 3300000, | ||
108 | }, | ||
109 | |||
110 | .num_consumer_supplies = 1, | ||
111 | }; | ||
112 | |||
113 | static __devinit int arizona_micsupp_probe(struct platform_device *pdev) | ||
114 | { | ||
115 | struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); | ||
116 | struct regulator_config config = { }; | ||
117 | struct arizona_micsupp *micsupp; | ||
118 | int ret; | ||
119 | |||
120 | micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL); | ||
121 | if (micsupp == NULL) { | ||
122 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | ||
123 | return -ENOMEM; | ||
124 | } | ||
125 | |||
126 | micsupp->arizona = arizona; | ||
127 | |||
128 | /* | ||
129 | * Since the chip usually supplies itself we provide some | ||
130 | * default init_data for it. This will be overridden with | ||
131 | * platform data if provided. | ||
132 | */ | ||
133 | micsupp->init_data = arizona_micsupp_default; | ||
134 | micsupp->init_data.consumer_supplies = &micsupp->supply; | ||
135 | micsupp->supply.supply = "MICVDD"; | ||
136 | micsupp->supply.dev_name = dev_name(arizona->dev); | ||
137 | |||
138 | config.dev = arizona->dev; | ||
139 | config.driver_data = micsupp; | ||
140 | config.regmap = arizona->regmap; | ||
141 | |||
142 | if (arizona->pdata.micvdd) | ||
143 | config.init_data = arizona->pdata.micvdd; | ||
144 | else | ||
145 | config.init_data = &micsupp->init_data; | ||
146 | |||
147 | /* Default to regulated mode until the API supports bypass */ | ||
148 | regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1, | ||
149 | ARIZONA_CPMIC_BYPASS, 0); | ||
150 | |||
151 | micsupp->regulator = regulator_register(&arizona_micsupp, &config); | ||
152 | if (IS_ERR(micsupp->regulator)) { | ||
153 | ret = PTR_ERR(micsupp->regulator); | ||
154 | dev_err(arizona->dev, "Failed to register mic supply: %d\n", | ||
155 | ret); | ||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | platform_set_drvdata(pdev, micsupp); | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static __devexit int arizona_micsupp_remove(struct platform_device *pdev) | ||
165 | { | ||
166 | struct arizona_micsupp *micsupp = platform_get_drvdata(pdev); | ||
167 | |||
168 | regulator_unregister(micsupp->regulator); | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | static struct platform_driver arizona_micsupp_driver = { | ||
174 | .probe = arizona_micsupp_probe, | ||
175 | .remove = __devexit_p(arizona_micsupp_remove), | ||
176 | .driver = { | ||
177 | .name = "arizona-micsupp", | ||
178 | .owner = THIS_MODULE, | ||
179 | }, | ||
180 | }; | ||
181 | |||
182 | module_platform_driver(arizona_micsupp_driver); | ||
183 | |||
184 | /* Module information */ | ||
185 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
186 | MODULE_DESCRIPTION("Arizona microphone supply driver"); | ||
187 | MODULE_LICENSE("GPL"); | ||
188 | MODULE_ALIAS("platform:arizona-micsupp"); | ||
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e8ee20095a19..2e31dffbefe7 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/mutex.h> | 23 | #include <linux/mutex.h> |
24 | #include <linux/suspend.h> | 24 | #include <linux/suspend.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/gpio.h> | ||
26 | #include <linux/of.h> | 27 | #include <linux/of.h> |
27 | #include <linux/regmap.h> | 28 | #include <linux/regmap.h> |
28 | #include <linux/regulator/of_regulator.h> | 29 | #include <linux/regulator/of_regulator.h> |
@@ -936,6 +937,14 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
936 | } | 937 | } |
937 | } | 938 | } |
938 | 939 | ||
940 | if (rdev->constraints->ramp_delay && ops->set_ramp_delay) { | ||
941 | ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); | ||
942 | if (ret < 0) { | ||
943 | rdev_err(rdev, "failed to set ramp_delay\n"); | ||
944 | goto out; | ||
945 | } | ||
946 | } | ||
947 | |||
939 | print_constraints(rdev); | 948 | print_constraints(rdev); |
940 | return 0; | 949 | return 0; |
941 | out: | 950 | out: |
@@ -1125,7 +1134,7 @@ overflow_err: | |||
1125 | static int _regulator_get_enable_time(struct regulator_dev *rdev) | 1134 | static int _regulator_get_enable_time(struct regulator_dev *rdev) |
1126 | { | 1135 | { |
1127 | if (!rdev->desc->ops->enable_time) | 1136 | if (!rdev->desc->ops->enable_time) |
1128 | return 0; | 1137 | return rdev->desc->enable_time; |
1129 | return rdev->desc->ops->enable_time(rdev); | 1138 | return rdev->desc->ops->enable_time(rdev); |
1130 | } | 1139 | } |
1131 | 1140 | ||
@@ -1407,10 +1416,54 @@ void devm_regulator_put(struct regulator *regulator) | |||
1407 | } | 1416 | } |
1408 | EXPORT_SYMBOL_GPL(devm_regulator_put); | 1417 | EXPORT_SYMBOL_GPL(devm_regulator_put); |
1409 | 1418 | ||
1419 | static int _regulator_do_enable(struct regulator_dev *rdev) | ||
1420 | { | ||
1421 | int ret, delay; | ||
1422 | |||
1423 | /* Query before enabling in case configuration dependent. */ | ||
1424 | ret = _regulator_get_enable_time(rdev); | ||
1425 | if (ret >= 0) { | ||
1426 | delay = ret; | ||
1427 | } else { | ||
1428 | rdev_warn(rdev, "enable_time() failed: %d\n", ret); | ||
1429 | delay = 0; | ||
1430 | } | ||
1431 | |||
1432 | trace_regulator_enable(rdev_get_name(rdev)); | ||
1433 | |||
1434 | if (rdev->ena_gpio) { | ||
1435 | gpio_set_value_cansleep(rdev->ena_gpio, | ||
1436 | !rdev->ena_gpio_invert); | ||
1437 | rdev->ena_gpio_state = 1; | ||
1438 | } else if (rdev->desc->ops->enable) { | ||
1439 | ret = rdev->desc->ops->enable(rdev); | ||
1440 | if (ret < 0) | ||
1441 | return ret; | ||
1442 | } else { | ||
1443 | return -EINVAL; | ||
1444 | } | ||
1445 | |||
1446 | /* Allow the regulator to ramp; it would be useful to extend | ||
1447 | * this for bulk operations so that the regulators can ramp | ||
1448 | * together. */ | ||
1449 | trace_regulator_enable_delay(rdev_get_name(rdev)); | ||
1450 | |||
1451 | if (delay >= 1000) { | ||
1452 | mdelay(delay / 1000); | ||
1453 | udelay(delay % 1000); | ||
1454 | } else if (delay) { | ||
1455 | udelay(delay); | ||
1456 | } | ||
1457 | |||
1458 | trace_regulator_enable_complete(rdev_get_name(rdev)); | ||
1459 | |||
1460 | return 0; | ||
1461 | } | ||
1462 | |||
1410 | /* locks held by regulator_enable() */ | 1463 | /* locks held by regulator_enable() */ |
1411 | static int _regulator_enable(struct regulator_dev *rdev) | 1464 | static int _regulator_enable(struct regulator_dev *rdev) |
1412 | { | 1465 | { |
1413 | int ret, delay; | 1466 | int ret; |
1414 | 1467 | ||
1415 | /* check voltage and requested load before enabling */ | 1468 | /* check voltage and requested load before enabling */ |
1416 | if (rdev->constraints && | 1469 | if (rdev->constraints && |
@@ -1424,40 +1477,10 @@ static int _regulator_enable(struct regulator_dev *rdev) | |||
1424 | if (!_regulator_can_change_status(rdev)) | 1477 | if (!_regulator_can_change_status(rdev)) |
1425 | return -EPERM; | 1478 | return -EPERM; |
1426 | 1479 | ||
1427 | if (!rdev->desc->ops->enable) | 1480 | ret = _regulator_do_enable(rdev); |
1428 | return -EINVAL; | ||
1429 | |||
1430 | /* Query before enabling in case configuration | ||
1431 | * dependent. */ | ||
1432 | ret = _regulator_get_enable_time(rdev); | ||
1433 | if (ret >= 0) { | ||
1434 | delay = ret; | ||
1435 | } else { | ||
1436 | rdev_warn(rdev, "enable_time() failed: %d\n", | ||
1437 | ret); | ||
1438 | delay = 0; | ||
1439 | } | ||
1440 | |||
1441 | trace_regulator_enable(rdev_get_name(rdev)); | ||
1442 | |||
1443 | /* Allow the regulator to ramp; it would be useful | ||
1444 | * to extend this for bulk operations so that the | ||
1445 | * regulators can ramp together. */ | ||
1446 | ret = rdev->desc->ops->enable(rdev); | ||
1447 | if (ret < 0) | 1481 | if (ret < 0) |
1448 | return ret; | 1482 | return ret; |
1449 | 1483 | ||
1450 | trace_regulator_enable_delay(rdev_get_name(rdev)); | ||
1451 | |||
1452 | if (delay >= 1000) { | ||
1453 | mdelay(delay / 1000); | ||
1454 | udelay(delay % 1000); | ||
1455 | } else if (delay) { | ||
1456 | udelay(delay); | ||
1457 | } | ||
1458 | |||
1459 | trace_regulator_enable_complete(rdev_get_name(rdev)); | ||
1460 | |||
1461 | } else if (ret < 0) { | 1484 | } else if (ret < 0) { |
1462 | rdev_err(rdev, "is_enabled() failed: %d\n", ret); | 1485 | rdev_err(rdev, "is_enabled() failed: %d\n", ret); |
1463 | return ret; | 1486 | return ret; |
@@ -1506,6 +1529,30 @@ int regulator_enable(struct regulator *regulator) | |||
1506 | } | 1529 | } |
1507 | EXPORT_SYMBOL_GPL(regulator_enable); | 1530 | EXPORT_SYMBOL_GPL(regulator_enable); |
1508 | 1531 | ||
1532 | static int _regulator_do_disable(struct regulator_dev *rdev) | ||
1533 | { | ||
1534 | int ret; | ||
1535 | |||
1536 | trace_regulator_disable(rdev_get_name(rdev)); | ||
1537 | |||
1538 | if (rdev->ena_gpio) { | ||
1539 | gpio_set_value_cansleep(rdev->ena_gpio, | ||
1540 | rdev->ena_gpio_invert); | ||
1541 | rdev->ena_gpio_state = 0; | ||
1542 | |||
1543 | } else if (rdev->desc->ops->disable) { | ||
1544 | ret = rdev->desc->ops->disable(rdev); | ||
1545 | if (ret != 0) | ||
1546 | return ret; | ||
1547 | } | ||
1548 | |||
1549 | trace_regulator_disable_complete(rdev_get_name(rdev)); | ||
1550 | |||
1551 | _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, | ||
1552 | NULL); | ||
1553 | return 0; | ||
1554 | } | ||
1555 | |||
1509 | /* locks held by regulator_disable() */ | 1556 | /* locks held by regulator_disable() */ |
1510 | static int _regulator_disable(struct regulator_dev *rdev) | 1557 | static int _regulator_disable(struct regulator_dev *rdev) |
1511 | { | 1558 | { |
@@ -1520,20 +1567,12 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
1520 | (rdev->constraints && !rdev->constraints->always_on)) { | 1567 | (rdev->constraints && !rdev->constraints->always_on)) { |
1521 | 1568 | ||
1522 | /* we are last user */ | 1569 | /* we are last user */ |
1523 | if (_regulator_can_change_status(rdev) && | 1570 | if (_regulator_can_change_status(rdev)) { |
1524 | rdev->desc->ops->disable) { | 1571 | ret = _regulator_do_disable(rdev); |
1525 | trace_regulator_disable(rdev_get_name(rdev)); | ||
1526 | |||
1527 | ret = rdev->desc->ops->disable(rdev); | ||
1528 | if (ret < 0) { | 1572 | if (ret < 0) { |
1529 | rdev_err(rdev, "failed to disable\n"); | 1573 | rdev_err(rdev, "failed to disable\n"); |
1530 | return ret; | 1574 | return ret; |
1531 | } | 1575 | } |
1532 | |||
1533 | trace_regulator_disable_complete(rdev_get_name(rdev)); | ||
1534 | |||
1535 | _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, | ||
1536 | NULL); | ||
1537 | } | 1576 | } |
1538 | 1577 | ||
1539 | rdev->use_count = 0; | 1578 | rdev->use_count = 0; |
@@ -1751,6 +1790,10 @@ EXPORT_SYMBOL_GPL(regulator_disable_regmap); | |||
1751 | 1790 | ||
1752 | static int _regulator_is_enabled(struct regulator_dev *rdev) | 1791 | static int _regulator_is_enabled(struct regulator_dev *rdev) |
1753 | { | 1792 | { |
1793 | /* A GPIO control always takes precedence */ | ||
1794 | if (rdev->ena_gpio) | ||
1795 | return rdev->ena_gpio_state; | ||
1796 | |||
1754 | /* If we don't know then assume that the regulator is always on */ | 1797 | /* If we don't know then assume that the regulator is always on */ |
1755 | if (!rdev->desc->ops->is_enabled) | 1798 | if (!rdev->desc->ops->is_enabled) |
1756 | return 1; | 1799 | return 1; |
@@ -2019,6 +2062,14 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev, | |||
2019 | { | 2062 | { |
2020 | int ret, voltage; | 2063 | int ret, voltage; |
2021 | 2064 | ||
2065 | /* Allow uV_step to be 0 for fixed voltage */ | ||
2066 | if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) { | ||
2067 | if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV) | ||
2068 | return 0; | ||
2069 | else | ||
2070 | return -EINVAL; | ||
2071 | } | ||
2072 | |||
2022 | if (!rdev->desc->uV_step) { | 2073 | if (!rdev->desc->uV_step) { |
2023 | BUG_ON(!rdev->desc->uV_step); | 2074 | BUG_ON(!rdev->desc->uV_step); |
2024 | return -EINVAL; | 2075 | return -EINVAL; |
@@ -2240,6 +2291,46 @@ int regulator_set_voltage_time(struct regulator *regulator, | |||
2240 | EXPORT_SYMBOL_GPL(regulator_set_voltage_time); | 2291 | EXPORT_SYMBOL_GPL(regulator_set_voltage_time); |
2241 | 2292 | ||
2242 | /** | 2293 | /** |
2294 | *regulator_set_voltage_time_sel - get raise/fall time | ||
2295 | * @regulator: regulator source | ||
2296 | * @old_selector: selector for starting voltage | ||
2297 | * @new_selector: selector for target voltage | ||
2298 | * | ||
2299 | * Provided with the starting and target voltage selectors, this function | ||
2300 | * returns time in microseconds required to rise or fall to this new voltage | ||
2301 | * | ||
2302 | * Drivers providing ramp_delay in regulation_constraints can use this as their | ||
2303 | * set_voltage_time_sel() operation. | ||
2304 | */ | ||
2305 | int regulator_set_voltage_time_sel(struct regulator_dev *rdev, | ||
2306 | unsigned int old_selector, | ||
2307 | unsigned int new_selector) | ||
2308 | { | ||
2309 | unsigned int ramp_delay = 0; | ||
2310 | int old_volt, new_volt; | ||
2311 | |||
2312 | if (rdev->constraints->ramp_delay) | ||
2313 | ramp_delay = rdev->constraints->ramp_delay; | ||
2314 | else if (rdev->desc->ramp_delay) | ||
2315 | ramp_delay = rdev->desc->ramp_delay; | ||
2316 | |||
2317 | if (ramp_delay == 0) { | ||
2318 | rdev_warn(rdev, "ramp_delay not set\n"); | ||
2319 | return 0; | ||
2320 | } | ||
2321 | |||
2322 | /* sanity check */ | ||
2323 | if (!rdev->desc->ops->list_voltage) | ||
2324 | return -EINVAL; | ||
2325 | |||
2326 | old_volt = rdev->desc->ops->list_voltage(rdev, old_selector); | ||
2327 | new_volt = rdev->desc->ops->list_voltage(rdev, new_selector); | ||
2328 | |||
2329 | return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay); | ||
2330 | } | ||
2331 | EXPORT_SYMBOL_GPL(regulator_set_voltage_time_sel); | ||
2332 | |||
2333 | /** | ||
2243 | * regulator_sync_voltage - re-apply last regulator output voltage | 2334 | * regulator_sync_voltage - re-apply last regulator output voltage |
2244 | * @regulator: regulator source | 2335 | * @regulator: regulator source |
2245 | * | 2336 | * |
@@ -2510,9 +2601,12 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
2510 | { | 2601 | { |
2511 | struct regulator_dev *rdev = regulator->rdev; | 2602 | struct regulator_dev *rdev = regulator->rdev; |
2512 | struct regulator *consumer; | 2603 | struct regulator *consumer; |
2513 | int ret, output_uV, input_uV, total_uA_load = 0; | 2604 | int ret, output_uV, input_uV = 0, total_uA_load = 0; |
2514 | unsigned int mode; | 2605 | unsigned int mode; |
2515 | 2606 | ||
2607 | if (rdev->supply) | ||
2608 | input_uV = regulator_get_voltage(rdev->supply); | ||
2609 | |||
2516 | mutex_lock(&rdev->mutex); | 2610 | mutex_lock(&rdev->mutex); |
2517 | 2611 | ||
2518 | /* | 2612 | /* |
@@ -2545,10 +2639,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
2545 | goto out; | 2639 | goto out; |
2546 | } | 2640 | } |
2547 | 2641 | ||
2548 | /* get input voltage */ | 2642 | /* No supply? Use constraint voltage */ |
2549 | input_uV = 0; | ||
2550 | if (rdev->supply) | ||
2551 | input_uV = regulator_get_voltage(rdev->supply); | ||
2552 | if (input_uV <= 0) | 2643 | if (input_uV <= 0) |
2553 | input_uV = rdev->constraints->input_uV; | 2644 | input_uV = rdev->constraints->input_uV; |
2554 | if (input_uV <= 0) { | 2645 | if (input_uV <= 0) { |
@@ -3126,6 +3217,26 @@ regulator_register(const struct regulator_desc *regulator_desc, | |||
3126 | 3217 | ||
3127 | dev_set_drvdata(&rdev->dev, rdev); | 3218 | dev_set_drvdata(&rdev->dev, rdev); |
3128 | 3219 | ||
3220 | if (config->ena_gpio) { | ||
3221 | ret = gpio_request_one(config->ena_gpio, | ||
3222 | GPIOF_DIR_OUT | config->ena_gpio_flags, | ||
3223 | rdev_get_name(rdev)); | ||
3224 | if (ret != 0) { | ||
3225 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", | ||
3226 | config->ena_gpio, ret); | ||
3227 | goto clean; | ||
3228 | } | ||
3229 | |||
3230 | rdev->ena_gpio = config->ena_gpio; | ||
3231 | rdev->ena_gpio_invert = config->ena_gpio_invert; | ||
3232 | |||
3233 | if (config->ena_gpio_flags & GPIOF_OUT_INIT_HIGH) | ||
3234 | rdev->ena_gpio_state = 1; | ||
3235 | |||
3236 | if (rdev->ena_gpio_invert) | ||
3237 | rdev->ena_gpio_state = !rdev->ena_gpio_state; | ||
3238 | } | ||
3239 | |||
3129 | /* set regulator constraints */ | 3240 | /* set regulator constraints */ |
3130 | if (init_data) | 3241 | if (init_data) |
3131 | constraints = &init_data->constraints; | 3242 | constraints = &init_data->constraints; |
@@ -3194,6 +3305,8 @@ unset_supplies: | |||
3194 | scrub: | 3305 | scrub: |
3195 | if (rdev->supply) | 3306 | if (rdev->supply) |
3196 | regulator_put(rdev->supply); | 3307 | regulator_put(rdev->supply); |
3308 | if (rdev->ena_gpio) | ||
3309 | gpio_free(rdev->ena_gpio); | ||
3197 | kfree(rdev->constraints); | 3310 | kfree(rdev->constraints); |
3198 | device_unregister(&rdev->dev); | 3311 | device_unregister(&rdev->dev); |
3199 | /* device core frees rdev */ | 3312 | /* device core frees rdev */ |
@@ -3227,6 +3340,8 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
3227 | unset_regulator_supplies(rdev); | 3340 | unset_regulator_supplies(rdev); |
3228 | list_del(&rdev->list); | 3341 | list_del(&rdev->list); |
3229 | kfree(rdev->constraints); | 3342 | kfree(rdev->constraints); |
3343 | if (rdev->ena_gpio) | ||
3344 | gpio_free(rdev->ena_gpio); | ||
3230 | device_unregister(&rdev->dev); | 3345 | device_unregister(&rdev->dev); |
3231 | mutex_unlock(®ulator_list_mutex); | 3346 | mutex_unlock(®ulator_list_mutex); |
3232 | } | 3347 | } |
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index 1005f5f7e603..36c5b92fe0af 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c | |||
@@ -107,6 +107,9 @@ static int da903x_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) | |||
107 | struct device *da9034_dev = to_da903x_dev(rdev); | 107 | struct device *da9034_dev = to_da903x_dev(rdev); |
108 | uint8_t val, mask; | 108 | uint8_t val, mask; |
109 | 109 | ||
110 | if (rdev->desc->n_voltages == 1) | ||
111 | return -EINVAL; | ||
112 | |||
110 | val = selector << info->vol_shift; | 113 | val = selector << info->vol_shift; |
111 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 114 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
112 | 115 | ||
@@ -120,6 +123,9 @@ static int da903x_get_voltage_sel(struct regulator_dev *rdev) | |||
120 | uint8_t val, mask; | 123 | uint8_t val, mask; |
121 | int ret; | 124 | int ret; |
122 | 125 | ||
126 | if (rdev->desc->n_voltages == 1) | ||
127 | return 0; | ||
128 | |||
123 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | 129 | ret = da903x_read(da9034_dev, info->vol_reg, &val); |
124 | if (ret) | 130 | if (ret) |
125 | return ret; | 131 | return ret; |
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index 88976d8d44ed..903299cf15cf 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c | |||
@@ -405,12 +405,12 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev) | |||
405 | if (!nproot) | 405 | if (!nproot) |
406 | return -ENODEV; | 406 | return -ENODEV; |
407 | 407 | ||
408 | for (np = of_get_next_child(nproot, NULL); np; | 408 | for_each_child_of_node(nproot, np) { |
409 | np = of_get_next_child(nproot, np)) { | ||
410 | if (!of_node_cmp(np->name, | 409 | if (!of_node_cmp(np->name, |
411 | regulator->info->reg_desc.name)) { | 410 | regulator->info->reg_desc.name)) { |
412 | config.init_data = of_get_regulator_init_data( | 411 | config.init_data = of_get_regulator_init_data( |
413 | &pdev->dev, np); | 412 | &pdev->dev, np); |
413 | config.of_node = np; | ||
414 | break; | 414 | break; |
415 | } | 415 | } |
416 | } | 416 | } |
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index f09fe7b20e82..185468c4d38f 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c | |||
@@ -35,10 +35,6 @@ struct fixed_voltage_data { | |||
35 | struct regulator_desc desc; | 35 | struct regulator_desc desc; |
36 | struct regulator_dev *dev; | 36 | struct regulator_dev *dev; |
37 | int microvolts; | 37 | int microvolts; |
38 | int gpio; | ||
39 | unsigned startup_delay; | ||
40 | bool enable_high; | ||
41 | bool is_enabled; | ||
42 | }; | 38 | }; |
43 | 39 | ||
44 | 40 | ||
@@ -61,11 +57,11 @@ of_get_fixed_voltage_config(struct device *dev) | |||
61 | config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), | 57 | config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), |
62 | GFP_KERNEL); | 58 | GFP_KERNEL); |
63 | if (!config) | 59 | if (!config) |
64 | return NULL; | 60 | return ERR_PTR(-ENOMEM); |
65 | 61 | ||
66 | config->init_data = of_get_regulator_init_data(dev, dev->of_node); | 62 | config->init_data = of_get_regulator_init_data(dev, dev->of_node); |
67 | if (!config->init_data) | 63 | if (!config->init_data) |
68 | return NULL; | 64 | return ERR_PTR(-EINVAL); |
69 | 65 | ||
70 | init_data = config->init_data; | 66 | init_data = config->init_data; |
71 | init_data->constraints.apply_uV = 0; | 67 | init_data->constraints.apply_uV = 0; |
@@ -76,13 +72,26 @@ of_get_fixed_voltage_config(struct device *dev) | |||
76 | } else { | 72 | } else { |
77 | dev_err(dev, | 73 | dev_err(dev, |
78 | "Fixed regulator specified with variable voltages\n"); | 74 | "Fixed regulator specified with variable voltages\n"); |
79 | return NULL; | 75 | return ERR_PTR(-EINVAL); |
80 | } | 76 | } |
81 | 77 | ||
82 | if (init_data->constraints.boot_on) | 78 | if (init_data->constraints.boot_on) |
83 | config->enabled_at_boot = true; | 79 | config->enabled_at_boot = true; |
84 | 80 | ||
85 | config->gpio = of_get_named_gpio(np, "gpio", 0); | 81 | config->gpio = of_get_named_gpio(np, "gpio", 0); |
82 | /* | ||
83 | * of_get_named_gpio() currently returns ENODEV rather than | ||
84 | * EPROBE_DEFER. This code attempts to be compatible with both | ||
85 | * for now; the ENODEV check can be removed once the API is fixed. | ||
86 | * of_get_named_gpio() doesn't differentiate between a missing | ||
87 | * property (which would be fine here, since the GPIO is optional) | ||
88 | * and some other error. Patches have been posted for both issues. | ||
89 | * Once they are check in, we should replace this with: | ||
90 | * if (config->gpio < 0 && config->gpio != -ENOENT) | ||
91 | */ | ||
92 | if ((config->gpio == -ENODEV) || (config->gpio == -EPROBE_DEFER)) | ||
93 | return ERR_PTR(-EPROBE_DEFER); | ||
94 | |||
86 | delay = of_get_property(np, "startup-delay-us", NULL); | 95 | delay = of_get_property(np, "startup-delay-us", NULL); |
87 | if (delay) | 96 | if (delay) |
88 | config->startup_delay = be32_to_cpu(*delay); | 97 | config->startup_delay = be32_to_cpu(*delay); |
@@ -93,41 +102,10 @@ of_get_fixed_voltage_config(struct device *dev) | |||
93 | if (of_find_property(np, "gpio-open-drain", NULL)) | 102 | if (of_find_property(np, "gpio-open-drain", NULL)) |
94 | config->gpio_is_open_drain = true; | 103 | config->gpio_is_open_drain = true; |
95 | 104 | ||
96 | return config; | 105 | if (of_find_property(np, "vin-supply", NULL)) |
97 | } | 106 | config->input_supply = "vin"; |
98 | |||
99 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | ||
100 | { | ||
101 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
102 | |||
103 | return data->is_enabled; | ||
104 | } | ||
105 | |||
106 | static int fixed_voltage_enable(struct regulator_dev *dev) | ||
107 | { | ||
108 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
109 | |||
110 | gpio_set_value_cansleep(data->gpio, data->enable_high); | ||
111 | data->is_enabled = true; | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | static int fixed_voltage_disable(struct regulator_dev *dev) | ||
117 | { | ||
118 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
119 | |||
120 | gpio_set_value_cansleep(data->gpio, !data->enable_high); | ||
121 | data->is_enabled = false; | ||
122 | |||
123 | return 0; | ||
124 | } | ||
125 | 107 | ||
126 | static int fixed_voltage_enable_time(struct regulator_dev *dev) | 108 | return config; |
127 | { | ||
128 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
129 | |||
130 | return data->startup_delay; | ||
131 | } | 109 | } |
132 | 110 | ||
133 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) | 111 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) |
@@ -151,15 +129,6 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev, | |||
151 | return data->microvolts; | 129 | return data->microvolts; |
152 | } | 130 | } |
153 | 131 | ||
154 | static struct regulator_ops fixed_voltage_gpio_ops = { | ||
155 | .is_enabled = fixed_voltage_is_enabled, | ||
156 | .enable = fixed_voltage_enable, | ||
157 | .disable = fixed_voltage_disable, | ||
158 | .enable_time = fixed_voltage_enable_time, | ||
159 | .get_voltage = fixed_voltage_get_voltage, | ||
160 | .list_voltage = fixed_voltage_list_voltage, | ||
161 | }; | ||
162 | |||
163 | static struct regulator_ops fixed_voltage_ops = { | 132 | static struct regulator_ops fixed_voltage_ops = { |
164 | .get_voltage = fixed_voltage_get_voltage, | 133 | .get_voltage = fixed_voltage_get_voltage, |
165 | .list_voltage = fixed_voltage_list_voltage, | 134 | .list_voltage = fixed_voltage_list_voltage, |
@@ -172,10 +141,13 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
172 | struct regulator_config cfg = { }; | 141 | struct regulator_config cfg = { }; |
173 | int ret; | 142 | int ret; |
174 | 143 | ||
175 | if (pdev->dev.of_node) | 144 | if (pdev->dev.of_node) { |
176 | config = of_get_fixed_voltage_config(&pdev->dev); | 145 | config = of_get_fixed_voltage_config(&pdev->dev); |
177 | else | 146 | if (IS_ERR(config)) |
147 | return PTR_ERR(config); | ||
148 | } else { | ||
178 | config = pdev->dev.platform_data; | 149 | config = pdev->dev.platform_data; |
150 | } | ||
179 | 151 | ||
180 | if (!config) | 152 | if (!config) |
181 | return -ENOMEM; | 153 | return -ENOMEM; |
@@ -196,59 +168,44 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
196 | } | 168 | } |
197 | drvdata->desc.type = REGULATOR_VOLTAGE; | 169 | drvdata->desc.type = REGULATOR_VOLTAGE; |
198 | drvdata->desc.owner = THIS_MODULE; | 170 | drvdata->desc.owner = THIS_MODULE; |
171 | drvdata->desc.ops = &fixed_voltage_ops; | ||
199 | 172 | ||
200 | if (config->microvolts) | 173 | drvdata->desc.enable_time = config->startup_delay; |
201 | drvdata->desc.n_voltages = 1; | ||
202 | 174 | ||
203 | drvdata->microvolts = config->microvolts; | 175 | if (config->input_supply) { |
204 | drvdata->gpio = config->gpio; | 176 | drvdata->desc.supply_name = kstrdup(config->input_supply, |
205 | drvdata->startup_delay = config->startup_delay; | 177 | GFP_KERNEL); |
206 | 178 | if (!drvdata->desc.supply_name) { | |
207 | if (gpio_is_valid(config->gpio)) { | ||
208 | int gpio_flag; | ||
209 | drvdata->enable_high = config->enable_high; | ||
210 | |||
211 | /* FIXME: Remove below print warning | ||
212 | * | ||
213 | * config->gpio must be set to -EINVAL by platform code if | ||
214 | * GPIO control is not required. However, early adopters | ||
215 | * not requiring GPIO control may forget to initialize | ||
216 | * config->gpio to -EINVAL. This will cause GPIO 0 to be used | ||
217 | * for GPIO control. | ||
218 | * | ||
219 | * This warning will be removed once there are a couple of users | ||
220 | * for this driver. | ||
221 | */ | ||
222 | if (!config->gpio) | ||
223 | dev_warn(&pdev->dev, | ||
224 | "using GPIO 0 for regulator enable control\n"); | ||
225 | |||
226 | /* | ||
227 | * set output direction without changing state | ||
228 | * to prevent glitch | ||
229 | */ | ||
230 | drvdata->is_enabled = config->enabled_at_boot; | ||
231 | ret = drvdata->is_enabled ? | ||
232 | config->enable_high : !config->enable_high; | ||
233 | gpio_flag = ret ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
234 | |||
235 | if (config->gpio_is_open_drain) | ||
236 | gpio_flag |= GPIOF_OPEN_DRAIN; | ||
237 | |||
238 | ret = gpio_request_one(config->gpio, gpio_flag, | ||
239 | config->supply_name); | ||
240 | if (ret) { | ||
241 | dev_err(&pdev->dev, | 179 | dev_err(&pdev->dev, |
242 | "Could not obtain regulator enable GPIO %d: %d\n", | 180 | "Failed to allocate input supply\n"); |
243 | config->gpio, ret); | 181 | ret = -ENOMEM; |
244 | goto err_name; | 182 | goto err_name; |
245 | } | 183 | } |
184 | } | ||
185 | |||
186 | if (config->microvolts) | ||
187 | drvdata->desc.n_voltages = 1; | ||
246 | 188 | ||
247 | drvdata->desc.ops = &fixed_voltage_gpio_ops; | 189 | drvdata->microvolts = config->microvolts; |
248 | 190 | ||
191 | if (config->gpio >= 0) | ||
192 | cfg.ena_gpio = config->gpio; | ||
193 | cfg.ena_gpio_invert = !config->enable_high; | ||
194 | if (config->enabled_at_boot) { | ||
195 | if (config->enable_high) { | ||
196 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | ||
197 | } else { | ||
198 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | ||
199 | } | ||
249 | } else { | 200 | } else { |
250 | drvdata->desc.ops = &fixed_voltage_ops; | 201 | if (config->enable_high) { |
202 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | ||
203 | } else { | ||
204 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | ||
205 | } | ||
251 | } | 206 | } |
207 | if (config->gpio_is_open_drain) | ||
208 | cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN; | ||
252 | 209 | ||
253 | cfg.dev = &pdev->dev; | 210 | cfg.dev = &pdev->dev; |
254 | cfg.init_data = config->init_data; | 211 | cfg.init_data = config->init_data; |
@@ -259,7 +216,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
259 | if (IS_ERR(drvdata->dev)) { | 216 | if (IS_ERR(drvdata->dev)) { |
260 | ret = PTR_ERR(drvdata->dev); | 217 | ret = PTR_ERR(drvdata->dev); |
261 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); | 218 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); |
262 | goto err_gpio; | 219 | goto err_input; |
263 | } | 220 | } |
264 | 221 | ||
265 | platform_set_drvdata(pdev, drvdata); | 222 | platform_set_drvdata(pdev, drvdata); |
@@ -269,9 +226,8 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
269 | 226 | ||
270 | return 0; | 227 | return 0; |
271 | 228 | ||
272 | err_gpio: | 229 | err_input: |
273 | if (gpio_is_valid(config->gpio)) | 230 | kfree(drvdata->desc.supply_name); |
274 | gpio_free(config->gpio); | ||
275 | err_name: | 231 | err_name: |
276 | kfree(drvdata->desc.name); | 232 | kfree(drvdata->desc.name); |
277 | err: | 233 | err: |
@@ -283,8 +239,7 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev) | |||
283 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); | 239 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); |
284 | 240 | ||
285 | regulator_unregister(drvdata->dev); | 241 | regulator_unregister(drvdata->dev); |
286 | if (gpio_is_valid(drvdata->gpio)) | 242 | kfree(drvdata->desc.supply_name); |
287 | gpio_free(drvdata->gpio); | ||
288 | kfree(drvdata->desc.name); | 243 | kfree(drvdata->desc.name); |
289 | 244 | ||
290 | return 0; | 245 | return 0; |
@@ -296,8 +251,6 @@ static const struct of_device_id fixed_of_match[] __devinitconst = { | |||
296 | {}, | 251 | {}, |
297 | }; | 252 | }; |
298 | MODULE_DEVICE_TABLE(of, fixed_of_match); | 253 | MODULE_DEVICE_TABLE(of, fixed_of_match); |
299 | #else | ||
300 | #define fixed_of_match NULL | ||
301 | #endif | 254 | #endif |
302 | 255 | ||
303 | static struct platform_driver regulator_fixed_voltage_driver = { | 256 | static struct platform_driver regulator_fixed_voltage_driver = { |
@@ -306,7 +259,7 @@ static struct platform_driver regulator_fixed_voltage_driver = { | |||
306 | .driver = { | 259 | .driver = { |
307 | .name = "reg-fixed-voltage", | 260 | .name = "reg-fixed-voltage", |
308 | .owner = THIS_MODULE, | 261 | .owner = THIS_MODULE, |
309 | .of_match_table = fixed_of_match, | 262 | .of_match_table = of_match_ptr(fixed_of_match), |
310 | }, | 263 | }, |
311 | }; | 264 | }; |
312 | 265 | ||
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 242851a4c1a6..34b67bee9323 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -36,11 +36,6 @@ struct gpio_regulator_data { | |||
36 | struct regulator_desc desc; | 36 | struct regulator_desc desc; |
37 | struct regulator_dev *dev; | 37 | struct regulator_dev *dev; |
38 | 38 | ||
39 | int enable_gpio; | ||
40 | bool enable_high; | ||
41 | bool is_enabled; | ||
42 | unsigned startup_delay; | ||
43 | |||
44 | struct gpio *gpios; | 39 | struct gpio *gpios; |
45 | int nr_gpios; | 40 | int nr_gpios; |
46 | 41 | ||
@@ -50,44 +45,6 @@ struct gpio_regulator_data { | |||
50 | int state; | 45 | int state; |
51 | }; | 46 | }; |
52 | 47 | ||
53 | static int gpio_regulator_is_enabled(struct regulator_dev *dev) | ||
54 | { | ||
55 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | ||
56 | |||
57 | return data->is_enabled; | ||
58 | } | ||
59 | |||
60 | static int gpio_regulator_enable(struct regulator_dev *dev) | ||
61 | { | ||
62 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | ||
63 | |||
64 | if (gpio_is_valid(data->enable_gpio)) { | ||
65 | gpio_set_value_cansleep(data->enable_gpio, data->enable_high); | ||
66 | data->is_enabled = true; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int gpio_regulator_disable(struct regulator_dev *dev) | ||
73 | { | ||
74 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | ||
75 | |||
76 | if (gpio_is_valid(data->enable_gpio)) { | ||
77 | gpio_set_value_cansleep(data->enable_gpio, !data->enable_high); | ||
78 | data->is_enabled = false; | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int gpio_regulator_enable_time(struct regulator_dev *dev) | ||
85 | { | ||
86 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | ||
87 | |||
88 | return data->startup_delay; | ||
89 | } | ||
90 | |||
91 | static int gpio_regulator_get_value(struct regulator_dev *dev) | 48 | static int gpio_regulator_get_value(struct regulator_dev *dev) |
92 | { | 49 | { |
93 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | 50 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); |
@@ -153,20 +110,12 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev, | |||
153 | } | 110 | } |
154 | 111 | ||
155 | static struct regulator_ops gpio_regulator_voltage_ops = { | 112 | static struct regulator_ops gpio_regulator_voltage_ops = { |
156 | .is_enabled = gpio_regulator_is_enabled, | ||
157 | .enable = gpio_regulator_enable, | ||
158 | .disable = gpio_regulator_disable, | ||
159 | .enable_time = gpio_regulator_enable_time, | ||
160 | .get_voltage = gpio_regulator_get_value, | 113 | .get_voltage = gpio_regulator_get_value, |
161 | .set_voltage = gpio_regulator_set_voltage, | 114 | .set_voltage = gpio_regulator_set_voltage, |
162 | .list_voltage = gpio_regulator_list_voltage, | 115 | .list_voltage = gpio_regulator_list_voltage, |
163 | }; | 116 | }; |
164 | 117 | ||
165 | static struct regulator_ops gpio_regulator_current_ops = { | 118 | static struct regulator_ops gpio_regulator_current_ops = { |
166 | .is_enabled = gpio_regulator_is_enabled, | ||
167 | .enable = gpio_regulator_enable, | ||
168 | .disable = gpio_regulator_disable, | ||
169 | .enable_time = gpio_regulator_enable_time, | ||
170 | .get_current_limit = gpio_regulator_get_value, | 119 | .get_current_limit = gpio_regulator_get_value, |
171 | .set_current_limit = gpio_regulator_set_current_limit, | 120 | .set_current_limit = gpio_regulator_set_current_limit, |
172 | }; | 121 | }; |
@@ -213,6 +162,7 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
213 | drvdata->nr_states = config->nr_states; | 162 | drvdata->nr_states = config->nr_states; |
214 | 163 | ||
215 | drvdata->desc.owner = THIS_MODULE; | 164 | drvdata->desc.owner = THIS_MODULE; |
165 | drvdata->desc.enable_time = config->startup_delay; | ||
216 | 166 | ||
217 | /* handle regulator type*/ | 167 | /* handle regulator type*/ |
218 | switch (config->type) { | 168 | switch (config->type) { |
@@ -232,52 +182,12 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
232 | break; | 182 | break; |
233 | } | 183 | } |
234 | 184 | ||
235 | drvdata->enable_gpio = config->enable_gpio; | ||
236 | drvdata->startup_delay = config->startup_delay; | ||
237 | |||
238 | if (gpio_is_valid(config->enable_gpio)) { | ||
239 | drvdata->enable_high = config->enable_high; | ||
240 | |||
241 | ret = gpio_request(config->enable_gpio, config->supply_name); | ||
242 | if (ret) { | ||
243 | dev_err(&pdev->dev, | ||
244 | "Could not obtain regulator enable GPIO %d: %d\n", | ||
245 | config->enable_gpio, ret); | ||
246 | goto err_memstate; | ||
247 | } | ||
248 | |||
249 | /* set output direction without changing state | ||
250 | * to prevent glitch | ||
251 | */ | ||
252 | if (config->enabled_at_boot) { | ||
253 | drvdata->is_enabled = true; | ||
254 | ret = gpio_direction_output(config->enable_gpio, | ||
255 | config->enable_high); | ||
256 | } else { | ||
257 | drvdata->is_enabled = false; | ||
258 | ret = gpio_direction_output(config->enable_gpio, | ||
259 | !config->enable_high); | ||
260 | } | ||
261 | |||
262 | if (ret) { | ||
263 | dev_err(&pdev->dev, | ||
264 | "Could not configure regulator enable GPIO %d direction: %d\n", | ||
265 | config->enable_gpio, ret); | ||
266 | goto err_enablegpio; | ||
267 | } | ||
268 | } else { | ||
269 | /* Regulator without GPIO control is considered | ||
270 | * always enabled | ||
271 | */ | ||
272 | drvdata->is_enabled = true; | ||
273 | } | ||
274 | |||
275 | drvdata->nr_gpios = config->nr_gpios; | 185 | drvdata->nr_gpios = config->nr_gpios; |
276 | ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); | 186 | ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); |
277 | if (ret) { | 187 | if (ret) { |
278 | dev_err(&pdev->dev, | 188 | dev_err(&pdev->dev, |
279 | "Could not obtain regulator setting GPIOs: %d\n", ret); | 189 | "Could not obtain regulator setting GPIOs: %d\n", ret); |
280 | goto err_enablegpio; | 190 | goto err_memstate; |
281 | } | 191 | } |
282 | 192 | ||
283 | /* build initial state from gpio init data. */ | 193 | /* build initial state from gpio init data. */ |
@@ -292,6 +202,21 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
292 | cfg.init_data = config->init_data; | 202 | cfg.init_data = config->init_data; |
293 | cfg.driver_data = drvdata; | 203 | cfg.driver_data = drvdata; |
294 | 204 | ||
205 | if (config->enable_gpio >= 0) | ||
206 | cfg.ena_gpio = config->enable_gpio; | ||
207 | cfg.ena_gpio_invert = !config->enable_high; | ||
208 | if (config->enabled_at_boot) { | ||
209 | if (config->enable_high) | ||
210 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | ||
211 | else | ||
212 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | ||
213 | } else { | ||
214 | if (config->enable_high) | ||
215 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; | ||
216 | else | ||
217 | cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | ||
218 | } | ||
219 | |||
295 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); | 220 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); |
296 | if (IS_ERR(drvdata->dev)) { | 221 | if (IS_ERR(drvdata->dev)) { |
297 | ret = PTR_ERR(drvdata->dev); | 222 | ret = PTR_ERR(drvdata->dev); |
@@ -305,9 +230,6 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
305 | 230 | ||
306 | err_stategpio: | 231 | err_stategpio: |
307 | gpio_free_array(drvdata->gpios, drvdata->nr_gpios); | 232 | gpio_free_array(drvdata->gpios, drvdata->nr_gpios); |
308 | err_enablegpio: | ||
309 | if (gpio_is_valid(config->enable_gpio)) | ||
310 | gpio_free(config->enable_gpio); | ||
311 | err_memstate: | 233 | err_memstate: |
312 | kfree(drvdata->states); | 234 | kfree(drvdata->states); |
313 | err_memgpio: | 235 | err_memgpio: |
@@ -329,9 +251,6 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev) | |||
329 | kfree(drvdata->states); | 251 | kfree(drvdata->states); |
330 | kfree(drvdata->gpios); | 252 | kfree(drvdata->gpios); |
331 | 253 | ||
332 | if (gpio_is_valid(drvdata->enable_gpio)) | ||
333 | gpio_free(drvdata->enable_gpio); | ||
334 | |||
335 | kfree(drvdata->desc.name); | 254 | kfree(drvdata->desc.name); |
336 | 255 | ||
337 | return 0; | 256 | return 0; |
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index 56d273f25603..1d145a07ada9 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c | |||
@@ -75,19 +75,12 @@ static struct regulator_ops isl_core_ops = { | |||
75 | 75 | ||
76 | static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) | 76 | static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) |
77 | { | 77 | { |
78 | int id = rdev_get_id(dev); | 78 | return dev->desc->min_uV; |
79 | return (id == 1) ? 1100000 : 1300000; | ||
80 | } | ||
81 | |||
82 | static int isl6271a_list_fixed_voltage(struct regulator_dev *dev, unsigned selector) | ||
83 | { | ||
84 | int id = rdev_get_id(dev); | ||
85 | return (id == 1) ? 1100000 : 1300000; | ||
86 | } | 79 | } |
87 | 80 | ||
88 | static struct regulator_ops isl_fixed_ops = { | 81 | static struct regulator_ops isl_fixed_ops = { |
89 | .get_voltage = isl6271a_get_fixed_voltage, | 82 | .get_voltage = isl6271a_get_fixed_voltage, |
90 | .list_voltage = isl6271a_list_fixed_voltage, | 83 | .list_voltage = regulator_list_voltage_linear, |
91 | }; | 84 | }; |
92 | 85 | ||
93 | static const struct regulator_desc isl_rd[] = { | 86 | static const struct regulator_desc isl_rd[] = { |
@@ -107,6 +100,7 @@ static const struct regulator_desc isl_rd[] = { | |||
107 | .ops = &isl_fixed_ops, | 100 | .ops = &isl_fixed_ops, |
108 | .type = REGULATOR_VOLTAGE, | 101 | .type = REGULATOR_VOLTAGE, |
109 | .owner = THIS_MODULE, | 102 | .owner = THIS_MODULE, |
103 | .min_uV = 1100000, | ||
110 | }, { | 104 | }, { |
111 | .name = "LDO2", | 105 | .name = "LDO2", |
112 | .id = 2, | 106 | .id = 2, |
@@ -114,6 +108,7 @@ static const struct regulator_desc isl_rd[] = { | |||
114 | .ops = &isl_fixed_ops, | 108 | .ops = &isl_fixed_ops, |
115 | .type = REGULATOR_VOLTAGE, | 109 | .type = REGULATOR_VOLTAGE, |
116 | .owner = THIS_MODULE, | 110 | .owner = THIS_MODULE, |
111 | .min_uV = 1300000, | ||
117 | }, | 112 | }, |
118 | }; | 113 | }; |
119 | 114 | ||
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 981bea9cb9d7..7c6e3b8ff484 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c | |||
@@ -65,11 +65,11 @@ static const int buck_base_addr[] = { | |||
65 | #define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) | 65 | #define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) |
66 | #define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) | 66 | #define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) |
67 | 67 | ||
68 | static const int buck_voltage_map[] = { | 68 | static const unsigned int buck_voltage_map[] = { |
69 | 0, 800, 850, 900, 950, 1000, 1050, 1100, | 69 | 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, |
70 | 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, | 70 | 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, |
71 | 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, | 71 | 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000, |
72 | 3000, 3300, | 72 | 3000000, 3300000, |
73 | }; | 73 | }; |
74 | 74 | ||
75 | #define BUCK_TARGET_VOL_MASK 0x3f | 75 | #define BUCK_TARGET_VOL_MASK 0x3f |
@@ -98,39 +98,19 @@ static const int buck_voltage_map[] = { | |||
98 | #define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) | 98 | #define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) |
99 | #define LDO_VOL_CONTR_MASK 0x0f | 99 | #define LDO_VOL_CONTR_MASK 0x0f |
100 | 100 | ||
101 | static const int ldo45_voltage_map[] = { | 101 | static const unsigned int ldo45_voltage_map[] = { |
102 | 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, | 102 | 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, |
103 | 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, | 103 | 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static const int ldo123_voltage_map[] = { | 106 | static const unsigned int ldo123_voltage_map[] = { |
107 | 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, | 107 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, |
108 | 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, | 108 | 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, |
109 | }; | 109 | }; |
110 | 110 | ||
111 | static const int *ldo_voltage_map[] = { | ||
112 | ldo123_voltage_map, /* LDO1 */ | ||
113 | ldo123_voltage_map, /* LDO2 */ | ||
114 | ldo123_voltage_map, /* LDO3 */ | ||
115 | ldo45_voltage_map, /* LDO4 */ | ||
116 | ldo45_voltage_map, /* LDO5 */ | ||
117 | }; | ||
118 | |||
119 | #define LDO_VOL_VALUE_MAP(x) (ldo_voltage_map[(x - LP3971_LDO1)]) | ||
120 | |||
121 | #define LDO_VOL_MIN_IDX 0x00 | 111 | #define LDO_VOL_MIN_IDX 0x00 |
122 | #define LDO_VOL_MAX_IDX 0x0f | 112 | #define LDO_VOL_MAX_IDX 0x0f |
123 | 113 | ||
124 | static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | ||
125 | { | ||
126 | int ldo = rdev_get_id(dev) - LP3971_LDO1; | ||
127 | |||
128 | if (index > LDO_VOL_MAX_IDX) | ||
129 | return -EINVAL; | ||
130 | |||
131 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[index]; | ||
132 | } | ||
133 | |||
134 | static int lp3971_ldo_is_enabled(struct regulator_dev *dev) | 114 | static int lp3971_ldo_is_enabled(struct regulator_dev *dev) |
135 | { | 115 | { |
136 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 116 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
@@ -169,7 +149,7 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev) | |||
169 | reg = lp3971_reg_read(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo)); | 149 | reg = lp3971_reg_read(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo)); |
170 | val = (reg >> LDO_VOL_CONTR_SHIFT(ldo)) & LDO_VOL_CONTR_MASK; | 150 | val = (reg >> LDO_VOL_CONTR_SHIFT(ldo)) & LDO_VOL_CONTR_MASK; |
171 | 151 | ||
172 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; | 152 | return dev->desc->volt_table[val]; |
173 | } | 153 | } |
174 | 154 | ||
175 | static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, | 155 | static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, |
@@ -184,7 +164,7 @@ static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, | |||
184 | } | 164 | } |
185 | 165 | ||
186 | static struct regulator_ops lp3971_ldo_ops = { | 166 | static struct regulator_ops lp3971_ldo_ops = { |
187 | .list_voltage = lp3971_ldo_list_voltage, | 167 | .list_voltage = regulator_list_voltage_table, |
188 | .is_enabled = lp3971_ldo_is_enabled, | 168 | .is_enabled = lp3971_ldo_is_enabled, |
189 | .enable = lp3971_ldo_enable, | 169 | .enable = lp3971_ldo_enable, |
190 | .disable = lp3971_ldo_disable, | 170 | .disable = lp3971_ldo_disable, |
@@ -192,14 +172,6 @@ static struct regulator_ops lp3971_ldo_ops = { | |||
192 | .set_voltage_sel = lp3971_ldo_set_voltage_sel, | 172 | .set_voltage_sel = lp3971_ldo_set_voltage_sel, |
193 | }; | 173 | }; |
194 | 174 | ||
195 | static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | ||
196 | { | ||
197 | if (index < BUCK_TARGET_VOL_MIN_IDX || index > BUCK_TARGET_VOL_MAX_IDX) | ||
198 | return -EINVAL; | ||
199 | |||
200 | return 1000 * buck_voltage_map[index]; | ||
201 | } | ||
202 | |||
203 | static int lp3971_dcdc_is_enabled(struct regulator_dev *dev) | 175 | static int lp3971_dcdc_is_enabled(struct regulator_dev *dev) |
204 | { | 176 | { |
205 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 177 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
@@ -240,7 +212,7 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev) | |||
240 | reg &= BUCK_TARGET_VOL_MASK; | 212 | reg &= BUCK_TARGET_VOL_MASK; |
241 | 213 | ||
242 | if (reg <= BUCK_TARGET_VOL_MAX_IDX) | 214 | if (reg <= BUCK_TARGET_VOL_MAX_IDX) |
243 | val = 1000 * buck_voltage_map[reg]; | 215 | val = buck_voltage_map[reg]; |
244 | else { | 216 | else { |
245 | val = 0; | 217 | val = 0; |
246 | dev_warn(&dev->dev, "chip reported incorrect voltage value.\n"); | 218 | dev_warn(&dev->dev, "chip reported incorrect voltage value.\n"); |
@@ -273,7 +245,7 @@ static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev, | |||
273 | } | 245 | } |
274 | 246 | ||
275 | static struct regulator_ops lp3971_dcdc_ops = { | 247 | static struct regulator_ops lp3971_dcdc_ops = { |
276 | .list_voltage = lp3971_dcdc_list_voltage, | 248 | .list_voltage = regulator_list_voltage_table, |
277 | .is_enabled = lp3971_dcdc_is_enabled, | 249 | .is_enabled = lp3971_dcdc_is_enabled, |
278 | .enable = lp3971_dcdc_enable, | 250 | .enable = lp3971_dcdc_enable, |
279 | .disable = lp3971_dcdc_disable, | 251 | .disable = lp3971_dcdc_disable, |
@@ -287,6 +259,7 @@ static const struct regulator_desc regulators[] = { | |||
287 | .id = LP3971_LDO1, | 259 | .id = LP3971_LDO1, |
288 | .ops = &lp3971_ldo_ops, | 260 | .ops = &lp3971_ldo_ops, |
289 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), | 261 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), |
262 | .volt_table = ldo123_voltage_map, | ||
290 | .type = REGULATOR_VOLTAGE, | 263 | .type = REGULATOR_VOLTAGE, |
291 | .owner = THIS_MODULE, | 264 | .owner = THIS_MODULE, |
292 | }, | 265 | }, |
@@ -295,6 +268,7 @@ static const struct regulator_desc regulators[] = { | |||
295 | .id = LP3971_LDO2, | 268 | .id = LP3971_LDO2, |
296 | .ops = &lp3971_ldo_ops, | 269 | .ops = &lp3971_ldo_ops, |
297 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), | 270 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), |
271 | .volt_table = ldo123_voltage_map, | ||
298 | .type = REGULATOR_VOLTAGE, | 272 | .type = REGULATOR_VOLTAGE, |
299 | .owner = THIS_MODULE, | 273 | .owner = THIS_MODULE, |
300 | }, | 274 | }, |
@@ -303,6 +277,7 @@ static const struct regulator_desc regulators[] = { | |||
303 | .id = LP3971_LDO3, | 277 | .id = LP3971_LDO3, |
304 | .ops = &lp3971_ldo_ops, | 278 | .ops = &lp3971_ldo_ops, |
305 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), | 279 | .n_voltages = ARRAY_SIZE(ldo123_voltage_map), |
280 | .volt_table = ldo123_voltage_map, | ||
306 | .type = REGULATOR_VOLTAGE, | 281 | .type = REGULATOR_VOLTAGE, |
307 | .owner = THIS_MODULE, | 282 | .owner = THIS_MODULE, |
308 | }, | 283 | }, |
@@ -311,6 +286,7 @@ static const struct regulator_desc regulators[] = { | |||
311 | .id = LP3971_LDO4, | 286 | .id = LP3971_LDO4, |
312 | .ops = &lp3971_ldo_ops, | 287 | .ops = &lp3971_ldo_ops, |
313 | .n_voltages = ARRAY_SIZE(ldo45_voltage_map), | 288 | .n_voltages = ARRAY_SIZE(ldo45_voltage_map), |
289 | .volt_table = ldo45_voltage_map, | ||
314 | .type = REGULATOR_VOLTAGE, | 290 | .type = REGULATOR_VOLTAGE, |
315 | .owner = THIS_MODULE, | 291 | .owner = THIS_MODULE, |
316 | }, | 292 | }, |
@@ -319,6 +295,7 @@ static const struct regulator_desc regulators[] = { | |||
319 | .id = LP3971_LDO5, | 295 | .id = LP3971_LDO5, |
320 | .ops = &lp3971_ldo_ops, | 296 | .ops = &lp3971_ldo_ops, |
321 | .n_voltages = ARRAY_SIZE(ldo45_voltage_map), | 297 | .n_voltages = ARRAY_SIZE(ldo45_voltage_map), |
298 | .volt_table = ldo45_voltage_map, | ||
322 | .type = REGULATOR_VOLTAGE, | 299 | .type = REGULATOR_VOLTAGE, |
323 | .owner = THIS_MODULE, | 300 | .owner = THIS_MODULE, |
324 | }, | 301 | }, |
@@ -327,6 +304,7 @@ static const struct regulator_desc regulators[] = { | |||
327 | .id = LP3971_DCDC1, | 304 | .id = LP3971_DCDC1, |
328 | .ops = &lp3971_dcdc_ops, | 305 | .ops = &lp3971_dcdc_ops, |
329 | .n_voltages = ARRAY_SIZE(buck_voltage_map), | 306 | .n_voltages = ARRAY_SIZE(buck_voltage_map), |
307 | .volt_table = buck_voltage_map, | ||
330 | .type = REGULATOR_VOLTAGE, | 308 | .type = REGULATOR_VOLTAGE, |
331 | .owner = THIS_MODULE, | 309 | .owner = THIS_MODULE, |
332 | }, | 310 | }, |
@@ -335,6 +313,7 @@ static const struct regulator_desc regulators[] = { | |||
335 | .id = LP3971_DCDC2, | 313 | .id = LP3971_DCDC2, |
336 | .ops = &lp3971_dcdc_ops, | 314 | .ops = &lp3971_dcdc_ops, |
337 | .n_voltages = ARRAY_SIZE(buck_voltage_map), | 315 | .n_voltages = ARRAY_SIZE(buck_voltage_map), |
316 | .volt_table = buck_voltage_map, | ||
338 | .type = REGULATOR_VOLTAGE, | 317 | .type = REGULATOR_VOLTAGE, |
339 | .owner = THIS_MODULE, | 318 | .owner = THIS_MODULE, |
340 | }, | 319 | }, |
@@ -343,6 +322,7 @@ static const struct regulator_desc regulators[] = { | |||
343 | .id = LP3971_DCDC3, | 322 | .id = LP3971_DCDC3, |
344 | .ops = &lp3971_dcdc_ops, | 323 | .ops = &lp3971_dcdc_ops, |
345 | .n_voltages = ARRAY_SIZE(buck_voltage_map), | 324 | .n_voltages = ARRAY_SIZE(buck_voltage_map), |
325 | .volt_table = buck_voltage_map, | ||
346 | .type = REGULATOR_VOLTAGE, | 326 | .type = REGULATOR_VOLTAGE, |
347 | .owner = THIS_MODULE, | 327 | .owner = THIS_MODULE, |
348 | }, | 328 | }, |
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index de073df7d344..3cdc755d9b22 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -74,54 +74,40 @@ struct lp3972 { | |||
74 | #define LP3972_OVER2_LDO4_EN BIT(4) | 74 | #define LP3972_OVER2_LDO4_EN BIT(4) |
75 | #define LP3972_OVER1_S_EN BIT(2) | 75 | #define LP3972_OVER1_S_EN BIT(2) |
76 | 76 | ||
77 | static const int ldo1_voltage_map[] = { | 77 | static const unsigned int ldo1_voltage_map[] = { |
78 | 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875, | 78 | 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000, |
79 | 1900, 1925, 1950, 1975, 2000, | 79 | 1900000, 1925000, 1950000, 1975000, 2000000, |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static const int ldo23_voltage_map[] = { | 82 | static const unsigned int ldo23_voltage_map[] = { |
83 | 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, | 83 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, |
84 | 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, | 84 | 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, |
85 | }; | 85 | }; |
86 | 86 | ||
87 | static const int ldo4_voltage_map[] = { | 87 | static const unsigned int ldo4_voltage_map[] = { |
88 | 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, | 88 | 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, |
89 | 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, | 89 | 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000, |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static const int ldo5_voltage_map[] = { | 92 | static const unsigned int ldo5_voltage_map[] = { |
93 | 0, 0, 0, 0, 0, 850, 875, 900, | 93 | 0, 0, 0, 0, 0, 850000, 875000, 900000, |
94 | 925, 950, 975, 1000, 1025, 1050, 1075, 1100, | 94 | 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000, |
95 | 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, | 95 | 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, |
96 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 96 | 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, |
97 | }; | 97 | }; |
98 | 98 | ||
99 | static const int buck1_voltage_map[] = { | 99 | static const unsigned int buck1_voltage_map[] = { |
100 | 725, 750, 775, 800, 825, 850, 875, 900, | 100 | 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000, |
101 | 925, 950, 975, 1000, 1025, 1050, 1075, 1100, | 101 | 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000, |
102 | 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, | 102 | 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, |
103 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 103 | 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static const int buck23_voltage_map[] = { | 106 | static const unsigned int buck23_voltage_map[] = { |
107 | 0, 800, 850, 900, 950, 1000, 1050, 1100, | 107 | 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, |
108 | 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, | 108 | 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, |
109 | 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, | 109 | 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000, |
110 | 3000, 3300, | 110 | 3000000, 3300000, |
111 | }; | ||
112 | |||
113 | static const int *ldo_voltage_map[] = { | ||
114 | ldo1_voltage_map, | ||
115 | ldo23_voltage_map, | ||
116 | ldo23_voltage_map, | ||
117 | ldo4_voltage_map, | ||
118 | ldo5_voltage_map, | ||
119 | }; | ||
120 | |||
121 | static const int *buck_voltage_map[] = { | ||
122 | buck1_voltage_map, | ||
123 | buck23_voltage_map, | ||
124 | buck23_voltage_map, | ||
125 | }; | 111 | }; |
126 | 112 | ||
127 | static const int ldo_output_enable_mask[] = { | 113 | static const int ldo_output_enable_mask[] = { |
@@ -160,7 +146,6 @@ static const int buck_base_addr[] = { | |||
160 | LP3972_B3TV_REG, | 146 | LP3972_B3TV_REG, |
161 | }; | 147 | }; |
162 | 148 | ||
163 | #define LP3972_LDO_VOL_VALUE_MAP(x) (ldo_voltage_map[x]) | ||
164 | #define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x]) | 149 | #define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x]) |
165 | #define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x]) | 150 | #define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x]) |
166 | 151 | ||
@@ -177,7 +162,6 @@ static const int buck_base_addr[] = { | |||
177 | #define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00) | 162 | #define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00) |
178 | #define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c) | 163 | #define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c) |
179 | 164 | ||
180 | #define LP3972_BUCK_VOL_VALUE_MAP(x) (buck_voltage_map[x]) | ||
181 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) | 165 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) |
182 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) | 166 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) |
183 | #define LP3972_BUCK_VOL_MASK 0x1f | 167 | #define LP3972_BUCK_VOL_MASK 0x1f |
@@ -242,17 +226,6 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val) | |||
242 | return ret; | 226 | return ret; |
243 | } | 227 | } |
244 | 228 | ||
245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | ||
246 | { | ||
247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | ||
248 | |||
249 | if (index < LP3972_LDO_VOL_MIN_IDX(ldo) || | ||
250 | index > LP3972_LDO_VOL_MAX_IDX(ldo)) | ||
251 | return -EINVAL; | ||
252 | |||
253 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; | ||
254 | } | ||
255 | |||
256 | static int lp3972_ldo_is_enabled(struct regulator_dev *dev) | 229 | static int lp3972_ldo_is_enabled(struct regulator_dev *dev) |
257 | { | 230 | { |
258 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 231 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
@@ -294,7 +267,7 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | |||
294 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); | 267 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); |
295 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; | 268 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; |
296 | 269 | ||
297 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; | 270 | return dev->desc->volt_table[val]; |
298 | } | 271 | } |
299 | 272 | ||
300 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, | 273 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, |
@@ -337,7 +310,7 @@ static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, | |||
337 | } | 310 | } |
338 | 311 | ||
339 | static struct regulator_ops lp3972_ldo_ops = { | 312 | static struct regulator_ops lp3972_ldo_ops = { |
340 | .list_voltage = lp3972_ldo_list_voltage, | 313 | .list_voltage = regulator_list_voltage_table, |
341 | .is_enabled = lp3972_ldo_is_enabled, | 314 | .is_enabled = lp3972_ldo_is_enabled, |
342 | .enable = lp3972_ldo_enable, | 315 | .enable = lp3972_ldo_enable, |
343 | .disable = lp3972_ldo_disable, | 316 | .disable = lp3972_ldo_disable, |
@@ -345,17 +318,6 @@ static struct regulator_ops lp3972_ldo_ops = { | |||
345 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, | 318 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, |
346 | }; | 319 | }; |
347 | 320 | ||
348 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | ||
349 | { | ||
350 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | ||
351 | |||
352 | if (index < LP3972_BUCK_VOL_MIN_IDX(buck) || | ||
353 | index > LP3972_BUCK_VOL_MAX_IDX(buck)) | ||
354 | return -EINVAL; | ||
355 | |||
356 | return 1000 * buck_voltage_map[buck][index]; | ||
357 | } | ||
358 | |||
359 | static int lp3972_dcdc_is_enabled(struct regulator_dev *dev) | 321 | static int lp3972_dcdc_is_enabled(struct regulator_dev *dev) |
360 | { | 322 | { |
361 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 323 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
@@ -401,7 +363,7 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) | |||
401 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); | 363 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); |
402 | reg &= LP3972_BUCK_VOL_MASK; | 364 | reg &= LP3972_BUCK_VOL_MASK; |
403 | if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) | 365 | if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) |
404 | val = 1000 * buck_voltage_map[buck][reg]; | 366 | val = dev->desc->volt_table[reg]; |
405 | else { | 367 | else { |
406 | val = 0; | 368 | val = 0; |
407 | dev_warn(&dev->dev, "chip reported incorrect voltage value." | 369 | dev_warn(&dev->dev, "chip reported incorrect voltage value." |
@@ -436,7 +398,7 @@ static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, | |||
436 | } | 398 | } |
437 | 399 | ||
438 | static struct regulator_ops lp3972_dcdc_ops = { | 400 | static struct regulator_ops lp3972_dcdc_ops = { |
439 | .list_voltage = lp3972_dcdc_list_voltage, | 401 | .list_voltage = regulator_list_voltage_table, |
440 | .is_enabled = lp3972_dcdc_is_enabled, | 402 | .is_enabled = lp3972_dcdc_is_enabled, |
441 | .enable = lp3972_dcdc_enable, | 403 | .enable = lp3972_dcdc_enable, |
442 | .disable = lp3972_dcdc_disable, | 404 | .disable = lp3972_dcdc_disable, |
@@ -450,6 +412,7 @@ static const struct regulator_desc regulators[] = { | |||
450 | .id = LP3972_LDO1, | 412 | .id = LP3972_LDO1, |
451 | .ops = &lp3972_ldo_ops, | 413 | .ops = &lp3972_ldo_ops, |
452 | .n_voltages = ARRAY_SIZE(ldo1_voltage_map), | 414 | .n_voltages = ARRAY_SIZE(ldo1_voltage_map), |
415 | .volt_table = ldo1_voltage_map, | ||
453 | .type = REGULATOR_VOLTAGE, | 416 | .type = REGULATOR_VOLTAGE, |
454 | .owner = THIS_MODULE, | 417 | .owner = THIS_MODULE, |
455 | }, | 418 | }, |
@@ -458,6 +421,7 @@ static const struct regulator_desc regulators[] = { | |||
458 | .id = LP3972_LDO2, | 421 | .id = LP3972_LDO2, |
459 | .ops = &lp3972_ldo_ops, | 422 | .ops = &lp3972_ldo_ops, |
460 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), | 423 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), |
424 | .volt_table = ldo23_voltage_map, | ||
461 | .type = REGULATOR_VOLTAGE, | 425 | .type = REGULATOR_VOLTAGE, |
462 | .owner = THIS_MODULE, | 426 | .owner = THIS_MODULE, |
463 | }, | 427 | }, |
@@ -466,6 +430,7 @@ static const struct regulator_desc regulators[] = { | |||
466 | .id = LP3972_LDO3, | 430 | .id = LP3972_LDO3, |
467 | .ops = &lp3972_ldo_ops, | 431 | .ops = &lp3972_ldo_ops, |
468 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), | 432 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), |
433 | .volt_table = ldo23_voltage_map, | ||
469 | .type = REGULATOR_VOLTAGE, | 434 | .type = REGULATOR_VOLTAGE, |
470 | .owner = THIS_MODULE, | 435 | .owner = THIS_MODULE, |
471 | }, | 436 | }, |
@@ -474,6 +439,7 @@ static const struct regulator_desc regulators[] = { | |||
474 | .id = LP3972_LDO4, | 439 | .id = LP3972_LDO4, |
475 | .ops = &lp3972_ldo_ops, | 440 | .ops = &lp3972_ldo_ops, |
476 | .n_voltages = ARRAY_SIZE(ldo4_voltage_map), | 441 | .n_voltages = ARRAY_SIZE(ldo4_voltage_map), |
442 | .volt_table = ldo4_voltage_map, | ||
477 | .type = REGULATOR_VOLTAGE, | 443 | .type = REGULATOR_VOLTAGE, |
478 | .owner = THIS_MODULE, | 444 | .owner = THIS_MODULE, |
479 | }, | 445 | }, |
@@ -482,6 +448,7 @@ static const struct regulator_desc regulators[] = { | |||
482 | .id = LP3972_LDO5, | 448 | .id = LP3972_LDO5, |
483 | .ops = &lp3972_ldo_ops, | 449 | .ops = &lp3972_ldo_ops, |
484 | .n_voltages = ARRAY_SIZE(ldo5_voltage_map), | 450 | .n_voltages = ARRAY_SIZE(ldo5_voltage_map), |
451 | .volt_table = ldo5_voltage_map, | ||
485 | .type = REGULATOR_VOLTAGE, | 452 | .type = REGULATOR_VOLTAGE, |
486 | .owner = THIS_MODULE, | 453 | .owner = THIS_MODULE, |
487 | }, | 454 | }, |
@@ -490,6 +457,7 @@ static const struct regulator_desc regulators[] = { | |||
490 | .id = LP3972_DCDC1, | 457 | .id = LP3972_DCDC1, |
491 | .ops = &lp3972_dcdc_ops, | 458 | .ops = &lp3972_dcdc_ops, |
492 | .n_voltages = ARRAY_SIZE(buck1_voltage_map), | 459 | .n_voltages = ARRAY_SIZE(buck1_voltage_map), |
460 | .volt_table = buck1_voltage_map, | ||
493 | .type = REGULATOR_VOLTAGE, | 461 | .type = REGULATOR_VOLTAGE, |
494 | .owner = THIS_MODULE, | 462 | .owner = THIS_MODULE, |
495 | }, | 463 | }, |
@@ -498,6 +466,7 @@ static const struct regulator_desc regulators[] = { | |||
498 | .id = LP3972_DCDC2, | 466 | .id = LP3972_DCDC2, |
499 | .ops = &lp3972_dcdc_ops, | 467 | .ops = &lp3972_dcdc_ops, |
500 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), | 468 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), |
469 | .volt_table = buck23_voltage_map, | ||
501 | .type = REGULATOR_VOLTAGE, | 470 | .type = REGULATOR_VOLTAGE, |
502 | .owner = THIS_MODULE, | 471 | .owner = THIS_MODULE, |
503 | }, | 472 | }, |
@@ -506,6 +475,7 @@ static const struct regulator_desc regulators[] = { | |||
506 | .id = LP3972_DCDC3, | 475 | .id = LP3972_DCDC3, |
507 | .ops = &lp3972_dcdc_ops, | 476 | .ops = &lp3972_dcdc_ops, |
508 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), | 477 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), |
478 | .volt_table = buck23_voltage_map, | ||
509 | .type = REGULATOR_VOLTAGE, | 479 | .type = REGULATOR_VOLTAGE, |
510 | .owner = THIS_MODULE, | 480 | .owner = THIS_MODULE, |
511 | }, | 481 | }, |
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c new file mode 100644 index 000000000000..212c38eaba70 --- /dev/null +++ b/drivers/regulator/lp872x.c | |||
@@ -0,0 +1,943 @@ | |||
1 | /* | ||
2 | * Copyright 2012 Texas Instruments | ||
3 | * | ||
4 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/i2c.h> | ||
15 | #include <linux/regmap.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/regulator/lp872x.h> | ||
19 | #include <linux/regulator/driver.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | |||
22 | /* Registers : LP8720/8725 shared */ | ||
23 | #define LP872X_GENERAL_CFG 0x00 | ||
24 | #define LP872X_LDO1_VOUT 0x01 | ||
25 | #define LP872X_LDO2_VOUT 0x02 | ||
26 | #define LP872X_LDO3_VOUT 0x03 | ||
27 | #define LP872X_LDO4_VOUT 0x04 | ||
28 | #define LP872X_LDO5_VOUT 0x05 | ||
29 | |||
30 | /* Registers : LP8720 */ | ||
31 | #define LP8720_BUCK_VOUT1 0x06 | ||
32 | #define LP8720_BUCK_VOUT2 0x07 | ||
33 | #define LP8720_ENABLE 0x08 | ||
34 | |||
35 | /* Registers : LP8725 */ | ||
36 | #define LP8725_LILO1_VOUT 0x06 | ||
37 | #define LP8725_LILO2_VOUT 0x07 | ||
38 | #define LP8725_BUCK1_VOUT1 0x08 | ||
39 | #define LP8725_BUCK1_VOUT2 0x09 | ||
40 | #define LP8725_BUCK2_VOUT1 0x0A | ||
41 | #define LP8725_BUCK2_VOUT2 0x0B | ||
42 | #define LP8725_BUCK_CTRL 0x0C | ||
43 | #define LP8725_LDO_CTRL 0x0D | ||
44 | |||
45 | /* Mask/shift : LP8720/LP8725 shared */ | ||
46 | #define LP872X_VOUT_M 0x1F | ||
47 | #define LP872X_START_DELAY_M 0xE0 | ||
48 | #define LP872X_START_DELAY_S 5 | ||
49 | #define LP872X_EN_LDO1_M BIT(0) | ||
50 | #define LP872X_EN_LDO2_M BIT(1) | ||
51 | #define LP872X_EN_LDO3_M BIT(2) | ||
52 | #define LP872X_EN_LDO4_M BIT(3) | ||
53 | #define LP872X_EN_LDO5_M BIT(4) | ||
54 | |||
55 | /* Mask/shift : LP8720 */ | ||
56 | #define LP8720_TIMESTEP_S 0 /* Addr 00h */ | ||
57 | #define LP8720_TIMESTEP_M BIT(0) | ||
58 | #define LP8720_EXT_DVS_M BIT(2) | ||
59 | #define LP8720_BUCK_FPWM_S 5 /* Addr 07h */ | ||
60 | #define LP8720_BUCK_FPWM_M BIT(5) | ||
61 | #define LP8720_EN_BUCK_M BIT(5) /* Addr 08h */ | ||
62 | #define LP8720_DVS_SEL_M BIT(7) | ||
63 | |||
64 | /* Mask/shift : LP8725 */ | ||
65 | #define LP8725_TIMESTEP_M 0xC0 /* Addr 00h */ | ||
66 | #define LP8725_TIMESTEP_S 6 | ||
67 | #define LP8725_BUCK1_EN_M BIT(0) | ||
68 | #define LP8725_DVS1_M BIT(2) | ||
69 | #define LP8725_DVS2_M BIT(3) | ||
70 | #define LP8725_BUCK2_EN_M BIT(4) | ||
71 | #define LP8725_BUCK_CL_M 0xC0 /* Addr 09h, 0Bh */ | ||
72 | #define LP8725_BUCK_CL_S 6 | ||
73 | #define LP8725_BUCK1_FPWM_S 1 /* Addr 0Ch */ | ||
74 | #define LP8725_BUCK1_FPWM_M BIT(1) | ||
75 | #define LP8725_BUCK2_FPWM_S 5 | ||
76 | #define LP8725_BUCK2_FPWM_M BIT(5) | ||
77 | #define LP8725_EN_LILO1_M BIT(5) /* Addr 0Dh */ | ||
78 | #define LP8725_EN_LILO2_M BIT(6) | ||
79 | |||
80 | /* PWM mode */ | ||
81 | #define LP872X_FORCE_PWM 1 | ||
82 | #define LP872X_AUTO_PWM 0 | ||
83 | |||
84 | #define LP8720_NUM_REGULATORS 6 | ||
85 | #define LP8725_NUM_REGULATORS 9 | ||
86 | #define EXTERN_DVS_USED 0 | ||
87 | #define MAX_DELAY 6 | ||
88 | |||
89 | /* dump registers in regmap-debugfs */ | ||
90 | #define MAX_REGISTERS 0x0F | ||
91 | |||
92 | enum lp872x_id { | ||
93 | LP8720, | ||
94 | LP8725, | ||
95 | }; | ||
96 | |||
97 | struct lp872x { | ||
98 | struct regmap *regmap; | ||
99 | struct device *dev; | ||
100 | enum lp872x_id chipid; | ||
101 | struct lp872x_platform_data *pdata; | ||
102 | struct regulator_dev **regulators; | ||
103 | int num_regulators; | ||
104 | enum lp872x_dvs_state dvs_pin; | ||
105 | int dvs_gpio; | ||
106 | }; | ||
107 | |||
108 | /* LP8720/LP8725 shared voltage table for LDOs */ | ||
109 | static const unsigned int lp872x_ldo_vtbl[] = { | ||
110 | 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000, | ||
111 | 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 2000000, | ||
112 | 2100000, 2200000, 2300000, 2400000, 2500000, 2600000, 2650000, 2700000, | ||
113 | 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3100000, 3300000, | ||
114 | }; | ||
115 | |||
116 | /* LP8720 LDO4 voltage table */ | ||
117 | static const unsigned int lp8720_ldo4_vtbl[] = { | ||
118 | 800000, 850000, 900000, 1000000, 1100000, 1200000, 1250000, 1300000, | ||
119 | 1350000, 1400000, 1450000, 1500000, 1550000, 1600000, 1650000, 1700000, | ||
120 | 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000, | ||
121 | 2400000, 2500000, 2600000, 2650000, 2700000, 2750000, 2800000, 2850000, | ||
122 | }; | ||
123 | |||
124 | /* LP8725 LILO(Low Input Low Output) voltage table */ | ||
125 | static const unsigned int lp8725_lilo_vtbl[] = { | ||
126 | 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000, | ||
127 | 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000, | ||
128 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, | ||
129 | 2600000, 2700000, 2800000, 2850000, 2900000, 3000000, 3100000, 3300000, | ||
130 | }; | ||
131 | |||
132 | /* LP8720 BUCK voltage table */ | ||
133 | #define EXT_R 0 /* external resistor divider */ | ||
134 | static const unsigned int lp8720_buck_vtbl[] = { | ||
135 | EXT_R, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, | ||
136 | 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, | ||
137 | 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, | ||
138 | 1950000, 2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000, | ||
139 | }; | ||
140 | |||
141 | /* LP8725 BUCK voltage table */ | ||
142 | static const unsigned int lp8725_buck_vtbl[] = { | ||
143 | 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 1150000, | ||
144 | 1200000, 1250000, 1300000, 1350000, 1400000, 1500000, 1600000, 1700000, | ||
145 | 1750000, 1800000, 1850000, 1900000, 2000000, 2100000, 2200000, 2300000, | ||
146 | 2400000, 2500000, 2600000, 2700000, 2800000, 2850000, 2900000, 3000000, | ||
147 | }; | ||
148 | |||
149 | /* LP8725 BUCK current limit */ | ||
150 | static const unsigned int lp8725_buck_uA[] = { | ||
151 | 460000, 780000, 1050000, 1370000, | ||
152 | }; | ||
153 | |||
154 | static int lp872x_read_byte(struct lp872x *lp, u8 addr, u8 *data) | ||
155 | { | ||
156 | int ret; | ||
157 | unsigned int val; | ||
158 | |||
159 | ret = regmap_read(lp->regmap, addr, &val); | ||
160 | if (ret < 0) { | ||
161 | dev_err(lp->dev, "failed to read 0x%.2x\n", addr); | ||
162 | return ret; | ||
163 | } | ||
164 | |||
165 | *data = (u8)val; | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static inline int lp872x_write_byte(struct lp872x *lp, u8 addr, u8 data) | ||
170 | { | ||
171 | return regmap_write(lp->regmap, addr, data); | ||
172 | } | ||
173 | |||
174 | static inline int lp872x_update_bits(struct lp872x *lp, u8 addr, | ||
175 | unsigned int mask, u8 data) | ||
176 | { | ||
177 | return regmap_update_bits(lp->regmap, addr, mask, data); | ||
178 | } | ||
179 | |||
180 | static int _rdev_to_offset(struct regulator_dev *rdev) | ||
181 | { | ||
182 | enum lp872x_regulator_id id = rdev_get_id(rdev); | ||
183 | |||
184 | switch (id) { | ||
185 | case LP8720_ID_LDO1 ... LP8720_ID_BUCK: | ||
186 | return id; | ||
187 | case LP8725_ID_LDO1 ... LP8725_ID_BUCK2: | ||
188 | return id - LP8725_ID_BASE; | ||
189 | default: | ||
190 | return -EINVAL; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | static int lp872x_get_timestep_usec(struct lp872x *lp) | ||
195 | { | ||
196 | enum lp872x_id chip = lp->chipid; | ||
197 | u8 val, mask, shift; | ||
198 | int *time_usec, size, ret; | ||
199 | int lp8720_time_usec[] = { 25, 50 }; | ||
200 | int lp8725_time_usec[] = { 32, 64, 128, 256 }; | ||
201 | |||
202 | switch (chip) { | ||
203 | case LP8720: | ||
204 | mask = LP8720_TIMESTEP_M; | ||
205 | shift = LP8720_TIMESTEP_S; | ||
206 | time_usec = &lp8720_time_usec[0]; | ||
207 | size = ARRAY_SIZE(lp8720_time_usec); | ||
208 | break; | ||
209 | case LP8725: | ||
210 | mask = LP8725_TIMESTEP_M; | ||
211 | shift = LP8725_TIMESTEP_S; | ||
212 | time_usec = &lp8725_time_usec[0]; | ||
213 | size = ARRAY_SIZE(lp8725_time_usec); | ||
214 | break; | ||
215 | default: | ||
216 | return -EINVAL; | ||
217 | } | ||
218 | |||
219 | ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val); | ||
220 | if (ret) | ||
221 | return -EINVAL; | ||
222 | |||
223 | val = (val & mask) >> shift; | ||
224 | if (val >= size) | ||
225 | return -EINVAL; | ||
226 | |||
227 | return *(time_usec + val); | ||
228 | } | ||
229 | |||
230 | static int lp872x_regulator_enable_time(struct regulator_dev *rdev) | ||
231 | { | ||
232 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
233 | enum lp872x_regulator_id regulator = rdev_get_id(rdev); | ||
234 | int time_step_us = lp872x_get_timestep_usec(lp); | ||
235 | int ret, offset; | ||
236 | u8 addr, val; | ||
237 | |||
238 | if (time_step_us < 0) | ||
239 | return -EINVAL; | ||
240 | |||
241 | switch (regulator) { | ||
242 | case LP8720_ID_LDO1 ... LP8720_ID_LDO5: | ||
243 | case LP8725_ID_LDO1 ... LP8725_ID_LILO2: | ||
244 | offset = _rdev_to_offset(rdev); | ||
245 | if (offset < 0) | ||
246 | return -EINVAL; | ||
247 | |||
248 | addr = LP872X_LDO1_VOUT + offset; | ||
249 | break; | ||
250 | case LP8720_ID_BUCK: | ||
251 | addr = LP8720_BUCK_VOUT1; | ||
252 | break; | ||
253 | case LP8725_ID_BUCK1: | ||
254 | addr = LP8725_BUCK1_VOUT1; | ||
255 | break; | ||
256 | case LP8725_ID_BUCK2: | ||
257 | addr = LP8725_BUCK2_VOUT1; | ||
258 | break; | ||
259 | default: | ||
260 | return -EINVAL; | ||
261 | } | ||
262 | |||
263 | ret = lp872x_read_byte(lp, addr, &val); | ||
264 | if (ret) | ||
265 | return ret; | ||
266 | |||
267 | val = (val & LP872X_START_DELAY_M) >> LP872X_START_DELAY_S; | ||
268 | |||
269 | return val > MAX_DELAY ? 0 : val * time_step_us; | ||
270 | } | ||
271 | |||
272 | static void lp872x_set_dvs(struct lp872x *lp, int gpio) | ||
273 | { | ||
274 | enum lp872x_dvs_sel dvs_sel = lp->pdata->dvs->vsel; | ||
275 | enum lp872x_dvs_state state; | ||
276 | |||
277 | state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW; | ||
278 | gpio_set_value(gpio, state); | ||
279 | lp->dvs_pin = state; | ||
280 | } | ||
281 | |||
282 | static u8 lp872x_select_buck_vout_addr(struct lp872x *lp, | ||
283 | enum lp872x_regulator_id buck) | ||
284 | { | ||
285 | u8 val, addr; | ||
286 | |||
287 | if (lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val)) | ||
288 | return 0; | ||
289 | |||
290 | switch (buck) { | ||
291 | case LP8720_ID_BUCK: | ||
292 | if (val & LP8720_EXT_DVS_M) { | ||
293 | addr = (lp->dvs_pin == DVS_HIGH) ? | ||
294 | LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2; | ||
295 | } else { | ||
296 | if (lp872x_read_byte(lp, LP8720_ENABLE, &val)) | ||
297 | return 0; | ||
298 | |||
299 | addr = val & LP8720_DVS_SEL_M ? | ||
300 | LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2; | ||
301 | } | ||
302 | break; | ||
303 | case LP8725_ID_BUCK1: | ||
304 | if (val & LP8725_DVS1_M) | ||
305 | addr = LP8725_BUCK1_VOUT1; | ||
306 | else | ||
307 | addr = (lp->dvs_pin == DVS_HIGH) ? | ||
308 | LP8725_BUCK1_VOUT1 : LP8725_BUCK1_VOUT2; | ||
309 | break; | ||
310 | case LP8725_ID_BUCK2: | ||
311 | addr = val & LP8725_DVS2_M ? | ||
312 | LP8725_BUCK2_VOUT1 : LP8725_BUCK2_VOUT2; | ||
313 | break; | ||
314 | default: | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | return addr; | ||
319 | } | ||
320 | |||
321 | static bool lp872x_is_valid_buck_addr(u8 addr) | ||
322 | { | ||
323 | switch (addr) { | ||
324 | case LP8720_BUCK_VOUT1: | ||
325 | case LP8720_BUCK_VOUT2: | ||
326 | case LP8725_BUCK1_VOUT1: | ||
327 | case LP8725_BUCK1_VOUT2: | ||
328 | case LP8725_BUCK2_VOUT1: | ||
329 | case LP8725_BUCK2_VOUT2: | ||
330 | return true; | ||
331 | default: | ||
332 | return false; | ||
333 | } | ||
334 | } | ||
335 | |||
336 | static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev, | ||
337 | unsigned selector) | ||
338 | { | ||
339 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
340 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
341 | u8 addr, mask = LP872X_VOUT_M; | ||
342 | struct lp872x_dvs *dvs = lp->pdata->dvs; | ||
343 | |||
344 | if (dvs && gpio_is_valid(dvs->gpio)) | ||
345 | lp872x_set_dvs(lp, dvs->gpio); | ||
346 | |||
347 | addr = lp872x_select_buck_vout_addr(lp, buck); | ||
348 | if (!lp872x_is_valid_buck_addr(addr)) | ||
349 | return -EINVAL; | ||
350 | |||
351 | return lp872x_update_bits(lp, addr, mask, selector); | ||
352 | } | ||
353 | |||
354 | static int lp872x_buck_get_voltage_sel(struct regulator_dev *rdev) | ||
355 | { | ||
356 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
357 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
358 | u8 addr, val; | ||
359 | int ret; | ||
360 | |||
361 | addr = lp872x_select_buck_vout_addr(lp, buck); | ||
362 | if (!lp872x_is_valid_buck_addr(addr)) | ||
363 | return -EINVAL; | ||
364 | |||
365 | ret = lp872x_read_byte(lp, addr, &val); | ||
366 | if (ret) | ||
367 | return ret; | ||
368 | |||
369 | return val & LP872X_VOUT_M; | ||
370 | } | ||
371 | |||
372 | static int lp8725_buck_set_current_limit(struct regulator_dev *rdev, | ||
373 | int min_uA, int max_uA) | ||
374 | { | ||
375 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
376 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
377 | int i, max = ARRAY_SIZE(lp8725_buck_uA); | ||
378 | u8 addr, val; | ||
379 | |||
380 | switch (buck) { | ||
381 | case LP8725_ID_BUCK1: | ||
382 | addr = LP8725_BUCK1_VOUT2; | ||
383 | break; | ||
384 | case LP8725_ID_BUCK2: | ||
385 | addr = LP8725_BUCK2_VOUT2; | ||
386 | break; | ||
387 | default: | ||
388 | return -EINVAL; | ||
389 | } | ||
390 | |||
391 | for (i = 0 ; i < max ; i++) | ||
392 | if (lp8725_buck_uA[i] >= min_uA && | ||
393 | lp8725_buck_uA[i] <= max_uA) | ||
394 | break; | ||
395 | |||
396 | if (i == max) | ||
397 | return -EINVAL; | ||
398 | |||
399 | val = i << LP8725_BUCK_CL_S; | ||
400 | |||
401 | return lp872x_update_bits(lp, addr, LP8725_BUCK_CL_M, val); | ||
402 | } | ||
403 | |||
404 | static int lp8725_buck_get_current_limit(struct regulator_dev *rdev) | ||
405 | { | ||
406 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
407 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
408 | u8 addr, val; | ||
409 | int ret; | ||
410 | |||
411 | switch (buck) { | ||
412 | case LP8725_ID_BUCK1: | ||
413 | addr = LP8725_BUCK1_VOUT2; | ||
414 | break; | ||
415 | case LP8725_ID_BUCK2: | ||
416 | addr = LP8725_BUCK2_VOUT2; | ||
417 | break; | ||
418 | default: | ||
419 | return -EINVAL; | ||
420 | } | ||
421 | |||
422 | ret = lp872x_read_byte(lp, addr, &val); | ||
423 | if (ret) | ||
424 | return ret; | ||
425 | |||
426 | val = (val & LP8725_BUCK_CL_M) >> LP8725_BUCK_CL_S; | ||
427 | |||
428 | return (val < ARRAY_SIZE(lp8725_buck_uA)) ? | ||
429 | lp8725_buck_uA[val] : -EINVAL; | ||
430 | } | ||
431 | |||
432 | static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) | ||
433 | { | ||
434 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
435 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
436 | u8 addr, mask, shift, val; | ||
437 | |||
438 | switch (buck) { | ||
439 | case LP8720_ID_BUCK: | ||
440 | addr = LP8720_BUCK_VOUT2; | ||
441 | mask = LP8720_BUCK_FPWM_M; | ||
442 | shift = LP8720_BUCK_FPWM_S; | ||
443 | break; | ||
444 | case LP8725_ID_BUCK1: | ||
445 | addr = LP8725_BUCK_CTRL; | ||
446 | mask = LP8725_BUCK1_FPWM_M; | ||
447 | shift = LP8725_BUCK1_FPWM_S; | ||
448 | break; | ||
449 | case LP8725_ID_BUCK2: | ||
450 | addr = LP8725_BUCK_CTRL; | ||
451 | mask = LP8725_BUCK2_FPWM_M; | ||
452 | shift = LP8725_BUCK2_FPWM_S; | ||
453 | break; | ||
454 | default: | ||
455 | return -EINVAL; | ||
456 | } | ||
457 | |||
458 | if (mode == REGULATOR_MODE_FAST) | ||
459 | val = LP872X_FORCE_PWM << shift; | ||
460 | else if (mode == REGULATOR_MODE_NORMAL) | ||
461 | val = LP872X_AUTO_PWM << shift; | ||
462 | else | ||
463 | return -EINVAL; | ||
464 | |||
465 | return lp872x_update_bits(lp, addr, mask, val); | ||
466 | } | ||
467 | |||
468 | static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev) | ||
469 | { | ||
470 | struct lp872x *lp = rdev_get_drvdata(rdev); | ||
471 | enum lp872x_regulator_id buck = rdev_get_id(rdev); | ||
472 | u8 addr, mask, val; | ||
473 | int ret; | ||
474 | |||
475 | switch (buck) { | ||
476 | case LP8720_ID_BUCK: | ||
477 | addr = LP8720_BUCK_VOUT2; | ||
478 | mask = LP8720_BUCK_FPWM_M; | ||
479 | break; | ||
480 | case LP8725_ID_BUCK1: | ||
481 | addr = LP8725_BUCK_CTRL; | ||
482 | mask = LP8725_BUCK1_FPWM_M; | ||
483 | break; | ||
484 | case LP8725_ID_BUCK2: | ||
485 | addr = LP8725_BUCK_CTRL; | ||
486 | mask = LP8725_BUCK2_FPWM_M; | ||
487 | break; | ||
488 | default: | ||
489 | return -EINVAL; | ||
490 | } | ||
491 | |||
492 | ret = lp872x_read_byte(lp, addr, &val); | ||
493 | if (ret) | ||
494 | return ret; | ||
495 | |||
496 | return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; | ||
497 | } | ||
498 | |||
499 | static struct regulator_ops lp872x_ldo_ops = { | ||
500 | .list_voltage = regulator_list_voltage_table, | ||
501 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
502 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
503 | .enable = regulator_enable_regmap, | ||
504 | .disable = regulator_disable_regmap, | ||
505 | .is_enabled = regulator_is_enabled_regmap, | ||
506 | .enable_time = lp872x_regulator_enable_time, | ||
507 | }; | ||
508 | |||
509 | static struct regulator_ops lp8720_buck_ops = { | ||
510 | .list_voltage = regulator_list_voltage_table, | ||
511 | .set_voltage_sel = lp872x_buck_set_voltage_sel, | ||
512 | .get_voltage_sel = lp872x_buck_get_voltage_sel, | ||
513 | .enable = regulator_enable_regmap, | ||
514 | .disable = regulator_disable_regmap, | ||
515 | .is_enabled = regulator_is_enabled_regmap, | ||
516 | .enable_time = lp872x_regulator_enable_time, | ||
517 | .set_mode = lp872x_buck_set_mode, | ||
518 | .get_mode = lp872x_buck_get_mode, | ||
519 | }; | ||
520 | |||
521 | static struct regulator_ops lp8725_buck_ops = { | ||
522 | .list_voltage = regulator_list_voltage_table, | ||
523 | .set_voltage_sel = lp872x_buck_set_voltage_sel, | ||
524 | .get_voltage_sel = lp872x_buck_get_voltage_sel, | ||
525 | .enable = regulator_enable_regmap, | ||
526 | .disable = regulator_disable_regmap, | ||
527 | .is_enabled = regulator_is_enabled_regmap, | ||
528 | .enable_time = lp872x_regulator_enable_time, | ||
529 | .set_mode = lp872x_buck_set_mode, | ||
530 | .get_mode = lp872x_buck_get_mode, | ||
531 | .set_current_limit = lp8725_buck_set_current_limit, | ||
532 | .get_current_limit = lp8725_buck_get_current_limit, | ||
533 | }; | ||
534 | |||
535 | static struct regulator_desc lp8720_regulator_desc[] = { | ||
536 | { | ||
537 | .name = "ldo1", | ||
538 | .id = LP8720_ID_LDO1, | ||
539 | .ops = &lp872x_ldo_ops, | ||
540 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
541 | .volt_table = lp872x_ldo_vtbl, | ||
542 | .type = REGULATOR_VOLTAGE, | ||
543 | .owner = THIS_MODULE, | ||
544 | .vsel_reg = LP872X_LDO1_VOUT, | ||
545 | .vsel_mask = LP872X_VOUT_M, | ||
546 | .enable_reg = LP8720_ENABLE, | ||
547 | .enable_mask = LP872X_EN_LDO1_M, | ||
548 | }, | ||
549 | { | ||
550 | .name = "ldo2", | ||
551 | .id = LP8720_ID_LDO2, | ||
552 | .ops = &lp872x_ldo_ops, | ||
553 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
554 | .volt_table = lp872x_ldo_vtbl, | ||
555 | .type = REGULATOR_VOLTAGE, | ||
556 | .owner = THIS_MODULE, | ||
557 | .vsel_reg = LP872X_LDO2_VOUT, | ||
558 | .vsel_mask = LP872X_VOUT_M, | ||
559 | .enable_reg = LP8720_ENABLE, | ||
560 | .enable_mask = LP872X_EN_LDO2_M, | ||
561 | }, | ||
562 | { | ||
563 | .name = "ldo3", | ||
564 | .id = LP8720_ID_LDO3, | ||
565 | .ops = &lp872x_ldo_ops, | ||
566 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
567 | .volt_table = lp872x_ldo_vtbl, | ||
568 | .type = REGULATOR_VOLTAGE, | ||
569 | .owner = THIS_MODULE, | ||
570 | .vsel_reg = LP872X_LDO3_VOUT, | ||
571 | .vsel_mask = LP872X_VOUT_M, | ||
572 | .enable_reg = LP8720_ENABLE, | ||
573 | .enable_mask = LP872X_EN_LDO3_M, | ||
574 | }, | ||
575 | { | ||
576 | .name = "ldo4", | ||
577 | .id = LP8720_ID_LDO4, | ||
578 | .ops = &lp872x_ldo_ops, | ||
579 | .n_voltages = ARRAY_SIZE(lp8720_ldo4_vtbl), | ||
580 | .volt_table = lp8720_ldo4_vtbl, | ||
581 | .type = REGULATOR_VOLTAGE, | ||
582 | .owner = THIS_MODULE, | ||
583 | .vsel_reg = LP872X_LDO4_VOUT, | ||
584 | .vsel_mask = LP872X_VOUT_M, | ||
585 | .enable_reg = LP8720_ENABLE, | ||
586 | .enable_mask = LP872X_EN_LDO4_M, | ||
587 | }, | ||
588 | { | ||
589 | .name = "ldo5", | ||
590 | .id = LP8720_ID_LDO5, | ||
591 | .ops = &lp872x_ldo_ops, | ||
592 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
593 | .volt_table = lp872x_ldo_vtbl, | ||
594 | .type = REGULATOR_VOLTAGE, | ||
595 | .owner = THIS_MODULE, | ||
596 | .vsel_reg = LP872X_LDO5_VOUT, | ||
597 | .vsel_mask = LP872X_VOUT_M, | ||
598 | .enable_reg = LP8720_ENABLE, | ||
599 | .enable_mask = LP872X_EN_LDO5_M, | ||
600 | }, | ||
601 | { | ||
602 | .name = "buck", | ||
603 | .id = LP8720_ID_BUCK, | ||
604 | .ops = &lp8720_buck_ops, | ||
605 | .n_voltages = ARRAY_SIZE(lp8720_buck_vtbl), | ||
606 | .volt_table = lp8720_buck_vtbl, | ||
607 | .type = REGULATOR_VOLTAGE, | ||
608 | .owner = THIS_MODULE, | ||
609 | .enable_reg = LP8720_ENABLE, | ||
610 | .enable_mask = LP8720_EN_BUCK_M, | ||
611 | }, | ||
612 | }; | ||
613 | |||
614 | static struct regulator_desc lp8725_regulator_desc[] = { | ||
615 | { | ||
616 | .name = "ldo1", | ||
617 | .id = LP8725_ID_LDO1, | ||
618 | .ops = &lp872x_ldo_ops, | ||
619 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
620 | .volt_table = lp872x_ldo_vtbl, | ||
621 | .type = REGULATOR_VOLTAGE, | ||
622 | .owner = THIS_MODULE, | ||
623 | .vsel_reg = LP872X_LDO1_VOUT, | ||
624 | .vsel_mask = LP872X_VOUT_M, | ||
625 | .enable_reg = LP8725_LDO_CTRL, | ||
626 | .enable_mask = LP872X_EN_LDO1_M, | ||
627 | }, | ||
628 | { | ||
629 | .name = "ldo2", | ||
630 | .id = LP8725_ID_LDO2, | ||
631 | .ops = &lp872x_ldo_ops, | ||
632 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
633 | .volt_table = lp872x_ldo_vtbl, | ||
634 | .type = REGULATOR_VOLTAGE, | ||
635 | .owner = THIS_MODULE, | ||
636 | .vsel_reg = LP872X_LDO2_VOUT, | ||
637 | .vsel_mask = LP872X_VOUT_M, | ||
638 | .enable_reg = LP8725_LDO_CTRL, | ||
639 | .enable_mask = LP872X_EN_LDO2_M, | ||
640 | }, | ||
641 | { | ||
642 | .name = "ldo3", | ||
643 | .id = LP8725_ID_LDO3, | ||
644 | .ops = &lp872x_ldo_ops, | ||
645 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
646 | .volt_table = lp872x_ldo_vtbl, | ||
647 | .type = REGULATOR_VOLTAGE, | ||
648 | .owner = THIS_MODULE, | ||
649 | .vsel_reg = LP872X_LDO3_VOUT, | ||
650 | .vsel_mask = LP872X_VOUT_M, | ||
651 | .enable_reg = LP8725_LDO_CTRL, | ||
652 | .enable_mask = LP872X_EN_LDO3_M, | ||
653 | }, | ||
654 | { | ||
655 | .name = "ldo4", | ||
656 | .id = LP8725_ID_LDO4, | ||
657 | .ops = &lp872x_ldo_ops, | ||
658 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
659 | .volt_table = lp872x_ldo_vtbl, | ||
660 | .type = REGULATOR_VOLTAGE, | ||
661 | .owner = THIS_MODULE, | ||
662 | .vsel_reg = LP872X_LDO4_VOUT, | ||
663 | .vsel_mask = LP872X_VOUT_M, | ||
664 | .enable_reg = LP8725_LDO_CTRL, | ||
665 | .enable_mask = LP872X_EN_LDO4_M, | ||
666 | }, | ||
667 | { | ||
668 | .name = "ldo5", | ||
669 | .id = LP8725_ID_LDO5, | ||
670 | .ops = &lp872x_ldo_ops, | ||
671 | .n_voltages = ARRAY_SIZE(lp872x_ldo_vtbl), | ||
672 | .volt_table = lp872x_ldo_vtbl, | ||
673 | .type = REGULATOR_VOLTAGE, | ||
674 | .owner = THIS_MODULE, | ||
675 | .vsel_reg = LP872X_LDO5_VOUT, | ||
676 | .vsel_mask = LP872X_VOUT_M, | ||
677 | .enable_reg = LP8725_LDO_CTRL, | ||
678 | .enable_mask = LP872X_EN_LDO5_M, | ||
679 | }, | ||
680 | { | ||
681 | .name = "lilo1", | ||
682 | .id = LP8725_ID_LILO1, | ||
683 | .ops = &lp872x_ldo_ops, | ||
684 | .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl), | ||
685 | .volt_table = lp8725_lilo_vtbl, | ||
686 | .type = REGULATOR_VOLTAGE, | ||
687 | .owner = THIS_MODULE, | ||
688 | .vsel_reg = LP8725_LILO1_VOUT, | ||
689 | .vsel_mask = LP872X_VOUT_M, | ||
690 | .enable_reg = LP8725_LDO_CTRL, | ||
691 | .enable_mask = LP8725_EN_LILO1_M, | ||
692 | }, | ||
693 | { | ||
694 | .name = "lilo2", | ||
695 | .id = LP8725_ID_LILO2, | ||
696 | .ops = &lp872x_ldo_ops, | ||
697 | .n_voltages = ARRAY_SIZE(lp8725_lilo_vtbl), | ||
698 | .volt_table = lp8725_lilo_vtbl, | ||
699 | .type = REGULATOR_VOLTAGE, | ||
700 | .owner = THIS_MODULE, | ||
701 | .vsel_reg = LP8725_LILO2_VOUT, | ||
702 | .vsel_mask = LP872X_VOUT_M, | ||
703 | .enable_reg = LP8725_LDO_CTRL, | ||
704 | .enable_mask = LP8725_EN_LILO2_M, | ||
705 | }, | ||
706 | { | ||
707 | .name = "buck1", | ||
708 | .id = LP8725_ID_BUCK1, | ||
709 | .ops = &lp8725_buck_ops, | ||
710 | .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl), | ||
711 | .volt_table = lp8725_buck_vtbl, | ||
712 | .type = REGULATOR_VOLTAGE, | ||
713 | .owner = THIS_MODULE, | ||
714 | .enable_reg = LP872X_GENERAL_CFG, | ||
715 | .enable_mask = LP8725_BUCK1_EN_M, | ||
716 | }, | ||
717 | { | ||
718 | .name = "buck2", | ||
719 | .id = LP8725_ID_BUCK2, | ||
720 | .ops = &lp8725_buck_ops, | ||
721 | .n_voltages = ARRAY_SIZE(lp8725_buck_vtbl), | ||
722 | .volt_table = lp8725_buck_vtbl, | ||
723 | .type = REGULATOR_VOLTAGE, | ||
724 | .owner = THIS_MODULE, | ||
725 | .enable_reg = LP872X_GENERAL_CFG, | ||
726 | .enable_mask = LP8725_BUCK2_EN_M, | ||
727 | }, | ||
728 | }; | ||
729 | |||
730 | static int lp872x_check_dvs_validity(struct lp872x *lp) | ||
731 | { | ||
732 | struct lp872x_dvs *dvs = lp->pdata->dvs; | ||
733 | u8 val = 0; | ||
734 | int ret; | ||
735 | |||
736 | ret = lp872x_read_byte(lp, LP872X_GENERAL_CFG, &val); | ||
737 | if (ret) | ||
738 | return ret; | ||
739 | |||
740 | ret = 0; | ||
741 | if (lp->chipid == LP8720) { | ||
742 | if (val & LP8720_EXT_DVS_M) | ||
743 | ret = dvs ? 0 : -EINVAL; | ||
744 | } else { | ||
745 | if ((val & LP8725_DVS1_M) == EXTERN_DVS_USED) | ||
746 | ret = dvs ? 0 : -EINVAL; | ||
747 | } | ||
748 | |||
749 | return ret; | ||
750 | } | ||
751 | |||
752 | static int lp872x_init_dvs(struct lp872x *lp) | ||
753 | { | ||
754 | int ret, gpio; | ||
755 | struct lp872x_dvs *dvs = lp->pdata->dvs; | ||
756 | enum lp872x_dvs_state pinstate; | ||
757 | |||
758 | ret = lp872x_check_dvs_validity(lp); | ||
759 | if (ret) { | ||
760 | dev_warn(lp->dev, "invalid dvs data: %d\n", ret); | ||
761 | return ret; | ||
762 | } | ||
763 | |||
764 | gpio = dvs->gpio; | ||
765 | if (!gpio_is_valid(gpio)) { | ||
766 | dev_err(lp->dev, "invalid gpio: %d\n", gpio); | ||
767 | return -EINVAL; | ||
768 | } | ||
769 | |||
770 | pinstate = dvs->init_state; | ||
771 | ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS"); | ||
772 | if (ret) { | ||
773 | dev_err(lp->dev, "gpio request err: %d\n", ret); | ||
774 | return ret; | ||
775 | } | ||
776 | |||
777 | lp->dvs_pin = pinstate; | ||
778 | lp->dvs_gpio = gpio; | ||
779 | |||
780 | return 0; | ||
781 | } | ||
782 | |||
783 | static int lp872x_config(struct lp872x *lp) | ||
784 | { | ||
785 | struct lp872x_platform_data *pdata = lp->pdata; | ||
786 | int ret; | ||
787 | |||
788 | if (!pdata->update_config) | ||
789 | return 0; | ||
790 | |||
791 | ret = lp872x_write_byte(lp, LP872X_GENERAL_CFG, pdata->general_config); | ||
792 | if (ret) | ||
793 | return ret; | ||
794 | |||
795 | return lp872x_init_dvs(lp); | ||
796 | } | ||
797 | |||
798 | static struct regulator_init_data | ||
799 | *lp872x_find_regulator_init_data(int id, struct lp872x *lp) | ||
800 | { | ||
801 | int i; | ||
802 | |||
803 | for (i = 0; i < lp->num_regulators; i++) { | ||
804 | if (lp->pdata->regulator_data[i].id == id) | ||
805 | return lp->pdata->regulator_data[i].init_data; | ||
806 | } | ||
807 | |||
808 | return NULL; | ||
809 | } | ||
810 | |||
811 | static int lp872x_regulator_register(struct lp872x *lp) | ||
812 | { | ||
813 | struct regulator_desc *desc; | ||
814 | struct regulator_config cfg = { }; | ||
815 | struct regulator_dev *rdev; | ||
816 | int i, ret; | ||
817 | |||
818 | for (i = 0 ; i < lp->num_regulators ; i++) { | ||
819 | desc = (lp->chipid == LP8720) ? &lp8720_regulator_desc[i] : | ||
820 | &lp8725_regulator_desc[i]; | ||
821 | |||
822 | cfg.dev = lp->dev; | ||
823 | cfg.init_data = lp872x_find_regulator_init_data(desc->id, lp); | ||
824 | cfg.driver_data = lp; | ||
825 | cfg.regmap = lp->regmap; | ||
826 | |||
827 | rdev = regulator_register(desc, &cfg); | ||
828 | if (IS_ERR(rdev)) { | ||
829 | dev_err(lp->dev, "regulator register err"); | ||
830 | ret = PTR_ERR(rdev); | ||
831 | goto err; | ||
832 | } | ||
833 | |||
834 | *(lp->regulators + i) = rdev; | ||
835 | } | ||
836 | |||
837 | return 0; | ||
838 | err: | ||
839 | while (--i >= 0) { | ||
840 | rdev = *(lp->regulators + i); | ||
841 | regulator_unregister(rdev); | ||
842 | } | ||
843 | return ret; | ||
844 | } | ||
845 | |||
846 | static void lp872x_regulator_unregister(struct lp872x *lp) | ||
847 | { | ||
848 | struct regulator_dev *rdev; | ||
849 | int i; | ||
850 | |||
851 | for (i = 0 ; i < lp->num_regulators ; i++) { | ||
852 | rdev = *(lp->regulators + i); | ||
853 | regulator_unregister(rdev); | ||
854 | } | ||
855 | } | ||
856 | |||
857 | static const struct regmap_config lp872x_regmap_config = { | ||
858 | .reg_bits = 8, | ||
859 | .val_bits = 8, | ||
860 | .max_register = MAX_REGISTERS, | ||
861 | }; | ||
862 | |||
863 | static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) | ||
864 | { | ||
865 | struct lp872x *lp; | ||
866 | struct lp872x_platform_data *pdata = cl->dev.platform_data; | ||
867 | int ret, size, num_regulators; | ||
868 | const int lp872x_num_regulators[] = { | ||
869 | [LP8720] = LP8720_NUM_REGULATORS, | ||
870 | [LP8725] = LP8725_NUM_REGULATORS, | ||
871 | }; | ||
872 | |||
873 | if (!pdata) { | ||
874 | dev_err(&cl->dev, "no platform data\n"); | ||
875 | return -EINVAL; | ||
876 | } | ||
877 | |||
878 | lp = devm_kzalloc(&cl->dev, sizeof(struct lp872x), GFP_KERNEL); | ||
879 | if (!lp) | ||
880 | goto err_mem; | ||
881 | |||
882 | num_regulators = lp872x_num_regulators[id->driver_data]; | ||
883 | size = sizeof(struct regulator_dev *) * num_regulators; | ||
884 | |||
885 | lp->regulators = devm_kzalloc(&cl->dev, size, GFP_KERNEL); | ||
886 | if (!lp->regulators) | ||
887 | goto err_mem; | ||
888 | |||
889 | lp->regmap = devm_regmap_init_i2c(cl, &lp872x_regmap_config); | ||
890 | if (IS_ERR(lp->regmap)) { | ||
891 | ret = PTR_ERR(lp->regmap); | ||
892 | dev_err(&cl->dev, "regmap init i2c err: %d\n", ret); | ||
893 | goto err_dev; | ||
894 | } | ||
895 | |||
896 | lp->dev = &cl->dev; | ||
897 | lp->pdata = pdata; | ||
898 | lp->chipid = id->driver_data; | ||
899 | lp->num_regulators = num_regulators; | ||
900 | i2c_set_clientdata(cl, lp); | ||
901 | |||
902 | ret = lp872x_config(lp); | ||
903 | if (ret) | ||
904 | goto err_dev; | ||
905 | |||
906 | return lp872x_regulator_register(lp); | ||
907 | |||
908 | err_mem: | ||
909 | return -ENOMEM; | ||
910 | err_dev: | ||
911 | return ret; | ||
912 | } | ||
913 | |||
914 | static int __devexit lp872x_remove(struct i2c_client *cl) | ||
915 | { | ||
916 | struct lp872x *lp = i2c_get_clientdata(cl); | ||
917 | |||
918 | lp872x_regulator_unregister(lp); | ||
919 | return 0; | ||
920 | } | ||
921 | |||
922 | static const struct i2c_device_id lp872x_ids[] = { | ||
923 | {"lp8720", LP8720}, | ||
924 | {"lp8725", LP8725}, | ||
925 | { } | ||
926 | }; | ||
927 | MODULE_DEVICE_TABLE(i2c, lp872x_ids); | ||
928 | |||
929 | static struct i2c_driver lp872x_driver = { | ||
930 | .driver = { | ||
931 | .name = "lp872x", | ||
932 | .owner = THIS_MODULE, | ||
933 | }, | ||
934 | .probe = lp872x_probe, | ||
935 | .remove = __devexit_p(lp872x_remove), | ||
936 | .id_table = lp872x_ids, | ||
937 | }; | ||
938 | |||
939 | module_i2c_driver(lp872x_driver); | ||
940 | |||
941 | MODULE_DESCRIPTION("TI/National Semiconductor LP872x PMU Regulator Driver"); | ||
942 | MODULE_AUTHOR("Milo Kim"); | ||
943 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c new file mode 100644 index 000000000000..6356e821400f --- /dev/null +++ b/drivers/regulator/lp8788-buck.c | |||
@@ -0,0 +1,629 @@ | |||
1 | /* | ||
2 | * TI LP8788 MFD - buck regulator driver | ||
3 | * | ||
4 | * Copyright 2012 Texas Instruments | ||
5 | * | ||
6 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/regulator/driver.h> | ||
19 | #include <linux/mfd/lp8788.h> | ||
20 | #include <linux/gpio.h> | ||
21 | |||
22 | /* register address */ | ||
23 | #define LP8788_EN_BUCK 0x0C | ||
24 | #define LP8788_BUCK_DVS_SEL 0x1D | ||
25 | #define LP8788_BUCK1_VOUT0 0x1E | ||
26 | #define LP8788_BUCK1_VOUT1 0x1F | ||
27 | #define LP8788_BUCK1_VOUT2 0x20 | ||
28 | #define LP8788_BUCK1_VOUT3 0x21 | ||
29 | #define LP8788_BUCK2_VOUT0 0x22 | ||
30 | #define LP8788_BUCK2_VOUT1 0x23 | ||
31 | #define LP8788_BUCK2_VOUT2 0x24 | ||
32 | #define LP8788_BUCK2_VOUT3 0x25 | ||
33 | #define LP8788_BUCK3_VOUT 0x26 | ||
34 | #define LP8788_BUCK4_VOUT 0x27 | ||
35 | #define LP8788_BUCK1_TIMESTEP 0x28 | ||
36 | #define LP8788_BUCK_PWM 0x2D | ||
37 | |||
38 | /* mask/shift bits */ | ||
39 | #define LP8788_EN_BUCK1_M BIT(0) /* Addr 0Ch */ | ||
40 | #define LP8788_EN_BUCK2_M BIT(1) | ||
41 | #define LP8788_EN_BUCK3_M BIT(2) | ||
42 | #define LP8788_EN_BUCK4_M BIT(3) | ||
43 | #define LP8788_BUCK1_DVS_SEL_M 0x04 /* Addr 1Dh */ | ||
44 | #define LP8788_BUCK1_DVS_M 0x03 | ||
45 | #define LP8788_BUCK1_DVS_S 0 | ||
46 | #define LP8788_BUCK2_DVS_SEL_M 0x40 | ||
47 | #define LP8788_BUCK2_DVS_M 0x30 | ||
48 | #define LP8788_BUCK2_DVS_S 4 | ||
49 | #define LP8788_BUCK1_DVS_I2C BIT(2) | ||
50 | #define LP8788_BUCK2_DVS_I2C BIT(6) | ||
51 | #define LP8788_BUCK1_DVS_PIN (0 << 2) | ||
52 | #define LP8788_BUCK2_DVS_PIN (0 << 6) | ||
53 | #define LP8788_VOUT_M 0x1F /* Addr 1Eh ~ 27h */ | ||
54 | #define LP8788_STARTUP_TIME_M 0xF8 /* Addr 28h ~ 2Bh */ | ||
55 | #define LP8788_STARTUP_TIME_S 3 | ||
56 | #define LP8788_FPWM_BUCK1_M BIT(0) /* Addr 2Dh */ | ||
57 | #define LP8788_FPWM_BUCK1_S 0 | ||
58 | #define LP8788_FPWM_BUCK2_M BIT(1) | ||
59 | #define LP8788_FPWM_BUCK2_S 1 | ||
60 | #define LP8788_FPWM_BUCK3_M BIT(2) | ||
61 | #define LP8788_FPWM_BUCK3_S 2 | ||
62 | #define LP8788_FPWM_BUCK4_M BIT(3) | ||
63 | #define LP8788_FPWM_BUCK4_S 3 | ||
64 | |||
65 | #define INVALID_ADDR 0xFF | ||
66 | #define LP8788_FORCE_PWM 1 | ||
67 | #define LP8788_AUTO_PWM 0 | ||
68 | #define PIN_LOW 0 | ||
69 | #define PIN_HIGH 1 | ||
70 | #define ENABLE_TIME_USEC 32 | ||
71 | |||
72 | enum lp8788_dvs_state { | ||
73 | DVS_LOW = GPIOF_OUT_INIT_LOW, | ||
74 | DVS_HIGH = GPIOF_OUT_INIT_HIGH, | ||
75 | }; | ||
76 | |||
77 | enum lp8788_dvs_mode { | ||
78 | REGISTER, | ||
79 | EXTPIN, | ||
80 | }; | ||
81 | |||
82 | enum lp8788_buck_id { | ||
83 | BUCK1, | ||
84 | BUCK2, | ||
85 | BUCK3, | ||
86 | BUCK4, | ||
87 | }; | ||
88 | |||
89 | struct lp8788_pwm_map { | ||
90 | u8 mask; | ||
91 | u8 shift; | ||
92 | }; | ||
93 | |||
94 | struct lp8788_buck { | ||
95 | struct lp8788 *lp; | ||
96 | struct regulator_dev *regulator; | ||
97 | struct lp8788_pwm_map *pmap; | ||
98 | void *dvs; | ||
99 | }; | ||
100 | |||
101 | /* BUCK 1 ~ 4 voltage table */ | ||
102 | static const int lp8788_buck_vtbl[] = { | ||
103 | 500000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, | ||
104 | 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, | ||
105 | 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, | ||
106 | 1950000, 2000000, | ||
107 | }; | ||
108 | |||
109 | /* buck pwm mode selection : used for set/get_mode in regulator ops | ||
110 | * @forced pwm : fast mode | ||
111 | * @auto pwm : normal mode | ||
112 | */ | ||
113 | static struct lp8788_pwm_map buck_pmap[] = { | ||
114 | [BUCK1] = { | ||
115 | .mask = LP8788_FPWM_BUCK1_M, | ||
116 | .shift = LP8788_FPWM_BUCK1_S, | ||
117 | }, | ||
118 | [BUCK2] = { | ||
119 | .mask = LP8788_FPWM_BUCK2_M, | ||
120 | .shift = LP8788_FPWM_BUCK2_S, | ||
121 | }, | ||
122 | [BUCK3] = { | ||
123 | .mask = LP8788_FPWM_BUCK3_M, | ||
124 | .shift = LP8788_FPWM_BUCK3_S, | ||
125 | }, | ||
126 | [BUCK4] = { | ||
127 | .mask = LP8788_FPWM_BUCK4_M, | ||
128 | .shift = LP8788_FPWM_BUCK4_S, | ||
129 | }, | ||
130 | }; | ||
131 | |||
132 | static const u8 buck1_vout_addr[] = { | ||
133 | LP8788_BUCK1_VOUT0, LP8788_BUCK1_VOUT1, | ||
134 | LP8788_BUCK1_VOUT2, LP8788_BUCK1_VOUT3, | ||
135 | }; | ||
136 | |||
137 | static const u8 buck2_vout_addr[] = { | ||
138 | LP8788_BUCK2_VOUT0, LP8788_BUCK2_VOUT1, | ||
139 | LP8788_BUCK2_VOUT2, LP8788_BUCK2_VOUT3, | ||
140 | }; | ||
141 | |||
142 | static void lp8788_buck1_set_dvs(struct lp8788_buck *buck) | ||
143 | { | ||
144 | struct lp8788_buck1_dvs *dvs = (struct lp8788_buck1_dvs *)buck->dvs; | ||
145 | enum lp8788_dvs_state pinstate; | ||
146 | |||
147 | if (!dvs) | ||
148 | return; | ||
149 | |||
150 | pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH; | ||
151 | if (gpio_is_valid(dvs->gpio)) | ||
152 | gpio_set_value(dvs->gpio, pinstate); | ||
153 | } | ||
154 | |||
155 | static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) | ||
156 | { | ||
157 | struct lp8788_buck2_dvs *dvs = (struct lp8788_buck2_dvs *)buck->dvs; | ||
158 | enum lp8788_dvs_state pin1, pin2; | ||
159 | |||
160 | if (!dvs) | ||
161 | return; | ||
162 | |||
163 | switch (dvs->vsel) { | ||
164 | case DVS_SEL_V0: | ||
165 | pin1 = DVS_LOW; | ||
166 | pin2 = DVS_LOW; | ||
167 | break; | ||
168 | case DVS_SEL_V1: | ||
169 | pin1 = DVS_HIGH; | ||
170 | pin2 = DVS_LOW; | ||
171 | break; | ||
172 | case DVS_SEL_V2: | ||
173 | pin1 = DVS_LOW; | ||
174 | pin2 = DVS_HIGH; | ||
175 | break; | ||
176 | case DVS_SEL_V3: | ||
177 | pin1 = DVS_HIGH; | ||
178 | pin2 = DVS_HIGH; | ||
179 | break; | ||
180 | default: | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | if (gpio_is_valid(dvs->gpio[0])) | ||
185 | gpio_set_value(dvs->gpio[0], pin1); | ||
186 | |||
187 | if (gpio_is_valid(dvs->gpio[1])) | ||
188 | gpio_set_value(dvs->gpio[1], pin2); | ||
189 | } | ||
190 | |||
191 | static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) | ||
192 | { | ||
193 | switch (id) { | ||
194 | case BUCK1: | ||
195 | lp8788_buck1_set_dvs(buck); | ||
196 | break; | ||
197 | case BUCK2: | ||
198 | lp8788_buck2_set_dvs(buck); | ||
199 | break; | ||
200 | default: | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | static enum lp8788_dvs_mode | ||
206 | lp8788_get_buck_dvs_ctrl_mode(struct lp8788_buck *buck, enum lp8788_buck_id id) | ||
207 | { | ||
208 | u8 val, mask; | ||
209 | |||
210 | switch (id) { | ||
211 | case BUCK1: | ||
212 | mask = LP8788_BUCK1_DVS_SEL_M; | ||
213 | break; | ||
214 | case BUCK2: | ||
215 | mask = LP8788_BUCK2_DVS_SEL_M; | ||
216 | break; | ||
217 | default: | ||
218 | return REGISTER; | ||
219 | } | ||
220 | |||
221 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | ||
222 | |||
223 | return val & mask ? REGISTER : EXTPIN; | ||
224 | } | ||
225 | |||
226 | static bool lp8788_is_valid_buck_addr(u8 addr) | ||
227 | { | ||
228 | switch (addr) { | ||
229 | case LP8788_BUCK1_VOUT0: | ||
230 | case LP8788_BUCK1_VOUT1: | ||
231 | case LP8788_BUCK1_VOUT2: | ||
232 | case LP8788_BUCK1_VOUT3: | ||
233 | case LP8788_BUCK2_VOUT0: | ||
234 | case LP8788_BUCK2_VOUT1: | ||
235 | case LP8788_BUCK2_VOUT2: | ||
236 | case LP8788_BUCK2_VOUT3: | ||
237 | return true; | ||
238 | default: | ||
239 | return false; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck, | ||
244 | enum lp8788_buck_id id) | ||
245 | { | ||
246 | enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id); | ||
247 | struct lp8788_buck1_dvs *b1_dvs; | ||
248 | struct lp8788_buck2_dvs *b2_dvs; | ||
249 | u8 val, idx, addr; | ||
250 | int pin1, pin2; | ||
251 | |||
252 | switch (id) { | ||
253 | case BUCK1: | ||
254 | if (mode == EXTPIN) { | ||
255 | b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs; | ||
256 | if (!b1_dvs) | ||
257 | goto err; | ||
258 | |||
259 | idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0; | ||
260 | } else { | ||
261 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | ||
262 | idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; | ||
263 | } | ||
264 | addr = buck1_vout_addr[idx]; | ||
265 | break; | ||
266 | case BUCK2: | ||
267 | if (mode == EXTPIN) { | ||
268 | b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs; | ||
269 | if (!b2_dvs) | ||
270 | goto err; | ||
271 | |||
272 | pin1 = gpio_get_value(b2_dvs->gpio[0]); | ||
273 | pin2 = gpio_get_value(b2_dvs->gpio[1]); | ||
274 | |||
275 | if (pin1 == PIN_LOW && pin2 == PIN_LOW) | ||
276 | idx = 0; | ||
277 | else if (pin1 == PIN_LOW && pin2 == PIN_HIGH) | ||
278 | idx = 2; | ||
279 | else if (pin1 == PIN_HIGH && pin2 == PIN_LOW) | ||
280 | idx = 1; | ||
281 | else | ||
282 | idx = 3; | ||
283 | } else { | ||
284 | lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); | ||
285 | idx = (val & LP8788_BUCK2_DVS_M) >> LP8788_BUCK2_DVS_S; | ||
286 | } | ||
287 | addr = buck2_vout_addr[idx]; | ||
288 | break; | ||
289 | default: | ||
290 | goto err; | ||
291 | } | ||
292 | |||
293 | return addr; | ||
294 | err: | ||
295 | return INVALID_ADDR; | ||
296 | } | ||
297 | |||
298 | static int lp8788_buck12_set_voltage_sel(struct regulator_dev *rdev, | ||
299 | unsigned selector) | ||
300 | { | ||
301 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | ||
302 | enum lp8788_buck_id id = rdev_get_id(rdev); | ||
303 | u8 addr; | ||
304 | |||
305 | if (buck->dvs) | ||
306 | lp8788_set_dvs(buck, id); | ||
307 | |||
308 | addr = lp8788_select_buck_vout_addr(buck, id); | ||
309 | if (!lp8788_is_valid_buck_addr(addr)) | ||
310 | return -EINVAL; | ||
311 | |||
312 | return lp8788_update_bits(buck->lp, addr, LP8788_VOUT_M, selector); | ||
313 | } | ||
314 | |||
315 | static int lp8788_buck12_get_voltage_sel(struct regulator_dev *rdev) | ||
316 | { | ||
317 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | ||
318 | enum lp8788_buck_id id = rdev_get_id(rdev); | ||
319 | int ret; | ||
320 | u8 val, addr; | ||
321 | |||
322 | addr = lp8788_select_buck_vout_addr(buck, id); | ||
323 | if (!lp8788_is_valid_buck_addr(addr)) | ||
324 | return -EINVAL; | ||
325 | |||
326 | ret = lp8788_read_byte(buck->lp, addr, &val); | ||
327 | if (ret) | ||
328 | return ret; | ||
329 | |||
330 | return val & LP8788_VOUT_M; | ||
331 | } | ||
332 | |||
333 | static int lp8788_buck_enable_time(struct regulator_dev *rdev) | ||
334 | { | ||
335 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | ||
336 | enum lp8788_buck_id id = rdev_get_id(rdev); | ||
337 | u8 val, addr = LP8788_BUCK1_TIMESTEP + id; | ||
338 | |||
339 | if (lp8788_read_byte(buck->lp, addr, &val)) | ||
340 | return -EINVAL; | ||
341 | |||
342 | val = (val & LP8788_STARTUP_TIME_M) >> LP8788_STARTUP_TIME_S; | ||
343 | |||
344 | return ENABLE_TIME_USEC * val; | ||
345 | } | ||
346 | |||
347 | static int lp8788_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) | ||
348 | { | ||
349 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | ||
350 | struct lp8788_pwm_map *pmap = buck->pmap; | ||
351 | u8 val; | ||
352 | |||
353 | if (!pmap) | ||
354 | return -EINVAL; | ||
355 | |||
356 | switch (mode) { | ||
357 | case REGULATOR_MODE_FAST: | ||
358 | val = LP8788_FORCE_PWM << pmap->shift; | ||
359 | break; | ||
360 | case REGULATOR_MODE_NORMAL: | ||
361 | val = LP8788_AUTO_PWM << pmap->shift; | ||
362 | break; | ||
363 | default: | ||
364 | return -EINVAL; | ||
365 | } | ||
366 | |||
367 | return lp8788_update_bits(buck->lp, LP8788_BUCK_PWM, pmap->mask, val); | ||
368 | } | ||
369 | |||
370 | static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev) | ||
371 | { | ||
372 | struct lp8788_buck *buck = rdev_get_drvdata(rdev); | ||
373 | struct lp8788_pwm_map *pmap = buck->pmap; | ||
374 | u8 val; | ||
375 | int ret; | ||
376 | |||
377 | if (!pmap) | ||
378 | return -EINVAL; | ||
379 | |||
380 | ret = lp8788_read_byte(buck->lp, LP8788_BUCK_PWM, &val); | ||
381 | if (ret) | ||
382 | return ret; | ||
383 | |||
384 | return val & pmap->mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; | ||
385 | } | ||
386 | |||
387 | static struct regulator_ops lp8788_buck12_ops = { | ||
388 | .list_voltage = regulator_list_voltage_table, | ||
389 | .set_voltage_sel = lp8788_buck12_set_voltage_sel, | ||
390 | .get_voltage_sel = lp8788_buck12_get_voltage_sel, | ||
391 | .enable = regulator_enable_regmap, | ||
392 | .disable = regulator_disable_regmap, | ||
393 | .is_enabled = regulator_is_enabled_regmap, | ||
394 | .enable_time = lp8788_buck_enable_time, | ||
395 | .set_mode = lp8788_buck_set_mode, | ||
396 | .get_mode = lp8788_buck_get_mode, | ||
397 | }; | ||
398 | |||
399 | static struct regulator_ops lp8788_buck34_ops = { | ||
400 | .list_voltage = regulator_list_voltage_table, | ||
401 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
402 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
403 | .enable = regulator_enable_regmap, | ||
404 | .disable = regulator_disable_regmap, | ||
405 | .is_enabled = regulator_is_enabled_regmap, | ||
406 | .enable_time = lp8788_buck_enable_time, | ||
407 | .set_mode = lp8788_buck_set_mode, | ||
408 | .get_mode = lp8788_buck_get_mode, | ||
409 | }; | ||
410 | |||
411 | static struct regulator_desc lp8788_buck_desc[] = { | ||
412 | { | ||
413 | .name = "buck1", | ||
414 | .id = BUCK1, | ||
415 | .ops = &lp8788_buck12_ops, | ||
416 | .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), | ||
417 | .volt_table = lp8788_buck_vtbl, | ||
418 | .type = REGULATOR_VOLTAGE, | ||
419 | .owner = THIS_MODULE, | ||
420 | .enable_reg = LP8788_EN_BUCK, | ||
421 | .enable_mask = LP8788_EN_BUCK1_M, | ||
422 | }, | ||
423 | { | ||
424 | .name = "buck2", | ||
425 | .id = BUCK2, | ||
426 | .ops = &lp8788_buck12_ops, | ||
427 | .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), | ||
428 | .volt_table = lp8788_buck_vtbl, | ||
429 | .type = REGULATOR_VOLTAGE, | ||
430 | .owner = THIS_MODULE, | ||
431 | .enable_reg = LP8788_EN_BUCK, | ||
432 | .enable_mask = LP8788_EN_BUCK2_M, | ||
433 | }, | ||
434 | { | ||
435 | .name = "buck3", | ||
436 | .id = BUCK3, | ||
437 | .ops = &lp8788_buck34_ops, | ||
438 | .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), | ||
439 | .volt_table = lp8788_buck_vtbl, | ||
440 | .type = REGULATOR_VOLTAGE, | ||
441 | .owner = THIS_MODULE, | ||
442 | .vsel_reg = LP8788_BUCK3_VOUT, | ||
443 | .vsel_mask = LP8788_VOUT_M, | ||
444 | .enable_reg = LP8788_EN_BUCK, | ||
445 | .enable_mask = LP8788_EN_BUCK3_M, | ||
446 | }, | ||
447 | { | ||
448 | .name = "buck4", | ||
449 | .id = BUCK4, | ||
450 | .ops = &lp8788_buck34_ops, | ||
451 | .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), | ||
452 | .volt_table = lp8788_buck_vtbl, | ||
453 | .type = REGULATOR_VOLTAGE, | ||
454 | .owner = THIS_MODULE, | ||
455 | .vsel_reg = LP8788_BUCK4_VOUT, | ||
456 | .vsel_mask = LP8788_VOUT_M, | ||
457 | .enable_reg = LP8788_EN_BUCK, | ||
458 | .enable_mask = LP8788_EN_BUCK4_M, | ||
459 | }, | ||
460 | }; | ||
461 | |||
462 | static int lp8788_set_default_dvs_ctrl_mode(struct lp8788 *lp, | ||
463 | enum lp8788_buck_id id) | ||
464 | { | ||
465 | u8 mask, val; | ||
466 | |||
467 | switch (id) { | ||
468 | case BUCK1: | ||
469 | mask = LP8788_BUCK1_DVS_SEL_M; | ||
470 | val = LP8788_BUCK1_DVS_I2C; | ||
471 | break; | ||
472 | case BUCK2: | ||
473 | mask = LP8788_BUCK2_DVS_SEL_M; | ||
474 | val = LP8788_BUCK2_DVS_I2C; | ||
475 | break; | ||
476 | default: | ||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | return lp8788_update_bits(lp, LP8788_BUCK_DVS_SEL, mask, val); | ||
481 | } | ||
482 | |||
483 | static int _gpio_request(struct lp8788_buck *buck, int gpio, char *name) | ||
484 | { | ||
485 | struct device *dev = buck->lp->dev; | ||
486 | |||
487 | if (!gpio_is_valid(gpio)) { | ||
488 | dev_err(dev, "invalid gpio: %d\n", gpio); | ||
489 | return -EINVAL; | ||
490 | } | ||
491 | |||
492 | return devm_gpio_request_one(dev, gpio, DVS_LOW, name); | ||
493 | } | ||
494 | |||
495 | static int lp8788_dvs_gpio_request(struct lp8788_buck *buck, | ||
496 | enum lp8788_buck_id id) | ||
497 | { | ||
498 | struct lp8788_platform_data *pdata = buck->lp->pdata; | ||
499 | char *b1_name = "LP8788_B1_DVS"; | ||
500 | char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" }; | ||
501 | int i, gpio, ret; | ||
502 | |||
503 | switch (id) { | ||
504 | case BUCK1: | ||
505 | gpio = pdata->buck1_dvs->gpio; | ||
506 | ret = _gpio_request(buck, gpio, b1_name); | ||
507 | if (ret) | ||
508 | return ret; | ||
509 | |||
510 | buck->dvs = pdata->buck1_dvs; | ||
511 | break; | ||
512 | case BUCK2: | ||
513 | for (i = 0 ; i < LP8788_NUM_BUCK2_DVS ; i++) { | ||
514 | gpio = pdata->buck2_dvs->gpio[i]; | ||
515 | ret = _gpio_request(buck, gpio, b2_name[i]); | ||
516 | if (ret) | ||
517 | return ret; | ||
518 | } | ||
519 | buck->dvs = pdata->buck2_dvs; | ||
520 | break; | ||
521 | default: | ||
522 | break; | ||
523 | } | ||
524 | |||
525 | return 0; | ||
526 | } | ||
527 | |||
528 | static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) | ||
529 | { | ||
530 | struct lp8788_platform_data *pdata = buck->lp->pdata; | ||
531 | u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M }; | ||
532 | u8 val[] = { LP8788_BUCK1_DVS_PIN, LP8788_BUCK2_DVS_PIN }; | ||
533 | |||
534 | /* no dvs for buck3, 4 */ | ||
535 | if (id == BUCK3 || id == BUCK4) | ||
536 | return 0; | ||
537 | |||
538 | /* no dvs platform data, then dvs will be selected by I2C registers */ | ||
539 | if (!pdata) | ||
540 | goto set_default_dvs_mode; | ||
541 | |||
542 | if ((id == BUCK1 && !pdata->buck1_dvs) || | ||
543 | (id == BUCK2 && !pdata->buck2_dvs)) | ||
544 | goto set_default_dvs_mode; | ||
545 | |||
546 | if (lp8788_dvs_gpio_request(buck, id)) | ||
547 | goto set_default_dvs_mode; | ||
548 | |||
549 | return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id], | ||
550 | val[id]); | ||
551 | |||
552 | set_default_dvs_mode: | ||
553 | return lp8788_set_default_dvs_ctrl_mode(buck->lp, id); | ||
554 | } | ||
555 | |||
556 | static __devinit int lp8788_buck_probe(struct platform_device *pdev) | ||
557 | { | ||
558 | struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); | ||
559 | int id = pdev->id; | ||
560 | struct lp8788_buck *buck; | ||
561 | struct regulator_config cfg = { }; | ||
562 | struct regulator_dev *rdev; | ||
563 | int ret; | ||
564 | |||
565 | buck = devm_kzalloc(lp->dev, sizeof(struct lp8788_buck), GFP_KERNEL); | ||
566 | if (!buck) | ||
567 | return -ENOMEM; | ||
568 | |||
569 | buck->lp = lp; | ||
570 | buck->pmap = &buck_pmap[id]; | ||
571 | |||
572 | ret = lp8788_init_dvs(buck, id); | ||
573 | if (ret) | ||
574 | return ret; | ||
575 | |||
576 | cfg.dev = lp->dev; | ||
577 | cfg.init_data = lp->pdata ? lp->pdata->buck_data[id] : NULL; | ||
578 | cfg.driver_data = buck; | ||
579 | cfg.regmap = lp->regmap; | ||
580 | |||
581 | rdev = regulator_register(&lp8788_buck_desc[id], &cfg); | ||
582 | if (IS_ERR(rdev)) { | ||
583 | ret = PTR_ERR(rdev); | ||
584 | dev_err(lp->dev, "BUCK%d regulator register err = %d\n", | ||
585 | id + 1, ret); | ||
586 | return ret; | ||
587 | } | ||
588 | |||
589 | buck->regulator = rdev; | ||
590 | platform_set_drvdata(pdev, buck); | ||
591 | |||
592 | return 0; | ||
593 | } | ||
594 | |||
595 | static int __devexit lp8788_buck_remove(struct platform_device *pdev) | ||
596 | { | ||
597 | struct lp8788_buck *buck = platform_get_drvdata(pdev); | ||
598 | |||
599 | platform_set_drvdata(pdev, NULL); | ||
600 | regulator_unregister(buck->regulator); | ||
601 | |||
602 | return 0; | ||
603 | } | ||
604 | |||
605 | static struct platform_driver lp8788_buck_driver = { | ||
606 | .probe = lp8788_buck_probe, | ||
607 | .remove = __devexit_p(lp8788_buck_remove), | ||
608 | .driver = { | ||
609 | .name = LP8788_DEV_BUCK, | ||
610 | .owner = THIS_MODULE, | ||
611 | }, | ||
612 | }; | ||
613 | |||
614 | static int __init lp8788_buck_init(void) | ||
615 | { | ||
616 | return platform_driver_register(&lp8788_buck_driver); | ||
617 | } | ||
618 | subsys_initcall(lp8788_buck_init); | ||
619 | |||
620 | static void __exit lp8788_buck_exit(void) | ||
621 | { | ||
622 | platform_driver_unregister(&lp8788_buck_driver); | ||
623 | } | ||
624 | module_exit(lp8788_buck_exit); | ||
625 | |||
626 | MODULE_DESCRIPTION("TI LP8788 BUCK Driver"); | ||
627 | MODULE_AUTHOR("Milo Kim"); | ||
628 | MODULE_LICENSE("GPL"); | ||
629 | MODULE_ALIAS("platform:lp8788-buck"); | ||
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c new file mode 100644 index 000000000000..d2122e41a96d --- /dev/null +++ b/drivers/regulator/lp8788-ldo.c | |||
@@ -0,0 +1,842 @@ | |||
1 | /* | ||
2 | * TI LP8788 MFD - ldo regulator driver | ||
3 | * | ||
4 | * Copyright 2012 Texas Instruments | ||
5 | * | ||
6 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/regulator/driver.h> | ||
19 | #include <linux/gpio.h> | ||
20 | #include <linux/mfd/lp8788.h> | ||
21 | |||
22 | /* register address */ | ||
23 | #define LP8788_EN_LDO_A 0x0D /* DLDO 1 ~ 8 */ | ||
24 | #define LP8788_EN_LDO_B 0x0E /* DLDO 9 ~ 12, ALDO 1 ~ 4 */ | ||
25 | #define LP8788_EN_LDO_C 0x0F /* ALDO 5 ~ 10 */ | ||
26 | #define LP8788_EN_SEL 0x10 | ||
27 | #define LP8788_DLDO1_VOUT 0x2E | ||
28 | #define LP8788_DLDO2_VOUT 0x2F | ||
29 | #define LP8788_DLDO3_VOUT 0x30 | ||
30 | #define LP8788_DLDO4_VOUT 0x31 | ||
31 | #define LP8788_DLDO5_VOUT 0x32 | ||
32 | #define LP8788_DLDO6_VOUT 0x33 | ||
33 | #define LP8788_DLDO7_VOUT 0x34 | ||
34 | #define LP8788_DLDO8_VOUT 0x35 | ||
35 | #define LP8788_DLDO9_VOUT 0x36 | ||
36 | #define LP8788_DLDO10_VOUT 0x37 | ||
37 | #define LP8788_DLDO11_VOUT 0x38 | ||
38 | #define LP8788_DLDO12_VOUT 0x39 | ||
39 | #define LP8788_ALDO1_VOUT 0x3A | ||
40 | #define LP8788_ALDO2_VOUT 0x3B | ||
41 | #define LP8788_ALDO3_VOUT 0x3C | ||
42 | #define LP8788_ALDO4_VOUT 0x3D | ||
43 | #define LP8788_ALDO5_VOUT 0x3E | ||
44 | #define LP8788_ALDO6_VOUT 0x3F | ||
45 | #define LP8788_ALDO7_VOUT 0x40 | ||
46 | #define LP8788_ALDO8_VOUT 0x41 | ||
47 | #define LP8788_ALDO9_VOUT 0x42 | ||
48 | #define LP8788_ALDO10_VOUT 0x43 | ||
49 | #define LP8788_DLDO1_TIMESTEP 0x44 | ||
50 | |||
51 | /* mask/shift bits */ | ||
52 | #define LP8788_EN_DLDO1_M BIT(0) /* Addr 0Dh ~ 0Fh */ | ||
53 | #define LP8788_EN_DLDO2_M BIT(1) | ||
54 | #define LP8788_EN_DLDO3_M BIT(2) | ||
55 | #define LP8788_EN_DLDO4_M BIT(3) | ||
56 | #define LP8788_EN_DLDO5_M BIT(4) | ||
57 | #define LP8788_EN_DLDO6_M BIT(5) | ||
58 | #define LP8788_EN_DLDO7_M BIT(6) | ||
59 | #define LP8788_EN_DLDO8_M BIT(7) | ||
60 | #define LP8788_EN_DLDO9_M BIT(0) | ||
61 | #define LP8788_EN_DLDO10_M BIT(1) | ||
62 | #define LP8788_EN_DLDO11_M BIT(2) | ||
63 | #define LP8788_EN_DLDO12_M BIT(3) | ||
64 | #define LP8788_EN_ALDO1_M BIT(4) | ||
65 | #define LP8788_EN_ALDO2_M BIT(5) | ||
66 | #define LP8788_EN_ALDO3_M BIT(6) | ||
67 | #define LP8788_EN_ALDO4_M BIT(7) | ||
68 | #define LP8788_EN_ALDO5_M BIT(0) | ||
69 | #define LP8788_EN_ALDO6_M BIT(1) | ||
70 | #define LP8788_EN_ALDO7_M BIT(2) | ||
71 | #define LP8788_EN_ALDO8_M BIT(3) | ||
72 | #define LP8788_EN_ALDO9_M BIT(4) | ||
73 | #define LP8788_EN_ALDO10_M BIT(5) | ||
74 | #define LP8788_EN_SEL_DLDO911_M BIT(0) /* Addr 10h */ | ||
75 | #define LP8788_EN_SEL_DLDO7_M BIT(1) | ||
76 | #define LP8788_EN_SEL_ALDO7_M BIT(2) | ||
77 | #define LP8788_EN_SEL_ALDO5_M BIT(3) | ||
78 | #define LP8788_EN_SEL_ALDO234_M BIT(4) | ||
79 | #define LP8788_EN_SEL_ALDO1_M BIT(5) | ||
80 | #define LP8788_VOUT_5BIT_M 0x1F /* Addr 2Eh ~ 43h */ | ||
81 | #define LP8788_VOUT_4BIT_M 0x0F | ||
82 | #define LP8788_VOUT_3BIT_M 0x07 | ||
83 | #define LP8788_VOUT_1BIT_M 0x01 | ||
84 | #define LP8788_STARTUP_TIME_M 0xF8 /* Addr 44h ~ 59h */ | ||
85 | #define LP8788_STARTUP_TIME_S 3 | ||
86 | |||
87 | #define ENABLE_TIME_USEC 32 | ||
88 | #define ENABLE GPIOF_OUT_INIT_HIGH | ||
89 | #define DISABLE GPIOF_OUT_INIT_LOW | ||
90 | |||
91 | enum lp8788_enable_mode { | ||
92 | REGISTER, | ||
93 | EXTPIN, | ||
94 | }; | ||
95 | |||
96 | enum lp8788_ldo_id { | ||
97 | DLDO1, | ||
98 | DLDO2, | ||
99 | DLDO3, | ||
100 | DLDO4, | ||
101 | DLDO5, | ||
102 | DLDO6, | ||
103 | DLDO7, | ||
104 | DLDO8, | ||
105 | DLDO9, | ||
106 | DLDO10, | ||
107 | DLDO11, | ||
108 | DLDO12, | ||
109 | ALDO1, | ||
110 | ALDO2, | ||
111 | ALDO3, | ||
112 | ALDO4, | ||
113 | ALDO5, | ||
114 | ALDO6, | ||
115 | ALDO7, | ||
116 | ALDO8, | ||
117 | ALDO9, | ||
118 | ALDO10, | ||
119 | }; | ||
120 | |||
121 | struct lp8788_ldo { | ||
122 | struct lp8788 *lp; | ||
123 | struct regulator_desc *desc; | ||
124 | struct regulator_dev *regulator; | ||
125 | struct lp8788_ldo_enable_pin *en_pin; | ||
126 | }; | ||
127 | |||
128 | /* DLDO 1, 2, 3, 9 voltage table */ | ||
129 | const int lp8788_dldo1239_vtbl[] = { | ||
130 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, | ||
131 | 2600000, 2700000, 2800000, 2900000, 3000000, 2850000, 2850000, 2850000, | ||
132 | 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, | ||
133 | 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, 2850000, | ||
134 | }; | ||
135 | |||
136 | /* DLDO 4 voltage table */ | ||
137 | static const int lp8788_dldo4_vtbl[] = { 1800000, 3000000 }; | ||
138 | |||
139 | /* DLDO 5, 7, 8 and ALDO 6 voltage table */ | ||
140 | static const int lp8788_dldo578_aldo6_vtbl[] = { | ||
141 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, | ||
142 | 2600000, 2700000, 2800000, 2900000, 3000000, 3000000, 3000000, 3000000, | ||
143 | }; | ||
144 | |||
145 | /* DLDO 6 voltage table */ | ||
146 | static const int lp8788_dldo6_vtbl[] = { | ||
147 | 3000000, 3100000, 3200000, 3300000, 3400000, 3500000, 3600000, 3600000, | ||
148 | }; | ||
149 | |||
150 | /* DLDO 10, 11 voltage table */ | ||
151 | static const int lp8788_dldo1011_vtbl[] = { | ||
152 | 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, | ||
153 | 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, 1500000, | ||
154 | }; | ||
155 | |||
156 | /* ALDO 1 voltage table */ | ||
157 | static const int lp8788_aldo1_vtbl[] = { 1800000, 2850000 }; | ||
158 | |||
159 | /* ALDO 7 voltage table */ | ||
160 | static const int lp8788_aldo7_vtbl[] = { | ||
161 | 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1800000, | ||
162 | }; | ||
163 | |||
164 | static enum lp8788_ldo_id lp8788_dldo_id[] = { | ||
165 | DLDO1, | ||
166 | DLDO2, | ||
167 | DLDO3, | ||
168 | DLDO4, | ||
169 | DLDO5, | ||
170 | DLDO6, | ||
171 | DLDO7, | ||
172 | DLDO8, | ||
173 | DLDO9, | ||
174 | DLDO10, | ||
175 | DLDO11, | ||
176 | DLDO12, | ||
177 | }; | ||
178 | |||
179 | static enum lp8788_ldo_id lp8788_aldo_id[] = { | ||
180 | ALDO1, | ||
181 | ALDO2, | ||
182 | ALDO3, | ||
183 | ALDO4, | ||
184 | ALDO5, | ||
185 | ALDO6, | ||
186 | ALDO7, | ||
187 | ALDO8, | ||
188 | ALDO9, | ||
189 | ALDO10, | ||
190 | }; | ||
191 | |||
192 | /* DLDO 7, 9 and 11, ALDO 1 ~ 5 and 7 | ||
193 | : can be enabled either by external pin or by i2c register */ | ||
194 | static enum lp8788_enable_mode | ||
195 | lp8788_get_ldo_enable_mode(struct lp8788_ldo *ldo, enum lp8788_ldo_id id) | ||
196 | { | ||
197 | int ret; | ||
198 | u8 val, mask; | ||
199 | |||
200 | ret = lp8788_read_byte(ldo->lp, LP8788_EN_SEL, &val); | ||
201 | if (ret) | ||
202 | return ret; | ||
203 | |||
204 | switch (id) { | ||
205 | case DLDO7: | ||
206 | mask = LP8788_EN_SEL_DLDO7_M; | ||
207 | break; | ||
208 | case DLDO9: | ||
209 | case DLDO11: | ||
210 | mask = LP8788_EN_SEL_DLDO911_M; | ||
211 | break; | ||
212 | case ALDO1: | ||
213 | mask = LP8788_EN_SEL_ALDO1_M; | ||
214 | break; | ||
215 | case ALDO2 ... ALDO4: | ||
216 | mask = LP8788_EN_SEL_ALDO234_M; | ||
217 | break; | ||
218 | case ALDO5: | ||
219 | mask = LP8788_EN_SEL_ALDO5_M; | ||
220 | break; | ||
221 | case ALDO7: | ||
222 | mask = LP8788_EN_SEL_ALDO7_M; | ||
223 | break; | ||
224 | default: | ||
225 | return REGISTER; | ||
226 | } | ||
227 | |||
228 | return val & mask ? EXTPIN : REGISTER; | ||
229 | } | ||
230 | |||
231 | static int lp8788_ldo_ctrl_by_extern_pin(struct lp8788_ldo *ldo, int pinstate) | ||
232 | { | ||
233 | struct lp8788_ldo_enable_pin *pin = ldo->en_pin; | ||
234 | |||
235 | if (!pin) | ||
236 | return -EINVAL; | ||
237 | |||
238 | if (gpio_is_valid(pin->gpio)) | ||
239 | gpio_set_value(pin->gpio, pinstate); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int lp8788_ldo_is_enabled_by_extern_pin(struct lp8788_ldo *ldo) | ||
245 | { | ||
246 | struct lp8788_ldo_enable_pin *pin = ldo->en_pin; | ||
247 | |||
248 | if (!pin) | ||
249 | return -EINVAL; | ||
250 | |||
251 | return gpio_get_value(pin->gpio) ? 1 : 0; | ||
252 | } | ||
253 | |||
254 | static int lp8788_ldo_enable(struct regulator_dev *rdev) | ||
255 | { | ||
256 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | ||
257 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
258 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
259 | |||
260 | switch (mode) { | ||
261 | case EXTPIN: | ||
262 | return lp8788_ldo_ctrl_by_extern_pin(ldo, ENABLE); | ||
263 | case REGISTER: | ||
264 | return regulator_enable_regmap(rdev); | ||
265 | default: | ||
266 | return -EINVAL; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | static int lp8788_ldo_disable(struct regulator_dev *rdev) | ||
271 | { | ||
272 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | ||
273 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
274 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
275 | |||
276 | switch (mode) { | ||
277 | case EXTPIN: | ||
278 | return lp8788_ldo_ctrl_by_extern_pin(ldo, DISABLE); | ||
279 | case REGISTER: | ||
280 | return regulator_disable_regmap(rdev); | ||
281 | default: | ||
282 | return -EINVAL; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | static int lp8788_ldo_is_enabled(struct regulator_dev *rdev) | ||
287 | { | ||
288 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | ||
289 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
290 | enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id); | ||
291 | |||
292 | switch (mode) { | ||
293 | case EXTPIN: | ||
294 | return lp8788_ldo_is_enabled_by_extern_pin(ldo); | ||
295 | case REGISTER: | ||
296 | return regulator_is_enabled_regmap(rdev); | ||
297 | default: | ||
298 | return -EINVAL; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | static int lp8788_ldo_enable_time(struct regulator_dev *rdev) | ||
303 | { | ||
304 | struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); | ||
305 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
306 | u8 val, addr = LP8788_DLDO1_TIMESTEP + id; | ||
307 | |||
308 | if (lp8788_read_byte(ldo->lp, addr, &val)) | ||
309 | return -EINVAL; | ||
310 | |||
311 | val = (val & LP8788_STARTUP_TIME_M) >> LP8788_STARTUP_TIME_S; | ||
312 | |||
313 | return ENABLE_TIME_USEC * val; | ||
314 | } | ||
315 | |||
316 | static int lp8788_ldo_fixed_get_voltage(struct regulator_dev *rdev) | ||
317 | { | ||
318 | enum lp8788_ldo_id id = rdev_get_id(rdev); | ||
319 | |||
320 | switch (id) { | ||
321 | case ALDO2 ... ALDO5: | ||
322 | return 2850000; | ||
323 | case DLDO12: | ||
324 | case ALDO8 ... ALDO9: | ||
325 | return 2500000; | ||
326 | case ALDO10: | ||
327 | return 1100000; | ||
328 | default: | ||
329 | return -EINVAL; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | static struct regulator_ops lp8788_ldo_voltage_table_ops = { | ||
334 | .list_voltage = regulator_list_voltage_table, | ||
335 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
336 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
337 | .enable = lp8788_ldo_enable, | ||
338 | .disable = lp8788_ldo_disable, | ||
339 | .is_enabled = lp8788_ldo_is_enabled, | ||
340 | .enable_time = lp8788_ldo_enable_time, | ||
341 | }; | ||
342 | |||
343 | static struct regulator_ops lp8788_ldo_voltage_fixed_ops = { | ||
344 | .get_voltage = lp8788_ldo_fixed_get_voltage, | ||
345 | .enable = lp8788_ldo_enable, | ||
346 | .disable = lp8788_ldo_disable, | ||
347 | .is_enabled = lp8788_ldo_is_enabled, | ||
348 | .enable_time = lp8788_ldo_enable_time, | ||
349 | }; | ||
350 | |||
351 | static struct regulator_desc lp8788_dldo_desc[] = { | ||
352 | { | ||
353 | .name = "dldo1", | ||
354 | .id = DLDO1, | ||
355 | .ops = &lp8788_ldo_voltage_table_ops, | ||
356 | .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl), | ||
357 | .volt_table = lp8788_dldo1239_vtbl, | ||
358 | .type = REGULATOR_VOLTAGE, | ||
359 | .owner = THIS_MODULE, | ||
360 | .vsel_reg = LP8788_DLDO1_VOUT, | ||
361 | .vsel_mask = LP8788_VOUT_5BIT_M, | ||
362 | .enable_reg = LP8788_EN_LDO_A, | ||
363 | .enable_mask = LP8788_EN_DLDO1_M, | ||
364 | }, | ||
365 | { | ||
366 | .name = "dldo2", | ||
367 | .id = DLDO2, | ||
368 | .ops = &lp8788_ldo_voltage_table_ops, | ||
369 | .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl), | ||
370 | .volt_table = lp8788_dldo1239_vtbl, | ||
371 | .type = REGULATOR_VOLTAGE, | ||
372 | .owner = THIS_MODULE, | ||
373 | .vsel_reg = LP8788_DLDO2_VOUT, | ||
374 | .vsel_mask = LP8788_VOUT_5BIT_M, | ||
375 | .enable_reg = LP8788_EN_LDO_A, | ||
376 | .enable_mask = LP8788_EN_DLDO2_M, | ||
377 | }, | ||
378 | { | ||
379 | .name = "dldo3", | ||
380 | .id = DLDO3, | ||
381 | .ops = &lp8788_ldo_voltage_table_ops, | ||
382 | .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl), | ||
383 | .volt_table = lp8788_dldo1239_vtbl, | ||
384 | .type = REGULATOR_VOLTAGE, | ||
385 | .owner = THIS_MODULE, | ||
386 | .vsel_reg = LP8788_DLDO3_VOUT, | ||
387 | .vsel_mask = LP8788_VOUT_5BIT_M, | ||
388 | .enable_reg = LP8788_EN_LDO_A, | ||
389 | .enable_mask = LP8788_EN_DLDO3_M, | ||
390 | }, | ||
391 | { | ||
392 | .name = "dldo4", | ||
393 | .id = DLDO4, | ||
394 | .ops = &lp8788_ldo_voltage_table_ops, | ||
395 | .n_voltages = ARRAY_SIZE(lp8788_dldo4_vtbl), | ||
396 | .volt_table = lp8788_dldo4_vtbl, | ||
397 | .type = REGULATOR_VOLTAGE, | ||
398 | .owner = THIS_MODULE, | ||
399 | .vsel_reg = LP8788_DLDO4_VOUT, | ||
400 | .vsel_mask = LP8788_VOUT_1BIT_M, | ||
401 | .enable_reg = LP8788_EN_LDO_A, | ||
402 | .enable_mask = LP8788_EN_DLDO4_M, | ||
403 | }, | ||
404 | { | ||
405 | .name = "dldo5", | ||
406 | .id = DLDO5, | ||
407 | .ops = &lp8788_ldo_voltage_table_ops, | ||
408 | .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl), | ||
409 | .volt_table = lp8788_dldo578_aldo6_vtbl, | ||
410 | .type = REGULATOR_VOLTAGE, | ||
411 | .owner = THIS_MODULE, | ||
412 | .vsel_reg = LP8788_DLDO5_VOUT, | ||
413 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
414 | .enable_reg = LP8788_EN_LDO_A, | ||
415 | .enable_mask = LP8788_EN_DLDO5_M, | ||
416 | }, | ||
417 | { | ||
418 | .name = "dldo6", | ||
419 | .id = DLDO6, | ||
420 | .ops = &lp8788_ldo_voltage_table_ops, | ||
421 | .n_voltages = ARRAY_SIZE(lp8788_dldo6_vtbl), | ||
422 | .volt_table = lp8788_dldo6_vtbl, | ||
423 | .type = REGULATOR_VOLTAGE, | ||
424 | .owner = THIS_MODULE, | ||
425 | .vsel_reg = LP8788_DLDO6_VOUT, | ||
426 | .vsel_mask = LP8788_VOUT_3BIT_M, | ||
427 | .enable_reg = LP8788_EN_LDO_A, | ||
428 | .enable_mask = LP8788_EN_DLDO6_M, | ||
429 | }, | ||
430 | { | ||
431 | .name = "dldo7", | ||
432 | .id = DLDO7, | ||
433 | .ops = &lp8788_ldo_voltage_table_ops, | ||
434 | .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl), | ||
435 | .volt_table = lp8788_dldo578_aldo6_vtbl, | ||
436 | .type = REGULATOR_VOLTAGE, | ||
437 | .owner = THIS_MODULE, | ||
438 | .vsel_reg = LP8788_DLDO7_VOUT, | ||
439 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
440 | .enable_reg = LP8788_EN_LDO_A, | ||
441 | .enable_mask = LP8788_EN_DLDO7_M, | ||
442 | }, | ||
443 | { | ||
444 | .name = "dldo8", | ||
445 | .id = DLDO8, | ||
446 | .ops = &lp8788_ldo_voltage_table_ops, | ||
447 | .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl), | ||
448 | .volt_table = lp8788_dldo578_aldo6_vtbl, | ||
449 | .type = REGULATOR_VOLTAGE, | ||
450 | .owner = THIS_MODULE, | ||
451 | .vsel_reg = LP8788_DLDO8_VOUT, | ||
452 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
453 | .enable_reg = LP8788_EN_LDO_A, | ||
454 | .enable_mask = LP8788_EN_DLDO8_M, | ||
455 | }, | ||
456 | { | ||
457 | .name = "dldo9", | ||
458 | .id = DLDO9, | ||
459 | .ops = &lp8788_ldo_voltage_table_ops, | ||
460 | .n_voltages = ARRAY_SIZE(lp8788_dldo1239_vtbl), | ||
461 | .volt_table = lp8788_dldo1239_vtbl, | ||
462 | .type = REGULATOR_VOLTAGE, | ||
463 | .owner = THIS_MODULE, | ||
464 | .vsel_reg = LP8788_DLDO9_VOUT, | ||
465 | .vsel_mask = LP8788_VOUT_5BIT_M, | ||
466 | .enable_reg = LP8788_EN_LDO_B, | ||
467 | .enable_mask = LP8788_EN_DLDO9_M, | ||
468 | }, | ||
469 | { | ||
470 | .name = "dldo10", | ||
471 | .id = DLDO10, | ||
472 | .ops = &lp8788_ldo_voltage_table_ops, | ||
473 | .n_voltages = ARRAY_SIZE(lp8788_dldo1011_vtbl), | ||
474 | .volt_table = lp8788_dldo1011_vtbl, | ||
475 | .type = REGULATOR_VOLTAGE, | ||
476 | .owner = THIS_MODULE, | ||
477 | .vsel_reg = LP8788_DLDO10_VOUT, | ||
478 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
479 | .enable_reg = LP8788_EN_LDO_B, | ||
480 | .enable_mask = LP8788_EN_DLDO10_M, | ||
481 | }, | ||
482 | { | ||
483 | .name = "dldo11", | ||
484 | .id = DLDO11, | ||
485 | .ops = &lp8788_ldo_voltage_table_ops, | ||
486 | .n_voltages = ARRAY_SIZE(lp8788_dldo1011_vtbl), | ||
487 | .volt_table = lp8788_dldo1011_vtbl, | ||
488 | .type = REGULATOR_VOLTAGE, | ||
489 | .owner = THIS_MODULE, | ||
490 | .vsel_reg = LP8788_DLDO11_VOUT, | ||
491 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
492 | .enable_reg = LP8788_EN_LDO_B, | ||
493 | .enable_mask = LP8788_EN_DLDO11_M, | ||
494 | }, | ||
495 | { | ||
496 | .name = "dldo12", | ||
497 | .id = DLDO12, | ||
498 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
499 | .type = REGULATOR_VOLTAGE, | ||
500 | .owner = THIS_MODULE, | ||
501 | .enable_reg = LP8788_EN_LDO_B, | ||
502 | .enable_mask = LP8788_EN_DLDO12_M, | ||
503 | }, | ||
504 | }; | ||
505 | |||
506 | static struct regulator_desc lp8788_aldo_desc[] = { | ||
507 | { | ||
508 | .name = "aldo1", | ||
509 | .id = ALDO1, | ||
510 | .ops = &lp8788_ldo_voltage_table_ops, | ||
511 | .n_voltages = ARRAY_SIZE(lp8788_aldo1_vtbl), | ||
512 | .volt_table = lp8788_aldo1_vtbl, | ||
513 | .type = REGULATOR_VOLTAGE, | ||
514 | .owner = THIS_MODULE, | ||
515 | .vsel_reg = LP8788_ALDO1_VOUT, | ||
516 | .vsel_mask = LP8788_VOUT_1BIT_M, | ||
517 | .enable_reg = LP8788_EN_LDO_B, | ||
518 | .enable_mask = LP8788_EN_ALDO1_M, | ||
519 | }, | ||
520 | { | ||
521 | .name = "aldo2", | ||
522 | .id = ALDO2, | ||
523 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
524 | .type = REGULATOR_VOLTAGE, | ||
525 | .owner = THIS_MODULE, | ||
526 | .enable_reg = LP8788_EN_LDO_B, | ||
527 | .enable_mask = LP8788_EN_ALDO2_M, | ||
528 | }, | ||
529 | { | ||
530 | .name = "aldo3", | ||
531 | .id = ALDO3, | ||
532 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
533 | .type = REGULATOR_VOLTAGE, | ||
534 | .owner = THIS_MODULE, | ||
535 | .enable_reg = LP8788_EN_LDO_B, | ||
536 | .enable_mask = LP8788_EN_ALDO3_M, | ||
537 | }, | ||
538 | { | ||
539 | .name = "aldo4", | ||
540 | .id = ALDO4, | ||
541 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
542 | .type = REGULATOR_VOLTAGE, | ||
543 | .owner = THIS_MODULE, | ||
544 | .enable_reg = LP8788_EN_LDO_B, | ||
545 | .enable_mask = LP8788_EN_ALDO4_M, | ||
546 | }, | ||
547 | { | ||
548 | .name = "aldo5", | ||
549 | .id = ALDO5, | ||
550 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
551 | .type = REGULATOR_VOLTAGE, | ||
552 | .owner = THIS_MODULE, | ||
553 | .enable_reg = LP8788_EN_LDO_C, | ||
554 | .enable_mask = LP8788_EN_ALDO5_M, | ||
555 | }, | ||
556 | { | ||
557 | .name = "aldo6", | ||
558 | .id = ALDO6, | ||
559 | .ops = &lp8788_ldo_voltage_table_ops, | ||
560 | .n_voltages = ARRAY_SIZE(lp8788_dldo578_aldo6_vtbl), | ||
561 | .volt_table = lp8788_dldo578_aldo6_vtbl, | ||
562 | .type = REGULATOR_VOLTAGE, | ||
563 | .owner = THIS_MODULE, | ||
564 | .vsel_reg = LP8788_ALDO6_VOUT, | ||
565 | .vsel_mask = LP8788_VOUT_4BIT_M, | ||
566 | .enable_reg = LP8788_EN_LDO_C, | ||
567 | .enable_mask = LP8788_EN_ALDO6_M, | ||
568 | }, | ||
569 | { | ||
570 | .name = "aldo7", | ||
571 | .id = ALDO7, | ||
572 | .ops = &lp8788_ldo_voltage_table_ops, | ||
573 | .n_voltages = ARRAY_SIZE(lp8788_aldo7_vtbl), | ||
574 | .volt_table = lp8788_aldo7_vtbl, | ||
575 | .type = REGULATOR_VOLTAGE, | ||
576 | .owner = THIS_MODULE, | ||
577 | .vsel_reg = LP8788_ALDO7_VOUT, | ||
578 | .vsel_mask = LP8788_VOUT_3BIT_M, | ||
579 | .enable_reg = LP8788_EN_LDO_C, | ||
580 | .enable_mask = LP8788_EN_ALDO7_M, | ||
581 | }, | ||
582 | { | ||
583 | .name = "aldo8", | ||
584 | .id = ALDO8, | ||
585 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
586 | .type = REGULATOR_VOLTAGE, | ||
587 | .owner = THIS_MODULE, | ||
588 | .enable_reg = LP8788_EN_LDO_C, | ||
589 | .enable_mask = LP8788_EN_ALDO8_M, | ||
590 | }, | ||
591 | { | ||
592 | .name = "aldo9", | ||
593 | .id = ALDO9, | ||
594 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
595 | .type = REGULATOR_VOLTAGE, | ||
596 | .owner = THIS_MODULE, | ||
597 | .enable_reg = LP8788_EN_LDO_C, | ||
598 | .enable_mask = LP8788_EN_ALDO9_M, | ||
599 | }, | ||
600 | { | ||
601 | .name = "aldo10", | ||
602 | .id = ALDO10, | ||
603 | .ops = &lp8788_ldo_voltage_fixed_ops, | ||
604 | .type = REGULATOR_VOLTAGE, | ||
605 | .owner = THIS_MODULE, | ||
606 | .enable_reg = LP8788_EN_LDO_C, | ||
607 | .enable_mask = LP8788_EN_ALDO10_M, | ||
608 | }, | ||
609 | }; | ||
610 | |||
611 | static int lp8788_gpio_request_ldo_en(struct lp8788_ldo *ldo, | ||
612 | enum lp8788_ext_ldo_en_id id) | ||
613 | { | ||
614 | struct device *dev = ldo->lp->dev; | ||
615 | struct lp8788_ldo_enable_pin *pin = ldo->en_pin; | ||
616 | int ret, gpio, pinstate; | ||
617 | char *name[] = { | ||
618 | [EN_ALDO1] = "LP8788_EN_ALDO1", | ||
619 | [EN_ALDO234] = "LP8788_EN_ALDO234", | ||
620 | [EN_ALDO5] = "LP8788_EN_ALDO5", | ||
621 | [EN_ALDO7] = "LP8788_EN_ALDO7", | ||
622 | [EN_DLDO7] = "LP8788_EN_DLDO7", | ||
623 | [EN_DLDO911] = "LP8788_EN_DLDO911", | ||
624 | }; | ||
625 | |||
626 | gpio = pin->gpio; | ||
627 | if (!gpio_is_valid(gpio)) { | ||
628 | dev_err(dev, "invalid gpio: %d\n", gpio); | ||
629 | return -EINVAL; | ||
630 | } | ||
631 | |||
632 | pinstate = pin->init_state; | ||
633 | ret = devm_gpio_request_one(dev, gpio, pinstate, name[id]); | ||
634 | if (ret == -EBUSY) { | ||
635 | dev_warn(dev, "gpio%d already used\n", gpio); | ||
636 | return 0; | ||
637 | } | ||
638 | |||
639 | return ret; | ||
640 | } | ||
641 | |||
642 | static int lp8788_config_ldo_enable_mode(struct lp8788_ldo *ldo, | ||
643 | enum lp8788_ldo_id id) | ||
644 | { | ||
645 | int ret; | ||
646 | struct lp8788 *lp = ldo->lp; | ||
647 | struct lp8788_platform_data *pdata = lp->pdata; | ||
648 | enum lp8788_ext_ldo_en_id enable_id; | ||
649 | u8 en_mask[] = { | ||
650 | [EN_ALDO1] = LP8788_EN_SEL_ALDO1_M, | ||
651 | [EN_ALDO234] = LP8788_EN_SEL_ALDO234_M, | ||
652 | [EN_ALDO5] = LP8788_EN_SEL_ALDO5_M, | ||
653 | [EN_ALDO7] = LP8788_EN_SEL_ALDO7_M, | ||
654 | [EN_DLDO7] = LP8788_EN_SEL_DLDO7_M, | ||
655 | [EN_DLDO911] = LP8788_EN_SEL_DLDO911_M, | ||
656 | }; | ||
657 | u8 val[] = { | ||
658 | [EN_ALDO1] = 0 << 5, | ||
659 | [EN_ALDO234] = 0 << 4, | ||
660 | [EN_ALDO5] = 0 << 3, | ||
661 | [EN_ALDO7] = 0 << 2, | ||
662 | [EN_DLDO7] = 0 << 1, | ||
663 | [EN_DLDO911] = 0 << 0, | ||
664 | }; | ||
665 | |||
666 | switch (id) { | ||
667 | case DLDO7: | ||
668 | enable_id = EN_DLDO7; | ||
669 | break; | ||
670 | case DLDO9: | ||
671 | case DLDO11: | ||
672 | enable_id = EN_DLDO911; | ||
673 | break; | ||
674 | case ALDO1: | ||
675 | enable_id = EN_ALDO1; | ||
676 | break; | ||
677 | case ALDO2 ... ALDO4: | ||
678 | enable_id = EN_ALDO234; | ||
679 | break; | ||
680 | case ALDO5: | ||
681 | enable_id = EN_ALDO5; | ||
682 | break; | ||
683 | case ALDO7: | ||
684 | enable_id = EN_ALDO7; | ||
685 | break; | ||
686 | default: | ||
687 | return 0; | ||
688 | } | ||
689 | |||
690 | /* if no platform data for ldo pin, then set default enable mode */ | ||
691 | if (!pdata || !pdata->ldo_pin || !pdata->ldo_pin[enable_id]) | ||
692 | goto set_default_ldo_enable_mode; | ||
693 | |||
694 | ldo->en_pin = pdata->ldo_pin[enable_id]; | ||
695 | |||
696 | ret = lp8788_gpio_request_ldo_en(ldo, enable_id); | ||
697 | if (ret) | ||
698 | goto set_default_ldo_enable_mode; | ||
699 | |||
700 | return ret; | ||
701 | |||
702 | set_default_ldo_enable_mode: | ||
703 | return lp8788_update_bits(lp, LP8788_EN_SEL, en_mask[enable_id], | ||
704 | val[enable_id]); | ||
705 | } | ||
706 | |||
707 | static __devinit int lp8788_dldo_probe(struct platform_device *pdev) | ||
708 | { | ||
709 | struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); | ||
710 | int id = pdev->id; | ||
711 | struct lp8788_ldo *ldo; | ||
712 | struct regulator_config cfg = { }; | ||
713 | struct regulator_dev *rdev; | ||
714 | int ret; | ||
715 | |||
716 | ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); | ||
717 | if (!ldo) | ||
718 | return -ENOMEM; | ||
719 | |||
720 | ldo->lp = lp; | ||
721 | ret = lp8788_config_ldo_enable_mode(ldo, lp8788_dldo_id[id]); | ||
722 | if (ret) | ||
723 | return ret; | ||
724 | |||
725 | cfg.dev = lp->dev; | ||
726 | cfg.init_data = lp->pdata ? lp->pdata->dldo_data[id] : NULL; | ||
727 | cfg.driver_data = ldo; | ||
728 | cfg.regmap = lp->regmap; | ||
729 | |||
730 | rdev = regulator_register(&lp8788_dldo_desc[id], &cfg); | ||
731 | if (IS_ERR(rdev)) { | ||
732 | ret = PTR_ERR(rdev); | ||
733 | dev_err(lp->dev, "DLDO%d regulator register err = %d\n", | ||
734 | id + 1, ret); | ||
735 | return ret; | ||
736 | } | ||
737 | |||
738 | ldo->regulator = rdev; | ||
739 | platform_set_drvdata(pdev, ldo); | ||
740 | |||
741 | return 0; | ||
742 | } | ||
743 | |||
744 | static int __devexit lp8788_dldo_remove(struct platform_device *pdev) | ||
745 | { | ||
746 | struct lp8788_ldo *ldo = platform_get_drvdata(pdev); | ||
747 | |||
748 | platform_set_drvdata(pdev, NULL); | ||
749 | regulator_unregister(ldo->regulator); | ||
750 | |||
751 | return 0; | ||
752 | } | ||
753 | |||
754 | static struct platform_driver lp8788_dldo_driver = { | ||
755 | .probe = lp8788_dldo_probe, | ||
756 | .remove = __devexit_p(lp8788_dldo_remove), | ||
757 | .driver = { | ||
758 | .name = LP8788_DEV_DLDO, | ||
759 | .owner = THIS_MODULE, | ||
760 | }, | ||
761 | }; | ||
762 | |||
763 | static __devinit int lp8788_aldo_probe(struct platform_device *pdev) | ||
764 | { | ||
765 | struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); | ||
766 | int id = pdev->id; | ||
767 | struct lp8788_ldo *ldo; | ||
768 | struct regulator_config cfg = { }; | ||
769 | struct regulator_dev *rdev; | ||
770 | int ret; | ||
771 | |||
772 | ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); | ||
773 | if (!ldo) | ||
774 | return -ENOMEM; | ||
775 | |||
776 | ldo->lp = lp; | ||
777 | ret = lp8788_config_ldo_enable_mode(ldo, lp8788_aldo_id[id]); | ||
778 | if (ret) | ||
779 | return ret; | ||
780 | |||
781 | cfg.dev = lp->dev; | ||
782 | cfg.init_data = lp->pdata ? lp->pdata->aldo_data[id] : NULL; | ||
783 | cfg.driver_data = ldo; | ||
784 | cfg.regmap = lp->regmap; | ||
785 | |||
786 | rdev = regulator_register(&lp8788_aldo_desc[id], &cfg); | ||
787 | if (IS_ERR(rdev)) { | ||
788 | ret = PTR_ERR(rdev); | ||
789 | dev_err(lp->dev, "ALDO%d regulator register err = %d\n", | ||
790 | id + 1, ret); | ||
791 | return ret; | ||
792 | } | ||
793 | |||
794 | ldo->regulator = rdev; | ||
795 | platform_set_drvdata(pdev, ldo); | ||
796 | |||
797 | return 0; | ||
798 | } | ||
799 | |||
800 | static int __devexit lp8788_aldo_remove(struct platform_device *pdev) | ||
801 | { | ||
802 | struct lp8788_ldo *ldo = platform_get_drvdata(pdev); | ||
803 | |||
804 | platform_set_drvdata(pdev, NULL); | ||
805 | regulator_unregister(ldo->regulator); | ||
806 | |||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | static struct platform_driver lp8788_aldo_driver = { | ||
811 | .probe = lp8788_aldo_probe, | ||
812 | .remove = __devexit_p(lp8788_aldo_remove), | ||
813 | .driver = { | ||
814 | .name = LP8788_DEV_ALDO, | ||
815 | .owner = THIS_MODULE, | ||
816 | }, | ||
817 | }; | ||
818 | |||
819 | static int __init lp8788_ldo_init(void) | ||
820 | { | ||
821 | int ret; | ||
822 | |||
823 | ret = platform_driver_register(&lp8788_dldo_driver); | ||
824 | if (ret) | ||
825 | return ret; | ||
826 | |||
827 | return platform_driver_register(&lp8788_aldo_driver); | ||
828 | } | ||
829 | subsys_initcall(lp8788_ldo_init); | ||
830 | |||
831 | static void __exit lp8788_ldo_exit(void) | ||
832 | { | ||
833 | platform_driver_unregister(&lp8788_aldo_driver); | ||
834 | platform_driver_unregister(&lp8788_dldo_driver); | ||
835 | } | ||
836 | module_exit(lp8788_ldo_exit); | ||
837 | |||
838 | MODULE_DESCRIPTION("TI LP8788 LDO Driver"); | ||
839 | MODULE_AUTHOR("Milo Kim"); | ||
840 | MODULE_LICENSE("GPL"); | ||
841 | MODULE_ALIAS("platform:lp8788-dldo"); | ||
842 | MODULE_ALIAS("platform:lp8788-aldo"); | ||
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index b9444ee08da9..f67af3c1b963 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c | |||
@@ -48,6 +48,14 @@ struct max1586_data { | |||
48 | }; | 48 | }; |
49 | 49 | ||
50 | /* | 50 | /* |
51 | * V6 voltage | ||
52 | * On I2C bus, sending a "x" byte to the max1586 means : | ||
53 | * set V6 to either 0V, 1.8V, 2.5V, 3V depending on (x & 0x3) | ||
54 | * As regulator framework doesn't accept voltages to be 0V, we use 1uV. | ||
55 | */ | ||
56 | static int v6_voltages_uv[] = { 1, 1800000, 2500000, 3000000 }; | ||
57 | |||
58 | /* | ||
51 | * V3 voltage | 59 | * V3 voltage |
52 | * On I2C bus, sending a "x" byte to the max1586 means : | 60 | * On I2C bus, sending a "x" byte to the max1586 means : |
53 | * set V3 to 0.700V + (x & 0x1f) * 0.025V | 61 | * set V3 to 0.700V + (x & 0x1f) * 0.025V |
@@ -55,113 +63,49 @@ struct max1586_data { | |||
55 | * R24 and R25=100kOhm as described in the data sheet. | 63 | * R24 and R25=100kOhm as described in the data sheet. |
56 | * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm | 64 | * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm |
57 | */ | 65 | */ |
58 | static int max1586_v3_calc_voltage(struct max1586_data *max1586, | 66 | static int max1586_v3_set_voltage_sel(struct regulator_dev *rdev, |
59 | unsigned selector) | 67 | unsigned selector) |
60 | { | ||
61 | unsigned range_uV = max1586->max_uV - max1586->min_uV; | ||
62 | |||
63 | return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL); | ||
64 | } | ||
65 | |||
66 | static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV, | ||
67 | unsigned *selector) | ||
68 | { | 68 | { |
69 | struct max1586_data *max1586 = rdev_get_drvdata(rdev); | 69 | struct max1586_data *max1586 = rdev_get_drvdata(rdev); |
70 | struct i2c_client *client = max1586->client; | 70 | struct i2c_client *client = max1586->client; |
71 | unsigned range_uV = max1586->max_uV - max1586->min_uV; | ||
72 | u8 v3_prog; | 71 | u8 v3_prog; |
73 | 72 | ||
74 | if (min_uV > max1586->max_uV || max_uV < max1586->min_uV) | ||
75 | return -EINVAL; | ||
76 | if (min_uV < max1586->min_uV) | ||
77 | min_uV = max1586->min_uV; | ||
78 | |||
79 | *selector = DIV_ROUND_UP((min_uV - max1586->min_uV) * | ||
80 | MAX1586_V3_MAX_VSEL, range_uV); | ||
81 | if (max1586_v3_calc_voltage(max1586, *selector) > max_uV) | ||
82 | return -EINVAL; | ||
83 | |||
84 | dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", | 73 | dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", |
85 | max1586_v3_calc_voltage(max1586, *selector) / 1000); | 74 | regulator_list_voltage_linear(rdev, selector) / 1000); |
86 | 75 | ||
87 | v3_prog = I2C_V3_SELECT | (u8) *selector; | 76 | v3_prog = I2C_V3_SELECT | (u8) selector; |
88 | return i2c_smbus_write_byte(client, v3_prog); | 77 | return i2c_smbus_write_byte(client, v3_prog); |
89 | } | 78 | } |
90 | 79 | ||
91 | static int max1586_v3_list(struct regulator_dev *rdev, unsigned selector) | 80 | static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev, |
92 | { | 81 | unsigned int selector) |
93 | struct max1586_data *max1586 = rdev_get_drvdata(rdev); | ||
94 | |||
95 | if (selector > MAX1586_V3_MAX_VSEL) | ||
96 | return -EINVAL; | ||
97 | return max1586_v3_calc_voltage(max1586, selector); | ||
98 | } | ||
99 | |||
100 | /* | ||
101 | * V6 voltage | ||
102 | * On I2C bus, sending a "x" byte to the max1586 means : | ||
103 | * set V6 to either 0V, 1.8V, 2.5V, 3V depending on (x & 0x3) | ||
104 | * As regulator framework doesn't accept voltages to be 0V, we use 1uV. | ||
105 | */ | ||
106 | static int max1586_v6_calc_voltage(unsigned selector) | ||
107 | { | ||
108 | static int voltages_uv[] = { 1, 1800000, 2500000, 3000000 }; | ||
109 | |||
110 | return voltages_uv[selector]; | ||
111 | } | ||
112 | |||
113 | static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV, | ||
114 | unsigned int *selector) | ||
115 | { | 82 | { |
116 | struct i2c_client *client = rdev_get_drvdata(rdev); | 83 | struct i2c_client *client = rdev_get_drvdata(rdev); |
117 | u8 v6_prog; | 84 | u8 v6_prog; |
118 | 85 | ||
119 | if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV) | ||
120 | return -EINVAL; | ||
121 | if (max_uV < MAX1586_V6_MIN_UV || max_uV > MAX1586_V6_MAX_UV) | ||
122 | return -EINVAL; | ||
123 | |||
124 | if (min_uV < 1800000) | ||
125 | *selector = 0; | ||
126 | else if (min_uV < 2500000) | ||
127 | *selector = 1; | ||
128 | else if (min_uV < 3000000) | ||
129 | *selector = 2; | ||
130 | else if (min_uV >= 3000000) | ||
131 | *selector = 3; | ||
132 | |||
133 | if (max1586_v6_calc_voltage(*selector) > max_uV) | ||
134 | return -EINVAL; | ||
135 | |||
136 | dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", | 86 | dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", |
137 | max1586_v6_calc_voltage(*selector) / 1000); | 87 | rdev->desc->volt_table[selector] / 1000); |
138 | 88 | ||
139 | v6_prog = I2C_V6_SELECT | (u8) *selector; | 89 | v6_prog = I2C_V6_SELECT | (u8) selector; |
140 | return i2c_smbus_write_byte(client, v6_prog); | 90 | return i2c_smbus_write_byte(client, v6_prog); |
141 | } | 91 | } |
142 | 92 | ||
143 | static int max1586_v6_list(struct regulator_dev *rdev, unsigned selector) | ||
144 | { | ||
145 | if (selector > MAX1586_V6_MAX_VSEL) | ||
146 | return -EINVAL; | ||
147 | return max1586_v6_calc_voltage(selector); | ||
148 | } | ||
149 | |||
150 | /* | 93 | /* |
151 | * The Maxim 1586 controls V3 and V6 voltages, but offers no way of reading back | 94 | * The Maxim 1586 controls V3 and V6 voltages, but offers no way of reading back |
152 | * the set up value. | 95 | * the set up value. |
153 | */ | 96 | */ |
154 | static struct regulator_ops max1586_v3_ops = { | 97 | static struct regulator_ops max1586_v3_ops = { |
155 | .set_voltage = max1586_v3_set, | 98 | .set_voltage_sel = max1586_v3_set_voltage_sel, |
156 | .list_voltage = max1586_v3_list, | 99 | .list_voltage = regulator_list_voltage_linear, |
100 | .map_voltage = regulator_map_voltage_linear, | ||
157 | }; | 101 | }; |
158 | 102 | ||
159 | static struct regulator_ops max1586_v6_ops = { | 103 | static struct regulator_ops max1586_v6_ops = { |
160 | .set_voltage = max1586_v6_set, | 104 | .set_voltage_sel = max1586_v6_set_voltage_sel, |
161 | .list_voltage = max1586_v6_list, | 105 | .list_voltage = regulator_list_voltage_table, |
162 | }; | 106 | }; |
163 | 107 | ||
164 | static const struct regulator_desc max1586_reg[] = { | 108 | static struct regulator_desc max1586_reg[] = { |
165 | { | 109 | { |
166 | .name = "Output_V3", | 110 | .name = "Output_V3", |
167 | .id = MAX1586_V3, | 111 | .id = MAX1586_V3, |
@@ -176,6 +120,7 @@ static const struct regulator_desc max1586_reg[] = { | |||
176 | .ops = &max1586_v6_ops, | 120 | .ops = &max1586_v6_ops, |
177 | .type = REGULATOR_VOLTAGE, | 121 | .type = REGULATOR_VOLTAGE, |
178 | .n_voltages = MAX1586_V6_MAX_VSEL + 1, | 122 | .n_voltages = MAX1586_V6_MAX_VSEL + 1, |
123 | .volt_table = v6_voltages_uv, | ||
179 | .owner = THIS_MODULE, | 124 | .owner = THIS_MODULE, |
180 | }, | 125 | }, |
181 | }; | 126 | }; |
@@ -213,6 +158,13 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client, | |||
213 | goto err; | 158 | goto err; |
214 | } | 159 | } |
215 | 160 | ||
161 | if (id == MAX1586_V3) { | ||
162 | max1586_reg[id].min_uV = max1586->min_uV; | ||
163 | max1586_reg[id].uV_step = | ||
164 | (max1586->max_uV - max1586->min_uV) / | ||
165 | MAX1586_V3_MAX_VSEL; | ||
166 | } | ||
167 | |||
216 | config.dev = &client->dev; | 168 | config.dev = &client->dev; |
217 | config.init_data = pdata->subdevs[i].platform_data; | 169 | config.init_data = pdata->subdevs[i].platform_data; |
218 | config.driver_data = max1586; | 170 | config.driver_data = max1586; |
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c new file mode 100644 index 000000000000..c564af6f05a3 --- /dev/null +++ b/drivers/regulator/max77686.c | |||
@@ -0,0 +1,389 @@ | |||
1 | /* | ||
2 | * max77686.c - Regulator driver for the Maxim 77686 | ||
3 | * | ||
4 | * Copyright (C) 2012 Samsung Electronics | ||
5 | * Chiwoong Byun <woong.byun@smasung.com> | ||
6 | * Jonghwa Lee <jonghwa3.lee@samsung.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | * This driver is based on max8997.c | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/bug.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/gpio.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/regulator/driver.h> | ||
33 | #include <linux/regulator/machine.h> | ||
34 | #include <linux/regulator/of_regulator.h> | ||
35 | #include <linux/mfd/max77686.h> | ||
36 | #include <linux/mfd/max77686-private.h> | ||
37 | |||
38 | #define MAX77686_LDO_MINUV 800000 | ||
39 | #define MAX77686_LDO_UVSTEP 50000 | ||
40 | #define MAX77686_LDO_LOW_MINUV 800000 | ||
41 | #define MAX77686_LDO_LOW_UVSTEP 25000 | ||
42 | #define MAX77686_BUCK_MINUV 750000 | ||
43 | #define MAX77686_BUCK_UVSTEP 50000 | ||
44 | #define MAX77686_RAMP_DELAY 100000 /* uV/us */ | ||
45 | #define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ | ||
46 | #define MAX77686_DVS_MINUV 600000 | ||
47 | #define MAX77686_DVS_UVSTEP 12500 | ||
48 | |||
49 | #define MAX77686_OPMODE_SHIFT 6 | ||
50 | #define MAX77686_OPMODE_BUCK234_SHIFT 4 | ||
51 | #define MAX77686_OPMODE_MASK 0x3 | ||
52 | |||
53 | #define MAX77686_VSEL_MASK 0x3F | ||
54 | #define MAX77686_DVS_VSEL_MASK 0xFF | ||
55 | |||
56 | #define MAX77686_RAMP_RATE_MASK 0xC0 | ||
57 | |||
58 | #define MAX77686_REGULATORS MAX77686_REG_MAX | ||
59 | #define MAX77686_LDOS 26 | ||
60 | |||
61 | enum max77686_ramp_rate { | ||
62 | RAMP_RATE_13P75MV, | ||
63 | RAMP_RATE_27P5MV, | ||
64 | RAMP_RATE_55MV, | ||
65 | RAMP_RATE_NO_CTRL, /* 100mV/us */ | ||
66 | }; | ||
67 | |||
68 | struct max77686_data { | ||
69 | struct regulator_dev **rdev; | ||
70 | }; | ||
71 | |||
72 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) | ||
73 | { | ||
74 | unsigned int ramp_value = RAMP_RATE_NO_CTRL; | ||
75 | |||
76 | switch (ramp_delay) { | ||
77 | case 1 ... 13750: | ||
78 | ramp_value = RAMP_RATE_13P75MV; | ||
79 | break; | ||
80 | case 13751 ... 27500: | ||
81 | ramp_value = RAMP_RATE_27P5MV; | ||
82 | break; | ||
83 | case 27501 ... 55000: | ||
84 | ramp_value = RAMP_RATE_55MV; | ||
85 | break; | ||
86 | case 55001 ... 100000: | ||
87 | break; | ||
88 | default: | ||
89 | pr_warn("%s: ramp_delay: %d not supported, setting 100000\n", | ||
90 | rdev->desc->name, ramp_delay); | ||
91 | } | ||
92 | |||
93 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | ||
94 | MAX77686_RAMP_RATE_MASK, ramp_value << 6); | ||
95 | } | ||
96 | |||
97 | static struct regulator_ops max77686_ops = { | ||
98 | .list_voltage = regulator_list_voltage_linear, | ||
99 | .map_voltage = regulator_map_voltage_linear, | ||
100 | .is_enabled = regulator_is_enabled_regmap, | ||
101 | .enable = regulator_enable_regmap, | ||
102 | .disable = regulator_disable_regmap, | ||
103 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
104 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
105 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
106 | }; | ||
107 | |||
108 | static struct regulator_ops max77686_buck_dvs_ops = { | ||
109 | .list_voltage = regulator_list_voltage_linear, | ||
110 | .map_voltage = regulator_map_voltage_linear, | ||
111 | .is_enabled = regulator_is_enabled_regmap, | ||
112 | .enable = regulator_enable_regmap, | ||
113 | .disable = regulator_disable_regmap, | ||
114 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
115 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
116 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
117 | .set_ramp_delay = max77686_set_ramp_delay, | ||
118 | }; | ||
119 | |||
120 | #define regulator_desc_ldo(num) { \ | ||
121 | .name = "LDO"#num, \ | ||
122 | .id = MAX77686_LDO##num, \ | ||
123 | .ops = &max77686_ops, \ | ||
124 | .type = REGULATOR_VOLTAGE, \ | ||
125 | .owner = THIS_MODULE, \ | ||
126 | .min_uV = MAX77686_LDO_MINUV, \ | ||
127 | .uV_step = MAX77686_LDO_UVSTEP, \ | ||
128 | .ramp_delay = MAX77686_RAMP_DELAY, \ | ||
129 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | ||
130 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | ||
131 | .vsel_mask = MAX77686_VSEL_MASK, \ | ||
132 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | ||
133 | .enable_mask = MAX77686_OPMODE_MASK \ | ||
134 | << MAX77686_OPMODE_SHIFT, \ | ||
135 | } | ||
136 | #define regulator_desc_ldo_low(num) { \ | ||
137 | .name = "LDO"#num, \ | ||
138 | .id = MAX77686_LDO##num, \ | ||
139 | .ops = &max77686_ops, \ | ||
140 | .type = REGULATOR_VOLTAGE, \ | ||
141 | .owner = THIS_MODULE, \ | ||
142 | .min_uV = MAX77686_LDO_LOW_MINUV, \ | ||
143 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ | ||
144 | .ramp_delay = MAX77686_RAMP_DELAY, \ | ||
145 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | ||
146 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | ||
147 | .vsel_mask = MAX77686_VSEL_MASK, \ | ||
148 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ | ||
149 | .enable_mask = MAX77686_OPMODE_MASK \ | ||
150 | << MAX77686_OPMODE_SHIFT, \ | ||
151 | } | ||
152 | #define regulator_desc_buck(num) { \ | ||
153 | .name = "BUCK"#num, \ | ||
154 | .id = MAX77686_BUCK##num, \ | ||
155 | .ops = &max77686_ops, \ | ||
156 | .type = REGULATOR_VOLTAGE, \ | ||
157 | .owner = THIS_MODULE, \ | ||
158 | .min_uV = MAX77686_BUCK_MINUV, \ | ||
159 | .uV_step = MAX77686_BUCK_UVSTEP, \ | ||
160 | .ramp_delay = MAX77686_RAMP_DELAY, \ | ||
161 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | ||
162 | .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ | ||
163 | .vsel_mask = MAX77686_VSEL_MASK, \ | ||
164 | .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \ | ||
165 | .enable_mask = MAX77686_OPMODE_MASK, \ | ||
166 | } | ||
167 | #define regulator_desc_buck1(num) { \ | ||
168 | .name = "BUCK"#num, \ | ||
169 | .id = MAX77686_BUCK##num, \ | ||
170 | .ops = &max77686_ops, \ | ||
171 | .type = REGULATOR_VOLTAGE, \ | ||
172 | .owner = THIS_MODULE, \ | ||
173 | .min_uV = MAX77686_BUCK_MINUV, \ | ||
174 | .uV_step = MAX77686_BUCK_UVSTEP, \ | ||
175 | .ramp_delay = MAX77686_RAMP_DELAY, \ | ||
176 | .n_voltages = MAX77686_VSEL_MASK + 1, \ | ||
177 | .vsel_reg = MAX77686_REG_BUCK1OUT, \ | ||
178 | .vsel_mask = MAX77686_VSEL_MASK, \ | ||
179 | .enable_reg = MAX77686_REG_BUCK1CTRL, \ | ||
180 | .enable_mask = MAX77686_OPMODE_MASK, \ | ||
181 | } | ||
182 | #define regulator_desc_buck_dvs(num) { \ | ||
183 | .name = "BUCK"#num, \ | ||
184 | .id = MAX77686_BUCK##num, \ | ||
185 | .ops = &max77686_buck_dvs_ops, \ | ||
186 | .type = REGULATOR_VOLTAGE, \ | ||
187 | .owner = THIS_MODULE, \ | ||
188 | .min_uV = MAX77686_DVS_MINUV, \ | ||
189 | .uV_step = MAX77686_DVS_UVSTEP, \ | ||
190 | .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ | ||
191 | .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ | ||
192 | .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ | ||
193 | .vsel_mask = MAX77686_DVS_VSEL_MASK, \ | ||
194 | .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ | ||
195 | .enable_mask = MAX77686_OPMODE_MASK \ | ||
196 | << MAX77686_OPMODE_BUCK234_SHIFT, \ | ||
197 | } | ||
198 | |||
199 | static struct regulator_desc regulators[] = { | ||
200 | regulator_desc_ldo_low(1), | ||
201 | regulator_desc_ldo_low(2), | ||
202 | regulator_desc_ldo(3), | ||
203 | regulator_desc_ldo(4), | ||
204 | regulator_desc_ldo(5), | ||
205 | regulator_desc_ldo_low(6), | ||
206 | regulator_desc_ldo_low(7), | ||
207 | regulator_desc_ldo_low(8), | ||
208 | regulator_desc_ldo(9), | ||
209 | regulator_desc_ldo(10), | ||
210 | regulator_desc_ldo(11), | ||
211 | regulator_desc_ldo(12), | ||
212 | regulator_desc_ldo(13), | ||
213 | regulator_desc_ldo(14), | ||
214 | regulator_desc_ldo_low(15), | ||
215 | regulator_desc_ldo(16), | ||
216 | regulator_desc_ldo(17), | ||
217 | regulator_desc_ldo(18), | ||
218 | regulator_desc_ldo(19), | ||
219 | regulator_desc_ldo(20), | ||
220 | regulator_desc_ldo(21), | ||
221 | regulator_desc_ldo(22), | ||
222 | regulator_desc_ldo(23), | ||
223 | regulator_desc_ldo(24), | ||
224 | regulator_desc_ldo(25), | ||
225 | regulator_desc_ldo(26), | ||
226 | regulator_desc_buck1(1), | ||
227 | regulator_desc_buck_dvs(2), | ||
228 | regulator_desc_buck_dvs(3), | ||
229 | regulator_desc_buck_dvs(4), | ||
230 | regulator_desc_buck(5), | ||
231 | regulator_desc_buck(6), | ||
232 | regulator_desc_buck(7), | ||
233 | regulator_desc_buck(8), | ||
234 | regulator_desc_buck(9), | ||
235 | }; | ||
236 | |||
237 | #ifdef CONFIG_OF | ||
238 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, | ||
239 | struct max77686_platform_data *pdata) | ||
240 | { | ||
241 | struct device_node *pmic_np, *regulators_np; | ||
242 | struct max77686_regulator_data *rdata; | ||
243 | struct of_regulator_match rmatch; | ||
244 | unsigned int i; | ||
245 | |||
246 | pmic_np = iodev->dev->of_node; | ||
247 | regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators"); | ||
248 | if (!regulators_np) { | ||
249 | dev_err(iodev->dev, "could not find regulators sub-node\n"); | ||
250 | return -EINVAL; | ||
251 | } | ||
252 | |||
253 | pdata->num_regulators = ARRAY_SIZE(regulators); | ||
254 | rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * | ||
255 | pdata->num_regulators, GFP_KERNEL); | ||
256 | if (!rdata) { | ||
257 | dev_err(iodev->dev, | ||
258 | "could not allocate memory for regulator data\n"); | ||
259 | return -ENOMEM; | ||
260 | } | ||
261 | |||
262 | for (i = 0; i < pdata->num_regulators; i++) { | ||
263 | rmatch.name = regulators[i].name; | ||
264 | rmatch.init_data = NULL; | ||
265 | rmatch.of_node = NULL; | ||
266 | of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); | ||
267 | rdata[i].initdata = rmatch.init_data; | ||
268 | } | ||
269 | |||
270 | pdata->regulators = rdata; | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | #else | ||
275 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, | ||
276 | struct max77686_platform_data *pdata) | ||
277 | { | ||
278 | return 0; | ||
279 | } | ||
280 | #endif /* CONFIG_OF */ | ||
281 | |||
282 | static __devinit int max77686_pmic_probe(struct platform_device *pdev) | ||
283 | { | ||
284 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); | ||
285 | struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev); | ||
286 | struct regulator_dev **rdev; | ||
287 | struct max77686_data *max77686; | ||
288 | int i, size; | ||
289 | int ret = 0; | ||
290 | struct regulator_config config = { }; | ||
291 | |||
292 | dev_dbg(&pdev->dev, "%s\n", __func__); | ||
293 | |||
294 | if (!pdata) { | ||
295 | dev_err(&pdev->dev, "no platform data found for regulator\n"); | ||
296 | return -ENODEV; | ||
297 | } | ||
298 | |||
299 | if (iodev->dev->of_node) { | ||
300 | ret = max77686_pmic_dt_parse_pdata(iodev, pdata); | ||
301 | if (ret) | ||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | if (pdata->num_regulators != MAX77686_REGULATORS) { | ||
306 | dev_err(&pdev->dev, | ||
307 | "Invalid initial data for regulator's initialiation\n"); | ||
308 | return -EINVAL; | ||
309 | } | ||
310 | |||
311 | max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), | ||
312 | GFP_KERNEL); | ||
313 | if (!max77686) | ||
314 | return -ENOMEM; | ||
315 | |||
316 | size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS; | ||
317 | max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | ||
318 | if (!max77686->rdev) | ||
319 | return -ENOMEM; | ||
320 | |||
321 | rdev = max77686->rdev; | ||
322 | config.dev = &pdev->dev; | ||
323 | config.regmap = iodev->regmap; | ||
324 | platform_set_drvdata(pdev, max77686); | ||
325 | |||
326 | for (i = 0; i < MAX77686_REGULATORS; i++) { | ||
327 | config.init_data = pdata->regulators[i].initdata; | ||
328 | |||
329 | rdev[i] = regulator_register(®ulators[i], &config); | ||
330 | if (IS_ERR(rdev[i])) { | ||
331 | ret = PTR_ERR(rdev[i]); | ||
332 | dev_err(&pdev->dev, | ||
333 | "regulator init failed for %d\n", i); | ||
334 | rdev[i] = NULL; | ||
335 | goto err; | ||
336 | } | ||
337 | } | ||
338 | |||
339 | return 0; | ||
340 | err: | ||
341 | while (--i >= 0) | ||
342 | regulator_unregister(rdev[i]); | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | static int __devexit max77686_pmic_remove(struct platform_device *pdev) | ||
347 | { | ||
348 | struct max77686_data *max77686 = platform_get_drvdata(pdev); | ||
349 | struct regulator_dev **rdev = max77686->rdev; | ||
350 | int i; | ||
351 | |||
352 | for (i = 0; i < MAX77686_REGULATORS; i++) | ||
353 | if (rdev[i]) | ||
354 | regulator_unregister(rdev[i]); | ||
355 | |||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static const struct platform_device_id max77686_pmic_id[] = { | ||
360 | {"max77686-pmic", 0}, | ||
361 | { }, | ||
362 | }; | ||
363 | MODULE_DEVICE_TABLE(platform, max77686_pmic_id); | ||
364 | |||
365 | static struct platform_driver max77686_pmic_driver = { | ||
366 | .driver = { | ||
367 | .name = "max77686-pmic", | ||
368 | .owner = THIS_MODULE, | ||
369 | }, | ||
370 | .probe = max77686_pmic_probe, | ||
371 | .remove = __devexit_p(max77686_pmic_remove), | ||
372 | .id_table = max77686_pmic_id, | ||
373 | }; | ||
374 | |||
375 | static int __init max77686_pmic_init(void) | ||
376 | { | ||
377 | return platform_driver_register(&max77686_pmic_driver); | ||
378 | } | ||
379 | subsys_initcall(max77686_pmic_init); | ||
380 | |||
381 | static void __exit max77686_pmic_cleanup(void) | ||
382 | { | ||
383 | platform_driver_unregister(&max77686_pmic_driver); | ||
384 | } | ||
385 | module_exit(max77686_pmic_cleanup); | ||
386 | |||
387 | MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); | ||
388 | MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); | ||
389 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c index 910c9b26d499..355ca7bad9d5 100644 --- a/drivers/regulator/max8952.c +++ b/drivers/regulator/max8952.c | |||
@@ -51,7 +51,6 @@ struct max8952_data { | |||
51 | 51 | ||
52 | bool vid0; | 52 | bool vid0; |
53 | bool vid1; | 53 | bool vid1; |
54 | bool en; | ||
55 | }; | 54 | }; |
56 | 55 | ||
57 | static int max8952_read_reg(struct max8952_data *max8952, u8 reg) | 56 | static int max8952_read_reg(struct max8952_data *max8952, u8 reg) |
@@ -80,38 +79,6 @@ static int max8952_list_voltage(struct regulator_dev *rdev, | |||
80 | return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000; | 79 | return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000; |
81 | } | 80 | } |
82 | 81 | ||
83 | static int max8952_is_enabled(struct regulator_dev *rdev) | ||
84 | { | ||
85 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | ||
86 | return max8952->en; | ||
87 | } | ||
88 | |||
89 | static int max8952_enable(struct regulator_dev *rdev) | ||
90 | { | ||
91 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | ||
92 | |||
93 | /* If not valid, assume "ALWAYS_HIGH" */ | ||
94 | if (gpio_is_valid(max8952->pdata->gpio_en)) | ||
95 | gpio_set_value(max8952->pdata->gpio_en, 1); | ||
96 | |||
97 | max8952->en = true; | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | static int max8952_disable(struct regulator_dev *rdev) | ||
102 | { | ||
103 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | ||
104 | |||
105 | /* If not valid, assume "ALWAYS_HIGH" -> not permitted */ | ||
106 | if (gpio_is_valid(max8952->pdata->gpio_en)) | ||
107 | gpio_set_value(max8952->pdata->gpio_en, 0); | ||
108 | else | ||
109 | return -EPERM; | ||
110 | |||
111 | max8952->en = false; | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int max8952_get_voltage_sel(struct regulator_dev *rdev) | 82 | static int max8952_get_voltage_sel(struct regulator_dev *rdev) |
116 | { | 83 | { |
117 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | 84 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); |
@@ -146,12 +113,8 @@ static int max8952_set_voltage_sel(struct regulator_dev *rdev, | |||
146 | 113 | ||
147 | static struct regulator_ops max8952_ops = { | 114 | static struct regulator_ops max8952_ops = { |
148 | .list_voltage = max8952_list_voltage, | 115 | .list_voltage = max8952_list_voltage, |
149 | .is_enabled = max8952_is_enabled, | ||
150 | .enable = max8952_enable, | ||
151 | .disable = max8952_disable, | ||
152 | .get_voltage_sel = max8952_get_voltage_sel, | 116 | .get_voltage_sel = max8952_get_voltage_sel, |
153 | .set_voltage_sel = max8952_set_voltage_sel, | 117 | .set_voltage_sel = max8952_set_voltage_sel, |
154 | .set_suspend_disable = max8952_disable, | ||
155 | }; | 118 | }; |
156 | 119 | ||
157 | static const struct regulator_desc regulator = { | 120 | static const struct regulator_desc regulator = { |
@@ -194,6 +157,10 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
194 | config.init_data = &pdata->reg_data; | 157 | config.init_data = &pdata->reg_data; |
195 | config.driver_data = max8952; | 158 | config.driver_data = max8952; |
196 | 159 | ||
160 | config.ena_gpio = pdata->gpio_en; | ||
161 | if (pdata->reg_data.constraints.boot_on) | ||
162 | config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; | ||
163 | |||
197 | max8952->rdev = regulator_register(®ulator, &config); | 164 | max8952->rdev = regulator_register(®ulator, &config); |
198 | 165 | ||
199 | if (IS_ERR(max8952->rdev)) { | 166 | if (IS_ERR(max8952->rdev)) { |
@@ -202,27 +169,9 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
202 | return ret; | 169 | return ret; |
203 | } | 170 | } |
204 | 171 | ||
205 | max8952->en = !!(pdata->reg_data.constraints.boot_on); | ||
206 | max8952->vid0 = pdata->default_mode & 0x1; | 172 | max8952->vid0 = pdata->default_mode & 0x1; |
207 | max8952->vid1 = (pdata->default_mode >> 1) & 0x1; | 173 | max8952->vid1 = (pdata->default_mode >> 1) & 0x1; |
208 | 174 | ||
209 | if (gpio_is_valid(pdata->gpio_en)) { | ||
210 | if (!gpio_request(pdata->gpio_en, "MAX8952 EN")) | ||
211 | gpio_direction_output(pdata->gpio_en, max8952->en); | ||
212 | else | ||
213 | err = 1; | ||
214 | } else | ||
215 | err = 2; | ||
216 | |||
217 | if (err) { | ||
218 | dev_info(max8952->dev, "EN gpio invalid: assume that EN" | ||
219 | "is always High\n"); | ||
220 | max8952->en = 1; | ||
221 | pdata->gpio_en = -1; /* Mark invalid */ | ||
222 | } | ||
223 | |||
224 | err = 0; | ||
225 | |||
226 | if (gpio_is_valid(pdata->gpio_vid0) && | 175 | if (gpio_is_valid(pdata->gpio_vid0) && |
227 | gpio_is_valid(pdata->gpio_vid1)) { | 176 | gpio_is_valid(pdata->gpio_vid1)) { |
228 | if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) | 177 | if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) |
@@ -308,7 +257,6 @@ static int __devexit max8952_pmic_remove(struct i2c_client *client) | |||
308 | 257 | ||
309 | gpio_free(pdata->gpio_vid0); | 258 | gpio_free(pdata->gpio_vid0); |
310 | gpio_free(pdata->gpio_vid1); | 259 | gpio_free(pdata->gpio_vid1); |
311 | gpio_free(pdata->gpio_en); | ||
312 | return 0; | 260 | return 0; |
313 | } | 261 | } |
314 | 262 | ||
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 704cd49ef375..e39a0c7260dc 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c | |||
@@ -1025,7 +1025,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1025 | */ | 1025 | */ |
1026 | if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || | 1026 | if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || |
1027 | pdata->buck5_gpiodvs) { | 1027 | pdata->buck5_gpiodvs) { |
1028 | bool gpio1set = false, gpio2set = false; | ||
1029 | 1028 | ||
1030 | if (!gpio_is_valid(pdata->buck125_gpios[0]) || | 1029 | if (!gpio_is_valid(pdata->buck125_gpios[0]) || |
1031 | !gpio_is_valid(pdata->buck125_gpios[1]) || | 1030 | !gpio_is_valid(pdata->buck125_gpios[1]) || |
@@ -1035,40 +1034,20 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1035 | goto err_out; | 1034 | goto err_out; |
1036 | } | 1035 | } |
1037 | 1036 | ||
1038 | ret = gpio_request(pdata->buck125_gpios[0], | 1037 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], |
1039 | "MAX8997 SET1"); | 1038 | "MAX8997 SET1"); |
1040 | if (ret == -EBUSY) | 1039 | if (ret) |
1041 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1042 | " on SET1\n"); | ||
1043 | else if (ret) | ||
1044 | goto err_out; | 1040 | goto err_out; |
1045 | else | 1041 | |
1046 | gpio1set = true; | 1042 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], |
1047 | 1043 | "MAX8997 SET2"); | |
1048 | ret = gpio_request(pdata->buck125_gpios[1], | 1044 | if (ret) |
1049 | "MAX8997 SET2"); | ||
1050 | if (ret == -EBUSY) | ||
1051 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1052 | " on SET2\n"); | ||
1053 | else if (ret) { | ||
1054 | if (gpio1set) | ||
1055 | gpio_free(pdata->buck125_gpios[0]); | ||
1056 | goto err_out; | 1045 | goto err_out; |
1057 | } else | ||
1058 | gpio2set = true; | ||
1059 | 1046 | ||
1060 | ret = gpio_request(pdata->buck125_gpios[2], | 1047 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], |
1061 | "MAX8997 SET3"); | 1048 | "MAX8997 SET3"); |
1062 | if (ret == -EBUSY) | 1049 | if (ret) |
1063 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1064 | " on SET3\n"); | ||
1065 | else if (ret) { | ||
1066 | if (gpio1set) | ||
1067 | gpio_free(pdata->buck125_gpios[0]); | ||
1068 | if (gpio2set) | ||
1069 | gpio_free(pdata->buck125_gpios[1]); | ||
1070 | goto err_out; | 1050 | goto err_out; |
1071 | } | ||
1072 | 1051 | ||
1073 | gpio_direction_output(pdata->buck125_gpios[0], | 1052 | gpio_direction_output(pdata->buck125_gpios[0], |
1074 | (max8997->buck125_gpioindex >> 2) | 1053 | (max8997->buck125_gpioindex >> 2) |
@@ -1079,7 +1058,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1079 | gpio_direction_output(pdata->buck125_gpios[2], | 1058 | gpio_direction_output(pdata->buck125_gpios[2], |
1080 | (max8997->buck125_gpioindex >> 0) | 1059 | (max8997->buck125_gpioindex >> 0) |
1081 | & 0x1); /* SET3 */ | 1060 | & 0x1); /* SET3 */ |
1082 | ret = 0; | ||
1083 | } | 1061 | } |
1084 | 1062 | ||
1085 | /* DVS-GPIO disabled */ | 1063 | /* DVS-GPIO disabled */ |
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 18bb58b9b96e..5dfa920ff0c8 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c | |||
@@ -111,27 +111,6 @@ static const struct voltage_map_desc *ldo_voltage_map[] = { | |||
111 | &buck4_voltage_map_desc, /* BUCK4 */ | 111 | &buck4_voltage_map_desc, /* BUCK4 */ |
112 | }; | 112 | }; |
113 | 113 | ||
114 | static int max8998_list_voltage(struct regulator_dev *rdev, | ||
115 | unsigned int selector) | ||
116 | { | ||
117 | const struct voltage_map_desc *desc; | ||
118 | int ldo = rdev_get_id(rdev); | ||
119 | int val; | ||
120 | |||
121 | if (ldo >= ARRAY_SIZE(ldo_voltage_map)) | ||
122 | return -EINVAL; | ||
123 | |||
124 | desc = ldo_voltage_map[ldo]; | ||
125 | if (desc == NULL) | ||
126 | return -EINVAL; | ||
127 | |||
128 | val = desc->min + desc->step * selector; | ||
129 | if (val > desc->max) | ||
130 | return -EINVAL; | ||
131 | |||
132 | return val * 1000; | ||
133 | } | ||
134 | |||
135 | static int max8998_get_enable_register(struct regulator_dev *rdev, | 114 | static int max8998_get_enable_register(struct regulator_dev *rdev, |
136 | int *reg, int *shift) | 115 | int *reg, int *shift) |
137 | { | 116 | { |
@@ -297,41 +276,18 @@ static int max8998_get_voltage_sel(struct regulator_dev *rdev) | |||
297 | return val; | 276 | return val; |
298 | } | 277 | } |
299 | 278 | ||
300 | static int max8998_set_voltage_ldo(struct regulator_dev *rdev, | 279 | static int max8998_set_voltage_ldo_sel(struct regulator_dev *rdev, |
301 | int min_uV, int max_uV, unsigned *selector) | 280 | unsigned selector) |
302 | { | 281 | { |
303 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 282 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
304 | struct i2c_client *i2c = max8998->iodev->i2c; | 283 | struct i2c_client *i2c = max8998->iodev->i2c; |
305 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | 284 | int reg, shift = 0, mask, ret; |
306 | const struct voltage_map_desc *desc; | ||
307 | int ldo = rdev_get_id(rdev); | ||
308 | int reg, shift = 0, mask, ret, i; | ||
309 | |||
310 | if (ldo >= ARRAY_SIZE(ldo_voltage_map)) | ||
311 | return -EINVAL; | ||
312 | |||
313 | desc = ldo_voltage_map[ldo]; | ||
314 | if (desc == NULL) | ||
315 | return -EINVAL; | ||
316 | |||
317 | if (max_vol < desc->min || min_vol > desc->max) | ||
318 | return -EINVAL; | ||
319 | |||
320 | if (min_vol < desc->min) | ||
321 | min_vol = desc->min; | ||
322 | |||
323 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); | ||
324 | |||
325 | if (desc->min + desc->step*i > max_vol) | ||
326 | return -EINVAL; | ||
327 | |||
328 | *selector = i; | ||
329 | 285 | ||
330 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); | 286 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); |
331 | if (ret) | 287 | if (ret) |
332 | return ret; | 288 | return ret; |
333 | 289 | ||
334 | ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); | 290 | ret = max8998_update_reg(i2c, reg, selector<<shift, mask<<shift); |
335 | 291 | ||
336 | return ret; | 292 | return ret; |
337 | } | 293 | } |
@@ -347,41 +303,18 @@ static inline void buck2_gpio_set(int gpio, int v) | |||
347 | gpio_set_value(gpio, v & 0x1); | 303 | gpio_set_value(gpio, v & 0x1); |
348 | } | 304 | } |
349 | 305 | ||
350 | static int max8998_set_voltage_buck(struct regulator_dev *rdev, | 306 | static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev, |
351 | int min_uV, int max_uV, unsigned *selector) | 307 | unsigned selector) |
352 | { | 308 | { |
353 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 309 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
354 | struct max8998_platform_data *pdata = | 310 | struct max8998_platform_data *pdata = |
355 | dev_get_platdata(max8998->iodev->dev); | 311 | dev_get_platdata(max8998->iodev->dev); |
356 | struct i2c_client *i2c = max8998->iodev->i2c; | 312 | struct i2c_client *i2c = max8998->iodev->i2c; |
357 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
358 | const struct voltage_map_desc *desc; | ||
359 | int buck = rdev_get_id(rdev); | 313 | int buck = rdev_get_id(rdev); |
360 | int reg, shift = 0, mask, ret; | 314 | int reg, shift = 0, mask, ret; |
361 | int i, j, previous_sel; | 315 | int j, previous_sel; |
362 | static u8 buck1_last_val; | 316 | static u8 buck1_last_val; |
363 | 317 | ||
364 | if (buck >= ARRAY_SIZE(ldo_voltage_map)) | ||
365 | return -EINVAL; | ||
366 | |||
367 | desc = ldo_voltage_map[buck]; | ||
368 | |||
369 | if (desc == NULL) | ||
370 | return -EINVAL; | ||
371 | |||
372 | if (max_vol < desc->min || min_vol > desc->max) | ||
373 | return -EINVAL; | ||
374 | |||
375 | if (min_vol < desc->min) | ||
376 | min_vol = desc->min; | ||
377 | |||
378 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); | ||
379 | |||
380 | if (desc->min + desc->step*i > max_vol) | ||
381 | return -EINVAL; | ||
382 | |||
383 | *selector = i; | ||
384 | |||
385 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); | 318 | ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); |
386 | if (ret) | 319 | if (ret) |
387 | return ret; | 320 | return ret; |
@@ -390,19 +323,19 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
390 | 323 | ||
391 | /* Check if voltage needs to be changed */ | 324 | /* Check if voltage needs to be changed */ |
392 | /* if previous_voltage equal new voltage, return */ | 325 | /* if previous_voltage equal new voltage, return */ |
393 | if (previous_sel == i) { | 326 | if (previous_sel == selector) { |
394 | dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", | 327 | dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", |
395 | max8998_list_voltage(rdev, previous_sel), | 328 | regulator_list_voltage_linear(rdev, previous_sel), |
396 | max8998_list_voltage(rdev, i)); | 329 | regulator_list_voltage_linear(rdev, selector)); |
397 | return ret; | 330 | return ret; |
398 | } | 331 | } |
399 | 332 | ||
400 | switch (buck) { | 333 | switch (buck) { |
401 | case MAX8998_BUCK1: | 334 | case MAX8998_BUCK1: |
402 | dev_dbg(max8998->dev, | 335 | dev_dbg(max8998->dev, |
403 | "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n" | 336 | "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n" |
404 | "buck1_vol3:%d, buck1_vol4:%d\n", | 337 | "buck1_vol3:%d, buck1_vol4:%d\n", |
405 | i, max8998->buck1_vol[0], max8998->buck1_vol[1], | 338 | selector, max8998->buck1_vol[0], max8998->buck1_vol[1], |
406 | max8998->buck1_vol[2], max8998->buck1_vol[3]); | 339 | max8998->buck1_vol[2], max8998->buck1_vol[3]); |
407 | 340 | ||
408 | if (gpio_is_valid(pdata->buck1_set1) && | 341 | if (gpio_is_valid(pdata->buck1_set1) && |
@@ -411,7 +344,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
411 | /* check if requested voltage */ | 344 | /* check if requested voltage */ |
412 | /* value is already defined */ | 345 | /* value is already defined */ |
413 | for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { | 346 | for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { |
414 | if (max8998->buck1_vol[j] == i) { | 347 | if (max8998->buck1_vol[j] == selector) { |
415 | max8998->buck1_idx = j; | 348 | max8998->buck1_idx = j; |
416 | buck1_gpio_set(pdata->buck1_set1, | 349 | buck1_gpio_set(pdata->buck1_set1, |
417 | pdata->buck1_set2, j); | 350 | pdata->buck1_set2, j); |
@@ -426,11 +359,11 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
426 | max8998->buck1_idx = (buck1_last_val % 2) + 2; | 359 | max8998->buck1_idx = (buck1_last_val % 2) + 2; |
427 | dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", | 360 | dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", |
428 | max8998->buck1_idx); | 361 | max8998->buck1_idx); |
429 | max8998->buck1_vol[max8998->buck1_idx] = i; | 362 | max8998->buck1_vol[max8998->buck1_idx] = selector; |
430 | ret = max8998_get_voltage_register(rdev, ®, | 363 | ret = max8998_get_voltage_register(rdev, ®, |
431 | &shift, | 364 | &shift, |
432 | &mask); | 365 | &mask); |
433 | ret = max8998_write_reg(i2c, reg, i); | 366 | ret = max8998_write_reg(i2c, reg, selector); |
434 | buck1_gpio_set(pdata->buck1_set1, | 367 | buck1_gpio_set(pdata->buck1_set1, |
435 | pdata->buck1_set2, max8998->buck1_idx); | 368 | pdata->buck1_set2, max8998->buck1_idx); |
436 | buck1_last_val++; | 369 | buck1_last_val++; |
@@ -440,20 +373,20 @@ buck1_exit: | |||
440 | gpio_get_value(pdata->buck1_set2)); | 373 | gpio_get_value(pdata->buck1_set2)); |
441 | break; | 374 | break; |
442 | } else { | 375 | } else { |
443 | ret = max8998_write_reg(i2c, reg, i); | 376 | ret = max8998_write_reg(i2c, reg, selector); |
444 | } | 377 | } |
445 | break; | 378 | break; |
446 | 379 | ||
447 | case MAX8998_BUCK2: | 380 | case MAX8998_BUCK2: |
448 | dev_dbg(max8998->dev, | 381 | dev_dbg(max8998->dev, |
449 | "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" | 382 | "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n", |
450 | , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); | 383 | selector, max8998->buck2_vol[0], max8998->buck2_vol[1]); |
451 | if (gpio_is_valid(pdata->buck2_set3)) { | 384 | if (gpio_is_valid(pdata->buck2_set3)) { |
452 | 385 | ||
453 | /* check if requested voltage */ | 386 | /* check if requested voltage */ |
454 | /* value is already defined */ | 387 | /* value is already defined */ |
455 | for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { | 388 | for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { |
456 | if (max8998->buck2_vol[j] == i) { | 389 | if (max8998->buck2_vol[j] == selector) { |
457 | max8998->buck2_idx = j; | 390 | max8998->buck2_idx = j; |
458 | buck2_gpio_set(pdata->buck2_set3, j); | 391 | buck2_gpio_set(pdata->buck2_set3, j); |
459 | goto buck2_exit; | 392 | goto buck2_exit; |
@@ -465,20 +398,21 @@ buck1_exit: | |||
465 | 398 | ||
466 | max8998_get_voltage_register(rdev, | 399 | max8998_get_voltage_register(rdev, |
467 | ®, &shift, &mask); | 400 | ®, &shift, &mask); |
468 | ret = max8998_write_reg(i2c, reg, i); | 401 | ret = max8998_write_reg(i2c, reg, selector); |
469 | max8998->buck2_vol[max8998->buck2_idx] = i; | 402 | max8998->buck2_vol[max8998->buck2_idx] = selector; |
470 | buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); | 403 | buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); |
471 | buck2_exit: | 404 | buck2_exit: |
472 | dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, | 405 | dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, |
473 | gpio_get_value(pdata->buck2_set3)); | 406 | gpio_get_value(pdata->buck2_set3)); |
474 | } else { | 407 | } else { |
475 | ret = max8998_write_reg(i2c, reg, i); | 408 | ret = max8998_write_reg(i2c, reg, selector); |
476 | } | 409 | } |
477 | break; | 410 | break; |
478 | 411 | ||
479 | case MAX8998_BUCK3: | 412 | case MAX8998_BUCK3: |
480 | case MAX8998_BUCK4: | 413 | case MAX8998_BUCK4: |
481 | ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); | 414 | ret = max8998_update_reg(i2c, reg, selector<<shift, |
415 | mask<<shift); | ||
482 | break; | 416 | break; |
483 | } | 417 | } |
484 | 418 | ||
@@ -519,34 +453,30 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev, | |||
519 | } | 453 | } |
520 | 454 | ||
521 | static struct regulator_ops max8998_ldo_ops = { | 455 | static struct regulator_ops max8998_ldo_ops = { |
522 | .list_voltage = max8998_list_voltage, | 456 | .list_voltage = regulator_list_voltage_linear, |
457 | .map_voltage = regulator_map_voltage_linear, | ||
523 | .is_enabled = max8998_ldo_is_enabled, | 458 | .is_enabled = max8998_ldo_is_enabled, |
524 | .enable = max8998_ldo_enable, | 459 | .enable = max8998_ldo_enable, |
525 | .disable = max8998_ldo_disable, | 460 | .disable = max8998_ldo_disable, |
526 | .get_voltage_sel = max8998_get_voltage_sel, | 461 | .get_voltage_sel = max8998_get_voltage_sel, |
527 | .set_voltage = max8998_set_voltage_ldo, | 462 | .set_voltage_sel = max8998_set_voltage_ldo_sel, |
528 | .set_suspend_enable = max8998_ldo_enable, | ||
529 | .set_suspend_disable = max8998_ldo_disable, | ||
530 | }; | 463 | }; |
531 | 464 | ||
532 | static struct regulator_ops max8998_buck_ops = { | 465 | static struct regulator_ops max8998_buck_ops = { |
533 | .list_voltage = max8998_list_voltage, | 466 | .list_voltage = regulator_list_voltage_linear, |
467 | .map_voltage = regulator_map_voltage_linear, | ||
534 | .is_enabled = max8998_ldo_is_enabled, | 468 | .is_enabled = max8998_ldo_is_enabled, |
535 | .enable = max8998_ldo_enable, | 469 | .enable = max8998_ldo_enable, |
536 | .disable = max8998_ldo_disable, | 470 | .disable = max8998_ldo_disable, |
537 | .get_voltage_sel = max8998_get_voltage_sel, | 471 | .get_voltage_sel = max8998_get_voltage_sel, |
538 | .set_voltage = max8998_set_voltage_buck, | 472 | .set_voltage_sel = max8998_set_voltage_buck_sel, |
539 | .set_voltage_time_sel = max8998_set_voltage_buck_time_sel, | 473 | .set_voltage_time_sel = max8998_set_voltage_buck_time_sel, |
540 | .set_suspend_enable = max8998_ldo_enable, | ||
541 | .set_suspend_disable = max8998_ldo_disable, | ||
542 | }; | 474 | }; |
543 | 475 | ||
544 | static struct regulator_ops max8998_others_ops = { | 476 | static struct regulator_ops max8998_others_ops = { |
545 | .is_enabled = max8998_ldo_is_enabled, | 477 | .is_enabled = max8998_ldo_is_enabled, |
546 | .enable = max8998_ldo_enable, | 478 | .enable = max8998_ldo_enable, |
547 | .disable = max8998_ldo_disable, | 479 | .disable = max8998_ldo_disable, |
548 | .set_suspend_enable = max8998_ldo_enable, | ||
549 | .set_suspend_disable = max8998_ldo_disable, | ||
550 | }; | 480 | }; |
551 | 481 | ||
552 | static struct regulator_desc regulators[] = { | 482 | static struct regulator_desc regulators[] = { |
@@ -860,7 +790,10 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
860 | desc = ldo_voltage_map[id]; | 790 | desc = ldo_voltage_map[id]; |
861 | if (desc && regulators[index].ops != &max8998_others_ops) { | 791 | if (desc && regulators[index].ops != &max8998_others_ops) { |
862 | int count = (desc->max - desc->min) / desc->step + 1; | 792 | int count = (desc->max - desc->min) / desc->step + 1; |
793 | |||
863 | regulators[index].n_voltages = count; | 794 | regulators[index].n_voltages = count; |
795 | regulators[index].min_uV = desc->min * 1000; | ||
796 | regulators[index].uV_step = desc->step * 1000; | ||
864 | } | 797 | } |
865 | 798 | ||
866 | config.dev = max8998->dev; | 799 | config.dev = max8998->dev; |
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index 7dcdfa283e93..4932e3449fe1 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c | |||
@@ -93,78 +93,78 @@ | |||
93 | 93 | ||
94 | 94 | ||
95 | /* Voltage Values */ | 95 | /* Voltage Values */ |
96 | static const int mc13783_sw3_val[] = { | 96 | static const unsigned int mc13783_sw3_val[] = { |
97 | 5000000, 5000000, 5000000, 5500000, | 97 | 5000000, 5000000, 5000000, 5500000, |
98 | }; | 98 | }; |
99 | 99 | ||
100 | static const int mc13783_vaudio_val[] = { | 100 | static const unsigned int mc13783_vaudio_val[] = { |
101 | 2775000, | 101 | 2775000, |
102 | }; | 102 | }; |
103 | 103 | ||
104 | static const int mc13783_viohi_val[] = { | 104 | static const unsigned int mc13783_viohi_val[] = { |
105 | 2775000, | 105 | 2775000, |
106 | }; | 106 | }; |
107 | 107 | ||
108 | static const int mc13783_violo_val[] = { | 108 | static const unsigned int mc13783_violo_val[] = { |
109 | 1200000, 1300000, 1500000, 1800000, | 109 | 1200000, 1300000, 1500000, 1800000, |
110 | }; | 110 | }; |
111 | 111 | ||
112 | static const int mc13783_vdig_val[] = { | 112 | static const unsigned int mc13783_vdig_val[] = { |
113 | 1200000, 1300000, 1500000, 1800000, | 113 | 1200000, 1300000, 1500000, 1800000, |
114 | }; | 114 | }; |
115 | 115 | ||
116 | static const int mc13783_vgen_val[] = { | 116 | static const unsigned int mc13783_vgen_val[] = { |
117 | 1200000, 1300000, 1500000, 1800000, | 117 | 1200000, 1300000, 1500000, 1800000, |
118 | 1100000, 2000000, 2775000, 2400000, | 118 | 1100000, 2000000, 2775000, 2400000, |
119 | }; | 119 | }; |
120 | 120 | ||
121 | static const int mc13783_vrfdig_val[] = { | 121 | static const unsigned int mc13783_vrfdig_val[] = { |
122 | 1200000, 1500000, 1800000, 1875000, | 122 | 1200000, 1500000, 1800000, 1875000, |
123 | }; | 123 | }; |
124 | 124 | ||
125 | static const int mc13783_vrfref_val[] = { | 125 | static const unsigned int mc13783_vrfref_val[] = { |
126 | 2475000, 2600000, 2700000, 2775000, | 126 | 2475000, 2600000, 2700000, 2775000, |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static const int mc13783_vrfcp_val[] = { | 129 | static const unsigned int mc13783_vrfcp_val[] = { |
130 | 2700000, 2775000, | 130 | 2700000, 2775000, |
131 | }; | 131 | }; |
132 | 132 | ||
133 | static const int mc13783_vsim_val[] = { | 133 | static const unsigned int mc13783_vsim_val[] = { |
134 | 1800000, 2900000, 3000000, | 134 | 1800000, 2900000, 3000000, |
135 | }; | 135 | }; |
136 | 136 | ||
137 | static const int mc13783_vesim_val[] = { | 137 | static const unsigned int mc13783_vesim_val[] = { |
138 | 1800000, 2900000, | 138 | 1800000, 2900000, |
139 | }; | 139 | }; |
140 | 140 | ||
141 | static const int mc13783_vcam_val[] = { | 141 | static const unsigned int mc13783_vcam_val[] = { |
142 | 1500000, 1800000, 2500000, 2550000, | 142 | 1500000, 1800000, 2500000, 2550000, |
143 | 2600000, 2750000, 2800000, 3000000, | 143 | 2600000, 2750000, 2800000, 3000000, |
144 | }; | 144 | }; |
145 | 145 | ||
146 | static const int mc13783_vrfbg_val[] = { | 146 | static const unsigned int mc13783_vrfbg_val[] = { |
147 | 1250000, | 147 | 1250000, |
148 | }; | 148 | }; |
149 | 149 | ||
150 | static const int mc13783_vvib_val[] = { | 150 | static const unsigned int mc13783_vvib_val[] = { |
151 | 1300000, 1800000, 2000000, 3000000, | 151 | 1300000, 1800000, 2000000, 3000000, |
152 | }; | 152 | }; |
153 | 153 | ||
154 | static const int mc13783_vmmc_val[] = { | 154 | static const unsigned int mc13783_vmmc_val[] = { |
155 | 1600000, 1800000, 2000000, 2600000, | 155 | 1600000, 1800000, 2000000, 2600000, |
156 | 2700000, 2800000, 2900000, 3000000, | 156 | 2700000, 2800000, 2900000, 3000000, |
157 | }; | 157 | }; |
158 | 158 | ||
159 | static const int mc13783_vrf_val[] = { | 159 | static const unsigned int mc13783_vrf_val[] = { |
160 | 1500000, 1875000, 2700000, 2775000, | 160 | 1500000, 1875000, 2700000, 2775000, |
161 | }; | 161 | }; |
162 | 162 | ||
163 | static const int mc13783_gpo_val[] = { | 163 | static const unsigned int mc13783_gpo_val[] = { |
164 | 3100000, | 164 | 3100000, |
165 | }; | 165 | }; |
166 | 166 | ||
167 | static const int mc13783_pwgtdrv_val[] = { | 167 | static const unsigned int mc13783_pwgtdrv_val[] = { |
168 | 5500000, | 168 | 5500000, |
169 | }; | 169 | }; |
170 | 170 | ||
@@ -328,7 +328,7 @@ static struct regulator_ops mc13783_gpo_regulator_ops = { | |||
328 | .enable = mc13783_gpo_regulator_enable, | 328 | .enable = mc13783_gpo_regulator_enable, |
329 | .disable = mc13783_gpo_regulator_disable, | 329 | .disable = mc13783_gpo_regulator_disable, |
330 | .is_enabled = mc13783_gpo_regulator_is_enabled, | 330 | .is_enabled = mc13783_gpo_regulator_is_enabled, |
331 | .list_voltage = mc13xxx_regulator_list_voltage, | 331 | .list_voltage = regulator_list_voltage_table, |
332 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, | 332 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, |
333 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, | 333 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, |
334 | }; | 334 | }; |
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index 970a233dbe46..b388b746452e 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c | |||
@@ -150,12 +150,12 @@ | |||
150 | #define MC13892_USB1 50 | 150 | #define MC13892_USB1 50 |
151 | #define MC13892_USB1_VUSBEN (1<<3) | 151 | #define MC13892_USB1_VUSBEN (1<<3) |
152 | 152 | ||
153 | static const int mc13892_vcoincell[] = { | 153 | static const unsigned int mc13892_vcoincell[] = { |
154 | 2500000, 2700000, 2800000, 2900000, 3000000, 3100000, | 154 | 2500000, 2700000, 2800000, 2900000, 3000000, 3100000, |
155 | 3200000, 3300000, | 155 | 3200000, 3300000, |
156 | }; | 156 | }; |
157 | 157 | ||
158 | static const int mc13892_sw1[] = { | 158 | static const unsigned int mc13892_sw1[] = { |
159 | 600000, 625000, 650000, 675000, 700000, 725000, | 159 | 600000, 625000, 650000, 675000, 700000, 725000, |
160 | 750000, 775000, 800000, 825000, 850000, 875000, | 160 | 750000, 775000, 800000, 825000, 850000, 875000, |
161 | 900000, 925000, 950000, 975000, 1000000, 1025000, | 161 | 900000, 925000, 950000, 975000, 1000000, 1025000, |
@@ -164,7 +164,7 @@ static const int mc13892_sw1[] = { | |||
164 | 1350000, 1375000 | 164 | 1350000, 1375000 |
165 | }; | 165 | }; |
166 | 166 | ||
167 | static const int mc13892_sw[] = { | 167 | static const unsigned int mc13892_sw[] = { |
168 | 600000, 625000, 650000, 675000, 700000, 725000, | 168 | 600000, 625000, 650000, 675000, 700000, 725000, |
169 | 750000, 775000, 800000, 825000, 850000, 875000, | 169 | 750000, 775000, 800000, 825000, 850000, 875000, |
170 | 900000, 925000, 950000, 975000, 1000000, 1025000, | 170 | 900000, 925000, 950000, 975000, 1000000, 1025000, |
@@ -176,65 +176,65 @@ static const int mc13892_sw[] = { | |||
176 | 1800000, 1825000, 1850000, 1875000 | 176 | 1800000, 1825000, 1850000, 1875000 |
177 | }; | 177 | }; |
178 | 178 | ||
179 | static const int mc13892_swbst[] = { | 179 | static const unsigned int mc13892_swbst[] = { |
180 | 5000000, | 180 | 5000000, |
181 | }; | 181 | }; |
182 | 182 | ||
183 | static const int mc13892_viohi[] = { | 183 | static const unsigned int mc13892_viohi[] = { |
184 | 2775000, | 184 | 2775000, |
185 | }; | 185 | }; |
186 | 186 | ||
187 | static const int mc13892_vpll[] = { | 187 | static const unsigned int mc13892_vpll[] = { |
188 | 1050000, 1250000, 1650000, 1800000, | 188 | 1050000, 1250000, 1650000, 1800000, |
189 | }; | 189 | }; |
190 | 190 | ||
191 | static const int mc13892_vdig[] = { | 191 | static const unsigned int mc13892_vdig[] = { |
192 | 1050000, 1250000, 1650000, 1800000, | 192 | 1050000, 1250000, 1650000, 1800000, |
193 | }; | 193 | }; |
194 | 194 | ||
195 | static const int mc13892_vsd[] = { | 195 | static const unsigned int mc13892_vsd[] = { |
196 | 1800000, 2000000, 2600000, 2700000, | 196 | 1800000, 2000000, 2600000, 2700000, |
197 | 2800000, 2900000, 3000000, 3150000, | 197 | 2800000, 2900000, 3000000, 3150000, |
198 | }; | 198 | }; |
199 | 199 | ||
200 | static const int mc13892_vusb2[] = { | 200 | static const unsigned int mc13892_vusb2[] = { |
201 | 2400000, 2600000, 2700000, 2775000, | 201 | 2400000, 2600000, 2700000, 2775000, |
202 | }; | 202 | }; |
203 | 203 | ||
204 | static const int mc13892_vvideo[] = { | 204 | static const unsigned int mc13892_vvideo[] = { |
205 | 2700000, 2775000, 2500000, 2600000, | 205 | 2700000, 2775000, 2500000, 2600000, |
206 | }; | 206 | }; |
207 | 207 | ||
208 | static const int mc13892_vaudio[] = { | 208 | static const unsigned int mc13892_vaudio[] = { |
209 | 2300000, 2500000, 2775000, 3000000, | 209 | 2300000, 2500000, 2775000, 3000000, |
210 | }; | 210 | }; |
211 | 211 | ||
212 | static const int mc13892_vcam[] = { | 212 | static const unsigned int mc13892_vcam[] = { |
213 | 2500000, 2600000, 2750000, 3000000, | 213 | 2500000, 2600000, 2750000, 3000000, |
214 | }; | 214 | }; |
215 | 215 | ||
216 | static const int mc13892_vgen1[] = { | 216 | static const unsigned int mc13892_vgen1[] = { |
217 | 1200000, 1500000, 2775000, 3150000, | 217 | 1200000, 1500000, 2775000, 3150000, |
218 | }; | 218 | }; |
219 | 219 | ||
220 | static const int mc13892_vgen2[] = { | 220 | static const unsigned int mc13892_vgen2[] = { |
221 | 1200000, 1500000, 1600000, 1800000, | 221 | 1200000, 1500000, 1600000, 1800000, |
222 | 2700000, 2800000, 3000000, 3150000, | 222 | 2700000, 2800000, 3000000, 3150000, |
223 | }; | 223 | }; |
224 | 224 | ||
225 | static const int mc13892_vgen3[] = { | 225 | static const unsigned int mc13892_vgen3[] = { |
226 | 1800000, 2900000, | 226 | 1800000, 2900000, |
227 | }; | 227 | }; |
228 | 228 | ||
229 | static const int mc13892_vusb[] = { | 229 | static const unsigned int mc13892_vusb[] = { |
230 | 3300000, | 230 | 3300000, |
231 | }; | 231 | }; |
232 | 232 | ||
233 | static const int mc13892_gpo[] = { | 233 | static const unsigned int mc13892_gpo[] = { |
234 | 2750000, | 234 | 2750000, |
235 | }; | 235 | }; |
236 | 236 | ||
237 | static const int mc13892_pwgtdrv[] = { | 237 | static const unsigned int mc13892_pwgtdrv[] = { |
238 | 5000000, | 238 | 5000000, |
239 | }; | 239 | }; |
240 | 240 | ||
@@ -394,7 +394,7 @@ static struct regulator_ops mc13892_gpo_regulator_ops = { | |||
394 | .enable = mc13892_gpo_regulator_enable, | 394 | .enable = mc13892_gpo_regulator_enable, |
395 | .disable = mc13892_gpo_regulator_disable, | 395 | .disable = mc13892_gpo_regulator_disable, |
396 | .is_enabled = mc13892_gpo_regulator_is_enabled, | 396 | .is_enabled = mc13892_gpo_regulator_is_enabled, |
397 | .list_voltage = mc13xxx_regulator_list_voltage, | 397 | .list_voltage = regulator_list_voltage_table, |
398 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, | 398 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, |
399 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, | 399 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, |
400 | }; | 400 | }; |
@@ -436,7 +436,7 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, | |||
436 | u32 valread; | 436 | u32 valread; |
437 | int ret; | 437 | int ret; |
438 | 438 | ||
439 | value = mc13892_regulators[id].voltages[selector]; | 439 | value = rdev->desc->volt_table[selector]; |
440 | 440 | ||
441 | mc13xxx_lock(priv->mc13xxx); | 441 | mc13xxx_lock(priv->mc13xxx); |
442 | ret = mc13xxx_reg_read(priv->mc13xxx, | 442 | ret = mc13xxx_reg_read(priv->mc13xxx, |
@@ -469,8 +469,7 @@ err: | |||
469 | } | 469 | } |
470 | 470 | ||
471 | static struct regulator_ops mc13892_sw_regulator_ops = { | 471 | static struct regulator_ops mc13892_sw_regulator_ops = { |
472 | .is_enabled = mc13xxx_sw_regulator_is_enabled, | 472 | .list_voltage = regulator_list_voltage_table, |
473 | .list_voltage = mc13xxx_regulator_list_voltage, | ||
474 | .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, | 473 | .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, |
475 | .get_voltage = mc13892_sw_regulator_get_voltage, | 474 | .get_voltage = mc13892_sw_regulator_get_voltage, |
476 | }; | 475 | }; |
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c index 4fa9704739bc..d6eda28ca5d0 100644 --- a/drivers/regulator/mc13xxx-regulator-core.c +++ b/drivers/regulator/mc13xxx-regulator-core.c | |||
@@ -80,20 +80,6 @@ static int mc13xxx_regulator_is_enabled(struct regulator_dev *rdev) | |||
80 | return (val & mc13xxx_regulators[id].enable_bit) != 0; | 80 | return (val & mc13xxx_regulators[id].enable_bit) != 0; |
81 | } | 81 | } |
82 | 82 | ||
83 | int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, | ||
84 | unsigned selector) | ||
85 | { | ||
86 | int id = rdev_get_id(rdev); | ||
87 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
88 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
89 | |||
90 | if (selector >= mc13xxx_regulators[id].desc.n_voltages) | ||
91 | return -EINVAL; | ||
92 | |||
93 | return mc13xxx_regulators[id].voltages[selector]; | ||
94 | } | ||
95 | EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage); | ||
96 | |||
97 | static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev, | 83 | static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev, |
98 | unsigned selector) | 84 | unsigned selector) |
99 | { | 85 | { |
@@ -135,14 +121,14 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev) | |||
135 | 121 | ||
136 | BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages); | 122 | BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages); |
137 | 123 | ||
138 | return mc13xxx_regulators[id].voltages[val]; | 124 | return rdev->desc->volt_table[val]; |
139 | } | 125 | } |
140 | 126 | ||
141 | struct regulator_ops mc13xxx_regulator_ops = { | 127 | struct regulator_ops mc13xxx_regulator_ops = { |
142 | .enable = mc13xxx_regulator_enable, | 128 | .enable = mc13xxx_regulator_enable, |
143 | .disable = mc13xxx_regulator_disable, | 129 | .disable = mc13xxx_regulator_disable, |
144 | .is_enabled = mc13xxx_regulator_is_enabled, | 130 | .is_enabled = mc13xxx_regulator_is_enabled, |
145 | .list_voltage = mc13xxx_regulator_list_voltage, | 131 | .list_voltage = regulator_list_voltage_table, |
146 | .set_voltage_sel = mc13xxx_regulator_set_voltage_sel, | 132 | .set_voltage_sel = mc13xxx_regulator_set_voltage_sel, |
147 | .get_voltage = mc13xxx_regulator_get_voltage, | 133 | .get_voltage = mc13xxx_regulator_get_voltage, |
148 | }; | 134 | }; |
@@ -151,15 +137,13 @@ EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops); | |||
151 | int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, | 137 | int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, |
152 | int max_uV, unsigned *selector) | 138 | int max_uV, unsigned *selector) |
153 | { | 139 | { |
154 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
155 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
156 | int id = rdev_get_id(rdev); | 140 | int id = rdev_get_id(rdev); |
157 | 141 | ||
158 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | 142 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", |
159 | __func__, id, min_uV, max_uV); | 143 | __func__, id, min_uV, max_uV); |
160 | 144 | ||
161 | if (min_uV >= mc13xxx_regulators[id].voltages[0] && | 145 | if (min_uV <= rdev->desc->volt_table[0] && |
162 | max_uV <= mc13xxx_regulators[id].voltages[0]) | 146 | rdev->desc->volt_table[0] <= max_uV) |
163 | return 0; | 147 | return 0; |
164 | else | 148 | else |
165 | return -EINVAL; | 149 | return -EINVAL; |
@@ -168,13 +152,11 @@ EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage); | |||
168 | 152 | ||
169 | int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev) | 153 | int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev) |
170 | { | 154 | { |
171 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
172 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
173 | int id = rdev_get_id(rdev); | 155 | int id = rdev_get_id(rdev); |
174 | 156 | ||
175 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | 157 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); |
176 | 158 | ||
177 | return mc13xxx_regulators[id].voltages[0]; | 159 | return rdev->desc->volt_table[0]; |
178 | } | 160 | } |
179 | EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage); | 161 | EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage); |
180 | 162 | ||
@@ -182,18 +164,12 @@ struct regulator_ops mc13xxx_fixed_regulator_ops = { | |||
182 | .enable = mc13xxx_regulator_enable, | 164 | .enable = mc13xxx_regulator_enable, |
183 | .disable = mc13xxx_regulator_disable, | 165 | .disable = mc13xxx_regulator_disable, |
184 | .is_enabled = mc13xxx_regulator_is_enabled, | 166 | .is_enabled = mc13xxx_regulator_is_enabled, |
185 | .list_voltage = mc13xxx_regulator_list_voltage, | 167 | .list_voltage = regulator_list_voltage_table, |
186 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, | 168 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, |
187 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, | 169 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, |
188 | }; | 170 | }; |
189 | EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops); | 171 | EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops); |
190 | 172 | ||
191 | int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev) | ||
192 | { | ||
193 | return 1; | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled); | ||
196 | |||
197 | #ifdef CONFIG_OF | 173 | #ifdef CONFIG_OF |
198 | int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev) | 174 | int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev) |
199 | { | 175 | { |
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h index 044aba4d28ec..eaff5510b6df 100644 --- a/drivers/regulator/mc13xxx.h +++ b/drivers/regulator/mc13xxx.h | |||
@@ -22,7 +22,6 @@ struct mc13xxx_regulator { | |||
22 | int vsel_shift; | 22 | int vsel_shift; |
23 | int vsel_mask; | 23 | int vsel_mask; |
24 | int hi_bit; | 24 | int hi_bit; |
25 | int const *voltages; | ||
26 | }; | 25 | }; |
27 | 26 | ||
28 | struct mc13xxx_regulator_priv { | 27 | struct mc13xxx_regulator_priv { |
@@ -33,10 +32,6 @@ struct mc13xxx_regulator_priv { | |||
33 | struct regulator_dev *regulators[]; | 32 | struct regulator_dev *regulators[]; |
34 | }; | 33 | }; |
35 | 34 | ||
36 | extern int mc13xxx_sw_regulator(struct regulator_dev *rdev); | ||
37 | extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev); | ||
38 | extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, | ||
39 | unsigned selector); | ||
40 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, | 35 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, |
41 | int min_uV, int max_uV, unsigned *selector); | 36 | int min_uV, int max_uV, unsigned *selector); |
42 | extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev); | 37 | extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev); |
@@ -68,6 +63,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
68 | .desc = { \ | 63 | .desc = { \ |
69 | .name = #_name, \ | 64 | .name = #_name, \ |
70 | .n_voltages = ARRAY_SIZE(_voltages), \ | 65 | .n_voltages = ARRAY_SIZE(_voltages), \ |
66 | .volt_table = _voltages, \ | ||
71 | .ops = &_ops, \ | 67 | .ops = &_ops, \ |
72 | .type = REGULATOR_VOLTAGE, \ | 68 | .type = REGULATOR_VOLTAGE, \ |
73 | .id = prefix ## _name, \ | 69 | .id = prefix ## _name, \ |
@@ -78,7 +74,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
78 | .vsel_reg = prefix ## _vsel_reg, \ | 74 | .vsel_reg = prefix ## _vsel_reg, \ |
79 | .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ | 75 | .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\ |
80 | .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ | 76 | .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\ |
81 | .voltages = _voltages, \ | ||
82 | } | 77 | } |
83 | 78 | ||
84 | #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ | 79 | #define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
@@ -86,6 +81,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
86 | .desc = { \ | 81 | .desc = { \ |
87 | .name = #_name, \ | 82 | .name = #_name, \ |
88 | .n_voltages = ARRAY_SIZE(_voltages), \ | 83 | .n_voltages = ARRAY_SIZE(_voltages), \ |
84 | .volt_table = _voltages, \ | ||
89 | .ops = &_ops, \ | 85 | .ops = &_ops, \ |
90 | .type = REGULATOR_VOLTAGE, \ | 86 | .type = REGULATOR_VOLTAGE, \ |
91 | .id = prefix ## _name, \ | 87 | .id = prefix ## _name, \ |
@@ -93,7 +89,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
93 | }, \ | 89 | }, \ |
94 | .reg = prefix ## _reg, \ | 90 | .reg = prefix ## _reg, \ |
95 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ | 91 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
96 | .voltages = _voltages, \ | ||
97 | } | 92 | } |
98 | 93 | ||
99 | #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ | 94 | #define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \ |
@@ -101,6 +96,7 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
101 | .desc = { \ | 96 | .desc = { \ |
102 | .name = #_name, \ | 97 | .name = #_name, \ |
103 | .n_voltages = ARRAY_SIZE(_voltages), \ | 98 | .n_voltages = ARRAY_SIZE(_voltages), \ |
99 | .volt_table = _voltages, \ | ||
104 | .ops = &_ops, \ | 100 | .ops = &_ops, \ |
105 | .type = REGULATOR_VOLTAGE, \ | 101 | .type = REGULATOR_VOLTAGE, \ |
106 | .id = prefix ## _name, \ | 102 | .id = prefix ## _name, \ |
@@ -108,7 +104,6 @@ extern struct regulator_ops mc13xxx_fixed_regulator_ops; | |||
108 | }, \ | 104 | }, \ |
109 | .reg = prefix ## _reg, \ | 105 | .reg = prefix ## _reg, \ |
110 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ | 106 | .enable_bit = prefix ## _reg ## _ ## _name ## EN, \ |
111 | .voltages = _voltages, \ | ||
112 | } | 107 | } |
113 | 108 | ||
114 | #define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \ | 109 | #define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \ |
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 56593b75168a..3e4106f2bda9 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -20,7 +20,7 @@ static void of_get_regulation_constraints(struct device_node *np, | |||
20 | struct regulator_init_data **init_data) | 20 | struct regulator_init_data **init_data) |
21 | { | 21 | { |
22 | const __be32 *min_uV, *max_uV, *uV_offset; | 22 | const __be32 *min_uV, *max_uV, *uV_offset; |
23 | const __be32 *min_uA, *max_uA; | 23 | const __be32 *min_uA, *max_uA, *ramp_delay; |
24 | struct regulation_constraints *constraints = &(*init_data)->constraints; | 24 | struct regulation_constraints *constraints = &(*init_data)->constraints; |
25 | 25 | ||
26 | constraints->name = of_get_property(np, "regulator-name", NULL); | 26 | constraints->name = of_get_property(np, "regulator-name", NULL); |
@@ -60,6 +60,10 @@ static void of_get_regulation_constraints(struct device_node *np, | |||
60 | constraints->always_on = true; | 60 | constraints->always_on = true; |
61 | else /* status change should be possible if not always on. */ | 61 | else /* status change should be possible if not always on. */ |
62 | constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; | 62 | constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; |
63 | |||
64 | ramp_delay = of_get_property(np, "regulator-ramp-delay", NULL); | ||
65 | if (ramp_delay) | ||
66 | constraints->ramp_delay = be32_to_cpu(*ramp_delay); | ||
63 | } | 67 | } |
64 | 68 | ||
65 | /** | 69 | /** |
@@ -88,15 +92,17 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, | |||
88 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); | 92 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); |
89 | 93 | ||
90 | /** | 94 | /** |
91 | * of_regulator_match - extract regulator init data | 95 | * of_regulator_match - extract regulator init data when node |
96 | * property "regulator-compatible" matches with the regulator name. | ||
92 | * @dev: device requesting the data | 97 | * @dev: device requesting the data |
93 | * @node: parent device node of the regulators | 98 | * @node: parent device node of the regulators |
94 | * @matches: match table for the regulators | 99 | * @matches: match table for the regulators |
95 | * @num_matches: number of entries in match table | 100 | * @num_matches: number of entries in match table |
96 | * | 101 | * |
97 | * This function uses a match table specified by the regulator driver and | 102 | * This function uses a match table specified by the regulator driver and |
98 | * looks up the corresponding init data in the device tree. Note that the | 103 | * looks up the corresponding init data in the device tree if |
99 | * match table is modified in place. | 104 | * regulator-compatible matches. Note that the match table is modified |
105 | * in place. | ||
100 | * | 106 | * |
101 | * Returns the number of matches found or a negative error code on failure. | 107 | * Returns the number of matches found or a negative error code on failure. |
102 | */ | 108 | */ |
@@ -106,27 +112,40 @@ int of_regulator_match(struct device *dev, struct device_node *node, | |||
106 | { | 112 | { |
107 | unsigned int count = 0; | 113 | unsigned int count = 0; |
108 | unsigned int i; | 114 | unsigned int i; |
115 | const char *regulator_comp; | ||
116 | struct device_node *child; | ||
109 | 117 | ||
110 | if (!dev || !node) | 118 | if (!dev || !node) |
111 | return -EINVAL; | 119 | return -EINVAL; |
112 | 120 | ||
113 | for (i = 0; i < num_matches; i++) { | 121 | for_each_child_of_node(node, child) { |
114 | struct of_regulator_match *match = &matches[i]; | 122 | regulator_comp = of_get_property(child, |
115 | struct device_node *child; | 123 | "regulator-compatible", NULL); |
116 | 124 | if (!regulator_comp) { | |
117 | child = of_find_node_by_name(node, match->name); | 125 | dev_err(dev, "regulator-compatible is missing for node %s\n", |
118 | if (!child) | ||
119 | continue; | ||
120 | |||
121 | match->init_data = of_get_regulator_init_data(dev, child); | ||
122 | if (!match->init_data) { | ||
123 | dev_err(dev, "failed to parse DT for regulator %s\n", | ||
124 | child->name); | 126 | child->name); |
125 | return -EINVAL; | 127 | continue; |
128 | } | ||
129 | for (i = 0; i < num_matches; i++) { | ||
130 | struct of_regulator_match *match = &matches[i]; | ||
131 | if (match->of_node) | ||
132 | continue; | ||
133 | |||
134 | if (strcmp(match->name, regulator_comp)) | ||
135 | continue; | ||
136 | |||
137 | match->init_data = | ||
138 | of_get_regulator_init_data(dev, child); | ||
139 | if (!match->init_data) { | ||
140 | dev_err(dev, | ||
141 | "failed to parse DT for regulator %s\n", | ||
142 | child->name); | ||
143 | return -EINVAL; | ||
144 | } | ||
145 | match->of_node = child; | ||
146 | count++; | ||
147 | break; | ||
126 | } | 148 | } |
127 | |||
128 | match->of_node = child; | ||
129 | count++; | ||
130 | } | 149 | } |
131 | 150 | ||
132 | return count; | 151 | return count; |
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index 795f75a6ac33..17d19fbbc490 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c | |||
@@ -257,8 +257,7 @@ static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) | |||
257 | unsigned int reg; | 257 | unsigned int reg; |
258 | 258 | ||
259 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | 259 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
260 | reg &= ~PALMAS_SMPS12_CTRL_STATUS_MASK; | 260 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
261 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; | ||
262 | 261 | ||
263 | switch (mode) { | 262 | switch (mode) { |
264 | case REGULATOR_MODE_NORMAL: | 263 | case REGULATOR_MODE_NORMAL: |
@@ -374,11 +373,22 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev, | |||
374 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, | 373 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, |
375 | int min_uV, int max_uV) | 374 | int min_uV, int max_uV) |
376 | { | 375 | { |
376 | struct palmas_pmic *pmic = rdev_get_drvdata(rdev); | ||
377 | int id = rdev_get_id(rdev); | ||
377 | int ret, voltage; | 378 | int ret, voltage; |
378 | 379 | ||
379 | ret = ((min_uV - 500000) / 10000) + 1; | 380 | if (min_uV == 0) |
380 | if (ret < 0) | 381 | return 0; |
381 | return ret; | 382 | |
383 | if (pmic->range[id]) { /* RANGE is x2 */ | ||
384 | if (min_uV < 1000000) | ||
385 | min_uV = 1000000; | ||
386 | ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1; | ||
387 | } else { /* RANGE is x1 */ | ||
388 | if (min_uV < 500000) | ||
389 | min_uV = 500000; | ||
390 | ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1; | ||
391 | } | ||
382 | 392 | ||
383 | /* Map back into a voltage to verify we're still in bounds */ | 393 | /* Map back into a voltage to verify we're still in bounds */ |
384 | voltage = palmas_list_voltage_smps(rdev, ret); | 394 | voltage = palmas_list_voltage_smps(rdev, ret); |
@@ -400,19 +410,14 @@ static struct regulator_ops palmas_ops_smps = { | |||
400 | .map_voltage = palmas_map_voltage_smps, | 410 | .map_voltage = palmas_map_voltage_smps, |
401 | }; | 411 | }; |
402 | 412 | ||
403 | static int palmas_list_voltage_smps10(struct regulator_dev *dev, | ||
404 | unsigned selector) | ||
405 | { | ||
406 | return 3750000 + (selector * 1250000); | ||
407 | } | ||
408 | |||
409 | static struct regulator_ops palmas_ops_smps10 = { | 413 | static struct regulator_ops palmas_ops_smps10 = { |
410 | .is_enabled = regulator_is_enabled_regmap, | 414 | .is_enabled = regulator_is_enabled_regmap, |
411 | .enable = regulator_enable_regmap, | 415 | .enable = regulator_enable_regmap, |
412 | .disable = regulator_disable_regmap, | 416 | .disable = regulator_disable_regmap, |
413 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 417 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
414 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 418 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
415 | .list_voltage = palmas_list_voltage_smps10, | 419 | .list_voltage = regulator_list_voltage_linear, |
420 | .map_voltage = regulator_map_voltage_linear, | ||
416 | }; | 421 | }; |
417 | 422 | ||
418 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) | 423 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) |
@@ -522,7 +527,15 @@ static int palmas_smps_init(struct palmas *palmas, int id, | |||
522 | if (ret) | 527 | if (ret) |
523 | return ret; | 528 | return ret; |
524 | 529 | ||
525 | if (id != PALMAS_REG_SMPS10) { | 530 | switch (id) { |
531 | case PALMAS_REG_SMPS10: | ||
532 | if (reg_init->mode_sleep) { | ||
533 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; | ||
534 | reg |= reg_init->mode_sleep << | ||
535 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; | ||
536 | } | ||
537 | break; | ||
538 | default: | ||
526 | if (reg_init->warm_reset) | 539 | if (reg_init->warm_reset) |
527 | reg |= PALMAS_SMPS12_CTRL_WR_S; | 540 | reg |= PALMAS_SMPS12_CTRL_WR_S; |
528 | 541 | ||
@@ -534,14 +547,8 @@ static int palmas_smps_init(struct palmas *palmas, int id, | |||
534 | reg |= reg_init->mode_sleep << | 547 | reg |= reg_init->mode_sleep << |
535 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; | 548 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; |
536 | } | 549 | } |
537 | } else { | ||
538 | if (reg_init->mode_sleep) { | ||
539 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; | ||
540 | reg |= reg_init->mode_sleep << | ||
541 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; | ||
542 | } | ||
543 | |||
544 | } | 550 | } |
551 | |||
545 | ret = palmas_smps_write(palmas, addr, reg); | 552 | ret = palmas_smps_write(palmas, addr, reg); |
546 | if (ret) | 553 | if (ret) |
547 | return ret; | 554 | return ret; |
@@ -665,10 +672,8 @@ static __devinit int palmas_probe(struct platform_device *pdev) | |||
665 | pmic->desc[id].name = palmas_regs_info[id].name; | 672 | pmic->desc[id].name = palmas_regs_info[id].name; |
666 | pmic->desc[id].id = id; | 673 | pmic->desc[id].id = id; |
667 | 674 | ||
668 | if (id != PALMAS_REG_SMPS10) { | 675 | switch (id) { |
669 | pmic->desc[id].ops = &palmas_ops_smps; | 676 | case PALMAS_REG_SMPS10: |
670 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; | ||
671 | } else { | ||
672 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; | 677 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; |
673 | pmic->desc[id].ops = &palmas_ops_smps10; | 678 | pmic->desc[id].ops = &palmas_ops_smps10; |
674 | pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL; | 679 | pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL; |
@@ -677,6 +682,12 @@ static __devinit int palmas_probe(struct platform_device *pdev) | |||
677 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, | 682 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
678 | PALMAS_SMPS10_STATUS); | 683 | PALMAS_SMPS10_STATUS); |
679 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; | 684 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; |
685 | pmic->desc[id].min_uV = 3750000; | ||
686 | pmic->desc[id].uV_step = 1250000; | ||
687 | break; | ||
688 | default: | ||
689 | pmic->desc[id].ops = &palmas_ops_smps; | ||
690 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; | ||
680 | } | 691 | } |
681 | 692 | ||
682 | pmic->desc[id].type = REGULATOR_VOLTAGE; | 693 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c index 8211101121f0..68777acc099f 100644 --- a/drivers/regulator/pcap-regulator.c +++ b/drivers/regulator/pcap-regulator.c | |||
@@ -18,80 +18,80 @@ | |||
18 | #include <linux/regulator/machine.h> | 18 | #include <linux/regulator/machine.h> |
19 | #include <linux/mfd/ezx-pcap.h> | 19 | #include <linux/mfd/ezx-pcap.h> |
20 | 20 | ||
21 | static const u16 V1_table[] = { | 21 | static const unsigned int V1_table[] = { |
22 | 2775, 1275, 1600, 1725, 1825, 1925, 2075, 2275, | 22 | 2775000, 1275000, 1600000, 1725000, 1825000, 1925000, 2075000, 2275000, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | static const u16 V2_table[] = { | 25 | static const unsigned int V2_table[] = { |
26 | 2500, 2775, | 26 | 2500000, 2775000, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | static const u16 V3_table[] = { | 29 | static const unsigned int V3_table[] = { |
30 | 1075, 1275, 1550, 1725, 1876, 1950, 2075, 2275, | 30 | 1075000, 1275000, 1550000, 1725000, 1876000, 1950000, 2075000, 2275000, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | static const u16 V4_table[] = { | 33 | static const unsigned int V4_table[] = { |
34 | 1275, 1550, 1725, 1875, 1950, 2075, 2275, 2775, | 34 | 1275000, 1550000, 1725000, 1875000, 1950000, 2075000, 2275000, 2775000, |
35 | }; | 35 | }; |
36 | 36 | ||
37 | static const u16 V5_table[] = { | 37 | static const unsigned int V5_table[] = { |
38 | 1875, 2275, 2475, 2775, | 38 | 1875000, 2275000, 2475000, 2775000, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static const u16 V6_table[] = { | 41 | static const unsigned int V6_table[] = { |
42 | 2475, 2775, | 42 | 2475000, 2775000, |
43 | }; | 43 | }; |
44 | 44 | ||
45 | static const u16 V7_table[] = { | 45 | static const unsigned int V7_table[] = { |
46 | 1875, 2775, | 46 | 1875000, 2775000, |
47 | }; | 47 | }; |
48 | 48 | ||
49 | #define V8_table V4_table | 49 | #define V8_table V4_table |
50 | 50 | ||
51 | static const u16 V9_table[] = { | 51 | static const unsigned int V9_table[] = { |
52 | 1575, 1875, 2475, 2775, | 52 | 1575000, 1875000, 2475000, 2775000, |
53 | }; | 53 | }; |
54 | 54 | ||
55 | static const u16 V10_table[] = { | 55 | static const unsigned int V10_table[] = { |
56 | 5000, | 56 | 5000000, |
57 | }; | 57 | }; |
58 | 58 | ||
59 | static const u16 VAUX1_table[] = { | 59 | static const unsigned int VAUX1_table[] = { |
60 | 1875, 2475, 2775, 3000, | 60 | 1875000, 2475000, 2775000, 3000000, |
61 | }; | 61 | }; |
62 | 62 | ||
63 | #define VAUX2_table VAUX1_table | 63 | #define VAUX2_table VAUX1_table |
64 | 64 | ||
65 | static const u16 VAUX3_table[] = { | 65 | static const unsigned int VAUX3_table[] = { |
66 | 1200, 1200, 1200, 1200, 1400, 1600, 1800, 2000, | 66 | 1200000, 1200000, 1200000, 1200000, 1400000, 1600000, 1800000, 2000000, |
67 | 2200, 2400, 2600, 2800, 3000, 3200, 3400, 3600, | 67 | 2200000, 2400000, 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, |
68 | }; | 68 | }; |
69 | 69 | ||
70 | static const u16 VAUX4_table[] = { | 70 | static const unsigned int VAUX4_table[] = { |
71 | 1800, 1800, 3000, 5000, | 71 | 1800000, 1800000, 3000000, 5000000, |
72 | }; | 72 | }; |
73 | 73 | ||
74 | static const u16 VSIM_table[] = { | 74 | static const unsigned int VSIM_table[] = { |
75 | 1875, 3000, | 75 | 1875000, 3000000, |
76 | }; | 76 | }; |
77 | 77 | ||
78 | static const u16 VSIM2_table[] = { | 78 | static const unsigned int VSIM2_table[] = { |
79 | 1875, | 79 | 1875000, |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static const u16 VVIB_table[] = { | 82 | static const unsigned int VVIB_table[] = { |
83 | 1300, 1800, 2000, 3000, | 83 | 1300000, 1800000, 2000000, 3000000, |
84 | }; | 84 | }; |
85 | 85 | ||
86 | static const u16 SW1_table[] = { | 86 | static const unsigned int SW1_table[] = { |
87 | 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, | 87 | 900000, 950000, 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, |
88 | 1300, 1350, 1400, 1450, 1500, 1600, 1875, 2250, | 88 | 1300000, 1350000, 1400000, 1450000, 1500000, 1600000, 1875000, 2250000, |
89 | }; | 89 | }; |
90 | 90 | ||
91 | #define SW2_table SW1_table | 91 | #define SW2_table SW1_table |
92 | 92 | ||
93 | static const u16 SW3_table[] = { | 93 | static const unsigned int SW3_table[] = { |
94 | 4000, 4500, 5000, 5500, | 94 | 4000000, 4500000, 5000000, 5500000, |
95 | }; | 95 | }; |
96 | 96 | ||
97 | struct pcap_regulator { | 97 | struct pcap_regulator { |
@@ -100,8 +100,6 @@ struct pcap_regulator { | |||
100 | const u8 index; | 100 | const u8 index; |
101 | const u8 stby; | 101 | const u8 stby; |
102 | const u8 lowpwr; | 102 | const u8 lowpwr; |
103 | const u8 n_voltages; | ||
104 | const u16 *voltage_table; | ||
105 | }; | 103 | }; |
106 | 104 | ||
107 | #define NA 0xff | 105 | #define NA 0xff |
@@ -113,8 +111,6 @@ struct pcap_regulator { | |||
113 | .index = _index, \ | 111 | .index = _index, \ |
114 | .stby = _stby, \ | 112 | .stby = _stby, \ |
115 | .lowpwr = _lowpwr, \ | 113 | .lowpwr = _lowpwr, \ |
116 | .n_voltages = ARRAY_SIZE(_vreg##_table), \ | ||
117 | .voltage_table = _vreg##_table, \ | ||
118 | } | 114 | } |
119 | 115 | ||
120 | static struct pcap_regulator vreg_table[] = { | 116 | static struct pcap_regulator vreg_table[] = { |
@@ -157,11 +153,11 @@ static int pcap_regulator_set_voltage_sel(struct regulator_dev *rdev, | |||
157 | void *pcap = rdev_get_drvdata(rdev); | 153 | void *pcap = rdev_get_drvdata(rdev); |
158 | 154 | ||
159 | /* the regulator doesn't support voltage switching */ | 155 | /* the regulator doesn't support voltage switching */ |
160 | if (vreg->n_voltages == 1) | 156 | if (rdev->desc->n_voltages == 1) |
161 | return -EINVAL; | 157 | return -EINVAL; |
162 | 158 | ||
163 | return ezx_pcap_set_bits(pcap, vreg->reg, | 159 | return ezx_pcap_set_bits(pcap, vreg->reg, |
164 | (vreg->n_voltages - 1) << vreg->index, | 160 | (rdev->desc->n_voltages - 1) << vreg->index, |
165 | selector << vreg->index); | 161 | selector << vreg->index); |
166 | } | 162 | } |
167 | 163 | ||
@@ -171,11 +167,11 @@ static int pcap_regulator_get_voltage_sel(struct regulator_dev *rdev) | |||
171 | void *pcap = rdev_get_drvdata(rdev); | 167 | void *pcap = rdev_get_drvdata(rdev); |
172 | u32 tmp; | 168 | u32 tmp; |
173 | 169 | ||
174 | if (vreg->n_voltages == 1) | 170 | if (rdev->desc->n_voltages == 1) |
175 | return 0; | 171 | return 0; |
176 | 172 | ||
177 | ezx_pcap_read(pcap, vreg->reg, &tmp); | 173 | ezx_pcap_read(pcap, vreg->reg, &tmp); |
178 | tmp = ((tmp >> vreg->index) & (vreg->n_voltages - 1)); | 174 | tmp = ((tmp >> vreg->index) & (rdev->desc->n_voltages - 1)); |
179 | return tmp; | 175 | return tmp; |
180 | } | 176 | } |
181 | 177 | ||
@@ -214,16 +210,8 @@ static int pcap_regulator_is_enabled(struct regulator_dev *rdev) | |||
214 | return (tmp >> vreg->en) & 1; | 210 | return (tmp >> vreg->en) & 1; |
215 | } | 211 | } |
216 | 212 | ||
217 | static int pcap_regulator_list_voltage(struct regulator_dev *rdev, | ||
218 | unsigned int index) | ||
219 | { | ||
220 | struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; | ||
221 | |||
222 | return vreg->voltage_table[index] * 1000; | ||
223 | } | ||
224 | |||
225 | static struct regulator_ops pcap_regulator_ops = { | 213 | static struct regulator_ops pcap_regulator_ops = { |
226 | .list_voltage = pcap_regulator_list_voltage, | 214 | .list_voltage = regulator_list_voltage_table, |
227 | .set_voltage_sel = pcap_regulator_set_voltage_sel, | 215 | .set_voltage_sel = pcap_regulator_set_voltage_sel, |
228 | .get_voltage_sel = pcap_regulator_get_voltage_sel, | 216 | .get_voltage_sel = pcap_regulator_get_voltage_sel, |
229 | .enable = pcap_regulator_enable, | 217 | .enable = pcap_regulator_enable, |
@@ -236,6 +224,7 @@ static struct regulator_ops pcap_regulator_ops = { | |||
236 | .name = #_vreg, \ | 224 | .name = #_vreg, \ |
237 | .id = _vreg, \ | 225 | .id = _vreg, \ |
238 | .n_voltages = ARRAY_SIZE(_vreg##_table), \ | 226 | .n_voltages = ARRAY_SIZE(_vreg##_table), \ |
227 | .volt_table = _vreg##_table, \ | ||
239 | .ops = &pcap_regulator_ops, \ | 228 | .ops = &pcap_regulator_ops, \ |
240 | .type = REGULATOR_VOLTAGE, \ | 229 | .type = REGULATOR_VOLTAGE, \ |
241 | .owner = THIS_MODULE, \ | 230 | .owner = THIS_MODULE, \ |
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c index 3c9d14c0017b..092e5cb848a1 100644 --- a/drivers/regulator/pcf50633-regulator.c +++ b/drivers/regulator/pcf50633-regulator.c | |||
@@ -100,13 +100,12 @@ static unsigned int ldo_voltage_value(u8 bits) | |||
100 | return 900 + (bits * 100); | 100 | return 900 + (bits * 100); |
101 | } | 101 | } |
102 | 102 | ||
103 | static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, | 103 | static int pcf50633_regulator_map_voltage(struct regulator_dev *rdev, |
104 | int min_uV, int max_uV, | 104 | int min_uV, int max_uV) |
105 | unsigned *selector) | ||
106 | { | 105 | { |
107 | struct pcf50633 *pcf; | 106 | struct pcf50633 *pcf; |
108 | int regulator_id, millivolts; | 107 | int regulator_id, millivolts; |
109 | u8 volt_bits, regnr; | 108 | u8 volt_bits; |
110 | 109 | ||
111 | pcf = rdev_get_drvdata(rdev); | 110 | pcf = rdev_get_drvdata(rdev); |
112 | 111 | ||
@@ -116,15 +115,11 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, | |||
116 | 115 | ||
117 | millivolts = min_uV / 1000; | 116 | millivolts = min_uV / 1000; |
118 | 117 | ||
119 | regnr = rdev->desc->vsel_reg; | ||
120 | |||
121 | switch (regulator_id) { | 118 | switch (regulator_id) { |
122 | case PCF50633_REGULATOR_AUTO: | 119 | case PCF50633_REGULATOR_AUTO: |
123 | volt_bits = auto_voltage_bits(millivolts); | 120 | volt_bits = auto_voltage_bits(millivolts); |
124 | break; | 121 | break; |
125 | case PCF50633_REGULATOR_DOWN1: | 122 | case PCF50633_REGULATOR_DOWN1: |
126 | volt_bits = down_voltage_bits(millivolts); | ||
127 | break; | ||
128 | case PCF50633_REGULATOR_DOWN2: | 123 | case PCF50633_REGULATOR_DOWN2: |
129 | volt_bits = down_voltage_bits(millivolts); | 124 | volt_bits = down_voltage_bits(millivolts); |
130 | break; | 125 | break; |
@@ -142,9 +137,7 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, | |||
142 | return -EINVAL; | 137 | return -EINVAL; |
143 | } | 138 | } |
144 | 139 | ||
145 | *selector = volt_bits; | 140 | return volt_bits; |
146 | |||
147 | return pcf50633_reg_write(pcf, regnr, volt_bits); | ||
148 | } | 141 | } |
149 | 142 | ||
150 | static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, | 143 | static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, |
@@ -159,8 +152,6 @@ static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, | |||
159 | millivolts = auto_voltage_value(index); | 152 | millivolts = auto_voltage_value(index); |
160 | break; | 153 | break; |
161 | case PCF50633_REGULATOR_DOWN1: | 154 | case PCF50633_REGULATOR_DOWN1: |
162 | millivolts = down_voltage_value(index); | ||
163 | break; | ||
164 | case PCF50633_REGULATOR_DOWN2: | 155 | case PCF50633_REGULATOR_DOWN2: |
165 | millivolts = down_voltage_value(index); | 156 | millivolts = down_voltage_value(index); |
166 | break; | 157 | break; |
@@ -182,9 +173,10 @@ static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, | |||
182 | } | 173 | } |
183 | 174 | ||
184 | static struct regulator_ops pcf50633_regulator_ops = { | 175 | static struct regulator_ops pcf50633_regulator_ops = { |
185 | .set_voltage = pcf50633_regulator_set_voltage, | 176 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
186 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 177 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
187 | .list_voltage = pcf50633_regulator_list_voltage, | 178 | .list_voltage = pcf50633_regulator_list_voltage, |
179 | .map_voltage = pcf50633_regulator_map_voltage, | ||
188 | .enable = regulator_enable_regmap, | 180 | .enable = regulator_enable_regmap, |
189 | .disable = regulator_disable_regmap, | 181 | .disable = regulator_disable_regmap, |
190 | .is_enabled = regulator_is_enabled_regmap, | 182 | .is_enabled = regulator_is_enabled_regmap, |
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c index 1d34e64a1307..8bf4e8c9de9a 100644 --- a/drivers/regulator/rc5t583-regulator.c +++ b/drivers/regulator/rc5t583-regulator.c | |||
@@ -42,7 +42,6 @@ struct rc5t583_regulator_info { | |||
42 | 42 | ||
43 | /* Regulator specific turn-on delay and voltage settling time*/ | 43 | /* Regulator specific turn-on delay and voltage settling time*/ |
44 | int enable_uv_per_us; | 44 | int enable_uv_per_us; |
45 | int change_uv_per_us; | ||
46 | 45 | ||
47 | /* Used by regulator core */ | 46 | /* Used by regulator core */ |
48 | struct regulator_desc desc; | 47 | struct regulator_desc desc; |
@@ -66,25 +65,6 @@ static int rc5t583_regulator_enable_time(struct regulator_dev *rdev) | |||
66 | return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us); | 65 | return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us); |
67 | } | 66 | } |
68 | 67 | ||
69 | static int rc5t583_set_voltage_time_sel(struct regulator_dev *rdev, | ||
70 | unsigned int old_selector, unsigned int new_selector) | ||
71 | { | ||
72 | struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); | ||
73 | int old_uV, new_uV; | ||
74 | old_uV = regulator_list_voltage_linear(rdev, old_selector); | ||
75 | |||
76 | if (old_uV < 0) | ||
77 | return old_uV; | ||
78 | |||
79 | new_uV = regulator_list_voltage_linear(rdev, new_selector); | ||
80 | if (new_uV < 0) | ||
81 | return new_uV; | ||
82 | |||
83 | return DIV_ROUND_UP(abs(old_uV - new_uV), | ||
84 | reg->reg_info->change_uv_per_us); | ||
85 | } | ||
86 | |||
87 | |||
88 | static struct regulator_ops rc5t583_ops = { | 68 | static struct regulator_ops rc5t583_ops = { |
89 | .is_enabled = regulator_is_enabled_regmap, | 69 | .is_enabled = regulator_is_enabled_regmap, |
90 | .enable = regulator_enable_regmap, | 70 | .enable = regulator_enable_regmap, |
@@ -94,7 +74,7 @@ static struct regulator_ops rc5t583_ops = { | |||
94 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 74 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
95 | .list_voltage = regulator_list_voltage_linear, | 75 | .list_voltage = regulator_list_voltage_linear, |
96 | .map_voltage = regulator_map_voltage_linear, | 76 | .map_voltage = regulator_map_voltage_linear, |
97 | .set_voltage_time_sel = rc5t583_set_voltage_time_sel, | 77 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
98 | }; | 78 | }; |
99 | 79 | ||
100 | #define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \ | 80 | #define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \ |
@@ -104,7 +84,6 @@ static struct regulator_ops rc5t583_ops = { | |||
104 | .disc_bit = _disc_bit, \ | 84 | .disc_bit = _disc_bit, \ |
105 | .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \ | 85 | .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \ |
106 | .enable_uv_per_us = _enable_mv * 1000, \ | 86 | .enable_uv_per_us = _enable_mv * 1000, \ |
107 | .change_uv_per_us = 40 * 1000, \ | ||
108 | .deepsleep_id = RC5T583_DS_##_id, \ | 87 | .deepsleep_id = RC5T583_DS_##_id, \ |
109 | .desc = { \ | 88 | .desc = { \ |
110 | .name = "rc5t583-regulator-"#_id, \ | 89 | .name = "rc5t583-regulator-"#_id, \ |
@@ -119,6 +98,7 @@ static struct regulator_ops rc5t583_ops = { | |||
119 | .enable_mask = BIT(_en_bit), \ | 98 | .enable_mask = BIT(_en_bit), \ |
120 | .min_uV = _min_mv * 1000, \ | 99 | .min_uV = _min_mv * 1000, \ |
121 | .uV_step = _step_uV, \ | 100 | .uV_step = _step_uV, \ |
101 | .ramp_delay = 40 * 1000, \ | ||
122 | }, \ | 102 | }, \ |
123 | } | 103 | } |
124 | 104 | ||
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c new file mode 100644 index 000000000000..4669dc9ac74a --- /dev/null +++ b/drivers/regulator/s2mps11.c | |||
@@ -0,0 +1,363 @@ | |||
1 | /* | ||
2 | * s2mps11.c | ||
3 | * | ||
4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd | ||
5 | * http://www.samsung.com | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
10 | * option) any later version. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/bug.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/regulator/driver.h> | ||
22 | #include <linux/regulator/machine.h> | ||
23 | #include <linux/mfd/samsung/core.h> | ||
24 | #include <linux/mfd/samsung/s2mps11.h> | ||
25 | |||
26 | struct s2mps11_info { | ||
27 | struct regulator_dev **rdev; | ||
28 | |||
29 | int ramp_delay2; | ||
30 | int ramp_delay34; | ||
31 | int ramp_delay5; | ||
32 | int ramp_delay16; | ||
33 | int ramp_delay7810; | ||
34 | int ramp_delay9; | ||
35 | |||
36 | bool buck6_ramp; | ||
37 | bool buck2_ramp; | ||
38 | bool buck3_ramp; | ||
39 | bool buck4_ramp; | ||
40 | }; | ||
41 | |||
42 | static int get_ramp_delay(int ramp_delay) | ||
43 | { | ||
44 | unsigned char cnt = 0; | ||
45 | |||
46 | ramp_delay /= 6; | ||
47 | |||
48 | while (true) { | ||
49 | ramp_delay = ramp_delay >> 1; | ||
50 | if (ramp_delay == 0) | ||
51 | break; | ||
52 | cnt++; | ||
53 | } | ||
54 | return cnt; | ||
55 | } | ||
56 | |||
57 | static struct regulator_ops s2mps11_ldo_ops = { | ||
58 | .list_voltage = regulator_list_voltage_linear, | ||
59 | .map_voltage = regulator_map_voltage_linear, | ||
60 | .is_enabled = regulator_is_enabled_regmap, | ||
61 | .enable = regulator_enable_regmap, | ||
62 | .disable = regulator_disable_regmap, | ||
63 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
64 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
65 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
66 | }; | ||
67 | |||
68 | static struct regulator_ops s2mps11_buck_ops = { | ||
69 | .list_voltage = regulator_list_voltage_linear, | ||
70 | .map_voltage = regulator_map_voltage_linear, | ||
71 | .is_enabled = regulator_is_enabled_regmap, | ||
72 | .enable = regulator_enable_regmap, | ||
73 | .disable = regulator_disable_regmap, | ||
74 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
75 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
76 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
77 | }; | ||
78 | |||
79 | #define regulator_desc_ldo1(num) { \ | ||
80 | .name = "LDO"#num, \ | ||
81 | .id = S2MPS11_LDO##num, \ | ||
82 | .ops = &s2mps11_ldo_ops, \ | ||
83 | .type = REGULATOR_VOLTAGE, \ | ||
84 | .owner = THIS_MODULE, \ | ||
85 | .min_uV = S2MPS11_LDO_MIN, \ | ||
86 | .uV_step = S2MPS11_LDO_STEP1, \ | ||
87 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ | ||
88 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ | ||
89 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ | ||
90 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ | ||
91 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
92 | } | ||
93 | #define regulator_desc_ldo2(num) { \ | ||
94 | .name = "LDO"#num, \ | ||
95 | .id = S2MPS11_LDO##num, \ | ||
96 | .ops = &s2mps11_ldo_ops, \ | ||
97 | .type = REGULATOR_VOLTAGE, \ | ||
98 | .owner = THIS_MODULE, \ | ||
99 | .min_uV = S2MPS11_LDO_MIN, \ | ||
100 | .uV_step = S2MPS11_LDO_STEP2, \ | ||
101 | .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ | ||
102 | .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \ | ||
103 | .vsel_mask = S2MPS11_LDO_VSEL_MASK, \ | ||
104 | .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \ | ||
105 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
106 | } | ||
107 | |||
108 | #define regulator_desc_buck1_4(num) { \ | ||
109 | .name = "BUCK"#num, \ | ||
110 | .id = S2MPS11_BUCK##num, \ | ||
111 | .ops = &s2mps11_buck_ops, \ | ||
112 | .type = REGULATOR_VOLTAGE, \ | ||
113 | .owner = THIS_MODULE, \ | ||
114 | .min_uV = S2MPS11_BUCK_MIN1, \ | ||
115 | .uV_step = S2MPS11_BUCK_STEP1, \ | ||
116 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | ||
117 | .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ | ||
118 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ | ||
119 | .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \ | ||
120 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
121 | } | ||
122 | |||
123 | #define regulator_desc_buck5 { \ | ||
124 | .name = "BUCK5", \ | ||
125 | .id = S2MPS11_BUCK5, \ | ||
126 | .ops = &s2mps11_buck_ops, \ | ||
127 | .type = REGULATOR_VOLTAGE, \ | ||
128 | .owner = THIS_MODULE, \ | ||
129 | .min_uV = S2MPS11_BUCK_MIN1, \ | ||
130 | .uV_step = S2MPS11_BUCK_STEP1, \ | ||
131 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | ||
132 | .vsel_reg = S2MPS11_REG_B5CTRL2, \ | ||
133 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ | ||
134 | .enable_reg = S2MPS11_REG_B5CTRL1, \ | ||
135 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
136 | } | ||
137 | |||
138 | #define regulator_desc_buck6_8(num) { \ | ||
139 | .name = "BUCK"#num, \ | ||
140 | .id = S2MPS11_BUCK##num, \ | ||
141 | .ops = &s2mps11_buck_ops, \ | ||
142 | .type = REGULATOR_VOLTAGE, \ | ||
143 | .owner = THIS_MODULE, \ | ||
144 | .min_uV = S2MPS11_BUCK_MIN1, \ | ||
145 | .uV_step = S2MPS11_BUCK_STEP1, \ | ||
146 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | ||
147 | .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ | ||
148 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ | ||
149 | .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \ | ||
150 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
151 | } | ||
152 | |||
153 | #define regulator_desc_buck9 { \ | ||
154 | .name = "BUCK9", \ | ||
155 | .id = S2MPS11_BUCK9, \ | ||
156 | .ops = &s2mps11_buck_ops, \ | ||
157 | .type = REGULATOR_VOLTAGE, \ | ||
158 | .owner = THIS_MODULE, \ | ||
159 | .min_uV = S2MPS11_BUCK_MIN3, \ | ||
160 | .uV_step = S2MPS11_BUCK_STEP3, \ | ||
161 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | ||
162 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ | ||
163 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ | ||
164 | .enable_reg = S2MPS11_REG_B9CTRL1, \ | ||
165 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
166 | } | ||
167 | |||
168 | #define regulator_desc_buck10 { \ | ||
169 | .name = "BUCK10", \ | ||
170 | .id = S2MPS11_BUCK10, \ | ||
171 | .ops = &s2mps11_buck_ops, \ | ||
172 | .type = REGULATOR_VOLTAGE, \ | ||
173 | .owner = THIS_MODULE, \ | ||
174 | .min_uV = S2MPS11_BUCK_MIN2, \ | ||
175 | .uV_step = S2MPS11_BUCK_STEP2, \ | ||
176 | .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ | ||
177 | .vsel_reg = S2MPS11_REG_B9CTRL2, \ | ||
178 | .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ | ||
179 | .enable_reg = S2MPS11_REG_B9CTRL1, \ | ||
180 | .enable_mask = S2MPS11_ENABLE_MASK \ | ||
181 | } | ||
182 | |||
183 | static struct regulator_desc regulators[] = { | ||
184 | regulator_desc_ldo2(1), | ||
185 | regulator_desc_ldo1(2), | ||
186 | regulator_desc_ldo1(3), | ||
187 | regulator_desc_ldo1(4), | ||
188 | regulator_desc_ldo1(5), | ||
189 | regulator_desc_ldo2(6), | ||
190 | regulator_desc_ldo1(7), | ||
191 | regulator_desc_ldo1(8), | ||
192 | regulator_desc_ldo1(9), | ||
193 | regulator_desc_ldo1(10), | ||
194 | regulator_desc_ldo2(11), | ||
195 | regulator_desc_ldo1(12), | ||
196 | regulator_desc_ldo1(13), | ||
197 | regulator_desc_ldo1(14), | ||
198 | regulator_desc_ldo1(15), | ||
199 | regulator_desc_ldo1(16), | ||
200 | regulator_desc_ldo1(17), | ||
201 | regulator_desc_ldo1(18), | ||
202 | regulator_desc_ldo1(19), | ||
203 | regulator_desc_ldo1(20), | ||
204 | regulator_desc_ldo1(21), | ||
205 | regulator_desc_ldo2(22), | ||
206 | regulator_desc_ldo2(23), | ||
207 | regulator_desc_ldo1(24), | ||
208 | regulator_desc_ldo1(25), | ||
209 | regulator_desc_ldo1(26), | ||
210 | regulator_desc_ldo2(27), | ||
211 | regulator_desc_ldo1(28), | ||
212 | regulator_desc_ldo1(29), | ||
213 | regulator_desc_ldo1(30), | ||
214 | regulator_desc_ldo1(31), | ||
215 | regulator_desc_ldo1(32), | ||
216 | regulator_desc_ldo1(33), | ||
217 | regulator_desc_ldo1(34), | ||
218 | regulator_desc_ldo1(35), | ||
219 | regulator_desc_ldo1(36), | ||
220 | regulator_desc_ldo1(37), | ||
221 | regulator_desc_ldo1(38), | ||
222 | regulator_desc_buck1_4(1), | ||
223 | regulator_desc_buck1_4(2), | ||
224 | regulator_desc_buck1_4(3), | ||
225 | regulator_desc_buck1_4(4), | ||
226 | regulator_desc_buck5, | ||
227 | regulator_desc_buck6_8(6), | ||
228 | regulator_desc_buck6_8(7), | ||
229 | regulator_desc_buck6_8(8), | ||
230 | regulator_desc_buck9, | ||
231 | regulator_desc_buck10, | ||
232 | }; | ||
233 | |||
234 | static __devinit int s2mps11_pmic_probe(struct platform_device *pdev) | ||
235 | { | ||
236 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); | ||
237 | struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); | ||
238 | struct regulator_config config = { }; | ||
239 | struct regulator_dev **rdev; | ||
240 | struct s2mps11_info *s2mps11; | ||
241 | int i, ret, size; | ||
242 | unsigned char ramp_enable, ramp_reg = 0; | ||
243 | |||
244 | if (!pdata) { | ||
245 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); | ||
246 | return -ENODEV; | ||
247 | } | ||
248 | |||
249 | s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), | ||
250 | GFP_KERNEL); | ||
251 | if (!s2mps11) | ||
252 | return -ENOMEM; | ||
253 | |||
254 | size = sizeof(struct regulator_dev *) * S2MPS11_REGULATOR_MAX; | ||
255 | s2mps11->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); | ||
256 | if (!s2mps11->rdev) { | ||
257 | return -ENOMEM; | ||
258 | } | ||
259 | |||
260 | rdev = s2mps11->rdev; | ||
261 | platform_set_drvdata(pdev, s2mps11); | ||
262 | |||
263 | s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; | ||
264 | s2mps11->ramp_delay34 = pdata->buck34_ramp_delay; | ||
265 | s2mps11->ramp_delay5 = pdata->buck5_ramp_delay; | ||
266 | s2mps11->ramp_delay16 = pdata->buck16_ramp_delay; | ||
267 | s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay; | ||
268 | s2mps11->ramp_delay9 = pdata->buck9_ramp_delay; | ||
269 | |||
270 | s2mps11->buck6_ramp = pdata->buck6_ramp_enable; | ||
271 | s2mps11->buck2_ramp = pdata->buck2_ramp_enable; | ||
272 | s2mps11->buck3_ramp = pdata->buck3_ramp_enable; | ||
273 | s2mps11->buck4_ramp = pdata->buck4_ramp_enable; | ||
274 | |||
275 | ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) | | ||
276 | (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ; | ||
277 | |||
278 | if (ramp_enable) { | ||
279 | if (s2mps11->buck2_ramp) | ||
280 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) >> 6; | ||
281 | if (s2mps11->buck3_ramp || s2mps11->buck4_ramp) | ||
282 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) >> 4; | ||
283 | sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable); | ||
284 | } | ||
285 | |||
286 | ramp_reg &= 0x00; | ||
287 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) >> 6; | ||
288 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) >> 4; | ||
289 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) >> 2; | ||
290 | ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9); | ||
291 | sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg); | ||
292 | |||
293 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { | ||
294 | |||
295 | config.dev = &pdev->dev; | ||
296 | config.regmap = iodev->regmap; | ||
297 | config.init_data = pdata->regulators[i].initdata; | ||
298 | config.driver_data = s2mps11; | ||
299 | |||
300 | rdev[i] = regulator_register(®ulators[i], &config); | ||
301 | if (IS_ERR(rdev[i])) { | ||
302 | ret = PTR_ERR(rdev[i]); | ||
303 | dev_err(&pdev->dev, "regulator init failed for %d\n", | ||
304 | i); | ||
305 | rdev[i] = NULL; | ||
306 | goto err; | ||
307 | } | ||
308 | } | ||
309 | |||
310 | return 0; | ||
311 | err: | ||
312 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) | ||
313 | if (rdev[i]) | ||
314 | regulator_unregister(rdev[i]); | ||
315 | |||
316 | return ret; | ||
317 | } | ||
318 | |||
319 | static int __devexit s2mps11_pmic_remove(struct platform_device *pdev) | ||
320 | { | ||
321 | struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev); | ||
322 | struct regulator_dev **rdev = s2mps11->rdev; | ||
323 | int i; | ||
324 | |||
325 | for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) | ||
326 | if (rdev[i]) | ||
327 | regulator_unregister(rdev[i]); | ||
328 | |||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static const struct platform_device_id s2mps11_pmic_id[] = { | ||
333 | { "s2mps11-pmic", 0}, | ||
334 | { }, | ||
335 | }; | ||
336 | MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id); | ||
337 | |||
338 | static struct platform_driver s2mps11_pmic_driver = { | ||
339 | .driver = { | ||
340 | .name = "s2mps11-pmic", | ||
341 | .owner = THIS_MODULE, | ||
342 | }, | ||
343 | .probe = s2mps11_pmic_probe, | ||
344 | .remove = __devexit_p(s2mps11_pmic_remove), | ||
345 | .id_table = s2mps11_pmic_id, | ||
346 | }; | ||
347 | |||
348 | static int __init s2mps11_pmic_init(void) | ||
349 | { | ||
350 | return platform_driver_register(&s2mps11_pmic_driver); | ||
351 | } | ||
352 | subsys_initcall(s2mps11_pmic_init); | ||
353 | |||
354 | static void __exit s2mps11_pmic_exit(void) | ||
355 | { | ||
356 | platform_driver_unregister(&s2mps11_pmic_driver); | ||
357 | } | ||
358 | module_exit(s2mps11_pmic_exit); | ||
359 | |||
360 | /* Module information */ | ||
361 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); | ||
362 | MODULE_DESCRIPTION("SAMSUNG S2MPS11 Regulator Driver"); | ||
363 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 9caadb482178..102287fa7ecb 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c | |||
@@ -41,6 +41,7 @@ struct s5m8767_info { | |||
41 | u8 buck3_vol[8]; | 41 | u8 buck3_vol[8]; |
42 | u8 buck4_vol[8]; | 42 | u8 buck4_vol[8]; |
43 | int buck_gpios[3]; | 43 | int buck_gpios[3]; |
44 | int buck_ds[3]; | ||
44 | int buck_gpioindex; | 45 | int buck_gpioindex; |
45 | }; | 46 | }; |
46 | 47 | ||
@@ -120,27 +121,6 @@ static const struct s5m_voltage_desc *reg_voltage_map[] = { | |||
120 | [S5M8767_BUCK9] = &buck_voltage_val3, | 121 | [S5M8767_BUCK9] = &buck_voltage_val3, |
121 | }; | 122 | }; |
122 | 123 | ||
123 | static int s5m8767_list_voltage(struct regulator_dev *rdev, | ||
124 | unsigned int selector) | ||
125 | { | ||
126 | const struct s5m_voltage_desc *desc; | ||
127 | int reg_id = rdev_get_id(rdev); | ||
128 | int val; | ||
129 | |||
130 | if (reg_id >= ARRAY_SIZE(reg_voltage_map) || reg_id < 0) | ||
131 | return -EINVAL; | ||
132 | |||
133 | desc = reg_voltage_map[reg_id]; | ||
134 | if (desc == NULL) | ||
135 | return -EINVAL; | ||
136 | |||
137 | val = desc->min + desc->step * selector; | ||
138 | if (val > desc->max) | ||
139 | return -EINVAL; | ||
140 | |||
141 | return val; | ||
142 | } | ||
143 | |||
144 | static unsigned int s5m8767_opmode_reg[][4] = { | 124 | static unsigned int s5m8767_opmode_reg[][4] = { |
145 | /* {OFF, ON, LOWPOWER, SUSPEND} */ | 125 | /* {OFF, ON, LOWPOWER, SUSPEND} */ |
146 | /* LDO1 ... LDO28 */ | 126 | /* LDO1 ... LDO28 */ |
@@ -283,17 +263,17 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) | |||
283 | reg = S5M8767_REG_BUCK1CTRL2; | 263 | reg = S5M8767_REG_BUCK1CTRL2; |
284 | break; | 264 | break; |
285 | case S5M8767_BUCK2: | 265 | case S5M8767_BUCK2: |
286 | reg = S5M8767_REG_BUCK2DVS1; | 266 | reg = S5M8767_REG_BUCK2DVS2; |
287 | if (s5m8767->buck2_gpiodvs) | 267 | if (s5m8767->buck2_gpiodvs) |
288 | reg += s5m8767->buck_gpioindex; | 268 | reg += s5m8767->buck_gpioindex; |
289 | break; | 269 | break; |
290 | case S5M8767_BUCK3: | 270 | case S5M8767_BUCK3: |
291 | reg = S5M8767_REG_BUCK3DVS1; | 271 | reg = S5M8767_REG_BUCK3DVS2; |
292 | if (s5m8767->buck3_gpiodvs) | 272 | if (s5m8767->buck3_gpiodvs) |
293 | reg += s5m8767->buck_gpioindex; | 273 | reg += s5m8767->buck_gpioindex; |
294 | break; | 274 | break; |
295 | case S5M8767_BUCK4: | 275 | case S5M8767_BUCK4: |
296 | reg = S5M8767_REG_BUCK4DVS1; | 276 | reg = S5M8767_REG_BUCK4DVS2; |
297 | if (s5m8767->buck4_gpiodvs) | 277 | if (s5m8767->buck4_gpiodvs) |
298 | reg += s5m8767->buck_gpioindex; | 278 | reg += s5m8767->buck_gpioindex; |
299 | break; | 279 | break; |
@@ -357,32 +337,34 @@ static int s5m8767_convert_voltage_to_sel( | |||
357 | return selector; | 337 | return selector; |
358 | } | 338 | } |
359 | 339 | ||
360 | static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) | 340 | static inline int s5m8767_set_high(struct s5m8767_info *s5m8767) |
361 | { | 341 | { |
362 | int temp_index = s5m8767->buck_gpioindex; | 342 | int temp_index = s5m8767->buck_gpioindex; |
363 | 343 | ||
364 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | 344 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
365 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | 345 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
366 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | 346 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
347 | |||
348 | return 0; | ||
367 | } | 349 | } |
368 | 350 | ||
369 | static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) | 351 | static inline int s5m8767_set_low(struct s5m8767_info *s5m8767) |
370 | { | 352 | { |
371 | int temp_index = s5m8767->buck_gpioindex; | 353 | int temp_index = s5m8767->buck_gpioindex; |
372 | 354 | ||
373 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | 355 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
374 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | 356 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
375 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | 357 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
358 | |||
359 | return 0; | ||
376 | } | 360 | } |
377 | 361 | ||
378 | static int s5m8767_set_voltage(struct regulator_dev *rdev, | 362 | static int s5m8767_set_voltage_sel(struct regulator_dev *rdev, |
379 | int min_uV, int max_uV, unsigned *selector) | 363 | unsigned selector) |
380 | { | 364 | { |
381 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | 365 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
382 | const struct s5m_voltage_desc *desc; | ||
383 | int reg_id = rdev_get_id(rdev); | 366 | int reg_id = rdev_get_id(rdev); |
384 | int sel, reg, mask, ret = 0, old_index, index = 0; | 367 | int reg, mask, ret = 0, old_index, index = 0; |
385 | u8 val; | ||
386 | u8 *buck234_vol = NULL; | 368 | u8 *buck234_vol = NULL; |
387 | 369 | ||
388 | switch (reg_id) { | 370 | switch (reg_id) { |
@@ -407,15 +389,9 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, | |||
407 | return -EINVAL; | 389 | return -EINVAL; |
408 | } | 390 | } |
409 | 391 | ||
410 | desc = reg_voltage_map[reg_id]; | ||
411 | |||
412 | sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); | ||
413 | if (sel < 0) | ||
414 | return sel; | ||
415 | |||
416 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ | 392 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ |
417 | if (buck234_vol) { | 393 | if (buck234_vol) { |
418 | while (*buck234_vol != sel) { | 394 | while (*buck234_vol != selector) { |
419 | buck234_vol++; | 395 | buck234_vol++; |
420 | index++; | 396 | index++; |
421 | } | 397 | } |
@@ -423,22 +399,16 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, | |||
423 | s5m8767->buck_gpioindex = index; | 399 | s5m8767->buck_gpioindex = index; |
424 | 400 | ||
425 | if (index > old_index) | 401 | if (index > old_index) |
426 | s5m8767_set_high(s5m8767); | 402 | return s5m8767_set_high(s5m8767); |
427 | else | 403 | else |
428 | s5m8767_set_low(s5m8767); | 404 | return s5m8767_set_low(s5m8767); |
429 | } else { | 405 | } else { |
430 | ret = s5m8767_get_voltage_register(rdev, ®); | 406 | ret = s5m8767_get_voltage_register(rdev, ®); |
431 | if (ret) | 407 | if (ret) |
432 | return ret; | 408 | return ret; |
433 | 409 | ||
434 | s5m_reg_read(s5m8767->iodev, reg, &val); | 410 | return s5m_reg_update(s5m8767->iodev, reg, selector, mask); |
435 | val = (val & ~mask) | sel; | ||
436 | |||
437 | ret = s5m_reg_write(s5m8767->iodev, reg, val); | ||
438 | } | 411 | } |
439 | |||
440 | *selector = sel; | ||
441 | return ret; | ||
442 | } | 412 | } |
443 | 413 | ||
444 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, | 414 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
@@ -458,15 +428,21 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, | |||
458 | } | 428 | } |
459 | 429 | ||
460 | static struct regulator_ops s5m8767_ops = { | 430 | static struct regulator_ops s5m8767_ops = { |
461 | .list_voltage = s5m8767_list_voltage, | 431 | .list_voltage = regulator_list_voltage_linear, |
462 | .is_enabled = s5m8767_reg_is_enabled, | 432 | .is_enabled = s5m8767_reg_is_enabled, |
463 | .enable = s5m8767_reg_enable, | 433 | .enable = s5m8767_reg_enable, |
464 | .disable = s5m8767_reg_disable, | 434 | .disable = s5m8767_reg_disable, |
465 | .get_voltage_sel = s5m8767_get_voltage_sel, | 435 | .get_voltage_sel = s5m8767_get_voltage_sel, |
466 | .set_voltage = s5m8767_set_voltage, | 436 | .set_voltage_sel = s5m8767_set_voltage_sel, |
467 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, | 437 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
468 | }; | 438 | }; |
469 | 439 | ||
440 | static struct regulator_ops s5m8767_buck78_ops = { | ||
441 | .is_enabled = s5m8767_reg_is_enabled, | ||
442 | .enable = s5m8767_reg_enable, | ||
443 | .disable = s5m8767_reg_disable, | ||
444 | }; | ||
445 | |||
470 | #define s5m8767_regulator_desc(_name) { \ | 446 | #define s5m8767_regulator_desc(_name) { \ |
471 | .name = #_name, \ | 447 | .name = #_name, \ |
472 | .id = S5M8767_##_name, \ | 448 | .id = S5M8767_##_name, \ |
@@ -475,6 +451,14 @@ static struct regulator_ops s5m8767_ops = { | |||
475 | .owner = THIS_MODULE, \ | 451 | .owner = THIS_MODULE, \ |
476 | } | 452 | } |
477 | 453 | ||
454 | #define s5m8767_regulator_buck78_desc(_name) { \ | ||
455 | .name = #_name, \ | ||
456 | .id = S5M8767_##_name, \ | ||
457 | .ops = &s5m8767_buck78_ops, \ | ||
458 | .type = REGULATOR_VOLTAGE, \ | ||
459 | .owner = THIS_MODULE, \ | ||
460 | } | ||
461 | |||
478 | static struct regulator_desc regulators[] = { | 462 | static struct regulator_desc regulators[] = { |
479 | s5m8767_regulator_desc(LDO1), | 463 | s5m8767_regulator_desc(LDO1), |
480 | s5m8767_regulator_desc(LDO2), | 464 | s5m8767_regulator_desc(LDO2), |
@@ -510,8 +494,8 @@ static struct regulator_desc regulators[] = { | |||
510 | s5m8767_regulator_desc(BUCK4), | 494 | s5m8767_regulator_desc(BUCK4), |
511 | s5m8767_regulator_desc(BUCK5), | 495 | s5m8767_regulator_desc(BUCK5), |
512 | s5m8767_regulator_desc(BUCK6), | 496 | s5m8767_regulator_desc(BUCK6), |
513 | s5m8767_regulator_desc(BUCK7), | 497 | s5m8767_regulator_buck78_desc(BUCK7), |
514 | s5m8767_regulator_desc(BUCK8), | 498 | s5m8767_regulator_buck78_desc(BUCK8), |
515 | s5m8767_regulator_desc(BUCK9), | 499 | s5m8767_regulator_desc(BUCK9), |
516 | }; | 500 | }; |
517 | 501 | ||
@@ -522,7 +506,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
522 | struct regulator_config config = { }; | 506 | struct regulator_config config = { }; |
523 | struct regulator_dev **rdev; | 507 | struct regulator_dev **rdev; |
524 | struct s5m8767_info *s5m8767; | 508 | struct s5m8767_info *s5m8767; |
525 | int i, ret, size; | 509 | int i, ret, size, buck_init; |
526 | 510 | ||
527 | if (!pdata) { | 511 | if (!pdata) { |
528 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); | 512 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
@@ -573,12 +557,37 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
573 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; | 557 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; |
574 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; | 558 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; |
575 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; | 559 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; |
560 | s5m8767->buck_ds[0] = pdata->buck_ds[0]; | ||
561 | s5m8767->buck_ds[1] = pdata->buck_ds[1]; | ||
562 | s5m8767->buck_ds[2] = pdata->buck_ds[2]; | ||
563 | |||
576 | s5m8767->ramp_delay = pdata->buck_ramp_delay; | 564 | s5m8767->ramp_delay = pdata->buck_ramp_delay; |
577 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; | 565 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
578 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; | 566 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
579 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; | 567 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
580 | s5m8767->opmode = pdata->opmode; | 568 | s5m8767->opmode = pdata->opmode; |
581 | 569 | ||
570 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, | ||
571 | pdata->buck2_init, | ||
572 | pdata->buck2_init + | ||
573 | buck_voltage_val2.step); | ||
574 | |||
575 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS2, buck_init); | ||
576 | |||
577 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, | ||
578 | pdata->buck3_init, | ||
579 | pdata->buck3_init + | ||
580 | buck_voltage_val2.step); | ||
581 | |||
582 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS2, buck_init); | ||
583 | |||
584 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, | ||
585 | pdata->buck4_init, | ||
586 | pdata->buck4_init + | ||
587 | buck_voltage_val2.step); | ||
588 | |||
589 | s5m_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS2, buck_init); | ||
590 | |||
582 | for (i = 0; i < 8; i++) { | 591 | for (i = 0; i < 8; i++) { |
583 | if (s5m8767->buck2_gpiodvs) { | 592 | if (s5m8767->buck2_gpiodvs) { |
584 | s5m8767->buck2_vol[i] = | 593 | s5m8767->buck2_vol[i] = |
@@ -608,48 +617,70 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
608 | } | 617 | } |
609 | } | 618 | } |
610 | 619 | ||
611 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || | 620 | if (gpio_is_valid(pdata->buck_gpios[0]) && |
612 | pdata->buck4_gpiodvs) { | 621 | gpio_is_valid(pdata->buck_gpios[1]) && |
613 | if (gpio_is_valid(pdata->buck_gpios[0]) && | 622 | gpio_is_valid(pdata->buck_gpios[2])) { |
614 | gpio_is_valid(pdata->buck_gpios[1]) && | 623 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0], |
615 | gpio_is_valid(pdata->buck_gpios[2])) { | 624 | "S5M8767 SET1"); |
616 | ret = gpio_request(pdata->buck_gpios[0], | 625 | if (ret) |
617 | "S5M8767 SET1"); | ||
618 | if (ret == -EBUSY) | ||
619 | dev_warn(&pdev->dev, "Duplicated gpio request for SET1\n"); | ||
620 | |||
621 | ret = gpio_request(pdata->buck_gpios[1], | ||
622 | "S5M8767 SET2"); | ||
623 | if (ret == -EBUSY) | ||
624 | dev_warn(&pdev->dev, "Duplicated gpio request for SET2\n"); | ||
625 | |||
626 | ret = gpio_request(pdata->buck_gpios[2], | ||
627 | "S5M8767 SET3"); | ||
628 | if (ret == -EBUSY) | ||
629 | dev_warn(&pdev->dev, "Duplicated gpio request for SET3\n"); | ||
630 | /* SET1 GPIO */ | ||
631 | gpio_direction_output(pdata->buck_gpios[0], | ||
632 | (s5m8767->buck_gpioindex >> 2) & 0x1); | ||
633 | /* SET2 GPIO */ | ||
634 | gpio_direction_output(pdata->buck_gpios[1], | ||
635 | (s5m8767->buck_gpioindex >> 1) & 0x1); | ||
636 | /* SET3 GPIO */ | ||
637 | gpio_direction_output(pdata->buck_gpios[2], | ||
638 | (s5m8767->buck_gpioindex >> 0) & 0x1); | ||
639 | ret = 0; | ||
640 | } else { | ||
641 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); | ||
642 | ret = -EINVAL; | ||
643 | return ret; | 626 | return ret; |
644 | } | 627 | |
628 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1], | ||
629 | "S5M8767 SET2"); | ||
630 | if (ret) | ||
631 | return ret; | ||
632 | |||
633 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2], | ||
634 | "S5M8767 SET3"); | ||
635 | if (ret) | ||
636 | return ret; | ||
637 | |||
638 | /* SET1 GPIO */ | ||
639 | gpio_direction_output(pdata->buck_gpios[0], | ||
640 | (s5m8767->buck_gpioindex >> 2) & 0x1); | ||
641 | /* SET2 GPIO */ | ||
642 | gpio_direction_output(pdata->buck_gpios[1], | ||
643 | (s5m8767->buck_gpioindex >> 1) & 0x1); | ||
644 | /* SET3 GPIO */ | ||
645 | gpio_direction_output(pdata->buck_gpios[2], | ||
646 | (s5m8767->buck_gpioindex >> 0) & 0x1); | ||
647 | } else { | ||
648 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); | ||
649 | ret = -EINVAL; | ||
650 | return ret; | ||
645 | } | 651 | } |
646 | 652 | ||
647 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, | 653 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2"); |
648 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); | 654 | if (ret) |
649 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, | 655 | return ret; |
650 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); | 656 | |
651 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, | 657 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3"); |
652 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1); | 658 | if (ret) |
659 | return ret; | ||
660 | |||
661 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4"); | ||
662 | if (ret) | ||
663 | return ret; | ||
664 | |||
665 | /* DS2 GPIO */ | ||
666 | gpio_direction_output(pdata->buck_ds[0], 0x0); | ||
667 | /* DS3 GPIO */ | ||
668 | gpio_direction_output(pdata->buck_ds[1], 0x0); | ||
669 | /* DS4 GPIO */ | ||
670 | gpio_direction_output(pdata->buck_ds[2], 0x0); | ||
671 | |||
672 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || | ||
673 | pdata->buck4_gpiodvs) { | ||
674 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, | ||
675 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), | ||
676 | 1 << 1); | ||
677 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, | ||
678 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), | ||
679 | 1 << 1); | ||
680 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, | ||
681 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), | ||
682 | 1 << 1); | ||
683 | } | ||
653 | 684 | ||
654 | /* Initialize GPIO DVS registers */ | 685 | /* Initialize GPIO DVS registers */ |
655 | for (i = 0; i < 8; i++) { | 686 | for (i = 0; i < 8; i++) { |
@@ -668,9 +699,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
668 | s5m8767->buck4_vol[i]); | 699 | s5m8767->buck4_vol[i]); |
669 | } | 700 | } |
670 | } | 701 | } |
671 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, 0x78, 0xff); | ||
672 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, 0x58, 0xff); | ||
673 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, 0x78, 0xff); | ||
674 | 702 | ||
675 | if (s5m8767->buck2_ramp) | 703 | if (s5m8767->buck2_ramp) |
676 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); | 704 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); |
@@ -684,9 +712,13 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
684 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp | 712 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp |
685 | || s5m8767->buck4_ramp) { | 713 | || s5m8767->buck4_ramp) { |
686 | switch (s5m8767->ramp_delay) { | 714 | switch (s5m8767->ramp_delay) { |
687 | case 15: | 715 | case 5: |
688 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, | 716 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
689 | 0xc0, 0xf0); | 717 | 0x40, 0xf0); |
718 | break; | ||
719 | case 10: | ||
720 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, | ||
721 | 0x90, 0xf0); | ||
690 | break; | 722 | break; |
691 | case 25: | 723 | case 25: |
692 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, | 724 | s5m_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
@@ -711,9 +743,12 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
711 | int id = pdata->regulators[i].id; | 743 | int id = pdata->regulators[i].id; |
712 | 744 | ||
713 | desc = reg_voltage_map[id]; | 745 | desc = reg_voltage_map[id]; |
714 | if (desc) | 746 | if (desc) { |
715 | regulators[id].n_voltages = | 747 | regulators[id].n_voltages = |
716 | (desc->max - desc->min) / desc->step + 1; | 748 | (desc->max - desc->min) / desc->step + 1; |
749 | regulators[id].min_uV = desc->min; | ||
750 | regulators[id].uV_step = desc->step; | ||
751 | } | ||
717 | 752 | ||
718 | config.dev = s5m8767->dev; | 753 | config.dev = s5m8767->dev; |
719 | config.init_data = pdata->regulators[i].initdata; | 754 | config.init_data = pdata->regulators[i].initdata; |
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c index d840d8440a91..1378409efaec 100644 --- a/drivers/regulator/tps6105x-regulator.c +++ b/drivers/regulator/tps6105x-regulator.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <linux/mfd/core.h> | 20 | #include <linux/mfd/core.h> |
21 | #include <linux/mfd/tps6105x.h> | 21 | #include <linux/mfd/tps6105x.h> |
22 | 22 | ||
23 | static const int tps6105x_voltages[] = { | 23 | static const unsigned int tps6105x_voltages[] = { |
24 | 4500000, | 24 | 4500000, |
25 | 5000000, | 25 | 5000000, |
26 | 5250000, | 26 | 5250000, |
@@ -105,22 +105,13 @@ static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev, | |||
105 | return 0; | 105 | return 0; |
106 | } | 106 | } |
107 | 107 | ||
108 | static int tps6105x_regulator_list_voltage(struct regulator_dev *rdev, | ||
109 | unsigned selector) | ||
110 | { | ||
111 | if (selector >= ARRAY_SIZE(tps6105x_voltages)) | ||
112 | return -EINVAL; | ||
113 | |||
114 | return tps6105x_voltages[selector]; | ||
115 | } | ||
116 | |||
117 | static struct regulator_ops tps6105x_regulator_ops = { | 108 | static struct regulator_ops tps6105x_regulator_ops = { |
118 | .enable = tps6105x_regulator_enable, | 109 | .enable = tps6105x_regulator_enable, |
119 | .disable = tps6105x_regulator_disable, | 110 | .disable = tps6105x_regulator_disable, |
120 | .is_enabled = tps6105x_regulator_is_enabled, | 111 | .is_enabled = tps6105x_regulator_is_enabled, |
121 | .get_voltage_sel = tps6105x_regulator_get_voltage_sel, | 112 | .get_voltage_sel = tps6105x_regulator_get_voltage_sel, |
122 | .set_voltage_sel = tps6105x_regulator_set_voltage_sel, | 113 | .set_voltage_sel = tps6105x_regulator_set_voltage_sel, |
123 | .list_voltage = tps6105x_regulator_list_voltage, | 114 | .list_voltage = regulator_list_voltage_table, |
124 | }; | 115 | }; |
125 | 116 | ||
126 | static const struct regulator_desc tps6105x_regulator_desc = { | 117 | static const struct regulator_desc tps6105x_regulator_desc = { |
@@ -130,6 +121,7 @@ static const struct regulator_desc tps6105x_regulator_desc = { | |||
130 | .id = 0, | 121 | .id = 0, |
131 | .owner = THIS_MODULE, | 122 | .owner = THIS_MODULE, |
132 | .n_voltages = ARRAY_SIZE(tps6105x_voltages), | 123 | .n_voltages = ARRAY_SIZE(tps6105x_voltages), |
124 | .volt_table = tps6105x_voltages, | ||
133 | }; | 125 | }; |
134 | 126 | ||
135 | /* | 127 | /* |
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c index e534269ed44a..68729a7c8709 100644 --- a/drivers/regulator/tps62360-regulator.c +++ b/drivers/regulator/tps62360-regulator.c | |||
@@ -65,10 +65,8 @@ struct tps62360_chip { | |||
65 | struct regulator_desc desc; | 65 | struct regulator_desc desc; |
66 | struct regulator_dev *rdev; | 66 | struct regulator_dev *rdev; |
67 | struct regmap *regmap; | 67 | struct regmap *regmap; |
68 | int chip_id; | ||
69 | int vsel0_gpio; | 68 | int vsel0_gpio; |
70 | int vsel1_gpio; | 69 | int vsel1_gpio; |
71 | int voltage_base; | ||
72 | u8 voltage_reg_mask; | 70 | u8 voltage_reg_mask; |
73 | bool en_internal_pulldn; | 71 | bool en_internal_pulldn; |
74 | bool en_discharge; | 72 | bool en_discharge; |
@@ -76,7 +74,6 @@ struct tps62360_chip { | |||
76 | int lru_index[4]; | 74 | int lru_index[4]; |
77 | int curr_vset_vsel[4]; | 75 | int curr_vset_vsel[4]; |
78 | int curr_vset_id; | 76 | int curr_vset_id; |
79 | int change_uv_per_us; | ||
80 | }; | 77 | }; |
81 | 78 | ||
82 | /* | 79 | /* |
@@ -175,23 +172,6 @@ static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev, | |||
175 | return 0; | 172 | return 0; |
176 | } | 173 | } |
177 | 174 | ||
178 | static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev, | ||
179 | unsigned int old_selector, unsigned int new_selector) | ||
180 | { | ||
181 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); | ||
182 | int old_uV, new_uV; | ||
183 | |||
184 | old_uV = regulator_list_voltage_linear(rdev, old_selector); | ||
185 | if (old_uV < 0) | ||
186 | return old_uV; | ||
187 | |||
188 | new_uV = regulator_list_voltage_linear(rdev, new_selector); | ||
189 | if (new_uV < 0) | ||
190 | return new_uV; | ||
191 | |||
192 | return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us); | ||
193 | } | ||
194 | |||
195 | static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode) | 175 | static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode) |
196 | { | 176 | { |
197 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); | 177 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); |
@@ -258,7 +238,7 @@ static struct regulator_ops tps62360_dcdc_ops = { | |||
258 | .set_voltage_sel = tps62360_dcdc_set_voltage_sel, | 238 | .set_voltage_sel = tps62360_dcdc_set_voltage_sel, |
259 | .list_voltage = regulator_list_voltage_linear, | 239 | .list_voltage = regulator_list_voltage_linear, |
260 | .map_voltage = regulator_map_voltage_linear, | 240 | .map_voltage = regulator_map_voltage_linear, |
261 | .set_voltage_time_sel = tps62360_set_voltage_time_sel, | 241 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
262 | .set_mode = tps62360_set_mode, | 242 | .set_mode = tps62360_set_mode, |
263 | .get_mode = tps62360_get_mode, | 243 | .get_mode = tps62360_get_mode, |
264 | }; | 244 | }; |
@@ -301,7 +281,7 @@ static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps, | |||
301 | ramp_ctrl = (ramp_ctrl >> 4) & 0x7; | 281 | ramp_ctrl = (ramp_ctrl >> 4) & 0x7; |
302 | 282 | ||
303 | /* ramp mV/us = 32/(2^ramp_ctrl) */ | 283 | /* ramp mV/us = 32/(2^ramp_ctrl) */ |
304 | tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl)); | 284 | tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl)); |
305 | return ret; | 285 | return ret; |
306 | } | 286 | } |
307 | 287 | ||
@@ -408,13 +388,13 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
408 | switch (chip_id) { | 388 | switch (chip_id) { |
409 | case TPS62360: | 389 | case TPS62360: |
410 | case TPS62362: | 390 | case TPS62362: |
411 | tps->voltage_base = TPS62360_BASE_VOLTAGE; | 391 | tps->desc.min_uV = TPS62360_BASE_VOLTAGE; |
412 | tps->voltage_reg_mask = 0x3F; | 392 | tps->voltage_reg_mask = 0x3F; |
413 | tps->desc.n_voltages = TPS62360_N_VOLTAGES; | 393 | tps->desc.n_voltages = TPS62360_N_VOLTAGES; |
414 | break; | 394 | break; |
415 | case TPS62361: | 395 | case TPS62361: |
416 | case TPS62363: | 396 | case TPS62363: |
417 | tps->voltage_base = TPS62361_BASE_VOLTAGE; | 397 | tps->desc.min_uV = TPS62361_BASE_VOLTAGE; |
418 | tps->voltage_reg_mask = 0x7F; | 398 | tps->voltage_reg_mask = 0x7F; |
419 | tps->desc.n_voltages = TPS62361_N_VOLTAGES; | 399 | tps->desc.n_voltages = TPS62361_N_VOLTAGES; |
420 | break; | 400 | break; |
@@ -427,7 +407,6 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
427 | tps->desc.ops = &tps62360_dcdc_ops; | 407 | tps->desc.ops = &tps62360_dcdc_ops; |
428 | tps->desc.type = REGULATOR_VOLTAGE; | 408 | tps->desc.type = REGULATOR_VOLTAGE; |
429 | tps->desc.owner = THIS_MODULE; | 409 | tps->desc.owner = THIS_MODULE; |
430 | tps->desc.min_uV = tps->voltage_base; | ||
431 | tps->desc.uV_step = 10000; | 410 | tps->desc.uV_step = 10000; |
432 | 411 | ||
433 | tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); | 412 | tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); |
@@ -449,24 +428,24 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
449 | int gpio_flags; | 428 | int gpio_flags; |
450 | gpio_flags = (pdata->vsel0_def_state) ? | 429 | gpio_flags = (pdata->vsel0_def_state) ? |
451 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | 430 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; |
452 | ret = gpio_request_one(tps->vsel0_gpio, | 431 | ret = devm_gpio_request_one(&client->dev, tps->vsel0_gpio, |
453 | gpio_flags, "tps62360-vsel0"); | 432 | gpio_flags, "tps62360-vsel0"); |
454 | if (ret) { | 433 | if (ret) { |
455 | dev_err(&client->dev, | 434 | dev_err(&client->dev, |
456 | "%s(): Could not obtain vsel0 GPIO %d: %d\n", | 435 | "%s(): Could not obtain vsel0 GPIO %d: %d\n", |
457 | __func__, tps->vsel0_gpio, ret); | 436 | __func__, tps->vsel0_gpio, ret); |
458 | goto err_gpio0; | 437 | return ret; |
459 | } | 438 | } |
460 | 439 | ||
461 | gpio_flags = (pdata->vsel1_def_state) ? | 440 | gpio_flags = (pdata->vsel1_def_state) ? |
462 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | 441 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; |
463 | ret = gpio_request_one(tps->vsel1_gpio, | 442 | ret = devm_gpio_request_one(&client->dev, tps->vsel1_gpio, |
464 | gpio_flags, "tps62360-vsel1"); | 443 | gpio_flags, "tps62360-vsel1"); |
465 | if (ret) { | 444 | if (ret) { |
466 | dev_err(&client->dev, | 445 | dev_err(&client->dev, |
467 | "%s(): Could not obtain vsel1 GPIO %d: %d\n", | 446 | "%s(): Could not obtain vsel1 GPIO %d: %d\n", |
468 | __func__, tps->vsel1_gpio, ret); | 447 | __func__, tps->vsel1_gpio, ret); |
469 | goto err_gpio1; | 448 | return ret; |
470 | } | 449 | } |
471 | tps->valid_gpios = true; | 450 | tps->valid_gpios = true; |
472 | 451 | ||
@@ -484,7 +463,7 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
484 | if (ret < 0) { | 463 | if (ret < 0) { |
485 | dev_err(tps->dev, "%s(): Init failed with err = %d\n", | 464 | dev_err(tps->dev, "%s(): Init failed with err = %d\n", |
486 | __func__, ret); | 465 | __func__, ret); |
487 | goto err_init; | 466 | return ret; |
488 | } | 467 | } |
489 | 468 | ||
490 | config.dev = &client->dev; | 469 | config.dev = &client->dev; |
@@ -498,21 +477,11 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
498 | dev_err(tps->dev, | 477 | dev_err(tps->dev, |
499 | "%s(): regulator register failed with err %s\n", | 478 | "%s(): regulator register failed with err %s\n", |
500 | __func__, id->name); | 479 | __func__, id->name); |
501 | ret = PTR_ERR(rdev); | 480 | return PTR_ERR(rdev); |
502 | goto err_init; | ||
503 | } | 481 | } |
504 | 482 | ||
505 | tps->rdev = rdev; | 483 | tps->rdev = rdev; |
506 | return 0; | 484 | return 0; |
507 | |||
508 | err_init: | ||
509 | if (gpio_is_valid(tps->vsel1_gpio)) | ||
510 | gpio_free(tps->vsel1_gpio); | ||
511 | err_gpio1: | ||
512 | if (gpio_is_valid(tps->vsel0_gpio)) | ||
513 | gpio_free(tps->vsel0_gpio); | ||
514 | err_gpio0: | ||
515 | return ret; | ||
516 | } | 485 | } |
517 | 486 | ||
518 | /** | 487 | /** |
@@ -525,12 +494,6 @@ static int __devexit tps62360_remove(struct i2c_client *client) | |||
525 | { | 494 | { |
526 | struct tps62360_chip *tps = i2c_get_clientdata(client); | 495 | struct tps62360_chip *tps = i2c_get_clientdata(client); |
527 | 496 | ||
528 | if (gpio_is_valid(tps->vsel1_gpio)) | ||
529 | gpio_free(tps->vsel1_gpio); | ||
530 | |||
531 | if (gpio_is_valid(tps->vsel0_gpio)) | ||
532 | gpio_free(tps->vsel0_gpio); | ||
533 | |||
534 | regulator_unregister(tps->rdev); | 497 | regulator_unregister(tps->rdev); |
535 | return 0; | 498 | return 0; |
536 | } | 499 | } |
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index 8f1be8586c72..6998d579d07b 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c | |||
@@ -69,10 +69,6 @@ | |||
69 | #define TPS65023_REG_CTRL2_DCDC1 BIT(1) | 69 | #define TPS65023_REG_CTRL2_DCDC1 BIT(1) |
70 | #define TPS65023_REG_CTRL2_DCDC3 BIT(0) | 70 | #define TPS65023_REG_CTRL2_DCDC3 BIT(0) |
71 | 71 | ||
72 | /* LDO_CTRL bitfields */ | ||
73 | #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) | ||
74 | #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0x07 << ((ldo_id)*4)) | ||
75 | |||
76 | /* Number of step-down converters available */ | 72 | /* Number of step-down converters available */ |
77 | #define TPS65023_NUM_DCDC 3 | 73 | #define TPS65023_NUM_DCDC 3 |
78 | /* Number of LDO voltage regulators available */ | 74 | /* Number of LDO voltage regulators available */ |
@@ -91,48 +87,53 @@ | |||
91 | #define TPS65023_MAX_REG_ID TPS65023_LDO_2 | 87 | #define TPS65023_MAX_REG_ID TPS65023_LDO_2 |
92 | 88 | ||
93 | /* Supported voltage values for regulators */ | 89 | /* Supported voltage values for regulators */ |
94 | static const u16 VCORE_VSEL_table[] = { | 90 | static const unsigned int VCORE_VSEL_table[] = { |
95 | 800, 825, 850, 875, | 91 | 800000, 825000, 850000, 875000, |
96 | 900, 925, 950, 975, | 92 | 900000, 925000, 950000, 975000, |
97 | 1000, 1025, 1050, 1075, | 93 | 1000000, 1025000, 1050000, 1075000, |
98 | 1100, 1125, 1150, 1175, | 94 | 1100000, 1125000, 1150000, 1175000, |
99 | 1200, 1225, 1250, 1275, | 95 | 1200000, 1225000, 1250000, 1275000, |
100 | 1300, 1325, 1350, 1375, | 96 | 1300000, 1325000, 1350000, 1375000, |
101 | 1400, 1425, 1450, 1475, | 97 | 1400000, 1425000, 1450000, 1475000, |
102 | 1500, 1525, 1550, 1600, | 98 | 1500000, 1525000, 1550000, 1600000, |
99 | }; | ||
100 | |||
101 | static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = { | ||
102 | 3300000, | ||
103 | }; | ||
104 | |||
105 | static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = { | ||
106 | 1800000, | ||
103 | }; | 107 | }; |
104 | 108 | ||
105 | /* Supported voltage values for LDO regulators for tps65020 */ | 109 | /* Supported voltage values for LDO regulators for tps65020 */ |
106 | static const u16 TPS65020_LDO1_VSEL_table[] = { | 110 | static const unsigned int TPS65020_LDO1_VSEL_table[] = { |
107 | 1000, 1050, 1100, 1300, | 111 | 1000000, 1050000, 1100000, 1300000, |
108 | 1800, 2500, 3000, 3300, | 112 | 1800000, 2500000, 3000000, 3300000, |
109 | }; | 113 | }; |
110 | 114 | ||
111 | static const u16 TPS65020_LDO2_VSEL_table[] = { | 115 | static const unsigned int TPS65020_LDO2_VSEL_table[] = { |
112 | 1000, 1050, 1100, 1300, | 116 | 1000000, 1050000, 1100000, 1300000, |
113 | 1800, 2500, 3000, 3300, | 117 | 1800000, 2500000, 3000000, 3300000, |
114 | }; | 118 | }; |
115 | 119 | ||
116 | /* Supported voltage values for LDO regulators | 120 | /* Supported voltage values for LDO regulators |
117 | * for tps65021 and tps65023 */ | 121 | * for tps65021 and tps65023 */ |
118 | static const u16 TPS65023_LDO1_VSEL_table[] = { | 122 | static const unsigned int TPS65023_LDO1_VSEL_table[] = { |
119 | 1000, 1100, 1300, 1800, | 123 | 1000000, 1100000, 1300000, 1800000, |
120 | 2200, 2600, 2800, 3150, | 124 | 2200000, 2600000, 2800000, 3150000, |
121 | }; | 125 | }; |
122 | 126 | ||
123 | static const u16 TPS65023_LDO2_VSEL_table[] = { | 127 | static const unsigned int TPS65023_LDO2_VSEL_table[] = { |
124 | 1050, 1200, 1300, 1800, | 128 | 1050000, 1200000, 1300000, 1800000, |
125 | 2500, 2800, 3000, 3300, | 129 | 2500000, 2800000, 3000000, 3300000, |
126 | }; | 130 | }; |
127 | 131 | ||
128 | /* Regulator specific details */ | 132 | /* Regulator specific details */ |
129 | struct tps_info { | 133 | struct tps_info { |
130 | const char *name; | 134 | const char *name; |
131 | unsigned min_uV; | ||
132 | unsigned max_uV; | ||
133 | bool fixed; | ||
134 | u8 table_len; | 135 | u8 table_len; |
135 | const u16 *table; | 136 | const unsigned int *table; |
136 | }; | 137 | }; |
137 | 138 | ||
138 | /* PMIC details */ | 139 | /* PMIC details */ |
@@ -150,7 +151,7 @@ struct tps_driver_data { | |||
150 | u8 core_regulator; | 151 | u8 core_regulator; |
151 | }; | 152 | }; |
152 | 153 | ||
153 | static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) | 154 | static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev) |
154 | { | 155 | { |
155 | struct tps_pmic *tps = rdev_get_drvdata(dev); | 156 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
156 | int ret; | 157 | int ret; |
@@ -164,9 +165,9 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) | |||
164 | if (ret != 0) | 165 | if (ret != 0) |
165 | return ret; | 166 | return ret; |
166 | data &= (tps->info[dcdc]->table_len - 1); | 167 | data &= (tps->info[dcdc]->table_len - 1); |
167 | return tps->info[dcdc]->table[data] * 1000; | 168 | return data; |
168 | } else | 169 | } else |
169 | return tps->info[dcdc]->min_uV; | 170 | return 0; |
170 | } | 171 | } |
171 | 172 | ||
172 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, | 173 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, |
@@ -193,76 +194,14 @@ out: | |||
193 | return ret; | 194 | return ret; |
194 | } | 195 | } |
195 | 196 | ||
196 | static int tps65023_ldo_get_voltage(struct regulator_dev *dev) | ||
197 | { | ||
198 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
199 | int data, ldo = rdev_get_id(dev); | ||
200 | int ret; | ||
201 | |||
202 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
203 | return -EINVAL; | ||
204 | |||
205 | ret = regmap_read(tps->regmap, TPS65023_REG_LDO_CTRL, &data); | ||
206 | if (ret != 0) | ||
207 | return ret; | ||
208 | |||
209 | data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)); | ||
210 | data &= (tps->info[ldo]->table_len - 1); | ||
211 | return tps->info[ldo]->table[data] * 1000; | ||
212 | } | ||
213 | |||
214 | static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev, | ||
215 | unsigned selector) | ||
216 | { | ||
217 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
218 | int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1; | ||
219 | |||
220 | return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL, | ||
221 | TPS65023_LDO_CTRL_LDOx_MASK(ldo_index), | ||
222 | selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index)); | ||
223 | } | ||
224 | |||
225 | static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, | ||
226 | unsigned selector) | ||
227 | { | ||
228 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
229 | int dcdc = rdev_get_id(dev); | ||
230 | |||
231 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | ||
232 | return -EINVAL; | ||
233 | |||
234 | if (dcdc == tps->core_regulator) { | ||
235 | if (selector >= tps->info[dcdc]->table_len) | ||
236 | return -EINVAL; | ||
237 | else | ||
238 | return tps->info[dcdc]->table[selector] * 1000; | ||
239 | } else | ||
240 | return tps->info[dcdc]->min_uV; | ||
241 | } | ||
242 | |||
243 | static int tps65023_ldo_list_voltage(struct regulator_dev *dev, | ||
244 | unsigned selector) | ||
245 | { | ||
246 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
247 | int ldo = rdev_get_id(dev); | ||
248 | |||
249 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
250 | return -EINVAL; | ||
251 | |||
252 | if (selector >= tps->info[ldo]->table_len) | ||
253 | return -EINVAL; | ||
254 | else | ||
255 | return tps->info[ldo]->table[selector] * 1000; | ||
256 | } | ||
257 | |||
258 | /* Operations permitted on VDCDCx */ | 197 | /* Operations permitted on VDCDCx */ |
259 | static struct regulator_ops tps65023_dcdc_ops = { | 198 | static struct regulator_ops tps65023_dcdc_ops = { |
260 | .is_enabled = regulator_is_enabled_regmap, | 199 | .is_enabled = regulator_is_enabled_regmap, |
261 | .enable = regulator_enable_regmap, | 200 | .enable = regulator_enable_regmap, |
262 | .disable = regulator_disable_regmap, | 201 | .disable = regulator_disable_regmap, |
263 | .get_voltage = tps65023_dcdc_get_voltage, | 202 | .get_voltage_sel = tps65023_dcdc_get_voltage_sel, |
264 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, | 203 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, |
265 | .list_voltage = tps65023_dcdc_list_voltage, | 204 | .list_voltage = regulator_list_voltage_table, |
266 | }; | 205 | }; |
267 | 206 | ||
268 | /* Operations permitted on LDOx */ | 207 | /* Operations permitted on LDOx */ |
@@ -270,9 +209,9 @@ static struct regulator_ops tps65023_ldo_ops = { | |||
270 | .is_enabled = regulator_is_enabled_regmap, | 209 | .is_enabled = regulator_is_enabled_regmap, |
271 | .enable = regulator_enable_regmap, | 210 | .enable = regulator_enable_regmap, |
272 | .disable = regulator_disable_regmap, | 211 | .disable = regulator_disable_regmap, |
273 | .get_voltage = tps65023_ldo_get_voltage, | 212 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
274 | .set_voltage_sel = tps65023_ldo_set_voltage_sel, | 213 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
275 | .list_voltage = tps65023_ldo_list_voltage, | 214 | .list_voltage = regulator_list_voltage_table, |
276 | }; | 215 | }; |
277 | 216 | ||
278 | static struct regmap_config tps65023_regmap_config = { | 217 | static struct regmap_config tps65023_regmap_config = { |
@@ -325,19 +264,28 @@ static int __devinit tps_65023_probe(struct i2c_client *client, | |||
325 | tps->desc[i].name = info->name; | 264 | tps->desc[i].name = info->name; |
326 | tps->desc[i].id = i; | 265 | tps->desc[i].id = i; |
327 | tps->desc[i].n_voltages = info->table_len; | 266 | tps->desc[i].n_voltages = info->table_len; |
267 | tps->desc[i].volt_table = info->table; | ||
328 | tps->desc[i].ops = (i > TPS65023_DCDC_3 ? | 268 | tps->desc[i].ops = (i > TPS65023_DCDC_3 ? |
329 | &tps65023_ldo_ops : &tps65023_dcdc_ops); | 269 | &tps65023_ldo_ops : &tps65023_dcdc_ops); |
330 | tps->desc[i].type = REGULATOR_VOLTAGE; | 270 | tps->desc[i].type = REGULATOR_VOLTAGE; |
331 | tps->desc[i].owner = THIS_MODULE; | 271 | tps->desc[i].owner = THIS_MODULE; |
332 | 272 | ||
333 | tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; | 273 | tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; |
334 | if (i == TPS65023_LDO_1) | 274 | switch (i) { |
275 | case TPS65023_LDO_1: | ||
276 | tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; | ||
277 | tps->desc[i].vsel_mask = 0x07; | ||
335 | tps->desc[i].enable_mask = 1 << 1; | 278 | tps->desc[i].enable_mask = 1 << 1; |
336 | else if (i == TPS65023_LDO_2) | 279 | break; |
280 | case TPS65023_LDO_2: | ||
281 | tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; | ||
282 | tps->desc[i].vsel_mask = 0x70; | ||
337 | tps->desc[i].enable_mask = 1 << 2; | 283 | tps->desc[i].enable_mask = 1 << 2; |
338 | else /* DCDCx */ | 284 | break; |
285 | default: /* DCDCx */ | ||
339 | tps->desc[i].enable_mask = | 286 | tps->desc[i].enable_mask = |
340 | 1 << (TPS65023_NUM_REGULATOR - i); | 287 | 1 << (TPS65023_NUM_REGULATOR - i); |
288 | } | ||
341 | 289 | ||
342 | config.dev = &client->dev; | 290 | config.dev = &client->dev; |
343 | config.init_data = init_data; | 291 | config.init_data = init_data; |
@@ -384,35 +332,26 @@ static int __devexit tps_65023_remove(struct i2c_client *client) | |||
384 | static const struct tps_info tps65020_regs[] = { | 332 | static const struct tps_info tps65020_regs[] = { |
385 | { | 333 | { |
386 | .name = "VDCDC1", | 334 | .name = "VDCDC1", |
387 | .min_uV = 3300000, | 335 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
388 | .max_uV = 3300000, | 336 | .table = DCDC_FIXED_3300000_VSEL_table, |
389 | .fixed = 1, | ||
390 | }, | 337 | }, |
391 | { | 338 | { |
392 | .name = "VDCDC2", | 339 | .name = "VDCDC2", |
393 | .min_uV = 1800000, | 340 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
394 | .max_uV = 1800000, | 341 | .table = DCDC_FIXED_1800000_VSEL_table, |
395 | .fixed = 1, | ||
396 | }, | 342 | }, |
397 | { | 343 | { |
398 | .name = "VDCDC3", | 344 | .name = "VDCDC3", |
399 | .min_uV = 800000, | ||
400 | .max_uV = 1600000, | ||
401 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), | 345 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
402 | .table = VCORE_VSEL_table, | 346 | .table = VCORE_VSEL_table, |
403 | }, | 347 | }, |
404 | |||
405 | { | 348 | { |
406 | .name = "LDO1", | 349 | .name = "LDO1", |
407 | .min_uV = 1000000, | ||
408 | .max_uV = 3150000, | ||
409 | .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), | 350 | .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), |
410 | .table = TPS65020_LDO1_VSEL_table, | 351 | .table = TPS65020_LDO1_VSEL_table, |
411 | }, | 352 | }, |
412 | { | 353 | { |
413 | .name = "LDO2", | 354 | .name = "LDO2", |
414 | .min_uV = 1050000, | ||
415 | .max_uV = 3300000, | ||
416 | .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), | 355 | .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), |
417 | .table = TPS65020_LDO2_VSEL_table, | 356 | .table = TPS65020_LDO2_VSEL_table, |
418 | }, | 357 | }, |
@@ -421,34 +360,26 @@ static const struct tps_info tps65020_regs[] = { | |||
421 | static const struct tps_info tps65021_regs[] = { | 360 | static const struct tps_info tps65021_regs[] = { |
422 | { | 361 | { |
423 | .name = "VDCDC1", | 362 | .name = "VDCDC1", |
424 | .min_uV = 3300000, | 363 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
425 | .max_uV = 3300000, | 364 | .table = DCDC_FIXED_3300000_VSEL_table, |
426 | .fixed = 1, | ||
427 | }, | 365 | }, |
428 | { | 366 | { |
429 | .name = "VDCDC2", | 367 | .name = "VDCDC2", |
430 | .min_uV = 1800000, | 368 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
431 | .max_uV = 1800000, | 369 | .table = DCDC_FIXED_1800000_VSEL_table, |
432 | .fixed = 1, | ||
433 | }, | 370 | }, |
434 | { | 371 | { |
435 | .name = "VDCDC3", | 372 | .name = "VDCDC3", |
436 | .min_uV = 800000, | ||
437 | .max_uV = 1600000, | ||
438 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), | 373 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
439 | .table = VCORE_VSEL_table, | 374 | .table = VCORE_VSEL_table, |
440 | }, | 375 | }, |
441 | { | 376 | { |
442 | .name = "LDO1", | 377 | .name = "LDO1", |
443 | .min_uV = 1000000, | ||
444 | .max_uV = 3150000, | ||
445 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), | 378 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
446 | .table = TPS65023_LDO1_VSEL_table, | 379 | .table = TPS65023_LDO1_VSEL_table, |
447 | }, | 380 | }, |
448 | { | 381 | { |
449 | .name = "LDO2", | 382 | .name = "LDO2", |
450 | .min_uV = 1050000, | ||
451 | .max_uV = 3300000, | ||
452 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), | 383 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
453 | .table = TPS65023_LDO2_VSEL_table, | 384 | .table = TPS65023_LDO2_VSEL_table, |
454 | }, | 385 | }, |
@@ -457,34 +388,26 @@ static const struct tps_info tps65021_regs[] = { | |||
457 | static const struct tps_info tps65023_regs[] = { | 388 | static const struct tps_info tps65023_regs[] = { |
458 | { | 389 | { |
459 | .name = "VDCDC1", | 390 | .name = "VDCDC1", |
460 | .min_uV = 800000, | ||
461 | .max_uV = 1600000, | ||
462 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), | 391 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
463 | .table = VCORE_VSEL_table, | 392 | .table = VCORE_VSEL_table, |
464 | }, | 393 | }, |
465 | { | 394 | { |
466 | .name = "VDCDC2", | 395 | .name = "VDCDC2", |
467 | .min_uV = 3300000, | 396 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
468 | .max_uV = 3300000, | 397 | .table = DCDC_FIXED_3300000_VSEL_table, |
469 | .fixed = 1, | ||
470 | }, | 398 | }, |
471 | { | 399 | { |
472 | .name = "VDCDC3", | 400 | .name = "VDCDC3", |
473 | .min_uV = 1800000, | 401 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
474 | .max_uV = 1800000, | 402 | .table = DCDC_FIXED_1800000_VSEL_table, |
475 | .fixed = 1, | ||
476 | }, | 403 | }, |
477 | { | 404 | { |
478 | .name = "LDO1", | 405 | .name = "LDO1", |
479 | .min_uV = 1000000, | ||
480 | .max_uV = 3150000, | ||
481 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), | 406 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
482 | .table = TPS65023_LDO1_VSEL_table, | 407 | .table = TPS65023_LDO1_VSEL_table, |
483 | }, | 408 | }, |
484 | { | 409 | { |
485 | .name = "LDO2", | 410 | .name = "LDO2", |
486 | .min_uV = 1050000, | ||
487 | .max_uV = 3300000, | ||
488 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), | 411 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
489 | .table = TPS65023_LDO2_VSEL_table, | 412 | .table = TPS65023_LDO2_VSEL_table, |
490 | }, | 413 | }, |
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index da38be1016aa..07d01ccdf308 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c | |||
@@ -43,58 +43,40 @@ | |||
43 | /* Number of total regulators available */ | 43 | /* Number of total regulators available */ |
44 | #define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO) | 44 | #define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO) |
45 | 45 | ||
46 | /* Supported voltage values for regulators (in milliVolts) */ | 46 | /* Supported voltage values for regulators (in microVolts) */ |
47 | static const u16 VDCDCx_VSEL_table[] = { | 47 | static const unsigned int VDCDCx_VSEL_table[] = { |
48 | 725, 750, 775, 800, | 48 | 725000, 750000, 775000, 800000, |
49 | 825, 850, 875, 900, | 49 | 825000, 850000, 875000, 900000, |
50 | 925, 950, 975, 1000, | 50 | 925000, 950000, 975000, 1000000, |
51 | 1025, 1050, 1075, 1100, | 51 | 1025000, 1050000, 1075000, 1100000, |
52 | 1125, 1150, 1175, 1200, | 52 | 1125000, 1150000, 1175000, 1200000, |
53 | 1225, 1250, 1275, 1300, | 53 | 1225000, 1250000, 1275000, 1300000, |
54 | 1325, 1350, 1375, 1400, | 54 | 1325000, 1350000, 1375000, 1400000, |
55 | 1425, 1450, 1475, 1500, | 55 | 1425000, 1450000, 1475000, 1500000, |
56 | 1550, 1600, 1650, 1700, | 56 | 1550000, 1600000, 1650000, 1700000, |
57 | 1750, 1800, 1850, 1900, | 57 | 1750000, 1800000, 1850000, 1900000, |
58 | 1950, 2000, 2050, 2100, | 58 | 1950000, 2000000, 2050000, 2100000, |
59 | 2150, 2200, 2250, 2300, | 59 | 2150000, 2200000, 2250000, 2300000, |
60 | 2350, 2400, 2450, 2500, | 60 | 2350000, 2400000, 2450000, 2500000, |
61 | 2550, 2600, 2650, 2700, | 61 | 2550000, 2600000, 2650000, 2700000, |
62 | 2750, 2800, 2850, 2900, | 62 | 2750000, 2800000, 2850000, 2900000, |
63 | 3000, 3100, 3200, 3300, | 63 | 3000000, 3100000, 3200000, 3300000, |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static const u16 LDO1_VSEL_table[] = { | 66 | static const unsigned int LDO1_VSEL_table[] = { |
67 | 1000, 1100, 1200, 1250, | 67 | 1000000, 1100000, 1200000, 1250000, |
68 | 1300, 1350, 1400, 1500, | 68 | 1300000, 1350000, 1400000, 1500000, |
69 | 1600, 1800, 2500, 2750, | 69 | 1600000, 1800000, 2500000, 2750000, |
70 | 2800, 3000, 3100, 3300, | 70 | 2800000, 3000000, 3100000, 3300000, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static const u16 LDO2_VSEL_table[] = { | 73 | /* The voltage mapping table for LDO2 is the same as VDCDCx */ |
74 | 725, 750, 775, 800, | 74 | #define LDO2_VSEL_table VDCDCx_VSEL_table |
75 | 825, 850, 875, 900, | ||
76 | 925, 950, 975, 1000, | ||
77 | 1025, 1050, 1075, 1100, | ||
78 | 1125, 1150, 1175, 1200, | ||
79 | 1225, 1250, 1275, 1300, | ||
80 | 1325, 1350, 1375, 1400, | ||
81 | 1425, 1450, 1475, 1500, | ||
82 | 1550, 1600, 1650, 1700, | ||
83 | 1750, 1800, 1850, 1900, | ||
84 | 1950, 2000, 2050, 2100, | ||
85 | 2150, 2200, 2250, 2300, | ||
86 | 2350, 2400, 2450, 2500, | ||
87 | 2550, 2600, 2650, 2700, | ||
88 | 2750, 2800, 2850, 2900, | ||
89 | 3000, 3100, 3200, 3300, | ||
90 | }; | ||
91 | 75 | ||
92 | struct tps_info { | 76 | struct tps_info { |
93 | const char *name; | 77 | const char *name; |
94 | unsigned min_uV; | ||
95 | unsigned max_uV; | ||
96 | u8 table_len; | 78 | u8 table_len; |
97 | const u16 *table; | 79 | const unsigned int *table; |
98 | 80 | ||
99 | /* Does DCDC high or the low register defines output voltage? */ | 81 | /* Does DCDC high or the low register defines output voltage? */ |
100 | bool defdcdc_default; | 82 | bool defdcdc_default; |
@@ -103,36 +85,26 @@ struct tps_info { | |||
103 | static struct tps_info tps6507x_pmic_regs[] = { | 85 | static struct tps_info tps6507x_pmic_regs[] = { |
104 | { | 86 | { |
105 | .name = "VDCDC1", | 87 | .name = "VDCDC1", |
106 | .min_uV = 725000, | ||
107 | .max_uV = 3300000, | ||
108 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), | 88 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), |
109 | .table = VDCDCx_VSEL_table, | 89 | .table = VDCDCx_VSEL_table, |
110 | }, | 90 | }, |
111 | { | 91 | { |
112 | .name = "VDCDC2", | 92 | .name = "VDCDC2", |
113 | .min_uV = 725000, | ||
114 | .max_uV = 3300000, | ||
115 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), | 93 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), |
116 | .table = VDCDCx_VSEL_table, | 94 | .table = VDCDCx_VSEL_table, |
117 | }, | 95 | }, |
118 | { | 96 | { |
119 | .name = "VDCDC3", | 97 | .name = "VDCDC3", |
120 | .min_uV = 725000, | ||
121 | .max_uV = 3300000, | ||
122 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), | 98 | .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), |
123 | .table = VDCDCx_VSEL_table, | 99 | .table = VDCDCx_VSEL_table, |
124 | }, | 100 | }, |
125 | { | 101 | { |
126 | .name = "LDO1", | 102 | .name = "LDO1", |
127 | .min_uV = 1000000, | ||
128 | .max_uV = 3300000, | ||
129 | .table_len = ARRAY_SIZE(LDO1_VSEL_table), | 103 | .table_len = ARRAY_SIZE(LDO1_VSEL_table), |
130 | .table = LDO1_VSEL_table, | 104 | .table = LDO1_VSEL_table, |
131 | }, | 105 | }, |
132 | { | 106 | { |
133 | .name = "LDO2", | 107 | .name = "LDO2", |
134 | .min_uV = 725000, | ||
135 | .max_uV = 3300000, | ||
136 | .table_len = ARRAY_SIZE(LDO2_VSEL_table), | 108 | .table_len = ARRAY_SIZE(LDO2_VSEL_table), |
137 | .table = LDO2_VSEL_table, | 109 | .table = LDO2_VSEL_table, |
138 | }, | 110 | }, |
@@ -375,28 +347,13 @@ static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, | |||
375 | return tps6507x_pmic_reg_write(tps, reg, data); | 347 | return tps6507x_pmic_reg_write(tps, reg, data); |
376 | } | 348 | } |
377 | 349 | ||
378 | static int tps6507x_pmic_list_voltage(struct regulator_dev *dev, | ||
379 | unsigned selector) | ||
380 | { | ||
381 | struct tps6507x_pmic *tps = rdev_get_drvdata(dev); | ||
382 | int rid = rdev_get_id(dev); | ||
383 | |||
384 | if (rid < TPS6507X_DCDC_1 || rid > TPS6507X_LDO_2) | ||
385 | return -EINVAL; | ||
386 | |||
387 | if (selector >= tps->info[rid]->table_len) | ||
388 | return -EINVAL; | ||
389 | else | ||
390 | return tps->info[rid]->table[selector] * 1000; | ||
391 | } | ||
392 | |||
393 | static struct regulator_ops tps6507x_pmic_ops = { | 350 | static struct regulator_ops tps6507x_pmic_ops = { |
394 | .is_enabled = tps6507x_pmic_is_enabled, | 351 | .is_enabled = tps6507x_pmic_is_enabled, |
395 | .enable = tps6507x_pmic_enable, | 352 | .enable = tps6507x_pmic_enable, |
396 | .disable = tps6507x_pmic_disable, | 353 | .disable = tps6507x_pmic_disable, |
397 | .get_voltage_sel = tps6507x_pmic_get_voltage_sel, | 354 | .get_voltage_sel = tps6507x_pmic_get_voltage_sel, |
398 | .set_voltage_sel = tps6507x_pmic_set_voltage_sel, | 355 | .set_voltage_sel = tps6507x_pmic_set_voltage_sel, |
399 | .list_voltage = tps6507x_pmic_list_voltage, | 356 | .list_voltage = regulator_list_voltage_table, |
400 | }; | 357 | }; |
401 | 358 | ||
402 | static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | 359 | static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) |
@@ -449,6 +406,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | |||
449 | tps->desc[i].name = info->name; | 406 | tps->desc[i].name = info->name; |
450 | tps->desc[i].id = i; | 407 | tps->desc[i].id = i; |
451 | tps->desc[i].n_voltages = info->table_len; | 408 | tps->desc[i].n_voltages = info->table_len; |
409 | tps->desc[i].volt_table = info->table; | ||
452 | tps->desc[i].ops = &tps6507x_pmic_ops; | 410 | tps->desc[i].ops = &tps6507x_pmic_ops; |
453 | tps->desc[i].type = REGULATOR_VOLTAGE; | 411 | tps->desc[i].type = REGULATOR_VOLTAGE; |
454 | tps->desc[i].owner = THIS_MODULE; | 412 | tps->desc[i].owner = THIS_MODULE; |
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 9d371d2cbcae..6caa222af77a 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <linux/regulator/machine.h> | 26 | #include <linux/regulator/machine.h> |
27 | #include <linux/mfd/tps65217.h> | 27 | #include <linux/mfd/tps65217.h> |
28 | 28 | ||
29 | #define TPS65217_REGULATOR(_name, _id, _ops, _n) \ | 29 | #define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t) \ |
30 | { \ | 30 | { \ |
31 | .name = _name, \ | 31 | .name = _name, \ |
32 | .id = _id, \ | 32 | .id = _id, \ |
@@ -34,23 +34,23 @@ | |||
34 | .n_voltages = _n, \ | 34 | .n_voltages = _n, \ |
35 | .type = REGULATOR_VOLTAGE, \ | 35 | .type = REGULATOR_VOLTAGE, \ |
36 | .owner = THIS_MODULE, \ | 36 | .owner = THIS_MODULE, \ |
37 | .vsel_reg = _vr, \ | ||
38 | .vsel_mask = _vm, \ | ||
39 | .enable_reg = TPS65217_REG_ENABLE, \ | ||
40 | .enable_mask = _em, \ | ||
41 | .volt_table = _t, \ | ||
37 | } \ | 42 | } \ |
38 | 43 | ||
39 | #define TPS65217_INFO(_nm, _min, _max, _f1, _f2, _t, _n, _em, _vr, _vm) \ | 44 | #define TPS65217_INFO(_nm, _min, _max, _f1, _f2) \ |
40 | { \ | 45 | { \ |
41 | .name = _nm, \ | 46 | .name = _nm, \ |
42 | .min_uV = _min, \ | 47 | .min_uV = _min, \ |
43 | .max_uV = _max, \ | 48 | .max_uV = _max, \ |
44 | .vsel_to_uv = _f1, \ | 49 | .vsel_to_uv = _f1, \ |
45 | .uv_to_vsel = _f2, \ | 50 | .uv_to_vsel = _f2, \ |
46 | .table = _t, \ | ||
47 | .table_len = _n, \ | ||
48 | .enable_mask = _em, \ | ||
49 | .set_vout_reg = _vr, \ | ||
50 | .set_vout_mask = _vm, \ | ||
51 | } | 51 | } |
52 | 52 | ||
53 | static const int LDO1_VSEL_table[] = { | 53 | static const unsigned int LDO1_VSEL_table[] = { |
54 | 1000000, 1100000, 1200000, 1250000, | 54 | 1000000, 1100000, 1200000, 1250000, |
55 | 1300000, 1350000, 1400000, 1500000, | 55 | 1300000, 1350000, 1400000, 1500000, |
56 | 1600000, 1800000, 2500000, 2750000, | 56 | 1600000, 1800000, 2500000, 2750000, |
@@ -78,7 +78,7 @@ static int tps65217_vsel_to_uv1(unsigned int vsel) | |||
78 | 78 | ||
79 | static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) | 79 | static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel) |
80 | { | 80 | { |
81 | if ((uV < 0) && (uV > 3300000)) | 81 | if (uV < 0 || uV > 3300000) |
82 | return -EINVAL; | 82 | return -EINVAL; |
83 | 83 | ||
84 | if (uV <= 1500000) | 84 | if (uV <= 1500000) |
@@ -112,7 +112,7 @@ static int tps65217_vsel_to_uv2(unsigned int vsel) | |||
112 | 112 | ||
113 | static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) | 113 | static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) |
114 | { | 114 | { |
115 | if ((uV < 0) && (uV > 3300000)) | 115 | if (uV < 0 || uV > 3300000) |
116 | return -EINVAL; | 116 | return -EINVAL; |
117 | 117 | ||
118 | if (uV <= 1900000) | 118 | if (uV <= 1900000) |
@@ -127,46 +127,20 @@ static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel) | |||
127 | 127 | ||
128 | static struct tps_info tps65217_pmic_regs[] = { | 128 | static struct tps_info tps65217_pmic_regs[] = { |
129 | TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, | 129 | TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, |
130 | tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC1_EN, | 130 | tps65217_uv_to_vsel1), |
131 | TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK), | ||
132 | TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, | 131 | TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, |
133 | tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC2_EN, | 132 | tps65217_uv_to_vsel1), |
134 | TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK), | ||
135 | TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, | 133 | TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, |
136 | tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_DC3_EN, | 134 | tps65217_uv_to_vsel1), |
137 | TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK), | 135 | TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL), |
138 | TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL, LDO1_VSEL_table, | ||
139 | 16, TPS65217_ENABLE_LDO1_EN, TPS65217_REG_DEFLDO1, | ||
140 | TPS65217_DEFLDO1_LDO1_MASK), | ||
141 | TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, | 136 | TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1, |
142 | tps65217_uv_to_vsel1, NULL, 64, TPS65217_ENABLE_LDO2_EN, | 137 | tps65217_uv_to_vsel1), |
143 | TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK), | ||
144 | TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, | 138 | TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2, |
145 | tps65217_uv_to_vsel2, NULL, 32, | 139 | tps65217_uv_to_vsel2), |
146 | TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, | ||
147 | TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK), | ||
148 | TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, | 140 | TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2, |
149 | tps65217_uv_to_vsel2, NULL, 32, | 141 | tps65217_uv_to_vsel2), |
150 | TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, | ||
151 | TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), | ||
152 | }; | 142 | }; |
153 | 143 | ||
154 | static int tps65217_pmic_is_enabled(struct regulator_dev *dev) | ||
155 | { | ||
156 | int ret; | ||
157 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
158 | unsigned int data, rid = rdev_get_id(dev); | ||
159 | |||
160 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) | ||
161 | return -EINVAL; | ||
162 | |||
163 | ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); | ||
164 | if (ret) | ||
165 | return ret; | ||
166 | |||
167 | return (data & tps->info[rid]->enable_mask) ? 1 : 0; | ||
168 | } | ||
169 | |||
170 | static int tps65217_pmic_enable(struct regulator_dev *dev) | 144 | static int tps65217_pmic_enable(struct regulator_dev *dev) |
171 | { | 145 | { |
172 | struct tps65217 *tps = rdev_get_drvdata(dev); | 146 | struct tps65217 *tps = rdev_get_drvdata(dev); |
@@ -177,9 +151,8 @@ static int tps65217_pmic_enable(struct regulator_dev *dev) | |||
177 | 151 | ||
178 | /* Enable the regulator and password protection is level 1 */ | 152 | /* Enable the regulator and password protection is level 1 */ |
179 | return tps65217_set_bits(tps, TPS65217_REG_ENABLE, | 153 | return tps65217_set_bits(tps, TPS65217_REG_ENABLE, |
180 | tps->info[rid]->enable_mask, | 154 | dev->desc->enable_mask, dev->desc->enable_mask, |
181 | tps->info[rid]->enable_mask, | 155 | TPS65217_PROTECT_L1); |
182 | TPS65217_PROTECT_L1); | ||
183 | } | 156 | } |
184 | 157 | ||
185 | static int tps65217_pmic_disable(struct regulator_dev *dev) | 158 | static int tps65217_pmic_disable(struct regulator_dev *dev) |
@@ -192,25 +165,7 @@ static int tps65217_pmic_disable(struct regulator_dev *dev) | |||
192 | 165 | ||
193 | /* Disable the regulator and password protection is level 1 */ | 166 | /* Disable the regulator and password protection is level 1 */ |
194 | return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, | 167 | return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, |
195 | tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); | 168 | dev->desc->enable_mask, TPS65217_PROTECT_L1); |
196 | } | ||
197 | |||
198 | static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev) | ||
199 | { | ||
200 | int ret; | ||
201 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
202 | unsigned int selector, rid = rdev_get_id(dev); | ||
203 | |||
204 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) | ||
205 | return -EINVAL; | ||
206 | |||
207 | ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector); | ||
208 | if (ret) | ||
209 | return ret; | ||
210 | |||
211 | selector &= tps->info[rid]->set_vout_mask; | ||
212 | |||
213 | return selector; | ||
214 | } | 169 | } |
215 | 170 | ||
216 | static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, | 171 | static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, |
@@ -221,8 +176,7 @@ static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, | |||
221 | unsigned int rid = rdev_get_id(dev); | 176 | unsigned int rid = rdev_get_id(dev); |
222 | 177 | ||
223 | /* Set the voltage based on vsel value and write protect level is 2 */ | 178 | /* Set the voltage based on vsel value and write protect level is 2 */ |
224 | ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, | 179 | ret = tps65217_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask, |
225 | tps->info[rid]->set_vout_mask, | ||
226 | selector, TPS65217_PROTECT_L2); | 180 | selector, TPS65217_PROTECT_L2); |
227 | 181 | ||
228 | /* Set GO bit for DCDCx to initiate voltage transistion */ | 182 | /* Set GO bit for DCDCx to initiate voltage transistion */ |
@@ -252,10 +206,10 @@ static int tps65217_pmic_map_voltage(struct regulator_dev *dev, | |||
252 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) | 206 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
253 | return -EINVAL; | 207 | return -EINVAL; |
254 | 208 | ||
255 | if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) | 209 | if (min_uV < tps->info[rid]->min_uV) |
256 | return -EINVAL; | 210 | min_uV = tps->info[rid]->min_uV; |
257 | 211 | ||
258 | if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV) | 212 | if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) |
259 | return -EINVAL; | 213 | return -EINVAL; |
260 | 214 | ||
261 | ret = tps->info[rid]->uv_to_vsel(min_uV, &sel); | 215 | ret = tps->info[rid]->uv_to_vsel(min_uV, &sel); |
@@ -274,21 +228,18 @@ static int tps65217_pmic_list_voltage(struct regulator_dev *dev, | |||
274 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) | 228 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
275 | return -EINVAL; | 229 | return -EINVAL; |
276 | 230 | ||
277 | if (selector >= tps->info[rid]->table_len) | 231 | if (selector >= dev->desc->n_voltages) |
278 | return -EINVAL; | 232 | return -EINVAL; |
279 | 233 | ||
280 | if (tps->info[rid]->table) | ||
281 | return tps->info[rid]->table[selector]; | ||
282 | |||
283 | return tps->info[rid]->vsel_to_uv(selector); | 234 | return tps->info[rid]->vsel_to_uv(selector); |
284 | } | 235 | } |
285 | 236 | ||
286 | /* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ | 237 | /* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ |
287 | static struct regulator_ops tps65217_pmic_ops = { | 238 | static struct regulator_ops tps65217_pmic_ops = { |
288 | .is_enabled = tps65217_pmic_is_enabled, | 239 | .is_enabled = regulator_is_enabled_regmap, |
289 | .enable = tps65217_pmic_enable, | 240 | .enable = tps65217_pmic_enable, |
290 | .disable = tps65217_pmic_disable, | 241 | .disable = tps65217_pmic_disable, |
291 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, | 242 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
292 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, | 243 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, |
293 | .list_voltage = tps65217_pmic_list_voltage, | 244 | .list_voltage = tps65217_pmic_list_voltage, |
294 | .map_voltage = tps65217_pmic_map_voltage, | 245 | .map_voltage = tps65217_pmic_map_voltage, |
@@ -296,22 +247,38 @@ static struct regulator_ops tps65217_pmic_ops = { | |||
296 | 247 | ||
297 | /* Operations permitted on LDO1 */ | 248 | /* Operations permitted on LDO1 */ |
298 | static struct regulator_ops tps65217_pmic_ldo1_ops = { | 249 | static struct regulator_ops tps65217_pmic_ldo1_ops = { |
299 | .is_enabled = tps65217_pmic_is_enabled, | 250 | .is_enabled = regulator_is_enabled_regmap, |
300 | .enable = tps65217_pmic_enable, | 251 | .enable = tps65217_pmic_enable, |
301 | .disable = tps65217_pmic_disable, | 252 | .disable = tps65217_pmic_disable, |
302 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, | 253 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
303 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, | 254 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, |
304 | .list_voltage = tps65217_pmic_list_voltage, | 255 | .list_voltage = regulator_list_voltage_table, |
305 | }; | 256 | }; |
306 | 257 | ||
307 | static const struct regulator_desc regulators[] = { | 258 | static const struct regulator_desc regulators[] = { |
308 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), | 259 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64, |
309 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), | 260 | TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK, |
310 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), | 261 | TPS65217_ENABLE_DC1_EN, NULL), |
311 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), | 262 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64, |
312 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), | 263 | TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK, |
313 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), | 264 | TPS65217_ENABLE_DC2_EN, NULL), |
314 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), | 265 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64, |
266 | TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK, | ||
267 | TPS65217_ENABLE_DC3_EN, NULL), | ||
268 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16, | ||
269 | TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK, | ||
270 | TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table), | ||
271 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64, | ||
272 | TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK, | ||
273 | TPS65217_ENABLE_LDO2_EN, NULL), | ||
274 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32, | ||
275 | TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, | ||
276 | TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, | ||
277 | NULL), | ||
278 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32, | ||
279 | TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, | ||
280 | TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, | ||
281 | NULL), | ||
315 | }; | 282 | }; |
316 | 283 | ||
317 | static int __devinit tps65217_regulator_probe(struct platform_device *pdev) | 284 | static int __devinit tps65217_regulator_probe(struct platform_device *pdev) |
@@ -326,6 +293,7 @@ static int __devinit tps65217_regulator_probe(struct platform_device *pdev) | |||
326 | tps->info[pdev->id] = info; | 293 | tps->info[pdev->id] = info; |
327 | 294 | ||
328 | config.dev = &pdev->dev; | 295 | config.dev = &pdev->dev; |
296 | config.of_node = pdev->dev.of_node; | ||
329 | config.init_data = pdev->dev.platform_data; | 297 | config.init_data = pdev->dev.platform_data; |
330 | config.driver_data = tps; | 298 | config.driver_data = tps; |
331 | 299 | ||
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c index 1b299aacf22f..947ece933d90 100644 --- a/drivers/regulator/tps6524x-regulator.c +++ b/drivers/regulator/tps6524x-regulator.c | |||
@@ -110,9 +110,6 @@ | |||
110 | #define N_SWITCH 2 | 110 | #define N_SWITCH 2 |
111 | #define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) | 111 | #define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) |
112 | 112 | ||
113 | #define FIXED_ILIMSEL BIT(0) | ||
114 | #define FIXED_VOLTAGE BIT(1) | ||
115 | |||
116 | #define CMD_READ(reg) ((reg) << 6) | 113 | #define CMD_READ(reg) ((reg) << 6) |
117 | #define CMD_WRITE(reg) (BIT(5) | (reg) << 6) | 114 | #define CMD_WRITE(reg) (BIT(5) | (reg) << 6) |
118 | #define STAT_CLK BIT(3) | 115 | #define STAT_CLK BIT(3) |
@@ -129,12 +126,9 @@ struct field { | |||
129 | struct supply_info { | 126 | struct supply_info { |
130 | const char *name; | 127 | const char *name; |
131 | int n_voltages; | 128 | int n_voltages; |
132 | const int *voltages; | 129 | const unsigned int *voltages; |
133 | int fixed_voltage; | ||
134 | int n_ilimsels; | 130 | int n_ilimsels; |
135 | const int *ilimsels; | 131 | const unsigned int *ilimsels; |
136 | int fixed_ilimsel; | ||
137 | int flags; | ||
138 | struct field enable, voltage, ilimsel; | 132 | struct field enable, voltage, ilimsel; |
139 | }; | 133 | }; |
140 | 134 | ||
@@ -307,7 +301,7 @@ static int write_field(struct tps6524x *hw, const struct field *field, | |||
307 | val << field->shift); | 301 | val << field->shift); |
308 | } | 302 | } |
309 | 303 | ||
310 | static const int dcdc1_voltages[] = { | 304 | static const unsigned int dcdc1_voltages[] = { |
311 | 800000, 825000, 850000, 875000, | 305 | 800000, 825000, 850000, 875000, |
312 | 900000, 925000, 950000, 975000, | 306 | 900000, 925000, 950000, 975000, |
313 | 1000000, 1025000, 1050000, 1075000, | 307 | 1000000, 1025000, 1050000, 1075000, |
@@ -318,7 +312,7 @@ static const int dcdc1_voltages[] = { | |||
318 | 1500000, 1525000, 1550000, 1575000, | 312 | 1500000, 1525000, 1550000, 1575000, |
319 | }; | 313 | }; |
320 | 314 | ||
321 | static const int dcdc2_voltages[] = { | 315 | static const unsigned int dcdc2_voltages[] = { |
322 | 1400000, 1450000, 1500000, 1550000, | 316 | 1400000, 1450000, 1500000, 1550000, |
323 | 1600000, 1650000, 1700000, 1750000, | 317 | 1600000, 1650000, 1700000, 1750000, |
324 | 1800000, 1850000, 1900000, 1950000, | 318 | 1800000, 1850000, 1900000, 1950000, |
@@ -329,7 +323,7 @@ static const int dcdc2_voltages[] = { | |||
329 | 2800000, 2850000, 2900000, 2950000, | 323 | 2800000, 2850000, 2900000, 2950000, |
330 | }; | 324 | }; |
331 | 325 | ||
332 | static const int dcdc3_voltages[] = { | 326 | static const unsigned int dcdc3_voltages[] = { |
333 | 2400000, 2450000, 2500000, 2550000, 2600000, | 327 | 2400000, 2450000, 2500000, 2550000, 2600000, |
334 | 2650000, 2700000, 2750000, 2800000, 2850000, | 328 | 2650000, 2700000, 2750000, 2800000, 2850000, |
335 | 2900000, 2950000, 3000000, 3050000, 3100000, | 329 | 2900000, 2950000, 3000000, 3050000, 3100000, |
@@ -337,38 +331,54 @@ static const int dcdc3_voltages[] = { | |||
337 | 3400000, 3450000, 3500000, 3550000, 3600000, | 331 | 3400000, 3450000, 3500000, 3550000, 3600000, |
338 | }; | 332 | }; |
339 | 333 | ||
340 | static const int ldo1_voltages[] = { | 334 | static const unsigned int ldo1_voltages[] = { |
341 | 4300000, 4350000, 4400000, 4450000, | 335 | 4300000, 4350000, 4400000, 4450000, |
342 | 4500000, 4550000, 4600000, 4650000, | 336 | 4500000, 4550000, 4600000, 4650000, |
343 | 4700000, 4750000, 4800000, 4850000, | 337 | 4700000, 4750000, 4800000, 4850000, |
344 | 4900000, 4950000, 5000000, 5050000, | 338 | 4900000, 4950000, 5000000, 5050000, |
345 | }; | 339 | }; |
346 | 340 | ||
347 | static const int ldo2_voltages[] = { | 341 | static const unsigned int ldo2_voltages[] = { |
348 | 1100000, 1150000, 1200000, 1250000, | 342 | 1100000, 1150000, 1200000, 1250000, |
349 | 1300000, 1700000, 1750000, 1800000, | 343 | 1300000, 1700000, 1750000, 1800000, |
350 | 1850000, 1900000, 3150000, 3200000, | 344 | 1850000, 1900000, 3150000, 3200000, |
351 | 3250000, 3300000, 3350000, 3400000, | 345 | 3250000, 3300000, 3350000, 3400000, |
352 | }; | 346 | }; |
353 | 347 | ||
354 | static const int ldo_ilimsel[] = { | 348 | static const unsigned int fixed_5000000_voltage[] = { |
349 | 5000000 | ||
350 | }; | ||
351 | |||
352 | static const unsigned int ldo_ilimsel[] = { | ||
355 | 400000, 1500000 | 353 | 400000, 1500000 |
356 | }; | 354 | }; |
357 | 355 | ||
358 | static const int usb_ilimsel[] = { | 356 | static const unsigned int usb_ilimsel[] = { |
359 | 200000, 400000, 800000, 1000000 | 357 | 200000, 400000, 800000, 1000000 |
360 | }; | 358 | }; |
361 | 359 | ||
360 | static const unsigned int fixed_2400000_ilimsel[] = { | ||
361 | 2400000 | ||
362 | }; | ||
363 | |||
364 | static const unsigned int fixed_1200000_ilimsel[] = { | ||
365 | 1200000 | ||
366 | }; | ||
367 | |||
368 | static const unsigned int fixed_400000_ilimsel[] = { | ||
369 | 400000 | ||
370 | }; | ||
371 | |||
362 | #define __MK_FIELD(_reg, _mask, _shift) \ | 372 | #define __MK_FIELD(_reg, _mask, _shift) \ |
363 | { .reg = (_reg), .mask = (_mask), .shift = (_shift), } | 373 | { .reg = (_reg), .mask = (_mask), .shift = (_shift), } |
364 | 374 | ||
365 | static const struct supply_info supply_info[N_REGULATORS] = { | 375 | static const struct supply_info supply_info[N_REGULATORS] = { |
366 | { | 376 | { |
367 | .name = "DCDC1", | 377 | .name = "DCDC1", |
368 | .flags = FIXED_ILIMSEL, | ||
369 | .n_voltages = ARRAY_SIZE(dcdc1_voltages), | 378 | .n_voltages = ARRAY_SIZE(dcdc1_voltages), |
370 | .voltages = dcdc1_voltages, | 379 | .voltages = dcdc1_voltages, |
371 | .fixed_ilimsel = 2400000, | 380 | .n_ilimsels = ARRAY_SIZE(fixed_2400000_ilimsel), |
381 | .ilimsels = fixed_2400000_ilimsel, | ||
372 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, | 382 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, |
373 | DCDCDCDC1_EN_SHIFT), | 383 | DCDCDCDC1_EN_SHIFT), |
374 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, | 384 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, |
@@ -376,10 +386,10 @@ static const struct supply_info supply_info[N_REGULATORS] = { | |||
376 | }, | 386 | }, |
377 | { | 387 | { |
378 | .name = "DCDC2", | 388 | .name = "DCDC2", |
379 | .flags = FIXED_ILIMSEL, | ||
380 | .n_voltages = ARRAY_SIZE(dcdc2_voltages), | 389 | .n_voltages = ARRAY_SIZE(dcdc2_voltages), |
381 | .voltages = dcdc2_voltages, | 390 | .voltages = dcdc2_voltages, |
382 | .fixed_ilimsel = 1200000, | 391 | .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel), |
392 | .ilimsels = fixed_1200000_ilimsel, | ||
383 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, | 393 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, |
384 | DCDCDCDC2_EN_SHIFT), | 394 | DCDCDCDC2_EN_SHIFT), |
385 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, | 395 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, |
@@ -387,10 +397,10 @@ static const struct supply_info supply_info[N_REGULATORS] = { | |||
387 | }, | 397 | }, |
388 | { | 398 | { |
389 | .name = "DCDC3", | 399 | .name = "DCDC3", |
390 | .flags = FIXED_ILIMSEL, | ||
391 | .n_voltages = ARRAY_SIZE(dcdc3_voltages), | 400 | .n_voltages = ARRAY_SIZE(dcdc3_voltages), |
392 | .voltages = dcdc3_voltages, | 401 | .voltages = dcdc3_voltages, |
393 | .fixed_ilimsel = 1200000, | 402 | .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel), |
403 | .ilimsels = fixed_1200000_ilimsel, | ||
394 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, | 404 | .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, |
395 | DCDCDCDC3_EN_SHIFT), | 405 | DCDCDCDC3_EN_SHIFT), |
396 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, | 406 | .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, |
@@ -424,8 +434,8 @@ static const struct supply_info supply_info[N_REGULATORS] = { | |||
424 | }, | 434 | }, |
425 | { | 435 | { |
426 | .name = "USB", | 436 | .name = "USB", |
427 | .flags = FIXED_VOLTAGE, | 437 | .n_voltages = ARRAY_SIZE(fixed_5000000_voltage), |
428 | .fixed_voltage = 5000000, | 438 | .voltages = fixed_5000000_voltage, |
429 | .n_ilimsels = ARRAY_SIZE(usb_ilimsel), | 439 | .n_ilimsels = ARRAY_SIZE(usb_ilimsel), |
430 | .ilimsels = usb_ilimsel, | 440 | .ilimsels = usb_ilimsel, |
431 | .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, | 441 | .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, |
@@ -435,29 +445,15 @@ static const struct supply_info supply_info[N_REGULATORS] = { | |||
435 | }, | 445 | }, |
436 | { | 446 | { |
437 | .name = "LCD", | 447 | .name = "LCD", |
438 | .flags = FIXED_VOLTAGE | FIXED_ILIMSEL, | 448 | .n_voltages = ARRAY_SIZE(fixed_5000000_voltage), |
439 | .fixed_voltage = 5000000, | 449 | .voltages = fixed_5000000_voltage, |
440 | .fixed_ilimsel = 400000, | 450 | .n_ilimsels = ARRAY_SIZE(fixed_400000_ilimsel), |
451 | .ilimsels = fixed_400000_ilimsel, | ||
441 | .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, | 452 | .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, |
442 | BLOCK_LCD_SHIFT), | 453 | BLOCK_LCD_SHIFT), |
443 | }, | 454 | }, |
444 | }; | 455 | }; |
445 | 456 | ||
446 | static int list_voltage(struct regulator_dev *rdev, unsigned selector) | ||
447 | { | ||
448 | const struct supply_info *info; | ||
449 | struct tps6524x *hw; | ||
450 | |||
451 | hw = rdev_get_drvdata(rdev); | ||
452 | info = &supply_info[rdev_get_id(rdev)]; | ||
453 | |||
454 | if (info->flags & FIXED_VOLTAGE) | ||
455 | return selector ? -EINVAL : info->fixed_voltage; | ||
456 | |||
457 | return ((selector < info->n_voltages) ? | ||
458 | info->voltages[selector] : -EINVAL); | ||
459 | } | ||
460 | |||
461 | static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) | 457 | static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
462 | { | 458 | { |
463 | const struct supply_info *info; | 459 | const struct supply_info *info; |
@@ -466,7 +462,7 @@ static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) | |||
466 | hw = rdev_get_drvdata(rdev); | 462 | hw = rdev_get_drvdata(rdev); |
467 | info = &supply_info[rdev_get_id(rdev)]; | 463 | info = &supply_info[rdev_get_id(rdev)]; |
468 | 464 | ||
469 | if (info->flags & FIXED_VOLTAGE) | 465 | if (rdev->desc->n_voltages == 1) |
470 | return -EINVAL; | 466 | return -EINVAL; |
471 | 467 | ||
472 | return write_field(hw, &info->voltage, selector); | 468 | return write_field(hw, &info->voltage, selector); |
@@ -481,7 +477,7 @@ static int get_voltage_sel(struct regulator_dev *rdev) | |||
481 | hw = rdev_get_drvdata(rdev); | 477 | hw = rdev_get_drvdata(rdev); |
482 | info = &supply_info[rdev_get_id(rdev)]; | 478 | info = &supply_info[rdev_get_id(rdev)]; |
483 | 479 | ||
484 | if (info->flags & FIXED_VOLTAGE) | 480 | if (rdev->desc->n_voltages == 1) |
485 | return 0; | 481 | return 0; |
486 | 482 | ||
487 | ret = read_field(hw, &info->voltage); | 483 | ret = read_field(hw, &info->voltage); |
@@ -503,7 +499,7 @@ static int set_current_limit(struct regulator_dev *rdev, int min_uA, | |||
503 | hw = rdev_get_drvdata(rdev); | 499 | hw = rdev_get_drvdata(rdev); |
504 | info = &supply_info[rdev_get_id(rdev)]; | 500 | info = &supply_info[rdev_get_id(rdev)]; |
505 | 501 | ||
506 | if (info->flags & FIXED_ILIMSEL) | 502 | if (info->n_ilimsels == 1) |
507 | return -EINVAL; | 503 | return -EINVAL; |
508 | 504 | ||
509 | for (i = 0; i < info->n_ilimsels; i++) | 505 | for (i = 0; i < info->n_ilimsels; i++) |
@@ -526,8 +522,8 @@ static int get_current_limit(struct regulator_dev *rdev) | |||
526 | hw = rdev_get_drvdata(rdev); | 522 | hw = rdev_get_drvdata(rdev); |
527 | info = &supply_info[rdev_get_id(rdev)]; | 523 | info = &supply_info[rdev_get_id(rdev)]; |
528 | 524 | ||
529 | if (info->flags & FIXED_ILIMSEL) | 525 | if (info->n_ilimsels == 1) |
530 | return info->fixed_ilimsel; | 526 | return info->ilimsels[0]; |
531 | 527 | ||
532 | ret = read_field(hw, &info->ilimsel); | 528 | ret = read_field(hw, &info->ilimsel); |
533 | if (ret < 0) | 529 | if (ret < 0) |
@@ -577,7 +573,7 @@ static struct regulator_ops regulator_ops = { | |||
577 | .disable = disable_supply, | 573 | .disable = disable_supply, |
578 | .get_voltage_sel = get_voltage_sel, | 574 | .get_voltage_sel = get_voltage_sel, |
579 | .set_voltage_sel = set_voltage_sel, | 575 | .set_voltage_sel = set_voltage_sel, |
580 | .list_voltage = list_voltage, | 576 | .list_voltage = regulator_list_voltage_table, |
581 | .set_current_limit = set_current_limit, | 577 | .set_current_limit = set_current_limit, |
582 | .get_current_limit = get_current_limit, | 578 | .get_current_limit = get_current_limit, |
583 | }; | 579 | }; |
@@ -629,13 +625,11 @@ static int __devinit pmic_probe(struct spi_device *spi) | |||
629 | hw->desc[i].name = info->name; | 625 | hw->desc[i].name = info->name; |
630 | hw->desc[i].id = i; | 626 | hw->desc[i].id = i; |
631 | hw->desc[i].n_voltages = info->n_voltages; | 627 | hw->desc[i].n_voltages = info->n_voltages; |
628 | hw->desc[i].volt_table = info->voltages; | ||
632 | hw->desc[i].ops = ®ulator_ops; | 629 | hw->desc[i].ops = ®ulator_ops; |
633 | hw->desc[i].type = REGULATOR_VOLTAGE; | 630 | hw->desc[i].type = REGULATOR_VOLTAGE; |
634 | hw->desc[i].owner = THIS_MODULE; | 631 | hw->desc[i].owner = THIS_MODULE; |
635 | 632 | ||
636 | if (info->flags & FIXED_VOLTAGE) | ||
637 | hw->desc[i].n_voltages = 1; | ||
638 | |||
639 | config.dev = dev; | 633 | config.dev = dev; |
640 | config.init_data = init_data; | 634 | config.init_data = init_data; |
641 | config.driver_data = hw; | 635 | config.driver_data = hw; |
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index c0a214575380..e6da90ab5153 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c | |||
@@ -63,8 +63,6 @@ struct tps6586x_regulator { | |||
63 | int enable_bit[2]; | 63 | int enable_bit[2]; |
64 | int enable_reg[2]; | 64 | int enable_reg[2]; |
65 | 65 | ||
66 | int *voltages; | ||
67 | |||
68 | /* for DVM regulators */ | 66 | /* for DVM regulators */ |
69 | int go_reg; | 67 | int go_reg; |
70 | int go_bit; | 68 | int go_bit; |
@@ -72,22 +70,9 @@ struct tps6586x_regulator { | |||
72 | 70 | ||
73 | static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev) | 71 | static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev) |
74 | { | 72 | { |
75 | return rdev_get_dev(rdev)->parent->parent; | 73 | return rdev_get_dev(rdev)->parent; |
76 | } | 74 | } |
77 | 75 | ||
78 | static int tps6586x_list_voltage(struct regulator_dev *rdev, unsigned selector) | ||
79 | { | ||
80 | struct tps6586x_regulator *info = rdev_get_drvdata(rdev); | ||
81 | int rid = rdev_get_id(rdev); | ||
82 | |||
83 | /* LDO0 has minimal voltage 1.2V rather than 1.25V */ | ||
84 | if ((rid == TPS6586X_ID_LDO_0) && (selector == 0)) | ||
85 | return (info->voltages[0] - 50) * 1000; | ||
86 | |||
87 | return info->voltages[selector] * 1000; | ||
88 | } | ||
89 | |||
90 | |||
91 | static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, | 76 | static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, |
92 | unsigned selector) | 77 | unsigned selector) |
93 | { | 78 | { |
@@ -168,7 +153,7 @@ static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev) | |||
168 | } | 153 | } |
169 | 154 | ||
170 | static struct regulator_ops tps6586x_regulator_ops = { | 155 | static struct regulator_ops tps6586x_regulator_ops = { |
171 | .list_voltage = tps6586x_list_voltage, | 156 | .list_voltage = regulator_list_voltage_table, |
172 | .get_voltage_sel = tps6586x_get_voltage_sel, | 157 | .get_voltage_sel = tps6586x_get_voltage_sel, |
173 | .set_voltage_sel = tps6586x_set_voltage_sel, | 158 | .set_voltage_sel = tps6586x_set_voltage_sel, |
174 | 159 | ||
@@ -177,39 +162,45 @@ static struct regulator_ops tps6586x_regulator_ops = { | |||
177 | .disable = tps6586x_regulator_disable, | 162 | .disable = tps6586x_regulator_disable, |
178 | }; | 163 | }; |
179 | 164 | ||
180 | static int tps6586x_ldo_voltages[] = { | 165 | static const unsigned int tps6586x_ldo0_voltages[] = { |
181 | 1250, 1500, 1800, 2500, 2700, 2850, 3100, 3300, | 166 | 1200000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000, |
167 | }; | ||
168 | |||
169 | static const unsigned int tps6586x_ldo4_voltages[] = { | ||
170 | 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000, | ||
171 | 1900000, 1925000, 1950000, 1975000, 2000000, 2025000, 2050000, 2075000, | ||
172 | 2100000, 2125000, 2150000, 2175000, 2200000, 2225000, 2250000, 2275000, | ||
173 | 2300000, 2325000, 2350000, 2375000, 2400000, 2425000, 2450000, 2475000, | ||
182 | }; | 174 | }; |
183 | 175 | ||
184 | static int tps6586x_ldo4_voltages[] = { | 176 | static const unsigned int tps6586x_ldo_voltages[] = { |
185 | 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875, | 177 | 1250000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000, |
186 | 1900, 1925, 1950, 1975, 2000, 2025, 2050, 2075, | ||
187 | 2100, 2125, 2150, 2175, 2200, 2225, 2250, 2275, | ||
188 | 2300, 2325, 2350, 2375, 2400, 2425, 2450, 2475, | ||
189 | }; | 178 | }; |
190 | 179 | ||
191 | static int tps6586x_sm2_voltages[] = { | 180 | static const unsigned int tps6586x_sm2_voltages[] = { |
192 | 3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350, | 181 | 3000000, 3050000, 3100000, 3150000, 3200000, 3250000, 3300000, 3350000, |
193 | 3400, 3450, 3500, 3550, 3600, 3650, 3700, 3750, | 182 | 3400000, 3450000, 3500000, 3550000, 3600000, 3650000, 3700000, 3750000, |
194 | 3800, 3850, 3900, 3950, 4000, 4050, 4100, 4150, | 183 | 3800000, 3850000, 3900000, 3950000, 4000000, 4050000, 4100000, 4150000, |
195 | 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550, | 184 | 4200000, 4250000, 4300000, 4350000, 4400000, 4450000, 4500000, 4550000, |
196 | }; | 185 | }; |
197 | 186 | ||
198 | static int tps6586x_dvm_voltages[] = { | 187 | static const unsigned int tps6586x_dvm_voltages[] = { |
199 | 725, 750, 775, 800, 825, 850, 875, 900, | 188 | 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000, |
200 | 925, 950, 975, 1000, 1025, 1050, 1075, 1100, | 189 | 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000, |
201 | 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, | 190 | 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, |
202 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 191 | 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, |
203 | }; | 192 | }; |
204 | 193 | ||
205 | #define TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ | 194 | #define TPS6586X_REGULATOR(_id, _pin_name, vdata, vreg, shift, nbits, \ |
206 | ereg0, ebit0, ereg1, ebit1) \ | 195 | ereg0, ebit0, ereg1, ebit1) \ |
207 | .desc = { \ | 196 | .desc = { \ |
197 | .supply_name = _pin_name, \ | ||
208 | .name = "REG-" #_id, \ | 198 | .name = "REG-" #_id, \ |
209 | .ops = &tps6586x_regulator_ops, \ | 199 | .ops = &tps6586x_regulator_ops, \ |
210 | .type = REGULATOR_VOLTAGE, \ | 200 | .type = REGULATOR_VOLTAGE, \ |
211 | .id = TPS6586X_ID_##_id, \ | 201 | .id = TPS6586X_ID_##_id, \ |
212 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ | 202 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ |
203 | .volt_table = tps6586x_##vdata##_voltages, \ | ||
213 | .owner = THIS_MODULE, \ | 204 | .owner = THIS_MODULE, \ |
214 | }, \ | 205 | }, \ |
215 | .volt_reg = TPS6586X_##vreg, \ | 206 | .volt_reg = TPS6586X_##vreg, \ |
@@ -218,44 +209,45 @@ static int tps6586x_dvm_voltages[] = { | |||
218 | .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ | 209 | .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \ |
219 | .enable_bit[0] = (ebit0), \ | 210 | .enable_bit[0] = (ebit0), \ |
220 | .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ | 211 | .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \ |
221 | .enable_bit[1] = (ebit1), \ | 212 | .enable_bit[1] = (ebit1), |
222 | .voltages = tps6586x_##vdata##_voltages, | ||
223 | 213 | ||
224 | #define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ | 214 | #define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ |
225 | .go_reg = TPS6586X_##goreg, \ | 215 | .go_reg = TPS6586X_##goreg, \ |
226 | .go_bit = (gobit), | 216 | .go_bit = (gobit), |
227 | 217 | ||
228 | #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ | 218 | #define TPS6586X_LDO(_id, _pname, vdata, vreg, shift, nbits, \ |
229 | ereg0, ebit0, ereg1, ebit1) \ | 219 | ereg0, ebit0, ereg1, ebit1) \ |
230 | { \ | 220 | { \ |
231 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ | 221 | TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \ |
232 | ereg0, ebit0, ereg1, ebit1) \ | 222 | ereg0, ebit0, ereg1, ebit1) \ |
233 | } | 223 | } |
234 | 224 | ||
235 | #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ | 225 | #define TPS6586X_DVM(_id, _pname, vdata, vreg, shift, nbits, \ |
236 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ | 226 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ |
237 | { \ | 227 | { \ |
238 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ | 228 | TPS6586X_REGULATOR(_id, _pname, vdata, vreg, shift, nbits, \ |
239 | ereg0, ebit0, ereg1, ebit1) \ | 229 | ereg0, ebit0, ereg1, ebit1) \ |
240 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ | 230 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ |
241 | } | 231 | } |
242 | 232 | ||
243 | static struct tps6586x_regulator tps6586x_regulator[] = { | 233 | static struct tps6586x_regulator tps6586x_regulator[] = { |
244 | TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0), | 234 | TPS6586X_LDO(LDO_0, "vinldo01", ldo0, SUPPLYV1, 5, 3, ENC, 0, END, 0), |
245 | TPS6586X_LDO(LDO_3, ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2), | 235 | TPS6586X_LDO(LDO_3, "vinldo23", ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2), |
246 | TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), | 236 | TPS6586X_LDO(LDO_5, NULL, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6), |
247 | TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), | 237 | TPS6586X_LDO(LDO_6, "vinldo678", ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4), |
248 | TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), | 238 | TPS6586X_LDO(LDO_7, "vinldo678", ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5), |
249 | TPS6586X_LDO(LDO_8, ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6), | 239 | TPS6586X_LDO(LDO_8, "vinldo678", ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6), |
250 | TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), | 240 | TPS6586X_LDO(LDO_9, "vinldo9", ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7), |
251 | TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), | 241 | TPS6586X_LDO(LDO_RTC, NULL, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7), |
252 | TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), | 242 | TPS6586X_LDO(LDO_1, "vinldo01", dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1), |
253 | TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7), | 243 | TPS6586X_LDO(SM_2, "sm2", sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7), |
254 | 244 | ||
255 | TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6), | 245 | TPS6586X_DVM(LDO_2, "vinldo23", dvm, LDO2BV1, 0, 5, ENA, 3, |
256 | TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6), | 246 | ENB, 3, VCC2, 6), |
257 | TPS6586X_DVM(SM_0, dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2), | 247 | TPS6586X_DVM(LDO_4, "vinldo4", ldo4, LDO4V1, 0, 5, ENC, 3, |
258 | TPS6586X_DVM(SM_1, dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0), | 248 | END, 3, VCC1, 6), |
249 | TPS6586X_DVM(SM_0, "sm0", dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2), | ||
250 | TPS6586X_DVM(SM_1, "sm1", dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0), | ||
259 | }; | 251 | }; |
260 | 252 | ||
261 | /* | 253 | /* |
@@ -362,7 +354,7 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) | |||
362 | if (err) | 354 | if (err) |
363 | return err; | 355 | return err; |
364 | 356 | ||
365 | config.dev = &pdev->dev; | 357 | config.dev = pdev->dev.parent; |
366 | config.of_node = pdev->dev.of_node; | 358 | config.of_node = pdev->dev.of_node; |
367 | config.init_data = pdev->dev.platform_data; | 359 | config.init_data = pdev->dev.platform_data; |
368 | config.driver_data = ri; | 360 | config.driver_data = ri; |
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 6bf864b4bdf6..793adda560c3 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c | |||
@@ -31,160 +31,147 @@ | |||
31 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ | 31 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ |
32 | TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) | 32 | TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) |
33 | 33 | ||
34 | /* supported VIO voltages in millivolts */ | 34 | /* supported VIO voltages in microvolts */ |
35 | static const u16 VIO_VSEL_table[] = { | 35 | static const unsigned int VIO_VSEL_table[] = { |
36 | 1500, 1800, 2500, 3300, | 36 | 1500000, 1800000, 2500000, 3300000, |
37 | }; | 37 | }; |
38 | 38 | ||
39 | /* VSEL tables for TPS65910 specific LDOs and dcdc's */ | 39 | /* VSEL tables for TPS65910 specific LDOs and dcdc's */ |
40 | 40 | ||
41 | /* supported VDD3 voltages in millivolts */ | 41 | /* supported VDD3 voltages in microvolts */ |
42 | static const u16 VDD3_VSEL_table[] = { | 42 | static const unsigned int VDD3_VSEL_table[] = { |
43 | 5000, | 43 | 5000000, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | /* supported VDIG1 voltages in millivolts */ | 46 | /* supported VDIG1 voltages in microvolts */ |
47 | static const u16 VDIG1_VSEL_table[] = { | 47 | static const unsigned int VDIG1_VSEL_table[] = { |
48 | 1200, 1500, 1800, 2700, | 48 | 1200000, 1500000, 1800000, 2700000, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | /* supported VDIG2 voltages in millivolts */ | 51 | /* supported VDIG2 voltages in microvolts */ |
52 | static const u16 VDIG2_VSEL_table[] = { | 52 | static const unsigned int VDIG2_VSEL_table[] = { |
53 | 1000, 1100, 1200, 1800, | 53 | 1000000, 1100000, 1200000, 1800000, |
54 | }; | 54 | }; |
55 | 55 | ||
56 | /* supported VPLL voltages in millivolts */ | 56 | /* supported VPLL voltages in microvolts */ |
57 | static const u16 VPLL_VSEL_table[] = { | 57 | static const unsigned int VPLL_VSEL_table[] = { |
58 | 1000, 1100, 1800, 2500, | 58 | 1000000, 1100000, 1800000, 2500000, |
59 | }; | 59 | }; |
60 | 60 | ||
61 | /* supported VDAC voltages in millivolts */ | 61 | /* supported VDAC voltages in microvolts */ |
62 | static const u16 VDAC_VSEL_table[] = { | 62 | static const unsigned int VDAC_VSEL_table[] = { |
63 | 1800, 2600, 2800, 2850, | 63 | 1800000, 2600000, 2800000, 2850000, |
64 | }; | 64 | }; |
65 | 65 | ||
66 | /* supported VAUX1 voltages in millivolts */ | 66 | /* supported VAUX1 voltages in microvolts */ |
67 | static const u16 VAUX1_VSEL_table[] = { | 67 | static const unsigned int VAUX1_VSEL_table[] = { |
68 | 1800, 2500, 2800, 2850, | 68 | 1800000, 2500000, 2800000, 2850000, |
69 | }; | 69 | }; |
70 | 70 | ||
71 | /* supported VAUX2 voltages in millivolts */ | 71 | /* supported VAUX2 voltages in microvolts */ |
72 | static const u16 VAUX2_VSEL_table[] = { | 72 | static const unsigned int VAUX2_VSEL_table[] = { |
73 | 1800, 2800, 2900, 3300, | 73 | 1800000, 2800000, 2900000, 3300000, |
74 | }; | 74 | }; |
75 | 75 | ||
76 | /* supported VAUX33 voltages in millivolts */ | 76 | /* supported VAUX33 voltages in microvolts */ |
77 | static const u16 VAUX33_VSEL_table[] = { | 77 | static const unsigned int VAUX33_VSEL_table[] = { |
78 | 1800, 2000, 2800, 3300, | 78 | 1800000, 2000000, 2800000, 3300000, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /* supported VMMC voltages in millivolts */ | 81 | /* supported VMMC voltages in microvolts */ |
82 | static const u16 VMMC_VSEL_table[] = { | 82 | static const unsigned int VMMC_VSEL_table[] = { |
83 | 1800, 2800, 3000, 3300, | 83 | 1800000, 2800000, 3000000, 3300000, |
84 | }; | 84 | }; |
85 | 85 | ||
86 | struct tps_info { | 86 | struct tps_info { |
87 | const char *name; | 87 | const char *name; |
88 | unsigned min_uV; | 88 | const char *vin_name; |
89 | unsigned max_uV; | ||
90 | u8 n_voltages; | 89 | u8 n_voltages; |
91 | const u16 *voltage_table; | 90 | const unsigned int *voltage_table; |
92 | int enable_time_us; | 91 | int enable_time_us; |
93 | }; | 92 | }; |
94 | 93 | ||
95 | static struct tps_info tps65910_regs[] = { | 94 | static struct tps_info tps65910_regs[] = { |
96 | { | 95 | { |
97 | .name = "vrtc", | 96 | .name = "vrtc", |
97 | .vin_name = "vcc7", | ||
98 | .enable_time_us = 2200, | 98 | .enable_time_us = 2200, |
99 | }, | 99 | }, |
100 | { | 100 | { |
101 | .name = "vio", | 101 | .name = "vio", |
102 | .min_uV = 1500000, | 102 | .vin_name = "vccio", |
103 | .max_uV = 3300000, | ||
104 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), | 103 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
105 | .voltage_table = VIO_VSEL_table, | 104 | .voltage_table = VIO_VSEL_table, |
106 | .enable_time_us = 350, | 105 | .enable_time_us = 350, |
107 | }, | 106 | }, |
108 | { | 107 | { |
109 | .name = "vdd1", | 108 | .name = "vdd1", |
110 | .min_uV = 600000, | 109 | .vin_name = "vcc1", |
111 | .max_uV = 4500000, | ||
112 | .enable_time_us = 350, | 110 | .enable_time_us = 350, |
113 | }, | 111 | }, |
114 | { | 112 | { |
115 | .name = "vdd2", | 113 | .name = "vdd2", |
116 | .min_uV = 600000, | 114 | .vin_name = "vcc2", |
117 | .max_uV = 4500000, | ||
118 | .enable_time_us = 350, | 115 | .enable_time_us = 350, |
119 | }, | 116 | }, |
120 | { | 117 | { |
121 | .name = "vdd3", | 118 | .name = "vdd3", |
122 | .min_uV = 5000000, | ||
123 | .max_uV = 5000000, | ||
124 | .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), | 119 | .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), |
125 | .voltage_table = VDD3_VSEL_table, | 120 | .voltage_table = VDD3_VSEL_table, |
126 | .enable_time_us = 200, | 121 | .enable_time_us = 200, |
127 | }, | 122 | }, |
128 | { | 123 | { |
129 | .name = "vdig1", | 124 | .name = "vdig1", |
130 | .min_uV = 1200000, | 125 | .vin_name = "vcc6", |
131 | .max_uV = 2700000, | ||
132 | .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), | 126 | .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), |
133 | .voltage_table = VDIG1_VSEL_table, | 127 | .voltage_table = VDIG1_VSEL_table, |
134 | .enable_time_us = 100, | 128 | .enable_time_us = 100, |
135 | }, | 129 | }, |
136 | { | 130 | { |
137 | .name = "vdig2", | 131 | .name = "vdig2", |
138 | .min_uV = 1000000, | 132 | .vin_name = "vcc6", |
139 | .max_uV = 1800000, | ||
140 | .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), | 133 | .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), |
141 | .voltage_table = VDIG2_VSEL_table, | 134 | .voltage_table = VDIG2_VSEL_table, |
142 | .enable_time_us = 100, | 135 | .enable_time_us = 100, |
143 | }, | 136 | }, |
144 | { | 137 | { |
145 | .name = "vpll", | 138 | .name = "vpll", |
146 | .min_uV = 1000000, | 139 | .vin_name = "vcc5", |
147 | .max_uV = 2500000, | ||
148 | .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), | 140 | .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), |
149 | .voltage_table = VPLL_VSEL_table, | 141 | .voltage_table = VPLL_VSEL_table, |
150 | .enable_time_us = 100, | 142 | .enable_time_us = 100, |
151 | }, | 143 | }, |
152 | { | 144 | { |
153 | .name = "vdac", | 145 | .name = "vdac", |
154 | .min_uV = 1800000, | 146 | .vin_name = "vcc5", |
155 | .max_uV = 2850000, | ||
156 | .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), | 147 | .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), |
157 | .voltage_table = VDAC_VSEL_table, | 148 | .voltage_table = VDAC_VSEL_table, |
158 | .enable_time_us = 100, | 149 | .enable_time_us = 100, |
159 | }, | 150 | }, |
160 | { | 151 | { |
161 | .name = "vaux1", | 152 | .name = "vaux1", |
162 | .min_uV = 1800000, | 153 | .vin_name = "vcc4", |
163 | .max_uV = 2850000, | ||
164 | .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), | 154 | .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), |
165 | .voltage_table = VAUX1_VSEL_table, | 155 | .voltage_table = VAUX1_VSEL_table, |
166 | .enable_time_us = 100, | 156 | .enable_time_us = 100, |
167 | }, | 157 | }, |
168 | { | 158 | { |
169 | .name = "vaux2", | 159 | .name = "vaux2", |
170 | .min_uV = 1800000, | 160 | .vin_name = "vcc4", |
171 | .max_uV = 3300000, | ||
172 | .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), | 161 | .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), |
173 | .voltage_table = VAUX2_VSEL_table, | 162 | .voltage_table = VAUX2_VSEL_table, |
174 | .enable_time_us = 100, | 163 | .enable_time_us = 100, |
175 | }, | 164 | }, |
176 | { | 165 | { |
177 | .name = "vaux33", | 166 | .name = "vaux33", |
178 | .min_uV = 1800000, | 167 | .vin_name = "vcc3", |
179 | .max_uV = 3300000, | ||
180 | .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), | 168 | .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), |
181 | .voltage_table = VAUX33_VSEL_table, | 169 | .voltage_table = VAUX33_VSEL_table, |
182 | .enable_time_us = 100, | 170 | .enable_time_us = 100, |
183 | }, | 171 | }, |
184 | { | 172 | { |
185 | .name = "vmmc", | 173 | .name = "vmmc", |
186 | .min_uV = 1800000, | 174 | .vin_name = "vcc3", |
187 | .max_uV = 3300000, | ||
188 | .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), | 175 | .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), |
189 | .voltage_table = VMMC_VSEL_table, | 176 | .voltage_table = VMMC_VSEL_table, |
190 | .enable_time_us = 100, | 177 | .enable_time_us = 100, |
@@ -194,91 +181,79 @@ static struct tps_info tps65910_regs[] = { | |||
194 | static struct tps_info tps65911_regs[] = { | 181 | static struct tps_info tps65911_regs[] = { |
195 | { | 182 | { |
196 | .name = "vrtc", | 183 | .name = "vrtc", |
184 | .vin_name = "vcc7", | ||
197 | .enable_time_us = 2200, | 185 | .enable_time_us = 2200, |
198 | }, | 186 | }, |
199 | { | 187 | { |
200 | .name = "vio", | 188 | .name = "vio", |
201 | .min_uV = 1500000, | 189 | .vin_name = "vccio", |
202 | .max_uV = 3300000, | ||
203 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), | 190 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
204 | .voltage_table = VIO_VSEL_table, | 191 | .voltage_table = VIO_VSEL_table, |
205 | .enable_time_us = 350, | 192 | .enable_time_us = 350, |
206 | }, | 193 | }, |
207 | { | 194 | { |
208 | .name = "vdd1", | 195 | .name = "vdd1", |
209 | .min_uV = 600000, | 196 | .vin_name = "vcc1", |
210 | .max_uV = 4500000, | 197 | .n_voltages = 0x4C, |
211 | .n_voltages = 73, | ||
212 | .enable_time_us = 350, | 198 | .enable_time_us = 350, |
213 | }, | 199 | }, |
214 | { | 200 | { |
215 | .name = "vdd2", | 201 | .name = "vdd2", |
216 | .min_uV = 600000, | 202 | .vin_name = "vcc2", |
217 | .max_uV = 4500000, | 203 | .n_voltages = 0x4C, |
218 | .n_voltages = 73, | ||
219 | .enable_time_us = 350, | 204 | .enable_time_us = 350, |
220 | }, | 205 | }, |
221 | { | 206 | { |
222 | .name = "vddctrl", | 207 | .name = "vddctrl", |
223 | .min_uV = 600000, | 208 | .n_voltages = 0x44, |
224 | .max_uV = 1400000, | ||
225 | .n_voltages = 65, | ||
226 | .enable_time_us = 900, | 209 | .enable_time_us = 900, |
227 | }, | 210 | }, |
228 | { | 211 | { |
229 | .name = "ldo1", | 212 | .name = "ldo1", |
230 | .min_uV = 1000000, | 213 | .vin_name = "vcc6", |
231 | .max_uV = 3300000, | 214 | .n_voltages = 0x33, |
232 | .n_voltages = 47, | ||
233 | .enable_time_us = 420, | 215 | .enable_time_us = 420, |
234 | }, | 216 | }, |
235 | { | 217 | { |
236 | .name = "ldo2", | 218 | .name = "ldo2", |
237 | .min_uV = 1000000, | 219 | .vin_name = "vcc6", |
238 | .max_uV = 3300000, | 220 | .n_voltages = 0x33, |
239 | .n_voltages = 47, | ||
240 | .enable_time_us = 420, | 221 | .enable_time_us = 420, |
241 | }, | 222 | }, |
242 | { | 223 | { |
243 | .name = "ldo3", | 224 | .name = "ldo3", |
244 | .min_uV = 1000000, | 225 | .vin_name = "vcc5", |
245 | .max_uV = 3300000, | 226 | .n_voltages = 0x1A, |
246 | .n_voltages = 24, | ||
247 | .enable_time_us = 230, | 227 | .enable_time_us = 230, |
248 | }, | 228 | }, |
249 | { | 229 | { |
250 | .name = "ldo4", | 230 | .name = "ldo4", |
251 | .min_uV = 1000000, | 231 | .vin_name = "vcc5", |
252 | .max_uV = 3300000, | 232 | .n_voltages = 0x33, |
253 | .n_voltages = 47, | ||
254 | .enable_time_us = 230, | 233 | .enable_time_us = 230, |
255 | }, | 234 | }, |
256 | { | 235 | { |
257 | .name = "ldo5", | 236 | .name = "ldo5", |
258 | .min_uV = 1000000, | 237 | .vin_name = "vcc4", |
259 | .max_uV = 3300000, | 238 | .n_voltages = 0x1A, |
260 | .n_voltages = 24, | ||
261 | .enable_time_us = 230, | 239 | .enable_time_us = 230, |
262 | }, | 240 | }, |
263 | { | 241 | { |
264 | .name = "ldo6", | 242 | .name = "ldo6", |
265 | .min_uV = 1000000, | 243 | .vin_name = "vcc3", |
266 | .max_uV = 3300000, | 244 | .n_voltages = 0x1A, |
267 | .n_voltages = 24, | ||
268 | .enable_time_us = 230, | 245 | .enable_time_us = 230, |
269 | }, | 246 | }, |
270 | { | 247 | { |
271 | .name = "ldo7", | 248 | .name = "ldo7", |
272 | .min_uV = 1000000, | 249 | .vin_name = "vcc3", |
273 | .max_uV = 3300000, | 250 | .n_voltages = 0x1A, |
274 | .n_voltages = 24, | ||
275 | .enable_time_us = 230, | 251 | .enable_time_us = 230, |
276 | }, | 252 | }, |
277 | { | 253 | { |
278 | .name = "ldo8", | 254 | .name = "ldo8", |
279 | .min_uV = 1000000, | 255 | .vin_name = "vcc3", |
280 | .max_uV = 3300000, | 256 | .n_voltages = 0x1A, |
281 | .n_voltages = 24, | ||
282 | .enable_time_us = 230, | 257 | .enable_time_us = 230, |
283 | }, | 258 | }, |
284 | }; | 259 | }; |
@@ -321,7 +296,6 @@ struct tps65910_reg { | |||
321 | struct tps65910 *mfd; | 296 | struct tps65910 *mfd; |
322 | struct regulator_dev **rdev; | 297 | struct regulator_dev **rdev; |
323 | struct tps_info **info; | 298 | struct tps_info **info; |
324 | struct mutex mutex; | ||
325 | int num_regulators; | 299 | int num_regulators; |
326 | int mode; | 300 | int mode; |
327 | int (*get_ctrl_reg)(int); | 301 | int (*get_ctrl_reg)(int); |
@@ -329,71 +303,6 @@ struct tps65910_reg { | |||
329 | unsigned int board_ext_control[TPS65910_NUM_REGS]; | 303 | unsigned int board_ext_control[TPS65910_NUM_REGS]; |
330 | }; | 304 | }; |
331 | 305 | ||
332 | static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg) | ||
333 | { | ||
334 | unsigned int val; | ||
335 | int err; | ||
336 | |||
337 | err = tps65910_reg_read(pmic->mfd, reg, &val); | ||
338 | if (err) | ||
339 | return err; | ||
340 | |||
341 | return val; | ||
342 | } | ||
343 | |||
344 | static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg, | ||
345 | u8 set_mask, u8 clear_mask) | ||
346 | { | ||
347 | int err, data; | ||
348 | |||
349 | mutex_lock(&pmic->mutex); | ||
350 | |||
351 | data = tps65910_read(pmic, reg); | ||
352 | if (data < 0) { | ||
353 | dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg); | ||
354 | err = data; | ||
355 | goto out; | ||
356 | } | ||
357 | |||
358 | data &= ~clear_mask; | ||
359 | data |= set_mask; | ||
360 | err = tps65910_reg_write(pmic->mfd, reg, data); | ||
361 | if (err) | ||
362 | dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg); | ||
363 | |||
364 | out: | ||
365 | mutex_unlock(&pmic->mutex); | ||
366 | return err; | ||
367 | } | ||
368 | |||
369 | static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg) | ||
370 | { | ||
371 | int data; | ||
372 | |||
373 | mutex_lock(&pmic->mutex); | ||
374 | |||
375 | data = tps65910_read(pmic, reg); | ||
376 | if (data < 0) | ||
377 | dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg); | ||
378 | |||
379 | mutex_unlock(&pmic->mutex); | ||
380 | return data; | ||
381 | } | ||
382 | |||
383 | static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val) | ||
384 | { | ||
385 | int err; | ||
386 | |||
387 | mutex_lock(&pmic->mutex); | ||
388 | |||
389 | err = tps65910_reg_write(pmic->mfd, reg, val); | ||
390 | if (err < 0) | ||
391 | dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg); | ||
392 | |||
393 | mutex_unlock(&pmic->mutex); | ||
394 | return err; | ||
395 | } | ||
396 | |||
397 | static int tps65910_get_ctrl_register(int id) | 306 | static int tps65910_get_ctrl_register(int id) |
398 | { | 307 | { |
399 | switch (id) { | 308 | switch (id) { |
@@ -462,13 +371,6 @@ static int tps65911_get_ctrl_register(int id) | |||
462 | } | 371 | } |
463 | } | 372 | } |
464 | 373 | ||
465 | static int tps65910_enable_time(struct regulator_dev *dev) | ||
466 | { | ||
467 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | ||
468 | int id = rdev_get_id(dev); | ||
469 | return pmic->info[id]->enable_time_us; | ||
470 | } | ||
471 | |||
472 | static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) | 374 | static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) |
473 | { | 375 | { |
474 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 376 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
@@ -481,8 +383,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) | |||
481 | 383 | ||
482 | switch (mode) { | 384 | switch (mode) { |
483 | case REGULATOR_MODE_NORMAL: | 385 | case REGULATOR_MODE_NORMAL: |
484 | return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT, | 386 | return tps65910_reg_update_bits(pmic->mfd, reg, |
485 | LDO_ST_MODE_BIT); | 387 | LDO_ST_MODE_BIT | LDO_ST_ON_BIT, |
388 | LDO_ST_ON_BIT); | ||
486 | case REGULATOR_MODE_IDLE: | 389 | case REGULATOR_MODE_IDLE: |
487 | value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; | 390 | value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; |
488 | return tps65910_reg_set_bits(mfd, reg, value); | 391 | return tps65910_reg_set_bits(mfd, reg, value); |
@@ -496,15 +399,15 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) | |||
496 | static unsigned int tps65910_get_mode(struct regulator_dev *dev) | 399 | static unsigned int tps65910_get_mode(struct regulator_dev *dev) |
497 | { | 400 | { |
498 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 401 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
499 | int reg, value, id = rdev_get_id(dev); | 402 | int ret, reg, value, id = rdev_get_id(dev); |
500 | 403 | ||
501 | reg = pmic->get_ctrl_reg(id); | 404 | reg = pmic->get_ctrl_reg(id); |
502 | if (reg < 0) | 405 | if (reg < 0) |
503 | return reg; | 406 | return reg; |
504 | 407 | ||
505 | value = tps65910_reg_read_locked(pmic, reg); | 408 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
506 | if (value < 0) | 409 | if (ret < 0) |
507 | return value; | 410 | return ret; |
508 | 411 | ||
509 | if (!(value & LDO_ST_ON_BIT)) | 412 | if (!(value & LDO_ST_ON_BIT)) |
510 | return REGULATOR_MODE_STANDBY; | 413 | return REGULATOR_MODE_STANDBY; |
@@ -517,33 +420,51 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev) | |||
517 | static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) | 420 | static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) |
518 | { | 421 | { |
519 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 422 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
520 | int id = rdev_get_id(dev); | 423 | int ret, id = rdev_get_id(dev); |
521 | int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; | 424 | int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; |
522 | 425 | ||
523 | switch (id) { | 426 | switch (id) { |
524 | case TPS65910_REG_VDD1: | 427 | case TPS65910_REG_VDD1: |
525 | opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP); | 428 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_OP, &opvsel); |
526 | mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1); | 429 | if (ret < 0) |
430 | return ret; | ||
431 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1, &mult); | ||
432 | if (ret < 0) | ||
433 | return ret; | ||
527 | mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; | 434 | mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; |
528 | srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR); | 435 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_SR, &srvsel); |
436 | if (ret < 0) | ||
437 | return ret; | ||
529 | sr = opvsel & VDD1_OP_CMD_MASK; | 438 | sr = opvsel & VDD1_OP_CMD_MASK; |
530 | opvsel &= VDD1_OP_SEL_MASK; | 439 | opvsel &= VDD1_OP_SEL_MASK; |
531 | srvsel &= VDD1_SR_SEL_MASK; | 440 | srvsel &= VDD1_SR_SEL_MASK; |
532 | vselmax = 75; | 441 | vselmax = 75; |
533 | break; | 442 | break; |
534 | case TPS65910_REG_VDD2: | 443 | case TPS65910_REG_VDD2: |
535 | opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP); | 444 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_OP, &opvsel); |
536 | mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2); | 445 | if (ret < 0) |
446 | return ret; | ||
447 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2, &mult); | ||
448 | if (ret < 0) | ||
449 | return ret; | ||
537 | mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; | 450 | mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; |
538 | srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR); | 451 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_SR, &srvsel); |
452 | if (ret < 0) | ||
453 | return ret; | ||
539 | sr = opvsel & VDD2_OP_CMD_MASK; | 454 | sr = opvsel & VDD2_OP_CMD_MASK; |
540 | opvsel &= VDD2_OP_SEL_MASK; | 455 | opvsel &= VDD2_OP_SEL_MASK; |
541 | srvsel &= VDD2_SR_SEL_MASK; | 456 | srvsel &= VDD2_SR_SEL_MASK; |
542 | vselmax = 75; | 457 | vselmax = 75; |
543 | break; | 458 | break; |
544 | case TPS65911_REG_VDDCTRL: | 459 | case TPS65911_REG_VDDCTRL: |
545 | opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP); | 460 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_OP, |
546 | srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR); | 461 | &opvsel); |
462 | if (ret < 0) | ||
463 | return ret; | ||
464 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_SR, | ||
465 | &srvsel); | ||
466 | if (ret < 0) | ||
467 | return ret; | ||
547 | sr = opvsel & VDDCTRL_OP_CMD_MASK; | 468 | sr = opvsel & VDDCTRL_OP_CMD_MASK; |
548 | opvsel &= VDDCTRL_OP_SEL_MASK; | 469 | opvsel &= VDDCTRL_OP_SEL_MASK; |
549 | srvsel &= VDDCTRL_SR_SEL_MASK; | 470 | srvsel &= VDDCTRL_SR_SEL_MASK; |
@@ -577,15 +498,15 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) | |||
577 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) | 498 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) |
578 | { | 499 | { |
579 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 500 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
580 | int reg, value, id = rdev_get_id(dev); | 501 | int ret, reg, value, id = rdev_get_id(dev); |
581 | 502 | ||
582 | reg = pmic->get_ctrl_reg(id); | 503 | reg = pmic->get_ctrl_reg(id); |
583 | if (reg < 0) | 504 | if (reg < 0) |
584 | return reg; | 505 | return reg; |
585 | 506 | ||
586 | value = tps65910_reg_read_locked(pmic, reg); | 507 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
587 | if (value < 0) | 508 | if (ret < 0) |
588 | return value; | 509 | return ret; |
589 | 510 | ||
590 | switch (id) { | 511 | switch (id) { |
591 | case TPS65910_REG_VIO: | 512 | case TPS65910_REG_VIO: |
@@ -609,18 +530,20 @@ static int tps65910_get_voltage_sel(struct regulator_dev *dev) | |||
609 | 530 | ||
610 | static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) | 531 | static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) |
611 | { | 532 | { |
612 | return 5 * 1000 * 1000; | 533 | return dev->desc->volt_table[0]; |
613 | } | 534 | } |
614 | 535 | ||
615 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) | 536 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) |
616 | { | 537 | { |
617 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 538 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
618 | int id = rdev_get_id(dev); | 539 | int ret, id = rdev_get_id(dev); |
619 | u8 value, reg; | 540 | unsigned int value, reg; |
620 | 541 | ||
621 | reg = pmic->get_ctrl_reg(id); | 542 | reg = pmic->get_ctrl_reg(id); |
622 | 543 | ||
623 | value = tps65910_reg_read_locked(pmic, reg); | 544 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
545 | if (ret < 0) | ||
546 | return ret; | ||
624 | 547 | ||
625 | switch (id) { | 548 | switch (id) { |
626 | case TPS65911_REG_LDO1: | 549 | case TPS65911_REG_LDO1: |
@@ -662,10 +585,10 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, | |||
662 | dcdc_mult--; | 585 | dcdc_mult--; |
663 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; | 586 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
664 | 587 | ||
665 | tps65910_modify_bits(pmic, TPS65910_VDD1, | 588 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD1, |
666 | (dcdc_mult << VDD1_VGAIN_SEL_SHIFT), | 589 | VDD1_VGAIN_SEL_MASK, |
667 | VDD1_VGAIN_SEL_MASK); | 590 | dcdc_mult << VDD1_VGAIN_SEL_SHIFT); |
668 | tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel); | 591 | tps65910_reg_write(pmic->mfd, TPS65910_VDD1_OP, vsel); |
669 | break; | 592 | break; |
670 | case TPS65910_REG_VDD2: | 593 | case TPS65910_REG_VDD2: |
671 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; | 594 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; |
@@ -673,14 +596,14 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, | |||
673 | dcdc_mult--; | 596 | dcdc_mult--; |
674 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; | 597 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
675 | 598 | ||
676 | tps65910_modify_bits(pmic, TPS65910_VDD2, | 599 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD2, |
677 | (dcdc_mult << VDD2_VGAIN_SEL_SHIFT), | 600 | VDD1_VGAIN_SEL_MASK, |
678 | VDD1_VGAIN_SEL_MASK); | 601 | dcdc_mult << VDD2_VGAIN_SEL_SHIFT); |
679 | tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel); | 602 | tps65910_reg_write(pmic->mfd, TPS65910_VDD2_OP, vsel); |
680 | break; | 603 | break; |
681 | case TPS65911_REG_VDDCTRL: | 604 | case TPS65911_REG_VDDCTRL: |
682 | vsel = selector + 3; | 605 | vsel = selector + 3; |
683 | tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel); | 606 | tps65910_reg_write(pmic->mfd, TPS65911_VDDCTRL_OP, vsel); |
684 | } | 607 | } |
685 | 608 | ||
686 | return 0; | 609 | return 0; |
@@ -706,8 +629,8 @@ static int tps65910_set_voltage_sel(struct regulator_dev *dev, | |||
706 | case TPS65910_REG_VAUX2: | 629 | case TPS65910_REG_VAUX2: |
707 | case TPS65910_REG_VAUX33: | 630 | case TPS65910_REG_VAUX33: |
708 | case TPS65910_REG_VMMC: | 631 | case TPS65910_REG_VMMC: |
709 | return tps65910_modify_bits(pmic, reg, | 632 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
710 | (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); | 633 | selector << LDO_SEL_SHIFT); |
711 | } | 634 | } |
712 | 635 | ||
713 | return -EINVAL; | 636 | return -EINVAL; |
@@ -727,18 +650,18 @@ static int tps65911_set_voltage_sel(struct regulator_dev *dev, | |||
727 | case TPS65911_REG_LDO1: | 650 | case TPS65911_REG_LDO1: |
728 | case TPS65911_REG_LDO2: | 651 | case TPS65911_REG_LDO2: |
729 | case TPS65911_REG_LDO4: | 652 | case TPS65911_REG_LDO4: |
730 | return tps65910_modify_bits(pmic, reg, | 653 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO1_SEL_MASK, |
731 | (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK); | 654 | selector << LDO_SEL_SHIFT); |
732 | case TPS65911_REG_LDO3: | 655 | case TPS65911_REG_LDO3: |
733 | case TPS65911_REG_LDO5: | 656 | case TPS65911_REG_LDO5: |
734 | case TPS65911_REG_LDO6: | 657 | case TPS65911_REG_LDO6: |
735 | case TPS65911_REG_LDO7: | 658 | case TPS65911_REG_LDO7: |
736 | case TPS65911_REG_LDO8: | 659 | case TPS65911_REG_LDO8: |
737 | return tps65910_modify_bits(pmic, reg, | 660 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO3_SEL_MASK, |
738 | (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK); | 661 | selector << LDO_SEL_SHIFT); |
739 | case TPS65910_REG_VIO: | 662 | case TPS65910_REG_VIO: |
740 | return tps65910_modify_bits(pmic, reg, | 663 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
741 | (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); | 664 | selector << LDO_SEL_SHIFT); |
742 | } | 665 | } |
743 | 666 | ||
744 | return -EINVAL; | 667 | return -EINVAL; |
@@ -768,23 +691,6 @@ static int tps65910_list_voltage_dcdc(struct regulator_dev *dev, | |||
768 | return volt * 100 * mult; | 691 | return volt * 100 * mult; |
769 | } | 692 | } |
770 | 693 | ||
771 | static int tps65910_list_voltage(struct regulator_dev *dev, | ||
772 | unsigned selector) | ||
773 | { | ||
774 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | ||
775 | int id = rdev_get_id(dev), voltage; | ||
776 | |||
777 | if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC) | ||
778 | return -EINVAL; | ||
779 | |||
780 | if (selector >= pmic->info[id]->n_voltages) | ||
781 | return -EINVAL; | ||
782 | else | ||
783 | voltage = pmic->info[id]->voltage_table[selector] * 1000; | ||
784 | |||
785 | return voltage; | ||
786 | } | ||
787 | |||
788 | static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) | 694 | static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) |
789 | { | 695 | { |
790 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 696 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
@@ -816,7 +722,7 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) | |||
816 | step_mv = 100; | 722 | step_mv = 100; |
817 | break; | 723 | break; |
818 | case TPS65910_REG_VIO: | 724 | case TPS65910_REG_VIO: |
819 | return pmic->info[id]->voltage_table[selector] * 1000; | 725 | return pmic->info[id]->voltage_table[selector]; |
820 | default: | 726 | default: |
821 | return -EINVAL; | 727 | return -EINVAL; |
822 | } | 728 | } |
@@ -824,42 +730,16 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) | |||
824 | return (LDO_MIN_VOLT + selector * step_mv) * 1000; | 730 | return (LDO_MIN_VOLT + selector * step_mv) * 1000; |
825 | } | 731 | } |
826 | 732 | ||
827 | static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev, | ||
828 | unsigned int old_selector, unsigned int new_selector) | ||
829 | { | ||
830 | int id = rdev_get_id(dev); | ||
831 | int old_volt, new_volt; | ||
832 | |||
833 | old_volt = tps65910_list_voltage_dcdc(dev, old_selector); | ||
834 | if (old_volt < 0) | ||
835 | return old_volt; | ||
836 | |||
837 | new_volt = tps65910_list_voltage_dcdc(dev, new_selector); | ||
838 | if (new_volt < 0) | ||
839 | return new_volt; | ||
840 | |||
841 | /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */ | ||
842 | switch (id) { | ||
843 | case TPS65910_REG_VDD1: | ||
844 | case TPS65910_REG_VDD2: | ||
845 | return DIV_ROUND_UP(abs(old_volt - new_volt), 12500); | ||
846 | case TPS65911_REG_VDDCTRL: | ||
847 | return DIV_ROUND_UP(abs(old_volt - new_volt), 5000); | ||
848 | } | ||
849 | return -EINVAL; | ||
850 | } | ||
851 | |||
852 | /* Regulator ops (except VRTC) */ | 733 | /* Regulator ops (except VRTC) */ |
853 | static struct regulator_ops tps65910_ops_dcdc = { | 734 | static struct regulator_ops tps65910_ops_dcdc = { |
854 | .is_enabled = regulator_is_enabled_regmap, | 735 | .is_enabled = regulator_is_enabled_regmap, |
855 | .enable = regulator_enable_regmap, | 736 | .enable = regulator_enable_regmap, |
856 | .disable = regulator_disable_regmap, | 737 | .disable = regulator_disable_regmap, |
857 | .enable_time = tps65910_enable_time, | ||
858 | .set_mode = tps65910_set_mode, | 738 | .set_mode = tps65910_set_mode, |
859 | .get_mode = tps65910_get_mode, | 739 | .get_mode = tps65910_get_mode, |
860 | .get_voltage_sel = tps65910_get_voltage_dcdc_sel, | 740 | .get_voltage_sel = tps65910_get_voltage_dcdc_sel, |
861 | .set_voltage_sel = tps65910_set_voltage_dcdc_sel, | 741 | .set_voltage_sel = tps65910_set_voltage_dcdc_sel, |
862 | .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel, | 742 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
863 | .list_voltage = tps65910_list_voltage_dcdc, | 743 | .list_voltage = tps65910_list_voltage_dcdc, |
864 | }; | 744 | }; |
865 | 745 | ||
@@ -867,30 +747,27 @@ static struct regulator_ops tps65910_ops_vdd3 = { | |||
867 | .is_enabled = regulator_is_enabled_regmap, | 747 | .is_enabled = regulator_is_enabled_regmap, |
868 | .enable = regulator_enable_regmap, | 748 | .enable = regulator_enable_regmap, |
869 | .disable = regulator_disable_regmap, | 749 | .disable = regulator_disable_regmap, |
870 | .enable_time = tps65910_enable_time, | ||
871 | .set_mode = tps65910_set_mode, | 750 | .set_mode = tps65910_set_mode, |
872 | .get_mode = tps65910_get_mode, | 751 | .get_mode = tps65910_get_mode, |
873 | .get_voltage = tps65910_get_voltage_vdd3, | 752 | .get_voltage = tps65910_get_voltage_vdd3, |
874 | .list_voltage = tps65910_list_voltage, | 753 | .list_voltage = regulator_list_voltage_table, |
875 | }; | 754 | }; |
876 | 755 | ||
877 | static struct regulator_ops tps65910_ops = { | 756 | static struct regulator_ops tps65910_ops = { |
878 | .is_enabled = regulator_is_enabled_regmap, | 757 | .is_enabled = regulator_is_enabled_regmap, |
879 | .enable = regulator_enable_regmap, | 758 | .enable = regulator_enable_regmap, |
880 | .disable = regulator_disable_regmap, | 759 | .disable = regulator_disable_regmap, |
881 | .enable_time = tps65910_enable_time, | ||
882 | .set_mode = tps65910_set_mode, | 760 | .set_mode = tps65910_set_mode, |
883 | .get_mode = tps65910_get_mode, | 761 | .get_mode = tps65910_get_mode, |
884 | .get_voltage_sel = tps65910_get_voltage_sel, | 762 | .get_voltage_sel = tps65910_get_voltage_sel, |
885 | .set_voltage_sel = tps65910_set_voltage_sel, | 763 | .set_voltage_sel = tps65910_set_voltage_sel, |
886 | .list_voltage = tps65910_list_voltage, | 764 | .list_voltage = regulator_list_voltage_table, |
887 | }; | 765 | }; |
888 | 766 | ||
889 | static struct regulator_ops tps65911_ops = { | 767 | static struct regulator_ops tps65911_ops = { |
890 | .is_enabled = regulator_is_enabled_regmap, | 768 | .is_enabled = regulator_is_enabled_regmap, |
891 | .enable = regulator_enable_regmap, | 769 | .enable = regulator_enable_regmap, |
892 | .disable = regulator_disable_regmap, | 770 | .disable = regulator_disable_regmap, |
893 | .enable_time = tps65910_enable_time, | ||
894 | .set_mode = tps65910_set_mode, | 771 | .set_mode = tps65910_set_mode, |
895 | .get_mode = tps65910_get_mode, | 772 | .get_mode = tps65910_get_mode, |
896 | .get_voltage_sel = tps65911_get_voltage_sel, | 773 | .get_voltage_sel = tps65911_get_voltage_sel, |
@@ -996,19 +873,27 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, | |||
996 | (tps65910_chip_id(mfd) == TPS65911))) { | 873 | (tps65910_chip_id(mfd) == TPS65911))) { |
997 | int op_reg_add = pmic->get_ctrl_reg(id) + 1; | 874 | int op_reg_add = pmic->get_ctrl_reg(id) + 1; |
998 | int sr_reg_add = pmic->get_ctrl_reg(id) + 2; | 875 | int sr_reg_add = pmic->get_ctrl_reg(id) + 2; |
999 | int opvsel = tps65910_reg_read_locked(pmic, op_reg_add); | 876 | int opvsel, srvsel; |
1000 | int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add); | 877 | |
878 | ret = tps65910_reg_read(pmic->mfd, op_reg_add, &opvsel); | ||
879 | if (ret < 0) | ||
880 | return ret; | ||
881 | ret = tps65910_reg_read(pmic->mfd, sr_reg_add, &srvsel); | ||
882 | if (ret < 0) | ||
883 | return ret; | ||
884 | |||
1001 | if (opvsel & VDD1_OP_CMD_MASK) { | 885 | if (opvsel & VDD1_OP_CMD_MASK) { |
1002 | u8 reg_val = srvsel & VDD1_OP_SEL_MASK; | 886 | u8 reg_val = srvsel & VDD1_OP_SEL_MASK; |
1003 | ret = tps65910_reg_write_locked(pmic, op_reg_add, | 887 | |
1004 | reg_val); | 888 | ret = tps65910_reg_write(pmic->mfd, op_reg_add, |
889 | reg_val); | ||
1005 | if (ret < 0) { | 890 | if (ret < 0) { |
1006 | dev_err(mfd->dev, | 891 | dev_err(mfd->dev, |
1007 | "Error in configuring op register\n"); | 892 | "Error in configuring op register\n"); |
1008 | return ret; | 893 | return ret; |
1009 | } | 894 | } |
1010 | } | 895 | } |
1011 | ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0); | 896 | ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0); |
1012 | if (ret < 0) { | 897 | if (ret < 0) { |
1013 | dev_err(mfd->dev, "Error in settting sr register\n"); | 898 | dev_err(mfd->dev, "Error in settting sr register\n"); |
1014 | return ret; | 899 | return ret; |
@@ -1126,6 +1011,7 @@ static struct tps65910_board *tps65910_parse_dt_reg_data( | |||
1126 | "ti,regulator-ext-sleep-control", &prop); | 1011 | "ti,regulator-ext-sleep-control", &prop); |
1127 | if (!ret) | 1012 | if (!ret) |
1128 | pmic_plat_data->regulator_ext_sleep_control[idx] = prop; | 1013 | pmic_plat_data->regulator_ext_sleep_control[idx] = prop; |
1014 | |||
1129 | } | 1015 | } |
1130 | 1016 | ||
1131 | return pmic_plat_data; | 1017 | return pmic_plat_data; |
@@ -1136,7 +1022,7 @@ static inline struct tps65910_board *tps65910_parse_dt_reg_data( | |||
1136 | struct of_regulator_match **tps65910_reg_matches) | 1022 | struct of_regulator_match **tps65910_reg_matches) |
1137 | { | 1023 | { |
1138 | *tps65910_reg_matches = NULL; | 1024 | *tps65910_reg_matches = NULL; |
1139 | return 0; | 1025 | return NULL; |
1140 | } | 1026 | } |
1141 | #endif | 1027 | #endif |
1142 | 1028 | ||
@@ -1168,7 +1054,6 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1168 | return -ENOMEM; | 1054 | return -ENOMEM; |
1169 | } | 1055 | } |
1170 | 1056 | ||
1171 | mutex_init(&pmic->mutex); | ||
1172 | pmic->mfd = tps65910; | 1057 | pmic->mfd = tps65910; |
1173 | platform_set_drvdata(pdev, pmic); | 1058 | platform_set_drvdata(pdev, pmic); |
1174 | 1059 | ||
@@ -1229,23 +1114,31 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1229 | pmic->info[i] = info; | 1114 | pmic->info[i] = info; |
1230 | 1115 | ||
1231 | pmic->desc[i].name = info->name; | 1116 | pmic->desc[i].name = info->name; |
1117 | pmic->desc[i].supply_name = info->vin_name; | ||
1232 | pmic->desc[i].id = i; | 1118 | pmic->desc[i].id = i; |
1233 | pmic->desc[i].n_voltages = info->n_voltages; | 1119 | pmic->desc[i].n_voltages = info->n_voltages; |
1120 | pmic->desc[i].enable_time = info->enable_time_us; | ||
1234 | 1121 | ||
1235 | if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { | 1122 | if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { |
1236 | pmic->desc[i].ops = &tps65910_ops_dcdc; | 1123 | pmic->desc[i].ops = &tps65910_ops_dcdc; |
1237 | pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE * | 1124 | pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE * |
1238 | VDD1_2_NUM_VOLT_COARSE; | 1125 | VDD1_2_NUM_VOLT_COARSE; |
1126 | pmic->desc[i].ramp_delay = 12500; | ||
1239 | } else if (i == TPS65910_REG_VDD3) { | 1127 | } else if (i == TPS65910_REG_VDD3) { |
1240 | if (tps65910_chip_id(tps65910) == TPS65910) | 1128 | if (tps65910_chip_id(tps65910) == TPS65910) { |
1241 | pmic->desc[i].ops = &tps65910_ops_vdd3; | 1129 | pmic->desc[i].ops = &tps65910_ops_vdd3; |
1242 | else | 1130 | pmic->desc[i].volt_table = info->voltage_table; |
1131 | } else { | ||
1243 | pmic->desc[i].ops = &tps65910_ops_dcdc; | 1132 | pmic->desc[i].ops = &tps65910_ops_dcdc; |
1133 | pmic->desc[i].ramp_delay = 5000; | ||
1134 | } | ||
1244 | } else { | 1135 | } else { |
1245 | if (tps65910_chip_id(tps65910) == TPS65910) | 1136 | if (tps65910_chip_id(tps65910) == TPS65910) { |
1246 | pmic->desc[i].ops = &tps65910_ops; | 1137 | pmic->desc[i].ops = &tps65910_ops; |
1247 | else | 1138 | pmic->desc[i].volt_table = info->voltage_table; |
1139 | } else { | ||
1248 | pmic->desc[i].ops = &tps65911_ops; | 1140 | pmic->desc[i].ops = &tps65911_ops; |
1141 | } | ||
1249 | } | 1142 | } |
1250 | 1143 | ||
1251 | err = tps65910_set_ext_sleep_config(pmic, i, | 1144 | err = tps65910_set_ext_sleep_config(pmic, i, |
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index c7390711d954..242fe90dc565 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c | |||
@@ -43,9 +43,6 @@ struct twlreg_info { | |||
43 | u8 table_len; | 43 | u8 table_len; |
44 | const u16 *table; | 44 | const u16 *table; |
45 | 45 | ||
46 | /* regulator specific turn-on delay */ | ||
47 | u16 delay; | ||
48 | |||
49 | /* State REMAP default configuration */ | 46 | /* State REMAP default configuration */ |
50 | u8 remap; | 47 | u8 remap; |
51 | 48 | ||
@@ -223,20 +220,6 @@ static int twl6030reg_enable(struct regulator_dev *rdev) | |||
223 | return ret; | 220 | return ret; |
224 | } | 221 | } |
225 | 222 | ||
226 | static int twl4030reg_enable_time(struct regulator_dev *rdev) | ||
227 | { | ||
228 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
229 | |||
230 | return info->delay; | ||
231 | } | ||
232 | |||
233 | static int twl6030reg_enable_time(struct regulator_dev *rdev) | ||
234 | { | ||
235 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
236 | |||
237 | return info->delay; | ||
238 | } | ||
239 | |||
240 | static int twl4030reg_disable(struct regulator_dev *rdev) | 223 | static int twl4030reg_disable(struct regulator_dev *rdev) |
241 | { | 224 | { |
242 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 225 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
@@ -508,7 +491,6 @@ static struct regulator_ops twl4030ldo_ops = { | |||
508 | .enable = twl4030reg_enable, | 491 | .enable = twl4030reg_enable, |
509 | .disable = twl4030reg_disable, | 492 | .disable = twl4030reg_disable, |
510 | .is_enabled = twl4030reg_is_enabled, | 493 | .is_enabled = twl4030reg_is_enabled, |
511 | .enable_time = twl4030reg_enable_time, | ||
512 | 494 | ||
513 | .set_mode = twl4030reg_set_mode, | 495 | .set_mode = twl4030reg_set_mode, |
514 | 496 | ||
@@ -577,59 +559,53 @@ static struct regulator_ops twl6030coresmps_ops = { | |||
577 | .get_voltage = twl6030coresmps_get_voltage, | 559 | .get_voltage = twl6030coresmps_get_voltage, |
578 | }; | 560 | }; |
579 | 561 | ||
580 | static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) | 562 | static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) |
581 | { | 563 | { |
582 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 564 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
583 | 565 | ||
584 | return ((info->min_mV + (index * 100)) * 1000); | 566 | switch (sel) { |
567 | case 0: | ||
568 | return 0; | ||
569 | case 1 ... 24: | ||
570 | /* Linear mapping from 00000001 to 00011000: | ||
571 | * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) | ||
572 | */ | ||
573 | return (info->min_mV + 100 * (sel - 1)) * 1000; | ||
574 | case 25 ... 30: | ||
575 | return -EINVAL; | ||
576 | case 31: | ||
577 | return 2750000; | ||
578 | default: | ||
579 | return -EINVAL; | ||
580 | } | ||
585 | } | 581 | } |
586 | 582 | ||
587 | static int | 583 | static int |
588 | twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | 584 | twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
589 | unsigned *selector) | ||
590 | { | 585 | { |
591 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 586 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
592 | int vsel; | ||
593 | |||
594 | if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV)) | ||
595 | return -EDOM; | ||
596 | |||
597 | /* | ||
598 | * Use the below formula to calculate vsel | ||
599 | * mV = 1000mv + 100mv * (vsel - 1) | ||
600 | */ | ||
601 | vsel = (min_uV/1000 - 1000)/100 + 1; | ||
602 | *selector = vsel; | ||
603 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel); | ||
604 | 587 | ||
588 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, | ||
589 | selector); | ||
605 | } | 590 | } |
606 | 591 | ||
607 | static int twl6030ldo_get_voltage(struct regulator_dev *rdev) | 592 | static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) |
608 | { | 593 | { |
609 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 594 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
610 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, | 595 | int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); |
611 | VREG_VOLTAGE); | ||
612 | |||
613 | if (vsel < 0) | ||
614 | return vsel; | ||
615 | 596 | ||
616 | /* | 597 | return vsel; |
617 | * Use the below formula to calculate vsel | ||
618 | * mV = 1000mv + 100mv * (vsel - 1) | ||
619 | */ | ||
620 | return (1000 + (100 * (vsel - 1))) * 1000; | ||
621 | } | 598 | } |
622 | 599 | ||
623 | static struct regulator_ops twl6030ldo_ops = { | 600 | static struct regulator_ops twl6030ldo_ops = { |
624 | .list_voltage = twl6030ldo_list_voltage, | 601 | .list_voltage = twl6030ldo_list_voltage, |
625 | 602 | ||
626 | .set_voltage = twl6030ldo_set_voltage, | 603 | .set_voltage_sel = twl6030ldo_set_voltage_sel, |
627 | .get_voltage = twl6030ldo_get_voltage, | 604 | .get_voltage_sel = twl6030ldo_get_voltage_sel, |
628 | 605 | ||
629 | .enable = twl6030reg_enable, | 606 | .enable = twl6030reg_enable, |
630 | .disable = twl6030reg_disable, | 607 | .disable = twl6030reg_disable, |
631 | .is_enabled = twl6030reg_is_enabled, | 608 | .is_enabled = twl6030reg_is_enabled, |
632 | .enable_time = twl6030reg_enable_time, | ||
633 | 609 | ||
634 | .set_mode = twl6030reg_set_mode, | 610 | .set_mode = twl6030reg_set_mode, |
635 | 611 | ||
@@ -663,7 +639,6 @@ static struct regulator_ops twl4030fixed_ops = { | |||
663 | .enable = twl4030reg_enable, | 639 | .enable = twl4030reg_enable, |
664 | .disable = twl4030reg_disable, | 640 | .disable = twl4030reg_disable, |
665 | .is_enabled = twl4030reg_is_enabled, | 641 | .is_enabled = twl4030reg_is_enabled, |
666 | .enable_time = twl4030reg_enable_time, | ||
667 | 642 | ||
668 | .set_mode = twl4030reg_set_mode, | 643 | .set_mode = twl4030reg_set_mode, |
669 | 644 | ||
@@ -678,7 +653,6 @@ static struct regulator_ops twl6030fixed_ops = { | |||
678 | .enable = twl6030reg_enable, | 653 | .enable = twl6030reg_enable, |
679 | .disable = twl6030reg_disable, | 654 | .disable = twl6030reg_disable, |
680 | .is_enabled = twl6030reg_is_enabled, | 655 | .is_enabled = twl6030reg_is_enabled, |
681 | .enable_time = twl6030reg_enable_time, | ||
682 | 656 | ||
683 | .set_mode = twl6030reg_set_mode, | 657 | .set_mode = twl6030reg_set_mode, |
684 | 658 | ||
@@ -689,7 +663,6 @@ static struct regulator_ops twl6030_fixed_resource = { | |||
689 | .enable = twl6030reg_enable, | 663 | .enable = twl6030reg_enable, |
690 | .disable = twl6030reg_disable, | 664 | .disable = twl6030reg_disable, |
691 | .is_enabled = twl6030reg_is_enabled, | 665 | .is_enabled = twl6030reg_is_enabled, |
692 | .enable_time = twl6030reg_enable_time, | ||
693 | .get_status = twl6030reg_get_status, | 666 | .get_status = twl6030reg_get_status, |
694 | }; | 667 | }; |
695 | 668 | ||
@@ -886,7 +859,6 @@ static struct regulator_ops twlsmps_ops = { | |||
886 | .enable = twl6030reg_enable, | 859 | .enable = twl6030reg_enable, |
887 | .disable = twl6030reg_disable, | 860 | .disable = twl6030reg_disable, |
888 | .is_enabled = twl6030reg_is_enabled, | 861 | .is_enabled = twl6030reg_is_enabled, |
889 | .enable_time = twl6030reg_enable_time, | ||
890 | 862 | ||
891 | .set_mode = twl6030reg_set_mode, | 863 | .set_mode = twl6030reg_set_mode, |
892 | 864 | ||
@@ -909,7 +881,6 @@ static struct twlreg_info TWL4030_INFO_##label = { \ | |||
909 | .id = num, \ | 881 | .id = num, \ |
910 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ | 882 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ |
911 | .table = label##_VSEL_table, \ | 883 | .table = label##_VSEL_table, \ |
912 | .delay = turnon_delay, \ | ||
913 | .remap = remap_conf, \ | 884 | .remap = remap_conf, \ |
914 | .desc = { \ | 885 | .desc = { \ |
915 | .name = #label, \ | 886 | .name = #label, \ |
@@ -918,6 +889,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \ | |||
918 | .ops = &twl4030ldo_ops, \ | 889 | .ops = &twl4030ldo_ops, \ |
919 | .type = REGULATOR_VOLTAGE, \ | 890 | .type = REGULATOR_VOLTAGE, \ |
920 | .owner = THIS_MODULE, \ | 891 | .owner = THIS_MODULE, \ |
892 | .enable_time = turnon_delay, \ | ||
921 | }, \ | 893 | }, \ |
922 | } | 894 | } |
923 | 895 | ||
@@ -925,7 +897,6 @@ static struct twlreg_info TWL4030_INFO_##label = { \ | |||
925 | static struct twlreg_info TWL4030_INFO_##label = { \ | 897 | static struct twlreg_info TWL4030_INFO_##label = { \ |
926 | .base = offset, \ | 898 | .base = offset, \ |
927 | .id = num, \ | 899 | .id = num, \ |
928 | .delay = turnon_delay, \ | ||
929 | .remap = remap_conf, \ | 900 | .remap = remap_conf, \ |
930 | .desc = { \ | 901 | .desc = { \ |
931 | .name = #label, \ | 902 | .name = #label, \ |
@@ -933,6 +904,7 @@ static struct twlreg_info TWL4030_INFO_##label = { \ | |||
933 | .ops = &twl4030smps_ops, \ | 904 | .ops = &twl4030smps_ops, \ |
934 | .type = REGULATOR_VOLTAGE, \ | 905 | .type = REGULATOR_VOLTAGE, \ |
935 | .owner = THIS_MODULE, \ | 906 | .owner = THIS_MODULE, \ |
907 | .enable_time = turnon_delay, \ | ||
936 | }, \ | 908 | }, \ |
937 | } | 909 | } |
938 | 910 | ||
@@ -955,7 +927,7 @@ static struct twlreg_info TWL6030_INFO_##label = { \ | |||
955 | .desc = { \ | 927 | .desc = { \ |
956 | .name = #label, \ | 928 | .name = #label, \ |
957 | .id = TWL6030_REG_##label, \ | 929 | .id = TWL6030_REG_##label, \ |
958 | .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \ | 930 | .n_voltages = 32, \ |
959 | .ops = &twl6030ldo_ops, \ | 931 | .ops = &twl6030ldo_ops, \ |
960 | .type = REGULATOR_VOLTAGE, \ | 932 | .type = REGULATOR_VOLTAGE, \ |
961 | .owner = THIS_MODULE, \ | 933 | .owner = THIS_MODULE, \ |
@@ -970,7 +942,7 @@ static struct twlreg_info TWL6025_INFO_##label = { \ | |||
970 | .desc = { \ | 942 | .desc = { \ |
971 | .name = #label, \ | 943 | .name = #label, \ |
972 | .id = TWL6025_REG_##label, \ | 944 | .id = TWL6025_REG_##label, \ |
973 | .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \ | 945 | .n_voltages = 32, \ |
974 | .ops = &twl6030ldo_ops, \ | 946 | .ops = &twl6030ldo_ops, \ |
975 | .type = REGULATOR_VOLTAGE, \ | 947 | .type = REGULATOR_VOLTAGE, \ |
976 | .owner = THIS_MODULE, \ | 948 | .owner = THIS_MODULE, \ |
@@ -983,7 +955,6 @@ static struct twlreg_info TWLFIXED_INFO_##label = { \ | |||
983 | .base = offset, \ | 955 | .base = offset, \ |
984 | .id = num, \ | 956 | .id = num, \ |
985 | .min_mV = mVolts, \ | 957 | .min_mV = mVolts, \ |
986 | .delay = turnon_delay, \ | ||
987 | .remap = remap_conf, \ | 958 | .remap = remap_conf, \ |
988 | .desc = { \ | 959 | .desc = { \ |
989 | .name = #label, \ | 960 | .name = #label, \ |
@@ -992,19 +963,20 @@ static struct twlreg_info TWLFIXED_INFO_##label = { \ | |||
992 | .ops = &operations, \ | 963 | .ops = &operations, \ |
993 | .type = REGULATOR_VOLTAGE, \ | 964 | .type = REGULATOR_VOLTAGE, \ |
994 | .owner = THIS_MODULE, \ | 965 | .owner = THIS_MODULE, \ |
966 | .enable_time = turnon_delay, \ | ||
995 | }, \ | 967 | }, \ |
996 | } | 968 | } |
997 | 969 | ||
998 | #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ | 970 | #define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \ |
999 | static struct twlreg_info TWLRES_INFO_##label = { \ | 971 | static struct twlreg_info TWLRES_INFO_##label = { \ |
1000 | .base = offset, \ | 972 | .base = offset, \ |
1001 | .delay = turnon_delay, \ | ||
1002 | .desc = { \ | 973 | .desc = { \ |
1003 | .name = #label, \ | 974 | .name = #label, \ |
1004 | .id = TWL6030_REG_##label, \ | 975 | .id = TWL6030_REG_##label, \ |
1005 | .ops = &twl6030_fixed_resource, \ | 976 | .ops = &twl6030_fixed_resource, \ |
1006 | .type = REGULATOR_VOLTAGE, \ | 977 | .type = REGULATOR_VOLTAGE, \ |
1007 | .owner = THIS_MODULE, \ | 978 | .owner = THIS_MODULE, \ |
979 | .enable_time = turnon_delay, \ | ||
1008 | }, \ | 980 | }, \ |
1009 | } | 981 | } |
1010 | 982 | ||
@@ -1109,7 +1081,6 @@ static u8 twl_get_smps_mult(void) | |||
1109 | #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) | 1081 | #define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) |
1110 | #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) | 1082 | #define TWL6025_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6025, label) |
1111 | #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) | 1083 | #define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) |
1112 | #define TWLRES_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLRES, label) | ||
1113 | #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) | 1084 | #define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) |
1114 | 1085 | ||
1115 | static const struct of_device_id twl_of_match[] __devinitconst = { | 1086 | static const struct of_device_id twl_of_match[] __devinitconst = { |
@@ -1157,7 +1128,6 @@ static const struct of_device_id twl_of_match[] __devinitconst = { | |||
1157 | TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), | 1128 | TWLFIXED_OF_MATCH("ti,twl6030-vusb", VUSB), |
1158 | TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), | 1129 | TWLFIXED_OF_MATCH("ti,twl6030-v1v8", V1V8), |
1159 | TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), | 1130 | TWLFIXED_OF_MATCH("ti,twl6030-v2v1", V2V1), |
1160 | TWLRES_OF_MATCH("ti,twl6030-clk32kg", CLK32KG), | ||
1161 | TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), | 1131 | TWLSMPS_OF_MATCH("ti,twl6025-smps3", SMPS3), |
1162 | TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), | 1132 | TWLSMPS_OF_MATCH("ti,twl6025-smps4", SMPS4), |
1163 | TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), | 1133 | TWLSMPS_OF_MATCH("ti,twl6025-vio", VIO), |
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 099da11e989f..7413885be01b 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c | |||
@@ -215,8 +215,8 @@ static int wm831x_buckv_list_voltage(struct regulator_dev *rdev, | |||
215 | return -EINVAL; | 215 | return -EINVAL; |
216 | } | 216 | } |
217 | 217 | ||
218 | static int wm831x_buckv_select_min_voltage(struct regulator_dev *rdev, | 218 | static int wm831x_buckv_map_voltage(struct regulator_dev *rdev, |
219 | int min_uV, int max_uV) | 219 | int min_uV, int max_uV) |
220 | { | 220 | { |
221 | u16 vsel; | 221 | u16 vsel; |
222 | 222 | ||
@@ -251,20 +251,14 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) | |||
251 | return 0; | 251 | return 0; |
252 | } | 252 | } |
253 | 253 | ||
254 | static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, | 254 | static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev, |
255 | int min_uV, int max_uV, unsigned *selector) | 255 | unsigned vsel) |
256 | { | 256 | { |
257 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | 257 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); |
258 | struct wm831x *wm831x = dcdc->wm831x; | 258 | struct wm831x *wm831x = dcdc->wm831x; |
259 | int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; | 259 | int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; |
260 | int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; | 260 | int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL; |
261 | int vsel, ret; | 261 | int ret; |
262 | |||
263 | vsel = wm831x_buckv_select_min_voltage(rdev, min_uV, max_uV); | ||
264 | if (vsel < 0) | ||
265 | return vsel; | ||
266 | |||
267 | *selector = vsel; | ||
268 | 262 | ||
269 | /* If this value is already set then do a GPIO update if we can */ | 263 | /* If this value is already set then do a GPIO update if we can */ |
270 | if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) | 264 | if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) |
@@ -315,7 +309,7 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev, | |||
315 | u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; | 309 | u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; |
316 | int vsel; | 310 | int vsel; |
317 | 311 | ||
318 | vsel = wm831x_buckv_select_min_voltage(rdev, uV, uV); | 312 | vsel = wm831x_buckv_map_voltage(rdev, uV, uV); |
319 | if (vsel < 0) | 313 | if (vsel < 0) |
320 | return vsel; | 314 | return vsel; |
321 | 315 | ||
@@ -373,9 +367,10 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev) | |||
373 | } | 367 | } |
374 | 368 | ||
375 | static struct regulator_ops wm831x_buckv_ops = { | 369 | static struct regulator_ops wm831x_buckv_ops = { |
376 | .set_voltage = wm831x_buckv_set_voltage, | 370 | .set_voltage_sel = wm831x_buckv_set_voltage_sel, |
377 | .get_voltage_sel = wm831x_buckv_get_voltage_sel, | 371 | .get_voltage_sel = wm831x_buckv_get_voltage_sel, |
378 | .list_voltage = wm831x_buckv_list_voltage, | 372 | .list_voltage = wm831x_buckv_list_voltage, |
373 | .map_voltage = wm831x_buckv_map_voltage, | ||
379 | .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, | 374 | .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, |
380 | .set_current_limit = wm831x_buckv_set_current_limit, | 375 | .set_current_limit = wm831x_buckv_set_current_limit, |
381 | .get_current_limit = wm831x_buckv_get_current_limit, | 376 | .get_current_limit = wm831x_buckv_get_current_limit, |
@@ -599,60 +594,25 @@ static struct platform_driver wm831x_buckv_driver = { | |||
599 | * BUCKP specifics | 594 | * BUCKP specifics |
600 | */ | 595 | */ |
601 | 596 | ||
602 | static int wm831x_buckp_list_voltage(struct regulator_dev *rdev, | 597 | static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
603 | unsigned selector) | ||
604 | { | ||
605 | if (selector <= WM831X_BUCKP_MAX_SELECTOR) | ||
606 | return 850000 + (selector * 25000); | ||
607 | else | ||
608 | return -EINVAL; | ||
609 | } | ||
610 | |||
611 | static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg, | ||
612 | int min_uV, int max_uV, int *selector) | ||
613 | { | 598 | { |
614 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | 599 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); |
615 | struct wm831x *wm831x = dcdc->wm831x; | 600 | struct wm831x *wm831x = dcdc->wm831x; |
616 | u16 vsel; | ||
617 | |||
618 | if (min_uV <= 34000000) | ||
619 | vsel = (min_uV - 850000) / 25000; | ||
620 | else | ||
621 | return -EINVAL; | ||
622 | |||
623 | if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV) | ||
624 | return -EINVAL; | ||
625 | |||
626 | *selector = vsel; | ||
627 | |||
628 | return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel); | ||
629 | } | ||
630 | |||
631 | static int wm831x_buckp_set_voltage(struct regulator_dev *rdev, | ||
632 | int min_uV, int max_uV, | ||
633 | unsigned *selector) | ||
634 | { | ||
635 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
636 | u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; | ||
637 | |||
638 | return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
639 | selector); | ||
640 | } | ||
641 | |||
642 | static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, | ||
643 | int uV) | ||
644 | { | ||
645 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
646 | u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; | 601 | u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; |
647 | unsigned selector; | 602 | int sel; |
603 | |||
604 | sel = regulator_map_voltage_linear(rdev, uV, uV); | ||
605 | if (sel < 0) | ||
606 | return sel; | ||
648 | 607 | ||
649 | return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector); | 608 | return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, sel); |
650 | } | 609 | } |
651 | 610 | ||
652 | static struct regulator_ops wm831x_buckp_ops = { | 611 | static struct regulator_ops wm831x_buckp_ops = { |
653 | .set_voltage = wm831x_buckp_set_voltage, | 612 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
654 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 613 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
655 | .list_voltage = wm831x_buckp_list_voltage, | 614 | .list_voltage = regulator_list_voltage_linear, |
615 | .map_voltage = regulator_map_voltage_linear, | ||
656 | .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, | 616 | .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, |
657 | 617 | ||
658 | .is_enabled = regulator_is_enabled_regmap, | 618 | .is_enabled = regulator_is_enabled_regmap, |
@@ -715,6 +675,8 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev) | |||
715 | dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; | 675 | dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; |
716 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; | 676 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; |
717 | dcdc->desc.enable_mask = 1 << id; | 677 | dcdc->desc.enable_mask = 1 << id; |
678 | dcdc->desc.min_uV = 850000; | ||
679 | dcdc->desc.uV_step = 25000; | ||
718 | 680 | ||
719 | config.dev = pdev->dev.parent; | 681 | config.dev = pdev->dev.parent; |
720 | if (pdata) | 682 | if (pdata) |
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index a9a28d8ac185..5cb70ca1e98d 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c | |||
@@ -78,13 +78,10 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, | |||
78 | return -EINVAL; | 78 | return -EINVAL; |
79 | } | 79 | } |
80 | 80 | ||
81 | static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, | 81 | static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev, |
82 | int min_uV, int max_uV, | 82 | int min_uV, int max_uV) |
83 | unsigned *selector) | ||
84 | { | 83 | { |
85 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 84 | int volt, vsel; |
86 | struct wm831x *wm831x = ldo->wm831x; | ||
87 | int vsel, ret; | ||
88 | 85 | ||
89 | if (min_uV < 900000) | 86 | if (min_uV < 900000) |
90 | vsel = 0; | 87 | vsel = 0; |
@@ -94,36 +91,25 @@ static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, | |||
94 | vsel = ((min_uV - 1700000) / 100000) | 91 | vsel = ((min_uV - 1700000) / 100000) |
95 | + WM831X_GP_LDO_SELECTOR_LOW + 1; | 92 | + WM831X_GP_LDO_SELECTOR_LOW + 1; |
96 | 93 | ||
97 | ret = wm831x_gp_ldo_list_voltage(rdev, vsel); | 94 | volt = wm831x_gp_ldo_list_voltage(rdev, vsel); |
98 | if (ret < 0) | 95 | if (volt < min_uV || volt > max_uV) |
99 | return ret; | ||
100 | if (ret < min_uV || ret > max_uV) | ||
101 | return -EINVAL; | 96 | return -EINVAL; |
102 | 97 | ||
103 | *selector = vsel; | 98 | return vsel; |
104 | |||
105 | return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); | ||
106 | } | ||
107 | |||
108 | static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, | ||
109 | int min_uV, int max_uV, | ||
110 | unsigned *selector) | ||
111 | { | ||
112 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
113 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
114 | |||
115 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
116 | selector); | ||
117 | } | 99 | } |
118 | 100 | ||
119 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, | 101 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
120 | int uV) | 102 | int uV) |
121 | { | 103 | { |
122 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 104 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
123 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 105 | struct wm831x *wm831x = ldo->wm831x; |
124 | unsigned int selector; | 106 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
125 | 107 | ||
126 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 108 | sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV); |
109 | if (sel < 0) | ||
110 | return sel; | ||
111 | |||
112 | return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel); | ||
127 | } | 113 | } |
128 | 114 | ||
129 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) | 115 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) |
@@ -243,8 +229,9 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, | |||
243 | 229 | ||
244 | static struct regulator_ops wm831x_gp_ldo_ops = { | 230 | static struct regulator_ops wm831x_gp_ldo_ops = { |
245 | .list_voltage = wm831x_gp_ldo_list_voltage, | 231 | .list_voltage = wm831x_gp_ldo_list_voltage, |
232 | .map_voltage = wm831x_gp_ldo_map_voltage, | ||
246 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 233 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
247 | .set_voltage = wm831x_gp_ldo_set_voltage, | 234 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
248 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, | 235 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, |
249 | .get_mode = wm831x_gp_ldo_get_mode, | 236 | .get_mode = wm831x_gp_ldo_get_mode, |
250 | .set_mode = wm831x_gp_ldo_set_mode, | 237 | .set_mode = wm831x_gp_ldo_set_mode, |
@@ -384,13 +371,10 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, | |||
384 | return -EINVAL; | 371 | return -EINVAL; |
385 | } | 372 | } |
386 | 373 | ||
387 | static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, | 374 | static int wm831x_aldo_map_voltage(struct regulator_dev *rdev, |
388 | int min_uV, int max_uV, | 375 | int min_uV, int max_uV) |
389 | unsigned *selector) | ||
390 | { | 376 | { |
391 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 377 | int volt, vsel; |
392 | struct wm831x *wm831x = ldo->wm831x; | ||
393 | int vsel, ret; | ||
394 | 378 | ||
395 | if (min_uV < 1000000) | 379 | if (min_uV < 1000000) |
396 | vsel = 0; | 380 | vsel = 0; |
@@ -400,35 +384,26 @@ static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, | |||
400 | vsel = ((min_uV - 1700000) / 100000) | 384 | vsel = ((min_uV - 1700000) / 100000) |
401 | + WM831X_ALDO_SELECTOR_LOW + 1; | 385 | + WM831X_ALDO_SELECTOR_LOW + 1; |
402 | 386 | ||
403 | ret = wm831x_aldo_list_voltage(rdev, vsel); | 387 | volt = wm831x_aldo_list_voltage(rdev, vsel); |
404 | if (ret < 0) | 388 | if (volt < min_uV || volt > max_uV) |
405 | return ret; | ||
406 | if (ret < min_uV || ret > max_uV) | ||
407 | return -EINVAL; | 389 | return -EINVAL; |
408 | 390 | ||
409 | *selector = vsel; | 391 | return vsel; |
410 | |||
411 | return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); | ||
412 | } | ||
413 | |||
414 | static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, | ||
415 | int min_uV, int max_uV, unsigned *selector) | ||
416 | { | ||
417 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
418 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
419 | 392 | ||
420 | return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
421 | selector); | ||
422 | } | 393 | } |
423 | 394 | ||
424 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, | 395 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, |
425 | int uV) | 396 | int uV) |
426 | { | 397 | { |
427 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 398 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
428 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 399 | struct wm831x *wm831x = ldo->wm831x; |
429 | unsigned int selector; | 400 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
401 | |||
402 | sel = wm831x_aldo_map_voltage(rdev, uV, uV); | ||
403 | if (sel < 0) | ||
404 | return sel; | ||
430 | 405 | ||
431 | return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 406 | return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel); |
432 | } | 407 | } |
433 | 408 | ||
434 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) | 409 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) |
@@ -506,8 +481,9 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev) | |||
506 | 481 | ||
507 | static struct regulator_ops wm831x_aldo_ops = { | 482 | static struct regulator_ops wm831x_aldo_ops = { |
508 | .list_voltage = wm831x_aldo_list_voltage, | 483 | .list_voltage = wm831x_aldo_list_voltage, |
484 | .map_voltage = wm831x_aldo_map_voltage, | ||
509 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 485 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
510 | .set_voltage = wm831x_aldo_set_voltage, | 486 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
511 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, | 487 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, |
512 | .get_mode = wm831x_aldo_get_mode, | 488 | .get_mode = wm831x_aldo_get_mode, |
513 | .set_mode = wm831x_aldo_set_mode, | 489 | .set_mode = wm831x_aldo_set_mode, |
@@ -628,47 +604,18 @@ static struct platform_driver wm831x_aldo_driver = { | |||
628 | 604 | ||
629 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf | 605 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf |
630 | 606 | ||
631 | static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, | ||
632 | int reg, | ||
633 | int min_uV, int max_uV, | ||
634 | unsigned *selector) | ||
635 | { | ||
636 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
637 | struct wm831x *wm831x = ldo->wm831x; | ||
638 | int vsel, ret; | ||
639 | |||
640 | vsel = (min_uV - 800000) / 50000; | ||
641 | |||
642 | ret = regulator_list_voltage_linear(rdev, vsel); | ||
643 | if (ret < 0) | ||
644 | return ret; | ||
645 | if (ret < min_uV || ret > max_uV) | ||
646 | return -EINVAL; | ||
647 | |||
648 | *selector = vsel; | ||
649 | |||
650 | return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); | ||
651 | } | ||
652 | |||
653 | static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, | ||
654 | int min_uV, int max_uV, | ||
655 | unsigned *selector) | ||
656 | { | ||
657 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
658 | int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; | ||
659 | |||
660 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
661 | selector); | ||
662 | } | ||
663 | |||
664 | static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, | 607 | static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
665 | int uV) | 608 | int uV) |
666 | { | 609 | { |
667 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 610 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
668 | int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; | 611 | struct wm831x *wm831x = ldo->wm831x; |
669 | unsigned selector; | 612 | int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; |
613 | |||
614 | sel = regulator_map_voltage_linear(rdev, uV, uV); | ||
615 | if (sel < 0) | ||
616 | return sel; | ||
670 | 617 | ||
671 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 618 | return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel); |
672 | } | 619 | } |
673 | 620 | ||
674 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | 621 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) |
@@ -690,8 +637,9 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | |||
690 | 637 | ||
691 | static struct regulator_ops wm831x_alive_ldo_ops = { | 638 | static struct regulator_ops wm831x_alive_ldo_ops = { |
692 | .list_voltage = regulator_list_voltage_linear, | 639 | .list_voltage = regulator_list_voltage_linear, |
640 | .map_voltage = regulator_map_voltage_linear, | ||
693 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 641 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
694 | .set_voltage = wm831x_alive_ldo_set_voltage, | 642 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
695 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, | 643 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, |
696 | .get_status = wm831x_alive_ldo_get_status, | 644 | .get_status = wm831x_alive_ldo_get_status, |
697 | 645 | ||
@@ -753,6 +701,7 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) | |||
753 | ldo->desc.enable_mask = 1 << id; | 701 | ldo->desc.enable_mask = 1 << id; |
754 | ldo->desc.min_uV = 800000; | 702 | ldo->desc.min_uV = 800000; |
755 | ldo->desc.uV_step = 50000; | 703 | ldo->desc.uV_step = 50000; |
704 | ldo->desc.enable_time = 1000; | ||
756 | 705 | ||
757 | config.dev = pdev->dev.parent; | 706 | config.dev = pdev->dev.parent; |
758 | if (pdata) | 707 | if (pdata) |
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 94e550dc70b6..7f0fa22ef2aa 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
@@ -108,33 +108,6 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting) | |||
108 | return -EINVAL; | 108 | return -EINVAL; |
109 | } | 109 | } |
110 | 110 | ||
111 | static inline int wm8350_ldo_val_to_mvolts(unsigned int val) | ||
112 | { | ||
113 | if (val < 16) | ||
114 | return (val * 50) + 900; | ||
115 | else | ||
116 | return ((val - 16) * 100) + 1800; | ||
117 | |||
118 | } | ||
119 | |||
120 | static inline unsigned int wm8350_ldo_mvolts_to_val(int mV) | ||
121 | { | ||
122 | if (mV < 1800) | ||
123 | return (mV - 900) / 50; | ||
124 | else | ||
125 | return ((mV - 1800) / 100) + 16; | ||
126 | } | ||
127 | |||
128 | static inline int wm8350_dcdc_val_to_mvolts(unsigned int val) | ||
129 | { | ||
130 | return (val * 25) + 850; | ||
131 | } | ||
132 | |||
133 | static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV) | ||
134 | { | ||
135 | return (mV - 850) / 25; | ||
136 | } | ||
137 | |||
138 | static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, | 111 | static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, |
139 | int max_uA) | 112 | int max_uA) |
140 | { | 113 | { |
@@ -359,104 +332,13 @@ int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, | |||
359 | } | 332 | } |
360 | EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); | 333 | EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); |
361 | 334 | ||
362 | static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV, | ||
363 | int max_uV, unsigned *selector) | ||
364 | { | ||
365 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
366 | int volt_reg, dcdc = rdev_get_id(rdev), mV, | ||
367 | min_mV = min_uV / 1000, max_mV = max_uV / 1000; | ||
368 | u16 val; | ||
369 | |||
370 | if (min_mV < 850 || min_mV > 4025) | ||
371 | return -EINVAL; | ||
372 | if (max_mV < 850 || max_mV > 4025) | ||
373 | return -EINVAL; | ||
374 | |||
375 | /* step size is 25mV */ | ||
376 | mV = (min_mV - 826) / 25; | ||
377 | if (wm8350_dcdc_val_to_mvolts(mV) > max_mV) | ||
378 | return -EINVAL; | ||
379 | BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV); | ||
380 | |||
381 | switch (dcdc) { | ||
382 | case WM8350_DCDC_1: | ||
383 | volt_reg = WM8350_DCDC1_CONTROL; | ||
384 | break; | ||
385 | case WM8350_DCDC_3: | ||
386 | volt_reg = WM8350_DCDC3_CONTROL; | ||
387 | break; | ||
388 | case WM8350_DCDC_4: | ||
389 | volt_reg = WM8350_DCDC4_CONTROL; | ||
390 | break; | ||
391 | case WM8350_DCDC_6: | ||
392 | volt_reg = WM8350_DCDC6_CONTROL; | ||
393 | break; | ||
394 | case WM8350_DCDC_2: | ||
395 | case WM8350_DCDC_5: | ||
396 | default: | ||
397 | return -EINVAL; | ||
398 | } | ||
399 | |||
400 | *selector = mV; | ||
401 | |||
402 | /* all DCDCs have same mV bits */ | ||
403 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; | ||
404 | wm8350_reg_write(wm8350, volt_reg, val | mV); | ||
405 | return 0; | ||
406 | } | ||
407 | |||
408 | static int wm8350_dcdc_get_voltage_sel(struct regulator_dev *rdev) | ||
409 | { | ||
410 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
411 | int volt_reg, dcdc = rdev_get_id(rdev); | ||
412 | |||
413 | switch (dcdc) { | ||
414 | case WM8350_DCDC_1: | ||
415 | volt_reg = WM8350_DCDC1_CONTROL; | ||
416 | break; | ||
417 | case WM8350_DCDC_3: | ||
418 | volt_reg = WM8350_DCDC3_CONTROL; | ||
419 | break; | ||
420 | case WM8350_DCDC_4: | ||
421 | volt_reg = WM8350_DCDC4_CONTROL; | ||
422 | break; | ||
423 | case WM8350_DCDC_6: | ||
424 | volt_reg = WM8350_DCDC6_CONTROL; | ||
425 | break; | ||
426 | case WM8350_DCDC_2: | ||
427 | case WM8350_DCDC_5: | ||
428 | default: | ||
429 | return -EINVAL; | ||
430 | } | ||
431 | |||
432 | /* all DCDCs have same mV bits */ | ||
433 | return wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK; | ||
434 | } | ||
435 | |||
436 | static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, | ||
437 | unsigned selector) | ||
438 | { | ||
439 | if (selector > WM8350_DCDC_MAX_VSEL) | ||
440 | return -EINVAL; | ||
441 | return wm8350_dcdc_val_to_mvolts(selector) * 1000; | ||
442 | } | ||
443 | |||
444 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) | 335 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
445 | { | 336 | { |
446 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | 337 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
447 | int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev); | 338 | int sel, volt_reg, dcdc = rdev_get_id(rdev); |
448 | u16 val; | 339 | u16 val; |
449 | 340 | ||
450 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV); | 341 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, uV / 1000); |
451 | |||
452 | if (mV && (mV < 850 || mV > 4025)) { | ||
453 | dev_err(wm8350->dev, | ||
454 | "DCDC%d suspend voltage %d mV out of range\n", | ||
455 | dcdc, mV); | ||
456 | return -EINVAL; | ||
457 | } | ||
458 | if (mV == 0) | ||
459 | mV = 850; | ||
460 | 342 | ||
461 | switch (dcdc) { | 343 | switch (dcdc) { |
462 | case WM8350_DCDC_1: | 344 | case WM8350_DCDC_1: |
@@ -477,10 +359,13 @@ static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) | |||
477 | return -EINVAL; | 359 | return -EINVAL; |
478 | } | 360 | } |
479 | 361 | ||
362 | sel = regulator_map_voltage_linear(rdev, uV, uV); | ||
363 | if (sel < 0) | ||
364 | return -EINVAL; | ||
365 | |||
480 | /* all DCDCs have same mV bits */ | 366 | /* all DCDCs have same mV bits */ |
481 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; | 367 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; |
482 | wm8350_reg_write(wm8350, volt_reg, | 368 | wm8350_reg_write(wm8350, volt_reg, val | sel); |
483 | val | wm8350_dcdc_mvolts_to_val(mV)); | ||
484 | return 0; | 369 | return 0; |
485 | } | 370 | } |
486 | 371 | ||
@@ -657,19 +542,49 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, | |||
657 | return 0; | 542 | return 0; |
658 | } | 543 | } |
659 | 544 | ||
545 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, | ||
546 | unsigned selector) | ||
547 | { | ||
548 | if (selector > WM8350_LDO1_VSEL_MASK) | ||
549 | return -EINVAL; | ||
550 | |||
551 | if (selector < 16) | ||
552 | return (selector * 50000) + 900000; | ||
553 | else | ||
554 | return ((selector - 16) * 100000) + 1800000; | ||
555 | } | ||
556 | |||
557 | static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV, | ||
558 | int max_uV) | ||
559 | { | ||
560 | int volt, sel; | ||
561 | int min_mV = min_uV / 1000; | ||
562 | int max_mV = max_uV / 1000; | ||
563 | |||
564 | if (min_mV < 900 || min_mV > 3300) | ||
565 | return -EINVAL; | ||
566 | if (max_mV < 900 || max_mV > 3300) | ||
567 | return -EINVAL; | ||
568 | |||
569 | if (min_mV < 1800) /* step size is 50mV < 1800mV */ | ||
570 | sel = DIV_ROUND_UP(min_uV - 900, 50); | ||
571 | else /* step size is 100mV > 1800mV */ | ||
572 | sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16; | ||
573 | |||
574 | volt = wm8350_ldo_list_voltage(rdev, sel); | ||
575 | if (volt < min_uV || volt > max_uV) | ||
576 | return -EINVAL; | ||
577 | |||
578 | return sel; | ||
579 | } | ||
580 | |||
660 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) | 581 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
661 | { | 582 | { |
662 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | 583 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
663 | int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev); | 584 | int sel, volt_reg, ldo = rdev_get_id(rdev); |
664 | u16 val; | 585 | u16 val; |
665 | 586 | ||
666 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV); | 587 | dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, uV / 1000); |
667 | |||
668 | if (mV < 900 || mV > 3300) { | ||
669 | dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n", | ||
670 | ldo, mV); | ||
671 | return -EINVAL; | ||
672 | } | ||
673 | 588 | ||
674 | switch (ldo) { | 589 | switch (ldo) { |
675 | case WM8350_LDO_1: | 590 | case WM8350_LDO_1: |
@@ -688,10 +603,13 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) | |||
688 | return -EINVAL; | 603 | return -EINVAL; |
689 | } | 604 | } |
690 | 605 | ||
606 | sel = wm8350_ldo_map_voltage(rdev, uV, uV); | ||
607 | if (sel < 0) | ||
608 | return -EINVAL; | ||
609 | |||
691 | /* all LDOs have same mV bits */ | 610 | /* all LDOs have same mV bits */ |
692 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; | 611 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; |
693 | wm8350_reg_write(wm8350, volt_reg, | 612 | wm8350_reg_write(wm8350, volt_reg, val | sel); |
694 | val | wm8350_ldo_mvolts_to_val(mV)); | ||
695 | return 0; | 613 | return 0; |
696 | } | 614 | } |
697 | 615 | ||
@@ -753,92 +671,6 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev) | |||
753 | return 0; | 671 | return 0; |
754 | } | 672 | } |
755 | 673 | ||
756 | static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, | ||
757 | int max_uV, unsigned *selector) | ||
758 | { | ||
759 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
760 | int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000, | ||
761 | max_mV = max_uV / 1000; | ||
762 | u16 val; | ||
763 | |||
764 | if (min_mV < 900 || min_mV > 3300) | ||
765 | return -EINVAL; | ||
766 | if (max_mV < 900 || max_mV > 3300) | ||
767 | return -EINVAL; | ||
768 | |||
769 | if (min_mV < 1800) { | ||
770 | /* step size is 50mV < 1800mV */ | ||
771 | mV = (min_mV - 851) / 50; | ||
772 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) | ||
773 | return -EINVAL; | ||
774 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); | ||
775 | } else { | ||
776 | /* step size is 100mV > 1800mV */ | ||
777 | mV = ((min_mV - 1701) / 100) + 16; | ||
778 | if (wm8350_ldo_val_to_mvolts(mV) > max_mV) | ||
779 | return -EINVAL; | ||
780 | BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV); | ||
781 | } | ||
782 | |||
783 | switch (ldo) { | ||
784 | case WM8350_LDO_1: | ||
785 | volt_reg = WM8350_LDO1_CONTROL; | ||
786 | break; | ||
787 | case WM8350_LDO_2: | ||
788 | volt_reg = WM8350_LDO2_CONTROL; | ||
789 | break; | ||
790 | case WM8350_LDO_3: | ||
791 | volt_reg = WM8350_LDO3_CONTROL; | ||
792 | break; | ||
793 | case WM8350_LDO_4: | ||
794 | volt_reg = WM8350_LDO4_CONTROL; | ||
795 | break; | ||
796 | default: | ||
797 | return -EINVAL; | ||
798 | } | ||
799 | |||
800 | *selector = mV; | ||
801 | |||
802 | /* all LDOs have same mV bits */ | ||
803 | val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; | ||
804 | wm8350_reg_write(wm8350, volt_reg, val | mV); | ||
805 | return 0; | ||
806 | } | ||
807 | |||
808 | static int wm8350_ldo_get_voltage_sel(struct regulator_dev *rdev) | ||
809 | { | ||
810 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
811 | int volt_reg, ldo = rdev_get_id(rdev); | ||
812 | |||
813 | switch (ldo) { | ||
814 | case WM8350_LDO_1: | ||
815 | volt_reg = WM8350_LDO1_CONTROL; | ||
816 | break; | ||
817 | case WM8350_LDO_2: | ||
818 | volt_reg = WM8350_LDO2_CONTROL; | ||
819 | break; | ||
820 | case WM8350_LDO_3: | ||
821 | volt_reg = WM8350_LDO3_CONTROL; | ||
822 | break; | ||
823 | case WM8350_LDO_4: | ||
824 | volt_reg = WM8350_LDO4_CONTROL; | ||
825 | break; | ||
826 | default: | ||
827 | return -EINVAL; | ||
828 | } | ||
829 | |||
830 | /* all LDOs have same mV bits */ | ||
831 | return wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK; | ||
832 | } | ||
833 | |||
834 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, | ||
835 | unsigned selector) | ||
836 | { | ||
837 | if (selector > WM8350_LDO1_VSEL_MASK) | ||
838 | return -EINVAL; | ||
839 | return wm8350_ldo_val_to_mvolts(selector) * 1000; | ||
840 | } | ||
841 | |||
842 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, | 674 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, |
843 | u16 stop, u16 fault) | 675 | u16 stop, u16 fault) |
844 | { | 676 | { |
@@ -959,63 +791,6 @@ int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode, | |||
959 | } | 791 | } |
960 | EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode); | 792 | EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode); |
961 | 793 | ||
962 | static int wm8350_dcdc_enable(struct regulator_dev *rdev) | ||
963 | { | ||
964 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
965 | int dcdc = rdev_get_id(rdev); | ||
966 | u16 shift; | ||
967 | |||
968 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
969 | return -EINVAL; | ||
970 | |||
971 | shift = dcdc - WM8350_DCDC_1; | ||
972 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
973 | return 0; | ||
974 | } | ||
975 | |||
976 | static int wm8350_dcdc_disable(struct regulator_dev *rdev) | ||
977 | { | ||
978 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
979 | int dcdc = rdev_get_id(rdev); | ||
980 | u16 shift; | ||
981 | |||
982 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
983 | return -EINVAL; | ||
984 | |||
985 | shift = dcdc - WM8350_DCDC_1; | ||
986 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
987 | |||
988 | return 0; | ||
989 | } | ||
990 | |||
991 | static int wm8350_ldo_enable(struct regulator_dev *rdev) | ||
992 | { | ||
993 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
994 | int ldo = rdev_get_id(rdev); | ||
995 | u16 shift; | ||
996 | |||
997 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
998 | return -EINVAL; | ||
999 | |||
1000 | shift = (ldo - WM8350_LDO_1) + 8; | ||
1001 | wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
1002 | return 0; | ||
1003 | } | ||
1004 | |||
1005 | static int wm8350_ldo_disable(struct regulator_dev *rdev) | ||
1006 | { | ||
1007 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1008 | int ldo = rdev_get_id(rdev); | ||
1009 | u16 shift; | ||
1010 | |||
1011 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
1012 | return -EINVAL; | ||
1013 | |||
1014 | shift = (ldo - WM8350_LDO_1) + 8; | ||
1015 | wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift); | ||
1016 | return 0; | ||
1017 | } | ||
1018 | |||
1019 | static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable) | 794 | static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable) |
1020 | { | 795 | { |
1021 | int reg = 0, ret; | 796 | int reg = 0, ret; |
@@ -1197,42 +972,17 @@ static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev, | |||
1197 | return mode; | 972 | return mode; |
1198 | } | 973 | } |
1199 | 974 | ||
1200 | static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev) | ||
1201 | { | ||
1202 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1203 | int dcdc = rdev_get_id(rdev), shift; | ||
1204 | |||
1205 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | ||
1206 | return -EINVAL; | ||
1207 | |||
1208 | shift = dcdc - WM8350_DCDC_1; | ||
1209 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) | ||
1210 | & (1 << shift); | ||
1211 | } | ||
1212 | |||
1213 | static int wm8350_ldo_is_enabled(struct regulator_dev *rdev) | ||
1214 | { | ||
1215 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
1216 | int ldo = rdev_get_id(rdev), shift; | ||
1217 | |||
1218 | if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4) | ||
1219 | return -EINVAL; | ||
1220 | |||
1221 | shift = (ldo - WM8350_LDO_1) + 8; | ||
1222 | return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED) | ||
1223 | & (1 << shift); | ||
1224 | } | ||
1225 | |||
1226 | static struct regulator_ops wm8350_dcdc_ops = { | 975 | static struct regulator_ops wm8350_dcdc_ops = { |
1227 | .set_voltage = wm8350_dcdc_set_voltage, | 976 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
1228 | .get_voltage_sel = wm8350_dcdc_get_voltage_sel, | 977 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
1229 | .list_voltage = wm8350_dcdc_list_voltage, | 978 | .list_voltage = regulator_list_voltage_linear, |
1230 | .enable = wm8350_dcdc_enable, | 979 | .map_voltage = regulator_map_voltage_linear, |
1231 | .disable = wm8350_dcdc_disable, | 980 | .enable = regulator_enable_regmap, |
981 | .disable = regulator_disable_regmap, | ||
982 | .is_enabled = regulator_is_enabled_regmap, | ||
1232 | .get_mode = wm8350_dcdc_get_mode, | 983 | .get_mode = wm8350_dcdc_get_mode, |
1233 | .set_mode = wm8350_dcdc_set_mode, | 984 | .set_mode = wm8350_dcdc_set_mode, |
1234 | .get_optimum_mode = wm8350_dcdc_get_optimum_mode, | 985 | .get_optimum_mode = wm8350_dcdc_get_optimum_mode, |
1235 | .is_enabled = wm8350_dcdc_is_enabled, | ||
1236 | .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage, | 986 | .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage, |
1237 | .set_suspend_enable = wm8350_dcdc_set_suspend_enable, | 987 | .set_suspend_enable = wm8350_dcdc_set_suspend_enable, |
1238 | .set_suspend_disable = wm8350_dcdc_set_suspend_disable, | 988 | .set_suspend_disable = wm8350_dcdc_set_suspend_disable, |
@@ -1240,20 +990,21 @@ static struct regulator_ops wm8350_dcdc_ops = { | |||
1240 | }; | 990 | }; |
1241 | 991 | ||
1242 | static struct regulator_ops wm8350_dcdc2_5_ops = { | 992 | static struct regulator_ops wm8350_dcdc2_5_ops = { |
1243 | .enable = wm8350_dcdc_enable, | 993 | .enable = regulator_enable_regmap, |
1244 | .disable = wm8350_dcdc_disable, | 994 | .disable = regulator_disable_regmap, |
1245 | .is_enabled = wm8350_dcdc_is_enabled, | 995 | .is_enabled = regulator_is_enabled_regmap, |
1246 | .set_suspend_enable = wm8350_dcdc25_set_suspend_enable, | 996 | .set_suspend_enable = wm8350_dcdc25_set_suspend_enable, |
1247 | .set_suspend_disable = wm8350_dcdc25_set_suspend_disable, | 997 | .set_suspend_disable = wm8350_dcdc25_set_suspend_disable, |
1248 | }; | 998 | }; |
1249 | 999 | ||
1250 | static struct regulator_ops wm8350_ldo_ops = { | 1000 | static struct regulator_ops wm8350_ldo_ops = { |
1251 | .set_voltage = wm8350_ldo_set_voltage, | 1001 | .map_voltage = wm8350_ldo_map_voltage, |
1252 | .get_voltage_sel = wm8350_ldo_get_voltage_sel, | 1002 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
1003 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
1253 | .list_voltage = wm8350_ldo_list_voltage, | 1004 | .list_voltage = wm8350_ldo_list_voltage, |
1254 | .enable = wm8350_ldo_enable, | 1005 | .enable = regulator_enable_regmap, |
1255 | .disable = wm8350_ldo_disable, | 1006 | .disable = regulator_disable_regmap, |
1256 | .is_enabled = wm8350_ldo_is_enabled, | 1007 | .is_enabled = regulator_is_enabled_regmap, |
1257 | .get_mode = wm8350_ldo_get_mode, | 1008 | .get_mode = wm8350_ldo_get_mode, |
1258 | .set_suspend_voltage = wm8350_ldo_set_suspend_voltage, | 1009 | .set_suspend_voltage = wm8350_ldo_set_suspend_voltage, |
1259 | .set_suspend_enable = wm8350_ldo_set_suspend_enable, | 1010 | .set_suspend_enable = wm8350_ldo_set_suspend_enable, |
@@ -1277,6 +1028,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1277 | .irq = WM8350_IRQ_UV_DC1, | 1028 | .irq = WM8350_IRQ_UV_DC1, |
1278 | .type = REGULATOR_VOLTAGE, | 1029 | .type = REGULATOR_VOLTAGE, |
1279 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | 1030 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
1031 | .min_uV = 850000, | ||
1032 | .uV_step = 25000, | ||
1033 | .vsel_reg = WM8350_DCDC1_CONTROL, | ||
1034 | .vsel_mask = WM8350_DC1_VSEL_MASK, | ||
1035 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1036 | .enable_mask = WM8350_DC1_ENA, | ||
1280 | .owner = THIS_MODULE, | 1037 | .owner = THIS_MODULE, |
1281 | }, | 1038 | }, |
1282 | { | 1039 | { |
@@ -1285,6 +1042,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1285 | .ops = &wm8350_dcdc2_5_ops, | 1042 | .ops = &wm8350_dcdc2_5_ops, |
1286 | .irq = WM8350_IRQ_UV_DC2, | 1043 | .irq = WM8350_IRQ_UV_DC2, |
1287 | .type = REGULATOR_VOLTAGE, | 1044 | .type = REGULATOR_VOLTAGE, |
1045 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1046 | .enable_mask = WM8350_DC2_ENA, | ||
1288 | .owner = THIS_MODULE, | 1047 | .owner = THIS_MODULE, |
1289 | }, | 1048 | }, |
1290 | { | 1049 | { |
@@ -1294,6 +1053,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1294 | .irq = WM8350_IRQ_UV_DC3, | 1053 | .irq = WM8350_IRQ_UV_DC3, |
1295 | .type = REGULATOR_VOLTAGE, | 1054 | .type = REGULATOR_VOLTAGE, |
1296 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | 1055 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
1056 | .min_uV = 850000, | ||
1057 | .uV_step = 25000, | ||
1058 | .vsel_reg = WM8350_DCDC3_CONTROL, | ||
1059 | .vsel_mask = WM8350_DC3_VSEL_MASK, | ||
1060 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1061 | .enable_mask = WM8350_DC3_ENA, | ||
1297 | .owner = THIS_MODULE, | 1062 | .owner = THIS_MODULE, |
1298 | }, | 1063 | }, |
1299 | { | 1064 | { |
@@ -1303,6 +1068,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1303 | .irq = WM8350_IRQ_UV_DC4, | 1068 | .irq = WM8350_IRQ_UV_DC4, |
1304 | .type = REGULATOR_VOLTAGE, | 1069 | .type = REGULATOR_VOLTAGE, |
1305 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | 1070 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
1071 | .min_uV = 850000, | ||
1072 | .uV_step = 25000, | ||
1073 | .vsel_reg = WM8350_DCDC4_CONTROL, | ||
1074 | .vsel_mask = WM8350_DC4_VSEL_MASK, | ||
1075 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1076 | .enable_mask = WM8350_DC4_ENA, | ||
1306 | .owner = THIS_MODULE, | 1077 | .owner = THIS_MODULE, |
1307 | }, | 1078 | }, |
1308 | { | 1079 | { |
@@ -1311,6 +1082,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1311 | .ops = &wm8350_dcdc2_5_ops, | 1082 | .ops = &wm8350_dcdc2_5_ops, |
1312 | .irq = WM8350_IRQ_UV_DC5, | 1083 | .irq = WM8350_IRQ_UV_DC5, |
1313 | .type = REGULATOR_VOLTAGE, | 1084 | .type = REGULATOR_VOLTAGE, |
1085 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1086 | .enable_mask = WM8350_DC5_ENA, | ||
1314 | .owner = THIS_MODULE, | 1087 | .owner = THIS_MODULE, |
1315 | }, | 1088 | }, |
1316 | { | 1089 | { |
@@ -1320,6 +1093,12 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1320 | .irq = WM8350_IRQ_UV_DC6, | 1093 | .irq = WM8350_IRQ_UV_DC6, |
1321 | .type = REGULATOR_VOLTAGE, | 1094 | .type = REGULATOR_VOLTAGE, |
1322 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | 1095 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, |
1096 | .min_uV = 850000, | ||
1097 | .uV_step = 25000, | ||
1098 | .vsel_reg = WM8350_DCDC6_CONTROL, | ||
1099 | .vsel_mask = WM8350_DC6_VSEL_MASK, | ||
1100 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1101 | .enable_mask = WM8350_DC6_ENA, | ||
1323 | .owner = THIS_MODULE, | 1102 | .owner = THIS_MODULE, |
1324 | }, | 1103 | }, |
1325 | { | 1104 | { |
@@ -1329,6 +1108,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1329 | .irq = WM8350_IRQ_UV_LDO1, | 1108 | .irq = WM8350_IRQ_UV_LDO1, |
1330 | .type = REGULATOR_VOLTAGE, | 1109 | .type = REGULATOR_VOLTAGE, |
1331 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, | 1110 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, |
1111 | .vsel_reg = WM8350_LDO1_CONTROL, | ||
1112 | .vsel_mask = WM8350_LDO1_VSEL_MASK, | ||
1113 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1114 | .enable_mask = WM8350_LDO1_ENA, | ||
1332 | .owner = THIS_MODULE, | 1115 | .owner = THIS_MODULE, |
1333 | }, | 1116 | }, |
1334 | { | 1117 | { |
@@ -1338,6 +1121,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1338 | .irq = WM8350_IRQ_UV_LDO2, | 1121 | .irq = WM8350_IRQ_UV_LDO2, |
1339 | .type = REGULATOR_VOLTAGE, | 1122 | .type = REGULATOR_VOLTAGE, |
1340 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, | 1123 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, |
1124 | .vsel_reg = WM8350_LDO2_CONTROL, | ||
1125 | .vsel_mask = WM8350_LDO2_VSEL_MASK, | ||
1126 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1127 | .enable_mask = WM8350_LDO2_ENA, | ||
1341 | .owner = THIS_MODULE, | 1128 | .owner = THIS_MODULE, |
1342 | }, | 1129 | }, |
1343 | { | 1130 | { |
@@ -1347,6 +1134,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1347 | .irq = WM8350_IRQ_UV_LDO3, | 1134 | .irq = WM8350_IRQ_UV_LDO3, |
1348 | .type = REGULATOR_VOLTAGE, | 1135 | .type = REGULATOR_VOLTAGE, |
1349 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, | 1136 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, |
1137 | .vsel_reg = WM8350_LDO3_CONTROL, | ||
1138 | .vsel_mask = WM8350_LDO3_VSEL_MASK, | ||
1139 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1140 | .enable_mask = WM8350_LDO3_ENA, | ||
1350 | .owner = THIS_MODULE, | 1141 | .owner = THIS_MODULE, |
1351 | }, | 1142 | }, |
1352 | { | 1143 | { |
@@ -1356,6 +1147,10 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1356 | .irq = WM8350_IRQ_UV_LDO4, | 1147 | .irq = WM8350_IRQ_UV_LDO4, |
1357 | .type = REGULATOR_VOLTAGE, | 1148 | .type = REGULATOR_VOLTAGE, |
1358 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, | 1149 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, |
1150 | .vsel_reg = WM8350_LDO4_CONTROL, | ||
1151 | .vsel_mask = WM8350_LDO4_VSEL_MASK, | ||
1152 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | ||
1153 | .enable_mask = WM8350_LDO4_ENA, | ||
1359 | .owner = THIS_MODULE, | 1154 | .owner = THIS_MODULE, |
1360 | }, | 1155 | }, |
1361 | { | 1156 | { |
@@ -1429,6 +1224,7 @@ static int wm8350_regulator_probe(struct platform_device *pdev) | |||
1429 | config.dev = &pdev->dev; | 1224 | config.dev = &pdev->dev; |
1430 | config.init_data = pdev->dev.platform_data; | 1225 | config.init_data = pdev->dev.platform_data; |
1431 | config.driver_data = dev_get_drvdata(&pdev->dev); | 1226 | config.driver_data = dev_get_drvdata(&pdev->dev); |
1227 | config.regmap = wm8350->regmap; | ||
1432 | 1228 | ||
1433 | /* register regulator */ | 1229 | /* register regulator */ |
1434 | rdev = regulator_register(&wm8350_reg[pdev->id], &config); | 1230 | rdev = regulator_register(&wm8350_reg[pdev->id], &config); |
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 69a2b7ce5e4a..9035dd053611 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c | |||
@@ -28,34 +28,26 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | |||
28 | if (selector < 15) | 28 | if (selector < 15) |
29 | return 900000 + (selector * 50000); | 29 | return 900000 + (selector * 50000); |
30 | else | 30 | else |
31 | return 1600000 + ((selector - 14) * 100000); | 31 | return 1700000 + ((selector - 15) * 100000); |
32 | } | 32 | } |
33 | 33 | ||
34 | static int wm8400_ldo_map_voltage(struct regulator_dev *dev, | 34 | static int wm8400_ldo_map_voltage(struct regulator_dev *dev, |
35 | int min_uV, int max_uV) | 35 | int min_uV, int max_uV) |
36 | { | 36 | { |
37 | u16 val; | 37 | u16 val; |
38 | int volt; | ||
38 | 39 | ||
39 | if (min_uV < 900000 || min_uV > 3300000) | 40 | if (min_uV < 900000 || min_uV > 3300000) |
40 | return -EINVAL; | 41 | return -EINVAL; |
41 | 42 | ||
42 | if (min_uV < 1700000) { | 43 | if (min_uV < 1700000) /* Steps of 50mV from 900mV; */ |
43 | /* Steps of 50mV from 900mV; */ | ||
44 | val = DIV_ROUND_UP(min_uV - 900000, 50000); | 44 | val = DIV_ROUND_UP(min_uV - 900000, 50000); |
45 | else /* Steps of 100mV from 1700mV */ | ||
46 | val = DIV_ROUND_UP(min_uV - 1700000, 100000) + 15; | ||
45 | 47 | ||
46 | if ((val * 50000) + 900000 > max_uV) | 48 | volt = wm8400_ldo_list_voltage(dev, val); |
47 | return -EINVAL; | 49 | if (volt < min_uV || volt > max_uV) |
48 | BUG_ON((val * 50000) + 900000 < min_uV); | 50 | return -EINVAL; |
49 | } else { | ||
50 | /* Steps of 100mV from 1700mV */ | ||
51 | val = DIV_ROUND_UP(min_uV - 1700000, 100000); | ||
52 | |||
53 | if ((val * 100000) + 1700000 > max_uV) | ||
54 | return -EINVAL; | ||
55 | BUG_ON((val * 100000) + 1700000 < min_uV); | ||
56 | |||
57 | val += 0xf; | ||
58 | } | ||
59 | 51 | ||
60 | return val; | 52 | return val; |
61 | } | 53 | } |
@@ -152,6 +144,7 @@ static struct regulator_ops wm8400_dcdc_ops = { | |||
152 | .enable = regulator_enable_regmap, | 144 | .enable = regulator_enable_regmap, |
153 | .disable = regulator_disable_regmap, | 145 | .disable = regulator_disable_regmap, |
154 | .list_voltage = regulator_list_voltage_linear, | 146 | .list_voltage = regulator_list_voltage_linear, |
147 | .map_voltage = regulator_map_voltage_linear, | ||
155 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 148 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
156 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 149 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
157 | .get_mode = wm8400_dcdc_get_mode, | 150 | .get_mode = wm8400_dcdc_get_mode, |
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c index 9a994316e63c..86bb48db149e 100644 --- a/drivers/regulator/wm8994-regulator.c +++ b/drivers/regulator/wm8994-regulator.c | |||
@@ -26,8 +26,6 @@ | |||
26 | #include <linux/mfd/wm8994/pdata.h> | 26 | #include <linux/mfd/wm8994/pdata.h> |
27 | 27 | ||
28 | struct wm8994_ldo { | 28 | struct wm8994_ldo { |
29 | int enable; | ||
30 | bool is_enabled; | ||
31 | struct regulator_dev *regulator; | 29 | struct regulator_dev *regulator; |
32 | struct wm8994 *wm8994; | 30 | struct wm8994 *wm8994; |
33 | }; | 31 | }; |
@@ -35,64 +33,9 @@ struct wm8994_ldo { | |||
35 | #define WM8994_LDO1_MAX_SELECTOR 0x7 | 33 | #define WM8994_LDO1_MAX_SELECTOR 0x7 |
36 | #define WM8994_LDO2_MAX_SELECTOR 0x3 | 34 | #define WM8994_LDO2_MAX_SELECTOR 0x3 |
37 | 35 | ||
38 | static int wm8994_ldo_enable(struct regulator_dev *rdev) | ||
39 | { | ||
40 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
41 | |||
42 | /* If we have no soft control assume that the LDO is always enabled. */ | ||
43 | if (!ldo->enable) | ||
44 | return 0; | ||
45 | |||
46 | gpio_set_value_cansleep(ldo->enable, 1); | ||
47 | ldo->is_enabled = true; | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static int wm8994_ldo_disable(struct regulator_dev *rdev) | ||
53 | { | ||
54 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
55 | |||
56 | /* If we have no soft control assume that the LDO is always enabled. */ | ||
57 | if (!ldo->enable) | ||
58 | return -EINVAL; | ||
59 | |||
60 | gpio_set_value_cansleep(ldo->enable, 0); | ||
61 | ldo->is_enabled = false; | ||
62 | |||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static int wm8994_ldo_is_enabled(struct regulator_dev *rdev) | ||
67 | { | ||
68 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
69 | |||
70 | return ldo->is_enabled; | ||
71 | } | ||
72 | |||
73 | static int wm8994_ldo_enable_time(struct regulator_dev *rdev) | ||
74 | { | ||
75 | /* 3ms is fairly conservative but this shouldn't be too performance | ||
76 | * critical; can be tweaked per-system if required. */ | ||
77 | return 3000; | ||
78 | } | ||
79 | |||
80 | static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev, | ||
81 | unsigned int selector) | ||
82 | { | ||
83 | if (selector > WM8994_LDO1_MAX_SELECTOR) | ||
84 | return -EINVAL; | ||
85 | |||
86 | return (selector * 100000) + 2400000; | ||
87 | } | ||
88 | |||
89 | static struct regulator_ops wm8994_ldo1_ops = { | 36 | static struct regulator_ops wm8994_ldo1_ops = { |
90 | .enable = wm8994_ldo_enable, | 37 | .list_voltage = regulator_list_voltage_linear, |
91 | .disable = wm8994_ldo_disable, | 38 | .map_voltage = regulator_map_voltage_linear, |
92 | .is_enabled = wm8994_ldo_is_enabled, | ||
93 | .enable_time = wm8994_ldo_enable_time, | ||
94 | |||
95 | .list_voltage = wm8994_ldo1_list_voltage, | ||
96 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 39 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
97 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 40 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
98 | }; | 41 | }; |
@@ -124,11 +67,6 @@ static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, | |||
124 | } | 67 | } |
125 | 68 | ||
126 | static struct regulator_ops wm8994_ldo2_ops = { | 69 | static struct regulator_ops wm8994_ldo2_ops = { |
127 | .enable = wm8994_ldo_enable, | ||
128 | .disable = wm8994_ldo_disable, | ||
129 | .is_enabled = wm8994_ldo_is_enabled, | ||
130 | .enable_time = wm8994_ldo_enable_time, | ||
131 | |||
132 | .list_voltage = wm8994_ldo2_list_voltage, | 70 | .list_voltage = wm8994_ldo2_list_voltage, |
133 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 71 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
134 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 72 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
@@ -143,6 +81,9 @@ static const struct regulator_desc wm8994_ldo_desc[] = { | |||
143 | .vsel_reg = WM8994_LDO_1, | 81 | .vsel_reg = WM8994_LDO_1, |
144 | .vsel_mask = WM8994_LDO1_VSEL_MASK, | 82 | .vsel_mask = WM8994_LDO1_VSEL_MASK, |
145 | .ops = &wm8994_ldo1_ops, | 83 | .ops = &wm8994_ldo1_ops, |
84 | .min_uV = 2400000, | ||
85 | .uV_step = 100000, | ||
86 | .enable_time = 3000, | ||
146 | .owner = THIS_MODULE, | 87 | .owner = THIS_MODULE, |
147 | }, | 88 | }, |
148 | { | 89 | { |
@@ -153,6 +94,7 @@ static const struct regulator_desc wm8994_ldo_desc[] = { | |||
153 | .vsel_reg = WM8994_LDO_2, | 94 | .vsel_reg = WM8994_LDO_2, |
154 | .vsel_mask = WM8994_LDO2_VSEL_MASK, | 95 | .vsel_mask = WM8994_LDO2_VSEL_MASK, |
155 | .ops = &wm8994_ldo2_ops, | 96 | .ops = &wm8994_ldo2_ops, |
97 | .enable_time = 3000, | ||
156 | .owner = THIS_MODULE, | 98 | .owner = THIS_MODULE, |
157 | }, | 99 | }, |
158 | }; | 100 | }; |
@@ -176,39 +118,26 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev) | |||
176 | 118 | ||
177 | ldo->wm8994 = wm8994; | 119 | ldo->wm8994 = wm8994; |
178 | 120 | ||
179 | if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { | ||
180 | ldo->enable = pdata->ldo[id].enable; | ||
181 | |||
182 | ret = gpio_request_one(ldo->enable, 0, "WM8994 LDO enable"); | ||
183 | if (ret < 0) { | ||
184 | dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n", | ||
185 | ret); | ||
186 | goto err; | ||
187 | } | ||
188 | } else | ||
189 | ldo->is_enabled = true; | ||
190 | |||
191 | config.dev = wm8994->dev; | 121 | config.dev = wm8994->dev; |
192 | config.driver_data = ldo; | 122 | config.driver_data = ldo; |
193 | config.regmap = wm8994->regmap; | 123 | config.regmap = wm8994->regmap; |
194 | if (pdata) | 124 | if (pdata) { |
195 | config.init_data = pdata->ldo[id].init_data; | 125 | config.init_data = pdata->ldo[id].init_data; |
126 | config.ena_gpio = pdata->ldo[id].enable; | ||
127 | } | ||
196 | 128 | ||
197 | ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); | 129 | ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); |
198 | if (IS_ERR(ldo->regulator)) { | 130 | if (IS_ERR(ldo->regulator)) { |
199 | ret = PTR_ERR(ldo->regulator); | 131 | ret = PTR_ERR(ldo->regulator); |
200 | dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", | 132 | dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", |
201 | id + 1, ret); | 133 | id + 1, ret); |
202 | goto err_gpio; | 134 | goto err; |
203 | } | 135 | } |
204 | 136 | ||
205 | platform_set_drvdata(pdev, ldo); | 137 | platform_set_drvdata(pdev, ldo); |
206 | 138 | ||
207 | return 0; | 139 | return 0; |
208 | 140 | ||
209 | err_gpio: | ||
210 | if (gpio_is_valid(ldo->enable)) | ||
211 | gpio_free(ldo->enable); | ||
212 | err: | 141 | err: |
213 | return ret; | 142 | return ret; |
214 | } | 143 | } |
@@ -220,8 +149,6 @@ static __devexit int wm8994_ldo_remove(struct platform_device *pdev) | |||
220 | platform_set_drvdata(pdev, NULL); | 149 | platform_set_drvdata(pdev, NULL); |
221 | 150 | ||
222 | regulator_unregister(ldo->regulator); | 151 | regulator_unregister(ldo->regulator); |
223 | if (gpio_is_valid(ldo->enable)) | ||
224 | gpio_free(ldo->enable); | ||
225 | 152 | ||
226 | return 0; | 153 | return 0; |
227 | } | 154 | } |