Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: mdshahid03@gmail.com
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Ray Jui" <rjui@broadcom.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com, linux-iio@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	"Mohammad Shahid" <mdshahid03@gmail.com>
Subject: [PATCH v2 3/5] iio: adc: bcm_iproc_adc: use devm-managed cleanup
Date: Sun, 30 Aug 2026 22:39:16 +0530	[thread overview]
Message-ID: <20260830170919.470974-4-mdshahid03@gmail.com> (raw)
In-Reply-To: <20260830170919.470974-1-mdshahid03@gmail.com>

From: Mohammad Shahid <mdshahid03@gmail.com>

Use devm_clk_get_enabled() to manage the ADC clock and
devm_add_action_or_reset() to manage ADC cleanup.

Since the clock is only needed during probe, keep it as a local
variable instead of storing it in struct iproc_adc_priv.

Register the ADC cleanup action immediately after enabling the ADC
so that it is automatically performed on probe failure and device
removal.

This removes the manual clock cleanup callback and simplifies the
probe error paths.

Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
 drivers/iio/adc/bcm_iproc_adc.c | 39 ++++++++++++++-------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/drivers/iio/adc/bcm_iproc_adc.c b/drivers/iio/adc/bcm_iproc_adc.c
index 2b59819c4ca4..c7fbdc21f8cc 100644
--- a/drivers/iio/adc/bcm_iproc_adc.c
+++ b/drivers/iio/adc/bcm_iproc_adc.c
@@ -107,7 +107,6 @@ do { \
 
 struct iproc_adc_priv {
 	struct regmap *regmap;
-	struct clk *adc_clk;
 	struct mutex mutex;
 	int  irqno;
 	int chan_val;
@@ -449,6 +448,13 @@ static void iproc_adc_disable(struct iio_dev *indio_dev)
 	}
 }
 
+static void iproc_adc_disable_action(void *data)
+{
+	struct iio_dev *indio_dev = data;
+
+	iproc_adc_disable(indio_dev);
+}
+
 static int iproc_adc_read_raw(struct iio_dev *indio_dev,
 			  struct iio_chan_spec const *chan,
 			  int *val,
@@ -508,6 +514,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));
@@ -527,10 +534,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)
@@ -548,13 +554,13 @@ static int iproc_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(adc_priv->adc_clk);
+	ret = iproc_adc_enable(indio_dev);
 	if (ret)
-		return dev_err_probe(dev, ret, "failed to enable clock\n");
+		return ret;
 
-	ret = iproc_adc_enable(indio_dev);
+	ret = devm_add_action_or_reset(dev, iproc_adc_disable_action, indio_dev);
 	if (ret)
-		goto err_adc_enable;
+		return ret;
 
 	indio_dev->name = "iproc-static-adc";
 	indio_dev->info = &iproc_adc_iio_info;
@@ -563,29 +569,18 @@ 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);
-err_adc_enable:
-	clk_disable_unprepare(adc_priv->adc_clk);
-
-	return ret;
 }
 
 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[] = {
-- 
2.43.0



  parent reply	other threads:[~2026-08-30 17:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 17:09 [PATCH v2 0/5] iio: adc: bcm_iproc_adc: use device-managed resources mdshahid03
2026-08-30 17:09 ` [PATCH v2 1/5] iio: adc: bcm_iproc_adc: sort headers alphabetically mdshahid03
2026-08-30 17:09 ` [PATCH v2 2/5] iio: adc: bcm_iproc_adc: fix include dependencies mdshahid03
2026-09-01  2:27   ` Marcelo Schmitt
2026-09-01  3:16     ` Jonathan Cameron
2026-09-01  6:57     ` Andy Shevchenko
2026-08-30 17:09 ` mdshahid03 [this message]
2026-08-30 20:18   ` [PATCH v2 3/5] iio: adc: bcm_iproc_adc: use devm-managed cleanup Jonathan Cameron
2026-08-30 17:09 ` [PATCH v2 4/5] iio: adc: bcm_iproc_adc: use devm-managed mutex initialization mdshahid03
2026-08-30 17:09 ` [PATCH v2 5/5] iio: adc: bcm_iproc_adc: use devm_iio_device_register() mdshahid03
2026-08-30 20:18   ` Jonathan Cameron
2026-09-01  2:13   ` Marcelo Schmitt
2026-09-01 14:40 ` [PATCH v2 0/5] iio: adc: bcm_iproc_adc: use device-managed resources mdshahid03

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260830170919.470974-4-mdshahid03@gmail.com \
    --to=mdshahid03@gmail.com \
    --cc=andy@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox