Skip to content

Commit

Permalink
regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Axel Lin authored and Mark Brown committed Aug 7, 2012
1 parent 0d7614f commit a5f8ae2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/regulator/palmas-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,12 @@ static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
{
int ret, voltage;

ret = ((min_uV - 900000) / 50000) + 1;
if (ret < 0)
return ret;
if (min_uV == 0)
return 0;

if (min_uV < 900000)
min_uV = 900000;
ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1;

/* Map back into a voltage to verify we're still in bounds */
voltage = palmas_list_voltage_ldo(rdev, ret);
Expand Down

0 comments on commit a5f8ae2

Please sign in to comment.