mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/5] iio: adc: ad7266: use devm_regulator_get_enable_read_voltage
Date: Wed, 12 Jun 2024 16:03:06 -0500	[thread overview]
Message-ID: <20240612-iio-adc-ref-supply-refactor-v2-2-fa622e7354e9@baylibre.com> (raw)
In-Reply-To: <20240612-iio-adc-ref-supply-refactor-v2-0-fa622e7354e9@baylibre.com>

This makes use of the new devm_regulator_get_enable_read_voltage()
function to reduce boilerplate code.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---

v2 changes:
- avoid else in return value check
- use macro instead of comment to explain internal reference voltage
---
 drivers/iio/adc/ad7266.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 353a97f9c086..874d2dc34f92 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -23,9 +23,10 @@
 
 #include <linux/platform_data/ad7266.h>
 
+#define AD7266_INTERNAL_REF_MV	2500
+
 struct ad7266_state {
 	struct spi_device	*spi;
-	struct regulator	*reg;
 	unsigned long		vref_mv;
 
 	struct spi_transfer	single_xfer[3];
@@ -377,11 +378,6 @@ static const char * const ad7266_gpio_labels[] = {
 	"ad0", "ad1", "ad2",
 };
 
-static void ad7266_reg_disable(void *reg)
-{
-	regulator_disable(reg);
-}
-
 static int ad7266_probe(struct spi_device *spi)
 {
 	struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -396,28 +392,11 @@ static int ad7266_probe(struct spi_device *spi)
 
 	st = iio_priv(indio_dev);
 
-	st->reg = devm_regulator_get_optional(&spi->dev, "vref");
-	if (!IS_ERR(st->reg)) {
-		ret = regulator_enable(st->reg);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
-		if (ret)
-			return ret;
-
-		ret = regulator_get_voltage(st->reg);
-		if (ret < 0)
-			return ret;
+	ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
+	if (ret < 0 && ret != -ENODEV)
+		return ret;
 
-		st->vref_mv = ret / 1000;
-	} else {
-		/* Any other error indicates that the regulator does exist */
-		if (PTR_ERR(st->reg) != -ENODEV)
-			return PTR_ERR(st->reg);
-		/* Use internal reference */
-		st->vref_mv = 2500;
-	}
+	st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000;
 
 	if (pdata) {
 		st->fixed_addr = pdata->fixed_addr;

-- 
2.45.2


  parent reply	other threads:[~2024-06-12 21:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12 21:03 [PATCH v2 0/5] iio: adc: use devm_regulator_get_enable_read_voltage round 1 David Lechner
2024-06-12 21:03 ` [PATCH v2 1/5] iio: adc: ad7192: use devm_regulator_get_enable_read_voltage David Lechner
2024-06-15 12:08   ` Jonathan Cameron
2024-06-17  9:35     ` Alisa-Dariana Roman
2024-06-17 13:22       ` David Lechner
2024-06-17 13:38         ` Alisa-Dariana Roman
2024-06-17 13:48           ` David Lechner
2024-06-17 14:10             ` Alisa-Dariana Roman
2024-06-17 15:28               ` David Lechner
2024-06-17 16:01                 ` Alisa-Dariana Roman
2024-06-17 20:00                   ` David Lechner
2024-06-18  9:45                     ` Alisa-Dariana Roman
2024-06-18 13:30                       ` David Lechner
2024-06-12 21:03 ` David Lechner [this message]
2024-06-15 12:12   ` [PATCH v2 2/5] iio: adc: ad7266: " Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 3/5] iio: adc: ad7292: " David Lechner
2024-06-14 15:11   ` Nuno Sá
2024-06-14 15:16     ` David Lechner
2024-06-15 12:14       ` Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 4/5] iio: adc: ad7793: " David Lechner
2024-06-15 12:15   ` Jonathan Cameron
2024-06-12 21:03 ` [PATCH v2 5/5] iio: adc: ad7944: " David Lechner
2024-06-14 15:16   ` Nuno Sá
2024-06-14 15:19     ` David Lechner
2024-06-15 12:18       ` Jonathan Cameron
2024-06-14 15:18 ` [PATCH v2 0/5] iio: adc: use devm_regulator_get_enable_read_voltage round 1 Nuno Sá

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=20240612-iio-adc-ref-supply-refactor-v2-2-fa622e7354e9@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=broonie@kernel.org \
    --cc=jic23@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --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

all inboxes | Powered by JetHome®