AD4130
Subsystems (5)
v3 cover AD4130
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
V1 -> V2
* add kernel version to ABI file
* merge ABI patch into driver patch
* make copyright header similar to other drivers
* rearrange includes
* use units.h defines where possible and add unit sufix to SOFT_RESET_SLEEP define
* remove ending comma to last members of enums / lists
* remove unused FILTER_MAX define
* use BIT macro for PIN_FN_*
* rearrange SETUP_SIZE definition
* group bools in ad4130_state and ad4130_chan_info
* put scale_tbls definition on one line
* remove newline before reg size == 0 check
* put mask used as value in a variable
* remove useless ret = 0 assignment
* make buffer attrs oneline
* use for_each_set_bit in update_scan_mode
* use if else for internal reference voltage error checking
* inline reference voltage check
* check number of vbias pins
* remove .has_int_pin = false
* remove avail_len for IIO_AVAIL_RANGE
* remove useless enabled_channels check in unlink_slot
* remove unused AD4130_RESET_CLK_COUNT define
* only call fwnode_handle_put for child in case of error
* default adi,reference-select to REFIN1
* default adi,int-ref-en to false
* of_irq_get_byname -> fwnode_irq_get_byname
* P1 -> P2 as interrupt pin options
* add missing comma in db3_freq_avail init
* cast values to u64 to make math using units.h work
* add datasheet reference to IRQ polarity
* add comment about disabling channels in predisable
* add part number prefix find_table_index
* return voltage from get_ref_voltage
* add datasheet reference for internal reference voltage selection
* add comment explaining AIN and GPIO pin sharing
* parse channel setup before parsing excitation pins
* only validate excitation pin if value is not off
* use FIELD_PREP for bipolar and int_ref_en
* put devm_regmap_init call on one line
* introduce a slot_info struct to contain setup_info for each slot
* enable internal reference automatically if needed
* decide mclk sel based on adi,ext-clk-freq and adi,int-clk-out
* dt-bindings: use internal reference explicitly
* dt-bindings: set type for adi,excitation-pin-0
* dt-bindings: set $ref for adi,vbias-pins
* dt-bindings: remove minItems from interrupts property
* dt-bindings: remove adi,int-ref-en default value
* dt-bindings: remove adi,bipolar default value
* dt-bindings: inline adi,int-ref-en description
* dt-bindings: default adi,reference-select to REFIN1
* dt-bindings: clean up description for diff-channels and adi,reference-select
* dt-bindings: add more text to interrupt-names description
* dt-bindings: turn interrupt-names into a single string
* dt-bindings: add maxItems to adi,vbias-pins
V2 -> V3
* dt-bindings: add interrupt controller include to example
* dt-bindings: remove $ref in diff-channels
Cosmin Tanislav (2):
dt-bindings: iio: adc: add AD4130
iio: adc: ad4130: add AD4130 driver
.../ABI/testing/sysfs-bus-iio-adc-ad4130 | 36 + .../bindings/iio/adc/adi,ad4130.yaml | 264 +++ MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad4130.c | 2078 +++++++++++++++++ 6 files changed, 2400 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml create mode 100644 drivers/iio/adc/ad4130.c
Signature · 1 line
2.35.3
PATCH v3 1/2 dt-bindings: iio: adc: add AD4130
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +264 -0
@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: | + Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible: + enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcsp + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + description: phandle to the master clock (mclk) + + clock-names: + items: + - const: mclk + + interrupts: + maxItems: 1 + + interrupt-names: + description: | + Specify which interrupt pin should be configured as Data Ready / FIFO + interrupt. + Default if not supplied is dout-int. + enum: + - dout-int + - clk + - p2 + - dout + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + refin1-supply: + description: refin1 supply. Can be used as reference for conversion. + + refin2-supply: + description: refin2 supply. Can be used as reference for conversion. + + avdd-supply: + description: AVDD voltage supply. Can be used as reference for conversion. + + iovdd-supply: + description: IOVDD voltage supply. Used for the chip interface. + + spi-max-frequency: + maximum: 5000000 + + adi,int-clk-out: + description: Specify if the internal clock should be exposed on the CLK pin. + type: boolean + + adi,ext-clk-freq: + description: Specify the frequency of the external clock. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [76800, 153600] + default: 76800 + + adi,bipolar: + description: Specify if the device should be used in bipolar mode. + type: boolean + + adi,vbias-pins: + description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to. + $ref: /schemas/types.yaml#/definitions/uint32-array + maxItems: 16 + items: + minimum: 0 + maximum: 15 + +required: + - compatible + - reg + - interrupts + +patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: adc.yaml + + properties: + reg: + description: | + The channel number. + items: + minimum: 0 + maximum: 15 + + diff-channels: + description: | + Besides the analog inputs available, internal inputs can be used. + 16: Internal temperature sensor. + 17: AVSS + 18: Internal reference + 19: DGND + 20: (AVDD − AVSS)/6+ + 21: (AVDD − AVSS)/6- + 22: (IOVDD − DGND)/6+ + 23: (IOVDD − DGND)/6- + 24: (ALDO − AVSS)/6+ + 25: (ALDO − AVSS)/6- + 26: (DLDO − DGND)/6+ + 27: (DLDO − DGND)/6- + 28: V_MV_P + 29: V_MV_M + items: + minimum: 0 + maximum: 29 + + adi,reference-select: + description: | + Select the reference source to use when converting on the + specific channel. Valid values are: + 0: REFIN1(+)/REFIN1(−) + 1: REFIN2(+)/REFIN2(−) + 2: REFOUT/AVSS (Internal reference) + 3: AVDD/AVSS + If not specified, REFIN1 is used. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + default: 0 + + adi,excitation-pin-0: + description: | + Analog input to apply excitation current to while the channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-pin-1: + description: | + Analog input to apply excitation current to while this channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-current-0-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-0 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,excitation-current-1-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-1 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,burnout-current-nanoamps: + description: | + Burnout current in nanoamps to be applied for this channel. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 500, 2000, 4000] + default: 0 + + adi,buffered-positive: + description: Enable buffered mode for positive input. + type: boolean + + adi,buffered-negative: + description: Enable buffered mode for negative input. + type: boolean + + required: + - reg + - diff-channels + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad4130-8-24-wlcsp"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + spi-max-frequency = <5000000>; + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + + channel@0 { + reg = <0>; + + adi,reference-select = <2>; + + /* AIN8, AIN9 */ + diff-channels = <8 9>; + }; + + channel@1 { + reg = <1>; + + adi,reference-select = <2>; + + /* AIN10, AIN11 */ + diff-channels = <10 11>; + }; + + channel@2 { + reg = <2>; + + adi,reference-select = <2>; + + /* Temperature Sensor, DGND */ + diff-channels = <16 19>; + }; + + channel@3 { + reg = <3>; + + adi,reference-select = <2>; + + /* Internal reference, DGND */ + diff-channels = <18 19>; + }; + + channel@4 { + reg = <4>; + + adi,reference-select = <2>; + + /* DGND, DGND */ + diff-channels = <19 19>; + }; + }; + };
Signature · 1 line
2.35.3
Rob Herring
maintainerRe: [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130
Quoted 34 lines · Cosmin Tanislav
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4130.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +13
-0@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: |
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible: + enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcsp
What is lfcsp? wlcsp seems to be the package type which generally shouldn't be part of the compatible.
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +7
-0+ + reg: + maxItems: 1 + + clocks: + maxItems: 1 + description: phandle to the master clock (mclk)
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ + clock-names: + items: + - const: mclk + + interrupts: + maxItems: 1 + + interrupt-names: + description: |
Don't need '|' if there is no formatting to preserve.
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 43
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +3
-0+ Specify which interrupt pin should be configured as Data Ready / FIFO + interrupt. + Default if not supplied is dout-int.
default: dout-int
Quoted 48 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +48
-0+ enum: + - dout-int + - clk + - p2 + - dout + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + refin1-supply: + description: refin1 supply. Can be used as reference for conversion. + + refin2-supply: + description: refin2 supply. Can be used as reference for conversion. + + avdd-supply: + description: AVDD voltage supply. Can be used as reference for conversion. + + iovdd-supply: + description: IOVDD voltage supply. Used for the chip interface. + + spi-max-frequency: + maximum: 5000000 + + adi,int-clk-out: + description: Specify if the internal clock should be exposed on the CLK pin. + type: boolean + + adi,ext-clk-freq: + description: Specify the frequency of the external clock. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [76800, 153600] + default: 76800 + + adi,bipolar: + description: Specify if the device should be used in bipolar mode. + type: boolean + + adi,vbias-pins: + description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to. + $ref: /schemas/types.yaml#/definitions/uint32-array + maxItems: 16 + items: + minimum: 0 + maximum: 15
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 101
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + +patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: adc.yaml
unevaluatedProperties: false
Quoted 167 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +163
-0+ + properties: + reg: + description: | + The channel number. + items: + minimum: 0 + maximum: 15 + + diff-channels: + description: | + Besides the analog inputs available, internal inputs can be used. + 16: Internal temperature sensor. + 17: AVSS + 18: Internal reference + 19: DGND + 20: (AVDD − AVSS)/6+ + 21: (AVDD − AVSS)/6- + 22: (IOVDD − DGND)/6+ + 23: (IOVDD − DGND)/6- + 24: (ALDO − AVSS)/6+ + 25: (ALDO − AVSS)/6- + 26: (DLDO − DGND)/6+ + 27: (DLDO − DGND)/6- + 28: V_MV_P + 29: V_MV_M + items: + minimum: 0 + maximum: 29 + + adi,reference-select: + description: | + Select the reference source to use when converting on the + specific channel. Valid values are: + 0: REFIN1(+)/REFIN1(−) + 1: REFIN2(+)/REFIN2(−) + 2: REFOUT/AVSS (Internal reference) + 3: AVDD/AVSS + If not specified, REFIN1 is used. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + default: 0 + + adi,excitation-pin-0: + description: | + Analog input to apply excitation current to while the channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-pin-1: + description: | + Analog input to apply excitation current to while this channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-current-0-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-0 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,excitation-current-1-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-1 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,burnout-current-nanoamps: + description: | + Burnout current in nanoamps to be applied for this channel. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 500, 2000, 4000] + default: 0 + + adi,buffered-positive: + description: Enable buffered mode for positive input. + type: boolean + + adi,buffered-negative: + description: Enable buffered mode for negative input. + type: boolean + + required: + - reg + - diff-channels + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad4130-8-24-wlcsp"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + spi-max-frequency = <5000000>; + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + + channel@0 { + reg = <0>; + + adi,reference-select = <2>; + + /* AIN8, AIN9 */ + diff-channels = <8 9>; + }; + + channel@1 { + reg = <1>; + + adi,reference-select = <2>; + + /* AIN10, AIN11 */ + diff-channels = <10 11>; + }; + + channel@2 { + reg = <2>; + + adi,reference-select = <2>; + + /* Temperature Sensor, DGND */ + diff-channels = <16 19>; + }; + + channel@3 { + reg = <3>; + + adi,reference-select = <2>; + + /* Internal reference, DGND */ + diff-channels = <18 19>; + }; + + channel@4 { + reg = <4>; + + adi,reference-select = <2>; + + /* DGND, DGND */ + diff-channels = <19 19>; + }; + }; + };Signature · 1 line
2.35.3
Re: [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130
Quoted 40 lines · Rob Herring
Quoted 39 lines · Cosmin Tanislav
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +18
-0@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: | + Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible:
Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 23
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +5
-0+ enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcspWhat is lfcsp? wlcsp seems to be the package type which generally shouldn't be part of the compatible.
lfcsp is a different package type. Sadly, lfcsp provides less interrupt options. On lfcsp, dout-int inside interrupt-names actually only means DOUT, while on wlcsp, it means INT. This is why we need to distinguish between the different package types. I can't think of any way around it, see my reply to Nathan for V1.
dout support is not implemented in the driver right now because when the interrupt pin is configured as dout, FIFO interrupts are unsupported, so the entire buffered part of the driver is useless, and extra logic is
needed for IRQ detection then.
Rob Herring
maintainerRe: [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130
Quoted 58 lines · Cosmin Tanislav
Quoted 40 lines · Rob Herring
Quoted 39 lines · Cosmin Tanislav
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +18
-0@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: | + Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible:Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 23
Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +5
-0+ enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcspWhat is lfcsp? wlcsp seems to be the package type which generally shouldn't be part of the compatible.
lfcsp is a different package type. Sadly, lfcsp provides less interrupt options. On lfcsp, dout-int inside interrupt-names actually only means DOUT, while on wlcsp, it means INT. This is why we need to distinguish between the different package types. I can't think of any way around it, see my reply to Nathan for V1.
Quoted 4 lines
dout support is not implemented in the driver right now because when the interrupt pin is configured as dout, FIFO interrupts are unsupported, so the entire buffered part of the driver is useless, and extra logic is needed for IRQ detection then.
Please capture all this in the binding. At least enough I don't ask the same question again when I've forgotten about this.
Rob
Re: [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130
In reply to Rob HerringQuoted 69 lines · Rob Herring
Quoted 34 lines · Cosmin Tanislav
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+)create mode 100644
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +13
-0@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: |Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible: + enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcspWhat is lfcsp? wlcsp seems to be the package type which generally shouldn't be part of the compatible.
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +7
-0+ + reg: + maxItems: 1 + + clocks: + maxItems: 1 + description: phandle to the master clock (mclk)Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ + clock-names: + items: + - const: mclk + + interrupts: + maxItems: 1 + + interrupt-names: + description: |Don't need '|' if there is no formatting to preserve.
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 43
Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +3
-0+ Specify which interrupt pin should be configured as Data Ready / FIFO + interrupt. + Default if not supplied is dout-int.default: dout-int
By the way. interrupt-names cannot have a default value.
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml:
properties:interrupt-names: Additional properties are not allowed ('default' was unexpected)
from schema $id: http://devicetree.org/meta-schemas/string-array.yaml#
Quoted 228 lines
Quoted 48 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +48
-0+ enum: + - dout-int + - clk + - p2 + - dout + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + refin1-supply: + description: refin1 supply. Can be used as reference for conversion. + + refin2-supply: + description: refin2 supply. Can be used as reference for conversion. + + avdd-supply: + description: AVDD voltage supply. Can be used as reference for conversion. + + iovdd-supply: + description: IOVDD voltage supply. Used for the chip interface. + + spi-max-frequency: + maximum: 5000000 + + adi,int-clk-out: + description: Specify if the internal clock should be exposed on the CLK pin. + type: boolean + + adi,ext-clk-freq: + description: Specify the frequency of the external clock. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [76800, 153600] + default: 76800 + + adi,bipolar: + description: Specify if the device should be used in bipolar mode. + type: boolean + + adi,vbias-pins: + description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to. + $ref: /schemas/types.yaml#/definitions/uint32-array + maxItems: 16 + items: + minimum: 0 + maximum: 15Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 101
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ +required: + - compatible + - reg + - interrupts + +patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: adc.yamlunevaluatedProperties: false
Quoted 167 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +163
-0+ + properties: + reg: + description: | + The channel number. + items: + minimum: 0 + maximum: 15 + + diff-channels: + description: | + Besides the analog inputs available, internal inputs can be used. + 16: Internal temperature sensor. + 17: AVSS + 18: Internal reference + 19: DGND + 20: (AVDD − AVSS)/6+ + 21: (AVDD − AVSS)/6- + 22: (IOVDD − DGND)/6+ + 23: (IOVDD − DGND)/6- + 24: (ALDO − AVSS)/6+ + 25: (ALDO − AVSS)/6- + 26: (DLDO − DGND)/6+ + 27: (DLDO − DGND)/6- + 28: V_MV_P + 29: V_MV_M + items: + minimum: 0 + maximum: 29 + + adi,reference-select: + description: | + Select the reference source to use when converting on the + specific channel. Valid values are: + 0: REFIN1(+)/REFIN1(−) + 1: REFIN2(+)/REFIN2(−) + 2: REFOUT/AVSS (Internal reference) + 3: AVDD/AVSS + If not specified, REFIN1 is used. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + default: 0 + + adi,excitation-pin-0: + description: | + Analog input to apply excitation current to while the channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-pin-1: + description: | + Analog input to apply excitation current to while this channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-current-0-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-0 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,excitation-current-1-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-1 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,burnout-current-nanoamps: + description: | + Burnout current in nanoamps to be applied for this channel. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 500, 2000, 4000] + default: 0 + + adi,buffered-positive: + description: Enable buffered mode for positive input. + type: boolean + + adi,buffered-negative: + description: Enable buffered mode for negative input. + type: boolean + + required: + - reg + - diff-channels + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad4130-8-24-wlcsp"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + spi-max-frequency = <5000000>; + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + + channel@0 { + reg = <0>; + + adi,reference-select = <2>; + + /* AIN8, AIN9 */ + diff-channels = <8 9>; + }; + + channel@1 { + reg = <1>; + + adi,reference-select = <2>; + + /* AIN10, AIN11 */ + diff-channels = <10 11>; + }; + + channel@2 { + reg = <2>; + + adi,reference-select = <2>; + + /* Temperature Sensor, DGND */ + diff-channels = <16 19>; + }; + + channel@3 { + reg = <3>; + + adi,reference-select = <2>; + + /* Internal reference, DGND */ + diff-channels = <18 19>; + }; + + channel@4 { + reg = <4>; + + adi,reference-select = <2>; + + /* DGND, DGND */ + diff-channels = <19 19>; + }; + }; + };Signature · 1 line
2.35.3
Jonathan Cameron
maintainerRe: [PATCH v3 1/2] dt-bindings: iio: adc: add AD4130
In reply to Cosmin TanislavQuoted 10 lines · On Tue, 19 Apr 2022 18:08:27 +0300 Cosmin Tanislav <[email protected]>…
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>
Hi Cosmin,
A few things inline to add to fixing the lack of detail Rob highlighted.
Thanks,
Jonathan
Quoted 77 lines
--- .../bindings/iio/adc/adi,ad4130.yaml | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4130.yamlDocumentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +66
-0@@ -0,0 +1,264 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2022 Analog Devices Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ad4130.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices AD4130 ADC device driver + +maintainers: + - Cosmin Tanislav <[email protected]> + +description: | + Bindings for the Analog Devices AD4130 ADC. Datasheet can be found here: + https://www.analog.com/media/en/technical-documentation/data-sheets/AD4130-8.pdf + +properties: + compatible: + enum: + - adi,ad4130-8-16-lfcsp + - adi,ad4130-8-16-wlcsp + - adi,ad4130-8-24-lfcsp + - adi,ad4130-8-24-wlcsp + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + description: phandle to the master clock (mclk) + + clock-names: + items: + - const: mclk + + interrupts: + maxItems: 1 + + interrupt-names: + description: | + Specify which interrupt pin should be configured as Data Ready / FIFO + interrupt. + Default if not supplied is dout-int. + enum: + - dout-int + - clk + - p2 + - dout + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + refin1-supply: + description: refin1 supply. Can be used as reference for conversion. + + refin2-supply: + description: refin2 supply. Can be used as reference for conversion. + + avdd-supply: + description: AVDD voltage supply. Can be used as reference for conversion. + + iovdd-supply: + description: IOVDD voltage supply. Used for the chip interface.
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 76
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ + spi-max-frequency: + maximum: 5000000 + + adi,int-clk-out: + description: Specify if the internal clock should be exposed on the CLK pin. + type: boolean + + adi,ext-clk-freq: + description: Specify the frequency of the external clock.
Units? Even better if we can map this to one of the standard unit types and include the unit in the name.
Quoted 20 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +20
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + enum: [76800, 153600] + default: 76800 + + adi,bipolar: + description: Specify if the device should be used in bipolar mode. + type: boolean + + adi,vbias-pins: + description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to. + $ref: /schemas/types.yaml#/definitions/uint32-array + maxItems: 16 + items: + minimum: 0 + maximum: 15 + +required: + - compatible + - reg + - interrupts
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml line 106
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +10
-0+ +patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: adc.yaml + + properties: + reg: + description: | + The channel number.
This isn't used explicitly in the driver. I'm wondering if perhaps it should be rather than using the order in which the child nodes are found...
The driver would then need to cope with potential holes however (or just reject a binding where they occur?).
Quoted 158 lines
Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml new file +158
-0+ items: + minimum: 0 + maximum: 15 + + diff-channels: + description: | + Besides the analog inputs available, internal inputs can be used. + 16: Internal temperature sensor. + 17: AVSS + 18: Internal reference + 19: DGND + 20: (AVDD − AVSS)/6+ + 21: (AVDD − AVSS)/6- + 22: (IOVDD − DGND)/6+ + 23: (IOVDD − DGND)/6- + 24: (ALDO − AVSS)/6+ + 25: (ALDO − AVSS)/6- + 26: (DLDO − DGND)/6+ + 27: (DLDO − DGND)/6- + 28: V_MV_P + 29: V_MV_M + items: + minimum: 0 + maximum: 29 + + adi,reference-select: + description: | + Select the reference source to use when converting on the + specific channel. Valid values are: + 0: REFIN1(+)/REFIN1(−) + 1: REFIN2(+)/REFIN2(−) + 2: REFOUT/AVSS (Internal reference) + 3: AVDD/AVSS + If not specified, REFIN1 is used. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + default: 0 + + adi,excitation-pin-0: + description: | + Analog input to apply excitation current to while the channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-pin-1: + description: | + Analog input to apply excitation current to while this channel + is active. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 + maximum: 15 + default: 0 + + adi,excitation-current-0-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-0 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,excitation-current-1-nanoamps: + description: | + Excitation current in nanoamps to be applied to pin specified in + adi,excitation-pin-1 while this channel is active. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 100, 10000, 20000, 50000, 100000, 150000, 200000] + default: 0 + + adi,burnout-current-nanoamps: + description: | + Burnout current in nanoamps to be applied for this channel. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 500, 2000, 4000] + default: 0 + + adi,buffered-positive: + description: Enable buffered mode for positive input. + type: boolean + + adi,buffered-negative: + description: Enable buffered mode for negative input. + type: boolean + + required: + - reg + - diff-channels + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "adi,ad4130-8-24-wlcsp"; + reg = <0>; + + #address-cells = <1>; + #size-cells = <0>; + + spi-max-frequency = <5000000>; + interrupts = <27 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + + channel@0 { + reg = <0>; + + adi,reference-select = <2>; + + /* AIN8, AIN9 */ + diff-channels = <8 9>; + }; + + channel@1 { + reg = <1>; + + adi,reference-select = <2>; + + /* AIN10, AIN11 */ + diff-channels = <10 11>; + }; + + channel@2 { + reg = <2>; + + adi,reference-select = <2>; + + /* Temperature Sensor, DGND */ + diff-channels = <16 19>; + }; + + channel@3 { + reg = <3>; + + adi,reference-select = <2>; + + /* Internal reference, DGND */ + diff-channels = <18 19>; + }; + + channel@4 { + reg = <4>; + + adi,reference-select = <2>; + + /* DGND, DGND */ + diff-channels = <19 19>; + }; + }; + };
PATCH v3 2/2 iio: adc: ad4130: add AD4130 driver
In reply to Cosmin TanislavAD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
--- .../ABI/testing/sysfs-bus-iio-adc-ad4130 | 36 + MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 13 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad4130.c | 2078 +++++++++++++++++ 5 files changed, 2136 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 create mode 100644 drivers/iio/adc/ad4130.c
Documentation/ABI/testing/sysfs-bus-iio-adc-ad4130 new file +36 -0
@@ -0,0 +1,36 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_voltage-voltage_filter_mode_available +KernelVersion: 5.18 +Contact: [email protected] +Description: + Reading returns a list with the possible filter modes. + "sinc4" - Sinc 4. Excellent noise performance. Long 1st + conversion time. No natural 50/60Hz rejection. + "sinc4+sinc1" - Sinc4 + averaging by 8. Low 1st conversion time. + "sinc3" - Sinc3. Moderate 1st conversion time. Good noise + performance. + "sinc3+rej60" - Sinc3 + 60Hz rejection. At a sampling frequency + of 50Hz, achieves simultaneous 50Hz and 60Hz + rejection. + "sinc3+sinc1" - Sinc3 + averaging by 8. Low 1st conversion time. + Best used with a sampling frequency of at least + 216.19Hz. + "sinc3+pf1" - Sinc3 + Post Filter 1. + 53dB rejection @ 50Hz, 58dB rejection @ 60Hz. + "sinc3+pf2" - Sinc3 + Post Filter 2. + 70dB rejection @ 50Hz, 70dB rejection @ 60Hz. + "sinc3+pf3" - Sinc3 + Post Filter 3. + 99dB rejection @ 50Hz, 103dB rejection @ 60Hz. + "sinc3+pf4" - Sinc3 + Post Filter 4. + 103dB rejection @ 50Hz, 109dB rejection @ 60Hz. + +What: /sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_filter_mode +KernelVersion: 5.18 +Contact: [email protected] +Description: + Set the filter mode of the differential channel. When the filter + mode changes, the in_voltageY-voltageZ_sampling_frequency and + in_voltageY-voltageZ_sampling_frequency_available attributes + might also change to accommodate the new filter mode. + If the current sampling frequency is out of range for the new + filter mode, the sampling frequency will be changed to the + closest valid one.
MAINTAINERS +8 -0
@@ -1074,6 +1074,14 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git T: git git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git F: drivers/net/amt.c +ANALOG DEVICES INC AD4130 DRIVER +M: Cosmin Tanislav <[email protected]> +L: [email protected] +S: Supported +W: http://ez.analog.com/community/linux-device-drivers +F: Documentation/devicetree/bindings/iio/adc/adi,ad4130.yaml +F: drivers/iio/adc/ad4130.c + ANALOG DEVICES INC AD7192 DRIVER M: Alexandru Tachici <[email protected]> L: [email protected]
drivers/iio/adc/Kconfig +13 -0
@@ -21,6 +21,19 @@ config AD_SIGMA_DELTA select IIO_BUFFER select IIO_TRIGGERED_BUFFER +config AD4130 + tristate "Analog Device AD4130 ADC Driver" + depends on SPI + select IIO_BUFFER + select IIO_KFIFO_BUF + select REGMAP_SPI + help + Say yes here to build support for Analog Devices AD4130-8 SPI analog + to digital converters (ADC). + + To compile this driver as a module, choose M here: the module will be + called ad4130. + config AD7091R5 tristate "Analog Devices AD7091R5 ADC Driver" depends on I2C
drivers/iio/adc/Makefile +1 -0
@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o +obj-$(CONFIG_AD4130) += ad4130.o obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.o obj-$(CONFIG_AD7124) += ad7124.o obj-$(CONFIG_AD7192) += ad7192.o
drivers/iio/adc/ad4130.c new file +2078 -0
2,078 lines not on this page · raw message
Signature · 1 line
2.35.3
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 10 lines · On Tue, 19 Apr 2022 18:08:28 +0300 Cosmin Tanislav <[email protected]>…
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>
Hi Cosmin,
Sorry this one took me a while to get back to. Last week was a little crazy on the day job front.
Anyhow, whilst reading this I realised we have some unclear ABI documentation and hence divergence in interpretation of the units of hwfifo_watermark. See below. I've not done a thorough audit as don't have enough time today, but we have at least some drivers treating it as being in scans (+ the core does this for watermark) and some treating it as being in individual channel readings... My intent IIRC was that it was in scans as otherwise you run into the problem you are working around with needing to tweak it to match scans within each driver.
A few other trivial things inline including the alignment issue I emailed the list about but haven't sent patches out for yet (about 90 driver are affected... *sigh*).
Thanks,
Jonathan
Quoted 1 line
---
...
Quoted 17 lines
drivers/iio/adc/Makefile +1
-0@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o +obj-$(CONFIG_AD4130) += ad4130.o obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.o obj-$(CONFIG_AD7124) += ad7124.o obj-$(CONFIG_AD7192) += ad7192.odrivers/iio/adc/ad4130.c new file +0
-0
...
Quoted 35 lines
drivers/iio/adc/ad4130.c new file +35
-0+struct ad4130_state { +const struct ad4130_chip_info *chip_info; +struct spi_device *spi; +struct regmap *regmap; +struct clk *mclk; +struct regulator_bulk_data regulators[4 ]; +u32 irq_trigger; +u32 inv_irq_trigger; + +/* +* Synchronize access to members of driver state, and ensure atomicity +* of consecutive regmap operations. +*/ +struct mutex lock; +struct completion completion; + +struct iio_chan_spec chans[AD4130_MAX_CHANNELS ]; +struct ad4130_chan_info chans_info[AD4130_MAX_CHANNELS ]; +struct ad4130_slot_info slots_info[AD4130_MAX_SETUPS ]; +enum ad4130_pin_function pins_fn[AD4130_MAX_ANALOG_PINS ]; +u32 vbias_pins[AD4130_MAX_ANALOG_PINS ]; +u32 num_vbias_pins; +int scale_tbls[AD4130_REF_SEL_MAX ][AD4130_PGA_NUM ][2 ]; +struct gpio_chip gc; +unsigned int gpio_offsets[AD4130_MAX_GPIOS ]; +unsigned int num_gpios; + +u32 int_pin_sel; +u32 int_ref_uv; +u32 mclk_sel; +bool int_ref_en; +bool bipolar; + +unsigned int num_enabled_channels; +unsigned int effective_watermark;
drivers/iio/adc/ad4130.c line 312
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+unsigned int watermark; + +struct spi_message fifo_msg; +struct spi_transfer fifo_xfer[2 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines. +*/ +u8 reset_buf[AD4130_RESET_BUF_SIZE ]____cacheline_aligned ;
This needs a fix along with the other set that I'll hopefully get this weekend. In meantime if you change this to __aligned(IIO_ALIGN); then the fix I have coming shortly will change that define to be large enough for the odd ARM systems with 128 byte requirement for DMA and 64 byte L1 cache alignment (which is what ___cacheline_aligned guarantees.
Quoted 25 lines
drivers/iio/adc/ad4130.c new file +24
-0+u8 reg_write_tx_buf[4 ]; +u8 reg_read_tx_buf[1 ]; +u8 reg_read_rx_buf[3 ]; +u8 fifo_tx_buf[2 ]; +u8 fifo_rx_buf[AD4130_FIFO_SIZE * +AD4130_FIFO_MAX_SAMPLE_SIZE ]; +}; + +static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);
drivers/iio/adc/ad4130.c
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;
Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...
Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So kfifo_len() returns the number of scans.
Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.
Quoted 7 lines
drivers/iio/adc/ad4130.c new file +7
-0+ +out: +mutex_unlock (&st->lock); + +return ret; +} +
...
Quoted 36 lines
drivers/iio/adc/ad4130.c new file +36
-0+ +static int ad4130_parse_fw_channel (struct iio_dev *indio_dev, +struct fwnode_handle *child) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int index = indio_dev->num_channels++; +struct device *dev = &st->spi->dev; +struct ad4130_chan_info *chan_info; +struct iio_chan_spec *chan; +u32 pins[2 ]; +int ret; + +if (index >=AD4130_MAX_CHANNELS ) +return dev_err_probe (dev, -EINVAL ,"Too many channels\n" ); + + chan = &st->chans[index]; + chan_info = &st->chans_info[index]; + + *chan = ad4130_channel_template; + chan->scan_type.realbits = st->chip_info->resolution; + chan->scan_type.storagebits = st->chip_info->resolution; + chan->scan_index = index; + + chan_info->slot =AD4130_INVALID_SLOT ; + chan_info->setup.fs =AD4130_FS_MIN ; + chan_info->initialized = true; + + ret =fwnode_property_read_u32_array (child,"diff-channels" , pins, +ARRAY_SIZE (pins)); +if (ret) +return ret; + + ret =ad4130_validate_diff_channels (st, pins,ARRAY_SIZE (pins)); +if (ret) +return ret; +
drivers/iio/adc/ad4130.c line 1619
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ chan->channel = pins[0 ]; + chan->channel2 = pins[1 ]; + + ret =ad4130_parse_fw_setup (st, child, &chan_info->setup); +if (ret) +return ret; + +fwnode_property_read_u32 (child,"adi,excitation-pin-0" , + &chan_info->iout0); +if (chan_info->setup.iout0_val !=AD4130_IOUT_OFF ) {
It would be slightly better to set an explicit default value here as the fact it is 0 is hidden by the enum. e.g.
chan_info->iout0 = AD4130_IOUT_OFF; fwnode_property_read_u32(child, "adi,excitation-pin-0", &chan_info->iout0); if (chan_info->....
That would save reviewers wondering what the default is and having to go check the enum (and I'm lazy :)
Quoted 20 lines
drivers/iio/adc/ad4130.c new file +20
-0+ ret =ad4130_validate_excitation_pin (st, chan_info->iout0); +if (ret) +return ret; + } + +fwnode_property_read_u32 (child,"adi,excitation-pin-1" , + &chan_info->iout1); +if (chan_info->setup.iout1_val !=AD4130_IOUT_OFF ) { + ret =ad4130_validate_excitation_pin (st, chan_info->iout1); +if (ret) +return ret; + } + +return 0 ; +} + +static int ad4130_parse_fw_children (struct iio_dev *indio_dev) +{ +struct ad4130_state *st =iio_priv (indio_dev); +struct device *dev = &st->spi->dev;
drivers/iio/adc/ad4130.c line 1649
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+struct fwnode_handle *child; +int ret; + + indio_dev->channels = st->chans; + +device_for_each_child_node (dev, child) { + ret =ad4130_parse_fw_channel (indio_dev, child); +if (ret) { +fwnode_handle_put (child); +break ;
Trivial, but slight preference for return ret here and then return 0 below.
Quoted 17 lines
drivers/iio/adc/ad4130.c new file +17
-0+ } + } + +return ret; +} + +static int ad4310_parse_fw (struct iio_dev *indio_dev) +{ +struct ad4130_state *st =iio_priv (indio_dev); +struct device *dev = &st->spi->dev; +u32 ext_clk_freq =AD4130_MCLK_FREQ_76_8KHZ ; +bool int_clk_out = false; +unsigned int i; +int avdd_uv; +int irq; +int ret; +
...
drivers/iio/adc/ad4130.c line 1697
Quoted 2 lines
drivers/iio/adc/ad4130.c new file +2
-0+ +device_property_read_u32 (dev,"adi,ext-clk-freq" , &ext_clk_freq);
I'll note this in reviewing the binding, but the naming should incorporate the units.
Quoted 6 lines
drivers/iio/adc/ad4130.c new file +6
-0+if (ext_clk_freq !=AD4130_MCLK_FREQ_153_6KHZ && + ext_clk_freq !=AD4130_MCLK_FREQ_76_8KHZ ) +return dev_err_probe (dev, -EINVAL , +"Invalid external clock frequency %u\n" , + ext_clk_freq); +
...
Quoted 29 lines
drivers/iio/adc/ad4130.c new file +28
-0+ +return 0 ; +} + + +static int ad4130_setup (struct iio_dev *indio_dev) +{ +struct ad4130_state *st =iio_priv (indio_dev); +struct device *dev = &st->spi->dev; +unsigned int int_ref_val; +unsigned long rate =AD4130_MCLK_FREQ_76_8KHZ ; +unsigned int val; +unsigned int i; +int ret; + +if (st->mclk_sel ==AD4130_MCLK_153_6KHZ_EXT ) + rate =AD4130_MCLK_FREQ_153_6KHZ ; + + ret =clk_set_rate (st->mclk, rate); +if (ret) +return ret; + + ret =clk_prepare_enable (st->mclk); +if (ret) +return ret; + + ret =devm_add_action_or_reset (dev, ad4130_clk_disable_unprepare, + st->mclk);
drivers/iio/adc/ad4130.c line 1831
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+if (ret) +return ret; + +if (st->int_ref_uv ==AD4130_INT_REF_2_5V ) + int_ref_val =AD4130_INT_REF_VAL_2_5V ; +else + int_ref_val =AD4130_INT_REF_VAL_1_25V ; + +/* Switch to SPI 4-wire mode. */ + val =AD4130_CSB_EN_MASK ;
Trivial but I'd prefer to see this treated as a field as well for consistency.
val = FIELD_PREP(AD4130_CSB_EN_MASK, 1);
Quoted 18 lines
drivers/iio/adc/ad4130.c new file +18
-0+ val |=FIELD_PREP (AD4130_BIPOLAR_MASK , st->bipolar); + val |=FIELD_PREP (AD4130_INT_REF_EN_MASK , st->int_ref_en); + val |=FIELD_PREP (AD4130_MODE_MASK ,AD4130_MODE_IDLE ); + val |=FIELD_PREP (AD4130_MCLK_SEL_MASK , st->mclk_sel); + val |=FIELD_PREP (AD4130_INT_REF_VAL_MASK , int_ref_val); + + ret =regmap_write (st->regmap,AD4130_REG_ADC_CONTROL , val); +if (ret) +return ret; + + val =FIELD_PREP (AD4130_INT_PIN_SEL_MASK , st->int_pin_sel); +for (i =0 ; i < st->num_gpios; i++) + val |=BIT (st->gpio_offsets[i]); + + ret =regmap_write (st->regmap,AD4130_REG_IO_CONTROL , val); +if (ret) +return ret; +
Re: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 103 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 19 Apr 2022 18:08:28 +0300 Cosmin Tanislav <[email protected]>…
AD4130-8 is an ultra-low power, high precision, measurement solution for low bandwidth battery operated applications.
The fully integrated AFE (Analog Front-End) includes a multiplexer for up to 16 single-ended or 8 differential inputs, PGA (Programmable Gain Amplifier), 24-bit Sigma-Delta ADC, on-chip reference and oscillator, selectable filter options, smart sequencer, sensor biasing and excitation options, diagnostics, and a FIFO buffer.
Signed-off-by Cosmin Tanislav <[email protected]>Hi Cosmin,
Sorry this one took me a while to get back to. Last week was a little crazy on the day job front.
Anyhow, whilst reading this I realised we have some unclear ABI documentation and hence divergence in interpretation of the units of
hwfifo_watermark. See below. I've not done a thorough audit as don't have enough time today, but we have at least some drivers treating it as being in scans (+ the core does this for watermark) and some treating it as being in individual channel readings... My intent IIRC was that it was in scans as otherwise you run into the problem you are working around with needing to tweak it to match scans within each driver.A few other trivial things inline including the alignment issue I emailed the list about but haven't sent patches out for yet (about 90 driver are affected... *sigh*).
Thanks,
Jonathan
Quoted 2 lines
---
...
Quoted 17 lines
drivers/iio/adc/Makefile +1
-0@@ -6,6 +6,7 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o +obj-$(CONFIG_AD4130) += ad4130.o obj-$(CONFIG_AD7091R5) += ad7091r5.o ad7091r-base.o obj-$(CONFIG_AD7124) += ad7124.o obj-$(CONFIG_AD7192) += ad7192.odrivers/iio/adc/ad4130.c new file +0
-0...
Quoted 43 lines
drivers/iio/adc/ad4130.c new file +43
-0+struct ad4130_state { +const struct ad4130_chip_info *chip_info; +struct spi_device *spi; +struct regmap *regmap; +struct clk *mclk; +struct regulator_bulk_data regulators[4 ]; +u32 irq_trigger; +u32 inv_irq_trigger; + +/* +* Synchronize access to members of driver state, and ensure atomicity +* of consecutive regmap operations. +*/ +struct mutex lock; +struct completion completion; + +struct iio_chan_spec chans[AD4130_MAX_CHANNELS ]; +struct ad4130_chan_info chans_info[AD4130_MAX_CHANNELS ]; +struct ad4130_slot_info slots_info[AD4130_MAX_SETUPS ]; +enum ad4130_pin_function pins_fn[AD4130_MAX_ANALOG_PINS ]; +u32 vbias_pins[AD4130_MAX_ANALOG_PINS ]; +u32 num_vbias_pins; +int scale_tbls[AD4130_REF_SEL_MAX ][AD4130_PGA_NUM ][2 ]; +struct gpio_chip gc; +unsigned int gpio_offsets[AD4130_MAX_GPIOS ]; +unsigned int num_gpios; + +u32 int_pin_sel; +u32 int_ref_uv; +u32 mclk_sel; +bool int_ref_en; +bool bipolar; + +unsigned int num_enabled_channels; +unsigned int effective_watermark; +unsigned int watermark; + +struct spi_message fifo_msg; +struct spi_transfer fifo_xfer[2 ]; + +/* +* DMA (thus cache coherency maintenance) requires the +* transfer buffers to live in their own cache lines.
Quoted 9 lines
drivers/iio/adc/ad4130.c
Quoted 2 lines
drivers/iio/adc/ad4130.c new file +2
-0+*/ +u8 reset_buf[AD4130_RESET_BUF_SIZE ]____cacheline_aligned ;This needs a fix along with the other set that I'll hopefully get this weekend. In meantime if you change this to
__aligned(IIO_ALIGN); then the fix I have coming shortly will change that define to be large enough for the odd ARM systems with 128 byte requirement for DMA and 64 byte L1 cache alignment (which is what___cacheline_alignedguarantees.
Sure thing.
Quoted 58 lines
Quoted 26 lines
drivers/iio/adc/ad4130.c new file +24
-0+u8 reg_write_tx_buf[4 ]; +u8 reg_read_tx_buf[1 ]; +u8 reg_read_rx_buf[3 ]; +u8 fifo_tx_buf[2 ]; +u8 fifo_rx_buf[AD4130_FIFO_SIZE * +AD4130_FIFO_MAX_SAMPLE_SIZE ]; +}; + +static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);drivers/iio/adc/ad4130.c
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.
Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
Quoted 60 lines
Quoted 7 lines
drivers/iio/adc/ad4130.c new file +7
-0+ +out: +mutex_unlock (&st->lock); + +return ret; +} +...
Quoted 36 lines
drivers/iio/adc/ad4130.c new file +36
-0+ +static int ad4130_parse_fw_channel (struct iio_dev *indio_dev, +struct fwnode_handle *child) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int index = indio_dev->num_channels++; +struct device *dev = &st->spi->dev; +struct ad4130_chan_info *chan_info; +struct iio_chan_spec *chan; +u32 pins[2 ]; +int ret; + +if (index >=AD4130_MAX_CHANNELS ) +return dev_err_probe (dev, -EINVAL ,"Too many channels\n" ); + + chan = &st->chans[index]; + chan_info = &st->chans_info[index]; + + *chan = ad4130_channel_template; + chan->scan_type.realbits = st->chip_info->resolution; + chan->scan_type.storagebits = st->chip_info->resolution; + chan->scan_index = index; + + chan_info->slot =AD4130_INVALID_SLOT ; + chan_info->setup.fs =AD4130_FS_MIN ; + chan_info->initialized = true; + + ret =fwnode_property_read_u32_array (child,"diff-channels" , pins, +ARRAY_SIZE (pins)); +if (ret) +return ret; + + ret =ad4130_validate_diff_channels (st, pins,ARRAY_SIZE (pins)); +if (ret) +return ret; +drivers/iio/adc/ad4130.c line 1619
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ chan->channel = pins[0 ]; + chan->channel2 = pins[1 ]; + + ret =ad4130_parse_fw_setup (st, child, &chan_info->setup); +if (ret) +return ret; + +fwnode_property_read_u32 (child,"adi,excitation-pin-0" , + &chan_info->iout0); +if (chan_info->setup.iout0_val !=AD4130_IOUT_OFF ) {It would be slightly better to set an explicit default value here as the fact it is 0 is hidden by the enum. e.g.
Quoted 6 lines
chan_info->iout0 = AD4130_IOUT_OFF; fwnode_property_read_u32(child, "adi,excitation-pin-0", &chan_info->iout0); if (chan_info->....That would save reviewers wondering what the default is and having to go check the enum (and I'm lazy :)
I understand the idea, but the default value for iout0 is not AD4130_IOUT_OFF. iout0 is the pin that iout0_val current is applied to, and AD4130_IOUT_OFF is a value for iout0_val. Look at ad4130_parse_fw_setup.
For iout0, I guess I could do
#define AD4130_AIN0 0x0
...chan_info->iout0 = AD4130_AIN0;
Quoted 76 lines
Quoted 17 lines
drivers/iio/adc/ad4130.c new file +17
-0+ } + } + +return ret; +} + +static int ad4310_parse_fw (struct iio_dev *indio_dev) +{ +struct ad4130_state *st =iio_priv (indio_dev); +struct device *dev = &st->spi->dev; +u32 ext_clk_freq =AD4130_MCLK_FREQ_76_8KHZ ; +bool int_clk_out = false; +unsigned int i; +int avdd_uv; +int irq; +int ret; +...
drivers/iio/adc/ad4130.c line 1697
Quoted 2 lines
drivers/iio/adc/ad4130.c new file +2
-0+ +device_property_read_u32 (dev,"adi,ext-clk-freq" , &ext_clk_freq);I'll note this in reviewing the binding, but the naming should incorporate the units.
Quoted 6 lines
drivers/iio/adc/ad4130.c new file +6
-0+if (ext_clk_freq !=AD4130_MCLK_FREQ_153_6KHZ && + ext_clk_freq !=AD4130_MCLK_FREQ_76_8KHZ ) +return dev_err_probe (dev, -EINVAL , +"Invalid external clock frequency %u\n" , + ext_clk_freq); +...
Quoted 29 lines
drivers/iio/adc/ad4130.c new file +28
-0+ +return 0 ; +} + + +static int ad4130_setup (struct iio_dev *indio_dev) +{ +struct ad4130_state *st =iio_priv (indio_dev); +struct device *dev = &st->spi->dev; +unsigned int int_ref_val; +unsigned long rate =AD4130_MCLK_FREQ_76_8KHZ ; +unsigned int val; +unsigned int i; +int ret; + +if (st->mclk_sel ==AD4130_MCLK_153_6KHZ_EXT ) + rate =AD4130_MCLK_FREQ_153_6KHZ ; + + ret =clk_set_rate (st->mclk, rate); +if (ret) +return ret; + + ret =clk_prepare_enable (st->mclk); +if (ret) +return ret; + + ret =devm_add_action_or_reset (dev, ad4130_clk_disable_unprepare, + st->mclk);drivers/iio/adc/ad4130.c line 1831
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+if (ret) +return ret; + +if (st->int_ref_uv ==AD4130_INT_REF_2_5V ) + int_ref_val =AD4130_INT_REF_VAL_2_5V ; +else + int_ref_val =AD4130_INT_REF_VAL_1_25V ; + +/* Switch to SPI 4-wire mode. */ + val =AD4130_CSB_EN_MASK ;Trivial but I'd prefer to see this treated as a field as well for consistency.
Quoted 1 line
val = FIELD_PREP(AD4130_CSB_EN_MASK, 1);
Already did, but I waited for your input before pushing the new patchset.
Quoted 19 lines
Quoted 18 lines
Quoted 1 line
drivers/iio/adc/ad4130.c new file +1
-0+ val |=FIELD_PREP (AD4130_BIPOLAR_MASK , st->bipolar);drivers/iio/adc/ad4130.c new file +17
-0+ val |=FIELD_PREP (AD4130_INT_REF_EN_MASK , st->int_ref_en); + val |=FIELD_PREP (AD4130_MODE_MASK ,AD4130_MODE_IDLE ); + val |=FIELD_PREP (AD4130_MCLK_SEL_MASK , st->mclk_sel); + val |=FIELD_PREP (AD4130_INT_REF_VAL_MASK , int_ref_val); + + ret =regmap_write (st->regmap,AD4130_REG_ADC_CONTROL , val); +if (ret) +return ret; + + val =FIELD_PREP (AD4130_INT_PIN_SEL_MASK , st->int_pin_sel); +for (i =0 ; i < st->num_gpios; i++) + val |=BIT (st->gpio_offsets[i]); + + ret =regmap_write (st->regmap,AD4130_REG_IO_CONTROL , val); +if (ret) +return ret; +
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 58 lines
Quoted 50 lines
Quoted 18 lines
drivers/iio/adc/ad4130.c new file +16
-0+static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);drivers/iio/adc/ad4130.c line 1243
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.
Quoted 4 lines
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
I missed it. Review is never perfect (mine definitely aren't!)
Thinking more on the adxl367. We still have a window to fix that as the driver isn't yet in a release kernel. Would you mind spinning a patch to fix that one? Even if we miss the rc cycle (it's a bit tight timing wise) we can sneak it in as an early fix in stable without significant risk of breaking anyone's userspace.
There might be other drivers that have that interpretation we can't fix but if we can reduce the scope of the problem by changing the adxl367 that would be great.
We should also definitely improve the docs and perhaps add a note to say that due to need to maintain ABI, a few drivers use scans * number of channels rather than scans.
Quoted 73 lines
Quoted 61 lines
Quoted 8 lines
drivers/iio/adc/ad4130.c new file +7
-0+ +out: +mutex_unlock (&st->lock); + +return ret; +} +...
Quoted 36 lines
drivers/iio/adc/ad4130.c new file +36
-0+ +static int ad4130_parse_fw_channel (struct iio_dev *indio_dev, +struct fwnode_handle *child) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int index = indio_dev->num_channels++; +struct device *dev = &st->spi->dev; +struct ad4130_chan_info *chan_info; +struct iio_chan_spec *chan; +u32 pins[2 ]; +int ret; + +if (index >=AD4130_MAX_CHANNELS ) +return dev_err_probe (dev, -EINVAL ,"Too many channels\n" ); + + chan = &st->chans[index]; + chan_info = &st->chans_info[index]; + + *chan = ad4130_channel_template; + chan->scan_type.realbits = st->chip_info->resolution; + chan->scan_type.storagebits = st->chip_info->resolution; + chan->scan_index = index; + + chan_info->slot =AD4130_INVALID_SLOT ; + chan_info->setup.fs =AD4130_FS_MIN ; + chan_info->initialized = true; + + ret =fwnode_property_read_u32_array (child,"diff-channels" , pins, +ARRAY_SIZE (pins)); +if (ret) +return ret; + + ret =ad4130_validate_diff_channels (st, pins,ARRAY_SIZE (pins)); +if (ret) +return ret; +drivers/iio/adc/ad4130.c line 1619
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ chan->channel = pins[0 ]; + chan->channel2 = pins[1 ]; + + ret =ad4130_parse_fw_setup (st, child, &chan_info->setup); +if (ret) +return ret; + +fwnode_property_read_u32 (child,"adi,excitation-pin-0" , + &chan_info->iout0); +if (chan_info->setup.iout0_val !=AD4130_IOUT_OFF ) {It would be slightly better to set an explicit default value here as the fact it is 0 is hidden by the enum. e.g.
Quoted 6 lines
chan_info->iout0 = AD4130_IOUT_OFF; fwnode_property_read_u32(child, "adi,excitation-pin-0", &chan_info->iout0); if (chan_info->....That would save reviewers wondering what the default is and having to go check the enum (and I'm lazy :)
I understand the idea, but the default value for iout0 is not
AD4130_IOUT_OFF. iout0 is the pin thatiout0_valcurrent is applied to, andAD4130_IOUT_OFFis a value foriout0_val. Look atad4130_parse_fw_setup.
Quoted 4 lines
For iout0, I guess I could do
#defineAD4130_AIN00x0
...chan_info->iout0=AD4130_AIN0;
Oops. I got confused. Code is fine as it is. Adding the define isn't going to make it much clearer.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/iio/adc/ad4130.c new file +6
-0+ } + } + +return ret; +} +
Re: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 63 lines · Jonathan Cameron
Quoted 58 lines
Quoted 50 lines
Quoted 18 lines
drivers/iio/adc/ad4130.c new file +16
-0+static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);drivers/iio/adc/ad4130.c line 1243
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.Quoted 4 lines
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
Quoted 8 lines
I missed it. Review is never perfect (mine definitely aren't!)
Thinking more on the adxl367. We still have a window to fix that as the driver isn't yet in a release kernel. Would you mind spinning a patch to fix that one? Even if we miss the rc cycle (it's a bit tight timing wise) we can sneak it in as an early fix in stable without significant risk of breaking anyone's userspace.
I hope Monday is not too late to do it?
I can also try to do the changes tomorrow but I don't have the hardware anymore so I won't be able to test until I get it back, which is only next week.
Quoted 7 lines
There might be other drivers that have that interpretation we can't fix but if we can reduce the scope of the problem by changing the adxl367 that would be great.
We should also definitely improve the docs and perhaps add a note to say that due to need to maintain ABI, a few drivers use scans * number of channels rather than scans.
I guess I could also do that at the same time.
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 66 lines · On Sat, 7 May 2022 19:49:17 +0300 Cosmin Tanislav <[email protected]> wrote:
Quoted 65 lines · Jonathan Cameron
Quoted 58 lines
Quoted 50 lines
Quoted 18 lines
drivers/iio/adc/ad4130.c new file +16
-0+static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);drivers/iio/adc/ad4130.c line 1243
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.Quoted 4 lines
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
I missed it. Review is never perfect (mine definitely aren't!)
Quoted 8 lines
Quoted 6 lines
Thinking more on the adxl367. We still have a window to fix that as the driver isn't yet in a release kernel. Would you mind spinning a patch to fix that one? Even if we miss the rc cycle (it's a bit tight timing wise) we can sneak it in as an early fix in stable without significant risk of breaking anyone's userspace.
I hope Monday is not too late to do it?
Any time next week should be fine. If it ends up later that's fine as well. We have at least a few weeks until the 5.18 release and then if we were to land this during the first few weeks of the next cycle that would be fine as well. No one should be insane enough to not pick up at least the first few stable releases of a new kernel!
Quoted 8 lines
I can also try to do the changes tomorrow but I don't have the hardware anymore so I won't be able to test until I get it back, which is only next week.
Quoted 4 lines
There might be other drivers that have that interpretation we can't fix but if we can reduce the scope of the problem by changing the adxl367 that would be great.
Quoted 5 lines
Quoted 3 lines
We should also definitely improve the docs and perhaps add a note to say that due to need to maintain ABI, a few drivers use scans * number of channels rather than scans.
I guess I could also do that at the same time.
Perfect :)
Thanks for sorting this out.
Jonathan
Re: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 96 lines · Jonathan Cameron
Quoted 66 lines · On Sat, 7 May 2022 19:49:17 +0300 Cosmin Tanislav <[email protected]> wrote:
Quoted 65 lines · Jonathan Cameron
Quoted 58 lines
Quoted 50 lines
Quoted 18 lines
drivers/iio/adc/ad4130.c new file +16
-0+static int ad4130_set_fifo_watermark (struct iio_dev *indio_dev,unsigned int val) +{ +struct ad4130_state *st =iio_priv (indio_dev); +unsigned int eff; +int ret; + +if (val >AD4130_FIFO_SIZE ) +return -EINVAL ; + +/* +* Always set watermark to a multiple of the number of enabled channels +* to avoid making the FIFO unaligned. +*/ + eff =rounddown (val, st->num_enabled_channels); + +mutex_lock (&st->lock);drivers/iio/adc/ad4130.c line 1243
Quoted 10 lines
drivers/iio/adc/ad4130.c new file +10
-0+ + ret =regmap_update_bits (st->regmap,AD4130_REG_FIFO_CONTROL , +AD4130_WATERMARK_MASK , +FIELD_PREP (AD4130_WATERMARK_MASK , +ad4130_watermark_reg_val (eff))); +if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.Quoted 4 lines
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
I missed it. Review is never perfect (mine definitely aren't!)
Quoted 8 lines
Quoted 6 lines
Thinking more on the adxl367. We still have a window to fix that as the driver isn't yet in a release kernel. Would you mind spinning a patch to fix that one? Even if we miss the rc cycle (it's a bit tight timing wise) we can sneak it in as an early fix in stable without significant risk of breaking anyone's userspace.
I hope Monday is not too late to do it?
Any time next week should be fine. If it ends up later that's fine as well. We have at least a few weeks until the 5.18 release and then if we were to land this during the first few weeks of the next cycle that would be fine as well. No one should be insane enough to not pick up at least the first few stable releases of a new kernel!
Quoted 12 lines
I can also try to do the changes tomorrow but I don't have the hardware anymore so I won't be able to test until I get it back, which is only next week.
Quoted 7 lines
There might be other drivers that have that interpretation we can't fix but if we can reduce the scope of the problem by changing the adxl367 that would be great.
We should also definitely improve the docs and perhaps add a note to say that due to need to maintain ABI, a few drivers use scans * number of channels rather than scans.
Quoted 9 lines
Quoted 1 line
I guess I could also do that at the same time.
Perfect :)
Thanks for sorting this out.
Jonathan
I've just had another good look at ADXL367. It seems that I'm quick at forgetting stuff about the code I write.
In adxl367_set_fifo_samples(), fifo_watermark is multiplied by fifo_set_size, then, if it is larger than the maximum watermark, it is capped at the maximum watermark, and then, it is divided by fifo_set_size again.
In the end, fifo_watermark actually seems to mean number of scans in that driver too.
So this was a huge confusion. The different thing about AD4130 is that the register actually means number of samples, and not number of scans, so that's where that confussion stemmed from.
Sorry for wasting your time on this.
Jonathan Cameron
maintainerRe: [PATCH v3 2/2] iio: adc: ad4130: add AD4130 driver
Quoted 115 lines · On Sat, 14 May 2022 16:32:25 +0300 Cosmin Tanislav <[email protected]>…
Quoted 96 lines · Jonathan Cameron
Quoted 66 lines · On Sat, 7 May 2022 19:49:17 +0300 Cosmin Tanislav <[email protected]> wrote:
Quoted 65 lines · Jonathan Cameron
Quoted 58 lines
Quoted 50 lines
Quoted 18 lines
(quoted diff) +16
-0+static int ad4130_set_fifo_watermark(struct iio_dev *indio_dev, unsigned int val) +{ + struct ad4130_state *st = iio_priv(indio_dev); + unsigned int eff; + int ret; + + if (val > AD4130_FIFO_SIZE) + return -EINVAL; + + /* + * Always set watermark to a multiple of the number of enabled channels + * to avoid making the FIFO unaligned. + */ + eff = rounddown(val, st->num_enabled_channels); + + mutex_lock(&st->lock);Review
Quoted 10 lines
(quoted diff) +10
-0+ + ret = regmap_update_bits(st->regmap, AD4130_REG_FIFO_CONTROL, + AD4130_WATERMARK_MASK, + FIELD_PREP(AD4130_WATERMARK_MASK, + ad4130_watermark_reg_val(eff))); + if (ret) + goto out; + + st->effective_watermark = eff; + st->watermark = val;Hmm this is a potential inconsistency in the IIO ABI.
ABI docs describes watermark as being number of 'scan elements' which is not the clearest text we could have gone with...Now I may well have made a mistake in the following as it's rather a long time since I last looked at the core handling for this...
The core treats it as number datum (which is same as a scan) when using it for the main watermark attribute and also when using watermarks with the kfifo (the IIO fifo is made up of objects each of which is a scan. So
kfifo_len()returns the number of scans.Looking very quickly at a few other drivers
adxl367 seems to use number of samples.
adxl372 is using number of scans.
bmc150 hardware seems to work on basis of frame count which I 'think' is probably scans. fxls8962 uses 'samples count' which is not clearly defined in the datasheet but there is an example showing that it's scans (I think)...
lsm6dsx - some of the fifos used with this are based on tagged data so the connection to what hits the front end buffers is non obvious.Quoted 7 lines
So, not great for consistency :(
Going forwards i think we should standardize the hardware fifo watermark on what is being used for the software watermark which I believe is number of scans.
Not necessary much we can do about old drivers though due to risk of breaking ABI... We should make the documentation clearer though.Quoted 4 lines
I was confused too, but this seemed more logical to me at the time, and since you didn't say anything regarding it on ADXL367, I did it the same way here. I guess we can't go back and change it now on ADXL367, I'm sorry for this. I'll fix it.
I missed it. Review is never perfect (mine definitely aren't!)
Quoted 8 lines
Quoted 6 lines
Thinking more on the adxl367. We still have a window to fix that as the driver isn't yet in a release kernel. Would you mind spinning a patch to fix that one? Even if we miss the rc cycle (it's a bit tight timing wise) we can sneak it in as an early fix in stable without significant risk of breaking anyone's userspace.
I hope Monday is not too late to do it?
Any time next week should be fine. If it ends up later that's fine as well. We have at least a few weeks until the 5.18 release and then if we were to land this during the first few weeks of the next cycle that would be fine as well. No one should be insane enough to not pick up at least the first few stable releases of a new kernel!
Quoted 12 lines
I can also try to do the changes tomorrow but I don't have the hardware anymore so I won't be able to test until I get it back, which is only next week.
Quoted 7 lines
There might be other drivers that have that interpretation we can't fix but if we can reduce the scope of the problem by changing the adxl367 that would be great.
We should also definitely improve the docs and perhaps add a note to say that due to need to maintain ABI, a few drivers use scans * number of channels rather than scans.
Quoted 9 lines
Quoted 1 line
I guess I could also do that at the same time.
Perfect :)
Thanks for sorting this out.
Jonathan
I've just had another good look at ADXL367. It seems that I'm quick at forgetting stuff about the code I write.
In
adxl367_set_fifo_samples(),fifo_watermarkis multiplied byfifo_set_size, then, if it is larger than the maximum watermark, it is capped at the maximum watermark, and then, it is divided byfifo_set_sizeagain.
Quoted 8 lines
In the end,
fifo_watermarkactually seems to mean number of scans in that driver too.So this was a huge confusion. The different thing about AD4130 is that the register actually means number of samples, and not number of scans, so that's where that confussion stemmed from.
Sorry for wasting your time on this.
No problem and thanks for looking into this in more depth!
Jonathan