regulator: Simplify the code to get selector in isl6271a_set_voltage
PATCH 1/1 regulator: Simplify the code to get selector in isl6271a_set_voltage
Signed-off-by Axel Lin <[email protected]>
--- drivers/regulator/isl6271a-regulator.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-)
drivers/regulator/isl6271a-regulator.c +3 -11
@@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, unsigned *selector) {struct isl_pmic *pmic =rdev_get_drvdata (dev); -int vsel, err, data; +int err, data;if (minuV <ISL6271A_VOLTAGE_MIN || minuV >ISL6271A_VOLTAGE_MAX )return -EINVAL ;if (maxuV <ISL6271A_VOLTAGE_MIN || maxuV >ISL6271A_VOLTAGE_MAX )return -EINVAL ; -/* Align to 50000 mV */ - vsel = minuV - (minuV %ISL6271A_VOLTAGE_STEP ); - -/* If the result fell out of [minuV,maxuV] range, put it back */ -if (vsel < minuV) - vsel +=ISL6271A_VOLTAGE_STEP ; - -/* Convert the microvolts to data for the chip */ - data = (vsel -ISL6271A_VOLTAGE_MIN ) /ISL6271A_VOLTAGE_STEP ; - + data =DIV_ROUND_UP (minuV -ISL6271A_VOLTAGE_MIN , +ISL6271A_VOLTAGE_STEP ); *selector = data;mutex_lock (&pmic->mtx);
Signature · 1 line
1.7.5.4
Quoted 12 lines
Signed-off-by Axel Lin <[email protected]>--- drivers/regulator/isl6271a-regulator.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/drivers/regulator/isl6271a-regulator.cindex c1a456c..775f5fd 100644drivers/regulator/isl6271a-regulator.c +0
-0@@ -63,23 +63,15 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, unsigned *selector) {
drivers/regulator/isl6271a-regulator.c static int isl6271a_set_voltage(struct regulator_dev · line 73
Quoted 10 lines
drivers/regulator/isl6271a-regulator.c +1
-2struct isl_pmic *pmic =rdev_get_drvdata (dev); -int vsel, err, data; +int err, data;if (minuV <ISL6271A_VOLTAGE_MIN || minuV >ISL6271A_VOLTAGE_MAX )return -EINVAL ;if (maxuV <ISL6271A_VOLTAGE_MIN || maxuV >ISL6271A_VOLTAGE_MAX )return -EINVAL ; -/* Align to 50000 mV */
Heh ... 50000mV ? :-)
drivers/regulator/isl6271a-regulator.c static int isl6271a_set_voltage(struct regulator_dev *dev, · line 74
Quoted 11 lines
drivers/regulator/isl6271a-regulator.c +2
-9- vsel = minuV - (minuV %ISL6271A_VOLTAGE_STEP ); - -/* If the result fell out of [minuV,maxuV] range, put it back */ -if (vsel < minuV) - vsel +=ISL6271A_VOLTAGE_STEP ; - -/* Convert the microvolts to data for the chip */ - data = (vsel -ISL6271A_VOLTAGE_MIN ) /ISL6271A_VOLTAGE_STEP ; - + data =DIV_ROUND_UP (minuV -ISL6271A_VOLTAGE_MIN , +ISL6271A_VOLTAGE_STEP );
Ok, this makes sense.
Acked-by Marek Vasut <[email protected]>
Quoted 3 lines
drivers/regulator/isl6271a-regulator.c +0
-0*selector = data;mutex_lock (&pmic->mtx);
Mark Brown
AppliedQuoted 1 line · Axel Lin
Signed-off-by Axel Lin <[email protected]>
Applied, thanks.