regulator: tps6591x: Fix set_voltage to return selector value
Antti P Miettinen [Tue, 18 Oct 2011 15:24:25 +0000 (18:24 +0300)]
Current regulator_ops interface expects selector value to be returned.
Not doing so results in uninitialized variables used.

Bug 886170

Change-Id: I004ee168eb0f003eb71c36d5fcd6c8106a1fc054
Reviewed-on: http://git-master/r/56648
Reviewed-by: Antti Miettinen <amiettinen@nvidia.com>
Tested-by: Antti Miettinen <amiettinen@nvidia.com>
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>

Rebase-Id: R5fa05ad3dc7cda25b634efbf956ae99280bab40d

drivers/regulator/tps6591x-regulator.c

index 87689d7..6a4dba8 100644 (file)
@@ -174,7 +174,8 @@ static void wait_for_voltage_change(struct tps6591x_regulator *ri, int uV)
 
 static int __tps6591x_vio_set_voltage(struct device *parent,
                                      struct tps6591x_regulator *ri,
-                                     int min_uV, int max_uV)
+                                     int min_uV, int max_uV,
+                                     unsigned *selector)
 {
        int uV;
        uint8_t mask;
@@ -187,6 +188,8 @@ static int __tps6591x_vio_set_voltage(struct device *parent,
 
                /* use the first in-range value */
                if (min_uV <= uV && uV <= max_uV) {
+                       if (selector)
+                               *selector = val;
 
                        reg_val = ri->supply_reg.cache_val;
                        val <<= ri->supply_reg.shift_bits;
@@ -209,12 +212,14 @@ static int __tps6591x_vio_set_voltage(struct device *parent,
 }
 
 static int tps6591x_vio_set_voltage(struct regulator_dev *rdev,
-                                   int min_uV, int max_uV)
+                                   int min_uV, int max_uV,
+                                   unsigned *selector)
 {
        struct tps6591x_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps6591x_dev(rdev);
 
-       return __tps6591x_vio_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps6591x_vio_set_voltage(parent, ri, min_uV, max_uV,
+                                         selector);
 }
 
 static int tps6591x_vio_get_voltage(struct regulator_dev *rdev)
@@ -243,8 +248,9 @@ static int tps6591x_ldo_list_voltage(struct regulator_dev *rdev,
 }
 
 static int __tps6591x_ldo1_set_voltage(struct device *parent,
-                                     struct tps6591x_regulator *ri,
-                                     int min_uV, int max_uV)
+                                      struct tps6591x_regulator *ri,
+                                      int min_uV, int max_uV,
+                                      unsigned *selector)
 {
        int val, uV;
        uint8_t mask;
@@ -256,6 +262,8 @@ static int __tps6591x_ldo1_set_voltage(struct device *parent,
 
                /* use the first in-range value */
                if (min_uV <= uV && uV <= max_uV) {
+                       if (selector)
+                               *selector = val;
                        reg_val = ri->supply_reg.cache_val;
                        val += 4;
                        val <<= ri->supply_reg.shift_bits;
@@ -277,12 +285,14 @@ static int __tps6591x_ldo1_set_voltage(struct device *parent,
 }
 
 static int tps6591x_ldo1_set_voltage(struct regulator_dev *rdev,
-                                   int min_uV, int max_uV)
+                                    int min_uV, int max_uV,
+                                    unsigned *selector)
 {
        struct tps6591x_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps6591x_dev(rdev);
 
-       return __tps6591x_ldo1_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps6591x_ldo1_set_voltage(parent, ri, min_uV, max_uV,
+                                          selector);
 }
 
 static int tps6591x_ldo1_get_voltage(struct regulator_dev *rdev)
@@ -307,7 +317,9 @@ static int tps6591x_ldo1_get_voltage(struct regulator_dev *rdev)
 }
 
 static int __tps6591x_ldo3_set_voltage(struct device *parent,
-               struct tps6591x_regulator *ri, int min_uV, int max_uV)
+                                      struct tps6591x_regulator *ri,
+                                      int min_uV, int max_uV,
+                                      unsigned *selector)
 {
        int val, uV;
        uint8_t mask;
@@ -319,6 +331,8 @@ static int __tps6591x_ldo3_set_voltage(struct device *parent,
 
                /* use the first in-range value */
                if (min_uV <= uV && uV <= max_uV) {
+                       if (selector)
+                               *selector = val;
                        reg_val = ri->supply_reg.cache_val;
                        val += 2;
                        val <<= ri->supply_reg.shift_bits;
@@ -341,12 +355,14 @@ static int __tps6591x_ldo3_set_voltage(struct device *parent,
 }
 
 static int tps6591x_ldo3_set_voltage(struct regulator_dev *rdev,
-                                   int min_uV, int max_uV)
+                                    int min_uV, int max_uV,
+                                    unsigned *selector)
 {
        struct tps6591x_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps6591x_dev(rdev);
 
-       return __tps6591x_ldo3_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps6591x_ldo3_set_voltage(parent, ri, min_uV, max_uV,
+                                          selector);
 }
 
 static int tps6591x_ldo3_get_voltage(struct regulator_dev *rdev)
@@ -372,7 +388,8 @@ static int tps6591x_ldo3_get_voltage(struct regulator_dev *rdev)
 
 static int __tps6591x_vdd_set_voltage(struct device *parent,
                                      struct tps6591x_regulator *ri,
-                                     int min_uV, int max_uV)
+                                     int min_uV, int max_uV,
+                                     unsigned *selector)
 {
        int val, uV, ret;
        uint8_t mask;
@@ -384,6 +401,8 @@ static int __tps6591x_vdd_set_voltage(struct device *parent,
 
                /* use the first in-range value */
                if (min_uV <= uV && uV <= max_uV) {
+                       if (selector)
+                               *selector = val;
                        op_reg_val = ri->op_reg.cache_val;
                        val += 3;
                        if (op_reg_val & 0x80) {
@@ -418,12 +437,14 @@ static int __tps6591x_vdd_set_voltage(struct device *parent,
 }
 
 static int tps6591x_vdd_set_voltage(struct regulator_dev *rdev,
-                                   int min_uV, int max_uV)
+                                   int min_uV, int max_uV,
+                                   unsigned *selector)
 {
        struct tps6591x_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps6591x_dev(rdev);
 
-       return __tps6591x_vdd_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps6591x_vdd_set_voltage(parent, ri, min_uV, max_uV,
+                                         selector);
 }
 
 static int tps6591x_vdd_get_voltage(struct regulator_dev *rdev)
@@ -700,7 +721,7 @@ static inline int tps6591x_regulator_preinit(struct device *parent,
                case TPS6591X_ID_VIO:
                        ret = __tps6591x_vio_set_voltage(parent, ri,
                                        tps6591x_pdata->init_uV,
-                                       tps6591x_pdata->init_uV);
+                                       tps6591x_pdata->init_uV, 0);
                        break;
 
                case TPS6591X_ID_LDO_1:
@@ -708,7 +729,7 @@ static inline int tps6591x_regulator_preinit(struct device *parent,
                case TPS6591X_ID_LDO_4:
                        ret = __tps6591x_ldo1_set_voltage(parent, ri,
                                        tps6591x_pdata->init_uV,
-                                       tps6591x_pdata->init_uV);
+                                       tps6591x_pdata->init_uV, 0);
                        break;
 
                case TPS6591X_ID_LDO_3:
@@ -718,7 +739,7 @@ static inline int tps6591x_regulator_preinit(struct device *parent,
                case TPS6591X_ID_LDO_8:
                        ret = __tps6591x_ldo3_set_voltage(parent, ri,
                                        tps6591x_pdata->init_uV,
-                                       tps6591x_pdata->init_uV);
+                                       tps6591x_pdata->init_uV, 0);
                        break;
 
                case TPS6591X_ID_VDD_1:
@@ -726,7 +747,7 @@ static inline int tps6591x_regulator_preinit(struct device *parent,
                case TPS6591X_ID_VDDCTRL:
                        ret = __tps6591x_vdd_set_voltage(parent, ri,
                                        tps6591x_pdata->init_uV,
-                                       tps6591x_pdata->init_uV);
+                                       tps6591x_pdata->init_uV, 0);
                        break;
 
                default: