aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-05-08 07:47:47 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-05-12 06:12:41 -0400
commit9447f35a1e7c27859212e8cea3c771720198b4bb (patch)
tree23ec10dfed60b5ae46ed148ab25210844df1bee4
parentd4eb56a16273a04f10eb7f959e1bb59b6f88d8c9 (diff)
regulator: da903x: Convert to get_voltage_sel
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/da903x.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index a9c4590061c1..c75e7b7a61b3 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -88,10 +88,6 @@ struct da903x_regulator_info {
88 int enable_bit; 88 int enable_bit;
89}; 89};
90 90
91static int da9034_ldo12_data[] = { 1700, 1750, 1800, 1850, 1900, 1950,
92 2000, 2050, 2700, 2750, 2800, 2850,
93 2900, 2950, 3000, 3050 };
94
95static inline struct device *to_da903x_dev(struct regulator_dev *rdev) 91static inline struct device *to_da903x_dev(struct regulator_dev *rdev)
96{ 92{
97 return rdev_get_dev(rdev)->parent->parent; 93 return rdev_get_dev(rdev)->parent->parent;
@@ -127,7 +123,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
127 return da903x_update(da9034_dev, info->vol_reg, val, mask); 123 return da903x_update(da9034_dev, info->vol_reg, val, mask);
128} 124}
129 125
130static int da903x_get_voltage(struct regulator_dev *rdev) 126static int da903x_get_voltage_sel(struct regulator_dev *rdev)
131{ 127{
132 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 128 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
133 struct device *da9034_dev = to_da903x_dev(rdev); 129 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -141,7 +137,7 @@ static int da903x_get_voltage(struct regulator_dev *rdev)
141 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 137 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
142 val = (val & mask) >> info->vol_shift; 138 val = (val & mask) >> info->vol_shift;
143 139
144 return info->min_uV + info->step_uV * val; 140 return val;
145} 141}
146 142
147static int da903x_enable(struct regulator_dev *rdev) 143static int da903x_enable(struct regulator_dev *rdev)
@@ -246,7 +242,7 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
246 return da903x_update(da903x_dev, info->vol_reg, val, mask); 242 return da903x_update(da903x_dev, info->vol_reg, val, mask);
247} 243}
248 244
249static int da9030_get_ldo14_voltage(struct regulator_dev *rdev) 245static int da9030_get_ldo14_voltage_sel(struct regulator_dev *rdev)
250{ 246{
251 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 247 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
252 struct device *da903x_dev = to_da903x_dev(rdev); 248 struct device *da903x_dev = to_da903x_dev(rdev);
@@ -260,11 +256,7 @@ static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
260 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 256 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
261 val = (val & mask) >> info->vol_shift; 257 val = (val & mask) >> info->vol_shift;
262 258
263 if (val & 0x4) 259 return val;
264 return info->min_uV + info->step_uV * (3 - (val & ~0x4));
265 else
266 return (info->max_uV + info->min_uV) / 2 +
267 info->step_uV * (val & ~0x4);
268} 260}
269 261
270static int da9030_list_ldo14_voltage(struct regulator_dev *rdev, 262static int da9030_list_ldo14_voltage(struct regulator_dev *rdev,
@@ -334,7 +326,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
334 return da903x_update(da9034_dev, info->vol_reg, val, mask); 326 return da903x_update(da9034_dev, info->vol_reg, val, mask);
335} 327}
336 328
337static int da9034_get_ldo12_voltage(struct regulator_dev *rdev) 329static int da9034_get_ldo12_voltage_sel(struct regulator_dev *rdev)
338{ 330{
339 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 331 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
340 struct device *da9034_dev = to_da903x_dev(rdev); 332 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -348,23 +340,29 @@ static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
348 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 340 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
349 val = (val & mask) >> info->vol_shift; 341 val = (val & mask) >> info->vol_shift;
350 342
351 if (val >= 8) 343 return val;
352 return 2700000 + info->step_uV * (val - 8);
353
354 return info->min_uV + info->step_uV * val;
355} 344}
356 345
357static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, 346static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
358 unsigned selector) 347 unsigned selector)
359{ 348{
360 if (selector >= ARRAY_SIZE(da9034_ldo12_data)) 349 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
350 int volt;
351
352 if (selector >= 8)
353 volt = 2700000 + info->step_uV * (selector - 8);
354 else
355 volt = info->min_uV + info->step_uV * selector;
356
357 if (volt > info->max_uV)
361 return -EINVAL; 358 return -EINVAL;
362 return da9034_ldo12_data[selector] * 1000; 359
360 return volt;
363} 361}
364 362
365static struct regulator_ops da903x_regulator_ldo_ops = { 363static struct regulator_ops da903x_regulator_ldo_ops = {
366 .set_voltage = da903x_set_ldo_voltage, 364 .set_voltage = da903x_set_ldo_voltage,
367 .get_voltage = da903x_get_voltage, 365 .get_voltage_sel = da903x_get_voltage_sel,
368 .list_voltage = da903x_list_voltage, 366 .list_voltage = da903x_list_voltage,
369 .enable = da903x_enable, 367 .enable = da903x_enable,
370 .disable = da903x_disable, 368 .disable = da903x_disable,
@@ -374,7 +372,7 @@ static struct regulator_ops da903x_regulator_ldo_ops = {
374/* NOTE: this is dedicated for the insane DA9030 LDO14 */ 372/* NOTE: this is dedicated for the insane DA9030 LDO14 */
375static struct regulator_ops da9030_regulator_ldo14_ops = { 373static struct regulator_ops da9030_regulator_ldo14_ops = {
376 .set_voltage = da9030_set_ldo14_voltage, 374 .set_voltage = da9030_set_ldo14_voltage,
377 .get_voltage = da9030_get_ldo14_voltage, 375 .get_voltage_sel = da9030_get_ldo14_voltage_sel,
378 .list_voltage = da9030_list_ldo14_voltage, 376 .list_voltage = da9030_list_ldo14_voltage,
379 .enable = da903x_enable, 377 .enable = da903x_enable,
380 .disable = da903x_disable, 378 .disable = da903x_disable,
@@ -384,7 +382,7 @@ static struct regulator_ops da9030_regulator_ldo14_ops = {
384/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ 382/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
385static struct regulator_ops da9030_regulator_ldo1_15_ops = { 383static struct regulator_ops da9030_regulator_ldo1_15_ops = {
386 .set_voltage = da9030_set_ldo1_15_voltage, 384 .set_voltage = da9030_set_ldo1_15_voltage,
387 .get_voltage = da903x_get_voltage, 385 .get_voltage_sel = da903x_get_voltage_sel,
388 .list_voltage = da903x_list_voltage, 386 .list_voltage = da903x_list_voltage,
389 .enable = da903x_enable, 387 .enable = da903x_enable,
390 .disable = da903x_disable, 388 .disable = da903x_disable,
@@ -393,7 +391,7 @@ static struct regulator_ops da9030_regulator_ldo1_15_ops = {
393 391
394static struct regulator_ops da9034_regulator_dvc_ops = { 392static struct regulator_ops da9034_regulator_dvc_ops = {
395 .set_voltage = da9034_set_dvc_voltage, 393 .set_voltage = da9034_set_dvc_voltage,
396 .get_voltage = da903x_get_voltage, 394 .get_voltage_sel = da903x_get_voltage_sel,
397 .list_voltage = da903x_list_voltage, 395 .list_voltage = da903x_list_voltage,
398 .enable = da903x_enable, 396 .enable = da903x_enable,
399 .disable = da903x_disable, 397 .disable = da903x_disable,
@@ -403,7 +401,7 @@ static struct regulator_ops da9034_regulator_dvc_ops = {
403/* NOTE: this is dedicated for the insane LDO12 */ 401/* NOTE: this is dedicated for the insane LDO12 */
404static struct regulator_ops da9034_regulator_ldo12_ops = { 402static struct regulator_ops da9034_regulator_ldo12_ops = {
405 .set_voltage = da9034_set_ldo12_voltage, 403 .set_voltage = da9034_set_ldo12_voltage,
406 .get_voltage = da9034_get_ldo12_voltage, 404 .get_voltage_sel = da9034_get_ldo12_voltage_sel,
407 .list_voltage = da9034_list_ldo12_voltage, 405 .list_voltage = da9034_list_ldo12_voltage,
408 .enable = da903x_enable, 406 .enable = da903x_enable,
409 .disable = da903x_disable, 407 .disable = da903x_disable,
@@ -546,7 +544,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
546 /* Workaround for the weird LDO12 voltage setting */ 544 /* Workaround for the weird LDO12 voltage setting */
547 if (ri->desc.id == DA9034_ID_LDO12) { 545 if (ri->desc.id == DA9034_ID_LDO12) {
548 ri->desc.ops = &da9034_regulator_ldo12_ops; 546 ri->desc.ops = &da9034_regulator_ldo12_ops;
549 ri->desc.n_voltages = ARRAY_SIZE(da9034_ldo12_data); 547 ri->desc.n_voltages = 16;
550 } 548 }
551 549
552 if (ri->desc.id == DA9030_ID_LDO14) 550 if (ri->desc.id == DA9030_ID_LDO14)