Revert "Revert "regulator: tps80031: rename regulator-name enums""
[linux-2.6.git] / drivers / regulator / tps80031-regulator.c
index aeb672b..9250123 100644 (file)
@@ -35,6 +35,7 @@
 /* Flags for DCDC Voltage reading */
 #define DCDC_OFFSET_EN         BIT(0)
 #define DCDC_EXTENDED_EN       BIT(1)
+#define TRACK_MODE_ENABLE      BIT(2)
 
 #define SMPS_MULTOFFSET_VIO    BIT(1)
 #define SMPS_MULTOFFSET_SMPS1  BIT(3)
 #define STATE_ON               0x01
 #define STATE_MASK             0x03
 
+#define TRANS_SLEEP_OFF                0x00
+#define TRANS_SLEEP_ON         0x04
+#define TRANS_SLEEP_MASK       0x0C
+
 #define SMPS_CMD_MASK          0xC0
 #define SMPS_VSEL_MASK         0x3F
 #define LDO_VSEL_MASK          0x1F
 #define OPA_MODE_EN            BIT(6)
 #define OPA_MODE_EN_MASK       BIT(6)
 
+#define USB_VBUS_CTRL_SET      0x04
+#define USB_VBUS_CTRL_CLR      0x05
+#define VBUS_DISCHRG           0x20
+
 #define EXT_PWR_REQ (PWR_REQ_INPUT_PREQ1 | PWR_REQ_INPUT_PREQ2 | \
                        PWR_REQ_INPUT_PREQ3)
-#define TPS80031_PREQ1_RES_ASS_A       0xD7
-#define TPS80031_PREQ2_RES_ASS_A       0xDA
-#define TPS80031_PREQ3_RES_ASS_A       0xDD
-#define TPS80031_PHOENIX_MSK_TRANSITION        0x20
 
 struct tps80031_regulator {
 
@@ -84,6 +89,10 @@ struct tps80031_regulator {
        u8              force_reg;
        u8              volt_reg;
        u8              volt_id;
+       uint8_t         trans_reg_cache;
+       uint8_t         state_reg_cache;
+       uint8_t         force_reg_cache;
+       uint8_t         volt_reg_cache;
 
        /* twl resource ID, for resource control state machine */
        u8                      id;
@@ -91,12 +100,14 @@ struct tps80031_regulator {
        /* chip constraints on regulator behavior */
        u16                     min_mV;
        u16                     max_mV;
+       unsigned int            tolerance_uv;
 
        /* regulator specific turn-on delay */
-       u16                     delay;
+       int                     delay;
 
        u8                      flags;
        unsigned int            platform_flags;
+       unsigned int            ext_ctrl_flag;
 
        /* used by regulator core */
        struct regulator_desc   desc;
@@ -149,19 +160,10 @@ static u8 tps80031_get_smps_mult(struct device *parent)
 static int tps80031_reg_is_enabled(struct regulator_dev *rdev)
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
-       struct device *parent = to_tps80031_dev(rdev);
-       uint8_t state;
-       int ret;
 
-       if (ri->platform_flags & EXT_PWR_REQ)
+       if (ri->ext_ctrl_flag & EXT_PWR_REQ)
                return true;
-
-       ret = tps80031_read(parent, SLAVE_ID1, ri->state_reg, &state);
-       if (ret < 0) {
-               dev_err(&rdev->dev, "Error in reading the STATE register\n");
-               return ret;
-       }
-       return ((state & STATE_MASK) == STATE_ON);
+       return ((ri->state_reg_cache & STATE_MASK) == STATE_ON);
 }
 
 static int tps80031_reg_enable(struct regulator_dev *rdev)
@@ -169,16 +171,19 @@ static int tps80031_reg_enable(struct regulator_dev *rdev)
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps80031_dev(rdev);
        int ret;
+       uint8_t reg_val;
 
-       if (ri->platform_flags & EXT_PWR_REQ)
+       if (ri->ext_ctrl_flag & EXT_PWR_REQ)
                return 0;
 
-       ret = tps80031_force_update(parent, SLAVE_ID1, ri->state_reg, STATE_ON,
-                                   STATE_MASK);
+       reg_val = (ri->state_reg_cache & ~STATE_MASK) |
+                                       (STATE_ON & STATE_MASK);
+       ret = tps80031_write(parent, SLAVE_ID1, ri->state_reg, reg_val);
        if (ret < 0) {
-               dev_err(&rdev->dev, "Error in updating the STATE register\n");
+               dev_err(&rdev->dev, "Error in writing the STATE register\n");
                return ret;
        }
+       ri->state_reg_cache = reg_val;
        udelay(ri->delay);
        return ret;
 }
@@ -188,15 +193,18 @@ static int tps80031_reg_disable(struct regulator_dev *rdev)
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps80031_dev(rdev);
        int ret;
+       uint8_t reg_val;
 
-       if (ri->platform_flags & EXT_PWR_REQ)
+       if (ri->ext_ctrl_flag & EXT_PWR_REQ)
                return 0;
 
-       ret = tps80031_force_update(parent, SLAVE_ID1, ri->state_reg, STATE_OFF,
-                                   STATE_MASK);
+       reg_val = (ri->state_reg_cache & ~STATE_MASK) |
+                                       (STATE_OFF & STATE_MASK);
+       ret = tps80031_write(parent, SLAVE_ID1, ri->state_reg, reg_val);
        if (ret < 0)
-               dev_err(&rdev->dev, "Error in updating the STATE register\n");
-
+               dev_err(&rdev->dev, "Error in writing the STATE register\n");
+       else
+               ri->state_reg_cache = reg_val;
        return ret;
 }
 
@@ -213,7 +221,7 @@ static int tps80031dcdc_list_voltage(struct regulator_dev *rdev, unsigned index)
                if (index == 0)
                        voltage = 0;
                else if (index < 58)
-                       voltage = (600000 + (12500 * (index - 1)));
+                       voltage = (607700 + (12660 * (index - 1)));
                else if (index == 58)
                        voltage = 1350 * 1000;
                else if (index == 59)
@@ -282,22 +290,30 @@ static int tps80031dcdc_list_voltage(struct regulator_dev *rdev, unsigned index)
 }
 
 static int __tps80031_dcdc_set_voltage(struct device *parent,
-               struct tps80031_regulator *ri, int min_uV, int max_uV)
+                                      struct tps80031_regulator *ri,
+                                      int min_uV, int max_uV,
+                                      unsigned *selector)
 {
        int vsel = 0;
        int ret;
-       uint8_t force = 0;
 
        switch (ri->flags) {
        case 0:
+               if (min_uV >= (607700 + ri->tolerance_uv))
+                       min_uV = min_uV - ri->tolerance_uv;
+
                if (min_uV == 0)
                        vsel = 0;
-               else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
-                       vsel = (min_uV - 600000) / 125;
+               else if ((min_uV >= 607700) && (min_uV <= 1300000)) {
+                       int cal_volt;
+                       vsel = (10 * (min_uV - 607700)) / 1266;
                        if (vsel % 100)
                                vsel += 100;
                        vsel /= 100;
                        vsel++;
+                       cal_volt = (607700 + (12660 * (vsel - 1)));
+                       if (cal_volt > max_uV)
+                               return -EINVAL;
                } else if ((min_uV > 1900000) && (max_uV >= 2100000))
                        vsel = 62;
                else if ((min_uV > 1800000) && (max_uV >= 1900000))
@@ -313,19 +329,25 @@ static int __tps80031_dcdc_set_voltage(struct device *parent,
                break;
 
        case DCDC_OFFSET_EN:
+               if (min_uV >= (700000 + ri->tolerance_uv))
+                       min_uV = min_uV - ri->tolerance_uv;
                if (min_uV == 0)
                        vsel = 0;
-               else if ((min_uV >= 700000) && (max_uV <= 1420000)) {
-                       vsel = (min_uV - 600000) / 125;
+               else if ((min_uV >= 700000) && (min_uV <= 1420000)) {
+                       int cal_volt;
+                       vsel = (min_uV - 700000) / 125;
                        if (vsel % 100)
                                vsel += 100;
                        vsel /= 100;
                        vsel++;
+                       cal_volt = (700000 + (12500 * (vsel - 1)));
+                       if (cal_volt > max_uV)
+                               return -EINVAL;
                } else if ((min_uV > 1900000) && (max_uV >= 2100000))
                        vsel = 62;
                else if ((min_uV > 1800000) && (max_uV >= 1900000))
                        vsel = 61;
-               else if ((min_uV > 1350000) && (max_uV >= 1800000))
+               else if ((min_uV > 1500000) && (max_uV >= 1800000))
                        vsel = 60;
                else if ((min_uV > 1350000) && (max_uV >= 1500000))
                        vsel = 59;
@@ -336,22 +358,25 @@ static int __tps80031_dcdc_set_voltage(struct device *parent,
                break;
 
        case DCDC_EXTENDED_EN:
+               if (min_uV >= (1852000 + ri->tolerance_uv))
+                       min_uV = min_uV - ri->tolerance_uv;
                if (min_uV == 0)
                        vsel = 0;
                else if ((min_uV >= 1852000) && (max_uV <= 4013600)) {
                        vsel = (min_uV - 1852000) / 386;
                        if (vsel % 100)
                                vsel += 100;
-                       vsel /= 100;
                        vsel++;
                }
                break;
 
        case DCDC_OFFSET_EN|DCDC_EXTENDED_EN:
+               if (min_uV >= (2161000 + ri->tolerance_uv))
+                       min_uV = min_uV - ri->tolerance_uv;
                if (min_uV == 0)
                        vsel = 0;
                else if ((min_uV >= 2161000) && (max_uV <= 4321000)) {
-                       vsel = (min_uV - 1852000) / 386;
+                       vsel = (min_uV - 2161000) / 386;
                        if (vsel % 100)
                                vsel += 100;
                        vsel /= 100;
@@ -360,24 +385,26 @@ static int __tps80031_dcdc_set_voltage(struct device *parent,
                break;
        }
 
+       if (selector)
+               *selector = vsel;
+
        if (ri->force_reg) {
-               ret = tps80031_read(parent, ri->volt_id, ri->force_reg,
-                                               &force);
-               if (ret < 0) {
-                       dev_err(ri->dev, "Error in reading the force register\n");
-                       return ret;
-               }
-               if (((force >> 6) & 0x3) == 0) {
+               if (((ri->force_reg_cache >> 6) & 0x3) == 0) {
                        ret = tps80031_write(parent, ri->volt_id,
                                                ri->force_reg, vsel);
-                       goto out;
+                       if (ret < 0)
+                               dev_err(ri->dev, "Error in writing the "
+                                               "force register\n");
+                       else
+                               ri->force_reg_cache = vsel;
+                       return ret;
                }
        }
        ret = tps80031_write(parent, ri->volt_id, ri->volt_reg, vsel);
-
-out:
        if (ret < 0)
-               dev_err(ri->dev, "Error in updating the Voltage register\n");
+               dev_err(ri->dev, "Error in writing the Voltage register\n");
+       else
+               ri->volt_reg_cache = vsel;
        return ret;
 }
 
@@ -386,32 +413,23 @@ static int tps80031dcdc_set_voltage(struct regulator_dev *rdev,
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps80031_dev(rdev);
-       return __tps80031_dcdc_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps80031_dcdc_set_voltage(parent, ri, min_uV, max_uV,
+                                          selector);
 }
 
 static int tps80031dcdc_get_voltage(struct regulator_dev *rdev)
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
-       struct device *parent = to_tps80031_dev(rdev);
        uint8_t vsel = 0;
-       int ret;
        int voltage = 0;
 
        if (ri->force_reg) {
-               ret = tps80031_read(parent, ri->volt_id, ri->force_reg, &vsel);
-               if (ret < 0) {
-                       dev_err(&rdev->dev, "Error in reading the force register\n");
-                       return ret;
-               }
+               vsel  = ri->force_reg_cache;
                if ((vsel & SMPS_CMD_MASK) == 0)
                        goto decode;
        }
 
-       ret = tps80031_read(parent, ri->volt_id, ri->volt_reg, &vsel);
-       if (ret < 0) {
-               dev_err(&rdev->dev, "Error in reading the Voltage register\n");
-               return ret;
-       }
+       vsel =  ri->volt_reg_cache;
 
 decode:
        vsel &= SMPS_VSEL_MASK;
@@ -421,7 +439,7 @@ decode:
                if (vsel == 0)
                        voltage = 0;
                else if (vsel < 58)
-                       voltage = (600000 + (12500 * (vsel - 1)));
+                       voltage = (607700 + (12660 * (vsel - 1)));
                else if (vsel == 58)
                        voltage = 1350 * 1000;
                else if (vsel == 59)
@@ -496,26 +514,81 @@ static int tps80031ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
        if (index == 0)
                return 0;
 
+       if ((ri->desc.id == TPS80031_REGULATOR_LDO2) &&
+                       (ri->flags &  TRACK_MODE_ENABLE))
+               return (ri->min_mV + (((index - 1) * 125))/10) * 1000;
+
        return (ri->min_mV + ((index - 1) * 100)) * 1000;
 }
 
-static int __tps80031_ldo_set_voltage(struct device *parent,
+static int __tps80031_ldo2_set_voltage_track_mode(struct device *parent,
                struct tps80031_regulator *ri, int min_uV, int max_uV)
 {
+       int vsel = 0;
+       int ret;
+       int nvsel;
+
+       if (min_uV < 600000) {
+               vsel = 0;
+       } else if ((min_uV >= 600000) && (max_uV <= 1300000)) {
+               vsel = (min_uV - 600000) / 125;
+               if (vsel % 100)
+                       vsel += 100;
+               vsel /= 100;
+               vsel++;
+       } else {
+               return -EINVAL;
+       }
+
+       /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
+       if ((tps80031_get_chip_info(parent) == TPS80031) ||
+               ((tps80031_get_chip_info(parent) == TPS80032) &&
+               (tps80031_get_pmu_version(parent) == 0x0))) {
+               nvsel = vsel & 0x1F;
+               if ((nvsel == 0x0) || (nvsel >= 0x19 && nvsel <= 0x1F)) {
+                       dev_err(ri->dev, "Invalid value for track mode LDO2 "
+                               "configuration for TPS8003x PMU\n");
+                       return -EINVAL;
+               }
+       }
+
+       ret = tps80031_write(parent, ri->volt_id, ri->volt_reg, vsel);
+       if (ret < 0)
+               dev_err(ri->dev, "Error in writing the Voltage register\n");
+       else
+               ri->volt_reg_cache = vsel;
+       return ret;
+}
+
+
+static int __tps80031_ldo_set_voltage(struct device *parent,
+                                     struct tps80031_regulator *ri,
+                                     int min_uV, int max_uV,
+                                     unsigned *selector)
+{
        int vsel;
        int ret;
 
        if ((min_uV/1000 < ri->min_mV) || (max_uV/1000 > ri->max_mV))
                return -EDOM;
 
+       if ((ri->desc.id == TPS80031_REGULATOR_LDO2) &&
+                       (ri->flags &  TRACK_MODE_ENABLE))
+               return __tps80031_ldo2_set_voltage_track_mode(parent, ri,
+                               min_uV, max_uV);
+
        /*
         * Use the below formula to calculate vsel
         * mV = 1000mv + 100mv * (vsel - 1)
         */
        vsel = (min_uV/1000 - 1000)/100 + 1;
+       if (selector)
+               *selector = vsel;
        ret = tps80031_write(parent, ri->volt_id, ri->volt_reg, vsel);
        if (ret < 0)
                dev_err(ri->dev, "Error in writing the Voltage register\n");
+       else
+               ri->volt_reg_cache = vsel;
        return ret;
 }
 
@@ -525,23 +598,23 @@ static int tps80031ldo_set_voltage(struct regulator_dev *rdev,
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps80031_dev(rdev);
 
-       return __tps80031_ldo_set_voltage(parent, ri, min_uV, max_uV);
+       return __tps80031_ldo_set_voltage(parent, ri, min_uV, max_uV,
+                                         selector);
 }
 
 static int tps80031ldo_get_voltage(struct regulator_dev *rdev)
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
-       struct device *parent = to_tps80031_dev(rdev);
        uint8_t vsel;
-       int ret;
 
-       ret = tps80031_read(parent, ri->volt_id, ri->volt_reg, &vsel);
-       if (ret < 0) {
-               dev_err(&rdev->dev, "Error in reading the Voltage register\n");
-               return ret;
+
+       if ((ri->desc.id == TPS80031_REGULATOR_LDO2) &&
+                       (ri->flags &  TRACK_MODE_ENABLE)) {
+               vsel = ri->volt_reg_cache & 0x3F;
+               return (ri->min_mV + (((vsel - 1) * 125))/10) * 1000;
        }
-       vsel &= LDO_VSEL_MASK;
 
+       vsel = ri->volt_reg_cache & LDO_VSEL_MASK;
        /*
         * Use the below formula to calculate vsel
         * mV = 1000mv + 100mv * (vsel - 1)
@@ -550,6 +623,11 @@ static int tps80031ldo_get_voltage(struct regulator_dev *rdev)
 }
 
 /* VBUS */
+static int tps80031_vbus_enable_time(struct regulator_dev *rdev)
+{
+       /* Enable and settling time for vbus is 3ms */
+       return 3000;
+}
 static int tps80031_vbus_is_enabled(struct regulator_dev *rdev)
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
@@ -603,19 +681,28 @@ static int tps80031_vbus_disable(struct regulator_dev *rdev)
 {
        struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
        struct device *parent = to_tps80031_dev(rdev);
-       int ret;
+       int ret = 0;
 
        if (ri->platform_flags & VBUS_SW_ONLY) {
-               ret = tps80031_clr_bits(parent, SLAVE_ID2,
+
+               if (ri->platform_flags & VBUS_DISCHRG_EN_PDN)
+                       ret = tps80031_write(parent, SLAVE_ID2,
+                               USB_VBUS_CTRL_SET, VBUS_DISCHRG);
+               if (!ret)
+                       ret = tps80031_clr_bits(parent, SLAVE_ID2,
                                CHARGERUSB_CTRL1_ADD,  OPA_MODE_EN);
                if (!ret)
                        ret = tps80031_clr_bits(parent, SLAVE_ID2,
                                        CHARGERUSB_CTRL3_ADD, BOOST_HW_PWR_EN);
-               if (ret < 0) {
+               if (!ret)
+                       mdelay((ri->delay + 999)/1000);
+
+               if (ri->platform_flags & VBUS_DISCHRG_EN_PDN)
+                       tps80031_write(parent, SLAVE_ID2,
+                               USB_VBUS_CTRL_CLR, VBUS_DISCHRG);
+
+               if (ret < 0)
                        dev_err(&rdev->dev, "Error in reading control reg\n");
-                       return ret;
-               }
-               udelay(ri->delay);
                return ret;
        }
        dev_err(&rdev->dev, "%s() is not supported with flag 0x%08x\n",
@@ -657,7 +744,7 @@ static struct regulator_ops tps80031vbus_ops = {
        .enable         = tps80031_vbus_enable,
        .disable        = tps80031_vbus_disable,
        .is_enabled     = tps80031_vbus_is_enabled,
-       .enable_time    = tps80031_regulator_enable_time,
+       .enable_time    = tps80031_vbus_enable_time,
 };
 
 #define TPS80031_REG(_id, _trans_reg, _state_reg, _force_reg, _volt_reg, \
@@ -669,12 +756,12 @@ static struct regulator_ops tps80031vbus_ops = {
        .force_reg = _force_reg,                                \
        .volt_reg = _volt_reg,                                  \
        .volt_id = _volt_id,                                    \
-       .id = TPS80031_ID_##_id,                                \
+       .id = TPS80031_REGULATOR_##_id,                         \
        .min_mV = min_mVolts,                                   \
        .max_mV = max_mVolts,                                   \
        .desc = {                                               \
                .name = tps80031_rails(_id),                    \
-               .id = TPS80031_ID_##_id,                        \
+               .id = TPS80031_REGULATOR_##_id,                 \
                .n_voltages = _n_volt,                          \
                .ops = &_ops,                                   \
                .type = REGULATOR_VOLTAGE,                      \
@@ -717,60 +804,47 @@ static struct tps80031_regulator tps80031_regulator[] = {
        TPS80031_REG(VANA,   0x81, 0x82, 0x00, 0x83, SLAVE_ID1, 1000, 3300,
                                tps80031ldo_ops, 25, 500, -1),
        TPS80031_REG(VBUS,   0x0,  0x0,  0x00, 0x0,  SLAVE_ID1, 0,    5000,
-                               tps80031vbus_ops, 2, 500, -1),
+                               tps80031vbus_ops, 2, 200000, -1),
 };
 
 static int tps80031_power_req_config(struct device *parent,
                struct tps80031_regulator *ri,
                struct tps80031_regulator_platform_data *tps80031_pdata)
 {
-       u8 res_ass_reg;
-       int preq_bit;
-       int preq_mask_bit;
-       int ret;
+       int ret = 0;
+       uint8_t reg_val;
 
-       if (!(ri->platform_flags & EXT_PWR_REQ))
-               return 0;
+       if (ri->preq_bit < 0)
+               goto skip_pwr_req_config;
 
-       preq_bit = ri->preq_bit & 0x7;
-       if (ri->platform_flags & PWR_REQ_INPUT_PREQ1) {
-               res_ass_reg = TPS80031_PREQ1_RES_ASS_A + (ri->preq_bit >> 3);
-               preq_mask_bit = 5;
-       } else if (ri->platform_flags & PWR_REQ_INPUT_PREQ2) {
-               res_ass_reg = TPS80031_PREQ2_RES_ASS_A + (ri->preq_bit >> 3);
-               preq_mask_bit = 6;
-       } else if (ri->platform_flags & PWR_REQ_INPUT_PREQ3) {
-               res_ass_reg = TPS80031_PREQ3_RES_ASS_A + (ri->preq_bit >> 3);
-               preq_mask_bit = 7;
-       }
+       ret = tps80031_ext_power_req_config(parent, ri->ext_ctrl_flag,
+                       ri->preq_bit, ri->state_reg, ri->trans_reg);
+       if (!ret)
+               ret = tps80031_read(parent, SLAVE_ID1, ri->trans_reg,
+                       &ri->trans_reg_cache);
 
-       /* Configure REQ_ASS registers */
-       ret = tps80031_set_bits(parent, SLAVE_ID1, res_ass_reg, BIT(preq_bit));
+       if (!ret && ri->state_reg)
+               ret = tps80031_read(parent, SLAVE_ID1, ri->state_reg,
+                       &ri->state_reg_cache);
        if (ret < 0) {
-               dev_err(ri->dev, "%s() Not able to set bit %d of "
-                       "reg %d error %d\n",
-                       __func__, preq_bit, res_ass_reg, ret);
+               dev_err(ri->dev, "%s() fails\n", __func__);
                return ret;
        }
 
-       /* Unmask the PREQ */
-       ret = tps80031_clr_bits(parent, SLAVE_ID1,
-                       TPS80031_PHOENIX_MSK_TRANSITION, BIT(preq_mask_bit));
-       if (ret < 0) {
-               dev_err(ri->dev, "%s() Not able to clear bit %d of "
-                       "reg %d error %d\n",
-                        __func__, preq_mask_bit,
-                       TPS80031_PHOENIX_MSK_TRANSITION, ret);
-               return ret;
-       }
-
-       /* Switch regulator control to resource now */
-       ret = tps80031_update(parent, SLAVE_ID1, ri->state_reg, 0x0,
-                                       STATE_MASK);
-       if (ret < 0) {
-               dev_err(ri->dev, "%s() Error in updating the STATE "
-                               "register error %d\n", __func__, ret);
-               return ret;
+skip_pwr_req_config:
+       if (tps80031_pdata->ext_ctrl_flag &
+                       (PWR_OFF_ON_SLEEP | PWR_ON_ON_SLEEP)) {
+               reg_val = (ri->trans_reg_cache & ~0xC);
+               if (tps80031_pdata->ext_ctrl_flag & PWR_ON_ON_SLEEP)
+                       reg_val |= 0x4;
+
+               ret = tps80031_write(parent, SLAVE_ID1, ri->trans_reg,
+                       reg_val);
+               if (ret < 0)
+                       dev_err(ri->dev, "Not able to write reg 0x%02x\n",
+                               ri->trans_reg);
+               else
+                       ri->trans_reg_cache = reg_val;
        }
        return ret;
 }
@@ -780,8 +854,9 @@ static int tps80031_regulator_preinit(struct device *parent,
                struct tps80031_regulator_platform_data *tps80031_pdata)
 {
        int ret = 0;
+       uint8_t reg_val;
 
-       if (ri->desc.id == TPS80031_ID_LDOUSB) {
+       if (ri->desc.id == TPS80031_REGULATOR_LDOUSB) {
                if (ri->platform_flags & USBLDO_INPUT_VSYS)
                        ret = tps80031_update(parent, SLAVE_ID1,
                                TPS80031_MISC2_ADD,
@@ -797,7 +872,7 @@ static int tps80031_regulator_preinit(struct device *parent,
                }
        }
 
-       if (ri->desc.id == TPS80031_ID_LDO3) {
+       if (ri->desc.id == TPS80031_REGULATOR_LDO3) {
                if (ri->platform_flags & LDO3_OUTPUT_VIB)
                        ret = tps80031_update(parent, SLAVE_ID1,
                                TPS80031_MISC2_ADD,
@@ -822,7 +897,7 @@ static int tps80031_regulator_preinit(struct device *parent,
                case TPS80031_ID_SMPS4:
                        ret = __tps80031_dcdc_set_voltage(parent, ri,
                                        tps80031_pdata->init_uV,
-                                       tps80031_pdata->init_uV);
+                                       tps80031_pdata->init_uV, 0);
                        break;
 
                case TPS80031_ID_LDO1:
@@ -837,7 +912,7 @@ static int tps80031_regulator_preinit(struct device *parent,
                case TPS80031_ID_VANA:
                        ret = __tps80031_ldo_set_voltage(parent, ri,
                                        tps80031_pdata->init_uV,
-                                       tps80031_pdata->init_uV);
+                                       tps80031_pdata->init_uV, 0);
                        break;
                default:
                        ret = -EINVAL;
@@ -853,15 +928,19 @@ static int tps80031_regulator_preinit(struct device *parent,
        }
 
        if (tps80031_pdata->init_enable)
-               ret = tps80031_force_update(parent, SLAVE_ID1, ri->state_reg,
-                                           STATE_ON, STATE_MASK);
+               reg_val = (ri->state_reg_cache & ~STATE_MASK) |
+                               (STATE_ON & STATE_MASK);
        else
-               ret = tps80031_force_update(parent, SLAVE_ID1, ri->state_reg,
-                                           STATE_OFF, STATE_MASK);
+               reg_val = (ri->state_reg_cache & ~STATE_MASK) |
+                               (STATE_OFF & STATE_MASK);
+
+       ret = tps80031_write(parent, SLAVE_ID1, ri->state_reg, reg_val);
        if (ret < 0)
                dev_err(ri->dev, "Not able to %s rail %d err %d\n",
                        (tps80031_pdata->init_enable) ? "enable" : "disable",
                        ri->desc.id, ret);
+       else
+               ri->state_reg_cache = reg_val;
        return ret;
 }
 
@@ -882,21 +961,31 @@ static void check_smps_mode_mult(struct device *parent,
 {
        int mult_offset;
        switch (ri->desc.id) {
-       case TPS80031_ID_VIO:
+       case TPS80031_REGULATOR_VIO:
                mult_offset = SMPS_MULTOFFSET_VIO;
                break;
-       case TPS80031_ID_SMPS1:
+       case TPS80031_REGULATOR_SMPS1:
                mult_offset = SMPS_MULTOFFSET_SMPS1;
                break;
-       case TPS80031_ID_SMPS2:
+       case TPS80031_REGULATOR_SMPS2:
                mult_offset = SMPS_MULTOFFSET_SMPS2;
                break;
-       case TPS80031_ID_SMPS3:
+       case TPS80031_REGULATOR_SMPS3:
                mult_offset = SMPS_MULTOFFSET_SMPS3;
                break;
-       case TPS80031_ID_SMPS4:
+       case TPS80031_REGULATOR_SMPS4:
                mult_offset = SMPS_MULTOFFSET_SMPS4;
                break;
+       case TPS80031_REGULATOR_LDO2:
+               ri->flags = (tps80031_get_smps_mult(parent) & (1 << 5)) ?
+                                               TRACK_MODE_ENABLE : 0;
+               /* TRACK mode the ldo2 varies from 600mV to 1300mV */
+               if (ri->flags & TRACK_MODE_ENABLE) {
+                       ri->min_mV = 600;
+                       ri->max_mV = 1300;
+                       ri->desc.n_voltages = 57;
+               }
+               return;
        default:
                return;
        }
@@ -908,6 +997,25 @@ static void check_smps_mode_mult(struct device *parent,
        return;
 }
 
+static inline int tps80031_cache_regulator_register(struct device *parent,
+       struct tps80031_regulator *ri)
+{
+       int ret;
+
+       ret = tps80031_read(parent, SLAVE_ID1, ri->trans_reg,
+                       &ri->trans_reg_cache);
+       if (!ret && ri->state_reg)
+               ret = tps80031_read(parent, SLAVE_ID1, ri->state_reg,
+                       &ri->state_reg_cache);
+       if (!ret && ri->force_reg)
+               ret = tps80031_read(parent, ri->volt_id, ri->force_reg,
+                       &ri->force_reg_cache);
+       if (!ret && ri->volt_reg)
+               ret = tps80031_read(parent, ri->volt_id, ri->volt_reg,
+                       &ri->volt_reg_cache);
+       return ret;
+}
+
 static int __devinit tps80031_regulator_probe(struct platform_device *pdev)
 {
        struct tps80031_regulator *ri = NULL;
@@ -925,10 +1033,19 @@ static int __devinit tps80031_regulator_probe(struct platform_device *pdev)
        }
        tps_pdata = pdev->dev.platform_data;
        ri->dev = &pdev->dev;
+       if (tps_pdata->delay_us > 0)
+               ri->delay = tps_pdata->delay_us;
+       ri->tolerance_uv = tps_pdata->tolerance_uv;
 
        check_smps_mode_mult(pdev->dev.parent, ri);
        ri->platform_flags = tps_pdata->flags;
+       ri->ext_ctrl_flag = tps_pdata->ext_ctrl_flag;
 
+       err = tps80031_cache_regulator_register(pdev->dev.parent, ri);
+       if (err) {
+               dev_err(&pdev->dev, "Register access for caching is failed\n");
+               return err;
+       }
        err = tps80031_regulator_preinit(pdev->dev.parent, ri, tps_pdata);
        if (err)
                return err;