iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
Subsystems (3)
PATCH v2 1/2 iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
Make use of the AD7991_REF_SEL bit and support using the external reference voltage if 'vref-supply' is present.
---
Changes in v2:
- Check if a provided external vref regulator is provided.
- Drop unused setting
- Add ad79xx documentation (second patch)
drivers/iio/adc/ad799x.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/iio/adc/ad799x.c +19 -2
@@ -770,6 +770,8 @@ static int ad799x_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; +int extra_config =0 ; +bool vref_external = true;struct ad799x_state *st;struct iio_dev *indio_dev; const struct ad799x_chip_info *chip_info =
@@ -797,7 +799,15 @@ static int ad799x_probe(struct i2c_client *client, ret =regulator_enable (st->reg);if (ret)return ret; - st->vref =devm_regulator_get (&client->dev,"vref" ); + +/* check if an external reference is supplied */ + st->vref =devm_regulator_get_optional (&client->dev,"vref" ); + +if (PTR_ERR (st->vref) == -ENODEV ) { + vref_external = false; +/* get dummy */ + st->vref =devm_regulator_get (&client->dev,"vref" ); + }if (IS_ERR (st->vref)) { ret =PTR_ERR (st->vref); goto error_disable_reg;
@@ -806,6 +816,13 @@ static int ad799x_probe(struct i2c_client *client,if (ret) goto error_disable_reg; +/* use external reference voltage, optional if regulator present */ +if (vref_external && + ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999))) { +dev_info (&client->dev,"Using external reference voltage\n" ); + extra_config |=AD7991_REF_SEL ; + } + st->client = client; indio_dev->name = id->name;
@@ -815,7 +832,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;
Signature · 1 line
2.30.2
PATCH v2 2/2 dt-binding: iio: Add documentation for AD799x driver
New documentation for AD799x series of I²C ADC ICs.
--- .../bindings/iio/adc/adi,ad799x.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad799x.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad799x.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad799x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD7991, AD7992, AD7993, AD7994, AD7995, AD7997, AD7998, + AD7999 and similar analog to digital converters + +maintainers: + - Michael Hennerich, Analog Devices Inc. <[email protected]> + +description: | + Specifications on the converters can be found at: + AD7991, AD7995, AD7999: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7991_7995_7999.pdf + AD7992: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7992.pdf + AD7993, AD7994: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7993_7994.pdf + AD7997, AD7998: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7997_7998.pdf + +properties: + compatible: + enum: + - adi,ad7991 + - adi,ad7992 + - adi,ad7993 + - adi,ad7994 + - adi,ad7995 + - adi,ad7997 + - adi,ad7998 + - adi,ad7999 + + reg: + maxItems: 1 + + vcc-supply: + description: + ADC power supply + + vref-supply: + description: + ADC reference voltage supply, optional for AD7991, AD7995 and AD7999 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + adc1: ad7991@28 { + reg = <0x28>; + compatible = "adi,ad7991"; + vcc-supply = <&vcc_3v3>; + vref-supply = <&adc_vref>; + }; +...
Signature · 1 line
2.30.2
Jonathan Cameron
maintainerRe: [PATCH v2 2/2] dt-binding: iio: Add documentation for AD799x driver
Quoted 1 line · On Wed, 8 Sep 2021 17:25:25 +0200 Florian Boor…
New documentation for AD799x series of I²C ADC ICs.
interrupts?
Otherwise seems to match what the driver support.
Thanks,
Jonathan
Quoted 74 lines
Signed-off-by Florian Boor <[email protected]>--- .../bindings/iio/adc/adi,ad799x.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad799x.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad799x.yaml new file +61
-0@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad799x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD7991, AD7992, AD7993, AD7994, AD7995, AD7997, AD7998, + AD7999 and similar analog to digital converters + +maintainers: + - Michael Hennerich, Analog Devices Inc. <[email protected]> + +description: | + Specifications on the converters can be found at: + AD7991, AD7995, AD7999: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7991_7995_7999.pdf + AD7992: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7992.pdf + AD7993, AD7994: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7993_7994.pdf + AD7997, AD7998: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7997_7998.pdf + +properties: + compatible: + enum: + - adi,ad7991 + - adi,ad7992 + - adi,ad7993 + - adi,ad7994 + - adi,ad7995 + - adi,ad7997 + - adi,ad7998 + - adi,ad7999 + + reg: + maxItems: 1 + + vcc-supply: + description: + ADC power supply + + vref-supply: + description: + ADC reference voltage supply, optional for AD7991, AD7995 and AD7999 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + adc1: ad7991@28 { + reg = <0x28>; + compatible = "adi,ad7991"; + vcc-supply = <&vcc_3v3>; + vref-supply = <&adc_vref>; + }; +...
Jonathan Cameron
maintainerQuoted 4 lines · On Wed, 8 Sep 2021 17:25:24 +0200 Florian Boor…
Make use of the
AD7991_REF_SELbit and support using the external reference voltage if 'vref-supply' is present.Signed-off-by Florian Boor <[email protected]>
Hi Florian,
Quoted 26 lines
---
Changes in v2:
- Check if a provided external vref regulator is provided.
- Drop unused setting
- Add ad79xx documentation (second patch)drivers/iio/adc/ad799x.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)drivers/iio/adc/ad799x.c +2
-0@@ -770,6 +770,8 @@ static int ad799x_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; +int extra_config =0 ; +bool vref_external = true;struct ad799x_state *st;struct iio_dev *indio_dev; const struct ad799x_chip_info *chip_info =@@ -797,7 +799,15 @@ static int ad799x_probe(struct i2c_client *client, ret =regulator_enable (st->reg);if (ret)
drivers/iio/adc/ad799x.c static int ad799x_probe(struct i2c_client *client, · line 809
Quoted 10 lines
drivers/iio/adc/ad799x.c +8
-1return ret; - st->vref =devm_regulator_get (&client->dev,"vref" ); + +/* check if an external reference is supplied */ + st->vref =devm_regulator_get_optional (&client->dev,"vref" ); + +if (PTR_ERR (st->vref) == -ENODEV ) { + vref_external = false; +/* get dummy */ + st->vref =devm_regulator_get (&client->dev,"vref" );
Why? Instead of doing this add if (st->vref) around the regulator enable and disable. We don't want to pretend there is a regulator when there isn't one connected and we are using VDD as the reference.
If we are in that mode, we need to change which regulator is read in read_raw()
Quoted 27 lines
drivers/iio/adc/ad799x.c +9
-1+ }if (IS_ERR (st->vref)) { ret =PTR_ERR (st->vref); goto error_disable_reg;@@ -806,6 +816,13 @@ static int ad799x_probe(struct i2c_client *client,if (ret) goto error_disable_reg; +/* use external reference voltage, optional if regulator present */ +if (vref_external && + ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999))) { +dev_info (&client->dev,"Using external reference voltage\n" ); + extra_config |=AD7991_REF_SEL ; + } + st->client = client; indio_dev->name = id->name;@@ -815,7 +832,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;
Hi Jonathan,
Quoted 51 lines · Jonathan Cameron
Quoted 4 lines · On Wed, 8 Sep 2021 17:25:24 +0200 Florian Boor…
Make use of the
AD7991_REF_SELbit and support using the external reference voltage if 'vref-supply' is present.Signed-off-by Florian Boor <[email protected]>Hi Florian,
Quoted 26 lines
---
Changes in v2:
- Check if a provided external vref regulator is provided.
- Drop unused setting
- Add ad79xx documentation (second patch)drivers/iio/adc/ad799x.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)drivers/iio/adc/ad799x.c +2
-0@@ -770,6 +770,8 @@ static int ad799x_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; +int extra_config =0 ; +bool vref_external = true;struct ad799x_state *st;struct iio_dev *indio_dev; const struct ad799x_chip_info *chip_info =@@ -797,7 +799,15 @@ static int ad799x_probe(struct i2c_client *client, ret =regulator_enable (st->reg);if (ret)drivers/iio/adc/ad799x.c static int ad799x_probe(struct i2c_client *client, · line 809
Quoted 10 lines
drivers/iio/adc/ad799x.c +8
-1return ret; - st->vref =devm_regulator_get (&client->dev,"vref" ); + +/* check if an external reference is supplied */ + st->vref =devm_regulator_get_optional (&client->dev,"vref" ); + +if (PTR_ERR (st->vref) == -ENODEV ) { + vref_external = false; +/* get dummy */ + st->vref =devm_regulator_get (&client->dev,"vref" );Why? Instead of doing this add if (
st->vref) around the regulator enable and disable. We don't want to pretend there is a regulator when there isn't one connected and we are using VDD as the reference.
Quoted 2 lines
If we are in that mode, we need to change which regulator is read in
read_raw()
I have to admit I wondered about how this is handled as well. My idea was not to change it at this point and improve this later in a separate patch. But I see the point - I'll add this change as well.
Greetings
Florian
Signature · 12 lines
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] [email protected] http://www.kernelconcepts.de/en kernel concepts GmbH Hauptstraße 16 57074 Siegen Deutschland Geschäftsführer: Ole Reinhardt HR Siegen, HR B 9613