diff options
Diffstat (limited to 'drivers/regulator/mc13783-regulator.c')
-rw-r--r-- | drivers/regulator/mc13783-regulator.c | 385 |
1 files changed, 76 insertions, 309 deletions
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index ecd99f59dba..3e5d0c3b4e5 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Regulator Driver for Freescale MC13783 PMIC | 2 | * Regulator Driver for Freescale MC13783 PMIC |
3 | * | 3 | * |
4 | * Copyright 2010 Yong Shen <yong.shen@linaro.org> | ||
4 | * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | 5 | * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
5 | * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> | 6 | * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> |
6 | * | 7 | * |
@@ -17,6 +18,7 @@ | |||
17 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
18 | #include <linux/init.h> | 19 | #include <linux/init.h> |
19 | #include <linux/err.h> | 20 | #include <linux/err.h> |
21 | #include "mc13xxx.h" | ||
20 | 22 | ||
21 | #define MC13783_REG_SWITCHERS5 29 | 23 | #define MC13783_REG_SWITCHERS5 29 |
22 | #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) | 24 | #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) |
@@ -89,154 +91,106 @@ | |||
89 | #define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15) | 91 | #define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15) |
90 | 92 | ||
91 | 93 | ||
92 | struct mc13783_regulator { | ||
93 | struct regulator_desc desc; | ||
94 | int reg; | ||
95 | int enable_bit; | ||
96 | int vsel_reg; | ||
97 | int vsel_shift; | ||
98 | int vsel_mask; | ||
99 | int const *voltages; | ||
100 | }; | ||
101 | |||
102 | /* Voltage Values */ | 94 | /* Voltage Values */ |
103 | static const int const mc13783_sw3_val[] = { | 95 | static const int mc13783_sw3_val[] = { |
104 | 5000000, 5000000, 5000000, 5500000, | 96 | 5000000, 5000000, 5000000, 5500000, |
105 | }; | 97 | }; |
106 | 98 | ||
107 | static const int const mc13783_vaudio_val[] = { | 99 | static const int mc13783_vaudio_val[] = { |
108 | 2775000, | 100 | 2775000, |
109 | }; | 101 | }; |
110 | 102 | ||
111 | static const int const mc13783_viohi_val[] = { | 103 | static const int mc13783_viohi_val[] = { |
112 | 2775000, | 104 | 2775000, |
113 | }; | 105 | }; |
114 | 106 | ||
115 | static const int const mc13783_violo_val[] = { | 107 | static const int mc13783_violo_val[] = { |
116 | 1200000, 1300000, 1500000, 1800000, | 108 | 1200000, 1300000, 1500000, 1800000, |
117 | }; | 109 | }; |
118 | 110 | ||
119 | static const int const mc13783_vdig_val[] = { | 111 | static const int mc13783_vdig_val[] = { |
120 | 1200000, 1300000, 1500000, 1800000, | 112 | 1200000, 1300000, 1500000, 1800000, |
121 | }; | 113 | }; |
122 | 114 | ||
123 | static const int const mc13783_vgen_val[] = { | 115 | static const int mc13783_vgen_val[] = { |
124 | 1200000, 1300000, 1500000, 1800000, | 116 | 1200000, 1300000, 1500000, 1800000, |
125 | 1100000, 2000000, 2775000, 2400000, | 117 | 1100000, 2000000, 2775000, 2400000, |
126 | }; | 118 | }; |
127 | 119 | ||
128 | static const int const mc13783_vrfdig_val[] = { | 120 | static const int mc13783_vrfdig_val[] = { |
129 | 1200000, 1500000, 1800000, 1875000, | 121 | 1200000, 1500000, 1800000, 1875000, |
130 | }; | 122 | }; |
131 | 123 | ||
132 | static const int const mc13783_vrfref_val[] = { | 124 | static const int mc13783_vrfref_val[] = { |
133 | 2475000, 2600000, 2700000, 2775000, | 125 | 2475000, 2600000, 2700000, 2775000, |
134 | }; | 126 | }; |
135 | 127 | ||
136 | static const int const mc13783_vrfcp_val[] = { | 128 | static const int mc13783_vrfcp_val[] = { |
137 | 2700000, 2775000, | 129 | 2700000, 2775000, |
138 | }; | 130 | }; |
139 | 131 | ||
140 | static const int const mc13783_vsim_val[] = { | 132 | static const int mc13783_vsim_val[] = { |
141 | 1800000, 2900000, 3000000, | 133 | 1800000, 2900000, 3000000, |
142 | }; | 134 | }; |
143 | 135 | ||
144 | static const int const mc13783_vesim_val[] = { | 136 | static const int mc13783_vesim_val[] = { |
145 | 1800000, 2900000, | 137 | 1800000, 2900000, |
146 | }; | 138 | }; |
147 | 139 | ||
148 | static const int const mc13783_vcam_val[] = { | 140 | static const int mc13783_vcam_val[] = { |
149 | 1500000, 1800000, 2500000, 2550000, | 141 | 1500000, 1800000, 2500000, 2550000, |
150 | 2600000, 2750000, 2800000, 3000000, | 142 | 2600000, 2750000, 2800000, 3000000, |
151 | }; | 143 | }; |
152 | 144 | ||
153 | static const int const mc13783_vrfbg_val[] = { | 145 | static const int mc13783_vrfbg_val[] = { |
154 | 1250000, | 146 | 1250000, |
155 | }; | 147 | }; |
156 | 148 | ||
157 | static const int const mc13783_vvib_val[] = { | 149 | static const int mc13783_vvib_val[] = { |
158 | 1300000, 1800000, 2000000, 3000000, | 150 | 1300000, 1800000, 2000000, 3000000, |
159 | }; | 151 | }; |
160 | 152 | ||
161 | static const int const mc13783_vmmc_val[] = { | 153 | static const int mc13783_vmmc_val[] = { |
162 | 1600000, 1800000, 2000000, 2600000, | 154 | 1600000, 1800000, 2000000, 2600000, |
163 | 2700000, 2800000, 2900000, 3000000, | 155 | 2700000, 2800000, 2900000, 3000000, |
164 | }; | 156 | }; |
165 | 157 | ||
166 | static const int const mc13783_vrf_val[] = { | 158 | static const int mc13783_vrf_val[] = { |
167 | 1500000, 1875000, 2700000, 2775000, | 159 | 1500000, 1875000, 2700000, 2775000, |
168 | }; | 160 | }; |
169 | 161 | ||
170 | static const int const mc13783_gpo_val[] = { | 162 | static const int mc13783_gpo_val[] = { |
171 | 3100000, | 163 | 3100000, |
172 | }; | 164 | }; |
173 | 165 | ||
174 | static const int const mc13783_pwgtdrv_val[] = { | 166 | static const int mc13783_pwgtdrv_val[] = { |
175 | 5500000, | 167 | 5500000, |
176 | }; | 168 | }; |
177 | 169 | ||
178 | static struct regulator_ops mc13783_regulator_ops; | ||
179 | static struct regulator_ops mc13783_fixed_regulator_ops; | ||
180 | static struct regulator_ops mc13783_gpo_regulator_ops; | 170 | static struct regulator_ops mc13783_gpo_regulator_ops; |
181 | 171 | ||
182 | #define MC13783_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages) \ | 172 | #define MC13783_DEFINE(prefix, name, reg, vsel_reg, voltages) \ |
183 | [MC13783_ ## prefix ## _ ## _name] = { \ | 173 | MC13xxx_DEFINE(MC13783_REG_, name, reg, vsel_reg, voltages, \ |
184 | .desc = { \ | 174 | mc13xxx_regulator_ops) |
185 | .name = #prefix "_" #_name, \ | ||
186 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
187 | .ops = &mc13783_regulator_ops, \ | ||
188 | .type = REGULATOR_VOLTAGE, \ | ||
189 | .id = MC13783_ ## prefix ## _ ## _name, \ | ||
190 | .owner = THIS_MODULE, \ | ||
191 | }, \ | ||
192 | .reg = MC13783_REG_ ## _reg, \ | ||
193 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | ||
194 | .vsel_reg = MC13783_REG_ ## _vsel_reg, \ | ||
195 | .vsel_shift = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL,\ | ||
196 | .vsel_mask = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL_M,\ | ||
197 | .voltages = _voltages, \ | ||
198 | } | ||
199 | 175 | ||
200 | #define MC13783_FIXED_DEFINE(prefix, _name, _reg, _voltages) \ | 176 | #define MC13783_FIXED_DEFINE(prefix, name, reg, voltages) \ |
201 | [MC13783_ ## prefix ## _ ## _name] = { \ | 177 | MC13xxx_FIXED_DEFINE(MC13783_REG_, name, reg, voltages, \ |
202 | .desc = { \ | 178 | mc13xxx_fixed_regulator_ops) |
203 | .name = #prefix "_" #_name, \ | ||
204 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
205 | .ops = &mc13783_fixed_regulator_ops, \ | ||
206 | .type = REGULATOR_VOLTAGE, \ | ||
207 | .id = MC13783_ ## prefix ## _ ## _name, \ | ||
208 | .owner = THIS_MODULE, \ | ||
209 | }, \ | ||
210 | .reg = MC13783_REG_ ## _reg, \ | ||
211 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | ||
212 | .voltages = _voltages, \ | ||
213 | } | ||
214 | 179 | ||
215 | #define MC13783_GPO_DEFINE(prefix, _name, _reg, _voltages) \ | 180 | #define MC13783_GPO_DEFINE(prefix, name, reg, voltages) \ |
216 | [MC13783_ ## prefix ## _ ## _name] = { \ | 181 | MC13xxx_GPO_DEFINE(MC13783_REG_, name, reg, voltages, \ |
217 | .desc = { \ | 182 | mc13783_gpo_regulator_ops) |
218 | .name = #prefix "_" #_name, \ | ||
219 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
220 | .ops = &mc13783_gpo_regulator_ops, \ | ||
221 | .type = REGULATOR_VOLTAGE, \ | ||
222 | .id = MC13783_ ## prefix ## _ ## _name, \ | ||
223 | .owner = THIS_MODULE, \ | ||
224 | }, \ | ||
225 | .reg = MC13783_REG_ ## _reg, \ | ||
226 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | ||
227 | .voltages = _voltages, \ | ||
228 | } | ||
229 | 183 | ||
230 | #define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \ | 184 | #define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \ |
231 | MC13783_DEFINE(SW, _name, _reg, _vsel_reg, _voltages) | 185 | MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages) |
232 | #define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \ | 186 | #define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \ |
233 | MC13783_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages) | 187 | MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages) |
234 | 188 | ||
235 | static struct mc13783_regulator mc13783_regulators[] = { | 189 | static struct mc13xxx_regulator mc13783_regulators[] = { |
236 | MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), | 190 | MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), |
237 | 191 | ||
238 | MC13783_FIXED_DEFINE(REGU, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), | 192 | MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), |
239 | MC13783_FIXED_DEFINE(REGU, VIOHI, REGULATORMODE0, mc13783_viohi_val), | 193 | MC13783_FIXED_DEFINE(REG, VIOHI, REGULATORMODE0, mc13783_viohi_val), |
240 | MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ | 194 | MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ |
241 | mc13783_violo_val), | 195 | mc13783_violo_val), |
242 | MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ | 196 | MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ |
@@ -255,7 +209,7 @@ static struct mc13783_regulator mc13783_regulators[] = { | |||
255 | mc13783_vesim_val), | 209 | mc13783_vesim_val), |
256 | MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ | 210 | MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ |
257 | mc13783_vcam_val), | 211 | mc13783_vcam_val), |
258 | MC13783_FIXED_DEFINE(REGU, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), | 212 | MC13783_FIXED_DEFINE(REG, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), |
259 | MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ | 213 | MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ |
260 | mc13783_vvib_val), | 214 | mc13783_vvib_val), |
261 | MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ | 215 | MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ |
@@ -266,215 +220,24 @@ static struct mc13783_regulator mc13783_regulators[] = { | |||
266 | mc13783_vmmc_val), | 220 | mc13783_vmmc_val), |
267 | MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ | 221 | MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ |
268 | mc13783_vmmc_val), | 222 | mc13783_vmmc_val), |
269 | MC13783_GPO_DEFINE(REGU, GPO1, POWERMISC, mc13783_gpo_val), | 223 | MC13783_GPO_DEFINE(REG, GPO1, POWERMISC, mc13783_gpo_val), |
270 | MC13783_GPO_DEFINE(REGU, GPO2, POWERMISC, mc13783_gpo_val), | 224 | MC13783_GPO_DEFINE(REG, GPO2, POWERMISC, mc13783_gpo_val), |
271 | MC13783_GPO_DEFINE(REGU, GPO3, POWERMISC, mc13783_gpo_val), | 225 | MC13783_GPO_DEFINE(REG, GPO3, POWERMISC, mc13783_gpo_val), |
272 | MC13783_GPO_DEFINE(REGU, GPO4, POWERMISC, mc13783_gpo_val), | 226 | MC13783_GPO_DEFINE(REG, GPO4, POWERMISC, mc13783_gpo_val), |
273 | MC13783_GPO_DEFINE(REGU, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val), | 227 | MC13783_GPO_DEFINE(REG, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val), |
274 | MC13783_GPO_DEFINE(REGU, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val), | 228 | MC13783_GPO_DEFINE(REG, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val), |
275 | }; | ||
276 | |||
277 | struct mc13783_regulator_priv { | ||
278 | struct mc13783 *mc13783; | ||
279 | u32 powermisc_pwgt_state; | ||
280 | struct regulator_dev *regulators[]; | ||
281 | }; | ||
282 | |||
283 | static int mc13783_regulator_enable(struct regulator_dev *rdev) | ||
284 | { | ||
285 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
286 | int id = rdev_get_id(rdev); | ||
287 | int ret; | ||
288 | |||
289 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
290 | |||
291 | mc13783_lock(priv->mc13783); | ||
292 | ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg, | ||
293 | mc13783_regulators[id].enable_bit, | ||
294 | mc13783_regulators[id].enable_bit); | ||
295 | mc13783_unlock(priv->mc13783); | ||
296 | |||
297 | return ret; | ||
298 | } | ||
299 | |||
300 | static int mc13783_regulator_disable(struct regulator_dev *rdev) | ||
301 | { | ||
302 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
303 | int id = rdev_get_id(rdev); | ||
304 | int ret; | ||
305 | |||
306 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
307 | |||
308 | mc13783_lock(priv->mc13783); | ||
309 | ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg, | ||
310 | mc13783_regulators[id].enable_bit, 0); | ||
311 | mc13783_unlock(priv->mc13783); | ||
312 | |||
313 | return ret; | ||
314 | } | ||
315 | |||
316 | static int mc13783_regulator_is_enabled(struct regulator_dev *rdev) | ||
317 | { | ||
318 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
319 | int ret, id = rdev_get_id(rdev); | ||
320 | unsigned int val; | ||
321 | |||
322 | mc13783_lock(priv->mc13783); | ||
323 | ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); | ||
324 | mc13783_unlock(priv->mc13783); | ||
325 | |||
326 | if (ret) | ||
327 | return ret; | ||
328 | |||
329 | return (val & mc13783_regulators[id].enable_bit) != 0; | ||
330 | } | ||
331 | |||
332 | static int mc13783_regulator_list_voltage(struct regulator_dev *rdev, | ||
333 | unsigned selector) | ||
334 | { | ||
335 | int id = rdev_get_id(rdev); | ||
336 | |||
337 | if (selector >= mc13783_regulators[id].desc.n_voltages) | ||
338 | return -EINVAL; | ||
339 | |||
340 | return mc13783_regulators[id].voltages[selector]; | ||
341 | } | ||
342 | |||
343 | static int mc13783_get_best_voltage_index(struct regulator_dev *rdev, | ||
344 | int min_uV, int max_uV) | ||
345 | { | ||
346 | int reg_id = rdev_get_id(rdev); | ||
347 | int i; | ||
348 | int bestmatch; | ||
349 | int bestindex; | ||
350 | |||
351 | /* | ||
352 | * Locate the minimum voltage fitting the criteria on | ||
353 | * this regulator. The switchable voltages are not | ||
354 | * in strict falling order so we need to check them | ||
355 | * all for the best match. | ||
356 | */ | ||
357 | bestmatch = INT_MAX; | ||
358 | bestindex = -1; | ||
359 | for (i = 0; i < mc13783_regulators[reg_id].desc.n_voltages; i++) { | ||
360 | if (mc13783_regulators[reg_id].voltages[i] >= min_uV && | ||
361 | mc13783_regulators[reg_id].voltages[i] < bestmatch) { | ||
362 | bestmatch = mc13783_regulators[reg_id].voltages[i]; | ||
363 | bestindex = i; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | if (bestindex < 0 || bestmatch > max_uV) { | ||
368 | dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n", | ||
369 | min_uV, max_uV); | ||
370 | return -EINVAL; | ||
371 | } | ||
372 | return bestindex; | ||
373 | } | ||
374 | |||
375 | static int mc13783_regulator_set_voltage(struct regulator_dev *rdev, | ||
376 | int min_uV, int max_uV) | ||
377 | { | ||
378 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
379 | int value, id = rdev_get_id(rdev); | ||
380 | int ret; | ||
381 | |||
382 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | ||
383 | __func__, id, min_uV, max_uV); | ||
384 | |||
385 | /* Find the best index */ | ||
386 | value = mc13783_get_best_voltage_index(rdev, min_uV, max_uV); | ||
387 | dev_dbg(rdev_get_dev(rdev), "%s best value: %d \n", __func__, value); | ||
388 | if (value < 0) | ||
389 | return value; | ||
390 | |||
391 | mc13783_lock(priv->mc13783); | ||
392 | ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].vsel_reg, | ||
393 | mc13783_regulators[id].vsel_mask, | ||
394 | value << mc13783_regulators[id].vsel_shift); | ||
395 | mc13783_unlock(priv->mc13783); | ||
396 | |||
397 | return ret; | ||
398 | } | ||
399 | |||
400 | static int mc13783_regulator_get_voltage(struct regulator_dev *rdev) | ||
401 | { | ||
402 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
403 | int ret, id = rdev_get_id(rdev); | ||
404 | unsigned int val; | ||
405 | |||
406 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
407 | |||
408 | mc13783_lock(priv->mc13783); | ||
409 | ret = mc13783_reg_read(priv->mc13783, | ||
410 | mc13783_regulators[id].vsel_reg, &val); | ||
411 | mc13783_unlock(priv->mc13783); | ||
412 | |||
413 | if (ret) | ||
414 | return ret; | ||
415 | |||
416 | val = (val & mc13783_regulators[id].vsel_mask) | ||
417 | >> mc13783_regulators[id].vsel_shift; | ||
418 | |||
419 | dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); | ||
420 | |||
421 | BUG_ON(val < 0 || val > mc13783_regulators[id].desc.n_voltages); | ||
422 | |||
423 | return mc13783_regulators[id].voltages[val]; | ||
424 | } | ||
425 | |||
426 | static struct regulator_ops mc13783_regulator_ops = { | ||
427 | .enable = mc13783_regulator_enable, | ||
428 | .disable = mc13783_regulator_disable, | ||
429 | .is_enabled = mc13783_regulator_is_enabled, | ||
430 | .list_voltage = mc13783_regulator_list_voltage, | ||
431 | .set_voltage = mc13783_regulator_set_voltage, | ||
432 | .get_voltage = mc13783_regulator_get_voltage, | ||
433 | }; | ||
434 | |||
435 | static int mc13783_fixed_regulator_set_voltage(struct regulator_dev *rdev, | ||
436 | int min_uV, int max_uV) | ||
437 | { | ||
438 | int id = rdev_get_id(rdev); | ||
439 | |||
440 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | ||
441 | __func__, id, min_uV, max_uV); | ||
442 | |||
443 | if (min_uV >= mc13783_regulators[id].voltages[0] && | ||
444 | max_uV <= mc13783_regulators[id].voltages[0]) | ||
445 | return 0; | ||
446 | else | ||
447 | return -EINVAL; | ||
448 | } | ||
449 | |||
450 | static int mc13783_fixed_regulator_get_voltage(struct regulator_dev *rdev) | ||
451 | { | ||
452 | int id = rdev_get_id(rdev); | ||
453 | |||
454 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
455 | |||
456 | return mc13783_regulators[id].voltages[0]; | ||
457 | } | ||
458 | |||
459 | static struct regulator_ops mc13783_fixed_regulator_ops = { | ||
460 | .enable = mc13783_regulator_enable, | ||
461 | .disable = mc13783_regulator_disable, | ||
462 | .is_enabled = mc13783_regulator_is_enabled, | ||
463 | .list_voltage = mc13783_regulator_list_voltage, | ||
464 | .set_voltage = mc13783_fixed_regulator_set_voltage, | ||
465 | .get_voltage = mc13783_fixed_regulator_get_voltage, | ||
466 | }; | 229 | }; |
467 | 230 | ||
468 | static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, | 231 | static int mc13783_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask, |
469 | u32 val) | 232 | u32 val) |
470 | { | 233 | { |
471 | struct mc13783 *mc13783 = priv->mc13783; | 234 | struct mc13xxx *mc13783 = priv->mc13xxx; |
472 | int ret; | 235 | int ret; |
473 | u32 valread; | 236 | u32 valread; |
474 | 237 | ||
475 | BUG_ON(val & ~mask); | 238 | BUG_ON(val & ~mask); |
476 | 239 | ||
477 | ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); | 240 | ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); |
478 | if (ret) | 241 | if (ret) |
479 | return ret; | 242 | return ret; |
480 | 243 | ||
@@ -489,34 +252,36 @@ static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, | |||
489 | valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | | 252 | valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | |
490 | priv->powermisc_pwgt_state; | 253 | priv->powermisc_pwgt_state; |
491 | 254 | ||
492 | return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread); | 255 | return mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread); |
493 | } | 256 | } |
494 | 257 | ||
495 | static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) | 258 | static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) |
496 | { | 259 | { |
497 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | 260 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
261 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
498 | int id = rdev_get_id(rdev); | 262 | int id = rdev_get_id(rdev); |
499 | int ret; | 263 | int ret; |
500 | u32 en_val = mc13783_regulators[id].enable_bit; | 264 | u32 en_val = mc13xxx_regulators[id].enable_bit; |
501 | 265 | ||
502 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | 266 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); |
503 | 267 | ||
504 | /* Power Gate enable value is 0 */ | 268 | /* Power Gate enable value is 0 */ |
505 | if (id == MC13783_REGU_PWGT1SPI || | 269 | if (id == MC13783_REG_PWGT1SPI || |
506 | id == MC13783_REGU_PWGT2SPI) | 270 | id == MC13783_REG_PWGT2SPI) |
507 | en_val = 0; | 271 | en_val = 0; |
508 | 272 | ||
509 | mc13783_lock(priv->mc13783); | 273 | mc13xxx_lock(priv->mc13xxx); |
510 | ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, | 274 | ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, |
511 | en_val); | 275 | en_val); |
512 | mc13783_unlock(priv->mc13783); | 276 | mc13xxx_unlock(priv->mc13xxx); |
513 | 277 | ||
514 | return ret; | 278 | return ret; |
515 | } | 279 | } |
516 | 280 | ||
517 | static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) | 281 | static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) |
518 | { | 282 | { |
519 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | 283 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
284 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
520 | int id = rdev_get_id(rdev); | 285 | int id = rdev_get_id(rdev); |
521 | int ret; | 286 | int ret; |
522 | u32 dis_val = 0; | 287 | u32 dis_val = 0; |
@@ -524,27 +289,28 @@ static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) | |||
524 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | 289 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); |
525 | 290 | ||
526 | /* Power Gate disable value is 1 */ | 291 | /* Power Gate disable value is 1 */ |
527 | if (id == MC13783_REGU_PWGT1SPI || | 292 | if (id == MC13783_REG_PWGT1SPI || |
528 | id == MC13783_REGU_PWGT2SPI) | 293 | id == MC13783_REG_PWGT2SPI) |
529 | dis_val = mc13783_regulators[id].enable_bit; | 294 | dis_val = mc13xxx_regulators[id].enable_bit; |
530 | 295 | ||
531 | mc13783_lock(priv->mc13783); | 296 | mc13xxx_lock(priv->mc13xxx); |
532 | ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, | 297 | ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit, |
533 | dis_val); | 298 | dis_val); |
534 | mc13783_unlock(priv->mc13783); | 299 | mc13xxx_unlock(priv->mc13xxx); |
535 | 300 | ||
536 | return ret; | 301 | return ret; |
537 | } | 302 | } |
538 | 303 | ||
539 | static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) | 304 | static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) |
540 | { | 305 | { |
541 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | 306 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
307 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
542 | int ret, id = rdev_get_id(rdev); | 308 | int ret, id = rdev_get_id(rdev); |
543 | unsigned int val; | 309 | unsigned int val; |
544 | 310 | ||
545 | mc13783_lock(priv->mc13783); | 311 | mc13xxx_lock(priv->mc13xxx); |
546 | ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); | 312 | ret = mc13xxx_reg_read(priv->mc13xxx, mc13xxx_regulators[id].reg, &val); |
547 | mc13783_unlock(priv->mc13783); | 313 | mc13xxx_unlock(priv->mc13xxx); |
548 | 314 | ||
549 | if (ret) | 315 | if (ret) |
550 | return ret; | 316 | return ret; |
@@ -554,22 +320,22 @@ static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) | |||
554 | val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) | | 320 | val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) | |
555 | (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M); | 321 | (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M); |
556 | 322 | ||
557 | return (val & mc13783_regulators[id].enable_bit) != 0; | 323 | return (val & mc13xxx_regulators[id].enable_bit) != 0; |
558 | } | 324 | } |
559 | 325 | ||
560 | static struct regulator_ops mc13783_gpo_regulator_ops = { | 326 | static struct regulator_ops mc13783_gpo_regulator_ops = { |
561 | .enable = mc13783_gpo_regulator_enable, | 327 | .enable = mc13783_gpo_regulator_enable, |
562 | .disable = mc13783_gpo_regulator_disable, | 328 | .disable = mc13783_gpo_regulator_disable, |
563 | .is_enabled = mc13783_gpo_regulator_is_enabled, | 329 | .is_enabled = mc13783_gpo_regulator_is_enabled, |
564 | .list_voltage = mc13783_regulator_list_voltage, | 330 | .list_voltage = mc13xxx_regulator_list_voltage, |
565 | .set_voltage = mc13783_fixed_regulator_set_voltage, | 331 | .set_voltage = mc13xxx_fixed_regulator_set_voltage, |
566 | .get_voltage = mc13783_fixed_regulator_get_voltage, | 332 | .get_voltage = mc13xxx_fixed_regulator_get_voltage, |
567 | }; | 333 | }; |
568 | 334 | ||
569 | static int __devinit mc13783_regulator_probe(struct platform_device *pdev) | 335 | static int __devinit mc13783_regulator_probe(struct platform_device *pdev) |
570 | { | 336 | { |
571 | struct mc13783_regulator_priv *priv; | 337 | struct mc13xxx_regulator_priv *priv; |
572 | struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent); | 338 | struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent); |
573 | struct mc13783_regulator_platform_data *pdata = | 339 | struct mc13783_regulator_platform_data *pdata = |
574 | dev_get_platdata(&pdev->dev); | 340 | dev_get_platdata(&pdev->dev); |
575 | struct mc13783_regulator_init_data *init_data; | 341 | struct mc13783_regulator_init_data *init_data; |
@@ -583,7 +349,8 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev) | |||
583 | if (!priv) | 349 | if (!priv) |
584 | return -ENOMEM; | 350 | return -ENOMEM; |
585 | 351 | ||
586 | priv->mc13783 = mc13783; | 352 | priv->mc13xxx_regulators = mc13783_regulators; |
353 | priv->mc13xxx = mc13783; | ||
587 | 354 | ||
588 | for (i = 0; i < pdata->num_regulators; i++) { | 355 | for (i = 0; i < pdata->num_regulators; i++) { |
589 | init_data = &pdata->regulators[i]; | 356 | init_data = &pdata->regulators[i]; |
@@ -613,7 +380,7 @@ err: | |||
613 | 380 | ||
614 | static int __devexit mc13783_regulator_remove(struct platform_device *pdev) | 381 | static int __devexit mc13783_regulator_remove(struct platform_device *pdev) |
615 | { | 382 | { |
616 | struct mc13783_regulator_priv *priv = platform_get_drvdata(pdev); | 383 | struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); |
617 | struct mc13783_regulator_platform_data *pdata = | 384 | struct mc13783_regulator_platform_data *pdata = |
618 | dev_get_platdata(&pdev->dev); | 385 | dev_get_platdata(&pdev->dev); |
619 | int i; | 386 | int i; |