diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-03-05 07:27:56 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-03-11 16:39:10 -0400 |
commit | 9365121869a15da99d6091802f11a82d59024d62 (patch) | |
tree | 2cb60af6d279a16cf76e560e40982eb0bb7904c4 | |
parent | 7b95765495d0b296cf35e97e68c780b208c85ad5 (diff) |
regulator: da9052: Ensure the selected voltage falls within the specified range
Integer division may truncate the result, use DIV_ROUND_UP to ensure the
selected voltage falls within the specified range.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | drivers/regulator/da9052-regulator.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index 319ba51fe61d..09915e89705d 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c | |||
@@ -226,7 +226,7 @@ static int da9052_regulator_set_voltage_int(struct regulator_dev *rdev, | |||
226 | if (min_uV < info->min_uV) | 226 | if (min_uV < info->min_uV) |
227 | min_uV = info->min_uV; | 227 | min_uV = info->min_uV; |
228 | 228 | ||
229 | *selector = (min_uV - info->min_uV) / info->step_uV; | 229 | *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); |
230 | 230 | ||
231 | ret = da9052_list_voltage(rdev, *selector); | 231 | ret = da9052_list_voltage(rdev, *selector); |
232 | if (ret < 0) | 232 | if (ret < 0) |
@@ -318,10 +318,10 @@ static int da9052_set_buckperi_voltage(struct regulator_dev *rdev, int min_uV, | |||
318 | if ((regulator->da9052->chip_id == DA9052) && | 318 | if ((regulator->da9052->chip_id == DA9052) && |
319 | (min_uV >= DA9052_CONST_3uV)) | 319 | (min_uV >= DA9052_CONST_3uV)) |
320 | *selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV + | 320 | *selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV + |
321 | ((min_uV - DA9052_CONST_3uV) / | 321 | DIV_ROUND_UP(min_uV - DA9052_CONST_3uV, |
322 | (DA9052_BUCK_PERI_3uV_STEP)); | 322 | DA9052_BUCK_PERI_3uV_STEP); |
323 | else | 323 | else |
324 | *selector = (min_uV - info->min_uV) / info->step_uV; | 324 | *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); |
325 | 325 | ||
326 | ret = da9052_list_buckperi_voltage(rdev, *selector); | 326 | ret = da9052_list_buckperi_voltage(rdev, *selector); |
327 | if (ret < 0) | 327 | if (ret < 0) |