regulator: lp872x: set_current_limit should select the maximum current in specific...
authorAxel Lin <axel.lin@gmail.com>
Wed, 8 Aug 2012 12:22:35 +0000 (20:22 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 28 Aug 2012 18:00:26 +0000 (11:00 -0700)
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/lp872x.c

index 212c38eaba700d857767a89c2ccfc3d5006018e6..6199d0f6cca1309434488f2bcdac68501a4317c8 100644 (file)
@@ -374,8 +374,8 @@ static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
 {
        struct lp872x *lp = rdev_get_drvdata(rdev);
        enum lp872x_regulator_id buck = rdev_get_id(rdev);
-       int i, max = ARRAY_SIZE(lp8725_buck_uA);
-       u8 addr, val;
+       int i;
+       u8 addr;
 
        switch (buck) {
        case LP8725_ID_BUCK1:
@@ -388,17 +388,15 @@ static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
                return -EINVAL;
        }
 
-       for (i = 0 ; i < max ; i++)
+       for (i = ARRAY_SIZE(lp8725_buck_uA) - 1 ; i >= 0; i--) {
                if (lp8725_buck_uA[i] >= min_uA &&
                        lp8725_buck_uA[i] <= max_uA)
-                       break;
-
-       if (i == max)
-               return -EINVAL;
-
-       val = i << LP8725_BUCK_CL_S;
+                       return lp872x_update_bits(lp, addr,
+                                                 LP8725_BUCK_CL_M,
+                                                 i << LP8725_BUCK_CL_S);
+       }
 
-       return lp872x_update_bits(lp, addr, LP8725_BUCK_CL_M, val);
+       return -EINVAL;
 }
 
 static int lp8725_buck_get_current_limit(struct regulator_dev *rdev)