2021-06-07 14:31:34

by Axel Lin

[permalink] [raw]
Subject: [PATCH] regulator: bd71815: Get rid of struct bd71815_pmic

The content of bd71815_regulators is never changed, no need to duplicate
it, thus remove descs[BD71815_REGULATOR_CNT].
The *regmap, *dev and *rdev[BD71815_REGULATOR_CNT] are not really needed.
The *gps is unused.

Thus the struct bd71815_pmic can be removed.

Signed-off-by: Axel Lin <[email protected]>
---
drivers/regulator/bd71815-regulator.c | 57 +++++++++------------------
1 file changed, 19 insertions(+), 38 deletions(-)

diff --git a/drivers/regulator/bd71815-regulator.c b/drivers/regulator/bd71815-regulator.c
index 4dd21ac24ddf..16edd9062ca9 100644
--- a/drivers/regulator/bd71815-regulator.c
+++ b/drivers/regulator/bd71815-regulator.c
@@ -28,14 +28,6 @@ struct bd71815_regulator {
const struct rohm_dvs_config *dvs;
};

-struct bd71815_pmic {
- struct bd71815_regulator descs[BD71815_REGULATOR_CNT];
- struct regmap *regmap;
- struct device *dev;
- struct gpio_descs *gps;
- struct regulator_dev *rdev[BD71815_REGULATOR_CNT];
-};
-
static const int bd7181x_wled_currents[] = {
10, 20, 30, 50, 70, 100, 200, 300, 500, 700, 1000, 2000, 3000, 4000,
5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000,
@@ -302,14 +294,13 @@ static int bd7181x_led_set_current_limit(struct regulator_dev *rdev,

static int bd7181x_buck12_get_voltage_sel(struct regulator_dev *rdev)
{
- struct bd71815_pmic *pmic = rdev_get_drvdata(rdev);
int rid = rdev_get_id(rdev);
int ret, regh, regl, val;

regh = BD71815_REG_BUCK1_VOLT_H + rid * 0x2;
regl = BD71815_REG_BUCK1_VOLT_L + rid * 0x2;

- ret = regmap_read(pmic->regmap, regh, &val);
+ ret = regmap_read(rdev->regmap, regh, &val);
if (ret)
return ret;

@@ -321,7 +312,7 @@ static int bd7181x_buck12_get_voltage_sel(struct regulator_dev *rdev)
* by BD71815_BUCK_DVSSEL bit
*/
if ((!(val & BD71815_BUCK_STBY_DVS)) && (!(val & BD71815_BUCK_DVSSEL)))
- ret = regmap_read(pmic->regmap, regl, &val);
+ ret = regmap_read(rdev->regmap, regl, &val);

if (ret)
return ret;
@@ -335,14 +326,13 @@ static int bd7181x_buck12_get_voltage_sel(struct regulator_dev *rdev)
static int bd7181x_buck12_set_voltage_sel(struct regulator_dev *rdev,
unsigned int sel)
{
- struct bd71815_pmic *pmic = rdev_get_drvdata(rdev);
int rid = rdev_get_id(rdev);
int ret, val, reg, regh, regl;

regh = BD71815_REG_BUCK1_VOLT_H + rid*0x2;
regl = BD71815_REG_BUCK1_VOLT_L + rid*0x2;

- ret = regmap_read(pmic->regmap, regh, &val);
+ ret = regmap_read(rdev->regmap, regh, &val);
if (ret)
return ret;

@@ -352,7 +342,7 @@ static int bd7181x_buck12_set_voltage_sel(struct regulator_dev *rdev,
* voltages at runtime is not supported by this driver.
*/
if (((val & BD71815_BUCK_STBY_DVS))) {
- return regmap_update_bits(pmic->regmap, regh, BD71815_VOLT_MASK,
+ return regmap_update_bits(rdev->regmap, regh, BD71815_VOLT_MASK,
sel);
}
/* Update new voltage to the register which is not selected now */
@@ -361,12 +351,13 @@ static int bd7181x_buck12_set_voltage_sel(struct regulator_dev *rdev,
else
reg = regh;

- ret = regmap_update_bits(pmic->regmap, reg, BD71815_VOLT_MASK, sel);
+ ret = regmap_update_bits(rdev->regmap, reg, BD71815_VOLT_MASK, sel);
if (ret)
return ret;

/* Select the other DVS register to be used */
- return regmap_update_bits(pmic->regmap, regh, BD71815_BUCK_DVSSEL, ~val);
+ return regmap_update_bits(rdev->regmap, regh, BD71815_BUCK_DVSSEL,
+ ~val);
}

static const struct regulator_ops bd7181x_ldo_regulator_ops = {
@@ -524,7 +515,7 @@ static const struct regulator_ops bd7181x_led_regulator_ops = {
.dvs = (_dvs), \
}

-static struct bd71815_regulator bd71815_regulators[] = {
+static const struct bd71815_regulator bd71815_regulators[] = {
BD71815_BUCK12_REG(buck1, BD71815_BUCK1, BD71815_REG_BUCK1_VOLT_H,
BD71815_REG_BUCK1_MODE, 800000, 2000000, 25000,
&buck1_dvs),
@@ -570,24 +561,16 @@ static struct bd71815_regulator bd71815_regulators[] = {

static int bd7181x_probe(struct platform_device *pdev)
{
- struct bd71815_pmic *pmic;
struct regulator_config config = {};
int i, ret;
struct gpio_desc *ldo4_en;
+ struct regmap *regmap;

- pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
- if (!pmic)
- return -ENOMEM;
-
- memcpy(pmic->descs, bd71815_regulators, sizeof(pmic->descs));
-
- pmic->dev = &pdev->dev;
- pmic->regmap = dev_get_regmap(pdev->dev.parent, NULL);
- if (!pmic->regmap) {
- dev_err(pmic->dev, "No parent regmap\n");
+ regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!regmap) {
+ dev_err(&pdev->dev, "No parent regmap\n");
return -ENODEV;
}
- platform_set_drvdata(pdev, pmic);
ldo4_en = devm_gpiod_get_from_of_node(&pdev->dev,
pdev->dev.parent->of_node,
"rohm,vsel-gpios", 0,
@@ -601,23 +584,23 @@ static int bd7181x_probe(struct platform_device *pdev)
}

/* Disable to go to ship-mode */
- ret = regmap_update_bits(pmic->regmap, BD71815_REG_PWRCTRL,
- RESTARTEN, 0);
+ ret = regmap_update_bits(regmap, BD71815_REG_PWRCTRL, RESTARTEN, 0);
if (ret)
return ret;

config.dev = pdev->dev.parent;
- config.regmap = pmic->regmap;
+ config.regmap = regmap;

for (i = 0; i < BD71815_REGULATOR_CNT; i++) {
- struct regulator_desc *desc;
+ const struct regulator_desc *desc;
struct regulator_dev *rdev;

- desc = &pmic->descs[i].desc;
+ desc = &bd71815_regulators[i].desc;
+
if (i == BD71815_LDO4)
config.ena_gpiod = ldo4_en;
-
- config.driver_data = pmic;
+ else
+ config.ena_gpiod = NULL;

rdev = devm_regulator_register(&pdev->dev, desc, &config);
if (IS_ERR(rdev)) {
@@ -626,8 +609,6 @@ static int bd7181x_probe(struct platform_device *pdev)
desc->name);
return PTR_ERR(rdev);
}
- config.ena_gpiod = NULL;
- pmic->rdev[i] = rdev;
}
return 0;
}
--
2.25.1


2021-06-08 07:54:58

by Matti Vaittinen

[permalink] [raw]
Subject: Re: [PATCH] regulator: bd71815: Get rid of struct bd71815_pmic


On Mon, 2021-06-07 at 22:30 +0800, Axel Lin wrote:
> The content of bd71815_regulators is never changed, no need to
> duplicate
> it, thus remove descs[BD71815_REGULATOR_CNT].
> The *regmap, *dev and *rdev[BD71815_REGULATOR_CNT] are not really
> needed.
> The *gps is unused.
>
> Thus the struct bd71815_pmic can be removed.
>
> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/regulator/bd71815-regulator.c | 57 +++++++++--------------
> ----
> 1 file changed, 19 insertions(+), 38 deletions(-)

Thanks a lot Axel. This is nice!

We might need to decide the ops for LDO3 based on a DT configuration
because the LDO3 state can be tied to DCIN connection. Currently the
driver does not support that though - and this patch is a nice
simplification!

Reviewed-by: Matti Vaittinen <[email protected]>

Best Regards
--Matti



Attachments:
signature.asc (499.00 B)
This is a digitally signed message part

2021-06-08 16:11:58

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regulator: bd71815: Get rid of struct bd71815_pmic

On Mon, 7 Jun 2021 22:30:02 +0800, Axel Lin wrote:
> The content of bd71815_regulators is never changed, no need to duplicate
> it, thus remove descs[BD71815_REGULATOR_CNT].
> The *regmap, *dev and *rdev[BD71815_REGULATOR_CNT] are not really needed.
> The *gps is unused.
>
> Thus the struct bd71815_pmic can be removed.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: bd71815: Get rid of struct bd71815_pmic
commit: 0ea461b4f229739345870a086aa4647a16ff42ff

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark