Revert "Revert "regulator: tps80031: rename regulator-name enums""
[linux-2.6.git] / drivers / regulator / tps80031-regulator.c
index 4b1df36..9250123 100644 (file)
@@ -100,6 +100,7 @@ struct tps80031_regulator {
        /* chip constraints on regulator behavior */
        u16                     min_mV;
        u16                     max_mV;
+       unsigned int            tolerance_uv;
 
        /* regulator specific turn-on delay */
        int                     delay;
@@ -298,6 +299,9 @@ static int __tps80031_dcdc_set_voltage(struct device *parent,
 
        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 >= 607700) && (min_uV <= 1300000)) {
@@ -325,6 +329,8 @@ 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) && (min_uV <= 1420000)) {
@@ -352,6 +358,8 @@ 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)) {
@@ -363,6 +371,8 @@ static int __tps80031_dcdc_set_voltage(struct device *parent,
                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)) {
@@ -504,7 +514,7 @@ static int tps80031ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
        if (index == 0)
                return 0;
 
-       if ((ri->desc.id == TPS80031_ID_LDO2) &&
+       if ((ri->desc.id == TPS80031_REGULATOR_LDO2) &&
                        (ri->flags &  TRACK_MODE_ENABLE))
                return (ri->min_mV + (((index - 1) * 125))/10) * 1000;
 
@@ -562,7 +572,7 @@ static int __tps80031_ldo_set_voltage(struct device *parent,
        if ((min_uV/1000 < ri->min_mV) || (max_uV/1000 > ri->max_mV))
                return -EDOM;
 
-       if ((ri->desc.id == TPS80031_ID_LDO2) &&
+       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);
@@ -598,7 +608,7 @@ static int tps80031ldo_get_voltage(struct regulator_dev *rdev)
        uint8_t vsel;
 
 
-       if ((ri->desc.id == TPS80031_ID_LDO2) &&
+       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;
@@ -746,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,                      \
@@ -846,7 +856,7 @@ static int tps80031_regulator_preinit(struct device *parent,
        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,
@@ -862,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,
@@ -951,22 +961,22 @@ 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_ID_LDO2:
+       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 */
@@ -1025,6 +1035,7 @@ static int __devinit tps80031_regulator_probe(struct platform_device *pdev)
        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;