]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/regulator/bd718x7-regulator.c
Merge tag 'xfs-5.6-merge-8' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux.git] / drivers / regulator / bd718x7-regulator.c
index 8f9b2d8eaf10c98e51e53e29b94f00f47a30197f..cf3872837abcc9f72c383c43fe6caacba1e3b029 100644 (file)
@@ -318,6 +318,7 @@ struct reg_init {
 };
 struct bd718xx_regulator_data {
        struct regulator_desc desc;
+       const struct rohm_dvs_config dvs;
        const struct reg_init init;
        const struct reg_init *additional_inits;
        int additional_init_amnt;
@@ -349,133 +350,15 @@ static const struct reg_init bd71837_ldo6_inits[] = {
        },
 };
 
-#define NUM_DVS_BUCKS 4
-
-struct of_dvs_setting {
-       const char *prop;
-       unsigned int reg;
-};
-
-static int set_dvs_levels(const struct of_dvs_setting *dvs,
-                         struct device_node *np,
-                         const struct regulator_desc *desc,
-                         struct regmap *regmap)
-{
-       int ret, i;
-       unsigned int uv;
-
-       ret = of_property_read_u32(np, dvs->prop, &uv);
-       if (ret) {
-               if (ret != -EINVAL)
-                       return ret;
-               return 0;
-       }
-
-       for (i = 0; i < desc->n_voltages; i++) {
-               ret = regulator_desc_list_voltage_linear_range(desc, i);
-               if (ret < 0)
-                       continue;
-               if (ret == uv) {
-                       i <<= ffs(desc->vsel_mask) - 1;
-                       ret = regmap_update_bits(regmap, dvs->reg,
-                                                DVS_BUCK_RUN_MASK, i);
-                       break;
-               }
-       }
-       return ret;
-}
-
-static int buck4_set_hw_dvs_levels(struct device_node *np,
+static int buck_set_hw_dvs_levels(struct device_node *np,
                            const struct regulator_desc *desc,
                            struct regulator_config *cfg)
 {
-       int ret, i;
-       const struct of_dvs_setting dvs[] = {
-               {
-                       .prop = "rohm,dvs-run-voltage",
-                       .reg = BD71837_REG_BUCK4_VOLT_RUN,
-               },
-       };
+       struct bd718xx_regulator_data *data;
 
-       for (i = 0; i < ARRAY_SIZE(dvs); i++) {
-               ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
-               if (ret)
-                       break;
-       }
-       return ret;
-}
-static int buck3_set_hw_dvs_levels(struct device_node *np,
-                           const struct regulator_desc *desc,
-                           struct regulator_config *cfg)
-{
-       int ret, i;
-       const struct of_dvs_setting dvs[] = {
-               {
-                       .prop = "rohm,dvs-run-voltage",
-                       .reg = BD71837_REG_BUCK3_VOLT_RUN,
-               },
-       };
+       data = container_of(desc, struct bd718xx_regulator_data, desc);
 
-       for (i = 0; i < ARRAY_SIZE(dvs); i++) {
-               ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
-               if (ret)
-                       break;
-       }
-       return ret;
-}
-
-static int buck2_set_hw_dvs_levels(struct device_node *np,
-                           const struct regulator_desc *desc,
-                           struct regulator_config *cfg)
-{
-       int ret, i;
-       const struct of_dvs_setting dvs[] = {
-               {
-                       .prop = "rohm,dvs-run-voltage",
-                       .reg = BD718XX_REG_BUCK2_VOLT_RUN,
-               },
-               {
-                       .prop = "rohm,dvs-idle-voltage",
-                       .reg = BD718XX_REG_BUCK2_VOLT_IDLE,
-               },
-       };
-
-
-
-       for (i = 0; i < ARRAY_SIZE(dvs); i++) {
-               ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
-               if (ret)
-                       break;
-       }
-       return ret;
-}
-
-static int buck1_set_hw_dvs_levels(struct device_node *np,
-                           const struct regulator_desc *desc,
-                           struct regulator_config *cfg)
-{
-       int ret, i;
-       const struct of_dvs_setting dvs[] = {
-               {
-                       .prop = "rohm,dvs-run-voltage",
-                       .reg = BD718XX_REG_BUCK1_VOLT_RUN,
-               },
-               {
-                       .prop = "rohm,dvs-idle-voltage",
-                       .reg = BD718XX_REG_BUCK1_VOLT_IDLE,
-               },
-               {
-                       .prop = "rohm,dvs-suspend-voltage",
-                       .reg = BD718XX_REG_BUCK1_VOLT_SUSP,
-               },
-       };
-
-       for (i = 0; i < ARRAY_SIZE(dvs); i++) {
-               ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
-               if (ret)
-                       break;
-       }
-       return ret;
+       return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
 }
 
 static const struct bd718xx_regulator_data bd71847_regulators[] = {
@@ -496,7 +379,17 @@ static const struct bd718xx_regulator_data bd71847_regulators[] = {
                        .enable_reg = BD718XX_REG_BUCK1_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck1_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
+                                    ROHM_DVS_LEVEL_SUSPEND,
+                       .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
+                       .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
+                       .idle_mask = DVS_BUCK_RUN_MASK,
+                       .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
+                       .suspend_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD718XX_REG_BUCK1_CTRL,
@@ -520,7 +413,14 @@ static const struct bd718xx_regulator_data bd71847_regulators[] = {
                        .enable_reg = BD718XX_REG_BUCK2_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck2_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
+                       .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
+                       .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
+                       .idle_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD718XX_REG_BUCK2_CTRL,
@@ -792,7 +692,17 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
                        .enable_reg = BD718XX_REG_BUCK1_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck1_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
+                                    ROHM_DVS_LEVEL_SUSPEND,
+                       .run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
+                       .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
+                       .idle_mask = DVS_BUCK_RUN_MASK,
+                       .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
+                       .suspend_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD718XX_REG_BUCK1_CTRL,
@@ -816,7 +726,14 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
                        .enable_reg = BD718XX_REG_BUCK2_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck2_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
+                       .run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
+                       .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
+                       .idle_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD718XX_REG_BUCK2_CTRL,
@@ -840,7 +757,12 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
                        .enable_reg = BD71837_REG_BUCK3_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck3_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN,
+                       .run_reg = BD71837_REG_BUCK3_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD71837_REG_BUCK3_CTRL,
@@ -864,7 +786,12 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
                        .enable_reg = BD71837_REG_BUCK4_CTRL,
                        .enable_mask = BD718XX_BUCK_EN,
                        .owner = THIS_MODULE,
-                       .of_parse_cb = buck4_set_hw_dvs_levels,
+                       .of_parse_cb = buck_set_hw_dvs_levels,
+               },
+               .dvs = {
+                       .level_map = ROHM_DVS_LEVEL_RUN,
+                       .run_reg = BD71837_REG_BUCK4_VOLT_RUN,
+                       .run_mask = DVS_BUCK_RUN_MASK,
                },
                .init = {
                        .reg = BD71837_REG_BUCK4_CTRL,
@@ -1150,6 +1077,7 @@ static int bd718xx_probe(struct platform_device *pdev)
        bool use_snvs;
        const struct bd718xx_regulator_data *reg_data;
        unsigned int num_reg_data;
+       enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
        mfd = dev_get_drvdata(pdev->dev.parent);
        if (!mfd) {
@@ -1158,7 +1086,7 @@ static int bd718xx_probe(struct platform_device *pdev)
                goto err;
        }
 
-       switch (mfd->chip.chip_type) {
+       switch (chip) {
        case ROHM_CHIP_TYPE_BD71837:
                reg_data = bd71837_regulators;
                num_reg_data = ARRAY_SIZE(bd71837_regulators);
@@ -1275,11 +1203,19 @@ static int bd718xx_probe(struct platform_device *pdev)
        return err;
 }
 
+static const struct platform_device_id bd718x7_pmic_id[] = {
+       { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
+       { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
+       { },
+};
+MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
+
 static struct platform_driver bd718xx_regulator = {
        .driver = {
                .name = "bd718xx-pmic",
        },
        .probe = bd718xx_probe,
+       .id_table = bd718x7_pmic_id,
 };
 
 module_platform_driver(bd718xx_regulator);