* [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
@ 2021-08-30 14:59 Florian Boor
2021-09-05 11:26 ` Jonathan Cameron
2021-09-05 11:32 ` Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Florian Boor @ 2021-08-30 14:59 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan.Cameron, Michael.Hennerich, Florian Boor
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>
---
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;
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
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
2021-09-08 15:03 ` Florian Boor
2021-09-05 11:32 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2021-09-05 11:26 UTC (permalink / raw)
To: Florian Boor; +Cc: linux-iio, Jonathan.Cameron, Michael.Hennerich
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;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
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
@ 2021-09-05 11:32 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-09-05 11:32 UTC (permalink / raw)
To: Florian Boor; +Cc: linux-iio, Jonathan Cameron, Michael Hennerich
On Mon, Aug 30, 2021 at 6:38 PM 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.
...
> + of_property_read_u32(client->dev.of_node, "vref-external",
> + &vref_external);
Please, use device property API instead in the code you are submitting to IIO.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
2021-09-05 11:26 ` Jonathan Cameron
@ 2021-09-08 15:03 ` Florian Boor
0 siblings, 0 replies; 4+ messages in thread
From: Florian Boor @ 2021-09-08 15:03 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Jonathan.Cameron, Michael.Hennerich
Hi,
On 05.09.21 13:26, Jonathan Cameron wrote:
> On Mon, 30 Aug 2021 16:59:34 +0200
> 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.
okay right - in this case we could get rid of the additional setting and only if
there is no vref-supply provided we need to get a dummy.
> The driver will need a few changes to handle the possible error return
> from that call, but it shouldn't be too complicated.
I'll send an updated patch...
> 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!
I'll add this as well.
Greetings
Florian
--
The dream of yesterday Florian Boor
is the hope of today Tel: +49(0) 271-338857-15
and the reality of tomorrow. Fax: +49(0) 271-338857-29
[Robert Hutchings Goddard, 1904] florian.boor@kernelconcepts.de
http://www.kernelconcepts.de/en
kernel concepts GmbH
Hauptstraße 16
57074 Siegen
Deutschland
Geschäftsführer: Ole Reinhardt
HR Siegen, HR B 9613
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-08 15:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-09-08 15:03 ` Florian Boor
2021-09-05 11:32 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.