]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/regulator/tps65217-regulator.c
regulator: Merge tps65217_pmic_ldo234_ops and tps65217_pmic_dcdc_ops to tps65217_pmic_ops
[mv-sheeva.git] / drivers / regulator / tps65217-regulator.c
index 15f2fa0bb0058edd54f6e4b6475f6d14255d687c..e39521b427723179f192fecbbba69ee50d2d7e06 100644 (file)
@@ -151,166 +151,69 @@ static struct tps_info tps65217_pmic_regs[] = {
                        TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK),
 };
 
-static int tps65217_pmic_dcdc_is_enabled(struct regulator_dev *dev)
+static int tps65217_pmic_is_enabled(struct regulator_dev *dev)
 {
        int ret;
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int data, dcdc = rdev_get_id(dev);
+       unsigned int data, rid = rdev_get_id(dev);
 
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
        ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data);
        if (ret)
                return ret;
 
-       return (data & tps->info[dcdc]->enable_mask) ? 1 : 0;
+       return (data & tps->info[rid]->enable_mask) ? 1 : 0;
 }
 
-static int tps65217_pmic_ldo_is_enabled(struct regulator_dev *dev)
+static int tps65217_pmic_enable(struct regulator_dev *dev)
 {
-       int ret;
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int data, ldo = rdev_get_id(dev);
+       unsigned int rid = rdev_get_id(dev);
 
-       if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
-               return -EINVAL;
-
-       ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data);
-       if (ret)
-               return ret;
-
-       return (data & tps->info[ldo]->enable_mask) ? 1 : 0;
-}
-
-static int tps65217_pmic_dcdc_enable(struct regulator_dev *dev)
-{
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int dcdc = rdev_get_id(dev);
-
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
        /* Enable the regulator and password protection is level 1 */
        return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
-                               tps->info[dcdc]->enable_mask,
-                               tps->info[dcdc]->enable_mask,
+                               tps->info[rid]->enable_mask,
+                               tps->info[rid]->enable_mask,
                                TPS65217_PROTECT_L1);
 }
 
-static int tps65217_pmic_dcdc_disable(struct regulator_dev *dev)
+static int tps65217_pmic_disable(struct regulator_dev *dev)
 {
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int dcdc = rdev_get_id(dev);
+       unsigned int rid = rdev_get_id(dev);
 
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
        /* Disable the regulator and password protection is level 1 */
        return tps65217_clear_bits(tps, TPS65217_REG_ENABLE,
-                       tps->info[dcdc]->enable_mask, TPS65217_PROTECT_L1);
-}
-
-static int tps65217_pmic_ldo_enable(struct regulator_dev *dev)
-{
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int ldo = rdev_get_id(dev);
-
-       if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
-               return -EINVAL;
-
-       /* Enable the regulator and password protection is level 1 */
-       return tps65217_set_bits(tps, TPS65217_REG_ENABLE,
-                               tps->info[ldo]->enable_mask,
-                               tps->info[ldo]->enable_mask,
-                               TPS65217_PROTECT_L1);
-}
-
-static int tps65217_pmic_ldo_disable(struct regulator_dev *dev)
-{
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int ldo = rdev_get_id(dev);
-
-       if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
-               return -EINVAL;
-
-       /* Disable the regulator and password protection is level 1 */
-       return tps65217_clear_bits(tps, TPS65217_REG_ENABLE,
-                       tps->info[ldo]->enable_mask, TPS65217_PROTECT_L1);
-}
-
-static int tps65217_pmic_dcdc_get_voltage_sel(struct regulator_dev *dev)
-{
-       int ret;
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int selector, dcdc = rdev_get_id(dev);
-
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
-               return -EINVAL;
-
-       ret = tps65217_reg_read(tps, tps->info[dcdc]->set_vout_reg, &selector);
-       if (ret)
-               return ret;
-
-       selector &= tps->info[dcdc]->set_vout_mask;
-
-       return selector;
+                       tps->info[rid]->enable_mask, TPS65217_PROTECT_L1);
 }
 
-static int tps65217_pmic_dcdc_set_voltage(struct regulator_dev *dev,
-                                 int min_uV, int max_uV, unsigned *selector)
+static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev)
 {
        int ret;
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int dcdc = rdev_get_id(dev);
-
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
-               return -EINVAL;
+       unsigned int selector, rid = rdev_get_id(dev);
 
-       if (min_uV < tps->info[dcdc]->min_uV
-               || min_uV > tps->info[dcdc]->max_uV)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
-       if (max_uV < tps->info[dcdc]->min_uV
-               || max_uV > tps->info[dcdc]->max_uV)
-               return -EINVAL;
-
-       ret = tps->info[dcdc]->uv_to_vsel(min_uV, selector);
+       ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector);
        if (ret)
                return ret;
 
-       /* Set the voltage based on vsel value and write protect level is 2 */
-       ret = tps65217_set_bits(tps, tps->info[dcdc]->set_vout_reg,
-                                       tps->info[dcdc]->set_vout_mask,
-                                       *selector, TPS65217_PROTECT_L2);
-       if (ret)
-               return ret;
-
-       /* Set GO bit to initiate voltage transistion */
-       return tps65217_set_bits(tps, TPS65217_REG_DEFSLEW,
-                               TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO,
-                               TPS65217_PROTECT_L2);
-}
-
-static int tps65217_pmic_ldo_get_voltage_sel(struct regulator_dev *dev)
-{
-       int ret;
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int selector, ldo = rdev_get_id(dev);
-
-       if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
-               return -EINVAL;
-
-       ret = tps65217_reg_read(tps, tps->info[ldo]->set_vout_reg, &selector);
-       if (ret)
-               return ret;
-
-       selector &= tps->info[ldo]->set_vout_mask;
+       selector &= tps->info[rid]->set_vout_mask;
 
        return selector;
 }
 
-static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev,
+static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev,
                                                unsigned selector)
 {
        struct tps65217 *tps = rdev_get_drvdata(dev);
@@ -328,112 +231,95 @@ static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev,
                                        selector, TPS65217_PROTECT_L2);
 }
 
-static int tps65217_pmic_ldo_set_voltage(struct regulator_dev *dev,
+static int tps65217_pmic_set_voltage(struct regulator_dev *dev,
                                  int min_uV, int max_uV, unsigned *selector)
 {
        int ret;
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int ldo = rdev_get_id(dev);
+       unsigned int rid = rdev_get_id(dev);
 
-       if (ldo < TPS65217_LDO_2 || ldo > TPS65217_LDO_4)
+       /* LDO1 implements set_voltage_sel callback */
+       if (rid == TPS65217_LDO_1)
                return -EINVAL;
 
-       if (min_uV < tps->info[ldo]->min_uV
-               || min_uV > tps->info[ldo]->max_uV)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
-       if (max_uV < tps->info[ldo]->min_uV
-               || max_uV > tps->info[ldo]->max_uV)
+       if (min_uV < tps->info[rid]->min_uV
+               || min_uV > tps->info[rid]->max_uV)
                return -EINVAL;
 
-       ret = tps->info[ldo]->uv_to_vsel(min_uV, selector);
+       if (max_uV < tps->info[rid]->min_uV
+               || max_uV > tps->info[rid]->max_uV)
+               return -EINVAL;
+
+       ret = tps->info[rid]->uv_to_vsel(min_uV, selector);
        if (ret)
                return ret;
 
        /* Set the voltage based on vsel value and write protect level is 2 */
-       return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg,
-                                       tps->info[ldo]->set_vout_mask,
-                                       *selector, TPS65217_PROTECT_L2);
-}
-
-static int tps65217_pmic_dcdc_list_voltage(struct regulator_dev *dev,
-                                       unsigned selector)
-{
-       struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int dcdc = rdev_get_id(dev);
-
-       if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3)
-               return -EINVAL;
-
-       if (selector >= tps->info[dcdc]->table_len)
-               return -EINVAL;
+       ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg,
+                               tps->info[rid]->set_vout_mask,
+                               *selector, TPS65217_PROTECT_L2);
+
+       /* Set GO bit for DCDCx to initiate voltage transistion */
+       switch (rid) {
+       case TPS65217_DCDC_1 ... TPS65217_DCDC_3:
+               ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW,
+                                      TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO,
+                                      TPS65217_PROTECT_L2);
+               break;
+       }
 
-       return tps->info[dcdc]->vsel_to_uv(selector);
+       return ret;
 }
 
-static int tps65217_pmic_ldo_list_voltage(struct regulator_dev *dev,
+static int tps65217_pmic_list_voltage(struct regulator_dev *dev,
                                        unsigned selector)
 {
        struct tps65217 *tps = rdev_get_drvdata(dev);
-       unsigned int ldo = rdev_get_id(dev);
+       unsigned int rid = rdev_get_id(dev);
 
-       if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4)
+       if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
                return -EINVAL;
 
-       if (selector >= tps->info[ldo]->table_len)
+       if (selector >= tps->info[rid]->table_len)
                return -EINVAL;
 
-       if (tps->info[ldo]->table)
-               return tps->info[ldo]->table[selector];
+       if (tps->info[rid]->table)
+               return tps->info[rid]->table[selector];
 
-       return tps->info[ldo]->vsel_to_uv(selector);
+       return tps->info[rid]->vsel_to_uv(selector);
 }
 
-/* Operations permitted on DCDCx */
-static struct regulator_ops tps65217_pmic_dcdc_ops = {
-       .is_enabled             = tps65217_pmic_dcdc_is_enabled,
-       .enable                 = tps65217_pmic_dcdc_enable,
-       .disable                = tps65217_pmic_dcdc_disable,
-       .get_voltage_sel        = tps65217_pmic_dcdc_get_voltage_sel,
-       .set_voltage            = tps65217_pmic_dcdc_set_voltage,
-       .list_voltage           = tps65217_pmic_dcdc_list_voltage,
+/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
+static struct regulator_ops tps65217_pmic_ops = {
+       .is_enabled             = tps65217_pmic_is_enabled,
+       .enable                 = tps65217_pmic_enable,
+       .disable                = tps65217_pmic_disable,
+       .get_voltage_sel        = tps65217_pmic_get_voltage_sel,
+       .set_voltage            = tps65217_pmic_set_voltage,
+       .list_voltage           = tps65217_pmic_list_voltage,
 };
 
 /* Operations permitted on LDO1 */
 static struct regulator_ops tps65217_pmic_ldo1_ops = {
-       .is_enabled             = tps65217_pmic_ldo_is_enabled,
-       .enable                 = tps65217_pmic_ldo_enable,
-       .disable                = tps65217_pmic_ldo_disable,
-       .get_voltage_sel        = tps65217_pmic_ldo_get_voltage_sel,
-       .set_voltage_sel        = tps65217_pmic_ldo_set_voltage_sel,
-       .list_voltage           = tps65217_pmic_ldo_list_voltage,
-};
-
-/* Operations permitted on LDO2, LDO3 and LDO4 */
-static struct regulator_ops tps65217_pmic_ldo234_ops = {
-       .is_enabled             = tps65217_pmic_ldo_is_enabled,
-       .enable                 = tps65217_pmic_ldo_enable,
-       .disable                = tps65217_pmic_ldo_disable,
-       .get_voltage_sel        = tps65217_pmic_ldo_get_voltage_sel,
-       .set_voltage            = tps65217_pmic_ldo_set_voltage,
-       .list_voltage           = tps65217_pmic_ldo_list_voltage,
+       .is_enabled             = tps65217_pmic_is_enabled,
+       .enable                 = tps65217_pmic_enable,
+       .disable                = tps65217_pmic_disable,
+       .get_voltage_sel        = tps65217_pmic_get_voltage_sel,
+       .set_voltage_sel        = tps65217_pmic_ldo1_set_voltage_sel,
+       .list_voltage           = tps65217_pmic_list_voltage,
 };
 
 static struct regulator_desc regulators[] = {
-       TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1,
-                               tps65217_pmic_dcdc_ops, 64),
-       TPS65217_REGULATOR("DCDC2",TPS65217_DCDC_2,
-                               tps65217_pmic_dcdc_ops, 64),
-       TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3,
-                               tps65217_pmic_dcdc_ops, 64),
-       TPS65217_REGULATOR("LDO1", TPS65217_LDO_1,
-                               tps65217_pmic_ldo1_ops, 16),
-       TPS65217_REGULATOR("LDO2", TPS65217_LDO_2,
-                               tps65217_pmic_ldo234_ops, 64),
-       TPS65217_REGULATOR("LDO3", TPS65217_LDO_3,
-                               tps65217_pmic_ldo234_ops, 32),
-       TPS65217_REGULATOR("LDO4", TPS65217_LDO_4,
-                               tps65217_pmic_ldo234_ops, 32),
+       TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64),
+       TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64),
+       TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64),
+       TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16),
+       TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64),
+       TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32),
+       TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32),
 };
 
 static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
@@ -486,7 +372,6 @@ static void __exit tps65217_regulator_exit(void)
 }
 module_exit(tps65217_regulator_exit);
 
-
 MODULE_AUTHOR("AnilKumar Ch <anilkumar@ti.com>");
 MODULE_DESCRIPTION("TPS65217 voltage regulator driver");
 MODULE_ALIAS("platform:tps65217-pmic");