regulator: palma: Disable smps10 boost during suspend
[linux-2.6.git] / drivers / regulator / max8925-regulator.c
index 8ae1475..2f242f4 100644 (file)
@@ -9,6 +9,7 @@
  * published by the Free Software Foundation.
  */
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #define SD1_DVM_SHIFT          5               /* SDCTL1 bit5 */
 #define SD1_DVM_EN             6               /* SDV1 bit 6 */
 
+/* bit definitions in LDO control registers */
+#define LDO_SEQ_I2C            0x7             /* Power U/D by i2c */
+#define LDO_SEQ_MASK           0x7             /* Power U/D sequence mask */
+#define LDO_SEQ_SHIFT          2               /* Power U/D sequence offset */
+#define LDO_I2C_EN             0x1             /* Enable by i2c */
+#define LDO_I2C_EN_MASK                0x1             /* Enable mask by i2c */
+#define LDO_I2C_EN_SHIFT       0               /* Enable offset by i2c */
+
 struct max8925_regulator_info {
        struct regulator_desc   desc;
        struct regulator_dev    *regulator;
@@ -35,7 +44,6 @@ struct max8925_regulator_info {
        int     vol_reg;
        int     vol_shift;
        int     vol_nbits;
-       int     enable_bit;
        int     enable_reg;
 };
 
@@ -65,7 +73,7 @@ static int max8925_set_voltage(struct regulator_dev *rdev,
                        min_uV, max_uV);
                return -EINVAL;
        }
-       data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
+       data = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
        *selector = data;
        data <<= info->vol_shift;
        mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
@@ -93,8 +101,10 @@ static int max8925_enable(struct regulator_dev *rdev)
        struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
 
        return max8925_set_bits(info->i2c, info->enable_reg,
-                               1 << info->enable_bit,
-                               1 << info->enable_bit);
+                               LDO_SEQ_MASK << LDO_SEQ_SHIFT |
+                               LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT,
+                               LDO_SEQ_I2C << LDO_SEQ_SHIFT |
+                               LDO_I2C_EN << LDO_I2C_EN_SHIFT);
 }
 
 static int max8925_disable(struct regulator_dev *rdev)
@@ -102,19 +112,24 @@ static int max8925_disable(struct regulator_dev *rdev)
        struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
 
        return max8925_set_bits(info->i2c, info->enable_reg,
-                               1 << info->enable_bit, 0);
+                               LDO_SEQ_MASK << LDO_SEQ_SHIFT |
+                               LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT,
+                               LDO_SEQ_I2C << LDO_SEQ_SHIFT);
 }
 
 static int max8925_is_enabled(struct regulator_dev *rdev)
 {
        struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
-       int ret;
+       int ldo_seq, ret;
 
        ret = max8925_reg_read(info->i2c, info->enable_reg);
        if (ret < 0)
                return ret;
-
-       return ret & (1 << info->enable_bit);
+       ldo_seq = (ret >> LDO_SEQ_SHIFT) & LDO_SEQ_MASK;
+       if (ldo_seq != LDO_SEQ_I2C)
+               return 1;
+       else
+               return ret & (LDO_I2C_EN_MASK << LDO_I2C_EN_SHIFT);
 }
 
 static int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV)
@@ -125,7 +140,7 @@ static int max8925_set_dvm_voltage(struct regulator_dev *rdev, int uV)
        if (uV < SD1_DVM_VMIN || uV > SD1_DVM_VMAX)
                return -EINVAL;
 
-       data = (uV - SD1_DVM_VMIN + SD1_DVM_STEP - 1) / SD1_DVM_STEP;
+       data = DIV_ROUND_UP(uV - SD1_DVM_VMIN, SD1_DVM_STEP);
        data <<= SD1_DVM_SHIFT;
        mask = 3 << SD1_DVM_SHIFT;
 
@@ -182,7 +197,6 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
        .vol_shift      = 0,                                    \
        .vol_nbits      = 6,                                    \
        .enable_reg     = MAX8925_SDCTL##_id,                   \
-       .enable_bit     = 0,                                    \
 }
 
 #define MAX8925_LDO(_id, min, max, step)                       \
@@ -201,7 +215,6 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
        .vol_shift      = 0,                                    \
        .vol_nbits      = 6,                                    \
        .enable_reg     = MAX8925_LDOCTL##_id,                  \
-       .enable_bit     = 0,                                    \
 }
 
 static struct max8925_regulator_info max8925_regulator_info[] = {
@@ -260,7 +273,7 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
        ri->chip = chip;
 
        rdev = regulator_register(&ri->desc, &pdev->dev,
-                                 pdata->regulator[pdev->id], ri);
+                                 pdata->regulator[pdev->id], ri, NULL);
        if (IS_ERR(rdev)) {
                dev_err(&pdev->dev, "failed to register regulator %s\n",
                                ri->desc.name);