Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ti-tsc2046: use devm_regulator_get_enable_read_voltage()
@ 2024-07-25 19:22 David Lechner
  2024-07-26 10:56 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: David Lechner @ 2024-07-25 19:22 UTC (permalink / raw)
  To: Oleksij Rempel, Jonathan Cameron
  Cc: David Lechner, kernel, Liam Girdwood, Mark Brown, linux-iio,
	linux-kernel

Use devm_regulator_get_enable_read_voltage() to replace
tsc2046_adc_configure_regulator() which does the same thing.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ti-tsc2046.c | 54 ++++++--------------------------------------
 1 file changed, 7 insertions(+), 47 deletions(-)

diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c
index 24b1d4390872..311d97001249 100644
--- a/drivers/iio/adc/ti-tsc2046.c
+++ b/drivers/iio/adc/ti-tsc2046.c
@@ -142,7 +142,7 @@ enum tsc2046_state {
 struct tsc2046_adc_priv {
 	struct spi_device *spi;
 	const struct tsc2046_adc_dcfg *dcfg;
-	struct regulator *vref_reg;
+	bool internal_vref;
 
 	struct iio_trigger *trig;
 	struct hrtimer trig_timer;
@@ -258,7 +258,7 @@ static u8 tsc2046_adc_get_cmd(struct tsc2046_adc_priv *priv, int ch_idx,
 	case TI_TSC2046_ADDR_VBAT:
 	case TI_TSC2046_ADDR_TEMP0:
 		pd |= TI_TSC2046_SER;
-		if (!priv->vref_reg)
+		if (priv->internal_vref)
 			pd |= TI_TSC2046_PD1_VREF_ON;
 	}
 
@@ -741,49 +741,6 @@ static void tsc2046_adc_parse_fwnode(struct tsc2046_adc_priv *priv)
 	}
 }
 
-static void tsc2046_adc_regulator_disable(void *data)
-{
-	struct tsc2046_adc_priv *priv = data;
-
-	regulator_disable(priv->vref_reg);
-}
-
-static int tsc2046_adc_configure_regulator(struct tsc2046_adc_priv *priv)
-{
-	struct device *dev = &priv->spi->dev;
-	int ret;
-
-	priv->vref_reg = devm_regulator_get_optional(dev, "vref");
-	if (IS_ERR(priv->vref_reg)) {
-		/* If regulator exists but can't be get, return an error */
-		if (PTR_ERR(priv->vref_reg) != -ENODEV)
-			return PTR_ERR(priv->vref_reg);
-		priv->vref_reg = NULL;
-	}
-	if (!priv->vref_reg) {
-		/* Use internal reference */
-		priv->vref_mv = TI_TSC2046_INT_VREF;
-		return 0;
-	}
-
-	ret = regulator_enable(priv->vref_reg);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(dev, tsc2046_adc_regulator_disable,
-				       priv);
-	if (ret)
-		return ret;
-
-	ret = regulator_get_voltage(priv->vref_reg);
-	if (ret < 0)
-		return ret;
-
-	priv->vref_mv = ret / MILLI;
-
-	return 0;
-}
-
 static int tsc2046_adc_probe(struct spi_device *spi)
 {
 	const struct tsc2046_adc_dcfg *dcfg;
@@ -825,10 +782,13 @@ static int tsc2046_adc_probe(struct spi_device *spi)
 	indio_dev->num_channels = dcfg->num_channels;
 	indio_dev->info = &tsc2046_adc_info;
 
-	ret = tsc2046_adc_configure_regulator(priv);
-	if (ret)
+	ret = devm_regulator_get_enable_read_voltage(dev, "vref");
+	if (ret < 0 && ret != -ENODEV)
 		return ret;
 
+	priv->internal_vref = ret == -ENODEV;
+	priv->vref_mv = priv->internal_vref ? TI_TSC2046_INT_VREF : ret / MILLI;
+
 	tsc2046_adc_parse_fwnode(priv);
 
 	ret = tsc2046_adc_setup_spi_msg(priv);

---
base-commit: 472438c7e0e2261c6737a8321f46ef176eef1c8f
change-id: 20240725-iio-regulator-refactor-round-4-13f032a6f2cc

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ti-tsc2046: use devm_regulator_get_enable_read_voltage()
  2024-07-25 19:22 [PATCH] iio: adc: ti-tsc2046: use devm_regulator_get_enable_read_voltage() David Lechner
@ 2024-07-26 10:56 ` Nuno Sá
  2024-07-28 15:34   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2024-07-26 10:56 UTC (permalink / raw)
  To: David Lechner, Oleksij Rempel, Jonathan Cameron
  Cc: kernel, Liam Girdwood, Mark Brown, linux-iio, linux-kernel

On Thu, 2024-07-25 at 14:22 -0500, David Lechner wrote:
> Use devm_regulator_get_enable_read_voltage() to replace
> tsc2046_adc_configure_regulator() which does the same thing.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: ti-tsc2046: use devm_regulator_get_enable_read_voltage()
  2024-07-26 10:56 ` Nuno Sá
@ 2024-07-28 15:34   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2024-07-28 15:34 UTC (permalink / raw)
  To: Nuno Sá
  Cc: David Lechner, Oleksij Rempel, kernel, Liam Girdwood, Mark Brown,
	linux-iio, linux-kernel

On Fri, 26 Jul 2024 12:56:27 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Thu, 2024-07-25 at 14:22 -0500, David Lechner wrote:
> > Use devm_regulator_get_enable_read_voltage() to replace
> > tsc2046_adc_configure_regulator() which does the same thing.
> > 
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---  
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 
> 

Applied

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-28 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 19:22 [PATCH] iio: adc: ti-tsc2046: use devm_regulator_get_enable_read_voltage() David Lechner
2024-07-26 10:56 ` Nuno Sá
2024-07-28 15:34   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox