public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Florian Boor <florian.boor@kernelconcepts.de>
Cc: linux-iio@vger.kernel.org, Jonathan.Cameron@huawei.com,
	Michael.Hennerich@analog.com
Subject: Re: [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
Date: Sun, 5 Sep 2021 12:26:53 +0100	[thread overview]
Message-ID: <20210905122653.0e081ab2@jic23-huawei> (raw)
In-Reply-To: <20210830145934.11024-1-florian.boor@kernelconcepts.de>

On Mon, 30 Aug 2021 16:59:34 +0200
Florian Boor <florian.boor@kernelconcepts.de> wrote:

> Make use of the AD7991_REF_SEL bit and support using the external
> reference voltage by setting the 'vref-external' property in devicetree.
> 
> Signed-off-by: Florian Boor <florian.boor@kernelconcepts.de>

Normal convention on this (not helped here by the complete lack of
a binding document for this device) would be that the driver would
use the external vref is vref-supply is present.

Currently the driver uses devm_regulator_get().  In this case it
should be using devm_regulator_get_optional() as that will avoid a
'fake' regulator being provided.  

The driver will need a few changes to handle the possible error return
from that call, but it shouldn't be too complicated.

If you are willing it would be great to have a binding description for
this driver. I'm no sure how it has slipped through the net for so long!

Jonathan

> ---
>  drivers/iio/adc/ad799x.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
> index 18bf8386d50a..3ae7ec72caa3 100644
> --- a/drivers/iio/adc/ad799x.c
> +++ b/drivers/iio/adc/ad799x.c
> @@ -770,6 +770,7 @@ static int ad799x_probe(struct i2c_client *client,
>  				   const struct i2c_device_id *id)
>  {
>  	int ret;
> +	int extra_config = 0;
>  	struct ad799x_state *st;
>  	struct iio_dev *indio_dev;
>  	const struct ad799x_chip_info *chip_info =
> @@ -806,6 +807,17 @@ static int ad799x_probe(struct i2c_client *client,
>  	if (ret)
>  		goto error_disable_reg;
>  
> +
> +	/* allow to use external reference voltage */
> +	if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) {
> +		unsigned int vref_external = 0;
> +	        of_property_read_u32(client->dev.of_node, "vref-external",
> +			&vref_external);
> +
> +		if (vref_external)
> +			extra_config |= AD7991_REF_SEL;
> +	}
> +
>  	st->client = client;
>  
>  	indio_dev->name = id->name;
> @@ -815,7 +827,7 @@ static int ad799x_probe(struct i2c_client *client,
>  	indio_dev->channels = st->chip_config->channel;
>  	indio_dev->num_channels = chip_info->num_channels;
>  
> -	ret = ad799x_update_config(st, st->chip_config->default_config);
> +	ret = ad799x_update_config(st, st->chip_config->default_config | extra_config);
>  	if (ret)
>  		goto error_disable_vref;
>  


  reply	other threads:[~2021-09-05 11:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 14:59 [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999 Florian Boor
2021-09-05 11:26 ` Jonathan Cameron [this message]
2021-09-08 15:03   ` Florian Boor
2021-09-05 11:32 ` Andy Shevchenko

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=20210905122653.0e081ab2@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=florian.boor@kernelconcepts.de \
    --cc=linux-iio@vger.kernel.org \
    /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