From 2c4fb70d185c7e7080e73bd382f3b4814d89d8c9 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 17 Aug 2020 09:10:59 +0200 Subject: [PATCH] staging: regulator: hi6421v600-regulator: code cleanup Do some code cleanup in order to make it cleaner for moving it out of staging in the future. Suggested-by: Jonathan Cameron Signed-off-by: Mauro Carvalho Chehab Link: https://lore.kernel.org/r/32fadb359c1817992af78052e2d9448b8c5fc61f.1597647359.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hikey9xx/hi6421v600-regulator.c | 78 ++++++++++--------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421v600-regulator.c b/drivers/staging/hikey9xx/hi6421v600-regulator.c index c80dfac..82635ff 100644 --- a/drivers/staging/hikey9xx/hi6421v600-regulator.c +++ b/drivers/staging/hikey9xx/hi6421v600-regulator.c @@ -15,29 +15,28 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * */ -#include +#include #include -#include #include #include -#include -#include -#include +#include +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include #include -#include +#include #include +#include +#include +#include #define rdev_dbg(rdev, fmt, arg...) \ pr_debug("%s: %s: " fmt, (rdev)->desc->name, __func__, ##arg) @@ -50,15 +49,16 @@ struct hi6421v600_regulator { static DEFINE_MUTEX(enable_mutex); -/* helper function to ensure when it returns it is at least 'delay_us' +/* + * helper function to ensure when it returns it is at least 'delay_us' * microseconds after 'since'. */ static int hi6421_spmi_regulator_is_enabled(struct regulator_dev *rdev) { - u32 reg_val; struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; + u32 reg_val; reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); @@ -136,7 +136,6 @@ static int hi6421_spmi_regulator_set_voltage_sel(struct regulator_dev *rdev, struct hi6421_spmi_pmic *pmic = sreg->pmic; u32 reg_val; - /* unlikely to happen. sanity test done by regulator core */ if (unlikely(selector >= rdev->desc->n_voltages)) return -EINVAL; @@ -158,8 +157,8 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); struct hi6421_spmi_pmic *pmic = sreg->pmic; - u32 reg_val; unsigned int mode; + u32 reg_val; reg_val = hi6421_spmi_pmic_read(pmic, rdev->desc->enable_reg); @@ -211,13 +210,10 @@ hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev, { struct hi6421v600_regulator *sreg = rdev_get_drvdata(rdev); - if (load_uA || ((unsigned int)load_uA > sreg->eco_uA)) { - rdev_dbg(rdev, "normal mode"); + if (load_uA || ((unsigned int)load_uA > sreg->eco_uA)) return REGULATOR_MODE_NORMAL; - } else { - rdev_dbg(rdev, "idle mode"); - return REGULATOR_MODE_IDLE; - } + + return REGULATOR_MODE_IDLE; } static int hi6421_spmi_dt_parse(struct platform_device *pdev, @@ -231,7 +227,7 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, ret = of_property_read_u32(np, "reg", &rdesc->enable_reg); if (ret) { - dev_err(dev, "missing reg property\nn"); + dev_err(dev, "missing reg property\n"); return ret; } @@ -256,8 +252,7 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, sreg->eco_mode_mask = 0; sreg->eco_uA = 0; } else { - ret = of_property_read_u32(np, "eco-microamp", - &sreg->eco_uA); + ret = of_property_read_u32(np, "eco-microamp", &sreg->eco_uA); if (ret) { dev_err(dev, "missing eco-microamp property\n"); return ret; @@ -308,13 +303,13 @@ static int hi6421_spmi_dt_parse(struct platform_device *pdev, */ rdesc->vsel_mask = (1 << (fls(rdesc->n_voltages) - 1)) - 1; - dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x", + dev_dbg(dev, "voltage selector settings: reg: 0x%x, mask: 0x%x\n", rdesc->vsel_reg, rdesc->vsel_mask); return 0; } -static struct regulator_ops hi6421_spmi_ldo_rops = { +static const struct regulator_ops hi6421_spmi_ldo_rops = { .is_enabled = hi6421_spmi_regulator_is_enabled, .enable = hi6421_spmi_regulator_enable, .disable = hi6421_spmi_regulator_disable, @@ -327,23 +322,19 @@ static struct regulator_ops hi6421_spmi_ldo_rops = { .get_optimum_mode = hi6421_spmi_regulator_get_optimum_mode, }; -/* - * Used only for parsing the DT properties - */ - static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, struct device_node *np, struct hi6421_spmi_pmic *pmic) { + struct regulation_constraints *constraint; + struct regulator_init_data *initdata; + struct regulator_config config = { }; + struct hi6421v600_regulator *sreg; struct device *dev = &pdev->dev; struct regulator_desc *rdesc; struct regulator_dev *rdev; - struct hi6421v600_regulator *sreg = NULL; - struct regulator_init_data *initdata; - struct regulator_config config = { }; - struct regulation_constraints *constraint; - const char *supplyname = NULL; - int ret = 0; + const char *supplyname; + int ret; initdata = of_get_regulator_init_data(dev, np, NULL); if (!initdata) { @@ -351,7 +342,7 @@ static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, return -EINVAL; } - sreg = kzalloc(sizeof(*sreg), GFP_KERNEL); + sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); if (!sreg) return -ENOMEM; @@ -370,7 +361,7 @@ static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, /* parse device tree data for regulator specific */ ret = hi6421_spmi_dt_parse(pdev, sreg, rdesc); if (ret) - goto probe_end; + return ret; /* hisi regulator supports two modes */ constraint = &initdata->constraints; @@ -391,18 +382,15 @@ static int hi6421_spmi_regulator_probe_ldo(struct platform_device *pdev, if (IS_ERR(rdev)) { dev_err(dev, "failed to register %s\n", rdesc->name); - ret = PTR_ERR(rdev); - goto probe_end; + return PTR_ERR(rdev); } rdev_dbg(rdev, "valid_modes_mask: 0x%x, valid_ops_mask: 0x%x\n", constraint->valid_modes_mask, constraint->valid_ops_mask); dev_set_drvdata(dev, rdev); -probe_end: - if (ret) - kfree(sreg); - return ret; + + return 0; } static int hi6421_spmi_regulator_probe(struct platform_device *pdev) @@ -414,7 +402,6 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) struct hi6421_spmi_pmic *pmic; int ret; - dev_dbg(&pdev->dev, "probing hi6421v600 regulator\n"); /* * This driver is meant to be called by hi6421-spmi-core, * which should first set drvdata. If this doesn't happen, hit @@ -463,7 +450,6 @@ static int hi6421_spmi_regulator_remove(struct platform_device *pdev) regulator_unregister(rdev); - /* TODO: should i worry about that? devm_kzalloc */ if (rdev->desc->volt_table) devm_kfree(&pdev->dev, (unsigned int *)rdev->desc->volt_table); -- 2.7.4