regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage
PATCH 1/2 regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage
Call wm8400_ldo_list_voltage() instead of open code to verify selected voltage falls within specified range.
Use wm8400_ldo_list_voltage() here is less error prone.
--- drivers/regulator/wm8400-regulator.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/regulator/wm8400-regulator.c +7 -15
@@ -35,27 +35,19 @@ static int wm8400_ldo_map_voltage(struct regulator_dev *dev, int min_uV, int max_uV) {u16 val; +int volt;if (min_uV <900000 || min_uV >3300000 )return -EINVAL ; -if (min_uV <1700000 ) { -/* Steps of 50mV from 900mV; */ +if (min_uV <1700000 )/* Steps of 50mV from 900mV; */ val =DIV_ROUND_UP (min_uV -900000 ,50000 ); +else /* Steps of 100mV from 1700mV */ + val =DIV_ROUND_UP (min_uV -1700000 ,100000 ) +15 ; -if ((val *50000 ) +900000 > max_uV) -return -EINVAL ; -BUG_ON ((val *50000 ) +900000 < min_uV); - }else { -/* Steps of 100mV from 1700mV */ - val =DIV_ROUND_UP (min_uV -1700000 ,100000 ); - -if ((val *100000 ) +1700000 > max_uV) -return -EINVAL ; -BUG_ON ((val *100000 ) +1700000 < min_uV); - - val +=0xf ; - } + volt =wm8400_ldo_list_voltage (dev, val); +if (volt < min_uV || volt > max_uV) +return -EINVAL ;return val; }
Signature · 1 line
1.7.9.5
PATCH 2/2 regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage
Adjust the equation for selector >= 15 for better readability. The equation "1700000 + ((selector - 15) * 100000)" can be interpreted by:
Starting from selector 15: Steps of 100mV from 1700mV
--- drivers/regulator/wm8400-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/wm8400-regulator.c +1 -1
@@ -28,7 +28,7 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev,if (selector <15 )return 900000 + (selector *50000 );else -return 1600000 + ((selector -14 ) *100000 ); +return 1700000 + ((selector -15 ) *100000 ); } static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
Signature · 1 line
1.7.9.5
Mark Brown
AppliedRe: [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage
Quoted 3 lines · Axel Lin
Adjust the equation for selector >= 15 for better readability. The equation "1700000 + ((selector - 15) * 100000)" can be interpreted by:
Starting from selector 15: Steps of 100mV from 1700mV
Applied, thanks.
Mark Brown
AppliedQuoted 3 lines · Axel Lin
Call
wm8400_ldo_list_voltage()instead of open code to verify selected voltage falls within specified range.
Usewm8400_ldo_list_voltage()here is less error prone.
Applied, thanks.