regulator: wm831x: Set the new rather than old value for DVS VSEL
[linux-2.6.git] / drivers / regulator / lp3971.c
index 671a7d1..0cfabd3 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/lp3971.h>
 #include <linux/slab.h>
@@ -168,7 +169,8 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev)
 }
 
 static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
-                                 int min_uV, int max_uV)
+                                 int min_uV, int max_uV,
+                                 unsigned int *selector)
 {
        struct lp3971 *lp3971 = rdev_get_drvdata(dev);
        int ldo = rdev_get_id(dev) - LP3971_LDO1;
@@ -187,6 +189,8 @@ static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
        if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol)
                return -EINVAL;
 
+       *selector = val;
+
        return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
                        LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
                        val << LDO_VOL_CONTR_SHIFT(ldo));
@@ -256,7 +260,8 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev)
 }
 
 static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
-                                 int min_uV, int max_uV)
+                                  int min_uV, int max_uV,
+                                  unsigned int *selector)
 {
        struct lp3971 *lp3971 = rdev_get_drvdata(dev);
        int buck = rdev_get_id(dev) - LP3971_DCDC1;
@@ -277,6 +282,8 @@ static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
        if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol)
                return -EINVAL;
 
+       *selector = val;
+
        ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
               BUCK_TARGET_VOL_MASK, val);
        if (ret)
@@ -377,7 +384,7 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
        if (count != 1)
                return -EIO;
        ret = i2c_smbus_read_byte_data(i2c, reg);
-       if (ret < 0 || count != 1)
+       if (ret < 0)
                return -EIO;
 
        *dest = ret;
@@ -387,15 +394,9 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
 static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count,
        const u16 *src)
 {
-       int ret;
-
        if (count != 1)
                return -EIO;
-       ret = i2c_smbus_write_byte_data(i2c, reg, *src);
-       if (ret >= 0)
-               return 0;
-
-       return ret;
+       return i2c_smbus_write_byte_data(i2c, reg, *src);
 }
 
 static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg)
@@ -450,7 +451,7 @@ static int __devinit setup_regulators(struct lp3971 *lp3971,
        for (i = 0; i < pdata->num_regulators; i++) {
                struct lp3971_regulator_subdev *reg = &pdata->regulators[i];
                lp3971->rdev[i] = regulator_register(&regulators[reg->id],
-                                       lp3971->dev, reg->initdata, lp3971);
+                               lp3971->dev, reg->initdata, lp3971, NULL);
 
                if (IS_ERR(lp3971->rdev[i])) {
                        err = PTR_ERR(lp3971->rdev[i]);
@@ -519,8 +520,6 @@ static int __devexit lp3971_i2c_remove(struct i2c_client *i2c)
        struct lp3971 *lp3971 = i2c_get_clientdata(i2c);
        int i;
 
-       i2c_set_clientdata(i2c, NULL);
-
        for (i = 0; i < lp3971->num_regulators; i++)
                regulator_unregister(lp3971->rdev[i]);