2021-06-25 17:07:40

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: [PATCH v9 2/5] regulator: hi6421v600-regulator: fix platform drvdata

platform drvdata can't be used inside the regulator driver,
as this is already used by the MFD and SPMI drivers.

So, change the logic to allocate it inside the
struct hi6421_spmi_pmic.

While here, drop the unused fields there.

Fixes: 50e629362e1f ("regulator: hi6421v600: Fix setting wrong driver_data")

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
---
drivers/regulator/hi6421v600-regulator.c | 26 +++++++++------------
drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 2 +-
include/linux/mfd/hi6421-spmi-pmic.h | 9 +++----
3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/regulator/hi6421v600-regulator.c b/drivers/regulator/hi6421v600-regulator.c
index 9b162c0555c3..49d83350435c 100644
--- a/drivers/regulator/hi6421v600-regulator.c
+++ b/drivers/regulator/hi6421v600-regulator.c
@@ -16,15 +16,13 @@
#include <linux/regulator/driver.h>
#include <linux/spmi.h>

-struct hi6421_spmi_reg_priv {
- /* Serialize regulator enable logic */
- struct mutex enable_mutex;
-};
-
struct hi6421_spmi_reg_info {
struct regulator_desc desc;
u8 eco_mode_mask;
u32 eco_uA;
+
+ /* Serialize regulator enable logic */
+ struct mutex *enable_mutex;
};

static const unsigned int ldo3_voltages[] = {
@@ -98,12 +96,11 @@ static const unsigned int ldo34_voltages[] = {

static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev)
{
- struct hi6421_spmi_reg_priv *priv;
+ struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev);
int ret;

- priv = dev_get_drvdata(rdev->dev.parent);
/* cannot enable more than one regulator at one time */
- mutex_lock(&priv->enable_mutex);
+ mutex_lock(sreg->enable_mutex);

ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask,
@@ -112,7 +109,7 @@ static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev)
/* Avoid powering up multiple devices at the same time */
usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 60);

- mutex_unlock(&priv->enable_mutex);
+ mutex_unlock(sreg->enable_mutex);

return ret;
}
@@ -231,7 +228,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
{
struct device *pmic_dev = pdev->dev.parent;
struct regulator_config config = { };
- struct hi6421_spmi_reg_priv *priv;
+ struct hi6421_spmi_reg_info *sreg;
struct hi6421_spmi_reg_info *info;
struct device *dev = &pdev->dev;
struct hi6421_spmi_pmic *pmic;
@@ -247,18 +244,17 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
if (WARN_ON(!pmic))
return -ENODEV;

- priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
- if (!priv)
+ sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL);
+ if (!sreg)
return -ENOMEM;

- mutex_init(&priv->enable_mutex);
- platform_set_drvdata(pdev, priv);
+ sreg->enable_mutex = &pmic->enable_mutex;

for (i = 0; i < ARRAY_SIZE(regulator_info); i++) {
info = &regulator_info[i];

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

rdev = devm_regulator_register(dev, &info->desc, &config);
diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c
index 0b5686655954..6864a19f3218 100644
--- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c
+++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c
@@ -40,7 +40,7 @@ static int hi6421_spmi_pmic_probe(struct spmi_device *pdev)
if (IS_ERR(ddata->regmap))
return PTR_ERR(ddata->regmap);

- ddata->dev = dev;
+ mutex_init(&ddata->enable_mutex);

dev_set_drvdata(&pdev->dev, ddata);

diff --git a/include/linux/mfd/hi6421-spmi-pmic.h b/include/linux/mfd/hi6421-spmi-pmic.h
index e5b8dbf828b6..a72b2797a997 100644
--- a/include/linux/mfd/hi6421-spmi-pmic.h
+++ b/include/linux/mfd/hi6421-spmi-pmic.h
@@ -16,10 +16,11 @@
#include <linux/regmap.h>

struct hi6421_spmi_pmic {
- struct resource *res;
- struct device *dev;
- void __iomem *regs;
- struct regmap *regmap;
+ /* Serialize regulator enable logic */
+ struct mutex enable_mutex;
+
+ /* SPMI register regmap */
+ struct regmap *regmap;
};

#endif /* __HISI_PMIC_H */
--
2.31.1


2021-06-26 03:43:16

by Axel Lin

[permalink] [raw]
Subject: Re: [PATCH v9 2/5] regulator: hi6421v600-regulator: fix platform drvdata

> @@ -231,7 +228,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
> {
> struct device *pmic_dev = pdev->dev.parent;
> struct regulator_config config = { };
> - struct hi6421_spmi_reg_priv *priv;
> + struct hi6421_spmi_reg_info *sreg;
> struct hi6421_spmi_reg_info *info;
> struct device *dev = &pdev->dev;
> struct hi6421_spmi_pmic *pmic;
> @@ -247,18 +244,17 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
> if (WARN_ON(!pmic))
> return -ENODEV;
>
> - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> - if (!priv)
> + sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL);
> + if (!sreg)
> return -ENOMEM;
>
> - mutex_init(&priv->enable_mutex);
> - platform_set_drvdata(pdev, priv);
> + sreg->enable_mutex = &pmic->enable_mutex;
>
> for (i = 0; i < ARRAY_SIZE(regulator_info); i++) {
> info = &regulator_info[i];
>
> config.dev = pdev->dev.parent;
> - config.driver_data = info;
> + config.driver_data = sreg;

This won't work and that was what my patch fixed.
e.g. When you call
struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev);
sreg->eco_mode_mask and sreg->eco_uA will always be 0.

Regards,
Axel

2021-06-29 11:50:08

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH v9 2/5] regulator: hi6421v600-regulator: fix platform drvdata

Em Sat, 26 Jun 2021 11:41:50 +0800
Axel Lin <[email protected]> escreveu:

> > @@ -231,7 +228,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
> > {
> > struct device *pmic_dev = pdev->dev.parent;
> > struct regulator_config config = { };
> > - struct hi6421_spmi_reg_priv *priv;
> > + struct hi6421_spmi_reg_info *sreg;
> > struct hi6421_spmi_reg_info *info;
> > struct device *dev = &pdev->dev;
> > struct hi6421_spmi_pmic *pmic;
> > @@ -247,18 +244,17 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev)
> > if (WARN_ON(!pmic))
> > return -ENODEV;
> >
> > - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > - if (!priv)
> > + sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL);
> > + if (!sreg)
> > return -ENOMEM;
> >
> > - mutex_init(&priv->enable_mutex);
> > - platform_set_drvdata(pdev, priv);
> > + sreg->enable_mutex = &pmic->enable_mutex;
> >
> > for (i = 0; i < ARRAY_SIZE(regulator_info); i++) {
> > info = &regulator_info[i];
> >
> > config.dev = pdev->dev.parent;
> > - config.driver_data = info;
> > + config.driver_data = sreg;
>
> This won't work and that was what my patch fixed.
> e.g. When you call
> struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev);
> sreg->eco_mode_mask and sreg->eco_uA will always be 0.

Yeah, probably something got lost during the several rebases.
Anyway, I'll send in a few a new patch series addressing this issue.

Thanks,
Mauro