Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Alisa-Dariana Roman" <alisa.roman@analog.com>,
	"Haibo Chen" <haibo.chen@nxp.com>,
	"Sean Nyekjaer" <sean@geanix.com>,
	"Andreas Klinger" <ak@it-klinger.de>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: [PATCH 2/8] iio: adc: fsl-imx25-gcq: Use devm_* and dev_err_probe() to simplify probe
Date: Sun, 18 Feb 2024 17:27:25 +0000	[thread overview]
Message-ID: <20240218172731.1023367-3-jic23@kernel.org> (raw)
In-Reply-To: <20240218172731.1023367-1-jic23@kernel.org>

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Custom callbacks are need for regulators (so there is a handle to read
the voltage from) and the clk because it is retrieved from the parent
rather than directly from firmware description.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/fsl-imx25-gcq.c | 86 ++++++++++++++-------------------
 1 file changed, 35 insertions(+), 51 deletions(-)

diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 534e73a24eb4..394396b91630 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -282,6 +282,17 @@ static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
 	return 0;
 }
 
+static void mx25_gcq_reg_disable(void *reg)
+{
+	regulator_disable(reg);
+}
+
+/* Custom handling needed as this driver doesn't own the clock */
+static void mx25_gcq_clk_disable(void *clk)
+{
+	clk_disable_unprepare(clk);
+}
+
 static int mx25_gcq_probe(struct platform_device *pdev)
 {
 	struct iio_dev *indio_dev;
@@ -303,10 +314,9 @@ static int mx25_gcq_probe(struct platform_device *pdev)
 		return PTR_ERR(mem);
 
 	priv->regs = devm_regmap_init_mmio(dev, mem, &mx25_gcq_regconfig);
-	if (IS_ERR(priv->regs)) {
-		dev_err(dev, "Failed to initialize regmap\n");
-		return PTR_ERR(priv->regs);
-	}
+	if (IS_ERR(priv->regs))
+		return dev_err_probe(dev, PTR_ERR(priv->regs),
+				     "Failed to initialize regmap\n");
 
 	mutex_init(&priv->lock);
 
@@ -322,69 +332,44 @@ static int mx25_gcq_probe(struct platform_device *pdev)
 
 		ret = regulator_enable(priv->vref[i]);
 		if (ret)
-			goto err_regulator_disable;
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, mx25_gcq_reg_disable,
+					       priv->vref[i]);
+		if (ret)
+			return ret;
 	}
 
 	priv->clk = tsadc->clk;
 	ret = clk_prepare_enable(priv->clk);
-	if (ret) {
-		dev_err(dev, "Failed to enable clock\n");
-		goto err_vref_disable;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to enable clock\n");
+
+	ret = devm_add_action_or_reset(dev, mx25_gcq_clk_disable,
+				       priv->clk);
+	if (ret)
+		return ret;
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
-		goto err_clk_unprepare;
+		return ret;
 
 	priv->irq = ret;
-	ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv);
-	if (ret) {
-		dev_err(dev, "Failed requesting IRQ\n");
-		goto err_clk_unprepare;
-	}
+	ret = devm_request_irq(dev, priv->irq, mx25_gcq_irq, 0, pdev->name,
+			       priv);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed requesting IRQ\n");
 
 	indio_dev->channels = mx25_gcq_channels;
 	indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
 	indio_dev->info = &mx25_gcq_iio_info;
 	indio_dev->name = driver_name;
 
-	ret = iio_device_register(indio_dev);
-	if (ret) {
-		dev_err(dev, "Failed to register iio device\n");
-		goto err_irq_free;
-	}
-
-	platform_set_drvdata(pdev, indio_dev);
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to register iio device\n");
 
 	return 0;
-
-err_irq_free:
-	free_irq(priv->irq, priv);
-err_clk_unprepare:
-	clk_disable_unprepare(priv->clk);
-err_vref_disable:
-	i = 4;
-err_regulator_disable:
-	for (; i-- > 0;) {
-		if (priv->vref[i])
-			regulator_disable(priv->vref[i]);
-	}
-	return ret;
-}
-
-static void mx25_gcq_remove(struct platform_device *pdev)
-{
-	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
-	struct mx25_gcq_priv *priv = iio_priv(indio_dev);
-	int i;
-
-	iio_device_unregister(indio_dev);
-	free_irq(priv->irq, priv);
-	clk_disable_unprepare(priv->clk);
-	for (i = 4; i-- > 0;) {
-		if (priv->vref[i])
-			regulator_disable(priv->vref[i]);
-	}
 }
 
 static const struct of_device_id mx25_gcq_ids[] = {
@@ -399,7 +384,6 @@ static struct platform_driver mx25_gcq_driver = {
 		.of_match_table = mx25_gcq_ids,
 	},
 	.probe		= mx25_gcq_probe,
-	.remove_new	= mx25_gcq_remove,
 };
 module_platform_driver(mx25_gcq_driver);
 
-- 
2.43.2


  parent reply	other threads:[~2024-02-18 17:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18 17:27 [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Jonathan Cameron
2024-02-18 17:27 ` [PATCH 1/8] iio: adc: fsl-imx25-gcq: Switch from of specific handing to fwnode based Jonathan Cameron
2024-02-18 17:27 ` Jonathan Cameron [this message]
2024-02-18 17:27 ` [PATCH 3/8] iio: adc: ad7124: Switch from of specific to fwnode based property handling Jonathan Cameron
2024-02-19  9:24   ` Nuno Sá
2024-02-19 11:59     ` Andy Shevchenko
2024-02-19 11:58   ` Andy Shevchenko
2024-02-24 15:19     ` Jonathan Cameron
2024-02-18 17:27 ` [PATCH 4/8] iio: adc: ad7292: Switch from of specific to fwnode " Jonathan Cameron
2024-02-19  9:26   ` Nuno Sá
2024-02-18 17:27 ` [PATCH 5/8] iio: adc: ad7192: Convert " Jonathan Cameron
2024-02-19  9:30   ` Nuno Sá
2024-02-19 12:02   ` Andy Shevchenko
2024-02-18 17:27 ` [PATCH 6/8] iio: accel: mma8452: Switch " Jonathan Cameron
2024-02-23 11:10   ` Bough Chen
2024-02-18 17:27 ` [PATCH 7/8] iio: accel: fxls8962af: Switch from of specific to fwnode based properties Jonathan Cameron
2024-02-19 12:03   ` Andy Shevchenko
2024-02-18 17:27 ` [PATCH 8/8] iio: adc: hx711: Switch from of specific to fwnode property handling Jonathan Cameron
2024-02-19 12:06   ` Andy Shevchenko
2024-02-19 12:06 ` [PATCH 0/8] IIO: Convert DT specific handling over to fwnode Andy Shevchenko
2024-02-24 15:31   ` Jonathan Cameron

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=20240218172731.1023367-3-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=ak@it-klinger.de \
    --cc=alisa.roman@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=haibo.chen@nxp.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sean@geanix.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