regulator: s2mps11: Fix setting ramp_delay
authorAxel Lin <axel.lin@ingics.com>
Mon, 5 Aug 2013 06:08:37 +0000 (14:08 +0800)
committerMark Brown <broonie@linaro.org>
Tue, 13 Aug 2013 10:17:58 +0000 (11:17 +0100)
Current code has wrong mask and val arguments for updating ramp_delay. Fix it.
Also ensure the return value of get_ramp_delay() won't greater than 3 because
the mask field for ramp_val only takes 2 bits.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/regulator/s2mps11.c

index 89140ae..5eba2ff 100644 (file)
@@ -50,6 +50,10 @@ static int get_ramp_delay(int ramp_delay)
                        break;
                cnt++;
        }
+
+       if (cnt > 3)
+               cnt = 3;
+
        return cnt;
 }
 
@@ -203,8 +207,8 @@ static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
 
        ramp_val = get_ramp_delay(ramp_delay);
 
-       return regmap_update_bits(rdev->regmap, ramp_reg,
-                                 ramp_val << ramp_shift, 1 << ramp_shift);
+       return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
+                                 ramp_val << ramp_shift);
 
 ramp_disable:
        return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,