diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-07-18 00:30:11 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-08-07 13:10:25 -0400 |
commit | a5f8ae2154eeb7ed18c6e3dbf6ac095ea4c3d5cf (patch) | |
tree | ae494cdcc5ed2594f5caf9675e403365ad12b19b | |
parent | 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff) |
regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
This patch fixes below issues when choosing selector:
1. Current code returns negative selector if min_uV < 900000 which is wrong.
For example, it is possible to satisfy the request with selector = 1 if
the requested min_uV is 850000.
2. Current code may select a voltage lower than requested min_uV.
For example, if the requested min_uV is 945000, current code chooses
selector = 1 which is lower than requested min_uV.
DIV_ROUND_UP to avoid this case.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | drivers/regulator/palmas-regulator.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index 17d19fbbc490..0fcf3550f65d 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c | |||
@@ -486,9 +486,12 @@ static int palmas_map_voltage_ldo(struct regulator_dev *rdev, | |||
486 | { | 486 | { |
487 | int ret, voltage; | 487 | int ret, voltage; |
488 | 488 | ||
489 | ret = ((min_uV - 900000) / 50000) + 1; | 489 | if (min_uV == 0) |
490 | if (ret < 0) | 490 | return 0; |
491 | return ret; | 491 | |
492 | if (min_uV < 900000) | ||
493 | min_uV = 900000; | ||
494 | ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1; | ||
492 | 495 | ||
493 | /* Map back into a voltage to verify we're still in bounds */ | 496 | /* Map back into a voltage to verify we're still in bounds */ |
494 | voltage = palmas_list_voltage_ldo(rdev, ret); | 497 | voltage = palmas_list_voltage_ldo(rdev, ret); |