linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability
@ 2025-08-07  7:48 Stefano Manni
  2025-08-07  7:48 ` [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info Stefano Manni
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Stefano Manni @ 2025-08-07  7:48 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy
  Cc: linux-iio, linux-kernel, Stefano Manni

This patch series refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
in order to add the capability of the chip to have an
external reference voltage into the chip_info struct.
And so avoid ugly conditional checks on the chip id.

In addition the AD7994 is marked to have the external
reference voltage as well.

Changes in v2 compared to v1 [1]:
* remove has_vref from the chips that do not support it,
  rely on the default false value
* remove useless message "Supplied reference not supported"
  shown for all the chips with has_vref = false
* refactor check on regulator being err or zero
* add external reference to ad7994 as oneliner

[1] https://lore.kernel.org/linux-iio/20250806090158.117628-1-stefano.manni@gmail.com/

Stefano Manni (2):
  iio: adc: ad799x: add reference voltage capability to chip_info
  iio: adc: ad799x: add reference voltage to ad7994

 drivers/iio/adc/ad799x.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

-- 
2.48.1


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

* [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info
  2025-08-07  7:48 [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability Stefano Manni
@ 2025-08-07  7:48 ` Stefano Manni
  2025-08-07 21:05   ` Andy Shevchenko
  2025-08-07  7:48 ` [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994 Stefano Manni
  2025-08-07 15:47 ` [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability David Lechner
  2 siblings, 1 reply; 7+ messages in thread
From: Stefano Manni @ 2025-08-07  7:48 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy
  Cc: linux-iio, linux-kernel, Stefano Manni, Andy Shevchenko

If the chip supports an external reference voltage
on REFIN pin then the "vref-supply" regulator may be used.

This commit partially refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
to add the capability of the chip to have an external
voltage reference and then remove the ugly conditional check
on chip id.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Stefano Manni <stefano.manni@gmail.com>
---
 drivers/iio/adc/ad799x.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 9c02f9199139..f645995b0929 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -114,11 +114,13 @@ struct ad799x_chip_config {
  * @num_channels:	number of channels
  * @noirq_config:	device configuration w/o IRQ
  * @irq_config:		device configuration w/IRQ
+ * @has_vref:		device supports external reference voltage
  */
 struct ad799x_chip_info {
 	int				num_channels;
 	const struct ad799x_chip_config	noirq_config;
 	const struct ad799x_chip_config	irq_config;
+	bool has_vref;
 };
 
 struct ad799x_state {
@@ -604,6 +606,7 @@ static const struct iio_event_spec ad799x_events[] = {
 static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7991] = {
 		.num_channels = 5,
+		.has_vref = true,
 		.noirq_config = {
 			.channel = {
 				AD799X_CHANNEL(0, 12),
@@ -617,6 +620,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7995] = {
 		.num_channels = 5,
+		.has_vref = true,
 		.noirq_config = {
 			.channel = {
 				AD799X_CHANNEL(0, 10),
@@ -630,6 +634,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7999] = {
 		.num_channels = 5,
+		.has_vref = true,
 		.noirq_config = {
 			.channel = {
 				AD799X_CHANNEL(0, 8),
@@ -809,32 +814,22 @@ static int ad799x_probe(struct i2c_client *client)
 		return ret;
 
 	/* check if an external reference is supplied */
-	st->vref = devm_regulator_get_optional(&client->dev, "vref");
-
-	if (IS_ERR(st->vref)) {
-		if (PTR_ERR(st->vref) == -ENODEV) {
+	if (chip_info->has_vref) {
+		st->vref = devm_regulator_get_optional(&client->dev, "vref");
+		ret = PTR_ERR_OR_ZERO(st->vref);
+		if (ret) {
+			if (ret != -ENODEV)
+				goto error_disable_reg;
 			st->vref = NULL;
 			dev_info(&client->dev, "Using VCC reference voltage\n");
-		} else {
-			ret = PTR_ERR(st->vref);
-			goto error_disable_reg;
 		}
-	}
 
-	if (st->vref) {
-		/*
-		 * Use external reference voltage if supported by hardware.
-		 * This is optional if voltage / regulator present, use VCC otherwise.
-		 */
-		if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) {
+		if (st->vref) {
 			dev_info(&client->dev, "Using external reference voltage\n");
 			extra_config |= AD7991_REF_SEL;
 			ret = regulator_enable(st->vref);
 			if (ret)
 				goto error_disable_reg;
-		} else {
-			st->vref = NULL;
-			dev_warn(&client->dev, "Supplied reference not supported\n");
 		}
 	}
 
-- 
2.48.1


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

* [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994
  2025-08-07  7:48 [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability Stefano Manni
  2025-08-07  7:48 ` [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info Stefano Manni
@ 2025-08-07  7:48 ` Stefano Manni
  2025-08-07 21:06   ` Andy Shevchenko
  2025-08-07 15:47 ` [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability David Lechner
  2 siblings, 1 reply; 7+ messages in thread
From: Stefano Manni @ 2025-08-07  7:48 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy
  Cc: linux-iio, linux-kernel, Stefano Manni

AD7994 supports external reference voltage on REFIN
pin so if a vref-supply has been defined it shall be
used.

Signed-off-by: Stefano Manni <stefano.manni@gmail.com>
---
 drivers/iio/adc/ad799x.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index f645995b0929..108bb22162ef 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -692,6 +692,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7994] = {
 		.num_channels = 5,
+		.has_vref = true,
 		.noirq_config = {
 			.channel = {
 				AD799X_CHANNEL(0, 12),
-- 
2.48.1


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

* Re: [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability
  2025-08-07  7:48 [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability Stefano Manni
  2025-08-07  7:48 ` [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info Stefano Manni
  2025-08-07  7:48 ` [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994 Stefano Manni
@ 2025-08-07 15:47 ` David Lechner
  2025-08-09 19:33   ` Jonathan Cameron
  2 siblings, 1 reply; 7+ messages in thread
From: David Lechner @ 2025-08-07 15:47 UTC (permalink / raw)
  To: Stefano Manni, lars, Michael.Hennerich, jic23, nuno.sa, andy
  Cc: linux-iio, linux-kernel

On 8/7/25 2:48 AM, Stefano Manni wrote:
> This patch series refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
> in order to add the capability of the chip to have an
> external reference voltage into the chip_info struct.
> And so avoid ugly conditional checks on the chip id.
> 
> In addition the AD7994 is marked to have the external
> reference voltage as well.
> 
> Changes in v2 compared to v1 [1]:
> * remove has_vref from the chips that do not support it,
>   rely on the default false value
> * remove useless message "Supplied reference not supported"
>   shown for all the chips with has_vref = false
> * refactor check on regulator being err or zero
> * add external reference to ad7994 as oneliner
> 
> [1] https://lore.kernel.org/linux-iio/20250806090158.117628-1-stefano.manni@gmail.com/
> 
> Stefano Manni (2):
>   iio: adc: ad799x: add reference voltage capability to chip_info
>   iio: adc: ad799x: add reference voltage to ad7994
> 
>  drivers/iio/adc/ad799x.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)
> 

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


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

* Re: [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info
  2025-08-07  7:48 ` [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info Stefano Manni
@ 2025-08-07 21:05   ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-08-07 21:05 UTC (permalink / raw)
  To: Stefano Manni
  Cc: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy,
	linux-iio, linux-kernel, Andy Shevchenko

On Thu, Aug 7, 2025 at 9:49 AM Stefano Manni <stefano.manni@gmail.com> wrote:
>
> If the chip supports an external reference voltage
> on REFIN pin then the "vref-supply" regulator may be used.
>
> This commit partially refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
> to add the capability of the chip to have an external
> voltage reference and then remove the ugly conditional check
> on chip id.

Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994
  2025-08-07  7:48 ` [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994 Stefano Manni
@ 2025-08-07 21:06   ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2025-08-07 21:06 UTC (permalink / raw)
  To: Stefano Manni
  Cc: lars, Michael.Hennerich, jic23, dlechner, nuno.sa, andy,
	linux-iio, linux-kernel

On Thu, Aug 7, 2025 at 9:49 AM Stefano Manni <stefano.manni@gmail.com> wrote:
>
> AD7994 supports external reference voltage on REFIN
> pin so if a vref-supply has been defined it shall be
> used.

Now LGTM
Reviewed-by: Andy Shevchenko <andy@kernel.org>

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability
  2025-08-07 15:47 ` [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability David Lechner
@ 2025-08-09 19:33   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2025-08-09 19:33 UTC (permalink / raw)
  To: David Lechner
  Cc: Stefano Manni, lars, Michael.Hennerich, nuno.sa, andy, linux-iio,
	linux-kernel

On Thu, 7 Aug 2025 10:47:29 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 8/7/25 2:48 AM, Stefano Manni wrote:
> > This patch series refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
> > in order to add the capability of the chip to have an
> > external reference voltage into the chip_info struct.
> > And so avoid ugly conditional checks on the chip id.
> > 
> > In addition the AD7994 is marked to have the external
> > reference voltage as well.
> > 
> > Changes in v2 compared to v1 [1]:
> > * remove has_vref from the chips that do not support it,
> >   rely on the default false value
> > * remove useless message "Supplied reference not supported"
> >   shown for all the chips with has_vref = false
> > * refactor check on regulator being err or zero
> > * add external reference to ad7994 as oneliner
> > 
> > [1] https://lore.kernel.org/linux-iio/20250806090158.117628-1-stefano.manni@gmail.com/
> > 
> > Stefano Manni (2):
> >   iio: adc: ad799x: add reference voltage capability to chip_info
> >   iio: adc: ad799x: add reference voltage to ad7994
> > 
> >  drivers/iio/adc/ad799x.c | 30 +++++++++++++-----------------
> >  1 file changed, 13 insertions(+), 17 deletions(-)
> >   
> 
> Reviewed-by: David Lechner <dlechner@baylibre.com>
> 
Applied to the testing branch of iio.git.  I'll rebase on rc1 once
it's available.

thanks,

Jonathan


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

end of thread, other threads:[~2025-08-09 19:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  7:48 [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability Stefano Manni
2025-08-07  7:48 ` [PATCH v2 1/2] iio: adc: ad799x: add reference voltage capability to chip_info Stefano Manni
2025-08-07 21:05   ` Andy Shevchenko
2025-08-07  7:48 ` [PATCH v2 2/2] iio: adc: ad799x: add reference voltage to ad7994 Stefano Manni
2025-08-07 21:06   ` Andy Shevchenko
2025-08-07 15:47 ` [PATCH v2 0/2] iio: adc: ad799x: reference voltage capability David Lechner
2025-08-09 19:33   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).