regulator: palmas: fix build warnings
[linux-2.6.git] / drivers / regulator / lp3972.c
index 0d9b475..49a15ee 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/bug.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
+#include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/lp3972.h>
@@ -192,7 +193,7 @@ static int lp3972_i2c_read(struct i2c_client *i2c, char reg, int count,
                return -EIO;
        ret = i2c_smbus_read_byte_data(i2c, reg);
        if (ret < 0)
-               return -EIO;
+               return ret;
 
        *dest = ret;
        return 0;
@@ -215,7 +216,7 @@ static u8 lp3972_reg_read(struct lp3972 *lp3972, u8 reg)
        lp3972_i2c_read(lp3972->i2c, reg, 1, &val);
 
        dev_dbg(lp3972->dev, "reg read 0x%02x -> 0x%02x\n", (int)reg,
-               (unsigned)val&0xff);
+               (unsigned)val & 0xff);
 
        mutex_unlock(&lp3972->io_lock);
 
@@ -234,7 +235,7 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val)
        if (ret == 0) {
                ret = lp3972_i2c_write(lp3972->i2c, reg, 1, &tmp);
                dev_dbg(lp3972->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg,
-                       (unsigned)val&0xff);
+                       (unsigned)val & 0xff);
        }
        mutex_unlock(&lp3972->io_lock);
 
@@ -292,7 +293,8 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
 }
 
 static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
-                                 int min_uV, int max_uV)
+                                 int min_uV, int max_uV,
+                                 unsigned int *selector)
 {
        struct lp3972 *lp3972 = rdev_get_drvdata(dev);
        int ldo = rdev_get_id(dev) - LP3972_LDO1;
@@ -313,6 +315,8 @@ static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
        if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol)
                return -EINVAL;
 
+       *selector = val;
+
        shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo);
        ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo),
                LP3972_LDO_VOL_MASK(ldo) << shift, val << shift);
@@ -320,6 +324,13 @@ static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
        if (ret)
                return ret;
 
+       /*
+        * LDO1 and LDO5 support voltage control by either target voltage1
+        * or target voltage2 register.
+        * We use target voltage1 register for LDO1 and LDO5 in this driver.
+        * We need to update voltage change control register(0x20) to enable
+        * LDO1 and LDO5 to change to their programmed target values.
+        */
        switch (ldo) {
        case LP3972_LDO1:
        case LP3972_LDO5:
@@ -401,14 +412,16 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
                val = 1000 * buck_voltage_map[buck][reg];
        else {
                val = 0;
-               dev_warn(&dev->dev, "chip reported incorrect voltage value.\n");
+               dev_warn(&dev->dev, "chip reported incorrect voltage value."
+                                   " reg = %d\n", reg);
        }
 
        return val;
 }
 
 static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
-                                 int min_uV, int max_uV)
+                                  int min_uV, int max_uV,
+                                  unsigned int *selector)
 {
        struct lp3972 *lp3972 = rdev_get_drvdata(dev);
        int buck = rdev_get_id(dev) - LP3972_DCDC1;
@@ -430,6 +443,8 @@ static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
            vol_map[val] > max_vol)
                return -EINVAL;
 
+       *selector = val;
+
        ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck),
                                LP3972_BUCK_VOL_MASK, val);
        if (ret)
@@ -523,7 +538,7 @@ static struct regulator_desc regulators[] = {
        },
 };
 
-static int setup_regulators(struct lp3972 *lp3972,
+static int __devinit setup_regulators(struct lp3972 *lp3972,
        struct lp3972_platform_data *pdata)
 {
        int i, err;
@@ -540,7 +555,7 @@ static int setup_regulators(struct lp3972 *lp3972,
        for (i = 0; i < pdata->num_regulators; i++) {
                struct lp3972_regulator_subdev *reg = &pdata->regulators[i];
                lp3972->rdev[i] = regulator_register(&regulators[reg->id],
-                                       lp3972->dev, reg->initdata, lp3972);
+                               lp3972->dev, reg->initdata, lp3972, NULL);
 
                if (IS_ERR(lp3972->rdev[i])) {
                        err = PTR_ERR(lp3972->rdev[i]);
@@ -584,10 +599,13 @@ static int __devinit lp3972_i2c_probe(struct i2c_client *i2c,
 
        /* Detect LP3972 */
        ret = lp3972_i2c_read(i2c, LP3972_SYS_CONTROL1_REG, 1, &val);
-       if (ret == 0 && (val & SYS_CONTROL1_INIT_MASK) != SYS_CONTROL1_INIT_VAL)
+       if (ret == 0 &&
+               (val & SYS_CONTROL1_INIT_MASK) != SYS_CONTROL1_INIT_VAL) {
                ret = -ENODEV;
+               dev_err(&i2c->dev, "chip reported: val = 0x%x\n", val);
+       }
        if (ret < 0) {
-               dev_err(&i2c->dev, "failed to detect device\n");
+               dev_err(&i2c->dev, "failed to detect device. ret = %d\n", ret);
                goto err_detect;
        }