aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/twl-regulator.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-07-08 23:22:31 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-07-15 17:06:05 -0400
commita3cb80f43a9bc9b64aedd14b100e99252767d78c (patch)
treee0e12208892082893cb80772c63bbab24a82a83b /drivers/regulator/twl-regulator.c
parent5febb3c9d52c65686a8e473a31f15137852f4b5e (diff)
regulator: twl: Fix the formula to calculate vsel and voltage for twl6030ldo
In twl6030ldo_set_voltage, current code use below formula to calculate vsel: vsel = (min_uV/1000 - 1000)/100 + 1; This is worng because when min_uV is 1000000 uV, vsel is 1. It should be 0 in this case. Fix it by change the equation to: (This equation is common for linear mapping) vsel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step); In twl6030ldo_get_voltage, current code use below formula to calculate voltage: mV = 1000mv + 100mv * (vsel - 1) This is worng because when vsel is 0, mV is 900mV. Note the min_uV is 1000mV. Fix it by change the equation to: (This equation is common for linear mapping) return rdev->desc->min_uV + vsel * rdev->desc->uV_step; Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/twl-regulator.c')
-rw-r--r--drivers/regulator/twl-regulator.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 8f0bd56c211..bb51decfcb8 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -569,30 +569,21 @@ twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
569 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV)) 569 if ((min_uV/1000 < info->min_mV) || (max_uV/1000 > info->max_mV))
570 return -EDOM; 570 return -EDOM;
571 571
572 /* 572 vsel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
573 * Use the below formula to calculate vsel
574 * mV = 1000mv + 100mv * (vsel - 1)
575 */
576 vsel = (min_uV/1000 - 1000)/100 + 1;
577 *selector = vsel; 573 *selector = vsel;
578 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
579 574
575 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
580} 576}
581 577
582static int twl6030ldo_get_voltage(struct regulator_dev *rdev) 578static int twl6030ldo_get_voltage(struct regulator_dev *rdev)
583{ 579{
584 struct twlreg_info *info = rdev_get_drvdata(rdev); 580 struct twlreg_info *info = rdev_get_drvdata(rdev);
585 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 581 int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE);
586 VREG_VOLTAGE);
587 582
588 if (vsel < 0) 583 if (vsel < 0)
589 return vsel; 584 return vsel;
590 585
591 /* 586 return rdev->desc->min_uV + vsel * rdev->desc->uV_step;
592 * Use the below formula to calculate vsel
593 * mV = 1000mv + 100mv * (vsel - 1)
594 */
595 return (1000 + (100 * (vsel - 1))) * 1000;
596} 587}
597 588
598static struct regulator_ops twl6030ldo_ops = { 589static struct regulator_ops twl6030ldo_ops = {