Skip to contentSkip to conversation

Add AD74413R driver

PATCH Superseded Cosmin Tanislav 3 participants 8 messages Nov 26, 2021 – Nov 27, 2021

Subsystems (5)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add AD74413R driver

The AD74412R and AD74413R are quad-channel software configurable input/output solutions for building and process control applications. They contain functionality for analog output, analog input, digital input, resistance temperature detector, and thermocouple measurements integrated into a single chip solution with an SPI interface.
The devices feature a 16-bit ADC and four configurable 13-bit DACs to provide four configurable input/output channels and a suite of diagnostic functions. The AD74413R differentiates itself from the AD74412R by being HART-compatible.

V1 -> V2
* sign off using company email

V2 -> V3
* replace gpo config firmware flag with one flag specifying whether gpo is in comparator mode
* create two separate gpiochips, one output-only for GPO pins not in comparator mode and one input-only for the value of digital input channels
* wire up all gpo functionalities using pinconf
* keep number of characters per line under 80
* rework locking
* do not invalidate other chip revisions
* do not set indio device parent
* print probe error for refin regulator
* move conversion from range register value to range / offset / raw offset into separate function
* module.h -> mod_devicetable.h
* use generic firmware interface functions
* add comment regarding cache alignment
* add comment regarding ADC channels buffered read setup
* un-inline comment regarding 100us delay for conversion start
* inline return statements
* remove assignments to val2 where not necessary
* local_channels -> chans
* index -> i
* channel_config -> config
* IIO_ALTVOLTAGE -> IIO_VOLTAGE
* .info_mask_shared_by_type_available -> .info_mask_separate_available
* remove unlikely probe error messages
* use an array indexed by channel function for retrieving iio channels
* count iio channels while parsing
* move HART rate rejection outside of setter
* move channel function validation outside of setter
* use SPI messages for read and write
* validate DAC code earlier
* simplify switches to only handle existing iio channels
* pass indio_dev into functions needing access to it
* pass spi into devm_regmap_init
* dt-bindings: sort compatibles
* dt-bindings: remove driver word from description
* dt-bindings: remove refin supply description
* dt-bindings: specify channel function default value
* dt-bindings: remove maxItems from scalar value

V3 -> v4
* remove double gpo from macro name
* reset at probe
* config -> chip_info and store chip name inside chip info
* cacheline align every DMA buffer
* simplify generation of adc samples message by caching xfer, tx_buf and rx_buf
* use mask itself for writing the value of channel enable and gpo data
* move reg read and write transfers to the same buffers and use local variables for transfers
* merge the two for loops handling gpio configuration
* let firmware decide irq edge
* remove INDIO_BUFFER_SOFTWARE already set by iio framwork
* do not set trigger device parent
* return dev_err_probe for regulator error case
* do not set cs_change to 0 when not needed
* do not set spi device drvdata as it is not needed
* fix bug regarding wrong channels being created for resistance input, digital input, and current input with hart
* use voltage input channels spec for high impedance mode
* put () around macro parameters
* merge AD74413R_CHANNEL macro into its uses
* remove unused switch case scope
* inline return IIO_VAL_INT
* use {get,put}_unaligned_be16
* use proper types for reg and val
* move default case handling into switch statements
* pass driver state into regmap functions
* use genmask for generating a 16bit max value
* alphanumeric order for part numbers
* dt-bindings: remove $ref from ohms value

V4 -> V5
* dt-bindings: include headers necessary
* dt-bindings: add IRQ_TYPE_EDGE_FALLING to interrupt flags
* dt-bindings: ohm -> ohms
* dt-bindings: spi0 -> spi

V5 -> V6
* fix warnings regarding overflows

Cosmin Tanislav (3):
iio: add adddac subdirectory
dt-bindings: iio: add AD74413R
iio: addac: add AD74413R driver

 .../bindings/iio/addac/adi,ad74413r.yaml      |  157 ++
 MAINTAINERS                                   |    9 +
 drivers/iio/Kconfig                           |    1 +
 drivers/iio/Makefile                          |    1 +
 drivers/iio/addac/Kconfig                     |   20 +
 drivers/iio/addac/Makefile                    |    7 +
 drivers/iio/addac/ad74413r.c                  | 1473 +++++++++++++++++
 include/dt-bindings/iio/addac/adi,ad74413r.h  |   21 +
 8 files changed, 1689 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml
 create mode 100644 drivers/iio/addac/Kconfig
 create mode 100644 drivers/iio/addac/Makefile
 create mode 100644 drivers/iio/addac/ad74413r.c
 create mode 100644 include/dt-bindings/iio/addac/adi,ad74413r.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/3 iio: add adddac subdirectory

From: Cosmin Tanislav <[email protected]>

For IIO devices that expose both ADC and DAC functionality.

---
 drivers/iio/Kconfig        | 1 +
 drivers/iio/Makefile       | 1 +
 drivers/iio/addac/Kconfig  | 8 ++++++++
 drivers/iio/addac/Makefile | 6 ++++++
 4 files changed, 16 insertions(+)
 create mode 100644 drivers/iio/addac/Kconfig
 create mode 100644 drivers/iio/addac/Makefile
drivers/iio/Kconfig +1 -0
index 2334ad249b46..4fb4321a72cb 100644
@@ -70,6 +70,7 @@ config IIO_TRIGGERED_EVENT
 
 source "drivers/iio/accel/Kconfig"
 source "drivers/iio/adc/Kconfig"
+source "drivers/iio/addac/Kconfig"
 source "drivers/iio/afe/Kconfig"
 source "drivers/iio/amplifiers/Kconfig"
 source "drivers/iio/cdc/Kconfig"
drivers/iio/Makefile +1 -0
index 65e39bd4f934..8d48c70fee4d 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o
 
 obj-y += accel/
 obj-y += adc/
+obj-y += addac/
 obj-y += afe/
 obj-y += amplifiers/
 obj-y += buffer/
drivers/iio/addac/Kconfig new file +8 -0
new file mode 100644
index 000000000000..2e64d7755d5e
@@ -0,0 +1,8 @@
+#
+# ADC DAC drivers
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Analog to digital and digital to analog converters"
+
+endmenu
drivers/iio/addac/Makefile new file +6 -0
new file mode 100644
index 000000000000..b888b9ee12da
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for industrial I/O ADDAC drivers
+#
+
+# When adding new entries keep the list in alphabetical order
Signature · 1 line
2.34.1
#2 lore raw

PATCH v6 2/3 dt-bindings: iio: add AD74413R

In reply to Cosmin Tanislav

The AD74412R and AD74413R are quad-channel software configurable input/output solutions for building and process control applications. They contain functionality for analog output, analog input, digital input, resistance temperature detector, and thermocouple measurements integrated into a single chip solution with an SPI interface.
The devices feature a 16-bit ADC and four configurable 13-bit DACs to provide four configurable input/output channels and a suite of diagnostic functions. The AD74413R differentiates itself from the AD74412R by being HART-compatible.

---
 .../bindings/iio/addac/adi,ad74413r.yaml      | 157 ++++++++++++++++++
 include/dt-bindings/iio/addac/adi,ad74413r.h  |  21 +++
 2 files changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml
 create mode 100644 include/dt-bindings/iio/addac/adi,ad74413r.h
Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml new file +157 -0
new file mode 100644
index 000000000000..a6d6b5ef13b3
@@ -0,0 +1,157 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/addac/adi,ad74413r.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD74412R/AD74413R device
+
+maintainers:
+  - Cosmin Tanislav <[email protected]>
+
+description: |
+  The AD74412R and AD74413R are quad-channel software configurable input/output
+  solutions for building and process control applications. They contain
+  functionality for analog output, analog input, digital input, resistance
+  temperature detector, and thermocouple measurements integrated
+  into a single chip solution with an SPI interface.
+  The devices feature a 16-bit ADC and four configurable 13-bit DACs to provide
+  four configurable input/output channels and a suite of diagnostic functions.
+  The AD74413R differentiates itself from the AD74412R by being HART-compatible.
+
+properties:
+  compatible:
+    enum:
+      - adi,ad74412r
+      - adi,ad74413r
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 1000000
+
+  spi-cpol: true
+
+  interrupts:
+    maxItems: 1
+
+  refin-supply: true
+
+  adi,rsense-resistance-ohms:
+    description:
+      RSense resistance values in Ohms.
+
+required:
+  - compatible
+  - reg
+  - spi-max-frequency
+  - spi-cpol
+  - refin-supply
+  - adi,rsense-resistance-ohms
+
+additionalProperties: false
+
+patternProperties:
+  "^channel@[0-3]$":
+    type: object
+    description: Represents the external channels which are connected to the device.
+
+    properties:
+      reg:
+        description: |
+          The channel number. It can have up to 4 channels numbered from 0 to 3.
+        minimum: 0
+        maximum: 3
+
+      adi,ch-func:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description: |
+          Channel function.
+          HART functions are not supported on AD74412R.
+          0 - CH_FUNC_HIGH_IMPEDANCE
+          1 - CH_FUNC_VOLTAGE_OUTPUT
+          2 - CH_FUNC_CURRENT_OUTPUT
+          3 - CH_FUNC_VOLTAGE_INPUT
+          4 - CH_FUNC_CURRENT_INPUT_EXT_POWER
+          5 - CH_FUNC_CURRENT_INPUT_LOOP_POWER
+          6 - CH_FUNC_RESISTANCE_INPUT
+          7 - CH_FUNC_DIGITAL_INPUT_LOGIC
+          8 - CH_FUNC_DIGITAL_INPUT_LOOP_POWER
+          9 - CH_FUNC_CURRENT_INPUT_EXT_POWER_HART
+          10 - CH_FUNC_CURRENT_INPUT_LOOP_POWER_HART
+        minimum: 0
+        maximum: 10
+        default: 0
+
+      adi,gpo-comparator:
+        type: boolean
+        description: |
+          Whether to configure GPO as a comparator or not.
+          When not configured as a comparator, the GPO will be treated as an
+          output-only GPIO.
+
+    required:
+      - reg
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/iio/addac/adi,ad74413r.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      cs-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
+      status = "okay";
+
+      ad74413r@0 {
+        compatible = "adi,ad74413r";
+        reg = <0>;
+        spi-max-frequency = <1000000>;
+        spi-cpol;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupt-parent = <&gpio>;
+        interrupts = <26 IRQ_TYPE_EDGE_FALLING>;
+
+        refin-supply = <&ad74413r_refin>;
+        adi,rsense-resistance-ohms = <100>;
+
+        channel@0 {
+          reg = <0>;
+
+          adi,ch-func = <CH_FUNC_VOLTAGE_OUTPUT>;
+        };
+
+        channel@1 {
+          reg = <1>;
+
+          adi,ch-func = <CH_FUNC_CURRENT_OUTPUT>;
+        };
+
+        channel@2 {
+          reg = <2>;
+
+          adi,ch-func = <CH_FUNC_DIGITAL_INPUT_LOGIC>;
+          adi,gpo-comparator;
+        };
+
+        channel@3 {
+          reg = <3>;
+
+          adi,ch-func = <CH_FUNC_CURRENT_INPUT_EXT_POWER>;
+        };
+      };
+    };
+...
include/dt-bindings/iio/addac/adi,ad74413r.h new file +21 -0
new file mode 100644
index 000000000000..a43b010f974f
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _DT_BINDINGS_ADI_AD74413R_H
+#define _DT_BINDINGS_ADI_AD74413R_H
+
+#define CH_FUNC_HIGH_IMPEDANCE					0x0
+#define CH_FUNC_VOLTAGE_OUTPUT					0x1
+#define CH_FUNC_CURRENT_OUTPUT					0x2
+#define CH_FUNC_VOLTAGE_INPUT					0x3
+#define CH_FUNC_CURRENT_INPUT_EXT_POWER			0x4
+#define CH_FUNC_CURRENT_INPUT_LOOP_POWER		0x5
+#define CH_FUNC_RESISTANCE_INPUT				0x6
+#define CH_FUNC_DIGITAL_INPUT_LOGIC				0x7
+#define CH_FUNC_DIGITAL_INPUT_LOOP_POWER		0x8
+#define CH_FUNC_CURRENT_INPUT_EXT_POWER_HART	0x9
+#define CH_FUNC_CURRENT_INPUT_LOOP_POWER_HART	0xA
+
+#define CH_FUNC_MIN		CH_FUNC_HIGH_IMPEDANCE
+#define CH_FUNC_MAX		CH_FUNC_CURRENT_INPUT_LOOP_POWER_HART
+
+#endif /* _DT_BINDINGS_ADI_AD74413R_H */
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v6 2/3] dt-bindings: iio: add AD74413R

Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml line 49

Quoted 3 lines · Cosmin Tanislav
Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml new file +3 -0
+  adi,rsense-resistance-ohms:
+    description:
+      RSense resistance values in Ohms.

This description is very terse. If it is existing for the same purpose as shunt-resistor-micro-ohms in Documentation/devicetree/bindings/iio/afe/current-sense-shunt.yaml then you should just recycle the standard binding shunt-resistor-micro-ohms instead of inventing this custom one.

Yours,
Linus Walleij

maintainer
#4 lore raw

Re: [PATCH v6 2/3] dt-bindings: iio: add AD74413R

Quoted 11 lines · On Sat, 27 Nov 2021 02:23:26 +0100 Linus Walleij <[email protected]>…

Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml line 49

Quoted 3 lines · Cosmin Tanislav
Documentation/devicetree/bindings/iio/addac/adi,ad74413r.yaml new file +3 -0
+  adi,rsense-resistance-ohms:
+    description:
+      RSense resistance values in Ohms.  

This description is very terse. If it is existing for the same purpose as shunt-resistor-micro-ohms in Documentation/devicetree/bindings/iio/afe/current-sense-shunt.yaml then you should just recycle the standard binding shunt-resistor-micro-ohms instead of inventing this custom one.

Good point. I'd forgotten about that one. We had to make that generic as a current sense shunt inherently doesn't have a vendor :)

Thanks Linus!

Jonathan

Quoted 3 lines

Yours,
Linus Walleij

#5 lore raw

PATCH v6 3/3 iio: addac: add AD74413R driver

In reply to Cosmin Tanislav

The AD74412R and AD74413R are quad-channel software configurable input/output solutions for building and process control applications. They contain functionality for analog output, analog input, digital input, resistance temperature detector, and thermocouple measurements integrated into a single chip solution with an SPI interface.
The devices feature a 16-bit ADC and four configurable 13-bit DACs to provide four configurable input/output channels and a suite of diagnostic functions. The AD74413R differentiates itself from the AD74412R by being HART-compatible.

When configured with channel 0 as voltage output, channel 1 as current output, channel 2 as voltage input and channel 3 as current input, the following structure is created under the corresponding IIO device.

.

├── in_current0_offset
├── in_current0_raw
├── in_current0_sampling_frequency
├── in_current0_sampling_frequency_available
├── in_current0_scale
├── in_voltage1_offset
├── in_voltage1_raw
├── in_voltage1_sampling_frequency
├── in_voltage1_sampling_frequency_available
├── in_voltage1_scale
├── in_voltage2_offset
├── in_voltage2_raw
├── in_voltage2_sampling_frequency
├── in_voltage2_sampling_frequency_available
├── in_voltage2_scale
├── in_current3_offset
├── in_current3_raw
├── in_current3_sampling_frequency
├── in_current3_sampling_frequency_available
├── in_current3_scale
├── out_voltage0_raw
├── out_voltage0_scale
├── out_current1_raw
├── out_current1_scale
├── name
├── buffer
│   ├── data_available
│   ├── enable
│   ├── length
│   └── watermark
└── scan_elements
    ├── in_current0_en
    ├── in_current0_index
    ├── in_current0_type
    ├── in_voltage1_en
    ├── in_voltage1_index
    ├── in_voltage1_type
    ├── in_voltage2_en
    ├── in_voltage2_index
    ├── in_voltage2_type
    ├── in_current3_en
    ├── in_current3_index
    └── in_current3_type
---
 MAINTAINERS                  |    9 +
 drivers/iio/addac/Kconfig    |   12 +
 drivers/iio/addac/Makefile   |    1 +
 drivers/iio/addac/ad74413r.c | 1473 ++++++++++++++++++++++++++++++++++
 4 files changed, 1495 insertions(+)
 create mode 100644 drivers/iio/addac/ad74413r.c
MAINTAINERS +9 -0
index 7a2345ce8521..ed13c5efeb4f 100644
@@ -1069,6 +1069,15 @@ W:	http://ez.analog.com/community/linux-device-drivers
 F:	Documentation/devicetree/bindings/iio/adc/adi,ad7780.yaml
 F:	drivers/iio/adc/ad7780.c
 
+ANALOG DEVICES INC AD74413R 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,ad74413r.yaml
+F:	drivers/iio/addac/ad74413r.c
+F:	include/dt-bindings/iio/addac/adi,ad74413r.h
+
 ANALOG DEVICES INC AD9389B DRIVER
 M:	Hans Verkuil <[email protected]>
 L:	[email protected]
drivers/iio/addac/Kconfig +12 -0
index 2e64d7755d5e..138492362f20 100644
@@ -5,4 +5,16 @@
 
 menu "Analog to digital and digital to analog converters"
 
+config AD74413R
+	tristate "Analog Devices AD74412R/AD74413R driver"
+	depends on GPIOLIB && SPI
+	select REGMAP_SPI
+	select CRC8
+	help
+	  Say yes here to build support for Analog Devices AD74412R/AD74413R
+	  quad-channel software configurable input/output solution.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ad74413r.
+
 endmenu
drivers/iio/addac/Makefile +1 -0
index b888b9ee12da..cfd4bbe64ad3 100644
@@ -4,3 +4,4 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_AD74413R) += ad74413r.o
drivers/iio/addac/ad74413r.c new file +1473 -0

1,473 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v6 3/3] iio: addac: add AD74413R driver

Hi Cosmin,

thanks for your patch!

I noticed this has a GPIO chip inside of it :)

On Fri, Nov 26, 2021 at 5:03 PM Cosmin Tanislav <[email protected]> wrote:

These:

Quoted 9 lines
drivers/iio/addac/ad74413r.c new file +9 -0
+static void ad74413r_gpio_set(struct gpio_chip *chip,
+                             unsigned int offset, int val)
+static void ad74413r_gpio_set_multiple(struct gpio_chip *chip,
+                                      unsigned long *mask,
+                                      unsigned long *bits)
+static int ad74413r_gpio_get(struct gpio_chip *chip, unsigned int offset)
+static int ad74413r_gpio_get_multiple(struct gpio_chip *chip,
+                                     unsigned long *mask,
+                                     unsigned long *bits)

(...)

Quoted 20 lines
drivers/iio/addac/ad74413r.c new file +20 -0
+       if (st->num_gpo_gpios) {
+               st->gpo_gpiochip.owner = THIS_MODULE;
+               st->gpo_gpiochip.label = st->chip_info->name;
+               st->gpo_gpiochip.base = -1;
+               st->gpo_gpiochip.ngpio = st->num_gpo_gpios;
+               st->gpo_gpiochip.parent = st->dev;
+               st->gpo_gpiochip.can_sleep = true;
+               st->gpo_gpiochip.set = ad74413r_gpio_set;
+               st->gpo_gpiochip.set_multiple = ad74413r_gpio_set_multiple;
+               st->gpo_gpiochip.set_config = ad74413r_gpio_set_gpo_config;
+               st->gpo_gpiochip.get_direction =
+                       ad74413r_gpio_get_gpo_direction;
+
+               ret = devm_gpiochip_add_data(st->dev, &st->gpo_gpiochip, st);
+               if (ret)
+                       return ret;
+       }
+
+       if (st->num_comparator_gpios) {
+               st->comp_gpiochip.owner = THIS_MODULE;

drivers/iio/addac/ad74413r.c line 1396

Quoted 10 lines
drivers/iio/addac/ad74413r.c new file +10 -0
+               st->comp_gpiochip.label = st->chip_info->name;
+               st->comp_gpiochip.base = -1;
+               st->comp_gpiochip.ngpio = st->num_comparator_gpios;
+               st->comp_gpiochip.parent = st->dev;
+               st->comp_gpiochip.can_sleep = true;
+               st->comp_gpiochip.get = ad74413r_gpio_get;
+               st->comp_gpiochip.get_multiple = ad74413r_gpio_get_multiple;
+               st->comp_gpiochip.set_config = ad74413r_gpio_set_comp_config;
+               st->comp_gpiochip.get_direction =
+                       ad74413r_gpio_get_comp_direction;

Look a bit like the generic drivers/gpio/gpio-regmap.c GPIO_REGMAP.

Example:
drivers/gpio/gpio-sl28cpld.c
drivers/pinctrl/bcm/pinctrl-bcm63xx.c

Or is it too particular for this?

I don't know if the regmap gpio can deal with adding a few functions like a custom .set_config() on top of the templates to be honest, maybe that is something we can fix in that case?

Cc ing Michael Walle so he can pitch in if I'm onto something here or not.

Anyways the GPIO portions look good otherwise.

Yours,
Linus Walleij

maintainer
#7 lore raw

Re: [PATCH v6 3/3] iio: addac: add AD74413R driver

In reply to Cosmin Tanislav
Quoted 9 lines · On Fri, 26 Nov 2021 18:02:19 +0200 Cosmin Tanislav <[email protected]>…

The AD74412R and AD74413R are quad-channel software configurable input/output solutions for building and process control applications. They contain functionality for analog output, analog input, digital input, resistance temperature detector, and thermocouple measurements integrated into a single chip solution with an SPI interface.
The devices feature a 16-bit ADC and four configurable 13-bit DACs to provide four configurable input/output channels and a suite of diagnostic functions. The AD74413R differentiates itself from the AD74412R by being HART-compatible.

Quoted 3 lines

When configured with channel 0 as voltage output, channel 1 as current output, channel 2 as voltage input and channel 3 as current input, the following structure is created under the corresponding IIO device.

Thanks for the example. This definitely helps.

Quoted 5 lines

.

├── in_current0_offset
├── in_current0_raw
├── in_current0_sampling_frequency

The sampling frequency per channel is a bit unusual, but oddly enough that is how it is documented even when in sequence mode. So I guess we should just live with it being strange... Obviously the actual sampling frequency will be lower because we'll be measuring other things between each reading of this channel. Oh well. odd :)

Quoted 41 lines
├── in_current0_sampling_frequency_available
├── in_current0_scale
├── in_voltage1_offset
├── in_voltage1_raw
├── in_voltage1_sampling_frequency
├── in_voltage1_sampling_frequency_available
├── in_voltage1_scale
├── in_voltage2_offset
├── in_voltage2_raw
├── in_voltage2_sampling_frequency
├── in_voltage2_sampling_frequency_available
├── in_voltage2_scale
├── in_current3_offset
├── in_current3_raw
├── in_current3_sampling_frequency
├── in_current3_sampling_frequency_available
├── in_current3_scale
├── out_voltage0_raw
├── out_voltage0_scale
├── out_current1_raw
├── out_current1_scale
├── name
├── buffer
│   ├── data_available
│   ├── enable
│   ├── length
│   └── watermark
└── scan_elements
    ├── in_current0_en
    ├── in_current0_index
    ├── in_current0_type
    ├── in_voltage1_en
    ├── in_voltage1_index
    ├── in_voltage1_type
    ├── in_voltage2_en
    ├── in_voltage2_index
    ├── in_voltage2_type
    ├── in_current3_en
    ├── in_current3_index
    └── in_current3_type
Quoted 1 line

Unless I'm missing something, you are being overly cautious with the DMA buffer alignments. Forcing that for the first one only should be enough.

Quoted 26 lines
drivers/iio/addac/ad74413r.c new file +26 -0
+};
+
+struct ad74413r_state {
+	struct ad74413r_channel_config	channel_configs[AD74413R_CHANNEL_MAX];
+	unsigned int			gpo_gpio_offsets[AD74413R_CHANNEL_MAX];
+	unsigned int			comp_gpio_offsets[AD74413R_CHANNEL_MAX];
+	struct gpio_chip		gpo_gpiochip;
+	struct gpio_chip		comp_gpiochip;
+	struct mutex			lock;
+	struct completion		adc_data_completion;
+	unsigned int			num_gpo_gpios;
+	unsigned int			num_comparator_gpios;
+	u32				rsense_resistance_ohms;
+
+	const struct ad74413r_chip_info	*chip_info;
+	struct spi_device		*spi;
+	struct regulator		*refin_reg;
+	struct regmap			*regmap;
+	struct device			*dev;
+	struct iio_trigger		*trig;
+
+	size_t			adc_active_channels;
+	struct spi_message	adc_samples_msg;
+	struct spi_transfer	adc_samples_xfer[AD74413R_CHANNEL_MAX + 1];
+
+	/*

drivers/iio/addac/ad74413r.c line 84

Quoted 10 lines
drivers/iio/addac/ad74413r.c new file +10 -0
+	 * DMA (thus cache coherency maintenance) requires the
+	 * transfer buffers to live in their own cache lines.
+	 */
+	struct {
+		u8 rx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX];
+		s64 timestamp;
+	} adc_samples_buf ____cacheline_aligned;
+
+	u8	adc_samples_tx_buf[AD74413R_FRAME_SIZE * AD74413R_CHANNEL_MAX]
+			____cacheline_aligned;

I'm surprised I didn't mention this before but you only need to ensure that any memory used for DMA is not in a cacheline with memory used for other things that might change concurrently.

I'm assuming there is only one DMA transaction going on to one piece of hardwre here so you should be fine with just forcing the alignment of adc_samples_buf to be ____cacheline_aligned. That will ensure non of these DMA buffers share a line with anything other than each other.

To give the short explanation of why we jump through these hoops.

1) DMA transfer started - it grabs a whole cacheline because that is how this particular platform works (even if it is doing DMA to just one byte)
2) A flag or similar is updated in the same cacheline.
3) The DMA transfer ends and the cacheline is entirely overwritten with the data from the DAM and whatever was grabbed in step 1.

So as long as we are only dealing with buffers in the same DMA transaction it will be safe for them to share cachelines.

Note that we play games with the alignment of iio_priv() region at allocation to ensure that is appropriately aligned, such that when we align an element within it the alignment ends up right as well. This case was so common it was worth the 'magic' handling to ensure we could embed DMA buffers.

Quoted 3 lines
drivers/iio/addac/ad74413r.c new file +3 -0
+	u8	reg_tx_buf[AD74413R_FRAME_SIZE] ____cacheline_aligned;
+	u8	reg_rx_buf[AD74413R_FRAME_SIZE] ____cacheline_aligned;
+};