Skip to contentSkip to conversation

iio: adc: bcm_iproc_adc: convert to devm-managed APIs

PATCH In review [email protected] 4 participants 11 messages Sep 8 – Sep 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover iio: adc: bcm_iproc_adc: convert to devm-managed APIs

From: Mohammad Shahid <[email protected]>

Changes in v4:
- Move the ADC enable error-path cleanup simplification into the clock conversion patch.
- Simplify the ADC devm cleanup action.
- Restore the blank line after the copyright header.

---
Mohammad Shahid (6):
iio: adc: bcm_iproc_adc: sort headers alphabetically
iio: adc: bcm_iproc_adc: fix include dependencies
iio: adc: bcm_iproc_adc: use devm-managed clock
iio: adc: bcm_iproc_adc: use devm-managed ADC cleanup
iio: adc: bcm_iproc_adc: use devm-managed mutex initialization
iio: adc: bcm_iproc_adc: use devm-managed IIO device registration

 drivers/iio/adc/bcm_iproc_adc.c | 65 +++++++++++++--------------------
 1 file changed, 25 insertions(+), 40 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/6 iio: adc: bcm_iproc_adc: sort headers alphabetically

From: Mohammad Shahid <[email protected]>

Sort the Linux kernel headers alphabetically to improve consistency and make the include list easier to maintain.

---
 drivers/iio/adc/bcm_iproc_adc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +4 -4
index ab66b97d2f04..e46e3761993a 100644
@@ -3,14 +3,14 @@
  * Copyright 2016 Broadcom
  */
 
-#include <linux/module.h>
-#include <linux/io.h>
 #include <linux/clk.h>
-#include <linux/mfd/syscon.h>
-#include <linux/regmap.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 
 #include <linux/iio/iio.h>
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/6 iio: adc: bcm_iproc_adc: fix include dependencies

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Add the headers required directly by the driver for the APIs and types it uses.

Remove the unused linux/io.h header now that register access is handled through regmap APIs.

---
 drivers/iio/adc/bcm_iproc_adc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/adc/bcm_iproc_adc.c +5 -1
index e46e3761993a..21bd51da9cd6 100644
@@ -3,14 +3,18 @@
  * Copyright 2016 Broadcom
  */
 
+#include <linux/array_size.h>
+#include <linux/bits.h>
 #include <linux/clk.h>
+#include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
-#include <linux/io.h>
 #include <linux/mfd/syscon.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/types.h>
 
 #include <linux/iio/iio.h>
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 3/6 iio: adc: bcm_iproc_adc: use devm-managed clock

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Convert the ADC clock to use devm-managed APIs to simplify resource cleanup.

---
 drivers/iio/adc/bcm_iproc_adc.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +5 -14
index 21bd51da9cd6..d6f82f8ddee1 100644
@@ -110,7 +110,6 @@ do { \
 
 struct iproc_adc_priv {
 	struct regmap *regmap;
-	struct clk *adc_clk;
 	struct mutex mutex;
 	int  irqno;
 	int chan_val;
@@ -511,6 +510,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	struct iproc_adc_priv *adc_priv;
 	struct iio_dev *indio_dev = NULL;
 	struct device *dev = &pdev->dev;
+	struct clk *adc_clk;
 	int ret;
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*adc_priv));
@@ -530,10 +530,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(adc_priv->regmap),
 				     "failed to get handle for tsc syscon\n");
 
-	adc_priv->adc_clk = devm_clk_get(dev, "tsc_clk");
-	if (IS_ERR(adc_priv->adc_clk))
-		return dev_err_probe(dev, PTR_ERR(adc_priv->adc_clk),
-				     "failed getting clock tsc_clk\n");
+	adc_clk = devm_clk_get_enabled(dev, "tsc_clk");
+	if (IS_ERR(adc_clk))
+		return dev_err_probe(dev, PTR_ERR(adc_clk), "failed to enable clock\n");
 
 	adc_priv->irqno = platform_get_irq(pdev, 0);
 	if (adc_priv->irqno < 0)
@@ -551,13 +550,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(adc_priv->adc_clk);
-	if (ret)
-		return dev_err_probe(dev, ret, "failed to enable clock\n");
-
 	ret = iproc_adc_enable(indio_dev);
 	if (ret)
-		goto err_adc_enable;
+		return ret;
 
 	indio_dev->name = "iproc-static-adc";
 	indio_dev->info = &iproc_adc_iio_info;
@@ -575,8 +570,6 @@ static int iproc_adc_probe(struct platform_device *pdev)
 
 err_clk:
 	iproc_adc_disable(indio_dev);
-err_adc_enable:
-	clk_disable_unprepare(adc_priv->adc_clk);
 
 	return ret;
 }
@@ -584,11 +577,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 static void iproc_adc_remove(struct platform_device *pdev)
 {
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-	struct iproc_adc_priv *adc_priv = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
 	iproc_adc_disable(indio_dev);
-	clk_disable_unprepare(adc_priv->adc_clk);
 }
 
 static const struct of_device_id iproc_adc_of_match[] = {
Signature · 1 line
2.43.0
#4 lore raw

PATCH v4 4/6 iio: adc: bcm_iproc_adc: use devm-managed ADC cleanup

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Use devm_add_action_or_reset() to disable the ADC automatically when the device is detached or probe fails.

This removes the manual ADC cleanup from the remove and error paths and ties the ADC cleanup to the device lifetime.

---
 drivers/iio/adc/bcm_iproc_adc.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +11 -10
index d6f82f8ddee1..ff271c7fb2de 100644
@@ -451,6 +451,11 @@ static void iproc_adc_disable(struct iio_dev *indio_dev)
 	}
 }
 
+static void iproc_adc_disable_action(void *indio_dev)
+{
+	iproc_adc_disable(indio_dev);
+}
+
 static int iproc_adc_read_raw(struct iio_dev *indio_dev,
 			  struct iio_chan_spec const *chan,
 			  int *val,
@@ -554,6 +559,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	ret = devm_add_action_or_reset(dev, iproc_adc_disable_action, indio_dev);
+	if (ret)
+		return ret;
+
 	indio_dev->name = "iproc-static-adc";
 	indio_dev->info = &iproc_adc_iio_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
@@ -561,17 +570,10 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	indio_dev->num_channels = ARRAY_SIZE(iproc_adc_iio_channels);
 
 	ret = iio_device_register(indio_dev);
-	if (ret) {
-		dev_err(&pdev->dev, "iio_device_register failed:err %d\n", ret);
-		goto err_clk;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "iio_device_register failed\n");
 
 	return 0;
-
-err_clk:
-	iproc_adc_disable(indio_dev);
-
-	return ret;
 }
 
 static void iproc_adc_remove(struct platform_device *pdev)
@@ -579,7 +581,6 @@ static void iproc_adc_remove(struct platform_device *pdev)
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 
 	iio_device_unregister(indio_dev);
-	iproc_adc_disable(indio_dev);
 }
 
 static const struct of_device_id iproc_adc_of_match[] = {
Signature · 1 line
2.43.0
#5 lore raw

PATCH v4 5/6 iio: adc: bcm_iproc_adc: use devm-managed mutex initialization

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Use devm_mutex_init() to tie the mutex lifetime to the device and improve debugging when CONFIG_DEBUG_MUTEXES is enabled.

---
 drivers/iio/adc/bcm_iproc_adc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/bcm_iproc_adc.c +3 -1
index ff271c7fb2de..9881a3104c26 100644
@@ -525,7 +525,9 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	adc_priv = iio_priv(indio_dev);
 	platform_set_drvdata(pdev, indio_dev);
 
-	mutex_init(&adc_priv->mutex);
+	ret = devm_mutex_init(dev, &adc_priv->mutex);
+	if (ret)
+		return ret;
 
 	init_completion(&adc_priv->completion);
 
Signature · 1 line
2.43.0
#6 lore raw

PATCH v4 6/6 iio: adc: bcm_iproc_adc: use devm-managed IIO device registration

In reply to [email protected]

From: Mohammad Shahid <[email protected]>

Use devm_iio_device_register() to automatically unregister the IIO device when the device is detached.

This removes the manual iio_device_unregister() call and makes the iproc_adc_remove() callback unnecessary.

---
 drivers/iio/adc/bcm_iproc_adc.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/iio/adc/bcm_iproc_adc.c +1 -14
index 9881a3104c26..ca81e0edd24d 100644
@@ -523,7 +523,6 @@ static int iproc_adc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	adc_priv = iio_priv(indio_dev);
-	platform_set_drvdata(pdev, indio_dev);
 
 	ret = devm_mutex_init(dev, &adc_priv->mutex);
 	if (ret)
@@ -571,18 +570,7 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	indio_dev->channels = iproc_adc_iio_channels;
 	indio_dev->num_channels = ARRAY_SIZE(iproc_adc_iio_channels);
 
-	ret = iio_device_register(indio_dev);
-	if (ret)
-		return dev_err_probe(dev, ret, "iio_device_register failed\n");
-
-	return 0;
-}
-
-static void iproc_adc_remove(struct platform_device *pdev)
-{
-	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-
-	iio_device_unregister(indio_dev);
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static const struct of_device_id iproc_adc_of_match[] = {
@@ -593,7 +581,6 @@ MODULE_DEVICE_TABLE(of, iproc_adc_of_match);
 
 static struct platform_driver iproc_adc_driver = {
 	.probe = iproc_adc_probe,
-	.remove = iproc_adc_remove,
 	.driver = {
 		.name = "iproc-static-adc",
 		.of_match_table = iproc_adc_of_match,
Signature · 1 line
2.43.0
Reviewed-by on the v4 series
#7 lore raw
In reply to [email protected]
Quoted 5 lines · On Tue, Sep 08, 2026 at 10:53:53PM +0530, [email protected] wrote:

Changes in v4:
- Move the ADC enable error-path cleanup simplification into the clock conversion patch.
- Simplify the ADC devm cleanup action.
- Restore the blank line after the copyright header.

Cover letter is not only changelog, it also a summary of the series. Patch wise LGTM,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw
Quoted 8 lines · On Wed, 9 Sep 2026 16:20:18 +0300 Andy Shevchenko…
Quoted 5 lines · On Tue, Sep 08, 2026 at 10:53:53PM +0530, [email protected] wrote:

Changes in v4:
- Move the ADC enable error-path cleanup simplification into the clock conversion patch.
- Simplify the ADC devm cleanup action.
- Restore the blank line after the copyright header.

Quoted 4 lines

Cover letter is not only changelog, it also a summary of the series. Patch wise LGTM,

Applied to the testing branch of iio.git for 0-day to take its normal look before I push out as something I'd rather not rebase.

Thanks

Jonathan

maintainer
#10 lore raw
Quoted 10 lines · On Mon, 14 Sep 2026 22:54:07 -0300 Marcelo Schmitt…
Quoted 8 lines · On 09/08, [email protected] wrote:

From: Mohammad Shahid <[email protected]>

Changes in v4:
- Move the ADC enable error-path cleanup simplification into the clock conversion patch.
- Simplify the ADC devm cleanup action.
- Restore the blank line after the copyright header.

Quoted 2 lines

For the whole series,

Thanks. Added.