]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/regulator/tps65217-regulator.c
Merge branch 'x86-atomic-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-bionic-kernel.git] / drivers / regulator / tps65217-regulator.c
index 66655668f965c17f54116234a37b208817b68e06..e39521b427723179f192fecbbba69ee50d2d7e06 100644 (file)
@@ -82,11 +82,11 @@ static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel)
                return -EINVAL;
 
        if (uV <= 1500000)
-               *vsel = (uV - 875001) / 25000;
+               *vsel = DIV_ROUND_UP(uV - 900000, 25000);
        else if (uV <= 2900000)
-               *vsel = 24 + (uV - 1450001) / 50000;
+               *vsel = 24 + DIV_ROUND_UP(uV - 1500000, 50000);
        else if (uV < 3300000)
-               *vsel = 52 + (uV - 2800001) / 100000;
+               *vsel = 52 + DIV_ROUND_UP(uV - 2900000, 100000);
        else
                *vsel = 56;
 
@@ -116,11 +116,11 @@ static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
                return -EINVAL;
 
        if (uV <= 1900000)
-               *vsel = (uV - 1450001) / 50000;
+               *vsel = DIV_ROUND_UP(uV - 1500000, 50000);
        else if (uV <= 2400000)
-               *vsel = 8 + (uV - 1800001) / 100000;
+               *vsel = 8 + DIV_ROUND_UP(uV - 1900000, 100000);
        else
-               *vsel = 13 + (uV - 2350001) / 50000;
+               *vsel = 13 + DIV_ROUND_UP(uV - 2400000, 50000);
 
        return 0;
 }
@@ -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)
@@ -447,7 +333,7 @@ static int __devinit tps65217_regulator_probe(struct platform_device *pdev)
        tps->info[pdev->id] = info;
 
        rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
-                                 pdev->dev.platform_data, tps);
+                                 pdev->dev.platform_data, tps, NULL);
        if (IS_ERR(rdev))
                return PTR_ERR(rdev);
 
@@ -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");