Skip to contentSkip to conversation

dt-bindings: iio: addac: add AD74115

PATCH Superseded Cosmin Tanislav 4 participants 6 messages Oct 3, 2022 – Oct 29, 2022 1 message not in the archive

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 dt-bindings: iio: addac: add AD74115

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

---
 .../bindings/iio/addac/adi,ad74115.yaml       | 491 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 498 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +491 -0
new file mode 100644
index 000000000000..1f894d80b259
@@ -0,0 +1,491 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/addac/adi,ad74115.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD74115H device
+
+maintainers:
+  - Cosmin Tanislav <[email protected]>
+
+description: |
+  The AD74115H is a single-channel software configurable input/output
+  device for industrial control applications. It contains functionality for
+  analog output, analog input, digital output, digital input, resistance
+  temperature detector, and thermocouple measurements integrated into a single
+  chip solution with an SPI interface. The device features a 16-bit ADC and a
+  14-bit DAC.
+
+    https://www.analog.com/en/products/ad74115h.html
+
+properties:
+  compatible:
+    enum:
+      - adi,ad74115h
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 24000000
+
+  spi-cpol: true
+
+  interrupts:
+    maxItems: 1
+
+  avdd-supply: true
+  avcc-supply: true
+  dvcc-supply: true
+  aldo1v8-supply: true
+  dovdd-supply: true
+  refin-supply: true
+
+  adi,ch-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Channel function.
+      0 - High impedance
+      1 - Voltage output
+      2 - Current output
+      3 - Voltage input
+      4 - Current input, externally-powered
+      5 - Current input, loop-powered
+      6 - Resistance input
+      7 - RTD measure
+      8 - Digital input logic
+      9 - Digital input, loop-powered
+      10 - Current output with HART
+      11 - Current input, externally-powered, with HART
+      12 - Current input, loop-powered, with HART
+    minimum: 0
+    maximum: 12
+    default: 0
+
+  adi,conv2-mux:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Input node for ADC conversion 2.
+      0 - SENSE_EXT1 to AGND_SENSE
+      1 - SENSE_EXT2 to AGND_SENSE
+      2 - SENSE_EXT2 to SENSE_EXT1
+      3 - AGND to AGND
+    minimum: 0
+    maximum: 3
+    default: 0
+
+  adi,conv2-range:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Conversion range for ADC conversion 2.
+      0 - 0V to 12V
+      1 - -12V to +12V
+      2 - -2.5V to +2.5V
+      3 - -2.5V to 0V
+      4 - 0V to 2.5V
+      5 - 0V to 0.625V
+      6 - -104mV to +104mV
+      7 - 0V to 12V
+    minimum: 0
+    maximum: 7
+    default: 0
+
+  adi,diag0-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Diagnostic channel 0 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sinking current from external digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag1-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Diagnostic channel 1 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sourcing current from external digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag2-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Diagnostic channel 2 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sinking current from internal digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag3-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Diagnostic channel 3 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sourcing current from internal digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,sense-agnd-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the AGND sense pin.
+
+  adi,lf-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the low-side filtered
+      sense pin.
+
+  adi,hf-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the high-side filtered
+      sense pin.
+
+  adi,ext2-buffer-lp:
+    type: boolean
+    description: Whether to enable low-power buffered mode for the EXT2 pin.
+
+  adi,ext1-buffer-lp:
+    type: boolean
+    description: Whether to enable low-power buffered mode for the EXT1 pin.
+
+  adi,comparator-invert-en:
+    type: boolean
+    description: Whether to invert the comparator output.
+
+  adi,digital-input-range:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Digital input range.
+      0 - Range 0.0 to 3.7mA in steps of 120uA, ~2k series resistance
+      1 - Range 1.0 to 7.4mA in steps of 240uA, ~1k series resistance
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,digital-input-sink:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Digital input sink.
+    minimum: 0
+    maximum: 31
+    default: 0
+
+  adi,digital-input-debounce-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Digital input debounce mode.
+      0 - Integrator method is used, a counter increments when the
+          signal is asserted and decrements when the signal is de-asserted
+      1 - A simple counter increments while a signal is asserted and
+          resets when the signal de-asserts
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,digital-input-unbuffered:
+    type: boolean
+    description: Whether to buffer digital input signals.
+
+  adi,digital-input-short-circuit-detection:
+    type: boolean
+    description: Whether to detect digital input short circuits.
+
+  adi,digital-input-open-circuit-detection:
+    type: boolean
+    description: Whether to detect digital input open circuits.
+
+  adi,digital-input-threshold-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Digital input threshold mode.
+      0 - The threshold range is from -0.96 * AVDD to AVDD
+      1 - The threshold range is fixed from -19V to 30V
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,dac-bipolar:
+    type: boolean
+    description: |
+      When not present, the DAC operates in the 0V to 12V range.
+      When present, the DAC operates in the -12V to 12V range.
+
+  adi,charge-pump-en:
+    type: boolean
+    description: Whether to enable the internal charge pump.
+
+  adi,dac-hart-slew:
+    type: boolean
+    description: Whether to use a HART-compatible slew rate.
+
+  adi,dac-current-limit:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Current limit.
+      0 - 32mA source or sink for VOUT, 4mA sink for IOUT
+      1 - 16mA source or sink for VOUT, 1mA sink for IOUT
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,rtd-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      RTD mode.
+      0 - 3-wire mode
+      1 - 4-wire mode
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,3-wire-rtd-excitation-swap:
+    type: boolean
+    description: Whether to swap the excitation for 3-wire RTD.
+
+  adi,rtd-excitation-current-microamp:
+    description: Excitation current to apply to RTD.
+    enum: [250, 500, 750, 1000]
+    default: 250
+
+  adi,ext1-burnout-en:
+    type: boolean
+    description: Whether to enable burnout current for EXT1.
+
+  adi,ext1-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current in nanoamps to be applied to EXT1.
+    enum: [0, 50, 500, 1000, 10000]
+    default: 0
+
+  adi,ext1-burnout-current-polarity:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for EXT2.
+      0 - Sinking
+      1 - Sourcing
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,ext2-burnout-en:
+    type: boolean
+    description: Whether to enable burnout current for EXT2.
+
+  adi,ext2-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Burnout current in nanoamps to be applied to EXT2.
+    enum: [0, 50, 500, 1000, 10000]
+    default: 0
+
+  adi,ext2-burnout-current-polarity:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for EXT2.
+      0 - Sinking
+      1 - Sourcing
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,viout-burnout-en:
+    type: boolean
+    description: Whether to enable burnout current for VIOUT.
+
+  adi,viout-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Burnout current in nanoamps to be applied to VIOUT.
+    enum: [0, 1000, 10000]
+    default: 0
+
+  adi,viout-burnout-current-polarity:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for VIOUT.
+      0 - Sinking
+      1 - Sourcing
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,gpio0-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Comparator output
+      3 - Control HART CD
+      4 - Monitor HART CD
+      5 - Monitor HART EOM status
+    minimum: 0
+    maximum: 5
+    default: 0
+
+  adi,gpio1-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Drive external digital output FET
+      3 - Control HART RXD
+      4 - Monitor HART RXD
+      5 - Monitor HART SOM status
+    minimum: 0
+    maximum: 5
+    default: 0
+
+  adi,gpio2-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Drive internal digital output FET
+      3 - Control HART TXD
+      4 - Monitor HART TXD
+      5 - Monitor HART TX complete status
+    minimum: 0
+    maximum: 5
+    default: 0
+
+  adi,gpio3-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - High impedance
+      3 - Control HART RTS
+      4 - Monitor HART RTS
+      5 - Monitor HART CD complete status
+    minimum: 0
+    maximum: 5
+    default: 0
+
+required:
+  - compatible
+  - reg
+  - spi-cpol
+  - avdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      cs-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
+      status = "okay";
+
+      addac@0 {
+        compatible = "adi,ad74115h";
+        reg = <0>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        spi-max-frequency = <12000000>;
+        spi-cpol;
+
+        interrupt-parent = <&gpio>;
+        interrupts = <26 IRQ_TYPE_EDGE_FALLING>;
+
+        refin-supply = <&ad74115_refin>;
+        avdd-supply = <&ad74115_avdd>;
+
+        adi,ch-func = <1>;
+        adi,conv2-mux = <2>;
+        adi,conv2-range = <1>;
+
+        adi,digital-input-unbuffered;
+        adi,gpio0-mode = <2>;
+
+        adi,gpio1-mode = <1>;
+        adi,gpio2-mode = <1>;
+        adi,gpio3-mode = <1>;
+
+        adi,diag0-func = <10>;
+        adi,diag1-func = <8>;
+        adi,diag2-func = <6>;
+        adi,diag3-func = <12>;
+
+        adi,dac-bipolar;
+      };
+    };
+...
MAINTAINERS +7 -0
index c547559eddf9..25071e763b33 100644
@@ -1140,6 +1140,13 @@ W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
 F:	drivers/iio/adc/ad7780.c
 
+ANALOG DEVICES INC AD74115 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/addac/adi,ad74115.yaml
+
 ANALOG DEVICES INC AD74413R DRIVER
 M:	Cosmin Tanislav <[email protected]>
 L:	[email protected]
Signature · 1 line
2.37.3
#2 lore raw
Quoted 16 lines · Cosmin Tanislav

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

Quoted 6 lines

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

I got only this patch. Where is the cover letter?

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml

Quoted 11 lines
---
 .../bindings/iio/addac/adi,ad74115.yaml       | 491 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 498 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +0 -0
new file mode 100644
index 000000000000..1f894d80b259

Filename matching compatible, so adi,ad74115h.yaml

Quoted 12 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +11 -0
@@ -0,0 +1,491 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/addac/adi,ad74115.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD74115H device
+
+maintainers:
+  - Cosmin Tanislav <[email protected]>
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 21

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+description: |
+  The AD74115H is a single-channel software configurable input/output
+  device for industrial control applications. It contains functionality for
+  analog output, analog input, digital output, digital input, resistance
+  temperature detector, and thermocouple measurements integrated into a single
+  chip solution with an SPI interface. The device features a 16-bit ADC and a
+  14-bit DAC.
+
+    https://www.analog.com/en/products/ad74115h.html
+

Missing allOf-ref to spi properties.

Quoted 44 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +44 -0
+properties:
+  compatible:
+    enum:
+      - adi,ad74115h
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 24000000
+
+  spi-cpol: true
+
+  interrupts:
+    maxItems: 1
+
+  avdd-supply: true
+  avcc-supply: true
+  dvcc-supply: true
+  aldo1v8-supply: true
+  dovdd-supply: true
+  refin-supply: true
+
+  adi,ch-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Channel function.
+      0 - High impedance
+      1 - Voltage output
+      2 - Current output
+      3 - Voltage input
+      4 - Current input, externally-powered
+      5 - Current input, loop-powered
+      6 - Resistance input
+      7 - RTD measure
+      8 - Digital input logic
+      9 - Digital input, loop-powered
+      10 - Current output with HART

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 75

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      11 - Current input, externally-powered, with HART
+      12 - Current input, loop-powered, with HART
+    minimum: 0
+    maximum: 12
+    default: 0
+
+  adi,conv2-mux:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Input node for ADC conversion 2.

node or mode?

Quoted 16 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +16 -0
+      0 - SENSE_EXT1 to AGND_SENSE
+      1 - SENSE_EXT2 to AGND_SENSE
+      2 - SENSE_EXT2 to SENSE_EXT1
+      3 - AGND to AGND
+    minimum: 0
+    maximum: 3
+    default: 0
+
+  adi,conv2-range:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Conversion range for ADC conversion 2.
+      0 - 0V to 12V
+      1 - -12V to +12V
+      2 - -2.5V to +2.5V
+      3 - -2.5V to 0V

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 101

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      4 - 0V to 2.5V
+      5 - 0V to 0.625V
+      6 - -104mV to +104mV
+      7 - 0V to 12V
+    minimum: 0
+    maximum: 7
+    default: 0
+
+  adi,diag0-func:
+    $ref: /schemas/types.yaml#/definitions/uint32

This nicely matches a string enum.

Quoted 15 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +15 -0
+    description: |
+      Diagnostic channel 0 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 126

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      13 - DO_VDD
+      14 - AGND
+      15 - Sinking current from external digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag1-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

Ditto

Quoted 13 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +13 -0
+      Diagnostic channel 1 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 149

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sourcing current from external digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag2-func:
+    $ref: /schemas/types.yaml#/definitions/uint32

Ditto

Quoted 15 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +15 -0
+    description: |
+      Diagnostic channel 2 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 174

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      13 - DO_VDD
+      14 - AGND
+      15 - Sinking current from internal digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag3-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

Ditto

Quoted 37 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +37 -0
+      Diagnostic channel 3 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2
+      13 - DO_VDD
+      14 - AGND
+      15 - Sourcing current from internal digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,sense-agnd-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the AGND sense pin.
+
+  adi,lf-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the low-side filtered
+      sense pin.
+
+  adi,hf-buffer-lp:
+    type: boolean
+    description: |
+      Whether to enable low-power buffered mode for the high-side filtered
+      sense pin.

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 221

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+
+  adi,ext2-buffer-lp:
+    type: boolean
+    description: Whether to enable low-power buffered mode for the EXT2 pin.
+
+  adi,ext1-buffer-lp:
+    type: boolean
+    description: Whether to enable low-power buffered mode for the EXT1 pin.
+
+  adi,comparator-invert-en:

Drop "-en" suffix.

Quoted 6 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +6 -0
+    type: boolean
+    description: Whether to invert the comparator output.
+
+  adi,digital-input-range:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 237

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      Digital input range.
+      0 - Range 0.0 to 3.7mA in steps of 120uA, ~2k series resistance
+      1 - Range 1.0 to 7.4mA in steps of 240uA, ~1k series resistance
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,digital-input-sink:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Digital input sink.

You just copied the name of property into description. It's not useful.

Quoted 4 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +4 -0
+    minimum: 0
+    maximum: 31
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 251

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,digital-input-debounce-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Digital input debounce mode.
+      0 - Integrator method is used, a counter increments when the
+          signal is asserted and decrements when the signal is de-asserted
+      1 - A simple counter increments while a signal is asserted and
+          resets when the signal de-asserts
+    minimum: 0
+    maximum: 1

This also looks like a string.

Quoted 34 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +34 -0
+    default: 0
+
+  adi,digital-input-unbuffered:
+    type: boolean
+    description: Whether to buffer digital input signals.
+
+  adi,digital-input-short-circuit-detection:
+    type: boolean
+    description: Whether to detect digital input short circuits.
+
+  adi,digital-input-open-circuit-detection:
+    type: boolean
+    description: Whether to detect digital input open circuits.
+
+  adi,digital-input-threshold-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Digital input threshold mode.
+      0 - The threshold range is from -0.96 * AVDD to AVDD
+      1 - The threshold range is fixed from -19V to 30V
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,dac-bipolar:
+    type: boolean
+    description: |
+      When not present, the DAC operates in the 0V to 12V range.
+      When present, the DAC operates in the -12V to 12V range.
+
+  adi,charge-pump-en:
+    type: boolean
+    description: Whether to enable the internal charge pump.
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 295

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,dac-hart-slew:
+    type: boolean
+    description: Whether to use a HART-compatible slew rate.
+
+  adi,dac-current-limit:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Current limit.
+      0 - 32mA source or sink for VOUT, 4mA sink for IOUT
+      1 - 16mA source or sink for VOUT, 1mA sink for IOUT

Use common property units, so microamp:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 305

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,rtd-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      RTD mode.
+      0 - 3-wire mode
+      1 - 4-wire mode

Looks like a string.

Quoted 4 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +4 -0
+    minimum: 0
+    maximum: 1
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 319

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,3-wire-rtd-excitation-swap:
+    type: boolean
+    description: Whether to swap the excitation for 3-wire RTD.
+
+  adi,rtd-excitation-current-microamp:
+    description: Excitation current to apply to RTD.
+    enum: [250, 500, 750, 1000]
+    default: 250
+
+  adi,ext1-burnout-en:

Drop "-en" suffix

Quoted 11 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +11 -0
+    type: boolean
+    description: Whether to enable burnout current for EXT1.
+
+  adi,ext1-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current in nanoamps to be applied to EXT1.
+    enum: [0, 50, 500, 1000, 10000]
+    default: 0
+
+  adi,ext1-burnout-current-polarity:

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 340

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for EXT2.
+      0 - Sinking
+      1 - Sourcing
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,ext2-burnout-en:

Drop "-en" suffix

Quoted 5 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +5 -0
+    type: boolean
+    description: Whether to enable burnout current for EXT2.
+
+  adi,ext2-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 355

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+    description: Burnout current in nanoamps to be applied to EXT2.
+    enum: [0, 50, 500, 1000, 10000]
+    default: 0
+
+  adi,ext2-burnout-current-polarity:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for EXT2.
+      0 - Sinking
+      1 - Sourcing

Looks like a string.

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 360

Quoted 5 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +5 -0
+    minimum: 0
+    maximum: 1
+    default: 0
+
+  adi,viout-burnout-en:

Drop "-en" suffix

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 370

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+    type: boolean
+    description: Whether to enable burnout current for VIOUT.
+
+  adi,viout-burnout-current-nanoamp:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Burnout current in nanoamps to be applied to VIOUT.
+    enum: [0, 1000, 10000]
+    default: 0
+
+  adi,viout-burnout-current-polarity:

Looks like a string

Quoted 9 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +9 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Burnout current polarity for VIOUT.
+      0 - Sinking
+      1 - Sourcing
+    minimum: 0
+    maximum: 1
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 389

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,gpio0-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Comparator output
+      3 - Control HART CD
+      4 - Monitor HART CD
+      5 - Monitor HART EOM status

Looks like a string

Quoted 4 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +4 -0
+    minimum: 0
+    maximum: 5
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 403

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,gpio1-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Drive external digital output FET
+      3 - Control HART RXD
+      4 - Monitor HART RXD
+      5 - Monitor HART SOM status

Looks like a string

Quoted 4 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +4 -0
+    minimum: 0
+    maximum: 5
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 417

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,gpio2-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - Drive internal digital output FET
+      3 - Control HART TXD
+      4 - Monitor HART TXD
+      5 - Monitor HART TX complete status

Looks like a string

Quoted 4 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +4 -0
+    minimum: 0
+    maximum: 5
+    default: 0
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 431

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+  adi,gpio3-mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      GPIO functions.
+      0 - Disabled
+      1 - Logic I/O
+      2 - High impedance
+      3 - Control HART RTS
+      4 - Monitor HART RTS
+      5 - Monitor HART CD complete status

Looks like a string

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 443

Quoted 12 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +12 -0
+    minimum: 0
+    maximum: 5
+    default: 0
+
+required:
+  - compatible
+  - reg
+  - spi-cpol
+  - avdd-supply
+
+additionalProperties: false
+

Best regards,
Krzysztof

maintainer
#3 lore raw
Quoted 143 lines · Krzysztof Kozlowski
Quoted 16 lines · Cosmin Tanislav

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

Quoted 6 lines

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

I got only this patch. Where is the cover letter?

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml

Quoted 11 lines
---
 .../bindings/iio/addac/adi,ad74115.yaml       | 491 ++++++++++++++++++
 MAINTAINERS                                   |   7 +
 2 files changed, 498 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +0 -0
new file mode 100644
index 000000000000..1f894d80b259

Filename matching compatible, so adi,ad74115h.yaml

Quoted 12 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +11 -0
@@ -0,0 +1,491 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/addac/adi,ad74115.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD74115H device
+
+maintainers:
+  - Cosmin Tanislav <[email protected]>
+

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 21

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+description: |
+  The AD74115H is a single-channel software configurable input/output
+  device for industrial control applications. It contains functionality for
+  analog output, analog input, digital output, digital input, resistance
+  temperature detector, and thermocouple measurements integrated into a single
+  chip solution with an SPI interface. The device features a 16-bit ADC and a
+  14-bit DAC.
+
+    https://www.analog.com/en/products/ad74115h.html
+

Missing allOf-ref to spi properties.

Quoted 44 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +44 -0
+properties:
+  compatible:
+    enum:
+      - adi,ad74115h
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 24000000
+
+  spi-cpol: true
+
+  interrupts:
+    maxItems: 1
+
+  avdd-supply: true
+  avcc-supply: true
+  dvcc-supply: true
+  aldo1v8-supply: true
+  dovdd-supply: true
+  refin-supply: true
+
+  adi,ch-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Channel function.
+      0 - High impedance
+      1 - Voltage output
+      2 - Current output
+      3 - Voltage input
+      4 - Current input, externally-powered
+      5 - Current input, loop-powered
+      6 - Resistance input
+      7 - RTD measure
+      8 - Digital input logic
+      9 - Digital input, loop-powered
+      10 - Current output with HART

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 75

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      11 - Current input, externally-powered, with HART
+      12 - Current input, loop-powered, with HART
+    minimum: 0
+    maximum: 12
+    default: 0
+
+  adi,conv2-mux:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Input node for ADC conversion 2.

node or mode?

Quoted 20 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +20 -0
+      0 - SENSE_EXT1 to AGND_SENSE
+      1 - SENSE_EXT2 to AGND_SENSE
+      2 - SENSE_EXT2 to SENSE_EXT1
+      3 - AGND to AGND
+    minimum: 0
+    maximum: 3
+    default: 0
+
+  adi,conv2-range:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Conversion range for ADC conversion 2.
+      0 - 0V to 12V
+      1 - -12V to +12V
+      2 - -2.5V to +2.5V
+      3 - -2.5V to 0V
+      4 - 0V to 2.5V
+      5 - 0V to 0.625V
+      6 - -104mV to +104mV
+      7 - 0V to 12V
Quoted 8 lines

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 101

Quoted 6 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +6 -0
+    minimum: 0
+    maximum: 7
+    default: 0
+
+  adi,diag0-func:
+    $ref: /schemas/types.yaml#/definitions/uint32

This nicely matches a string enum.

Then the driver has to do a bunch of string comparisons to get back to a register setting. Worth it if something common, but for a device specific setting, I'd just stick with register field values.

If these are diagnostic/debug, why would you want it in DT to begin with? Wouldn't someone want to change this at run-time? Seems like a debugfs feature instead.

Quoted 28 lines
Quoted 16 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +15 -0
+    description: |
+      Diagnostic channel 0 function.
+      0 - Disabled
+      1 - Temperature sensor
+      2 - DVCC
+      3 - AVCC
+      4 - ALDO1V8
+      5 - DLDO1V8
+      6 - REFOUT
+      7 - AVDD
+      8 - AVSS
+      9 - LVIN
+      10 - SENSEL
+      11 - SENSE_EXT1
+      12 - SENSE_EXT2

Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml line 126

Quoted 10 lines
Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml new file +10 -0
+      13 - DO_VDD
+      14 - AGND
+      15 - Sinking current from external digital output
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  adi,diag1-func:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

Ditto

#4 lore raw

PATCH 2/2 iio: addac: add AD74115 driver

In reply to a message not in the archive

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

---
 MAINTAINERS                 |    1 +
 drivers/iio/addac/Kconfig   |   14 +
 drivers/iio/addac/Makefile  |    1 +
 drivers/iio/addac/ad74115.c | 2025 +++++++++++++++++++++++++++++++++++
 4 files changed, 2041 insertions(+)
 create mode 100644 drivers/iio/addac/ad74115.c
MAINTAINERS +1 -0
index 25071e763b33..c5b6d8bbb386 100644
@@ -1146,6 +1146,7 @@ L:	[email protected]
 S:	Supported
 W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/devicetree/bindings/iio/addac/adi,ad74115.yaml
+F:	drivers/iio/addac/ad74115.c
 
 ANALOG DEVICES INC AD74413R DRIVER
 M:	Cosmin Tanislav <[email protected]>
drivers/iio/addac/Kconfig +14 -0
index fcf6d2269bfc..2843fcb70e24 100644
@@ -5,6 +5,20 @@
 
 menu "Analog to digital and digital to analog converters"
 
+config AD74115
+	tristate "Analog Devices AD74115H driver"
+	depends on GPIOLIB && SPI
+	select CRC8
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices AD74115H
+	  single-channel software configurable input/output solution.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad74115.
+
 config AD74413R
 	tristate "Analog Devices AD74412R/AD74413R driver"
 	depends on GPIOLIB && SPI
drivers/iio/addac/Makefile +1 -0
index 17de20ef0d8e..577777276e43 100644
@@ -4,5 +4,6 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_AD74115) += ad74115.o
 obj-$(CONFIG_AD74413R) += ad74413r.o
 obj-$(CONFIG_STX104) += stx104.o
drivers/iio/addac/ad74115.c new file +2025 -0

2,025 lines not on this page · raw message

Signature · 1 line
2.37.3
maintainer
#5 lore raw

Re: [PATCH 2/2] iio: addac: add AD74115 driver

Quoted 16 lines · On Mon, 3 Oct 2022 13:30:15 +0300 Cosmin Tanislav <[email protected]>…

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

Quoted 6 lines

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

Hi Cosmin, very much a partial review as I'm out of time today. I'll get back to the rest, but may be a few days.

Quoted 8 lines
---
 MAINTAINERS                 |    1 +
 drivers/iio/addac/Kconfig   |   14 +
 drivers/iio/addac/Makefile  |    1 +
 drivers/iio/addac/ad74115.c | 2025 +++++++++++++++++++++++++++++++++++
 4 files changed, 2041 insertions(+)
 create mode 100644 drivers/iio/addac/ad74115.c

...

Quoted 17 lines
drivers/iio/addac/Makefile +1 -0
index 17de20ef0d8e..577777276e43 100644
@@ -4,5 +4,6 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_AD74115) += ad74115.o
 obj-$(CONFIG_AD74413R) += ad74413r.o
 obj-$(CONFIG_STX104) += stx104.o
drivers/iio/addac/ad74115.c new file +0 -0
new file mode 100644
index 000000000000..3234b7165b9f

drivers/iio/addac/ad74115.c line 7

Quoted 7 lines
drivers/iio/addac/ad74115.c new file +7 -0
@@ -0,0 +1,2025 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Analog Devices, Inc.
+ * Author: Cosmin Tanislav <[email protected]>
+ */
+
+#include <linux/crc8.h>

Stick to alphabetical order within the 3 blocks of includes.

Quoted 46 lines
drivers/iio/addac/ad74115.c new file +46 -0
+#include <linux/bitfield.h>
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/gpio/driver.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
+#include <linux/units.h>
+
+#include <asm/unaligned.h>
+
+#include <linux/iio/buffer.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+> +
+struct ad74115_channels {
+	struct iio_chan_spec		*channels;
+	unsigned int			num_channels;
+};
+
+struct ad74115_state {
+	struct spi_device		*spi;
+	struct regmap			*regmap;
+	struct iio_trigger		*trig;
+
+	/*
+	 * Synchronize consecutive operations when doing a one-shot
+	 * conversion and when updating the ADC samples SPI message.
+	 */
+	struct mutex			lock;
+	struct regulator_bulk_data	regulators[AD74115_REGULATORS_NUM];
+	struct gpio_chip		gc;
+	struct gpio_chip		comp_gc;
+
+	unsigned int			avdd_mv;
+	unsigned long			gpio_valid_mask;
+	bool				dac_bipolar;
+	bool				dac_hart_slew;
+	enum ad74115_ch_func		ch_func;
+	enum ad74115_diag_func		diag_func[AD74115_DIAG_NUM];
+	enum ad74115_din_threshold_mode	din_threshold_mode;
+	enum ad74115_rtd_mode		rtd_mode;

drivers/iio/addac/ad74115.c line 63

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+
+	struct completion		adc_data_completion;
+	struct spi_message		adc_samples_msg;
+	struct spi_transfer		adc_samples_xfer[AD74115_ADC_CH_NUM + 1];
+
+	/*
+	 * DMA (thus cache coherency maintenance) requires the
+	 * transfer buffers to live in their own cache lines.
+	 */
+	u8				reg_tx_buf[AD74115_FRAME_SIZE] ____cacheline_aligned;

Switch to __aligned(IIO_DMA_MINALIGN)
See the patches that did that for all the other drivers for why...

drivers/iio/addac/ad74115.c line 268

Quoted 4 lines
drivers/iio/addac/ad74115.c new file +4 -0
+	u8				reg_rx_buf[AD74115_FRAME_SIZE];
+	u8				adc_samples_tx_buf[AD74115_FRAME_SIZE * AD74115_ADC_CH_NUM];
+	u8				adc_samples_rx_buf[AD74115_FRAME_SIZE * AD74115_ADC_CH_NUM];
+};

... BIG CHUNK I SKIPPED OVER due to lack of time...

Quoted 19 lines
drivers/iio/addac/ad74115.c new file +19 -0
+
+static int ad74115_probe(struct spi_device *spi)
+{
+	struct device *dev = &spi->dev;
+	struct ad74115_state *st;
+	struct iio_dev *indio_dev;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+
+	st->spi = spi;
+	mutex_init(&st->lock);
+	init_completion(&st->adc_data_completion);
+
+	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", AD74115_NAME,

drivers/iio/addac/ad74115.c line 1929

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+					  iio_device_id(indio_dev));
+	if (!st->trig)
+		return -ENOMEM;
+
+	st->trig->ops = &ad74115_trigger_ops;
+	iio_trigger_set_drvdata(st->trig, st);
+
+	ret = devm_iio_trigger_register(dev, st->trig);
+	if (ret)
+		return ret;

I'd normally expect trigger registration to be alongside the irq setup. Makes it easier to see everything involved.

drivers/iio/addac/ad74115.c line 1941

Quoted 12 lines
drivers/iio/addac/ad74115.c new file +12 -0
+
+	indio_dev->name = AD74115_NAME;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ad74115_info;
+	indio_dev->trig = iio_trigger_get(st->trig);
+
+	st->regulators[AD74115_AVDD_REGULATOR].supply = "avdd";
+	st->regulators[AD74115_AVCC_REGULATOR].supply = "avcc";
+	st->regulators[AD74115_DVCC_REGULATOR].supply = "dvcc";
+	st->regulators[AD74115_ALDO1V8_REGULATOR].supply = "aldo1v8";
+	st->regulators[AD74115_DOVDD_REGULATOR].supply = "dovdd";
+	st->regulators[AD74115_REFIN_REGULATOR].supply = "refin";

I think you only query the voltages on a subset of these. I'd be tempted to handle those independently of those where you only care if they are on.

That way you can use the new devm_regulator_bulk_get_enabled() call to reduce how many need the more complex handling.

Also makes it clear here which ones you might query.

Quoted 18 lines
drivers/iio/addac/ad74115.c new file +18 -0
+
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators),
+				      st->regulators);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get regulators\n");
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to enable regulators\n");
+
+	ret = devm_add_action_or_reset(dev, ad74115_regulators_disable, st);
+	if (ret)
+		return ret;
+
+	st->regmap = devm_regmap_init(dev, NULL, st, &ad74115_regmap_config);
+	if (IS_ERR(st->regmap))
+		return PTR_ERR(st->regmap);
+

drivers/iio/addac/ad74115.c line 1969

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+	ret = ad74115_reset(st);
+	if (ret)
+		return ret;
+
+	ret = ad74115_setup(indio_dev);
+	if (ret)
+		return ret;
+
+	ret = devm_request_irq(dev, spi->irq, ad74115_adc_data_interrupt,
+			       0, AD74115_NAME, indio_dev);

It's unusual to have a required irq. Is it not possible to use a fixed length sleep if no irq is wired? (people for ever seem to decide not writing the interrupt is a good idea when they are short on pins).

Obviously if irq no present then the trigger doesn't make much sense, but other trigger types will be fine. You allow those currently...

Quoted 7 lines
drivers/iio/addac/ad74115.c new file +7 -0
+	if (ret)
+		return ret;
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      iio_pollfunc_store_time,
+					      ad74115_trigger_handler,
+					      &ad74115_buffer_ops);

drivers/iio/addac/ad74115.c line 1998

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +9 -0
+	if (ret)
+		return ret;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
 
+
+static const struct spi_device_id ad74115_spi_id[] = {
+	{ "ad74115h", 0 },

No point in filling in the data with 0. That's the default and I would hope you aren't currently using it anyway given only one supported ID.

drivers/iio/addac/ad74115.c line 1999

Quoted 1 line
drivers/iio/addac/ad74115.c new file +1 -0
+	{ },

I'd prefer no comma after "NULL" terminators like this one. Makes it slightly harder to add stuff afterwards which never makes sense.

drivers/iio/addac/ad74115.c line 2006

Quoted 7 lines
drivers/iio/addac/ad74115.c new file +7 -0
+};
+
+MODULE_DEVICE_TABLE(spi, ad74115_spi_id);
+
+static const struct of_device_id ad74115_dt_id[] = {
+	{ .compatible = "adi,ad74115h" },
+	{},

Prefer no comma on NULL terminator + consistent spacing for similar structures.

Quoted 19 lines
drivers/iio/addac/ad74115.c new file +19 -0
+};
+MODULE_DEVICE_TABLE(of, ad74115_dt_id);
+
+static struct spi_driver ad74115_driver = {
+	.driver = {
+		   .name = "ad74115",
+		   .of_match_table = ad74115_dt_id,
+	},
+	.probe = ad74115_probe,
+	.id_table = ad74115_spi_id,
+};
+
+module_driver(ad74115_driver,
+	      ad74115_register_driver,
+	      ad74115_unregister_driver);
+
+MODULE_AUTHOR("Cosmin Tanislav <[email protected]>");
+MODULE_DESCRIPTION("Analog Devices AD74115 ADDAC");
+MODULE_LICENSE("GPL");
maintainer
#6 lore raw

Re: [PATCH 2/2] iio: addac: add AD74115 driver

In reply to Cosmin Tanislav
Quoted 16 lines · On Mon, 3 Oct 2022 13:30:15 +0300 Cosmin Tanislav <[email protected]>…

From: Cosmin Tanislav <[email protected]>

The AD74115H is a single-channel, software-configurable, input and output device for industrial control applications. The AD74115H provides a wide range of use cases, integrated on a single chip.

These use cases include analog output, analog input, digital output, digital input, resistance temperature detector (RTD), and thermocouple measurement capability. The AD74115H also has an integrated HART modem.

A serial peripheral interface (SPI) is used to handle all communications to the device, including communications with the HART modem. The digital input and digital outputs can be accessed via the SPI or the general-purpose input and output (GPIO) pins to support higher speed data rates.

Quoted 6 lines

The device features a 16-bit, sigma-delta analog-to-digital converter (ADC) and a 14-bit digital-to-analog converter (DAC).
The AD74115H contains a high accuracy 2.5 V on-chip reference that can be used as the DAC and ADC reference.

Hi Cosmin,

Took me a touch longer than expected to get back to this.

Anyhow, a few minor comments inline. It's a huge driver so I'm not going to looks super closely at individual register settings etc (I rarely do unless something 'smells' off!)

Biggest additional thing in here is a suggest to change the fw parsing code to make it clear when we are just parsing and when applying the result.

Rest looked good to me.

Jonathan

Quoted 11 lines
drivers/iio/addac/ad74115.c new file +11 -0
+static int _ad74115_get_adc_code(struct ad74115_state *st,
+				 enum ad74115_adc_ch channel, int *val)
+{
+	unsigned int uval;
+	int ret;
+
+	reinit_completion(&st->adc_data_completion);
+
+	ret = ad74115_set_adc_ch_en(st, channel, true);
+	if (ret)
+		return ret;

drivers/iio/addac/ad74115.c line 864

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+
+	ret = ad74115_set_adc_conv_seq(st, AD74115_ADC_CONV_SEQ_SINGLE);
+	if (ret)
+		return ret;
+
+	ret = wait_for_completion_timeout(&st->adc_data_completion,
+					  msecs_to_jiffies(1000));
+	if (!ret) {
+		ret = -ETIMEDOUT;
+		return ret;
		return -ETIMEDOUT;
Quoted 18 lines
drivers/iio/addac/ad74115.c new file +18 -0
+	}
+
+	ret = regmap_read(st->regmap, ad74115_adc_ch_data_regs[channel], &uval);
+	if (ret)
+		return ret;
+
+	ret = ad74115_set_adc_conv_seq(st, AD74115_ADC_CONV_SEQ_STANDBY);
+	if (ret)
+		return ret;
+
+	ret = ad74115_set_adc_ch_en(st, channel, false);
+	if (ret)
+		return ret;
+
+	*val = uval;
+
+	return IIO_VAL_INT;
+}

...

Quoted 13 lines
drivers/iio/addac/ad74115.c new file +13 -0
+static int ad74115_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long info)
+{
+	struct ad74115_state *st = iio_priv(indio_dev);
+	int ret;
+
+	switch (info) {
+	case IIO_CHAN_INFO_SCALE:
+		if (ad74115_is_diag_channel(chan->channel))
+			return ad74115_get_diag_scale(st, chan, val, val2);
+		else if (chan->output)
+			return ad74115_get_dac_scale(st, chan, val, val2);

drivers/iio/addac/ad74115.c line 1311

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+
+		return ad74115_get_adc_scale(st, chan, val, val2);
+	case IIO_CHAN_INFO_OFFSET:
+		if (ad74115_is_diag_channel(chan->channel))
+			return ad74115_get_diag_offset(st, chan, val, val2);
+		else if (chan->output)
+			return ad74115_get_dac_offset(st, chan, val);
+
+		return ad74115_get_adc_offset(st, chan, val);
+	case IIO_CHAN_INFO_RAW:

Trivial: Perhaps order these to match the enum order.

Quoted 19 lines
drivers/iio/addac/ad74115.c new file +19 -0
+		if (chan->output)
+			return ad74115_get_dac_code(st, chan, val);
+
+		return ad74115_get_adc_code(indio_dev, chan, val);
+	case IIO_CHAN_INFO_PROCESSED:
+		ret = ad74115_get_adc_code(indio_dev, chan, val);
+		if (ret)
+			return ret;
+
+		return ad74115_adc_code_to_resistance(*val, val, val2);
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		if (chan->output)
+			return ad74115_get_dac_rate(st, chan, val);
+
+		return ad74115_get_adc_rate(st, chan, val);
+	default:
+		return -EINVAL;
+	}
+}

drivers/iio/addac/ad74115.c

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +9 -0
 
+static int ad74115_parse_fw_prop(struct ad74115_state *st,
+				 const struct ad74115_fw_prop *prop, u32 *retval)
+{
+	struct device *dev = &st->spi->dev;
+	u32 val;
+	int ret;
+
+	if (prop->is_boolean) {
+		val = device_property_read_bool(dev, prop->name);

Maybe worth splitting this into two separate utility functions as there isn't a lot of overlap for the is_boolean case with the others.

Quoted 18 lines
drivers/iio/addac/ad74115.c new file +18 -0
+	} else {
+		ret = device_property_read_u32(dev, prop->name, &val);
+		if (ret)
+			return 0;
+	}
+
+	*retval = val;
+
+	if (prop->is_boolean) {
+		if (prop->negate)
+			val = !val;
+	} else {
+		if (prop->lookup_tbl)
+			ret = _ad74115_find_tbl_index(prop->lookup_tbl,
+						      prop->lookup_tbl_len,
+						      val, &val);
+		else if (prop->max && val > prop->max)
+			ret = -EINVAL;

drivers/iio/addac/ad74115.c line 1673

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+		else
+			ret = 0;
+
+		if (ret)
+			return dev_err_probe(dev, -EINVAL,
+					     "Invalid value %u for prop %s\n",
+					     val, prop->name);
+	}
+
+	if (!prop->mask)

I'm not sure I like the fact there is a mask or not controlling if this is directly applied. That isn't obvious at the call sight. Perhaps add an explicit parameter to the function call - or rename it to have ad75115_parse_fw_prop() called by ad75115_apply_fw_prop() (see below) So at the call site it is immediately clear if a state update is an expected side effect.

drivers/iio/addac/ad74115.c line 1678

Quoted 5 lines
drivers/iio/addac/ad74115.c new file +5 -0
+		return 0;
+
+	val = (val << __ffs(prop->mask)) & prop->mask;
+
+	return regmap_update_bits(st->regmap, prop->reg, prop->mask, val);

Not obvious from function naming that you will do a register update. Perhaps rename as
ad74115_apply_fw_prop() or something along those lines?

Quoted 8 lines
drivers/iio/addac/ad74115.c new file +6 -0
+}
+
 
 
+static int ad74115_setup_comp_gc(struct ad74115_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	u32 val;

drivers/iio/addac/ad74115.c line 1766

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+	int ret;
+
+	ret = regmap_read(st->regmap, AD74115_DIN_CONFIG1_REG, &val);
+	if (ret)
+		return ret;
+
+	if (!(val & AD74115_DIN_COMPARATOR_EN_MASK))
+		return 0;
+
+	st->gc.owner = THIS_MODULE;

Could do a structure copy based initialization for this.

	st->gc = (struct gpio_chip) {
		.owner = 
		.label = ...
	...
	};

Up to you, but generally I think it looks a little nicer.

Quoted 11 lines
drivers/iio/addac/ad74115.c new file +11 -0
+	st->gc.label = AD74115_NAME;
+	st->gc.base = -1;
+	st->gc.ngpio = 1;
+	st->gc.parent = dev;
+	st->gc.can_sleep = true;
+	st->gc.get_direction = ad74115_comp_gpio_get_direction;
+	st->gc.get = ad74115_comp_gpio_get;
+	st->gc.set_config = ad74115_comp_gpio_set_config;
+
+	return devm_gpiochip_add_data(dev, &st->gc, st);
+}

drivers/iio/addac/ad74115.c line 1787

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+
+static int ad74115_setup(struct iio_dev *indio_dev)
+{
+	struct ad74115_state *st = iio_priv(indio_dev);
+	unsigned int i;
+	u32 val;
+	int ret;
+
+	val = AD74115_CH_FUNC_HIGH_IMPEDANCE;
+	ret = ad74115_parse_fw_prop(st, &ad74115_ch_func_fw_prop, &val);

As mentioned above, I'd like to see it clearer on whether these calls apply the configuration or just parse the fw.

Quoted 74 lines
drivers/iio/addac/ad74115.c new file +74 -0
+	if (ret)
+		return ret;
+
+	indio_dev->num_channels += ad74115_channels_map[val].num_channels;
+	st->ch_func = val;
+
+	val = false;
+	ret = ad74115_parse_fw_prop(st, &ad74115_dac_hart_slew_prop, &val);
+	if (ret)
+		return ret;
+
+	st->dac_hart_slew = val;
+
+	if (val) {
+		ret = regmap_update_bits(st->regmap, AD74115_OUTPUT_CONFIG_REG,
+					 AD74115_OUTPUT_SLEW_EN_MASK,
+					 FIELD_PREP(AD74115_OUTPUT_SLEW_EN_MASK,
+						    AD74115_SLEW_MODE_HART));
+		if (ret)
+			return ret;
+	}
+
+	val = AD74115_DIN_THRESHOLD_MODE_AVDD;
+	ret = ad74115_parse_fw_prop(st, &ad74115_din_threshold_mode_fw_prop, &val);
+	if (ret)
+		return ret;
+
+	if (val == AD74115_DIN_THRESHOLD_MODE_AVDD) {
+		ret = regulator_get_voltage(st->regulators[AD74115_AVDD_REGULATOR].consumer);
+		if (ret < 0)
+			return ret;
+
+		st->avdd_mv = ret / 1000;
+	}
+
+	st->din_threshold_mode = val;
+
+	val = false;
+	ret = ad74115_parse_fw_prop(st, &ad74115_dac_bipolar_fw_prop, &val);
+	if (ret)
+		return ret;
+
+	st->dac_bipolar = val;
+
+	val = AD74115_RTD_MODE_3_WIRE;
+	ret = ad74115_parse_fw_prop(st, &ad74115_ch_func_fw_prop, &val);
+	if (ret)
+		return ret;
+
+	st->rtd_mode = val;
+
+	for (i = 0; i < AD74115_GPIO_NUM; i++) {
+		val = AD74115_GPIO_MODE_LOGIC;
+
+		ret = ad74115_parse_fw_prop(st, &ad74115_gpio_mode_fw_props[i], &val);
+		if (ret)
+			return ret;
+
+		if (val == AD74115_GPIO_MODE_LOGIC)
+			st->gpio_valid_mask |= BIT(i);
+	}
+
+	for (i = 0; i < AD74115_DIAG_NUM; i++) {
+		val = AD74115_DIAG_FUNC_DISABLED;
+
+		ret = ad74115_parse_fw_prop(st, &ad74115_diag_func_fw_props[i], &val);
+		if (ret)
+			return ret;
+
+		st->diag_func[i] = val;
+
+		if (val != AD74115_DIAG_FUNC_DISABLED)
+			indio_dev->num_channels++;
+	}

drivers/iio/addac/ad74115.c line 1871

Quoted 10 lines
drivers/iio/addac/ad74115.c new file +10 -0
+
+	for (i = 0; i < ARRAY_SIZE(ad74115_fw_props); i++) {
+		const struct ad74115_fw_prop *prop = &ad74115_fw_props[i];
+
+		ret = ad74115_parse_fw_prop(st, prop, &val);
+		if (ret)
+			return ret;
+	}
+
+	ret = ad74115_setup_gc(st);

gc isn't enough to make it obvious to me that this is a gpiochip. I'd use the extra characters to just spell it out. I briefly wondered what garbage collection was doing in here ;)

Quoted 11 lines
drivers/iio/addac/ad74115.c new file +10 -0
+	if (ret)
+		return ret;
+
+	ret = ad74115_setup_comp_gc(st);
+	if (ret)
+		return ret;
+
+	return ad74115_setup_iio_channels(indio_dev);
+}
+