regulator: regulator for Palmas Kconfig
[linux-2.6.git] / drivers / regulator / s5m8767.c
index 9d5d915..4ca2db0 100644 (file)
@@ -219,6 +219,7 @@ static int s5m8767_reg_disable(struct regulator_dev *rdev)
 
 static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
 {
+       struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
        int reg_id = rdev_get_id(rdev);
        int reg;
 
@@ -234,12 +235,18 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
                break;
        case S5M8767_BUCK2:
                reg = S5M8767_REG_BUCK2DVS1;
+               if (s5m8767->buck2_gpiodvs)
+                       reg += s5m8767->buck_gpioindex;
                break;
        case S5M8767_BUCK3:
                reg = S5M8767_REG_BUCK3DVS1;
+               if (s5m8767->buck3_gpiodvs)
+                       reg += s5m8767->buck_gpioindex;
                break;
        case S5M8767_BUCK4:
                reg = S5M8767_REG_BUCK4DVS1;
+               if (s5m8767->buck4_gpiodvs)
+                       reg += s5m8767->buck_gpioindex;
                break;
        case S5M8767_BUCK5:
                reg = S5M8767_REG_BUCK5CTRL2;
@@ -259,7 +266,7 @@ static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg)
 static int s5m8767_get_voltage_sel(struct regulator_dev *rdev)
 {
        struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
-       int reg, mask = 0xff, ret;
+       int reg, mask, ret;
        int reg_id = rdev_get_id(rdev);
        u8 val;
 
@@ -267,23 +274,7 @@ static int s5m8767_get_voltage_sel(struct regulator_dev *rdev)
        if (ret)
                return ret;
 
-       switch (reg_id) {
-       case S5M8767_LDO1 ... S5M8767_LDO28:
-               mask = 0x3f;
-               break;
-       case S5M8767_BUCK2:
-               if (s5m8767->buck2_gpiodvs)
-                       reg += s5m8767->buck_gpioindex;
-               break;
-       case S5M8767_BUCK3:
-               if (s5m8767->buck3_gpiodvs)
-                       reg += s5m8767->buck_gpioindex;
-               break;
-       case S5M8767_BUCK4:
-               if (s5m8767->buck4_gpiodvs)
-                       reg += s5m8767->buck_gpioindex;
-               break;
-       }
+       mask = (reg_id < S5M8767_BUCK1) ? 0x3f : 0xff;
 
        ret = s5m_reg_read(s5m8767->iodev, reg, &val);
        if (ret)
@@ -320,8 +311,7 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
        struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
        const struct s5m_voltage_desc *desc;
        int reg_id = rdev_get_id(rdev);
-       int reg, mask, ret;
-       int i;
+       int sel, reg, mask, ret;
        u8 val;
 
        switch (reg_id) {
@@ -342,19 +332,20 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev,
 
        desc = reg_voltage_map[reg_id];
 
-       i = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
-       if (i < 0)
-               return i;
+       sel = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV);
+       if (sel < 0)
+               return sel;
 
        ret = s5m8767_get_voltage_register(rdev, &reg);
        if (ret)
                return ret;
 
        s5m_reg_read(s5m8767->iodev, reg, &val);
-       val = val & mask;
+       val &= ~mask;
+       val |= sel;
 
        ret = s5m_reg_write(s5m8767->iodev, reg, val);
-       *selector = i;
+       *selector = sel;
 
        return ret;
 }
@@ -547,6 +538,27 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
+       if (pdata->buck2_gpiodvs) {
+               if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
+                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (pdata->buck3_gpiodvs) {
+               if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
+                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
+                       return -EINVAL;
+               }
+       }
+
+       if (pdata->buck4_gpiodvs) {
+               if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
+                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
+                       return -EINVAL;
+               }
+       }
+
        s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info),
                                GFP_KERNEL);
        if (!s5m8767)
@@ -640,30 +652,6 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
                }
        }
 
-       if (pdata->buck2_gpiodvs) {
-               if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) {
-                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
-                       ret = -EINVAL;
-                       return ret;
-               }
-       }
-
-       if (pdata->buck3_gpiodvs) {
-               if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) {
-                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
-                       ret = -EINVAL;
-                       return ret;
-               }
-       }
-
-       if (pdata->buck4_gpiodvs) {
-               if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) {
-                       dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n");
-                       ret = -EINVAL;
-                       return ret;
-               }
-       }
-
        s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL,
                        (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), 1 << 1);
        s5m_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL,