Skip to contentSkip to conversation

regulator: Simplify the code to get selector in isl6271a_set_voltage

PATCH Applied Axel Lin 3 participants 3 messages Mar 2, 2012 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: Simplify the code to get selector in isl6271a_set_voltage

---
 drivers/regulator/isl6271a-regulator.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)
drivers/regulator/isl6271a-regulator.c +3 -11
index c1a456c..775f5fd 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines
---
 drivers/regulator/isl6271a-regulator.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/regulator/isl6271a-regulator.c index c1a456c..775f5fd 100644

drivers/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 -2
 	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 */

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.

Quoted 3 lines
drivers/regulator/isl6271a-regulator.c +0 -0
 	*selector = data;
 
 	mutex_lock(&pmic->mtx);