regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
Subsystems (2)
PATCH 1/1 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.
--- drivers/regulator/palmas-regulator.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/regulator/palmas-regulator.c +6 -3
@@ -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);
Signature · 1 line
1.7.9.5
Quoted 5 lines · Axel Lin
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 requestedmin_uVis 850000.
Isnt this defending against bugs in the regulator core? I am normally against repeating the same checks at multiple levels in a stack.
Quoted 30 lines
2. Current code may select a voltage lower than requested
min_uV. For example, if the requestedmin_uVis 945000, current code chooses selector = 1 which is lower than requestedmin_uV.DIV_ROUND_UPto avoid this case.Signed-off-by Axel Lin <[email protected]>--- drivers/regulator/palmas-regulator.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/regulator/palmas-regulator.c +6
-3@@ -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);
Quoted 9 lines · Graeme Gregory
Quoted 5 lines · Axel Lin
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 requestedmin_uVis 850000.Isnt this defending against bugs in the regulator core? I am normally against repeating the same checks at multiple levels in a stack.
This isn't a bug in the core, a negative selector is an error code (and in general whatever selector is returned by the driver ought to agree with selectors the driver actually supports). It's probably at least a questionable decision in the machine constraints to allow a request for less than the regulator can deliver to get through though.