OSDN Git Service

regulator: labibb: Fix slew rate calculation in LAB/IBB set_voltage
authorSubbaraman Narayanamurthy <subbaram@codeaurora.org>
Tue, 10 May 2016 19:25:16 +0000 (12:25 -0700)
committerKyle Yan <kyan@codeaurora.org>
Thu, 26 May 2016 22:25:13 +0000 (15:25 -0700)
Currently, while setting the voltage on LAB and IBB regulators,
slew rate is always calculated based on the difference between
user specified minimum voltage(min_uV) and the minimum voltage
(min_volt) that can be supported on the regulator based on the
mode it is operating.

However, it should be really calculated based upon the difference
between current voltage and new voltage which will be set. Fix
it. Also, add the missing return -EINVAL to set_voltage of LAB
regulator if min_uV is less than min_volt.

While at it, remove the redundant function name added to the
pr_err() statements in set_voltage callbacks.

CRs-Fixed: 1013913
Change-Id: I9a17c83d6613ff37cede4a7bb52612465e4d0101
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
drivers/regulator/qpnp-labibb-regulator.c

index 5dd772a..55ba6cf 100644 (file)
@@ -899,9 +899,8 @@ static int qpnp_lab_dt_init(struct qpnp_labibb *labibb,
                                val);
 
        if (rc) {
-               pr_err("qpnp_lab_regulator_set_voltage write register %x failed rc = %d\n",
-                       REG_LAB_VOLTAGE, rc);
-
+               pr_err("write to register %x failed rc = %d\n", REG_LAB_VOLTAGE,
+                       rc);
                return rc;
        }
 
@@ -1519,8 +1518,9 @@ static int qpnp_lab_regulator_set_voltage(struct regulator_dev *rdev,
                return 0;
 
        if (min_uV < labibb->lab_vreg.min_volt) {
-               pr_err("qpnp_lab_regulator_set_voltage failed, min_uV %d is less than min_volt %d",
-                       min_uV, labibb->lab_vreg.min_volt);
+               pr_err("min_uV %d is less than min_volt %d", min_uV,
+                       labibb->lab_vreg.min_volt);
+               return -EINVAL;
        }
 
        val = DIV_ROUND_UP(min_uV - labibb->lab_vreg.min_volt,
@@ -1528,7 +1528,7 @@ static int qpnp_lab_regulator_set_voltage(struct regulator_dev *rdev,
        new_uV = val * labibb->lab_vreg.step_size + labibb->lab_vreg.min_volt;
 
        if (new_uV > max_uV) {
-               pr_err("qpnp_lab_regulator_set_voltage unable to set voltage (%d %d)\n",
+               pr_err("unable to set voltage %d (min:%d max:%d)\n", new_uV,
                        min_uV, max_uV);
                return -EINVAL;
        }
@@ -1540,14 +1540,16 @@ static int qpnp_lab_regulator_set_voltage(struct regulator_dev *rdev,
                                val | LAB_VOLTAGE_OVERRIDE_EN);
 
        if (rc) {
-               pr_err("qpnp_lab_regulator_set_voltage write register %x failed rc = %d\n",
-                       REG_LAB_VOLTAGE, rc);
-
+               pr_err("write to register %x failed rc = %d\n", REG_LAB_VOLTAGE,
+                       rc);
                return rc;
        }
 
-       if (new_uV > labibb->lab_vreg.curr_volt)
+       if (new_uV > labibb->lab_vreg.curr_volt) {
+               val = DIV_ROUND_UP(new_uV - labibb->lab_vreg.curr_volt,
+                               labibb->lab_vreg.step_size);
                udelay(val * labibb->lab_vreg.slew_rate);
+       }
        labibb->lab_vreg.curr_volt = new_uV;
 
        return 0;
@@ -2299,8 +2301,8 @@ static int qpnp_ibb_regulator_set_voltage(struct regulator_dev *rdev,
                return 0;
 
        if (min_uV < labibb->ibb_vreg.min_volt) {
-               pr_err("qpnp_ibb_regulator_set_voltage failed, min_uV %d is less than min_volt %d",
-                       min_uV, labibb->ibb_vreg.min_volt);
+               pr_err("min_uV %d is less than min_volt %d", min_uV,
+                       labibb->ibb_vreg.min_volt);
                return -EINVAL;
        }
 
@@ -2309,7 +2311,7 @@ static int qpnp_ibb_regulator_set_voltage(struct regulator_dev *rdev,
        new_uV = val * labibb->ibb_vreg.step_size + labibb->ibb_vreg.min_volt;
 
        if (new_uV > max_uV) {
-               pr_err("qpnp_ibb_regulator_set_voltage unable to set voltage (%d %d)\n",
+               pr_err("unable to set voltage %d (min:%d max:%d)\n", new_uV,
                        min_uV, max_uV);
                return -EINVAL;
        }
@@ -2321,14 +2323,16 @@ static int qpnp_ibb_regulator_set_voltage(struct regulator_dev *rdev,
                                val | IBB_VOLTAGE_OVERRIDE_EN);
 
        if (rc) {
-               pr_err("qpnp_ibb_regulator_set_voltage write register %x failed rc = %d\n",
-                       REG_IBB_VOLTAGE, rc);
-
+               pr_err("write to register %x failed rc = %d\n", REG_IBB_VOLTAGE,
+                       rc);
                return rc;
        }
 
-       if (new_uV > labibb->ibb_vreg.curr_volt)
+       if (new_uV > labibb->ibb_vreg.curr_volt) {
+               val = DIV_ROUND_UP(new_uV - labibb->ibb_vreg.curr_volt,
+                               labibb->ibb_vreg.step_size);
                udelay(val * labibb->ibb_vreg.slew_rate);
+       }
        labibb->ibb_vreg.curr_volt = new_uV;
 
        return 0;