public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: [PATCH v2 4/4] iio: adc: ti-ads7950: complete conversion to using managed resources
Date: Wed, 18 Feb 2026 18:29:28 -0800	[thread overview]
Message-ID: <20260219022929.3558081-5-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260219022929.3558081-1-dmitry.torokhov@gmail.com>

All resources that the driver needs have managed API now. Switch to
using them to make code clearer and drop ti_ads7950_remove().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/iio/adc/ti-ads7950.c | 98 +++++++++++++++---------------------
 1 file changed, 40 insertions(+), 58 deletions(-)

diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index d31397f37ec4..1c53e000bdcc 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -528,19 +528,26 @@ static int ti_ads7950_init_hw(struct ti_ads7950_state *st)
 	return 0;
 }
 
+static void ti_ads7950_power_off(void *data)
+{
+	struct ti_ads7950_state *st = data;
+
+	regulator_disable(st->reg);
+}
+
 static int ti_ads7950_probe(struct spi_device *spi)
 {
 	struct ti_ads7950_state *st;
 	struct iio_dev *indio_dev;
 	const struct ti_ads7950_chip_info *info;
-	int ret;
+	int error;
 
 	spi->bits_per_word = 16;
 	spi->mode |= SPI_CS_WORD;
-	ret = spi_setup(spi);
-	if (ret < 0) {
+	error = spi_setup(spi);
+	if (error) {
 		dev_err(&spi->dev, "Error in spi setup\n");
-		return ret;
+		return error;
 	}
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -598,36 +605,36 @@ static int ti_ads7950_probe(struct spi_device *spi)
 	mutex_init(&st->slock);
 
 	st->reg = devm_regulator_get(&spi->dev, "vref");
-	if (IS_ERR(st->reg)) {
-		ret = dev_err_probe(&spi->dev, PTR_ERR(st->reg),
+	error = PTR_ERR_OR_ZERO(st->reg);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
 				     "Failed to get regulator \"vref\"\n");
-		goto error_destroy_mutex;
-	}
 
-	ret = regulator_enable(st->reg);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to enable regulator \"vref\"\n");
-		goto error_destroy_mutex;
-	}
+	error = regulator_enable(st->reg);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
+				     "Failed to enable regulator \"vref\"\n");
 
-	ret = iio_triggered_buffer_setup(indio_dev, NULL,
-					 &ti_ads7950_trigger_handler, NULL);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to setup triggered buffer\n");
-		goto error_disable_reg;
-	}
+	error = devm_add_action_or_reset(&spi->dev, ti_ads7950_power_off, st);
+	if (error)
+		return error;
 
-	ret = ti_ads7950_init_hw(st);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to init adc chip\n");
-		goto error_cleanup_ring;
-	}
+	error = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,
+						&ti_ads7950_trigger_handler,
+						NULL);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
+				     "Failed to setup triggered buffer\n");
 
-	ret = iio_device_register(indio_dev);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to register iio device\n");
-		goto error_cleanup_ring;
-	}
+	error = ti_ads7950_init_hw(st);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
+				     "Failed to init adc chip\n");
+
+	error = devm_iio_device_register(&spi->dev, indio_dev);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
+				     "Failed to register iio device\n");
 
 	/* Add GPIO chip */
 	st->chip.label = dev_name(&st->spi->dev);
@@ -642,36 +649,12 @@ static int ti_ads7950_probe(struct spi_device *spi)
 	st->chip.get = ti_ads7950_get;
 	st->chip.set = ti_ads7950_set;
 
-	ret = gpiochip_add_data(&st->chip, st);
-	if (ret) {
-		dev_err(&spi->dev, "Failed to init GPIOs\n");
-		goto error_iio_device;
-	}
+	error = devm_gpiochip_add_data(&spi->dev, &st->chip, st);
+	if (error)
+		return dev_err_probe(&spi->dev, error,
+				     "Failed to init GPIOs\n");
 
 	return 0;
-
-error_iio_device:
-	iio_device_unregister(indio_dev);
-error_cleanup_ring:
-	iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
-	regulator_disable(st->reg);
-error_destroy_mutex:
-	mutex_destroy(&st->slock);
-
-	return ret;
-}
-
-static void ti_ads7950_remove(struct spi_device *spi)
-{
-	struct iio_dev *indio_dev = spi_get_drvdata(spi);
-	struct ti_ads7950_state *st = iio_priv(indio_dev);
-
-	gpiochip_remove(&st->chip);
-	iio_device_unregister(indio_dev);
-	iio_triggered_buffer_cleanup(indio_dev);
-	regulator_disable(st->reg);
-	mutex_destroy(&st->slock);
 }
 
 static const struct spi_device_id ti_ads7950_id[] = {
@@ -714,7 +697,6 @@ static struct spi_driver ti_ads7950_driver = {
 		.of_match_table = ads7950_of_table,
 	},
 	.probe		= ti_ads7950_probe,
-	.remove		= ti_ads7950_remove,
 	.id_table	= ti_ads7950_id,
 };
 module_spi_driver(ti_ads7950_driver);
-- 
2.53.0.335.g19a08e0c02-goog


  parent reply	other threads:[~2026-02-19  2:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-19  2:29 [PATCH v2 0/4] ti-ads7950: fix gpio handling and facelift Dmitry Torokhov
2026-02-19  2:29 ` [PATCH v2 1/4] iio: adc: ti-ads7950: normalize return value of gpio_get Dmitry Torokhov
2026-02-19  7:52   ` Andy Shevchenko
2026-02-19  9:17   ` Bartosz Golaszewski
2026-02-19 18:25   ` Linus Walleij
2026-02-22 14:03   ` Jonathan Cameron
2026-02-22 21:22     ` Dmitry Torokhov
2026-02-19  2:29 ` [PATCH v2 2/4] iio: adc: ti-ads7950: do not clobber gpio state in ti_ads7950_get() Dmitry Torokhov
2026-02-19  7:55   ` Andy Shevchenko
2026-02-21 17:21   ` David Lechner
2026-02-19  2:29 ` [PATCH v2 3/4] iio: adc: ti-ads7950: switch to using guard() notation Dmitry Torokhov
2026-02-19  7:51   ` Andy Shevchenko
2026-02-21 17:20     ` David Lechner
2026-02-22 21:31       ` Dmitry Torokhov
2026-02-23 16:35         ` David Lechner
2026-02-21 17:34   ` David Lechner
2026-02-22 21:37     ` Dmitry Torokhov
2026-02-23 16:31       ` David Lechner
2026-02-19  2:29 ` Dmitry Torokhov [this message]
2026-02-19  7:59   ` [PATCH v2 4/4] iio: adc: ti-ads7950: complete conversion to using managed resources Andy Shevchenko
2026-02-21  0:09     ` Dmitry Torokhov
2026-02-22 19:12       ` Andy Shevchenko
2026-02-23 20:52         ` Jonathan Cameron
2026-02-21 17:43   ` David Lechner
2026-02-22 14:09   ` Jonathan Cameron
2026-02-22 21:39     ` Dmitry Torokhov

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=20260219022929.3558081-5-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.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