aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-05-14 22:04:23 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-05-15 13:32:57 -0400
commit70b4e7862d604aa6ae30a772830670bf7288ec42 (patch)
tree7a1bebaf848f1df17df49696a9cd3a8d1cf20966
parent9a00630c3db8ca064a8904dbcd9632fb81244bc0 (diff)
regulator: da903x: Convert to regulator_list_voltage_linear()
Use regulator_list_voltage_linear() to replace da903x_list_voltage(). Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/da903x.c54
1 files changed, 21 insertions, 33 deletions
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index c75e7b7a61b3..3a0d0800374e 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -76,9 +76,7 @@
76struct da903x_regulator_info { 76struct da903x_regulator_info {
77 struct regulator_desc desc; 77 struct regulator_desc desc;
78 78
79 int min_uV;
80 int max_uV; 79 int max_uV;
81 int step_uV;
82 int vol_reg; 80 int vol_reg;
83 int vol_shift; 81 int vol_shift;
84 int vol_nbits; 82 int vol_nbits;
@@ -96,7 +94,7 @@ static inline struct device *to_da903x_dev(struct regulator_dev *rdev)
96static inline int check_range(struct da903x_regulator_info *info, 94static inline int check_range(struct da903x_regulator_info *info,
97 int min_uV, int max_uV) 95 int min_uV, int max_uV)
98{ 96{
99 if (min_uV < info->min_uV || min_uV > info->max_uV) 97 if (min_uV < info->desc.min_uV || min_uV > info->max_uV)
100 return -EINVAL; 98 return -EINVAL;
101 99
102 return 0; 100 return 0;
@@ -115,7 +113,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
115 return -EINVAL; 113 return -EINVAL;
116 } 114 }
117 115
118 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 116 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
119 *selector = val; 117 *selector = val;
120 val <<= info->vol_shift; 118 val <<= info->vol_shift;
121 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 119 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -172,17 +170,6 @@ static int da903x_is_enabled(struct regulator_dev *rdev)
172 return !!(reg_val & (1 << info->enable_bit)); 170 return !!(reg_val & (1 << info->enable_bit));
173} 171}
174 172
175static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
176{
177 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
178 int ret;
179
180 ret = info->min_uV + info->step_uV * selector;
181 if (ret > info->max_uV)
182 return -EINVAL;
183 return ret;
184}
185
186/* DA9030 specific operations */ 173/* DA9030 specific operations */
187static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, 174static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
188 int min_uV, int max_uV, 175 int min_uV, int max_uV,
@@ -198,7 +185,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
198 return -EINVAL; 185 return -EINVAL;
199 } 186 }
200 187
201 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 188 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
202 *selector = val; 189 *selector = val;
203 val <<= info->vol_shift; 190 val <<= info->vol_shift;
204 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 191 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -227,12 +214,12 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
227 return -EINVAL; 214 return -EINVAL;
228 } 215 }
229 216
230 thresh = (info->max_uV + info->min_uV) / 2; 217 thresh = (info->max_uV + info->desc.min_uV) / 2;
231 if (min_uV < thresh) { 218 if (min_uV < thresh) {
232 val = DIV_ROUND_UP(thresh - min_uV, info->step_uV); 219 val = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step);
233 val |= 0x4; 220 val |= 0x4;
234 } else { 221 } else {
235 val = DIV_ROUND_UP(min_uV - thresh, info->step_uV); 222 val = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step);
236 } 223 }
237 224
238 *selector = val; 225 *selector = val;
@@ -266,10 +253,11 @@ static int da9030_list_ldo14_voltage(struct regulator_dev *rdev,
266 int volt; 253 int volt;
267 254
268 if (selector & 0x4) 255 if (selector & 0x4)
269 volt = info->min_uV + info->step_uV * (3 - (selector & ~0x4)); 256 volt = rdev->desc->min_uV +
257 rdev->desc->uV_step * (3 - (selector & ~0x4));
270 else 258 else
271 volt = (info->max_uV + info->min_uV) / 2 + 259 volt = (info->max_uV + rdev->desc->min_uV) / 2 +
272 info->step_uV * (selector & ~0x4); 260 rdev->desc->uV_step * (selector & ~0x4);
273 261
274 if (volt > info->max_uV) 262 if (volt > info->max_uV)
275 return -EINVAL; 263 return -EINVAL;
@@ -291,7 +279,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
291 return -EINVAL; 279 return -EINVAL;
292 } 280 }
293 281
294 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 282 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
295 *selector = val; 283 *selector = val;
296 val <<= info->vol_shift; 284 val <<= info->vol_shift;
297 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 285 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -317,7 +305,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
317 return -EINVAL; 305 return -EINVAL;
318 } 306 }
319 307
320 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); 308 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
321 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 309 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
322 *selector = val; 310 *selector = val;
323 val <<= info->vol_shift; 311 val <<= info->vol_shift;
@@ -350,9 +338,9 @@ static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
350 int volt; 338 int volt;
351 339
352 if (selector >= 8) 340 if (selector >= 8)
353 volt = 2700000 + info->step_uV * (selector - 8); 341 volt = 2700000 + rdev->desc->uV_step * (selector - 8);
354 else 342 else
355 volt = info->min_uV + info->step_uV * selector; 343 volt = rdev->desc->min_uV + rdev->desc->uV_step * selector;
356 344
357 if (volt > info->max_uV) 345 if (volt > info->max_uV)
358 return -EINVAL; 346 return -EINVAL;
@@ -363,7 +351,7 @@ static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
363static struct regulator_ops da903x_regulator_ldo_ops = { 351static struct regulator_ops da903x_regulator_ldo_ops = {
364 .set_voltage = da903x_set_ldo_voltage, 352 .set_voltage = da903x_set_ldo_voltage,
365 .get_voltage_sel = da903x_get_voltage_sel, 353 .get_voltage_sel = da903x_get_voltage_sel,
366 .list_voltage = da903x_list_voltage, 354 .list_voltage = regulator_list_voltage_linear,
367 .enable = da903x_enable, 355 .enable = da903x_enable,
368 .disable = da903x_disable, 356 .disable = da903x_disable,
369 .is_enabled = da903x_is_enabled, 357 .is_enabled = da903x_is_enabled,
@@ -383,7 +371,7 @@ static struct regulator_ops da9030_regulator_ldo14_ops = {
383static struct regulator_ops da9030_regulator_ldo1_15_ops = { 371static struct regulator_ops da9030_regulator_ldo1_15_ops = {
384 .set_voltage = da9030_set_ldo1_15_voltage, 372 .set_voltage = da9030_set_ldo1_15_voltage,
385 .get_voltage_sel = da903x_get_voltage_sel, 373 .get_voltage_sel = da903x_get_voltage_sel,
386 .list_voltage = da903x_list_voltage, 374 .list_voltage = regulator_list_voltage_linear,
387 .enable = da903x_enable, 375 .enable = da903x_enable,
388 .disable = da903x_disable, 376 .disable = da903x_disable,
389 .is_enabled = da903x_is_enabled, 377 .is_enabled = da903x_is_enabled,
@@ -392,7 +380,7 @@ static struct regulator_ops da9030_regulator_ldo1_15_ops = {
392static struct regulator_ops da9034_regulator_dvc_ops = { 380static struct regulator_ops da9034_regulator_dvc_ops = {
393 .set_voltage = da9034_set_dvc_voltage, 381 .set_voltage = da9034_set_dvc_voltage,
394 .get_voltage_sel = da903x_get_voltage_sel, 382 .get_voltage_sel = da903x_get_voltage_sel,
395 .list_voltage = da903x_list_voltage, 383 .list_voltage = regulator_list_voltage_linear,
396 .enable = da903x_enable, 384 .enable = da903x_enable,
397 .disable = da903x_disable, 385 .disable = da903x_disable,
398 .is_enabled = da903x_is_enabled, 386 .is_enabled = da903x_is_enabled,
@@ -417,10 +405,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = {
417 .id = _pmic##_ID_LDO##_id, \ 405 .id = _pmic##_ID_LDO##_id, \
418 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ 406 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
419 .owner = THIS_MODULE, \ 407 .owner = THIS_MODULE, \
408 .min_uV = (min) * 1000, \
409 .uV_step = (step) * 1000, \
420 }, \ 410 }, \
421 .min_uV = (min) * 1000, \
422 .max_uV = (max) * 1000, \ 411 .max_uV = (max) * 1000, \
423 .step_uV = (step) * 1000, \
424 .vol_reg = _pmic##_##vreg, \ 412 .vol_reg = _pmic##_##vreg, \
425 .vol_shift = (shift), \ 413 .vol_shift = (shift), \
426 .vol_nbits = (nbits), \ 414 .vol_nbits = (nbits), \
@@ -437,10 +425,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = {
437 .id = _pmic##_ID_##_id, \ 425 .id = _pmic##_ID_##_id, \
438 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ 426 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
439 .owner = THIS_MODULE, \ 427 .owner = THIS_MODULE, \
428 .min_uV = (min) * 1000, \
429 .uV_step = (step) * 1000, \
440 }, \ 430 }, \
441 .min_uV = (min) * 1000, \
442 .max_uV = (max) * 1000, \ 431 .max_uV = (max) * 1000, \
443 .step_uV = (step) * 1000, \
444 .vol_reg = _pmic##_##vreg, \ 432 .vol_reg = _pmic##_##vreg, \
445 .vol_shift = (0), \ 433 .vol_shift = (0), \
446 .vol_nbits = (nbits), \ 434 .vol_nbits = (nbits), \