regulator: Simplify the code to get selector in isl6271a_set_voltage
authorAxel Lin <axel.lin@gmail.com>
Fri, 2 Mar 2012 01:19:02 +0000 (09:19 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 11 Mar 2012 20:48:47 +0000 (20:48 +0000)
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Acked-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/isl6271a-regulator.c

index c1a456c4257c1b5f3b23a553ee87a1a67f939a00..775f5fd208c375e87690f6fb48b7bb38893e566f 100644 (file)
@@ -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);