Add support for additional AD717x models
Subsystems (3)
v2 cover Add support for additional AD717x models
This patch series adds support for the Analog Devices AD7172-2, AD7175-8,
AD7177-2 ADCs within the AD7173 driver.
Datasheets:
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-4.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-8.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7177-2.pdf
V1->V2
dt-bindings: adc: ad7173: add support for additional models:
- Remove bindings descriptions update as already included in latest AD7173 bindings
- Remove default: false for adi,reference-select
iio: adc: ad7173: add support for additional models:
- Add period to commit message
- AD717X -> AD717x
- Fix typo
- Reformat supported devices list
- Reorder device ID's by value
- Use correct comment style
- Add missing space
Dumitru Ceclan (2):
dt-bindings: adc: ad7173: add support for additional models
iio: adc: ad7173: add support for additional models
.../bindings/iio/adc/adi,ad7173.yaml | 39 ++++++++- drivers/iio/adc/ad7173.c | 82 +++++++++++++++++-- 2 files changed, 110 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 dt-bindings: adc: ad7173: add support for additional models
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence.
--- .../bindings/iio/adc/adi,ad7173.yaml | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +36 -3
@@ -21,17 +21,23 @@ description: | Datasheets for supported chips: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7173-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7176-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7177-2.pdf properties: compatible: enum: - adi,ad7172-2 + - adi,ad7172-4 - adi,ad7173-8 - adi,ad7175-2 + - adi,ad7175-8 - adi,ad7176-2 + - adi,ad7177-2 reg: maxItems: 1
@@ -136,8 +142,10 @@ patternProperties: refout-avss: REFOUT/AVSS (Internal reference) avdd : AVDD /AVSS - External reference ref2 only available on ad7173-8. - If not specified, internal reference used. + External reference ref2 only available on ad7173-8 and ad7172-4. + Internal reference refout-avss not available on ad7172-4. + + If not specified, internal reference used (if available). $ref: /schemas/types.yaml#/definitions/string enum: - vref
@@ -157,12 +165,15 @@ required: allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# + # Only ad7172-4 and ad7173-8 support vref2 - if: properties: compatible: not: contains: - const: adi,ad7173-8 + anyOf: + - const: adi,ad7172-4 + - const: adi,ad7173-8 then: properties: vref2-supply: false
@@ -177,6 +188,28 @@ allOf: reg: maximum: 3 + # Model ad7172-4 does not support internal reference + # mandatory to have an external reference + - if: + properties: + compatible: + contains: + const: adi,ad7172-4 + then: + patternProperties: + "^channel@[0-9a-f]$": + properties: + adi,reference-select: + enum: + - vref + - vref2 + - avdd + required: + - adi,reference-select + oneOf: + - required: [vref2-supply] + - required: [vref-supply] + - if: anyOf: - required: [clock-names]
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Quoted 13 lines · Dumitru Ceclan
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence.Signed-off-by Dumitru Ceclan <[email protected]>--- .../bindings/iio/adc/adi,ad7173.yaml | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +0
-0
There is no such file in next-20240229.
Quoted 39 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-2@@ -21,17 +21,23 @@ description: | Datasheets for supported chips: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7173-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7176-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7177-2.pdf properties: compatible: enum: - adi,ad7172-2 + - adi,ad7172-4 - adi,ad7173-8 - adi,ad7175-2 + - adi,ad7175-8 - adi,ad7176-2 + - adi,ad7177-2 reg: maxItems: 1@@ -136,8 +142,10 @@ patternProperties: refout-avss: REFOUT/AVSS (Internal reference) avdd : AVDD /AVSS - External reference ref2 only available on ad7173-8. - If not specified, internal reference used. + External reference ref2 only available on ad7173-8 and ad7172-4. + Internal reference refout-avss not available on ad7172-4. + + If not specified, internal reference used (if available). $ref: /schemas/types.yaml#/definitions/string enum: - vref@@ -157,12 +165,15 @@ required: allOf:
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml required: · line 174
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +2
-1- $ref: /schemas/spi/spi-peripheral-props.yaml# + # Only ad7172-4 and ad7173-8 support vref2 - if: properties: compatible: not: contains: - const: adi,ad7173-8 + anyOf:
That's enum... or you want to make something more complicated because I see there not:...
Quoted 17 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-0+ - const: adi,ad7172-4 + - const: adi,ad7173-8 then: properties: vref2-supply: false@@ -177,6 +188,28 @@ allOf: reg: maximum: 3 + # Model ad7172-4 does not support internal reference + # mandatory to have an external reference + - if: + properties: + compatible: + contains: + const: adi,ad7172-4 + then:
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml allOf: · line 208
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-0+ patternProperties: + "^channel@[0-9a-f]$": + properties: + adi,reference-select: + enum: + - vref + - vref2 + - avdd + required: + - adi,reference-select
Are you defining properties here? I cannot verify because this file does not exist in next.
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml allOf: · line 211
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +3
-0+ oneOf: + - required: [vref2-supply] + - required: [vref-supply]
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Dumitru Ceclan
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence.
...
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Quoted 2 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +0
-0There is no such file in next-20240229.
It's not yet accepted
https://lore.kernel.org/all/[email protected]/
...
Quoted 19 lines
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +8
-0+ # Model ad7172-4 does not support internal reference + # mandatory to have an external reference + - if: + properties: + compatible: + contains: + const: adi,ad7172-4 + then:Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml allOf: · line 208
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-0+ patternProperties: + "^channel@[0-9a-f]$": + properties: + adi,reference-select: + enum: + - vref + - vref2 + - avdd + required: + - adi,reference-select
Quoted 3 lines
Are you defining properties here? I cannot verify because this file does not exist in next.
No, just constraining reference-select to be required and exclude "refout-avss".
Quoted 5 lines
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
Quoted 8 lines · Dumitru
Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Dumitru Ceclan
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence....
Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Quoted 2 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +0
-0There is no such file in next-20240229.
It's not yet accepted
https://lore.kernel.org/all/[email protected]/
And how can we know this? You must clearly document dependencies.
This also means the patch cannot be directly applied and cannot be tested by toolset.
Did you test this particular patch?
Quoted 22 lines
...
Quoted 19 lines
Quoted 18 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +18
-0+ # Model ad7172-4 does not support internal reference + # mandatory to have an external reference + - if: + properties: + compatible: + contains: + const: adi,ad7172-4 + then: + patternProperties: + "^channel@[0-9a-f]$": + properties: + adi,reference-select: + enum: + - vref + - vref2 + - avdd + required: + - adi,reference-select
Quoted 7 lines
Quoted 3 lines
Are you defining properties here? I cannot verify because this file does not exist in next.
No, just constraining reference-select to be required and exclude "refout-avss".
ok
Best regards,
Krzysztof
Re: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
Quoted 15 lines · Krzysztof Kozlowski
Quoted 14 lines · Dumitru
Quoted 4 lines · Krzysztof Kozlowski
Quoted 3 lines · Dumitru Ceclan
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence....
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml
Quoted 2 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +0
-0There is no such file in next-20240229.
Quoted 7 lines
Quoted 2 lines
It's not yet accepted
https://lore.kernel.org/all/[email protected]/And how can we know this? You must clearly document dependencies.
This also means the patch cannot be directly applied and cannot be tested by toolset.
Understood, sorry.
Quoted 3 lines
Did you test this particular patch?
Yes
David Lechner
reviewerRe: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
In reply to Dumitru CeclanQuoted 55 lines · Dumitru Ceclan
Add support for: AD7172-2, AD7175-8, AD7177-2.
AD7172-4 does not feature an internal reference, check for external
reference presence.Signed-off-by Dumitru Ceclan <[email protected]>--- .../bindings/iio/adc/adi,ad7173.yaml | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-2@@ -21,17 +21,23 @@ description: | Datasheets for supported chips: https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7172-4.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7173-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7175-8.pdf https://www.analog.com/media/en/technical-documentation/data-sheets/AD7176-2.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/AD7177-2.pdf properties: compatible: enum: - adi,ad7172-2 + - adi,ad7172-4 - adi,ad7173-8 - adi,ad7175-2 + - adi,ad7175-8 - adi,ad7176-2 + - adi,ad7177-2 reg: maxItems: 1@@ -136,8 +142,10 @@ patternProperties: refout-avss: REFOUT/AVSS (Internal reference) avdd : AVDD /AVSS - External reference ref2 only available on ad7173-8. - If not specified, internal reference used. + External reference ref2 only available on ad7173-8 and ad7172-4. + Internal reference refout-avss not available on ad7172-4. + + If not specified, internal reference used (if available). $ref: /schemas/types.yaml#/definitions/string enum: - vref@@ -157,12 +165,15 @@ required: allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml#
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml required: · line 176
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +4
-1+ # Only ad7172-4 and ad7173-8 support vref2 - if: properties: compatible: not: contains: - const: adi,ad7173-8 + anyOf: + - const: adi,ad7172-4 + - const: adi,ad7173-8
According to the datasheets, it looks like adi,ad7175-8 should be included here too.
Quoted 18 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +11
-0then: properties: vref2-supply: false@@ -177,6 +188,28 @@ allOf: reg: maximum: 3 + # Model ad7172-4 does not support internal reference + # mandatory to have an external reference + - if: + properties: + compatible: + contains: + const: adi,ad7172-4 + then: + patternProperties: + "^channel@[0-9a-f]$": + properties:
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml allOf: · line 211
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +10
-0+ adi,reference-select: + enum: + - vref + - vref2 + - avdd + required: + - adi,reference-select + oneOf: + - required: [vref2-supply] + - required: [vref-supply]
Do these actually need to be required since avdd is also a possibility?
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +1
-1+ - if: anyOf: - required: [clock-names] --2.43.0
Re: [PATCH v2 1/2] dt-bindings: adc: ad7173: add support for additional models
Quoted 1 line · David Lechner
On Wed, Feb 28, 2024 at 7:55 AM Dumitru Ceclan <[email protected]> wrote:
...
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml allOf: · line 211
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad7173.yaml +3
-0+ oneOf: + - required: [vref2-supply] + - required: [vref-supply]Do these actually need to be required since avdd is also a possibility?
I added this constraint based on this mention from the datasheet:
"AVDD1 − AVSS. This can be used to as a diagnostic to validate other reference values."
If you consider that to be unnecessary, mention it.
PATCH v2 2/2 iio: adc: ad7173: add support for additional models
In reply to Dumitru CeclanAdd support for Analog Devices AD7172-2, AD7175-8, AD7177-2.
--- drivers/iio/adc/ad7173.c | 82 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 8 deletions(-)
drivers/iio/adc/ad7173.c +74 -8
@@ -1,6 +1,11 @@// SPDX-License-Identifier: GPL-2.0+ /* -* AD7172-2/AD7173-8/AD7175-2/AD7176-2 SPI ADC driver +* AD717x family SPI ADC driver +* +* Supported devices: +* AD7172-2/AD7172-4/AD7173-8/AD7175-2 +* AD7175-8/AD7176-2/AD7177-2 +* * Copyright (C) 2015, 2024 Analog Devices, Inc. */
@@ -61,10 +66,13 @@#define AD7173_AIN_TEMP_POS 17#define AD7173_AIN_TEMP_NEG 18 -#define AD7172_ID 0x00d0 -#define AD7173_ID 0x30d0 -#define AD7175_ID 0x0cd0 +#define AD7172_2_ID 0x00d0#define AD7176_ID 0x0c90 +#define AD7175_2_ID 0x0cd0 +#define AD7172_4_ID 0x2050 +#define AD7173_ID 0x30d0 +#define AD7175_8_ID 0x3cd0 +#define AD7177_ID 0x4fd0#define AD7173_ID_MASK GENMASK(15, 4)#define AD7173_ADC_MODE_REF_EN BIT(15)
@@ -110,15 +118,19 @@#define AD7173_SETUP_REF_SEL_EXT_REF 0x0#define AD7173_VOLTAGE_INT_REF_uV 2500000#define AD7173_TEMP_SENSIIVITY_uV_per_C 477 +#define AD7177_ODR_START_VALUE 0x07#define AD7173_FILTER_ODR0_MASK GENMASK(5, 0)#define AD7173_MAX_CONFIGS 8enum ad7173_ids {ID_AD7172_2 , +ID_AD7172_4 ,ID_AD7173_8 ,ID_AD7175_2 , +ID_AD7175_8 ,ID_AD7176_2 , +ID_AD7177_2 , };struct ad7173_device_info {
@@ -190,7 +202,7 @@ static const unsigned int ad7175_sinc5_data_rates[] = {static const struct ad7173_device_info ad7173_device_info[] = { [ID_AD7172_2 ] = { .name ="ad7172-2" , - .id =AD7172_ID , + .id =AD7172_2_ID , .num_inputs =5 , .num_channels =4 , .num_configs =4 ,
@@ -200,6 +212,17 @@ static const struct ad7173_device_info ad7173_device_info[] = { .sinc5_data_rates = ad7173_sinc5_data_rates, .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), }, + [ID_AD7172_4] = { + .id = AD7172_4_ID, + .num_inputs = 9, + .num_channels = 8, + .num_configs = 8, + .num_gpios = 4, + .has_temp = false, + .clock = 2 * HZ_PER_MHZ, + .sinc5_data_rates = ad7173_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7173_sinc5_data_rates), + }, [ID_AD7173_8] = { .name = "ad7173-8", .id = AD7173_ID,
@@ -214,7 +237,7 @@ static const struct ad7173_device_info ad7173_device_info[] = { }, [ID_AD7175_2] = { .name = "ad7175-2", - .id = AD7175_ID, + .id = AD7175_2_ID, .num_inputs = 5, .num_channels = 4, .num_configs = 4,
@@ -224,6 +247,17 @@ static const struct ad7173_device_info ad7173_device_info[] = { .sinc5_data_rates = ad7175_sinc5_data_rates, .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates), }, + [ID_AD7175_8] = { + .id = AD7175_8_ID, + .num_inputs = 17, + .num_channels = 16, + .num_configs = 8, + .num_gpios = 4, + .has_temp = true, + .clock = 16 * HZ_PER_MHZ, + .sinc5_data_rates = ad7175_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates), + }, [ID_AD7176_2] = { .name = "ad7176-2", .id = AD7176_ID,
@@ -236,6 +270,17 @@ static const struct ad7173_device_info ad7173_device_info[] = { .sinc5_data_rates = ad7175_sinc5_data_rates, .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates), }, + [ID_AD7177_2] = { + .id = AD7177_ID, + .num_inputs = 5, + .num_channels = 4, + .num_configs = 4, + .num_gpios = 2, + .has_temp = true, + .clock = 16 * HZ_PER_MHZ, + .sinc5_data_rates = ad7175_sinc5_data_rates, + .num_sinc5_data_rates = ARRAY_SIZE(ad7175_sinc5_data_rates), + }, };static const char *const ad7173_ref_sel_str[] = {
@@ -656,7 +701,12 @@ static int ad7173_write_raw(struct iio_dev *indio_dev,switch (info) {case IIO_CHAN_INFO_SAMP_FREQ : freq = val *MILLI + val2 /MILLI ; -for (i =0 ; i < st->info->num_sinc5_data_rates -1 ; i++) +/* +* AD7177-2 has the filter values [0-6] marked as reserved +* datasheet page 58 +*/ + i = (st->info->id ==AD7177_ID ) ?AD7177_ODR_START_VALUE :0 ; +for (; i < st->info->num_sinc5_data_rates -1 ; i++)if (freq >= st->info->sinc5_data_rates[i])break ;
@@ -908,8 +958,15 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)else ref_sel = ret; +if (ref_sel ==AD7173_SETUP_REF_SEL_INT_REF && + st->info->id ==AD7172_2_ID ) { +fwnode_handle_put (child); +return dev_err_probe (dev, -EINVAL , +"Internal reference is not available on ad7172-2\n" ); + } +if (ref_sel ==AD7173_SETUP_REF_SEL_EXT_REF2 && - st->info->id !=AD7173_ID ) { + st->info->id !=AD7173_ID && st->info->id !=AD7172_2_ID ) {fwnode_handle_put (child);return dev_err_probe (dev, -EINVAL ,"External reference 2 is only available on ad7173-8\n" );
@@ -1080,21 +1137,30 @@ static int ad7173_probe(struct spi_device *spi)static const struct of_device_id ad7173_of_match[] = { { .compatible ="adi,ad7172-2" , .data = &ad7173_device_info[ID_AD7172_2 ]}, + { .compatible ="adi,ad7172-4" , + .data = &ad7173_device_info[ID_AD7172_4 ]}, { .compatible ="adi,ad7173-8" , .data = &ad7173_device_info[ID_AD7173_8 ]}, { .compatible ="adi,ad7175-2" , .data = &ad7173_device_info[ID_AD7175_2 ]}, + { .compatible ="adi,ad7175-8" , + .data = &ad7173_device_info[ID_AD7175_8 ]}, { .compatible ="adi,ad7176-2" , .data = &ad7173_device_info[ID_AD7176_2 ]}, + { .compatible ="adi,ad7177-2" , + .data = &ad7173_device_info[ID_AD7177_2 ]}, { } };MODULE_DEVICE_TABLE (of, ad7173_of_match);static const struct spi_device_id ad7173_id_table[] = { {"ad7172-2" , (kernel_ulong_t)&ad7173_device_info[ID_AD7172_2 ]}, + {"ad7172-4" , (kernel_ulong_t)&ad7173_device_info[ID_AD7172_4 ] }, {"ad7173-8" , (kernel_ulong_t)&ad7173_device_info[ID_AD7173_8 ]}, {"ad7175-2" , (kernel_ulong_t)&ad7173_device_info[ID_AD7175_2 ]}, + {"ad7175-8" , (kernel_ulong_t)&ad7173_device_info[ID_AD7175_8 ]}, {"ad7176-2" , (kernel_ulong_t)&ad7173_device_info[ID_AD7176_2 ]}, + {"ad7177-2" , (kernel_ulong_t)&ad7173_device_info[ID_AD7177_2 ]}, { } };MODULE_DEVICE_TABLE (spi, ad7173_id_table);
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v2 2/2] iio: adc: ad7173: add support for additional models
Quoted 3 lines · On Wed, 28 Feb 2024 15:54:57 +0200 Dumitru Ceclan <[email protected]>…
Add support for Analog Devices AD7172-2, AD7175-8, AD7177-2.
Signed-off-by Dumitru Ceclan <[email protected]>
Hi Dumitru
Some of the changes in here make it clear more inter chip variability should be specified directly in your device_info structures, and less (preferably none) use made of the id field + if statements inline.
Those ID fields should just be for matching, not for direct use to adjust code flow.
Jonathan
Quoted 47 lines
--- drivers/iio/adc/ad7173.c | 82 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 8 deletions(-)drivers/iio/adc/ad7173.c +13
-4@@ -1,6 +1,11 @@// SPDX-License-Identifier: GPL-2.0+ /* -* AD7172-2/AD7173-8/AD7175-2/AD7176-2 SPI ADC driver +* AD717x family SPI ADC driver +* +* Supported devices: +* AD7172-2/AD7172-4/AD7173-8/AD7175-2 +* AD7175-8/AD7176-2/AD7177-2 +* * Copyright (C) 2015, 2024 Analog Devices, Inc. */ @@ -61,10 +66,13 @@#define AD7173_AIN_TEMP_POS 17#define AD7173_AIN_TEMP_NEG 18 -#define AD7172_ID 0x00d0 -#define AD7173_ID 0x30d0 -#define AD7175_ID 0x0cd0 +#define AD7172_2_ID 0x00d0#define AD7176_ID 0x0c90 +#define AD7175_2_ID 0x0cd0 +#define AD7172_4_ID 0x2050 +#define AD7173_ID 0x30d0 +#define AD7175_8_ID 0x3cd0 +#define AD7177_ID 0x4fd0#define AD7173_ID_MASK GENMASK(15, 4)#define AD7173_ADC_MODE_REF_EN BIT(15)@@ -110,15 +118,19 @@#define AD7173_SETUP_REF_SEL_EXT_REF 0x0#define AD7173_VOLTAGE_INT_REF_uV 2500000#define AD7173_TEMP_SENSIIVITY_uV_per_C 477 +#define AD7177_ODR_START_VALUE 0x07#define AD7173_FILTER_ODR0_MASK GENMASK(5, 0)#define AD7173_MAX_CONFIGS 8
...
drivers/iio/adc/ad7173.c static int ad7173_write_raw(struct iio_dev *indio_dev, · line 708
Quoted 12 lines
static const char *const ad7173_ref_sel_str[] = {
drivers/iio/adc/ad7173.c +5
-1@@ -656,7 +701,12 @@ static int ad7173_write_raw(struct iio_dev *indio_dev,switch (info) {case IIO_CHAN_INFO_SAMP_FREQ : freq = val *MILLI + val2 /MILLI ; -for (i =0 ; i < st->info->num_sinc5_data_rates -1 ; i++) +/* +* AD7177-2 has the filter values [0-6] marked as reserved +* datasheet page 58 +*/ + i = (st->info->id ==AD7177_ID ) ?AD7177_ODR_START_VALUE :0 ;
Add an st->info->odr_start_value field. Can set it only for this part, but if in future others turn up that needs similar it becomes very easy to support.
drivers/iio/adc/ad7173.c static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) · line 962
Quoted 10 lines
drivers/iio/adc/ad7173.c +3
-0+for (; i < st->info->num_sinc5_data_rates -1 ; i++)if (freq >= st->info->sinc5_data_rates[i])break ;@@ -908,8 +958,15 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)else ref_sel = ret; +if (ref_sel ==AD7173_SETUP_REF_SEL_INT_REF && + st->info->id ==AD7172_2_ID ) {
As below. You may well end up adding more devices here. Make it data instead by adding has_ref1 boolean to your st->info structure.
drivers/iio/adc/ad7173.c static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev) · line 969
Quoted 8 lines
drivers/iio/adc/ad7173.c +6
-1+fwnode_handle_put (child); +return dev_err_probe (dev, -EINVAL , +"Internal reference is not available on ad7172-2\n" ); + } +if (ref_sel ==AD7173_SETUP_REF_SEL_EXT_REF2 && - st->info->id !=AD7173_ID ) { + st->info->id !=AD7173_ID && st->info->id !=AD7172_2_ID ) {
This is one of those cases that clearly shows why ID matching doesn't generalize well. Better to have a flag in info that directly says if there is an external reference 2 possible for each chip variant. Otherwise this list just keeps on growing!
!st->info->has_ref2
Quoted 3 lines
drivers/iio/adc/ad7173.c +0
-0fwnode_handle_put (child);return dev_err_probe (dev, -EINVAL ,"External reference 2 is only available on ad7173-8\n" );
David Lechner
reviewerRe: [PATCH v2 2/2] iio: adc: ad7173: add support for additional models
In reply to Dumitru CeclanQuoted 29 lines · Dumitru Ceclan
Add support for Analog Devices AD7172-2, AD7175-8, AD7177-2.
Signed-off-by Dumitru Ceclan <[email protected]>--- drivers/iio/adc/ad7173.c | 82 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 8 deletions(-)drivers/iio/adc/ad7173.c +6
-1@@ -1,6 +1,11 @@// SPDX-License-Identifier: GPL-2.0+ /* -* AD7172-2/AD7173-8/AD7175-2/AD7176-2 SPI ADC driver +* AD717x family SPI ADC driver +* +* Supported devices: +* AD7172-2/AD7172-4/AD7173-8/AD7175-2 +* AD7175-8/AD7176-2/AD7177-2 +* * Copyright (C) 2015, 2024 Analog Devices, Inc. */ @@ -61,10 +66,13 @@#define AD7173_AIN_TEMP_POS 17#define AD7173_AIN_TEMP_NEG 18
drivers/iio/adc/ad7173.c line 75
Quoted 10 lines
drivers/iio/adc/ad7173.c +6
-3-#define AD7172_ID 0x00d0 -#define AD7173_ID 0x30d0 -#define AD7175_ID 0x0cd0 +#define AD7172_2_ID 0x00d0#define AD7176_ID 0x0c90 +#define AD7175_2_ID 0x0cd0 +#define AD7172_4_ID 0x2050 +#define AD7173_ID 0x30d0 +#define AD7175_8_ID 0x3cd0 +#define AD7177_ID 0x4fd0
It would be nice to keep these sorted by name/number like they were.
Quoted 24 lines
drivers/iio/adc/ad7173.c +4
-0#define AD7173_ID_MASK GENMASK(15, 4)#define AD7173_ADC_MODE_REF_EN BIT(15)@@ -110,15 +118,19 @@#define AD7173_SETUP_REF_SEL_EXT_REF 0x0#define AD7173_VOLTAGE_INT_REF_uV 2500000#define AD7173_TEMP_SENSIIVITY_uV_per_C 477 +#define AD7177_ODR_START_VALUE 0x07#define AD7173_FILTER_ODR0_MASK GENMASK(5, 0)#define AD7173_MAX_CONFIGS 8enum ad7173_ids {ID_AD7172_2 , +ID_AD7172_4 ,ID_AD7173_8 ,ID_AD7175_2 , +ID_AD7175_8 ,ID_AD7176_2 , +ID_AD7177_2 , };struct ad7173_device_info {
drivers/iio/adc/ad7173.c static const unsigned int ad7175_sinc5_data_rates[] = { · line 205
Quoted 5 lines
drivers/iio/adc/ad7173.c +1
-1@@ -190,7 +202,7 @@ static const unsigned int ad7175_sinc5_data_rates[] = {static const struct ad7173_device_info ad7173_device_info[] = { [ID_AD7172_2 ] = { .name ="ad7172-2" , - .id =AD7172_ID , + .id =AD7172_2_ID ,
It would be nice to put these renames in a separate patch since it is unrelated to the parts being added.