Thread (7 messages) 7 messages, 3 authors, 2021-06-29
STALE1826d
Revisions (15)
  1. v6 [diff vs current]
  2. v8 [diff vs current]
  3. v5 [diff vs current]
  4. v5 [diff vs current]
  5. v6 [diff vs current]
  6. v6 [diff vs current]
  7. v7 [diff vs current]
  8. v8 [diff vs current]
  9. v9 current
  10. v10 [diff vs current]
  11. v11 [diff vs current]
  12. v12 [diff vs current]
  13. v13 [diff vs current]
  14. v14 [diff vs current]
  15. v15 [diff vs current]

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

From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Date: 2021-06-25 17:06:21
Also in: lkml
Subsystem: multifunction devices (mfd), staging subsystem, the rest, voltage and current regulator framework · Maintainers: Lee Jones, Greg Kroah-Hartman, Linus Torvalds, Liam Girdwood, Mark Brown

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 <mchehab+huawei@kernel.org>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help