Skip to contentSkip to conversation

iio: adc: Add TI ADS126X ADC family support

PATCH Superseded Kurt Borja 3 participants 41 messages Jun 28 – Jul 26

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kurt Borja

author
#0 lore raw

v2 cover iio: adc: Add TI ADS126X ADC family support

Hi all,

This series introduces support for TI ADS1262 and ADS1263 ADCs [1]. These devices are very similar (if not the same), except ADS1263 includes a secondary auxiliary ADC.

I plan to add these features to the main driver soon:

- Automatic calibration
- GPIO controller capabilities
- Channel hot-reloading in buffer mode
- SPI offload support (38400 SPS turns out to be too high for some systems)
- User triggered, automatic calibration (Datasheet 9.4.9)

Additionally, full support for the (less capable) auxiliary ADC is introduced by the auxiliary ti-ads1263-adc2 driver included in this series.

The auxiliary ADC operates almost completely independent of the main ADC. The only consideration that has to be taken for interoperability is when reading conversion data in direct mode (Datasheet 9.4.7.1), which happens only in buffer mode, when multiple channels are enabled.

When reading data in direct mode, all SPI activity is forbidden between the data-ready signal and the data retrieval. To achieve this a second mutex called xfer_lock was introduced to block SPI activity on the device.

This is one of the biggest drivers I've developed, so I hope the code and the comments are self-explainatory. If not, please let me know so I can clarify them.

As always, thanks for your reviews and help. Submitting upstream is always a great learning experience :)

[1] https://www.ti.com/lit/ds/symlink/ads1263.pdf

---
v2:
dt-bindings
-----------

- ADS1262/ADS1263 now use a fallback compatible ("ti,ads1263", "ti,ads1262") instead of two independent compatibles, as the ADS1263 is a strict superset of the ADS1262.

- Reworked dt-bindings keeping up with the latest discussion around per-channel IDAC and reference source selection. Reference source and excitation (IDAC) configuration moved from device-level properties to per-channel properties:
- ti,pos-refmux/ti,neg-refmux -> per-channel "reference-sources"
- ti,idac{1,2}-pin -> per-channel "excitation-channels"
- ti,idac{1,2}-microamp -> per-channel "excitation-current-nanoamp"
- ti,sbias-polarity -> ti,burn-out-polarity
- ti,sbias-magnitude -> burn-out-current-nanoamp
- ti,sbias-connection removed, maybe user-space should handle that

- Split the single "vref-supply" into "refp-supply" and "refn-supply".

- Renamed "ti,chop-mode" -> "ti,input-chopping" and

    "ti,idac-rotation-mode" -> "ti,idac-chopping".

- Dropped "ti,rev-vref-pol"; reference polarity reversal is now handled automatically by the driver based on refp/refn voltages.

- "#io-channel-cells" is now per-compatible to address the auxiliary ADC.

- Dropped the "adc" sub-node and the separate ti,ads1263-adc2.yaml binding.

ti-ads1262
----------

- Split the main driver to make review easier.

- Simplified the series a bit (I'll submit them later):
- Removed runtime PM support.
- Removed gpiochip support.
- Removed channel hot-reloading.
- Removed manual calibration support.

- Reworked ads1262_channel struct to avoid bitfields.

- Reworked firmware parsing and added easy to grep error messages.

- Reference polarity reversal (MODE0 REFREV) is now applied automatically when refp < refn.

- Reorganized registers and bitfield masks with indentantion. Moved bitfield values to enums.

- Removed union in DMA aligned rx buffer.

- Reworked the buffer/SPI transfer model.

- The regmap_bus callbacks now copy regs and values into DMA safe buffers before transfer.

- Now channels in direct mode are enabled with regmap as latency is not that big of a deal in this mode.

- Added per-channel IDAC and reference source configuration. Scale is now computed from the per-channel reference source (internal 2.5 V, external refp/refn, or AVDD-AVSS).

- Removed sensor bias (burn-out current) handling, as we are still discussing the approach for it.

ti-ads1263-adc2
---------------

- Dropped callbacks in favor of exported (TI_ADS1262 namespace) functions

- Dropped channel hot-reloading

- The auxiliary device is now instantiated with an explicit device link and inherits the parent's OF node; scale/reference handling moved to the parent driver.

v1: https://patch.msgid.link/[email protected]

---
Kurt Borja (7):
dt-bindings: iio: adc: Add TI ADS126x ADC family
iio: adc: Add ti-ads1262 driver
iio: adc: ti-ads1262: Add channel filter support
iio: adc: ti-ads1262: Add excitation current support
iio: adc: ti-ads1262: Add conversion delay support
iio: adc: ti-ads1262: Add buffer and trigger support
iio: adc: Add ti-ads1263-adc2 driver

 .../devicetree/bindings/iio/adc/ti,ads1262.yaml    |  309 ++++
 MAINTAINERS                                        |    9 +
 drivers/iio/adc/Kconfig                            |   27 +
 drivers/iio/adc/Makefile                           |    2 +
 drivers/iio/adc/ti-ads1262.c                       | 1835 ++++++++++++++++++++
 drivers/iio/adc/ti-ads1262.h                       |   39 +
 drivers/iio/adc/ti-ads1263-adc2.c                  |  379 ++++
 7 files changed, 2600 insertions(+)

---
base-commit: 7667a80340e99fd45357d0c90ae05813b01bbfef
change-id: 20251129-ads126x-fb6107505cae
prerequisite-change-id: 20260514-iio-adc-ti-ads122c14-d0b92479334e:v2
prerequisite-patch-id: 8be45fbe0c6037e775f6ef0e028184403241866c
prerequisite-patch-id: e76673f5e60ebd0a47584756cbcd297cb87d74b7
prerequisite-patch-id: 7eb0e6028d5a49d311e373be866ebae8e83a523a
prerequisite-patch-id: d5c4c4c78f42e6c0b4f186f1ab7f51aa6acd3561
prerequisite-patch-id: ee187ef4a7632cab6bc76c0588c8e2002ac26b7b
prerequisite-patch-id: 31ce1bee6d2c97f43df79c44e5386bf88a9a5d98
prerequisite-patch-id: 3ec60d0638598ef8d006c12a3a8dece2d6bdc54b
prerequisite-patch-id: bbfa2e76f94d06b60e3458dab448579c627225ea

Signature · 2 lines
Thanks, 
 ~ Kurt
author
#1 lore raw

PATCH v2 1/7 dt-bindings: iio: adc: Add TI ADS126x ADC family

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

Each can configure it's own voltage reference source, the two excitation current sources (IDAC), plus input and excitation channels rotation for offset and IDAC mismatch cancellation. This lets the device drive and ratiometrically measure RTDs and other resistive sensors.

---
 .../devicetree/bindings/iio/adc/ti,ads1262.yaml    | 309 +++++++++++++++++++++
 MAINTAINERS                                        |   6 +
 2 files changed, 315 insertions(+)
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +309 -0
new file mode 100644
index 0000000000000000..2f4e812ae2af135a
@@ -0,0 +1,309 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1262.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI ADS1262/ADS1263 analog to digital converter
+
+maintainers:
+  - Kurt Borja <[email protected]>
+
+description: |
+  The ADS1262 and ADS1263 are 38.4-kSPS, delta-sigma (ΔΣ) ADCs with an
+  integrated PGA, reference, and internal fault monitors. The ADS1263 integrates
+  an auxiliary, 24-bit, ΔΣ ADC intended for background measurements.
+
+  Datasheets:
+    - ADS126x: https://www.ti.com/lit/ds/symlink/ads1262.pdf
+
+properties:
+  compatible:
+    oneOf:
+      - const: ti,ads1262
+      - items:
+          - const: ti,ads1263
+          - const: ti,ads1262
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 8000000
+
+  spi-cpha: true
+
+  interrupts:
+    description: Data ready (DRDY) interrupt line.
+    maxItems: 1
+
+  start-gpios:
+    description: Start conversion control.
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  dvdd-supply:
+    description: Digital power supply.
+
+  avdd-supply:
+    description: Analog power supply.
+
+  refp-supply:
+    description: External positive voltage reference.
+
+  refn-supply:
+    description: External negative voltage reference.
+
+  ti,vbias:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: Enables the level-shift voltage on the AINCOM pin.
+
+  clocks:
+    maxItems: 1
+
+  '#io-channel-cells':
+    minimum: 1
+    maximum: 2
+
+  '#gpio-cells':
+    const: 2
+
+  gpio-controller: true
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+
+      diff-channels:
+        description: |
+          Selects the analog input configuration for this channel. The first
+          value is the positive input and the second is the negative input.
+          The following values are available:
+          0: AIN0 pin
+          1: AIN1 pin
+          2: AIN2 pin
+          3: AIN3 pin
+          4: AIN4 pin
+          5: AIN5 pin
+          6: AIN6 pin
+          7: AIN7 pin
+          8: AIN8 pin
+          9: AIN9 pin
+          10: AINCOM pin
+          11: Temperature sensor monitor
+          12: Analog power supply monitor
+          13: Digital power supply monitor
+          14: TDAC test signal
+          15: Float (open connection)
+        items:
+          minimum: 0
+          maximum: 15
+
+      reference-sources:
+        minItems: 2
+        description:
+          Indicates the reference sources for this channel. The first and second
+          items are the positive and negative sources of the main ADC (ADC1).
+          The third item is the reference source of the secondary ADC (ADC2).
+        items:
+          - enum: [internal, ain0, ain2, ain4, avdd]
+          - enum: [internal, ain1, ain3, ain5, avss]
+          - enum: [internal, ain0-ain1, ain2-ain3, ain4-ain5, avdd-avss]
+
+      excitation-channels:
+        $ref: /schemas/types.yaml#/definitions/uint32-array
+        minItems: 2
+        maxItems: 2
+        description: |
+          Selects pins for the IDAC sources from the following options:
+            0: AIN0
+            1: AIN1
+            2: AIN2
+            3: AIN3
+            4: AIN4
+            5: AIN5
+            6: AIN6
+            7: AIN7
+            8: AIN8
+            9: AIN9
+            10: AINCOM
+            11: No Connection
+          The first value corresponds to IDAC1 and the second to IDAC2.
+        items:
+          minimum: 0
+          maximum: 11
+
+      excitation-current-nanoamp:
+        minItems: 2
+        maxItems: 2
+        description:
+          The first value corresponds to IDAC1 and the second to IDAC2.
+        items:
+          enum: [0, 50000, 100000, 250000, 500000, 750000, 1000000, 1500000,
+                 2000000, 2500000, 3000000]
+
+      burn-out-current-nanoamp:
+        description:
+          The ADC incorporates a sensor bias current source that can be used to
+          apply a small test current to diagnose broken sensor leads or problems
+          existing in the sensor.
+        enum: [0, 500, 2000, 10000, 50000, 200000]
+
+      ti,burn-out-resistor:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: |
+          Instead of a fixed current, the sensor bias (burn-out) current source
+          can be pulled using an internal 10 MΩ resistor.
+
+      ti,burn-out-polarity:
+        $ref: /schemas/types.yaml#/definitions/string
+        description:
+          The sensor bias can be configured to either pull-up or pull-down mode.
+          In pull-up mode, the current flows into the positive input and flows
+          out of the negative input. In pull-down mode, the polarities are
+          reversed.
+        enum: [pull-up, pull-down]
+
+      input-chopping:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          When enabled, the ADC performs two internal conversions to cancel the
+          input offset voltage. The first conversion is taken with normal input
+          polarity. The ADC reverses the internal input polarity for the second
+          conversion. The difference of the two conversions is computed to yield
+          the final corrected result with the offset voltage removed.
+
+      ti,idac-chopping:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          Automatically swap the IDAC1 and IDAC2 connections of alternate
+          conversions. The ADC averages the alternate conversions to eliminate
+          IDAC mismatch.
+
+      ti,pga-bypass:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: Bypass the Programmable Gain Amplifier (PGA).
+
+    dependencies:
+      excitation-channels: [excitation-current-nanoamp]
+      excitation-current-nanoamp: [excitation-channels]
+      burn-out-current-nanoamp:
+        not:
+          required:
+            - ti,burn-out-resistor
+
+    required:
+      - reg
+
+dependencies:
+  refn-supply: [refp-supply]
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - dvdd-supply
+  - '#address-cells'
+  - '#size-cells'
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: ti,ads1263
+    then:
+      properties:
+        '#io-channel-cells':
+          const: 2
+      patternProperties:
+        "^channel@[0-9]+$":
+          properties:
+            reference-sources:
+              minItems: 3
+    else:
+      properties:
+        '#io-channel-cells':
+          const: 1
+      patternProperties:
+        "^channel@[0-9]+$":
+          properties:
+            reference-sources:
+              maxItems: 2
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "ti,ads1262";
+            reg = <0>;
+            spi-max-frequency = <8000000>;
+            spi-cpha;
+            avdd-supply = <&avdd>;
+            dvdd-supply = <&dvdd>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&gpio 10 IRQ_TYPE_EDGE_FALLING>;
+
+            channel@0 {
+                reg = <0>;
+                diff-channels = <0x0 0xA>;
+            };
+        };
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "ti,ads1263", "ti,ads1262";
+            reg = <0>;
+            spi-max-frequency = <8000000>;
+            spi-cpha;
+            avdd-supply = <&avdd>;
+            dvdd-supply = <&dvdd>;
+            refp-supply = <&refp>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&gpio 10 IRQ_TYPE_EDGE_FALLING>;
+
+            channel@0 {
+                reg = <0>;
+                diff-channels = <0x4 0x5>;
+                reference-sources = "ain2", "ain3", "ain2-ain3";
+                excitation-channels = <0x1 0x6>;
+                excitation-current-nanoamp = <500000 500000>;
+            };
+        };
+    };
MAINTAINERS +6 -0
index 6c0471487974f145..9b83d294734b574d 100644
@@ -26923,6 +26923,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/ti,ads1018.yaml
 F:	drivers/iio/adc/ti-ads1018.c
 
+TI ADS1262 ADC DRIVER
+M:	Kurt Borja <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml
+
 TI ADS7924 ADC DRIVER
 M:	Hugo Villeneuve <[email protected]>
 L:	[email protected]
Signature · 1 line
2.54.0
reviewer
#2 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 56 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

Each can configure it's own voltage reference source, the two excitation current sources (IDAC), plus input and excitation channels rotation for offset and IDAC mismatch cancellation. This lets the device drive and ratiometrically measure RTDs and other resistive sensors.

---
 .../devicetree/bindings/iio/adc/ti,ads1262.yaml    | 309 +++++++++++++++++++++
 MAINTAINERS                                        |   6 +
 2 files changed, 315 insertions(+)
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +34 -0
new file mode 100644
index 0000000000000000..2f4e812ae2af135a
@@ -0,0 +1,309 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1262.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI ADS1262/ADS1263 analog to digital converter
+
+maintainers:
+  - Kurt Borja <[email protected]>
+
+description: |
+  The ADS1262 and ADS1263 are 38.4-kSPS, delta-sigma (ΔΣ) ADCs with an
+  integrated PGA, reference, and internal fault monitors. The ADS1263 integrates
+  an auxiliary, 24-bit, ΔΣ ADC intended for background measurements.
+
+  Datasheets:
+    - ADS126x: https://www.ti.com/lit/ds/symlink/ads1262.pdf
+
+properties:
+  compatible:
+    oneOf:
+      - const: ti,ads1262
+      - items:
+          - const: ti,ads1263
+          - const: ti,ads1262
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+    const: 0
+
+  spi-max-frequency:
+    maximum: 8000000
+
+  spi-cpha: true
+
+  interrupts:
+    description: Data ready (DRDY) interrupt line.
+    maxItems: 1

Technically, there are two pins with the DRDY signal, so we should have two interrupts in order to be able to tell which one is wired up.

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+  start-gpios:
+    description: Start conversion control.
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  dvdd-supply:
+    description: Digital power supply.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+  avdd-supply:
+    description: Analog power supply.
+
+  refp-supply:
+    description: External positive voltage reference.
+
+  refn-supply:
+    description: External negative voltage reference.
+

Which pins are these? I see 4 possible external reference sources, but all go through the AINx pins. So I would expect:

refp1-supply, refn1-supply, refp2-supply, refn2-supply, refp3-supply, refn3-supply, refp4-supply, refn4-supply

Also, similar to the chip I am working on, I expect that these pins could be connected to a resistor rather than a voltage source, so could use additional bindings for that.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 67

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +3 -0
+  ti,vbias:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: Enables the level-shift voltage on the AINCOM pin.

VBIAS is a voltage source, so I would expect that to be modeled as a regulator provider. (If we do that REFOUT should be included as well.)

Quoted 12 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +12 -0
+
+  clocks:
+    maxItems: 1
+
+  '#io-channel-cells':
+    minimum: 1
+    maximum: 2
+
+  '#gpio-cells':
+    const: 2
+
+  gpio-controller: true

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +11 -0
+      diff-channels:
+        description: |
+          Selects the analog input configuration for this channel. The first
+          value is the positive input and the second is the negative input.
+          The following values are available:
+          0: AIN0 pin
+          1: AIN1 pin
+          2: AIN2 pin
+          3: AIN3 pin
+          4: AIN4 pin
+          5: AIN5 pin

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 109

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +9 -0
+          6: AIN6 pin
+          7: AIN7 pin
+          8: AIN8 pin
+          9: AIN9 pin
+          10: AINCOM pin
 
+          11: Temperature sensor monitor
+          12: Analog power supply monitor
+          13: Digital power supply monitor
+          14: TDAC test signal

These are all internal signals, so not sure it makes sense to have them in the devicetree. It would make more sense to have fixed channels defined in the driver for these since they are always there.

We probably also need a separate property (a bool/flag?) to say that this channel is a TDAC output rather than an analog input. Although that is for testing, so maybe something to omit for now until we actually have an application that uses it (to make sure we get it right)?

Quoted 1 line

+ 15: Float (open connection)

How could we have a differential input with one or both pins open? Likely this will just be the setting for pins not specified as something else in the devicetree.

Quoted 8 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +8 -0
+        items:
+          minimum: 0
+          maximum: 15
+
+      reference-sources:
+        minItems: 2
+        description:
+          Indicates the reference sources for this channel. The first and second

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 128

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+          items are the positive and negative sources of the main ADC (ADC1).
+          The third item is the reference source of the secondary ADC (ADC2).
+        items:
+          - enum: [internal, ain0, ain2, ain4, avdd]
+          - enum: [internal, ain1, ain3, ain5, avss]
+          - enum: [internal, ain0-ain1, ain2-ain3, ain4-ain5, avdd-avss]
+
+      excitation-channels:
+        $ref: /schemas/types.yaml#/definitions/uint32-array
+        minItems: 2

minItems should be 1 since there are applications that only use one current source.

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +5 -0
+        maxItems: 2
+        description: |
+          Selects pins for the IDAC sources from the following options:
+            0: AIN0
+            1: AIN1

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 143

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+            2: AIN2
+            3: AIN3
+            4: AIN4
+            5: AIN5
+            6: AIN6
+            7: AIN7
+            8: AIN8
+            9: AIN9
+            10: AINCOM
+            11: No Connection

Having a value for "no connection" doesn't make sense. We would just omit the property or only have one item in the array.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 156

Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +13 -0
+          The first value corresponds to IDAC1 and the second to IDAC2.
+        items:
+          minimum: 0
+          maximum: 11
+
+      excitation-current-nanoamp:
+        minItems: 2
+        maxItems: 2
+        description:
+          The first value corresponds to IDAC1 and the second to IDAC2.
+        items:
+          enum: [0, 50000, 100000, 250000, 500000, 750000, 1000000, 1500000,
+                 2000000, 2500000, 3000000]

In the chip I am working on, I left out 0 with the intention that we would just omit the property in that case. If we do include 0, then we should also have default: 0. Not sure which way would be preferred by others though.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 162

Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +6 -0
+
+      burn-out-current-nanoamp:
+        description:
+          The ADC incorporates a sensor bias current source that can be used to
+          apply a small test current to diagnose broken sensor leads or problems
+          existing in the sensor.

This description doesn't add anything that adc.yaml doesn't already say, so can be omitted.

Quoted 1 line

+ enum: [0, 500, 2000, 10000, 50000, 200000]

Same thing here about 0 value.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 167

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +4 -0
+
+      ti,burn-out-resistor:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: |

Don't see a reason to need | here.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 178

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +11 -0
+          Instead of a fixed current, the sensor bias (burn-out) current source
+          can be pulled using an internal 10 MΩ resistor.
+
+      ti,burn-out-polarity:
+        $ref: /schemas/types.yaml#/definitions/string
+        description:
+          The sensor bias can be configured to either pull-up or pull-down mode.
+          In pull-up mode, the current flows into the positive input and flows
+          out of the negative input. In pull-down mode, the polarities are
+          reversed.
+        enum: [pull-up, pull-down]

Needs a default.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 189

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +11 -0
+
+      input-chopping:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          When enabled, the ADC performs two internal conversions to cancel the
+          input offset voltage. The first conversion is taken with normal input
+          polarity. The ADC reverses the internal input polarity for the second
+          conversion. The difference of the two conversions is computed to yield
+          the final corrected result with the offset voltage removed.
+
+      ti,idac-chopping:

I would call this ti,excitation-channel-chopping to match the excitation-channel property. Or since this isn't a generic property, call it ti,idac-rotation to match the datasheet.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 198

Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +9 -0
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          Automatically swap the IDAC1 and IDAC2 connections of alternate
+          conversions. The ADC averages the alternate conversions to eliminate
+          IDAC mismatch.
+
+      ti,pga-bypass:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: Bypass the Programmable Gain Amplifier (PGA).

Why would this need to be a DT property? I didn't read this datasheet too much, but in other chips I have seen there are usually rules that PGA has to be bypassed under certain conditions, but not others, so this seems like something for the driver to handle rather than the devicetree.

Quoted 66 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +66 -0
+
+    dependencies:
+      excitation-channels: [excitation-current-nanoamp]
+      excitation-current-nanoamp: [excitation-channels]
+      burn-out-current-nanoamp:
+        not:
+          required:
+            - ti,burn-out-resistor
+
+    required:
+      - reg
+
+dependencies:
+  refn-supply: [refp-supply]
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+  - dvdd-supply
+  - '#address-cells'
+  - '#size-cells'
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: ti,ads1263
+    then:
+      properties:
+        '#io-channel-cells':
+          const: 2
+      patternProperties:
+        "^channel@[0-9]+$":
+          properties:
+            reference-sources:
+              minItems: 3
+    else:
+      properties:
+        '#io-channel-cells':
+          const: 1
+      patternProperties:
+        "^channel@[0-9]+$":
+          properties:
+            reference-sources:
+              maxItems: 2
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "ti,ads1262";
+            reg = <0>;
+            spi-max-frequency = <8000000>;
+            spi-cpha;
+            avdd-supply = <&avdd>;

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 274

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+            dvdd-supply = <&dvdd>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&gpio 10 IRQ_TYPE_EDGE_FALLING>;
+
+            channel@0 {
+                reg = <0>;
+                diff-channels = <0x0 0xA>;

I would just use decimal instead of hex for these. That is how they are listed in the description anyway.

Quoted 53 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +35 -0
+            };
+        };
+    };
+
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "ti,ads1263", "ti,ads1262";
+            reg = <0>;
+            spi-max-frequency = <8000000>;
+            spi-cpha;
+            avdd-supply = <&avdd>;
+            dvdd-supply = <&dvdd>;
+            refp-supply = <&refp>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&gpio 10 IRQ_TYPE_EDGE_FALLING>;
+
+            channel@0 {
+                reg = <0>;
+                diff-channels = <0x4 0x5>;
+                reference-sources = "ain2", "ain3", "ain2-ain3";
+                excitation-channels = <0x1 0x6>;
+                excitation-current-nanoamp = <500000 500000>;
+            };
+        };
+    };
MAINTAINERS +6 -0
index 6c0471487974f145..9b83d294734b574d 100644
@@ -26923,6 +26923,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/ti,ads1018.yaml
 F:	drivers/iio/adc/ti-ads1018.c
 
+TI ADS1262 ADC DRIVER
+M:	Kurt Borja <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml
+
 TI ADS7924 ADC DRIVER
 M:	Hugo Villeneuve <[email protected]>
 L:	[email protected]
author
#3 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 62 lines · David Lechner
Quoted 61 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

Each can configure it's own voltage reference source, the two excitation current sources (IDAC), plus input and excitation channels rotation for offset and IDAC mismatch cancellation. This lets the device drive and ratiometrically measure RTDs and other resistive sensors.

---
 .../devicetree/bindings/iio/adc/ti,ads1262.yaml    | 309 +++++++++++++++++++++
 MAINTAINERS                                        |   6 +
 2 files changed, 315 insertions(+)
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +39 -0
new file mode 100644
index 0000000000000000..2f4e812ae2af135a
@@ -0,0 +1,309 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/ti,ads1262.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI ADS1262/ADS1263 analog to digital converter
+
+maintainers:
+  - Kurt Borja <[email protected]>
+
+description: |
+  The ADS1262 and ADS1263 are 38.4-kSPS, delta-sigma (ΔΣ) ADCs with an
+  integrated PGA, reference, and internal fault monitors. The ADS1263 integrates
+  an auxiliary, 24-bit, ΔΣ ADC intended for background measurements.
+
+  Datasheets:
+    - ADS126x: https://www.ti.com/lit/ds/symlink/ads1262.pdf
+
+properties:
+  compatible:
+    oneOf:
+      - const: ti,ads1262
+      - items:
+          - const: ti,ads1263
+          - const: ti,ads1262
+
+  reg:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  spi-max-frequency:
+    maximum: 8000000
+
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 44

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +5 -0
+  spi-cpha: true
+
+  interrupts:
+    description: Data ready (DRDY) interrupt line.
+    maxItems: 1

Technically, there are two pins with the DRDY signal, so we should have two interrupts in order to be able to tell which one is wired up.

Oh you're right. I'll describe both here. I may not add support for it though, at least until I complete everything else.

Quoted 25 lines
Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+  start-gpios:
+    description: Start conversion control.
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  dvdd-supply:
+    description: Digital power supply.

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+  avdd-supply:
+    description: Analog power supply.
+
+  refp-supply:
+    description: External positive voltage reference.
+
+  refn-supply:
+    description: External negative voltage reference.
+

Which pins are these? I see 4 possible external reference sources, but all go through the AINx pins. So I would expect:

Quoted 2 lines

refp1-supply, refn1-supply, refp2-supply, refn2-supply, refp3-supply, refn3-supply, refp4-supply, refn4-supply

I tried to go for a simpler route, but I agree with this.

Quoted 4 lines

Also, similar to the chip I am working on, I expect that these pins could be connected to a resistor rather than a voltage source, so could use additional bindings for that.

Sure!

Quoted 9 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 67

Quoted 5 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +3 -0
+  ti,vbias:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description: Enables the level-shift voltage on the AINCOM pin.

VBIAS is a voltage source, so I would expect that to be modeled as a regulator provider. (If we do that REFOUT should be included as well.)

I didn't think about that, I agree.

Quoted 28 lines
Quoted 13 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +12 -0
+
+  clocks:
+    maxItems: 1
+
+  '#io-channel-cells':
+    minimum: 1
+    maximum: 2
+
+  '#gpio-cells':
+    const: 2
+
+  gpio-controller: true

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

Quoted 18 lines
Quoted 17 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +16 -0
+      diff-channels:
+        description: |
+          Selects the analog input configuration for this channel. The first
+          value is the positive input and the second is the negative input.
+          The following values are available:
+          0: AIN0 pin
+          1: AIN1 pin
+          2: AIN2 pin
+          3: AIN3 pin
+          4: AIN4 pin
+          5: AIN5 pin
+          6: AIN6 pin
+          7: AIN7 pin
+          8: AIN8 pin
+          9: AIN9 pin
+          10: AINCOM pin
Quoted 8 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 109

Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +4 -0
+          11: Temperature sensor monitor
+          12: Analog power supply monitor
+          13: Digital power supply monitor
+          14: TDAC test signal

These are all internal signals, so not sure it makes sense to have them in the devicetree. It would make more sense to have fixed channels defined in the driver for these since they are always there.

Similar to the approach you took.

Quoted 6 lines

We probably also need a separate property (a bool/flag?) to say that this channel is a TDAC output rather than an analog input. Although that is for testing, so maybe something to omit for now until we actually have an application that uses it (to make sure we get it right)?

Yes, I will add the monitor channel for this too. The users can adjust voltage from debugfs. IMO that should be enough.

Quoted 7 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 110

Quoted 3 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +1 -0
+          15: Float (open connection)

How could we have a differential input with one or both pins open? Likely this will just be the setting for pins not specified as something else in the devicetree.

I should remove this too. Leaving the pins floating is necessary when calibrating. I will add full automatic calibration on probe right after this series.

[...]

Quoted 5 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 189

Quoted 1 line
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +1 -0
+      ti,idac-chopping:

I would call this ti,excitation-channel-chopping to match the excitation-channel property. Or since this isn't a generic property, call it ti,idac-rotation to match the datasheet.

Both are fine by me. I went with chopping based on what you said about the term in your series.

Quoted 11 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 198

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +9 -0
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          Automatically swap the IDAC1 and IDAC2 connections of alternate
+          conversions. The ADC averages the alternate conversions to eliminate
+          IDAC mismatch.
+
+      ti,pga-bypass:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: Bypass the Programmable Gain Amplifier (PGA).
Quoted 5 lines

Why would this need to be a DT property? I didn't read this datasheet too much, but in other chips I have seen there are usually rules that PGA has to be bypassed under certain conditions, but not others, so this seems like something for the driver to handle rather than the devicetree.

To be honest, I don't know what would be the application for this. AFAIK when the PGA is bypassed the analog inputs are read unbuffered (?) In that case shouldn't this belong DT?

[...]

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#4 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Quoted 16 lines
Quoted 10 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 198

Quoted 9 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +9 -0
+        $ref: /schemas/types.yaml#/definitions/flag
+        description:
+          Automatically swap the IDAC1 and IDAC2 connections of alternate
+          conversions. The ADC averages the alternate conversions to eliminate
+          IDAC mismatch.
+
+      ti,pga-bypass:
+        $ref: /schemas/types.yaml#/definitions/flag
+        description: Bypass the Programmable Gain Amplifier (PGA).
Quoted 5 lines

Why would this need to be a DT property? I didn't read this datasheet too much, but in other chips I have seen there are usually rules that PGA has to be bypassed under certain conditions, but not others, so this seems like something for the driver to handle rather than the devicetree.

Quoted 4 lines

To be honest, I don't know what would be the application for this. AFAIK when the PGA is bypassed the analog inputs are read unbuffered (?) In that case shouldn't this belong DT?

Let's leave it out of the DT for now until we learn more about how it is intended to be used.

author
#5 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10

That way we would only need one common-mode-supply. Would that be okay?

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#6 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 36 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Quoted 9 lines

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10

That way we would only need one common-mode-supply. Would that be okay?

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

author
#7 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 44 lines · David Lechner
Quoted 43 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml line 89

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml new file +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10
Quoted 6 lines
Quoted 2 lines

That way we would only need one common-mode-supply. Would that be okay?

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

Makes sense.

I just have a doubt: In the ADS112c14 bindings, is there a specific reason why you didn't describe common-mode-<N>-supply?

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#8 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 48 lines · Kurt Borja
Quoted 47 lines · David Lechner
Quoted 45 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10

That way we would only need one common-mode-supply. Would that be okay?

Quoted 9 lines
Quoted 3 lines

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

Makes sense.

I just have a doubt: In the ADS112c14 bindings, is there a specific reason why you didn't describe common-mode-<N>-supply?

For singled-ended inputs on ADS112c14, there is an internal connection to GND, so it isn't possible to have a pseudo- differential input like that. I guess technically, it could still be possible, but wasn't a typical wiring described in the datasheet like it is on ADS1263.

maintainer
#9 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 46 lines · On Tue, 30 Jun 2026 13:38:30 -0500 David Lechner <[email protected]> wrote:
Quoted 45 lines · Kurt Borja
Quoted 44 lines · David Lechner
Quoted 43 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+  

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

That way we would only need one common-mode-supply. Would that be okay?

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

I'm a bit confused on this. Arguably you could wire up any side of a differential pair to a common mode signal, but we haven't had this binding applied more generally than cases where their is a setup where the intent is a shared common (shielding on cable in some cases IIRC).

So why is this case special? I see AIN_COM can be wired up to an internal vbias but other than that it looks like any other AINX input.

Jonathan

Quoted 13 lines
Quoted 6 lines

Makes sense.

I just have a doubt: In the ADS112c14 bindings, is there a specific reason why you didn't describe common-mode-<N>-supply?

For singled-ended inputs on ADS112c14, there is an internal connection to GND, so it isn't possible to have a pseudo- differential input like that. I guess technically, it could still be possible, but wasn't a typical wiring described in the datasheet like it is on ADS1263.

author
#10 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 56 lines · Jonathan Cameron
Quoted 46 lines · On Tue, 30 Jun 2026 13:38:30 -0500 David Lechner <[email protected]> wrote:
Quoted 45 lines · Kurt Borja
Quoted 44 lines · David Lechner
Quoted 43 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+  

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

That way we would only need one common-mode-supply. Would that be okay?

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

Quoted 7 lines

I'm a bit confused on this. Arguably you could wire up any side of a differential pair to a common mode signal, but we haven't had this binding applied more generally than cases where their is a setup where the intent is a shared common (shielding on cable in some cases IIRC).

So why is this case special? I see AIN_COM can be wired up to an internal vbias but other than that it looks like any other AINX input.

Hi,

I forgot to respond to this email!

As you said, there is nothing special about AINCOM, it's just like any other input. That's why David suggested to have a common-mode-N-supply for each input.

I implemented this of course, but I still have doubts because there is no precedent for something like this in IIO. I understand the logic, but I'll personally be inclined to drop it. If there is no further discussion I'll keep the 10 common-mode supplies.

I'm finishing v3 and I'll submit it in a couple of days.

Quoted 16 lines

Jonathan

Quoted 13 lines
Quoted 6 lines

Makes sense.

I just have a doubt: In the ADS112c14 bindings, is there a specific reason why you didn't describe common-mode-<N>-supply?

For singled-ended inputs on ADS112c14, there is an internal connection to GND, so it isn't possible to have a pseudo- differential input like that. I guess technically, it could still be possible, but wasn't a typical wiring described in the datasheet like it is on ADS1263.

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#11 lore raw

Re: [PATCH v2 1/7] dt-bindings: iio: adc: Add TI ADS126x ADC family

Quoted 67 lines · Kurt Borja
Quoted 56 lines · Jonathan Cameron
Quoted 46 lines · On Tue, 30 Jun 2026 13:38:30 -0500 David Lechner <[email protected]> wrote:
Quoted 45 lines · Kurt Borja
Quoted 44 lines · David Lechner
Quoted 43 lines · Kurt Borja
Quoted 26 lines · David Lechner
Quoted 7 lines · Kurt Borja
Quoted 6 lines · David Lechner
Quoted 5 lines · Kurt Borja

The ADS1262 and ADS1263 are 32-bit, 38.4-kSPS delta-sigma ADCs with an integrated PGA, internal reference, excitation and burn-out current sources for sensor biasing and diagnostics. The ADS1263 adds a second, 24-bit delta-sigma ADC (ADC2) for background measurements.

...

Quoted 15 lines
Quoted 15 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+patternProperties:
+  "^channel@[0-9]+$":
+    $ref: /schemas/iio/adc/adc.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        maxItems: 1
+  

If we want to allow single-ended/pseudo-differential inputs, then we should also allow single-channel (positive pin) and common-mode-channel (negative pin) properties.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This will also require additional common-mode-<N>-supply properties to allow for the negative pin connected to something other than GND.

Ah interesting. Why the N though? wouldn't a single supply connected to AINCOM be enough here?

In theory, any AINx could be a common mode input by connecting it to a constant voltage supply.

Technically yes, but there is a pin named AINCOM intended for this purpose. Can we do a simplification here? I propose having

common-mode-channel:

    /* AINCOM pin */
    const: 10
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

That way we would only need one common-mode-supply. Would that be okay?

Ideally, we shouldn't limit how the chip can be wired up in the devicetree bindings. It doesn't mean that we have to implement everything in the driver though.

Quoted 7 lines

I'm a bit confused on this. Arguably you could wire up any side of a differential pair to a common mode signal, but we haven't had this binding applied more generally than cases where their is a setup where the intent is a shared common (shielding on cable in some cases IIRC).

So why is this case special? I see AIN_COM can be wired up to an internal vbias but other than that it looks like any other AINX input.

Hi,

Quoted 8 lines

I forgot to respond to this email!

As you said, there is nothing special about AINCOM, it's just like any other input. That's why David suggested to have a common-mode-N-supply for each input.

I implemented this of course, but I still have doubts because there is no precedent for something like this in IIO. I understand the logic, but

FWIW, we have 4 ainx-supply properties on adi,ad7380.

Quoted 2 lines

I'll personally be inclined to drop it. If there is no further discussion I'll keep the 10 common-mode supplies.

To make the bindings less verbose, we could use:

patternProperties:
ain[0-9]-supply:
description: fixed voltage input when AIN pin is used as common mode

Quoted 20 lines

I'm finishing v3 and I'll submit it in a couple of days.

Quoted 16 lines

Jonathan

Quoted 13 lines
Quoted 6 lines

Makes sense.

I just have a doubt: In the ADS112c14 bindings, is there a specific reason why you didn't describe common-mode-<N>-supply?

For singled-ended inputs on ADS112c14, there is an internal connection to GND, so it isn't possible to have a pseudo- differential input like that. I guess technically, it could still be possible, but wasn't a typical wiring described in the datasheet like it is on ADS1263.

author
#12 lore raw

PATCH v2 2/7 iio: adc: Add ti-ads1262 driver

In reply to Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

---
 MAINTAINERS                  |    1 +
 drivers/iio/adc/Kconfig      |   13 +
 drivers/iio/adc/Makefile     |    1 +
 drivers/iio/adc/ti-ads1262.c | 1206 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1221 insertions(+)
MAINTAINERS +1 -0
index 9b83d294734b574d..d868b25f2c65bcd9 100644
@@ -26928,6 +26928,7 @@ M:	Kurt Borja <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml
+F:	drivers/iio/adc/ti-ads1262.c
 
 TI ADS7924 ADC DRIVER
 M:	Hugo Villeneuve <[email protected]>
drivers/iio/adc/Kconfig +13 -0
index 5845db2011fb5be1..6051092c20b96731 100644
@@ -1811,6 +1811,19 @@ config TI_ADS124S08
 	  This driver can also be built as a module. If so, the module will be
 	  called ti-ads124s08.
 
+config TI_ADS1262
+	tristate "Texas Instruments ADS1262"
+	depends on SPI
+	select REGMAP
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  If you say yes here you get support for Texas Instruments ADS1262 and
+	  ADS1263 ADC chips.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called ti-ads1262.
+
 config TI_ADS1298
 	tristate "Texas Instruments ADS1298"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index 72f4c6b33ca87b3f..4b1f89a2317a35f7 100644
@@ -155,6 +155,7 @@ obj-$(CONFIG_TI_ADS1100) += ti-ads1100.o
 obj-$(CONFIG_TI_ADS1119) += ti-ads1119.o
 obj-$(CONFIG_TI_ADS112C14) += ti-ads112c14.o
 obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
+obj-$(CONFIG_TI_ADS1262) += ti-ads1262.o
 obj-$(CONFIG_TI_ADS1298) += ti-ads1298.o
 obj-$(CONFIG_TI_ADS131E08) += ti-ads131e08.o
 obj-$(CONFIG_TI_ADS131M02) += ti-ads131m02.o
drivers/iio/adc/ti-ads1262.c new file +1206 -0

1,206 lines not on this page · raw message

Signature · 1 line
2.54.0
reviewer
#13 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

Quoted 11 lines · Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

---
 MAINTAINERS                  |    1 +
 drivers/iio/adc/Kconfig      |   13 +
 drivers/iio/adc/Makefile     |    1 +
 drivers/iio/adc/ti-ads1262.c | 1206 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1221 insertions(+)

Ideally, an intial patch would be 1/2 this size. Over 1000 lines in a single patch make it take more than twice as long to review as if it was split into two patches (or you just don't get a detailed review). For example, sample rate and gain can be split out into seprate patches.

I certainly don't have time to revew this plus an additonal 1000 lines of more patches on top of it in a week.

Quoted 18 lines
MAINTAINERS +1 -0
index 9b83d294734b574d..d868b25f2c65bcd9 100644
@@ -26928,6 +26928,7 @@ M:	Kurt Borja <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml
+F:	drivers/iio/adc/ti-ads1262.c
 
 TI ADS7924 ADC DRIVER
 M:	Hugo Villeneuve <[email protected]>
drivers/iio/adc/Kconfig +0 -0
index 5845db2011fb5be1..6051092c20b96731 100644

drivers/iio/adc/Kconfig config TI_ADS124S08 · line 1819

Quoted 9 lines
drivers/iio/adc/Kconfig +6 -0
@@ -1811,6 +1811,19 @@ config TI_ADS124S08
 	  This driver can also be built as a module. If so, the module will be
 	  called ti-ads124s08.
 
+config TI_ADS1262
+	tristate "Texas Instruments ADS1262"
+	depends on SPI
+	select REGMAP
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER

Buffer support isn't added until a later patch.

Quoted 221 lines
drivers/iio/adc/Kconfig +7 -0
+	help
+	  If you say yes here you get support for Texas Instruments ADS1262 and
+	  ADS1263 ADC chips.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called ti-ads1262.
+
 config TI_ADS1298
 	tristate "Texas Instruments ADS1298"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index 72f4c6b33ca87b3f..4b1f89a2317a35f7 100644
@@ -155,6 +155,7 @@ obj-$(CONFIG_TI_ADS1100) += ti-ads1100.o
 obj-$(CONFIG_TI_ADS1119) += ti-ads1119.o
 obj-$(CONFIG_TI_ADS112C14) += ti-ads112c14.o
 obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
+obj-$(CONFIG_TI_ADS1262) += ti-ads1262.o
 obj-$(CONFIG_TI_ADS1298) += ti-ads1298.o
 obj-$(CONFIG_TI_ADS131E08) += ti-ads131e08.o
 obj-$(CONFIG_TI_ADS131M02) += ti-ads131m02.o
drivers/iio/adc/ti-ads1262.c new file +193 -0
new file mode 100644
index 0000000000000000..6103cf5a2d1624a9
@@ -0,0 +1,1206 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Texas Instruments ADS1262 ADC driver
+ *
+ * Copyright (C) 2025 Kurt Borja <[email protected]>
+ */
+
+#include <linux/array_size.h>
+#include <linux/align.h>
+#include <linux/bitfield.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/compiler_attributes.h>
+#include <linux/compiler_types.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/interrupt.h>
+#include <linux/lockdep.h>
+#include <linux/math.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mutex.h>
+#include <linux/overflow.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
+#include <linux/string.h>
+#include <linux/time.h>
+#include <linux/types.h>
+#include <linux/units.h>
+
+#include <asm/byteorder.h>
+
+#include <linux/iio/iio.h>
+
+#define ADS1262_OPCODE_NOP			0x00
+#define ADS1262_OPCODE_RESET			0x06
+#define ADS1262_OPCODE_START1			0x08
+#define ADS1262_OPCODE_STOP1			0x0A
+#define ADS1262_OPCODE_START2			0x0C
+#define ADS1262_OPCODE_STOP2			0x0E
+#define ADS1262_OPCODE_RDATA1			0x12
+#define ADS1262_OPCODE_RDATA2			0x14
+#define ADS1262_OPCODE_SYOCAL1			0x16
+#define ADS1262_OPCODE_SYGCAL1			0x17
+#define ADS1262_OPCODE_SFOCAL1			0x19
+#define ADS1262_OPCODE_SYOCAL2			0x1B
+#define ADS1262_OPCODE_SYGCAL2			0x1C
+#define ADS1262_OPCODE_SFOCAL2			0x1E
+#define ADS1262_OPCODE_RREG			0x20
+#define ADS1262_OPCODE_WREG			0x40
+
+#define ADS1262_ID_REG				0x00
+#define   ADS1262_DEV_ID_MASK			GENMASK(7, 5)
+#define   ADS1262_REV_ID_MASK			GENMASK(4, 0)
+
+#define ADS1262_POWER_REG			0x01
+#define   ADS1262_POWER_RESET_MASK		BIT(4)
+#define   ADS1262_POWER_VBIAS_MASK		BIT(1)
+#define   ADS1262_POWER_INTREF_MASK		BIT(0)
+
+#define ADS1262_INTERFACE_REG			0x02
+#define   ADS1262_INTERFACE_TIMEOUT_MASK	BIT(3)
+#define   ADS1262_INTERFACE_STATUS_MASK		BIT(2)
+#define   ADS1262_INTERFACE_CRC_MASK		GENMASK(1, 0)
+
+#define ADS1262_MODE0_REG			0x03
+#define   ADS1262_MODE0_REFREV_MASK		BIT(7)
+#define   ADS1262_MODE0_RUNMODE_MASK		BIT(6)
+#define   ADS1262_MODE0_IDAC_CHOP_MASK		BIT(5)
+#define   ADS1262_MODE0_INPUT_CHOP_MASK		BIT(4)
+#define   ADS1262_MODE0_DELAY_MASK		GENMASK(3, 0)
+
+#define ADS1262_MODE1_REG			0x04
+#define   ADS1262_MODE1_FILTER_MASK		GENMASK(7, 5)
+#define   ADS1262_MODE1_SBADC_MASK		BIT(4)
+#define   ADS1262_MODE1_SBPOL_MASK		BIT(3)
+#define   ADS1262_MODE1_SBMAG_MASK		GENMASK(2, 0)
+
+#define ADS1262_MODE2_REG			0x05
+#define   ADS1262_MODE2_BYPASS_MASK		BIT(7)
+#define   ADS1262_MODE2_GAIN_MASK		GENMASK(6, 4)
+#define   ADS1262_MODE2_DR_MASK			GENMASK(3, 0)
+
+#define ADS1262_INPMUX_REG			0x06
+#define   ADS1262_INPMUX_MUXP_MASK		GENMASK(7, 4)
+#define   ADS1262_INPMUX_MUXN_MASK		GENMASK(3, 0)
+
+#define ADS1262_OFCAL0_REG			0x07
+#define ADS1262_OFCAL1_REG			0x08
+#define ADS1262_OFCAL2_REG			0x09
+#define ADS1262_FSCAL0_REG			0x0A
+#define ADS1262_FSCAL1_REG			0x0B
+#define ADS1262_FSCAL2_REG			0x0C
+
+#define ADS1262_IDACMUX_REG			0x0D
+#define   ADS1262_IDACMUX_MUX2_MASK		GENMASK(7, 4)
+#define   ADS1262_IDACMUX_MUX1_MASK		GENMASK(3, 0)
+
+#define ADS1262_IDACMAG_REG			0x0E
+#define   ADS1262_IDACMAG_MAG2_MASK		GENMASK(7, 4)
+#define   ADS1262_IDACMAG_MAG1_MASK		GENMASK(3, 0)
+
+#define ADS1262_REFMUX_REG			0x0F
+#define   ADS1262_REFMUX_RMUXP_MASK		GENMASK(5, 3)
+#define   ADS1262_REFMUX_RMUXN_MASK		GENMASK(2, 0)
+
+#define ADS1262_TDACP_REG			0x10
+#define   ADS1262_TDACP_OUTP_MASK		BIT(7)
+#define   ADS1262_TDACP_MAGP_MASK		GENMASK(4, 0)
+
+#define ADS1262_TDACN_REG			0x11
+#define   ADS1262_TDACN_OUTN_MASK		BIT(7)
+#define   ADS1262_TDACN_MAGN_MASK		GENMASK(4, 0)
+
+#define ADS1262_GPIOCON_REG			0x12
+#define ADS1262_GPIODIR_REG			0x13
+#define ADS1262_GPIODAT_REG			0x14
+
+#define ADS1262_ADC2CFG_REG			0x15
+#define   ADS1262_ADC2CFG_DR2_MASK		GENMASK(7, 6)
+#define   ADS1262_ADC2CFG_REF2_MASK		GENMASK(5, 3)
+#define   ADS1262_ADC2CFG_GAIN2_MASK		GENMASK(2, 0)
+
+#define ADS1262_ADC2MUX_REG			0x16
+#define   ADS1262_ADC2MUX_MUXP2_MASK		GENMASK(7, 4)
+#define   ADS1262_ADC2MUX_MUXN2_MASK		GENMASK(3, 0)
+
+#define ADS1262_ADC2OFC0_REG			0x17
+#define ADS1262_ADC2OFC1_REG			0x18
+#define ADS1262_ADC2FSC0_REG			0x19
+#define ADS1262_ADC2FSC1_REG			0x1A
+#define ADS1262_REG_COUNT			0x1B
+
+#define ADS1262_MAX_CHANNEL_COUNT		16
+#define ADS1262_XFER_BUFFER_SZ			11
+
+enum {
+	ADS1262_RUNMODE_CONTINUOUS,
+	ADS1262_RUNMODE_PULSE,
+};
+
+enum {
+	ADS1262_DR_2_5_SPS,
+	ADS1262_DR_5_SPS,
+	ADS1262_DR_10_SPS,
+	ADS1262_DR_16_6_SPS,
+	ADS1262_DR_20_SPS,
+	ADS1262_DR_50_SPS,
+	ADS1262_DR_60_SPS,
+	ADS1262_DR_100_SPS,
+	ADS1262_DR_400_SPS,
+	ADS1262_DR_1200_SPS,
+	ADS1262_DR_2400_SPS,
+	ADS1262_DR_4800_SPS,
+	ADS1262_DR_7200_SPS,
+	ADS1262_DR_14400_SPS,
+	ADS1262_DR_19200_SPS,
+	ADS1262_DR_38400_SPS,
+};
+
+enum {
+	ADS1262_INPMUX_AIN0,
+	ADS1262_INPMUX_AIN1,
+	ADS1262_INPMUX_AIN2,
+	ADS1262_INPMUX_AIN3,
+	ADS1262_INPMUX_AIN4,
+	ADS1262_INPMUX_AIN5,
+	ADS1262_INPMUX_AIN6,
+	ADS1262_INPMUX_AIN7,
+	ADS1262_INPMUX_AIN8,
+	ADS1262_INPMUX_AIN9,
+	ADS1262_INPMUX_AINCOM,
+	ADS1262_INPMUX_TEMP,
+	ADS1262_INPMUX_AVDD,
+	ADS1262_INPMUX_DVDD,
+	ADS1262_INPMUX_TDAC,
+	ADS1262_INPMUX_FLOAT,
+	ADS1262_INPMUX_LAST
+};
+
+enum {
+	ADS1262_REFMUX_INTERNAL,
+	ADS1262_REFMUX_AIN0_AIN1,
+	ADS1262_REFMUX_AIN2_AIN3,
+	ADS1262_REFMUX_AIN4_AIN5,
+	ADS1262_REFMUX_AVDD_AVSS,

drivers/iio/adc/ti-ads1262.c line 203

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	ADS1262_REFMUX_LAST
+};
+
+struct ads1262_chip_info {
+	const char *name;
+	bool has_aux_adc;
+};
+
+struct ads1262_channel {
+	u8 input[2];

Since this is already stored in channel and channel2, we don't really need to repeat the same thing here.

drivers/iio/adc/ti-ads1262.c line 206

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c new file +3 -0
+	u8 gain;
+	u8 data_rate;
+	u8 reference[3];

I would just make 3 fields for this. We never pass a variable value for the index, so would be easier to understand if we give it proper names.

drivers/iio/adc/ti-ads1262.c line 210

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+	u8 pga_bypass:1;
+	u8 ref_reversal:1;
+	u8 input_chop:1;
+	u8 idac_chop:1;

Just make these bool instead of bitfields.

Quoted 15 lines
drivers/iio/adc/ti-ads1262.c new file +15 -0
+};
+
+struct ads1262 {
+	struct spi_device *spi;
+	const struct ads1262_chip_info *info;
+	struct regmap *regmap;
+	struct iio_dev *indio_dev;
+	struct gpio_desc *reset_gpiod;
+	struct gpio_desc *start_gpiod;
+
+	/* Protects channel state */
+	struct mutex chan_lock;
+	unsigned int num_channels;
+	struct ads1262_channel *channels;
+	struct completion drdy;

drivers/iio/adc/ti-ads1262.c line 235

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+
+	int refp_uV;
+	int refn_uV;
+	int avdd_uV;
+
+	/* Protects transfer buffers and concurrent SPI transfers */
+	struct mutex xfer_lock;
+
+	u8 tx[ADS1262_XFER_BUFFER_SZ] __aligned(IIO_DMA_MINALIGN);
+	u8 rx[ADS1262_XFER_BUFFER_SZ] __aligned(IIO_DMA_MINALIGN);

2nd one doesn't need __aligned(IIO_DMA_MINALIGN). They are never used at the same time by different DMA operations.

Quoted 38 lines
drivers/iio/adc/ti-ads1262.c new file +38 -0
+};
+
+static const int ads1262_data_rate_avail[][2] = {
+	[ADS1262_DR_2_5_SPS]	= { 2,		500000 },
+	[ADS1262_DR_5_SPS]	= { 5,		0 },
+	[ADS1262_DR_10_SPS]	= { 10,		0 },
+	[ADS1262_DR_16_6_SPS]	= { 16,		666667 },
+	[ADS1262_DR_20_SPS]	= { 20,		0 },
+	[ADS1262_DR_50_SPS]	= { 50,		0 },
+	[ADS1262_DR_60_SPS]	= { 60,		0 },
+	[ADS1262_DR_100_SPS]	= { 100,	0 },
+	[ADS1262_DR_400_SPS]	= { 400,	0 },
+	[ADS1262_DR_1200_SPS]	= { 1200,	0 },
+	[ADS1262_DR_2400_SPS]	= { 2400,	0 },
+	[ADS1262_DR_4800_SPS]	= { 4800,	0 },
+	[ADS1262_DR_7200_SPS]	= { 7200,	0 },
+	[ADS1262_DR_14400_SPS]	= { 14400,	0 },
+	[ADS1262_DR_19200_SPS]	= { 19200,	0 },
+	[ADS1262_DR_38400_SPS]	= { 38400,	0 },
+};
+
+static const int ads1262_pga_gain_avail[] = {
+	1, 2, 4, 8, 16, 32
+};
+
+#define ads1262_find_one(_arr, _val)					\
+({									\
+	int _i;								\
+	for (_i = 0; _i < ARRAY_SIZE(_arr); _i++) {			\
+		if ((_val) == _arr[_i])					\
+			break;						\
+	}								\
+	if (_i == ARRAY_SIZE(_arr))					\
+		_i = -EINVAL;						\
+	_i;								\
+})
+
+#define ads1262_find_two(_arr, _val, _val2)				\

drivers/iio/adc/ti-ads1262.c line 283

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+({									\
+	int _i;								\
+	for (_i = 0; _i < ARRAY_SIZE(_arr); _i++) {			\
+		if ((_val) == _arr[_i][0] && (_val2) == _arr[_i][1])	\
+			break;						\
+	}								\
+	if (_i == ARRAY_SIZE(_arr))					\
+		_i = -EINVAL;						\
+	_i;								\
+})

It looks like these are only used once, so not much point in making it a macro.

drivers/iio/adc/ti-ads1262.c line 285

Quoted 2 lines
drivers/iio/adc/ti-ads1262.c new file +2 -0
+
+#define ads1262_find_string(_arr, _str)					\

Isn't this the same as match_string()?

Quoted 9 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+({									\
+	int _i;								\
+	for (_i = 0; _i < ARRAY_SIZE(_arr); _i++) {			\
+		if (!strcmp(_arr[_i], _str))				\
+			break;						\
+	}								\
+	if (_i == ARRAY_SIZE(_arr))					\
+		_i = -EINVAL;						\
+	_i;								\

drivers/iio/adc/ti-ads1262.c line 304

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+})
+
+static int ads1262_dev_cmd(struct ads1262 *st, u8 opcode)
+{
+	guard(mutex)(&st->xfer_lock);
+
+	return spi_write_then_read(st->spi, &opcode, sizeof(opcode), NULL, 0);
+}
+
+static int ads1262_dev_reset(struct ads1262 *st)

I would call this soft_reset since there is also a hardware reset pin.

Or also add the hardware reset here.

Quoted 36 lines
drivers/iio/adc/ti-ads1262.c new file +36 -0
+{
+	int ret;
+
+	ret = ads1262_dev_cmd(st, ADS1262_OPCODE_RESET);
+	if (ret)
+		return ret;
+
+	/* RESET command timing requirement is 1.085 usecs (Table 9-32) */
+	fsleep(2);
+
+	return ret;
+}
+
+static int ads1262_dev_start(struct ads1262 *st)
+{
+	int ret;
+
+	if (st->start_gpiod)
+		ret = gpiod_set_value_cansleep(st->start_gpiod, 1);
+	else
+		ret = ads1262_dev_cmd(st, ADS1262_OPCODE_START1);
+
+	return ret;
+}
+
+static int ads1262_dev_stop(struct ads1262 *st)
+{
+	int ret;
+
+	if (st->start_gpiod)
+		ret = gpiod_set_value_cansleep(st->start_gpiod, 0);
+	else
+		ret = ads1262_dev_cmd(st, ADS1262_OPCODE_STOP1);
+
+	return ret;
+}

drivers/iio/adc/ti-ads1262.c line 350

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+
+static int ads1262_dev_start_one(struct ads1262 *st, u8 runmode)
+{
+	int ret;
+
+	ret = ads1262_dev_start(st);
+	if (ret)
+		return ret;
+
+	if (runmode == ADS1262_RUNMODE_CONTINUOUS)

Why would we not just put the device in single-shot mode to start a single conversion?

OK, anwsered later.

Quoted 8 lines
drivers/iio/adc/ti-ads1262.c new file +8 -0
+		return ads1262_dev_stop(st);
+
+	return 0;
+}
+
+static int ads1262_calculate_scale(struct ads1262 *st, u8 realbits, u8 gain,
+				   u8 pos_ref, u8 neg_ref, int *val, int *val2)
+{

drivers/iio/adc/ti-ads1262.c line 368

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	u64 divd, divr, tmp, rem;
+	int pos_uV, neg_uV;
+
+	switch (pos_ref) {
+	case ADS1262_REFMUX_INTERNAL:
+		/* Internal voltage reference is 2.5 V */
+		pos_uV = 2500000;
+		break;
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:
+		pos_uV = st->refp_uV;

I don't think it is safe to assume the same reference is wired to all of these.

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		break;
+	case ADS1262_REFMUX_AVDD_AVSS:
+		pos_uV = st->avdd_uV;
+		break;

drivers/iio/adc/ti-ads1262.c line 382

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	default:
+		return -EINVAL;
+	}
+
+	switch (neg_ref) {
+	case ADS1262_REFMUX_INTERNAL:
+		neg_uV = 0;
+		break;
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:
+		neg_uV = st->refn_uV == -ENODEV ? 0 : st->refn_uV;

Why not just store 0 in refn_uV directly?

drivers/iio/adc/ti-ads1262.c line 391

Quoted 9 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+		break;
+	case ADS1262_REFMUX_AVDD_AVSS:
+		neg_uV = 0;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+

Could use a comment to explain why pos would ever be less than negative.

drivers/iio/adc/ti-ads1262.c line 392

Quoted 1 line
drivers/iio/adc/ti-ads1262.c new file +1 -0
+	if (pos_uV < neg_uV)

Why not checking chan->ref_reversal?

drivers/iio/adc/ti-ads1262.c line 395

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c new file +3 -0
+		divd = neg_uV - pos_uV;
+	else
+		divd = pos_uV - neg_uV;

Why not just use abs()?

drivers/iio/adc/ti-ads1262.c line 397

Quoted 2 lines
drivers/iio/adc/ti-ads1262.c new file +2 -0
+	divr = BIT_ULL(gain + realbits - 1) * 1000;
+	tmp = div64_u64(divd * NANO, divr);

Not a fan of variables named tmp. Would prefer a meaningful name like scale_nano.

Quoted 27 lines
drivers/iio/adc/ti-ads1262.c new file +27 -0
+
+	*val = div64_u64_rem(tmp, NANO, &rem);
+	*val2 = rem;
+
+	return 0;
+}
+
+static int ads1262_channel_get_scale(struct ads1262 *st,
+				     struct iio_chan_spec const *chan, int *val,
+				     int *val2)
+{
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+
+	return ads1262_calculate_scale(st, chan->scan_type.realbits, chan_data->gain,
+				       chan_data->reference[0], chan_data->reference[1],
+				       val, val2);
+}
+
+static long ads1262_wait_for_conversion(struct ads1262 *st)
+{
+	/*
+	 * The first conversion latency is affected by the channel's data rate,
+	 * filter, the configurable conversion delay and whether chop mode
+	 * and/or IDAC rotation mode are enabled.
+	 *
+	 * The worst possible latency is calculated by taking the lowest data
+	 * rate (2.5 SPS) and the sinc4 filter. This gives a latency of 1600 ms

drivers/iio/adc/ti-ads1262.c line 434

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	 * (Table 9-13). Then add the slowest configurable conversion delay
+	 * (9 ms) and multiply by 4 to account for chop and IDAC rotation modes
+	 * (Equation 20).
+	 *
+	 * Final result is 4 * (1600 ms + 9 ms) = 6436.
+	 */
+	return wait_for_completion_interruptible_timeout(&st->drdy, msecs_to_jiffies(6436));
+}
+
+static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)

Would be more logical to put this right after ads1262_dev_cmd().

Quoted 15 lines
drivers/iio/adc/ti-ads1262.c new file +15 -0
+{
+	guard(mutex)(&st->xfer_lock);
+
+	return spi_write_then_read(st->spi, &cmd, sizeof(cmd), val, sizeof(*val));
+}
+
+static int ads1262_channel_enable(struct ads1262 *st,
+				  struct ads1262_channel *chan)
+{
+	u8 mode0, mode2, inpmux, refmux;
+	int ret;
+
+	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
+	mutex_lock(&st->chan_lock);
+	mode0 = FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |

drivers/iio/adc/ti-ads1262.c line 459

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+		FIELD_PREP(ADS1262_MODE0_IDAC_CHOP_MASK, chan->idac_chop) |
+		FIELD_PREP(ADS1262_MODE0_REFREV_MASK, chan->ref_reversal);
+	mode2 = FIELD_PREP(ADS1262_MODE2_DR_MASK, chan->data_rate) |
+		FIELD_PREP(ADS1262_MODE2_GAIN_MASK, chan->gain) |
+		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
+	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
+		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
+		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
+	mutex_unlock(&st->chan_lock);

Why does lock not also include actually writing the bits?

Quoted 59 lines
drivers/iio/adc/ti-ads1262.c new file +59 -0
+
+	ret = regmap_update_bits(st->regmap, ADS1262_MODE0_REG,
+				 ADS1262_MODE0_INPUT_CHOP_MASK |
+				 ADS1262_MODE0_IDAC_CHOP_MASK |
+				 ADS1262_MODE0_REFREV_MASK, mode0);
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(st->regmap, ADS1262_MODE2_REG,
+				 ADS1262_MODE2_DR_MASK |
+				 ADS1262_MODE2_GAIN_MASK |
+				 ADS1262_MODE2_BYPASS_MASK, mode2);
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(st->regmap, ADS1262_INPMUX_REG,
+				 ADS1262_INPMUX_MUXN_MASK |
+				 ADS1262_INPMUX_MUXP_MASK, inpmux);
+	if (ret)
+		return ret;
+
+	return regmap_update_bits(st->regmap, ADS1262_REFMUX_REG,
+				  ADS1262_REFMUX_RMUXN_MASK |
+				  ADS1262_REFMUX_RMUXP_MASK, refmux);
+}
+
+static int ads1262_set_runmode(struct ads1262 *st, u8 runmode)
+{
+	return regmap_update_bits(st->regmap, ADS1262_MODE0_REG,
+				  ADS1262_MODE0_RUNMODE_MASK,
+				  FIELD_PREP(ADS1262_MODE0_RUNMODE_MASK, runmode));
+}
+
+static int ads1262_channel_read(struct ads1262 *st,
+				struct ads1262_channel *chan_data, __be32 *val)
+{
+	u8 runmode;
+	int ret;
+
+	IIO_DEV_ACQUIRE_DIRECT_MODE(st->indio_dev, claim);
+	if (IIO_DEV_ACQUIRE_FAILED(claim))
+		return -EBUSY;
+
+	/*
+	 * When a channel has chop mode or IDAC rotation mode, the first
+	 * conversion is always withheld so the datasheet suggests using the
+	 * CONTINUOUS mode and briefly starting and stopping conversions to
+	 * achieve the same effect (Section 9.4.1.2).
+	 */
+	if (chan_data->input_chop || chan_data->idac_chop)
+		runmode = ADS1262_RUNMODE_CONTINUOUS;
+	else
+		runmode = ADS1262_RUNMODE_PULSE;
+
+	ret = ads1262_set_runmode(st, runmode);
+	if (ret)
+		return ret;
+
+	ret = ads1262_channel_enable(st, chan_data);

drivers/iio/adc/ti-ads1262.c line 528

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	if (ret)
+		return ret;
+
+	reinit_completion(&st->drdy);
+
+	ret = ads1262_dev_start_one(st, runmode);
+	if (ret)
+		return ret;
+
+	ads1262_wait_for_conversion(st);

This can timeout, so would expect to check return value here.

Quoted 24 lines
drivers/iio/adc/ti-ads1262.c new file +24 -0
+
+	return ads1262_dev_read_by_cmd(st, ADS1262_OPCODE_RDATA1, val);
+}
+
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {

drivers/iio/adc/ti-ads1262.c line 562

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

Quoted 78 lines
drivers/iio/adc/ti-ads1262.c new file +78 -0
+		guard(mutex)(&st->chan_lock);
+
+		*val = ads1262_pga_gain_avail[chan_data->gain];
+
+		return IIO_VAL_INT;
+	}
+
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		guard(mutex)(&st->chan_lock);
+
+		*val = ads1262_data_rate_avail[chan_data->data_rate][0];
+		*val2 = ads1262_data_rate_avail[chan_data->data_rate][1];
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int ads1262_read_avail(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan, const int **vals,
+			      int *type, int *length, long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		*type = IIO_VAL_INT_PLUS_MICRO;
+		*vals = (const int *)ads1262_data_rate_avail;
+		*length = ARRAY_SIZE(ads1262_data_rate_avail) * 2;
+		return IIO_AVAIL_LIST;
+
+	case IIO_CHAN_INFO_HARDWAREGAIN:
+		*type = IIO_VAL_INT;
+		*vals = ads1262_pga_gain_avail;
+		*length = ARRAY_SIZE(ads1262_pga_gain_avail);
+		return IIO_AVAIL_LIST;
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int ads1262_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan, int val,
+			     int val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data;
+	int i;
+
+	chan_data = &st->channels[chan->scan_index];
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		i = ads1262_find_two(ads1262_data_rate_avail, val, val2);
+		if (i < 0)
+			return i;
+
+		guard(mutex)(&st->chan_lock);
+		chan_data->data_rate = i;
+
+		break;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {
+		i = ads1262_find_one(ads1262_pga_gain_avail, val);
+		if (i < 0)
+			return i;
+
+		guard(mutex)(&st->chan_lock);
+		chan_data->gain = i;
+
+		break;
+	}
+
+	default:
+		return -EOPNOTSUPP;

drivers/iio/adc/ti-ads1262.c line 650

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	}
+
+	return 0;
+}
+
+static int ads1262_write_raw_get_fmt(struct iio_dev *indio_dev,
+				     struct iio_chan_spec const *chan, long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_CONVDELAY:

Looks like this belongs in a later patch.

Quoted 57 lines
drivers/iio/adc/ti-ads1262.c new file +57 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	default:
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+}
+
+static int ads1262_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg,
+				      unsigned int writeval, unsigned int *readval)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read_bypassed(st->regmap, reg, readval);
+
+	return regmap_write(st->regmap, reg, writeval);
+}
+
+static const struct iio_info ads1262_iio_info = {
+	.read_raw = ads1262_read_raw,
+	.read_avail = ads1262_read_avail,
+	.write_raw = ads1262_write_raw,
+	.write_raw_get_fmt = ads1262_write_raw_get_fmt,
+	.debugfs_reg_access = ads1262_debugfs_reg_access,
+};
+
+static irqreturn_t ads1262_irq_handler(int irq, void *dev_id)
+{
+	struct ads1262 *st = dev_id;
+
+	complete(&st->drdy);
+
+	return IRQ_HANDLED;
+}
+
+static int ads1262_alloc_channels(struct ads1262 *st,
+				  struct iio_chan_spec **channels)
+{
+	struct device *dev = &st->spi->dev;
+	struct ads1262_channel *chan_data;
+	struct iio_chan_spec *chans;
+	unsigned int i, num_channels;
+
+	/* Account for the timestamp channel */
+	num_channels = st->num_channels + 1;
+	chans = devm_kcalloc(dev, num_channels, sizeof(*chans), GFP_KERNEL);
+	if (!chans)
+		return -ENOMEM;
+
+	for (i = 0; i < st->num_channels; i++) {
+		chan_data = &st->channels[i];
+		chans[i] = (struct iio_chan_spec) {
+			.type = IIO_VOLTAGE,
+			.channel = chan_data->input[0],
+			.channel2 = chan_data->input[1],
+			.scan_index = i,
+			.scan_type = {
+				.format = IIO_SCAN_FORMAT_SIGNED_INT,

drivers/iio/adc/ti-ads1262.c line 717

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+				.realbits = 32,
+				.storagebits = 32,
+				.endianness = IIO_BE,
+			},
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+					      BIT(IIO_CHAN_INFO_SCALE) |
+					      BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
+					      BIT(IIO_CHAN_INFO_SAMP_FREQ),
+			.info_mask_shared_by_type_available =
+				BIT(IIO_CHAN_INFO_HARDWAREGAIN) |

Gain available might make more sense as separate if there are restrictions on gain allowed due to other conditions.

drivers/iio/adc/ti-ads1262.c line 718

Quoted 1 line
drivers/iio/adc/ti-ads1262.c new file +1 -0
+				BIT(IIO_CHAN_INFO_SAMP_FREQ),

Could be the same case with sampling frequency if filters can affect that.

drivers/iio/adc/ti-ads1262.c line 720

Quoted 2 lines
drivers/iio/adc/ti-ads1262.c new file +2 -0
+			.indexed = true,
+			.differential = true,

These two make more sense closer to the top since they affect the channel naming along with type and channel.

drivers/iio/adc/ti-ads1262.c line 722

Quoted 2 lines
drivers/iio/adc/ti-ads1262.c new file +2 -0
+		};
+	}

As mentioned in the DT bindings review, I would make the diagnostic channels fixed so that they don't have to be always specified in the devicetree.

Quoted 76 lines
drivers/iio/adc/ti-ads1262.c new file +76 -0
+
+	chans[i] = IIO_CHAN_SOFT_TIMESTAMP(i);
+
+	*channels = chans;
+
+	return num_channels;
+}
+
+static int ads1262_dev_configure(struct ads1262 *st)
+{
+	struct device *dev = &st->spi->dev;
+	int ret;
+
+	ret = ads1262_dev_reset(st);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to reset device\n");
+
+	ret = regmap_clear_bits(st->regmap, ADS1262_POWER_REG,
+				ADS1262_POWER_RESET_MASK);
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(st->regmap, ADS1262_INTERFACE_REG,
+				ADS1262_INTERFACE_STATUS_MASK |
+				ADS1262_INTERFACE_CRC_MASK);
+	if (ret)
+		return ret;
+
+	if (device_property_present(dev, "ti,vbias")) {
+		ret = regmap_set_bits(st->regmap, ADS1262_POWER_REG,
+				      ADS1262_POWER_VBIAS_MASK);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const struct regmap_range ads1262_read_write_range[] = {
+	regmap_reg_range(ADS1262_ID_REG, ADS1262_ADC2FSC1_REG),
+};
+
+static const struct regmap_range ads1262_read_only_range[] = {
+	regmap_reg_range(ADS1262_ID_REG, ADS1262_ID_REG),
+};
+
+static const struct regmap_access_table ads1262_wr_table = {
+	.yes_ranges = ads1262_read_write_range,
+	.n_yes_ranges = ARRAY_SIZE(ads1262_read_write_range),
+	.no_ranges = ads1262_read_only_range,
+	.n_no_ranges = ARRAY_SIZE(ads1262_read_only_range),
+};
+
+static const struct regmap_access_table ads1262_rd_table = {
+	.yes_ranges = ads1262_read_write_range,
+	.n_yes_ranges = ARRAY_SIZE(ads1262_read_write_range),
+};
+
+static const struct reg_default ads1262_reg_defaults[] = {
+	{ ADS1262_POWER_REG,		0x11 },
+	{ ADS1262_INTERFACE_REG,	0x05 },
+	{ ADS1262_MODE0_REG,		0x00 },
+	{ ADS1262_MODE1_REG,		0x80 },
+	{ ADS1262_MODE2_REG,		0x04 },
+	{ ADS1262_INPMUX_REG,		0x01 },
+	{ ADS1262_OFCAL0_REG,		0x00 },
+	{ ADS1262_OFCAL1_REG,		0x00 },
+	{ ADS1262_OFCAL2_REG,		0x00 },
+	{ ADS1262_FSCAL0_REG,		0x00 },
+	{ ADS1262_FSCAL1_REG,		0x00 },
+	{ ADS1262_FSCAL2_REG,		0x40 },
+	{ ADS1262_IDACMUX_REG,		0xBB },
+	{ ADS1262_IDACMAG_REG,		0x00 },
+	{ ADS1262_REFMUX_REG,		0x00 },
+	{ ADS1262_TDACP_REG,		0x00 },
+	{ ADS1262_TDACN_REG,		0x00 },

drivers/iio/adc/ti-ads1262.c line 808

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	{ ADS1262_GPIOCON_REG,		0x00 },
+	{ ADS1262_GPIODIR_REG,		0x00 },
+	{ ADS1262_GPIODAT_REG,		0x00 },
+	{ ADS1262_ADC2CFG_REG,		0x00 },
+	{ ADS1262_ADC2MUX_REG,		0x01 },
+	{ ADS1262_ADC2OFC0_REG,		0x00 },
+	{ ADS1262_ADC2OFC1_REG,		0x00 },
+	{ ADS1262_ADC2FSC0_REG,		0x00 },
+	{ ADS1262_ADC2FSC1_REG,		0x40 },
+};

Jonathan says he prefers to spell out the default values (e.g. with FIELD_PREP_CONST()) it it isn't too messy.

drivers/iio/adc/ti-ads1262.c line 821

Quoted 13 lines
drivers/iio/adc/ti-ads1262.c new file +13 -0
+
+static const struct regmap_config ads1262_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.wr_table = &ads1262_wr_table,
+	.rd_table = &ads1262_rd_table,
+	.reg_defaults = ads1262_reg_defaults,
+	.num_reg_defaults = ARRAY_SIZE(ads1262_reg_defaults),
+	.max_register = ADS1262_ADC2FSC1_REG,
+	.read_flag_mask = ADS1262_OPCODE_RREG,
+	.write_flag_mask = ADS1262_OPCODE_WREG,
+	.can_sleep = true,
+	.cache_type = REGCACHE_MAPLE,

Need to define volatile registers in order for cache to work correctly.

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+};
+
+static int ads1262_regmap_read(void *context, const void *reg_buf,
+			       size_t reg_size, void *val_buf, size_t val_size)

drivers/iio/adc/ti-ads1262.c line 835

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+{
+	struct ads1262 *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->tx,
+		.rx_buf = st->rx,
+		.len = reg_size + 1 + val_size,
+	};
+	int ret;
+
+	guard(mutex)(&st->xfer_lock);

SPI bus and regmap both already have their own locking, so putting a lock here seems out of place. Instead, the lock should be for higher-level operations where there are mulitple register access in a single operation.

Quoted 43 lines
drivers/iio/adc/ti-ads1262.c new file +43 -0
+
+	memset(st->tx, 0, reg_size + 1 + val_size);
+
+	memcpy(&st->tx[0], reg_buf, 1);
+	st->tx[1] = val_size - 1;
+
+	ret = spi_sync_transfer(st->spi, &xfer, 1);
+	if (ret)
+		return ret;
+
+	memcpy(val_buf, &st->rx[2], val_size);
+
+	return 0;
+}
+
+static int ads1262_regmap_gather_write(void *context, const void *reg_buf,
+				       size_t reg_size, const void *val_buf,
+				       size_t val_size)
+{
+	struct ads1262 *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->tx,
+		.rx_buf = st->rx,
+		.len = reg_size + 1 + val_size,
+	};
+
+	guard(mutex)(&st->xfer_lock);
+
+	memset(st->tx, 0, reg_size + 1 + val_size);
+
+	memcpy(&st->tx[0], reg_buf, 1);
+	st->tx[1] = val_size - 1;
+	memcpy(&st->tx[2], val_buf, val_size);
+
+	return spi_sync_transfer(st->spi, &xfer, 1);
+}
+
+static int ads1262_regmap_write(void *context, const void *data, size_t count)
+{
+	return ads1262_regmap_gather_write(context, data, 1, data + 1,
+					   count - 1);
+}
+

drivers/iio/adc/ti-ads1262.c line 888

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+static const struct regmap_bus ads1262_regmap_bus = {
+	.read = ads1262_regmap_read,
+	.gather_write = ads1262_regmap_gather_write,
+	.write = ads1262_regmap_write,
+	.reg_format_endian_default = REGMAP_ENDIAN_BIG,
+	.val_format_endian_default = REGMAP_ENDIAN_BIG,
+	/* The first two bytes of the buffer are reserved for the protocol */
+	.max_raw_read = ADS1262_XFER_BUFFER_SZ - 2,
+	.max_raw_write = ADS1262_XFER_BUFFER_SZ - 2,
+};

Why do we need our own bus instead of using REGMAP_SPI?

Quoted 31 lines
drivers/iio/adc/ti-ads1262.c new file +31 -0
+
+static int ads1262_channel_sanity_check(struct ads1262 *st,
+					struct ads1262_channel *chan)
+{
+	struct device *dev = &st->spi->dev;
+	int pos_uV, neg_uV;
+
+	/* Positive reference */
+	switch (chan->reference[0]) {
+	case ADS1262_REFMUX_INTERNAL:
+		/* Internal voltage reference is 2.5 V */
+		pos_uV = 2500000;
+		break;
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:
+		if (st->refp_uV == -ENODEV)
+			return dev_err_probe(dev, -ENODEV, "refp-supply not found\n");
+		pos_uV = st->refp_uV;
+		break;
+	case ADS1262_REFMUX_AVDD_AVSS:
+		pos_uV = st->avdd_uV;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* Negative reference */
+	switch (chan->reference[1]) {
+	case ADS1262_REFMUX_INTERNAL:
+		neg_uV = 0;
+		break;
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:

drivers/iio/adc/ti-ads1262.c line 929

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+		neg_uV = st->refn_uV == -ENODEV ? 0 : st->refn_uV;
+		break;
+	case ADS1262_REFMUX_AVDD_AVSS:
+		neg_uV = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* If the positive reference is bellow the negative, reverse it */

s/bellow/below/

Quoted 42 lines
drivers/iio/adc/ti-ads1262.c new file +42 -0
+	if (pos_uV < neg_uV)
+		chan->ref_reversal = 1;
+
+	/* ADC2 reference */
+	switch (chan->reference[2]) {
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:
+		if (st->refp_uV == -ENODEV)
+			return dev_err_probe(dev, -ENODEV, "refp-supply not found\n");
+		pos_uV = st->refp_uV;
+		neg_uV = st->refn_uV == -ENODEV ? 0 : st->refn_uV;
+
+		/* We can't reverse ADC2 reference */
+		if (pos_uV < neg_uV && st->info->has_aux_adc)
+			return dev_err_probe(dev, -EINVAL,
+					     "ADC2 doesn't support negative reference voltage\n");
+
+		break;
+	}
+
+	return 0;
+}
+
+static const char * const ads1262_ref_sources_positive[] = {
+	[ADS1262_REFMUX_INTERNAL] = "internal",
+	[ADS1262_REFMUX_AIN0_AIN1] = "ain0",
+	[ADS1262_REFMUX_AIN2_AIN3] = "ain2",
+	[ADS1262_REFMUX_AIN4_AIN5] = "ain4",
+	[ADS1262_REFMUX_AVDD_AVSS] = "avdd"
+};
+
+static const char * const ads1262_ref_sources_negative[] = {
+	[ADS1262_REFMUX_INTERNAL] = "internal",
+	[ADS1262_REFMUX_AIN0_AIN1] = "ain1",
+	[ADS1262_REFMUX_AIN2_AIN3] = "ain3",
+	[ADS1262_REFMUX_AIN4_AIN5] = "ain5",
+	[ADS1262_REFMUX_AVDD_AVSS] = "avss"
+};
+
+static const char * const ads1262_ref_sources_adc2[] = {
+	[ADS1262_REFMUX_INTERNAL] = "internal",
+	[ADS1262_REFMUX_AIN0_AIN1] = "ain0-ain1",
+	[ADS1262_REFMUX_AIN2_AIN3] = "ain2-ain3",

drivers/iio/adc/ti-ads1262.c line 981

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	[ADS1262_REFMUX_AIN4_AIN5] = "ain4-ain5",
+	[ADS1262_REFMUX_AVDD_AVSS] = "avdd-avss"
+};
+
+static int ads1262_parse_channel_node(struct ads1262 *st,
+				      struct ads1262_channel *chan,
+				      struct fwnode_handle *node)
+{
+	struct device *dev = &st->spi->dev;
+	const char *ref_sources[3] = {};

IIO style is with space between { }.

Quoted 36 lines
drivers/iio/adc/ti-ads1262.c new file +36 -0
+	u32 pins[2];
+	int ret;
+
+	/* Write non-zero default configuration values */
+	chan->data_rate = ADS1262_DR_20_SPS;
+
+	ret = fwnode_property_read_u32_array(node, "diff-channels", pins, ARRAY_SIZE(pins));
+	if (ret)
+		return dev_err_probe(dev, ret, "%s: Failed to read diff-channels\n",
+				     fwnode_get_name(node));
+	if (pins[0] >= ADS1262_INPMUX_LAST || pins[1] >= ADS1262_INPMUX_LAST)
+		return dev_err_probe(dev, -EINVAL, "%s: input channels not in range\n",
+				     fwnode_get_name(node));
+	chan->input[0] = pins[0];
+	chan->input[1] = pins[1];
+
+	if (fwnode_property_present(node, "reference-sources")) {
+		ret = fwnode_property_read_string_array(node, "reference-sources", ref_sources,
+							st->info->has_aux_adc ? 3 : 2);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "%s: Failed to read reference-sources\n",
+					     fwnode_get_name(node));
+
+		ret = ads1262_find_string(ads1262_ref_sources_positive, ref_sources[0]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "%s: Invalid positive reference\n",
+					     fwnode_get_name(node));
+		chan->reference[0] = ret;
+
+		ret = ads1262_find_string(ads1262_ref_sources_negative, ref_sources[1]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret, "%s: Invalid negative reference\n",
+					     fwnode_get_name(node));
+		chan->reference[1] = ret;
+
+		if (st->info->has_aux_adc) {

drivers/iio/adc/ti-ads1262.c line 1027

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+			ret = ads1262_find_string(ads1262_ref_sources_adc2, ref_sources[2]);
+			if (ret < 0)
+				return dev_err_probe(dev, ret, "%s: Invalid ADC2 reference\n",
+						     fwnode_get_name(node));
+			chan->reference[2] = ret;
+		}
+	}
+
+	if (fwnode_property_present(node, "ti,pga-bypass"))
+		chan->pga_bypass = 1;

These can be one-line:

	chan->pga_bypass = fwnode_property_read_bool(node, "ti,pga-bypass");
Quoted 9 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+
+	if (fwnode_property_present(node, "input-chopping"))
+		chan->input_chop = 1;
+
+	if (fwnode_property_present(node, "ti,idac-chopping"))
+		chan->idac_chop = 1;
+
+	return ads1262_channel_sanity_check(st, chan);
+}

drivers/iio/adc/ti-ads1262.c line 1046

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+
+static int ads1262_parse_firmware(struct ads1262 *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct clk *clk;
+	u32 reg;
+	int ret;
+
+	/* Set the nominal clock frequency */
+	clk = devm_clk_get_optional_enabled_with_rate(dev, NULL, 7372800);

This is quite unusual. Usually an external clock would be a fixed clock and therefore can't be set.

drivers/iio/adc/ti-ads1262.c line 1055

Quoted 9 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk),
+				     "Failed to get external clock\n");
+
+	ret = devm_regulator_get_enable(dev, "dvdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get dvdd regulator\n");
+
+	st->avdd_uV = devm_regulator_get_enable_read_voltage(dev, "avdd");

We only need the voltage of avdd if it is actually used as a reference, which is probably quite rare. Not all regulators provide a voltage value.

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	if (st->avdd_uV < 0)
+		return dev_err_probe(dev, st->avdd_uV, "Failed to get avdd regulator\n");
+
+	st->refp_uV = devm_regulator_get_enable_read_voltage(dev, "refp");
+	if (st->refp_uV < 0 && st->refp_uV != -ENODEV)
+		return dev_err_probe(dev, st->refp_uV, "Failed to get refp regulator\n");
+
+	st->refn_uV = devm_regulator_get_enable_read_voltage(dev, "refn");
+	if (st->refn_uV < 0 && st->refn_uV != -ENODEV)
+		return dev_err_probe(dev, st->refn_uV, "Failed to get refn regulator\n");

drivers/iio/adc/ti-ads1262.c line 1075

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+
+	st->start_gpiod = devm_gpiod_get_optional(dev, "start", GPIOD_OUT_LOW);
+	if (IS_ERR(st->start_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->start_gpiod),
+				     "Failed to get start GPIO\n");
+
+	st->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(st->reset_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->reset_gpiod),
+				     "Failed to get reset GPIO\n");

This is currently never used.

Quoted 11 lines
drivers/iio/adc/ti-ads1262.c new file +11 -0
+
+	st->num_channels = device_get_named_child_node_count(dev, "channel");
+	if (!st->num_channels)
+		return dev_err_probe(dev, -ENXIO,
+				     "No 'channel' nodes configured\n");
+	if (st->num_channels > ADS1262_MAX_CHANNEL_COUNT)
+		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
+
+	st->channels = devm_kcalloc(dev, st->num_channels, sizeof(*st->channels),
+				    GFP_KERNEL);
+	if (!st->channels)

drivers/iio/adc/ti-ads1262.c line 1096

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+		return -ENOMEM;
+
+	device_for_each_named_child_node_scoped(dev, node, "channel") {
+		ret = fwnode_property_read_u32(node, "reg", &reg);
+		if (ret)
+			return dev_err_probe(dev, ret, "%s: Failed to read channel reg\n",
+					     fwnode_get_name(node));
+		if (reg >= st->num_channels)
+			return dev_err_probe(dev, -EINVAL, "%s: reg out of range\n",
+					     fwnode_get_name(node));

If reg is going to be the channel index, then we need to make sure there are no gaps in the array as well.

Quoted 20 lines
drivers/iio/adc/ti-ads1262.c new file +20 -0
+
+		ret = ads1262_parse_channel_node(st, &st->channels[reg], node);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int ads1262_spi_probe(struct spi_device *spi)
+{
+	const struct ads1262_chip_info *info;
+	struct iio_chan_spec *channels;
+	struct device *dev = &spi->dev;
+	struct iio_dev *indio_dev;
+	struct ads1262 *st;
+	int num_channels;
+	int ret;
+
+	info = spi_get_device_match_data(spi);

drivers/iio/adc/ti-ads1262.c line 1126

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	if (!info)
+		return -EINVAL;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi = spi;
+	st->indio_dev = indio_dev;

It is quite rare to need a circular reference between indio_dev and private data. We can eliminate it by passing indio_dev to ads1262_channel_read().

drivers/iio/adc/ti-ads1262.c line 1129

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c new file +3 -0
+	st->info = info;
+	init_completion(&st->drdy);
+	dev_set_drvdata(dev, st);

We never get this, so don't need to set it.

Quoted 25 lines
drivers/iio/adc/ti-ads1262.c new file +25 -0
+
+	ret = devm_mutex_init(dev, &st->chan_lock);
+	if (ret)
+		return ret;
+	ret = devm_mutex_init(dev, &st->xfer_lock);
+	if (ret)
+		return ret;
+
+	ret = ads1262_parse_firmware(st);
+	if (ret)
+		return ret;
+
+	st->regmap = devm_regmap_init(dev, &ads1262_regmap_bus, st,
+				      &ads1262_regmap_config);
+	if (IS_ERR(st->regmap))
+		return PTR_ERR(st->regmap);
+
+	ret = ads1262_dev_configure(st);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to configure device\n");
+
+	num_channels = ads1262_alloc_channels(st, &channels);
+	if (num_channels < 0)
+		return num_channels;
+	indio_dev->name = info->name;

drivers/iio/adc/ti-ads1262.c line 1164

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &ads1262_iio_info;
+	indio_dev->channels = channels;
+	indio_dev->num_channels = num_channels;
+
+	if (spi->irq > 0) {
+		ret = devm_request_irq(dev, spi->irq, ads1262_irq_handler,
+				       IRQF_NO_THREAD, info->name, st);
+		if (ret)
+			return ret;

It seems like the driver would not work without an interrupt currently so this should not be optional.

Quoted 43 lines
drivers/iio/adc/ti-ads1262.c new file +42 -0
+	}
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct ads1262_chip_info ads1262_chip_info = {
+	.name = "ads1262",
+	.has_aux_adc = false,
+};
+
+static const struct ads1262_chip_info ads1263_chip_info = {
+	.name = "ads1263",
+	.has_aux_adc = true,
+};
+
+static const struct of_device_id ads1262_of_match[] = {
+	{ .compatible = "ti,ads1263", .data = &ads1263_chip_info },
+	{ .compatible = "ti,ads1262", .data = &ads1262_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ads1262_of_match);
+
+static const struct spi_device_id ads1262_spi_match[] = {
+	{ .name = "ads1263", .driver_data = (kernel_ulong_t)&ads1263_chip_info },
+	{ .name = "ads1262", .driver_data = (kernel_ulong_t)&ads1262_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, ads1262_spi_match);
+
+static struct spi_driver ads1262_spi_driver = {
+	.driver = {
+		.name = "ads1262",
+		.of_match_table = ads1262_of_match,
+	},
+	.probe = ads1262_spi_probe,
+	.id_table = ads1262_spi_match,
+};
+module_spi_driver(ads1262_spi_driver);
+
+MODULE_DESCRIPTION("Texas Instruments ADS1262 ADC driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kurt Borja <[email protected]>");
author
#14 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

Quoted 13 lines · David Lechner
Quoted 11 lines · Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

---
 MAINTAINERS                  |    1 +
 drivers/iio/adc/Kconfig      |   13 +
 drivers/iio/adc/Makefile     |    1 +
 drivers/iio/adc/ti-ads1262.c | 1206 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1221 insertions(+)
Quoted 8 lines

Ideally, an intial patch would be 1/2 this size. Over 1000 lines in a single patch make it take more than twice as long to review as if it was split into two patches (or you just don't get a detailed review). For example, sample rate and gain can be split out into seprate patches.

I certainly don't have time to revew this plus an additonal 1000 lines of more patches on top of it in a week.

Sure, I'll split it even more.

[...]

Quoted 7 lines
Quoted 7 lines
drivers/iio/adc/ti-ads1262.c new file +7 -0
+static int ads1262_calculate_scale(struct ads1262 *st, u8 realbits, u8 gain,
+				   u8 pos_ref, u8 neg_ref, int *val, int *val2)
+{
+	u64 divd, divr, tmp, rem;
+	int pos_uV, neg_uV;
+
+	switch (pos_ref) {
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 368

Quoted 6 lines
drivers/iio/adc/ti-ads1262.c new file +6 -0
+	case ADS1262_REFMUX_INTERNAL:
+		/* Internal voltage reference is 2.5 V */
+		pos_uV = 2500000;
+		break;
+	case ADS1262_REFMUX_AIN0_AIN1...ADS1262_REFMUX_AIN4_AIN5:
+		pos_uV = st->refp_uV;

I don't think it is safe to assume the same reference is wired to all of these.

Yes, you're right. I'll add supplies for the other options.

[...]

Quoted 13 lines
Quoted 13 lines
drivers/iio/adc/ti-ads1262.c new file +13 -0
+static int ads1262_channel_enable(struct ads1262 *st,
+				  struct ads1262_channel *chan)
+{
+	u8 mode0, mode2, inpmux, refmux;
+	int ret;
+
+	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
+	mutex_lock(&st->chan_lock);
+	mode0 = FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |
+		FIELD_PREP(ADS1262_MODE0_IDAC_CHOP_MASK, chan->idac_chop) |
+		FIELD_PREP(ADS1262_MODE0_REFREV_MASK, chan->ref_reversal);
+	mode2 = FIELD_PREP(ADS1262_MODE2_DR_MASK, chan->data_rate) |
+		FIELD_PREP(ADS1262_MODE2_GAIN_MASK, chan->gain) |
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 459

Quoted 6 lines
drivers/iio/adc/ti-ads1262.c new file +6 -0
+		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
+	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
+		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
+		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
+	mutex_unlock(&st->chan_lock);

Why does lock not also include actually writing the bits?

Because we take the xfer_lock in that path. Later in the series, I'm forced to take the xfer_lock first, so that would be AB/BA bug. But...

See the regmap answer below.

[...]

Quoted 26 lines
Quoted 26 lines
drivers/iio/adc/ti-ads1262.c new file +26 -0
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 562

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

I went with hardwaregain because the scale loses too many significant digits at high gain. With the internal reference and gain = 1, the scale is at 0.000001164; then at gain = 32, the scale is at 0.000000036.

In this case I expect users to just calculate the scale themselves based on the hardwaregain. Is this acceptable? If not I'll go with scale_available.

[...]

Quoted 37 lines
Quoted 23 lines
drivers/iio/adc/ti-ads1262.c new file +23 -0
+static int ads1262_alloc_channels(struct ads1262 *st,
+				  struct iio_chan_spec **channels)
+{
+	struct device *dev = &st->spi->dev;
+	struct ads1262_channel *chan_data;
+	struct iio_chan_spec *chans;
+	unsigned int i, num_channels;
+
+	/* Account for the timestamp channel */
+	num_channels = st->num_channels + 1;
+	chans = devm_kcalloc(dev, num_channels, sizeof(*chans), GFP_KERNEL);
+	if (!chans)
+		return -ENOMEM;
+
+	for (i = 0; i < st->num_channels; i++) {
+		chan_data = &st->channels[i];
+		chans[i] = (struct iio_chan_spec) {
+			.type = IIO_VOLTAGE,
+			.channel = chan_data->input[0],
+			.channel2 = chan_data->input[1],
+			.scan_index = i,
+			.scan_type = {
+				.format = IIO_SCAN_FORMAT_SIGNED_INT,

drivers/iio/adc/ti-ads1262.c line 717

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+				.realbits = 32,
+				.storagebits = 32,
+				.endianness = IIO_BE,
+			},
+			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+					      BIT(IIO_CHAN_INFO_SCALE) |
+					      BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
+					      BIT(IIO_CHAN_INFO_SAMP_FREQ),
+			.info_mask_shared_by_type_available =
+				BIT(IIO_CHAN_INFO_HARDWAREGAIN) |

Gain available might make more sense as separate if there are restrictions on gain allowed due to other conditions.

Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+				BIT(IIO_CHAN_INFO_SAMP_FREQ),

Could be the same case with sampling frequency if filters can affect that.

Actually, sampling frequency takes precedence over the filter configuration. Some rates cause the chip to ignore the filter configuration.

Quoted 7 lines

drivers/iio/adc/ti-ads1262.c line 720

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c new file +2 -0
+			.indexed = true,
+			.differential = true,

These two make more sense closer to the top since they affect the channel naming along with type and channel.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		};
+	}

As mentioned in the DT bindings review, I would make the diagnostic channels fixed so that they don't have to be always specified in the devicetree.

I agree. I'll add the monitors here.

[...]

Quoted 8 lines
Quoted 8 lines
drivers/iio/adc/ti-ads1262.c new file +8 -0
+static int ads1262_regmap_read(void *context, const void *reg_buf,
+			       size_t reg_size, void *val_buf, size_t val_size)
+{
+	struct ads1262 *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->tx,
+		.rx_buf = st->rx,
+		.len = reg_size + 1 + val_size,
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 835

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+	};
+	int ret;
+
+	guard(mutex)(&st->xfer_lock);

SPI bus and regmap both already have their own locking, so putting a lock here seems out of place. Instead, the lock should be for higher-level operations where there are mulitple register access in a single operation.

I agree. I can definitely move this one to a "higher level". But IMO, because this also protects tx and rx buffers, it makes sense to have it here too.

Quoted 48 lines
Quoted 48 lines
drivers/iio/adc/ti-ads1262.c new file +47 -0
+
+	memset(st->tx, 0, reg_size + 1 + val_size);
+
+	memcpy(&st->tx[0], reg_buf, 1);
+	st->tx[1] = val_size - 1;
+
+	ret = spi_sync_transfer(st->spi, &xfer, 1);
+	if (ret)
+		return ret;
+
+	memcpy(val_buf, &st->rx[2], val_size);
+
+	return 0;
+}
+
+static int ads1262_regmap_gather_write(void *context, const void *reg_buf,
+				       size_t reg_size, const void *val_buf,
+				       size_t val_size)
+{
+	struct ads1262 *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->tx,
+		.rx_buf = st->rx,
+		.len = reg_size + 1 + val_size,
+	};
+
+	guard(mutex)(&st->xfer_lock);
+
+	memset(st->tx, 0, reg_size + 1 + val_size);
+
+	memcpy(&st->tx[0], reg_buf, 1);
+	st->tx[1] = val_size - 1;
+	memcpy(&st->tx[2], val_buf, val_size);
+
+	return spi_sync_transfer(st->spi, &xfer, 1);
+}
+
+static int ads1262_regmap_write(void *context, const void *data, size_t count)
+{
+	return ads1262_regmap_gather_write(context, data, 1, data + 1,
+					   count - 1);
+}
+
+static const struct regmap_bus ads1262_regmap_bus = {
+	.read = ads1262_regmap_read,
+	.gather_write = ads1262_regmap_gather_write,
+	.write = ads1262_regmap_write,
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 888

Quoted 6 lines
drivers/iio/adc/ti-ads1262.c new file +6 -0
+	.reg_format_endian_default = REGMAP_ENDIAN_BIG,
+	.val_format_endian_default = REGMAP_ENDIAN_BIG,
+	/* The first two bytes of the buffer are reserved for the protocol */
+	.max_raw_read = ADS1262_XFER_BUFFER_SZ - 2,
+	.max_raw_write = ADS1262_XFER_BUFFER_SZ - 2,
+};

Why do we need our own bus instead of using REGMAP_SPI?

Because the protocol is different. Read/write protocol for this chip is

first reg + command | number of regs - 1 | reg values

while regmap_spi is

first reg | reg values

I had a comment explaining this, but I forgot to restore it.

[...]

Quoted 4 lines
Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+static int ads1262_parse_firmware(struct ads1262 *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct clk *clk;
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 1046

Quoted 5 lines
drivers/iio/adc/ti-ads1262.c new file +5 -0
+	u32 reg;
+	int ret;
+
+	/* Set the nominal clock frequency */
+	clk = devm_clk_get_optional_enabled_with_rate(dev, NULL, 7372800);

This is quite unusual. Usually an external clock would be a fixed clock and therefore can't be set.

Really? It can be a crystal of course, but it also can be anything else. Shouldn't I be trying to set the clock frequency in that case?

Quoted 13 lines

drivers/iio/adc/ti-ads1262.c line 1055

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk),
+				     "Failed to get external clock\n");
+
+	ret = devm_regulator_get_enable(dev, "dvdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get dvdd regulator\n");
+
+	st->avdd_uV = devm_regulator_get_enable_read_voltage(dev, "avdd");

We only need the voltage of avdd if it is actually used as a reference, which is probably quite rare. Not all regulators provide a voltage value.

Then I should just check for ENODEV here.

Quoted 15 lines
Quoted 15 lines
drivers/iio/adc/ti-ads1262.c new file +14 -0
+	if (st->avdd_uV < 0)
+		return dev_err_probe(dev, st->avdd_uV, "Failed to get avdd regulator\n");
+
+	st->refp_uV = devm_regulator_get_enable_read_voltage(dev, "refp");
+	if (st->refp_uV < 0 && st->refp_uV != -ENODEV)
+		return dev_err_probe(dev, st->refp_uV, "Failed to get refp regulator\n");
+
+	st->refn_uV = devm_regulator_get_enable_read_voltage(dev, "refn");
+	if (st->refn_uV < 0 && st->refn_uV != -ENODEV)
+		return dev_err_probe(dev, st->refn_uV, "Failed to get refn regulator\n");
+
+	st->start_gpiod = devm_gpiod_get_optional(dev, "start", GPIOD_OUT_LOW);
+	if (IS_ERR(st->start_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->start_gpiod),
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 1075

Quoted 6 lines
drivers/iio/adc/ti-ads1262.c new file +6 -0
+				     "Failed to get start GPIO\n");
+
+	st->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(st->reset_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->reset_gpiod),
+				     "Failed to get reset GPIO\n");

This is currently never used.

It has to be de-asserted for the chip to be in an active state though.

[...]

Quoted 3 lines

drivers/iio/adc/ti-ads1262.c line 1206

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c new file +3 -0
+MODULE_DESCRIPTION("Texas Instruments ADS1262 ADC driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kurt Borja <[email protected]>");

I agree with all other comments. Thanks a lot for the review!

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#15 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

Quoted 6 lines · Kurt Borja
Quoted 5 lines · David Lechner
Quoted 4 lines · Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

...

Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
drivers/iio/adc/ti-ads1262.c new file +26 -0
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 562

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

Quoted 7 lines

I went with hardwaregain because the scale loses too many significant digits at high gain. With the internal reference and gain = 1, the scale is at 0.000001164; then at gain = 32, the scale is at 0.000000036.

In this case I expect users to just calculate the scale themselves based on the hardwaregain. Is this acceptable? If not I'll go with scale_available.

I'm pretty sure there is a series floating around that has proposed adding new fixed-point IIO_VAL_* types that could be another solution. We'll see what Jonathan says about this too.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/iio/adc/ti-ads1262.c new file +8 -0
+static int ads1262_regmap_read(void *context, const void *reg_buf,
+			       size_t reg_size, void *val_buf, size_t val_size)
+{
+	struct ads1262 *st = context;
+	struct spi_transfer xfer = {
+		.tx_buf = st->tx,
+		.rx_buf = st->rx,
+		.len = reg_size + 1 + val_size,
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 835

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+	};
+	int ret;
+
+	guard(mutex)(&st->xfer_lock);

SPI bus and regmap both already have their own locking, so putting a lock here seems out of place. Instead, the lock should be for higher-level operations where there are mulitple register access in a single operation.

Quoted 3 lines

I agree. I can definitely move this one to a "higher level". But IMO, because this also protects tx and rx buffers, it makes sense to have it here too.

It still seems redundant to me to have a lower-level lock if we have a higher-level lock that is always going to be held anyway. But maybe there is some case where it still makes sense?

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+static int ads1262_parse_firmware(struct ads1262 *st)
+{
+	struct device *dev = &st->spi->dev;
+	struct clk *clk;
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 1046

Quoted 5 lines
drivers/iio/adc/ti-ads1262.c new file +5 -0
+	u32 reg;
+	int ret;
+
+	/* Set the nominal clock frequency */
+	clk = devm_clk_get_optional_enabled_with_rate(dev, NULL, 7372800);

This is quite unusual. Usually an external clock would be a fixed clock and therefore can't be set.

Quoted 2 lines

Really? It can be a crystal of course, but it also can be anything else. Shouldn't I be trying to set the clock frequency in that case?

According to the datasheet, 7.3728 MHz is just the nominal value while 1 to 8 MHz is allowed. So I would expect the external clock to already be providing the chosen design-specific rate and we should be getting the rate here, not setting it.

Quoted 15 lines
Quoted 14 lines

drivers/iio/adc/ti-ads1262.c line 1055

Quoted 11 lines
drivers/iio/adc/ti-ads1262.c new file +9 -0
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk),
+				     "Failed to get external clock\n");
+
+	ret = devm_regulator_get_enable(dev, "dvdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get dvdd regulator\n");
+
+	st->avdd_uV = devm_regulator_get_enable_read_voltage(dev, "avdd");

We only need the voltage of avdd if it is actually used as a reference, which is probably quite rare. Not all regulators provide a voltage value.

Quoted 1 line

Then I should just check for ENODEV here.

Except AVDD is a required supply. They way I did it in the driver I am working on is first parse all of the channels to see if anything is actually using AVDD as a reference and only call devm_regulator_get_enable_read_voltage() in that case, otherwise call devm_regulator_get_enable().

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/iio/adc/ti-ads1262.c new file +14 -0
+	if (st->avdd_uV < 0)
+		return dev_err_probe(dev, st->avdd_uV, "Failed to get avdd regulator\n");
+
+	st->refp_uV = devm_regulator_get_enable_read_voltage(dev, "refp");
+	if (st->refp_uV < 0 && st->refp_uV != -ENODEV)
+		return dev_err_probe(dev, st->refp_uV, "Failed to get refp regulator\n");
+
+	st->refn_uV = devm_regulator_get_enable_read_voltage(dev, "refn");
+	if (st->refn_uV < 0 && st->refn_uV != -ENODEV)
+		return dev_err_probe(dev, st->refn_uV, "Failed to get refn regulator\n");
+
+	st->start_gpiod = devm_gpiod_get_optional(dev, "start", GPIOD_OUT_LOW);
+	if (IS_ERR(st->start_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->start_gpiod),
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 1075

Quoted 6 lines
drivers/iio/adc/ti-ads1262.c new file +6 -0
+				     "Failed to get start GPIO\n");
+
+	st->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(st->reset_gpiod))
+		return dev_err_probe(dev, PTR_ERR(st->reset_gpiod),
+				     "Failed to get reset GPIO\n");

This is currently never used.

Quoted 2 lines

It has to be de-asserted for the chip to be in an active state though.

Usually, if we have hardware reset available, we use it to reset instead of writing a register to do the reset.

maintainer
#16 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

Quoted 49 lines · On Mon, 29 Jun 2026 09:38:13 -0500 David Lechner <[email protected]> wrote:
Quoted 6 lines · Kurt Borja
Quoted 5 lines · David Lechner
Quoted 4 lines · Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

...

Quoted 39 lines
Quoted 26 lines
Quoted 26 lines
drivers/iio/adc/ti-ads1262.c new file +26 -0
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 562

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {  

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

I went with hardwaregain because the scale loses too many significant digits at high gain. With the internal reference and gain = 1, the scale is at 0.000001164; then at gain = 32, the scale is at 0.000000036.

Quoted 7 lines
Quoted 3 lines

In this case I expect users to just calculate the scale themselves based on the hardwaregain. Is this acceptable? If not I'll go with scale_available.

I'm pretty sure there is a series floating around that has proposed adding new fixed-point IIO_VAL_* types that could be another solution. We'll see what Jonathan says about this too.

Yup. That series should allow for easy representation of very small values.

It's in my testing branch already (see iio.git on kernel.org) and IIO_VAL_DECIMAL64_PICO for most extreme case.

HARDWAREGAIN doesn't seem appropriate here, so please do the really small scales instead.

Thanks,

Jonathan

author
#17 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

Quoted 60 lines · Jonathan Cameron
Quoted 49 lines · On Mon, 29 Jun 2026 09:38:13 -0500 David Lechner <[email protected]> wrote:
Quoted 6 lines · Kurt Borja
Quoted 5 lines · David Lechner
Quoted 4 lines · Kurt Borja

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

...

Quoted 39 lines
Quoted 26 lines
Quoted 26 lines
drivers/iio/adc/ti-ads1262.c new file +26 -0
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 562

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {  

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

I went with hardwaregain because the scale loses too many significant digits at high gain. With the internal reference and gain = 1, the scale is at 0.000001164; then at gain = 32, the scale is at 0.000000036.

Quoted 7 lines
Quoted 3 lines

In this case I expect users to just calculate the scale themselves based on the hardwaregain. Is this acceptable? If not I'll go with scale_available.

I'm pretty sure there is a series floating around that has proposed adding new fixed-point IIO_VAL_* types that could be another solution. We'll see what Jonathan says about this too.

Quoted 7 lines

Yup. That series should allow for easy representation of very small values.

It's in my testing branch already (see iio.git on kernel.org) and IIO_VAL_DECIMAL64_PICO for most extreme case.

HARDWAREGAIN doesn't seem appropriate here, so please do the really small scales instead.

IIO_VAL_DECIMAL64_PICO is just what I needed. I'll go for that, thanks!

Quoted 4 lines

Thanks,

Jonathan

Signature · 2 lines
Thanks,
 ~ Kurt
maintainer
#18 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

In reply to David Lechner
Quoted 26 lines
Quoted 26 lines
drivers/iio/adc/ti-ads1262.c new file +26 -0
+static int ads1262_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data = &st->channels[chan->scan_index];
+	u8 realbits = chan->scan_type.realbits;
+	__be32 raw;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ads1262_channel_read(st, chan_data, &raw);
+		if (ret)
+			return ret;
+		*val = sign_extend32(be32_to_cpu(raw), realbits - 1);
+
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE: {
+		guard(mutex)(&st->chan_lock);
+
+		ret = ads1262_channel_get_scale(st, chan, val, val2);
+		if (ret)
+			return ret;
+
Quoted 8 lines

drivers/iio/adc/ti-ads1262.c line 562

Quoted 4 lines
drivers/iio/adc/ti-ads1262.c new file +4 -0
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {  

There is only one other ADC that uses "hardwaregain". Usually, we just make scale writeable to control the gain. I don't remember what the rules for that attribute are. Using it for in_voltage is not documented in the ABI.

Roughly speaking it should only be used when the gain is no affecting the thing being measured (so we can't do it with _scale). Examples are things like the gain on a time of flight sensor - it affects how likely we are to get a measurement, not what the measurement is.

Hmm. The one ADC using is the ina2xx - that's a weird device so it would take some digging to try and figure out why that one go through review.

Quoted 21 lines
Quoted 21 lines
drivers/iio/adc/ti-ads1262.c new file +20 -0
+		guard(mutex)(&st->chan_lock);
+
+		*val = ads1262_pga_gain_avail[chan_data->gain];
+
+		return IIO_VAL_INT;
+	}
+
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		guard(mutex)(&st->chan_lock);
+
+		*val = ads1262_data_rate_avail[chan_data->data_rate][0];
+		*val2 = ads1262_data_rate_avail[chan_data->data_rate][1];
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+
+	default:
+		return -EOPNOTSUPP;
+	}
+}
maintainer
#19 lore raw

Re: [PATCH v2 2/7] iio: adc: Add ti-ads1262 driver

In reply to Kurt Borja
Quoted 5 lines · On Sun, 28 Jun 2026 00:36:03 -0500 Kurt Borja <[email protected]> wrote:

Add the ti-ads1262 driver with initial support for the primary ADC (ADC1). The ADS1263 auxiliary ADC (ADC2) is handled by a separate driver and interoperability considerations were taken into account.

I took a quick look and vast majority of stuff I found was already well covered by David. I'll take a more detailed look at next version.

One trivial thing inline.

Thanks,

Jonathan

Quoted 19 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
new file mode 100644
index 0000000000000000..6103cf5a2d1624a9
 
 
 
 
+static int ads1262_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan, int val,
+			     int val2, long mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data;
+	int i;
+
+	chan_data = &st->channels[chan->scan_index];
+

drivers/iio/adc/ti-ads1262.c line 625

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c new file +10 -0
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ: {
+		i = ads1262_find_two(ads1262_data_rate_avail, val, val2);
+		if (i < 0)
+			return i;
+
+		guard(mutex)(&st->chan_lock);
+		chan_data->data_rate = i;
+
+		break;

Trivial but might as well return 0 here and save a reader going to look for what else happens after the switch.

Quoted 19 lines
drivers/iio/adc/ti-ads1262.c new file +19 -0
+	}
+
+	case IIO_CHAN_INFO_HARDWAREGAIN: {
+		i = ads1262_find_one(ads1262_pga_gain_avail, val);
+		if (i < 0)
+			return i;
+
+		guard(mutex)(&st->chan_lock);
+		chan_data->gain = i;
+
+		break;
+	}
+
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
author
#20 lore raw

PATCH v2 3/7 iio: adc: ti-ads1262: Add channel filter support

In reply to Kurt Borja

Expose per-channel filter configuration through the filter_type attribute.

---
 drivers/iio/adc/ti-ads1262.c | 65 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)
drivers/iio/adc/ti-ads1262.c +64 -1
index 6103cf5a2d1624a9..ece97a0c2b1304ad 100644
@@ -146,6 +146,14 @@ enum {
 	ADS1262_RUNMODE_PULSE,
 };
 
+enum {
+	ADS1262_FILTER_SINC1,
+	ADS1262_FILTER_SINC2,
+	ADS1262_FILTER_SINC3,
+	ADS1262_FILTER_SINC4,
+	ADS1262_FILTER_FIR,
+};
+
 enum {
 	ADS1262_DR_2_5_SPS,
 	ADS1262_DR_5_SPS,
@@ -201,6 +209,7 @@ struct ads1262_chip_info {
 
 struct ads1262_channel {
 	u8 input[2];
+	u8 filter;
 	u8 gain;
 	u8 data_rate;
 	u8 reference[3];
@@ -441,7 +450,7 @@ static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)
 static int ads1262_channel_enable(struct ads1262 *st,
 				  struct ads1262_channel *chan)
 {
-	u8 mode0, mode2, inpmux, refmux;
+	u8 mode0, mode1, mode2, inpmux, refmux;
 	int ret;
 
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
@@ -449,6 +458,7 @@ static int ads1262_channel_enable(struct ads1262 *st,
 	mode0 = FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |
 		FIELD_PREP(ADS1262_MODE0_IDAC_CHOP_MASK, chan->idac_chop) |
 		FIELD_PREP(ADS1262_MODE0_REFREV_MASK, chan->ref_reversal);
+	mode1 = FIELD_PREP(ADS1262_MODE1_FILTER_MASK, chan->filter);
 	mode2 = FIELD_PREP(ADS1262_MODE2_DR_MASK, chan->data_rate) |
 		FIELD_PREP(ADS1262_MODE2_GAIN_MASK, chan->gain) |
 		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
@@ -465,6 +475,11 @@ static int ads1262_channel_enable(struct ads1262 *st,
 	if (ret)
 		return ret;
 
+	ret = regmap_update_bits(st->regmap, ADS1262_MODE1_REG,
+				 ADS1262_MODE1_FILTER_MASK, mode1);
+	if (ret)
+		return ret;
+
 	ret = regmap_update_bits(st->regmap, ADS1262_MODE2_REG,
 				 ADS1262_MODE2_DR_MASK |
 				 ADS1262_MODE2_GAIN_MASK |
@@ -682,6 +697,52 @@ static irqreturn_t ads1262_irq_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static int ads1262_get_filter_type(struct iio_dev *indio_dev,
+				   const struct iio_chan_spec *chan)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct ads1262_channel *chan_data;
+
+	guard(mutex)(&st->chan_lock);
+
+	chan_data = &st->channels[chan->scan_index];
+	return chan_data->filter;
+}
+
+static int ads1262_set_filter_type(struct iio_dev *indio_dev,
+				   const struct iio_chan_spec *chan,
+				   unsigned int val)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+
+	guard(mutex)(&st->chan_lock);
+	st->channels[chan->scan_index].filter = val;
+
+	return 0;
+}
+
+static const char * const ads1262_filter_type_labels[] = {
+	[ADS1262_FILTER_SINC1] = "sinc1",
+	[ADS1262_FILTER_SINC2] = "sinc2",
+	[ADS1262_FILTER_SINC3] = "sinc3",
+	[ADS1262_FILTER_SINC4] = "sinc4",
+	[ADS1262_FILTER_FIR] = "fir",
+};
+
+static const struct iio_enum ads1262_filter_type_enum = {
+	.items = ads1262_filter_type_labels,
+	.num_items = ARRAY_SIZE(ads1262_filter_type_labels),
+	.get = ads1262_get_filter_type,
+	.set = ads1262_set_filter_type,
+};
+
+static const struct iio_chan_spec_ext_info ads1262_ext_info[] = {
+	IIO_ENUM("filter_type", IIO_SEPARATE, &ads1262_filter_type_enum),
+	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_TYPE,
+			   &ads1262_filter_type_enum),
+	{ }
+};
+
 static int ads1262_alloc_channels(struct ads1262 *st,
 				  struct iio_chan_spec **channels)
 {
@@ -718,6 +779,7 @@ static int ads1262_alloc_channels(struct ads1262 *st,
 				BIT(IIO_CHAN_INFO_SAMP_FREQ),
 			.indexed = true,
 			.differential = true,
+			.ext_info = ads1262_ext_info,
 		};
 	}
 
@@ -983,6 +1045,7 @@ static int ads1262_parse_channel_node(struct ads1262 *st,
 	int ret;
 
 	/* Write non-zero default configuration values */
+	chan->filter = ADS1262_FILTER_FIR;
 	chan->data_rate = ADS1262_DR_20_SPS;
 
 	ret = fwnode_property_read_u32_array(node, "diff-channels", pins, ARRAY_SIZE(pins));
Signature · 1 line
2.54.0
author
#21 lore raw

PATCH v2 4/7 iio: adc: ti-ads1262: Add excitation current support

In reply to Kurt Borja

Support the two IDAC excitation current sources. Each channel can route its IDAC1/IDAC2 outputs to a pin via the "excitation-channels" property and select a magnitude via "excitation-current-nanoamp".

---
 drivers/iio/adc/ti-ads1262.c | 78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads1262.c +76 -2
index ece97a0c2b1304ad..8921eaae537f6b0a 100644
@@ -193,6 +193,22 @@ enum {
 	ADS1262_INPMUX_LAST
 };
 
+enum {
+	ADS1262_IDACMUX_AIN0,
+	ADS1262_IDACMUX_AIN1,
+	ADS1262_IDACMUX_AIN2,
+	ADS1262_IDACMUX_AIN3,
+	ADS1262_IDACMUX_AIN4,
+	ADS1262_IDACMUX_AIN5,
+	ADS1262_IDACMUX_AIN6,
+	ADS1262_IDACMUX_AIN7,
+	ADS1262_IDACMUX_AIN8,
+	ADS1262_IDACMUX_AIN9,
+	ADS1262_IDACMUX_AINCOM,
+	ADS1262_IDACMUX_NO_CONN,
+	ADS1262_IDACMUX_LAST
+};
+
 enum {
 	ADS1262_REFMUX_INTERNAL,
 	ADS1262_REFMUX_AIN0_AIN1,
@@ -213,6 +229,8 @@ struct ads1262_channel {
 	u8 gain;
 	u8 data_rate;
 	u8 reference[3];
+	u8 idac_mux[2];
+	u8 idac_mag[2];
 	u8 pga_bypass:1;
 	u8 ref_reversal:1;
 	u8 input_chop:1;
@@ -450,7 +468,7 @@ static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)
 static int ads1262_channel_enable(struct ads1262 *st,
 				  struct ads1262_channel *chan)
 {
-	u8 mode0, mode1, mode2, inpmux, refmux;
+	u8 mode0, mode1, mode2, inpmux, idacmux, idacmag, refmux;
 	int ret;
 
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
@@ -464,6 +482,10 @@ static int ads1262_channel_enable(struct ads1262 *st,
 		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
 	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
 		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	idacmux = FIELD_PREP(ADS1262_IDACMUX_MUX1_MASK, chan->idac_mux[0]) |
+		  FIELD_PREP(ADS1262_IDACMUX_MUX2_MASK, chan->idac_mux[1]);
+	idacmag = FIELD_PREP(ADS1262_IDACMAG_MAG1_MASK, chan->idac_mag[0]) |
+		  FIELD_PREP(ADS1262_IDACMAG_MAG2_MASK, chan->idac_mag[1]);
 	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
 		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
 	mutex_unlock(&st->chan_lock);
@@ -493,6 +515,18 @@ static int ads1262_channel_enable(struct ads1262 *st,
 	if (ret)
 		return ret;
 
+	ret = regmap_update_bits(st->regmap, ADS1262_IDACMUX_REG,
+				 ADS1262_IDACMUX_MUX1_MASK |
+				 ADS1262_IDACMUX_MUX2_MASK, idacmux);
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(st->regmap, ADS1262_IDACMAG_REG,
+				 ADS1262_IDACMAG_MAG1_MASK |
+				 ADS1262_IDACMAG_MAG2_MASK, idacmag);
+	if (ret)
+		return ret;
+
 	return regmap_update_bits(st->regmap, ADS1262_REFMUX_REG,
 				  ADS1262_REFMUX_RMUXN_MASK |
 				  ADS1262_REFMUX_RMUXP_MASK, refmux);
@@ -1040,13 +1074,19 @@ static int ads1262_parse_channel_node(struct ads1262 *st,
 				      struct fwnode_handle *node)
 {
 	struct device *dev = &st->spi->dev;
+	static const u32 idac_nA[] = {
+		0, 50000, 100000, 250000, 500000, 750000,
+		1000000, 1500000, 2000000, 2500000, 3000000
+	};
 	const char *ref_sources[3] = {};
-	u32 pins[2];
+	u32 pins[2], mags[2];
 	int ret;
 
 	/* Write non-zero default configuration values */
 	chan->filter = ADS1262_FILTER_FIR;
 	chan->data_rate = ADS1262_DR_20_SPS;
+	chan->idac_mux[0] = ADS1262_IDACMUX_NO_CONN;
+	chan->idac_mux[1] = ADS1262_IDACMUX_NO_CONN;
 
 	ret = fwnode_property_read_u32_array(node, "diff-channels", pins, ARRAY_SIZE(pins));
 	if (ret)
@@ -1086,6 +1126,40 @@ static int ads1262_parse_channel_node(struct ads1262 *st,
 		}
 	}
 
+	if (fwnode_property_present(node, "excitation-channels")) {
+		ret = fwnode_property_read_u32_array(node, "excitation-channels",
+						     pins, ARRAY_SIZE(pins));
+		if (ret)
+			return dev_err_probe(dev, ret, "%s: Failed to read excitation-channels\n",
+					     fwnode_get_name(node));
+		if (pins[0] >= ADS1262_IDACMUX_LAST || pins[1] >= ADS1262_IDACMUX_LAST)
+			return dev_err_probe(dev, -EINVAL, "%s: excitation-channels not in range\n",
+					     fwnode_get_name(node));
+		chan->idac_mux[0] = pins[0];
+		chan->idac_mux[1] = pins[1];
+
+		ret = fwnode_property_read_u32_array(node, "excitation-current-nanoamp",
+						     mags, ARRAY_SIZE(mags));
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "%s: Failed to read excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+
+		ret = ads1262_find_one(idac_nA, mags[0]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret,
+					     "%s: Invalid excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+		chan->idac_mag[0] = ret;
+
+		ret = ads1262_find_one(idac_nA, mags[1]);
+		if (ret < 0)
+			return dev_err_probe(dev, ret,
+					     "%s: Invalid excitation-current-nanoamp\n",
+					     fwnode_get_name(node));
+		chan->idac_mag[1] = ret;
+	}
+
 	if (fwnode_property_present(node, "ti,pga-bypass"))
 		chan->pga_bypass = 1;
 
Signature · 1 line
2.54.0
maintainer
#22 lore raw

Re: [PATCH v2 4/7] iio: adc: ti-ads1262: Add excitation current support

Quoted 21 lines · On Sun, 28 Jun 2026 00:36:05 -0500 Kurt Borja <[email protected]> wrote:

Support the two IDAC excitation current sources. Each channel can route its IDAC1/IDAC2 outputs to a pin via the "excitation-channels" property and select a magnitude via "excitation-current-nanoamp".

---
 drivers/iio/adc/ti-ads1262.c | 78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads1262.c +4 -0
index ece97a0c2b1304ad..8921eaae537f6b0a 100644
@@ -193,6 +193,22 @@ enum {
 	ADS1262_INPMUX_LAST
 };
 
+enum {
+	ADS1262_IDACMUX_AIN0,
+	ADS1262_IDACMUX_AIN1,
+	ADS1262_IDACMUX_AIN2,

drivers/iio/adc/ti-ads1262.c enum { · line 209

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c +10 -0
+	ADS1262_IDACMUX_AIN3,
+	ADS1262_IDACMUX_AIN4,
+	ADS1262_IDACMUX_AIN5,
+	ADS1262_IDACMUX_AIN6,
+	ADS1262_IDACMUX_AIN7,
+	ADS1262_IDACMUX_AIN8,
+	ADS1262_IDACMUX_AIN9,
+	ADS1262_IDACMUX_AINCOM,
+	ADS1262_IDACMUX_NO_CONN,
+	ADS1262_IDACMUX_LAST

_LAST usually means inclusive. So probably call this NUM or something like that to show that it should be one more than last value.

Quoted 12 lines
drivers/iio/adc/ti-ads1262.c +2 -1
+};
 
@@ -450,7 +468,7 @@ static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)
 static int ads1262_channel_enable(struct ads1262 *st,
 				  struct ads1262_channel *chan)
 {
-	u8 mode0, mode1, mode2, inpmux, refmux;
+	u8 mode0, mode1, mode2, inpmux, idacmux, idacmag, refmux;
 	int ret;
 
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */

drivers/iio/adc/ti-ads1262.c static int ads1262_channel_enable(struct ads1262 *st, · line 488

Quoted 7 lines
drivers/iio/adc/ti-ads1262.c +4 -0
@@ -464,6 +482,10 @@ static int ads1262_channel_enable(struct ads1262 *st,
 		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
 	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
 		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	idacmux = FIELD_PREP(ADS1262_IDACMUX_MUX1_MASK, chan->idac_mux[0]) |
+		  FIELD_PREP(ADS1262_IDACMUX_MUX2_MASK, chan->idac_mux[1]);
+	idacmag = FIELD_PREP(ADS1262_IDACMAG_MAG1_MASK, chan->idac_mag[0]) |
+		  FIELD_PREP(ADS1262_IDACMAG_MAG2_MASK, chan->idac_mag[1]);

This presumably feeds into the discussion of locking that you were having with David, but I'd find this a lot easier to read if these were just above where the values are used. Then we can clearly see the match between masks and fields. If you have to do it like this, then add variables up here for the masks as well.

Quoted 3 lines
drivers/iio/adc/ti-ads1262.c +0 -0
 	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
 		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
 	mutex_unlock(&st->chan_lock);
author
#23 lore raw

Re: [PATCH v2 4/7] iio: adc: ti-ads1262: Add excitation current support

Quoted 48 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 28 Jun 2026 00:36:05 -0500 Kurt Borja <[email protected]> wrote:

Support the two IDAC excitation current sources. Each channel can route its IDAC1/IDAC2 outputs to a pin via the "excitation-channels" property and select a magnitude via "excitation-current-nanoamp".

---
 drivers/iio/adc/ti-ads1262.c | 78 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 2 deletions(-)
drivers/iio/adc/ti-ads1262.c +4 -0
index ece97a0c2b1304ad..8921eaae537f6b0a 100644
@@ -193,6 +193,22 @@ enum {
 	ADS1262_INPMUX_LAST
 };
 
+enum {
+	ADS1262_IDACMUX_AIN0,
+	ADS1262_IDACMUX_AIN1,
+	ADS1262_IDACMUX_AIN2,

drivers/iio/adc/ti-ads1262.c enum { · line 209

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c +10 -0
+	ADS1262_IDACMUX_AIN3,
+	ADS1262_IDACMUX_AIN4,
+	ADS1262_IDACMUX_AIN5,
+	ADS1262_IDACMUX_AIN6,
+	ADS1262_IDACMUX_AIN7,
+	ADS1262_IDACMUX_AIN8,
+	ADS1262_IDACMUX_AIN9,
+	ADS1262_IDACMUX_AINCOM,
+	ADS1262_IDACMUX_NO_CONN,
+	ADS1262_IDACMUX_LAST

_LAST usually means inclusive. So probably call this NUM or something like that to show that it should be one more than last value.

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c +2 -1
+};
 
@@ -450,7 +468,7 @@ static int ads1262_dev_read_by_cmd(struct ads1262 *st, u8 cmd, __be32 *val)
 static int ads1262_channel_enable(struct ads1262 *st,
 				  struct ads1262_channel *chan)
 {
-	u8 mode0, mode1, mode2, inpmux, refmux;
+	u8 mode0, mode1, mode2, inpmux, idacmux, idacmag, refmux;
 	int ret;
 
Quoted 15 lines

drivers/iio/adc/ti-ads1262.c static int ads1262_channel_enable(struct ads1262 *st, · line 488

Quoted 9 lines
drivers/iio/adc/ti-ads1262.c +4 -0
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
@@ -464,6 +482,10 @@ static int ads1262_channel_enable(struct ads1262 *st,
 		FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
 	inpmux = FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]) |
 		 FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]);
+	idacmux = FIELD_PREP(ADS1262_IDACMUX_MUX1_MASK, chan->idac_mux[0]) |
+		  FIELD_PREP(ADS1262_IDACMUX_MUX2_MASK, chan->idac_mux[1]);
+	idacmag = FIELD_PREP(ADS1262_IDACMAG_MAG1_MASK, chan->idac_mag[0]) |
+		  FIELD_PREP(ADS1262_IDACMAG_MAG2_MASK, chan->idac_mag[1]);

This presumably feeds into the discussion of locking that you were having with David, but I'd find this a lot easier to read if these were just above where the values are used. Then we can clearly see the match between masks and fields. If you have to do it like this, then add variables up here for the masks as well.

I'll move them above each regmap calls after reorganizing the locking stuff.

Quoted 5 lines
Quoted 5 lines
drivers/iio/adc/ti-ads1262.c +0 -0
 	refmux = FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]) |
 		 FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]);
 	mutex_unlock(&st->chan_lock);
Signature · 2 lines
Thanks,
 ~ Kurt
author
#24 lore raw

PATCH v2 5/7 iio: adc: ti-ads1262: Add conversion delay support

In reply to Kurt Borja

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

---
 drivers/iio/adc/ti-ads1262.c | 63 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
drivers/iio/adc/ti-ads1262.c +62 -1
index 8921eaae537f6b0a..4ae22c1b0b4b7d79 100644
@@ -141,6 +141,21 @@
 #define ADS1262_MAX_CHANNEL_COUNT		16
 #define ADS1262_XFER_BUFFER_SZ			11
 
+enum {
+	ADS1262_DELAY_NO_DELAY,
+	ADS1262_DELAY_8700_NS,
+	ADS1262_DELAY_17_US,
+	ADS1262_DELAY_35_US,
+	ADS1262_DELAY_69_US,
+	ADS1262_DELAY_139_US,
+	ADS1262_DELAY_278_US,
+	ADS1262_DELAY_555_US,
+	ADS1262_DELAY_1100_US,
+	ADS1262_DELAY_2200_US,
+	ADS1262_DELAY_4400_US,
+	ADS1262_DELAY_8800_US,
+};
+
 enum {
 	ADS1262_RUNMODE_CONTINUOUS,
 	ADS1262_RUNMODE_PULSE,
@@ -225,6 +240,7 @@ struct ads1262_chip_info {
 
 struct ads1262_channel {
 	u8 input[2];
+	u8 delay;
 	u8 filter;
 	u8 gain;
 	u8 data_rate;
@@ -281,6 +297,21 @@ static const int ads1262_data_rate_avail[][2] = {
 	[ADS1262_DR_38400_SPS]	= { 38400,	0 },
 };
 
+static const int ads1262_conv_delay_avail[][2] = {
+	[ADS1262_DELAY_NO_DELAY]	= { 0, 0 },
+	[ADS1262_DELAY_8700_NS]		= { 0, 8700 },
+	[ADS1262_DELAY_17_US]		= { 0, 17000 },
+	[ADS1262_DELAY_35_US]		= { 0, 35000 },
+	[ADS1262_DELAY_69_US]		= { 0, 69000 },
+	[ADS1262_DELAY_139_US]		= { 0, 139000 },
+	[ADS1262_DELAY_278_US]		= { 0, 278000 },
+	[ADS1262_DELAY_555_US]		= { 0, 555000 },
+	[ADS1262_DELAY_1100_US]		= { 0, 1100000 },
+	[ADS1262_DELAY_2200_US]		= { 0, 2200000 },
+	[ADS1262_DELAY_4400_US]		= { 0, 4400000 },
+	[ADS1262_DELAY_8800_US]		= { 0, 8800000 },
+};
+
 static const int ads1262_pga_gain_avail[] = {
 	1, 2, 4, 8, 16, 32
 };
@@ -473,7 +504,8 @@ static int ads1262_channel_enable(struct ads1262 *st,
 
 	/* Avoid using guard() here to mitigate AB/BA deadlock warning */
 	mutex_lock(&st->chan_lock);
-	mode0 = FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |
+	mode0 = FIELD_PREP(ADS1262_MODE0_DELAY_MASK, chan->delay) |
+		FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |
 		FIELD_PREP(ADS1262_MODE0_IDAC_CHOP_MASK, chan->idac_chop) |
 		FIELD_PREP(ADS1262_MODE0_REFREV_MASK, chan->ref_reversal);
 	mode1 = FIELD_PREP(ADS1262_MODE1_FILTER_MASK, chan->filter);
@@ -491,6 +523,7 @@ static int ads1262_channel_enable(struct ads1262 *st,
 	mutex_unlock(&st->chan_lock);
 
 	ret = regmap_update_bits(st->regmap, ADS1262_MODE0_REG,
+				 ADS1262_MODE0_DELAY_MASK |
 				 ADS1262_MODE0_INPUT_CHOP_MASK |
 				 ADS1262_MODE0_IDAC_CHOP_MASK |
 				 ADS1262_MODE0_REFREV_MASK, mode0);
@@ -625,6 +658,15 @@ static int ads1262_read_raw(struct iio_dev *indio_dev,
 		return IIO_VAL_INT_PLUS_MICRO;
 	}
 
+	case IIO_CHAN_INFO_CONVDELAY: {
+		guard(mutex)(&st->chan_lock);
+
+		*val = ads1262_conv_delay_avail[chan_data->delay][0];
+		*val2 = ads1262_conv_delay_avail[chan_data->delay][1];
+
+		return IIO_VAL_INT_PLUS_NANO;
+	}
+
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -647,6 +689,12 @@ static int ads1262_read_avail(struct iio_dev *indio_dev,
 		*length = ARRAY_SIZE(ads1262_pga_gain_avail);
 		return IIO_AVAIL_LIST;
 
+	case IIO_CHAN_INFO_CONVDELAY:
+		*type = IIO_VAL_INT_PLUS_NANO;
+		*vals = (const int *)ads1262_conv_delay_avail;
+		*length = ARRAY_SIZE(ads1262_conv_delay_avail) * 2;
+		return IIO_AVAIL_LIST;
+
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -685,6 +733,17 @@ static int ads1262_write_raw(struct iio_dev *indio_dev,
 		break;
 	}
 
+	case IIO_CHAN_INFO_CONVDELAY: {
+		i = ads1262_find_two(ads1262_conv_delay_avail, val, val2);
+		if (i < 0)
+			return i;
+
+		guard(mutex)(&st->chan_lock);
+		chan_data->delay = i;
+
+		break;
+	}
+
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -807,8 +866,10 @@ static int ads1262_alloc_channels(struct ads1262 *st,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 					      BIT(IIO_CHAN_INFO_SCALE) |
 					      BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
+					      BIT(IIO_CHAN_INFO_CONVDELAY) |
 					      BIT(IIO_CHAN_INFO_SAMP_FREQ),
 			.info_mask_shared_by_type_available =
+				BIT(IIO_CHAN_INFO_CONVDELAY) |
 				BIT(IIO_CHAN_INFO_HARDWAREGAIN) |
 				BIT(IIO_CHAN_INFO_SAMP_FREQ),
 			.indexed = true,
Signature · 1 line
2.54.0
maintainer
#25 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Jonathan

author
#26 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#27 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

Quoted 7 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

maintainer
#28 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 18 lines · On Tue, 30 Jun 2026 13:44:49 -0500 David Lechner <[email protected]> wrote:
Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Quoted 8 lines

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

See settling-time-us in adc.yaml. I'd forgotten we had that ;)

Quoted 9 lines
Quoted 8 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

reviewer
#29 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Tue, 30 Jun 2026 13:44:49 -0500 David Lechner <[email protected]> wrote:
Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

Quoted 5 lines
Quoted 3 lines

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

See settling-time-us in adc.yaml. I'd forgotten we had that ;)

I got some more feedback on this and this may indeed be something we want to tune at runtime after all.

I'm not really sure where it fits in though. On AD112C14 that I am working on, the DELAY register value adds a delay (for settling time) in addition to some other intrinsic delays. I'm pretty sure ADS1262 is similar.

So one question is do we want a usespace control to be the total delay or just the additional delay?

And when the delay takes effect depends on other things. Normally the delay only happens before the first sample after any other parameters change. If we read the same channel again with the same config, then there won't be any added delay. But if input chopping is enabled, then this delay happens on every conversion.

I'm a bit on the fence of if we should extend the definition of convdelay for this or if we should propose a new settling time attribute. I'll have to think about it some more.

Maybe something like in_voltageY_calibsettlingtime?

Quoted 11 lines
Quoted 10 lines
Quoted 9 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

maintainer
#30 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 36 lines · On Mon, 6 Jul 2026 11:19:40 -0500 David Lechner <[email protected]> wrote:
Quoted 26 lines · Jonathan Cameron
Quoted 23 lines · On Tue, 30 Jun 2026 13:44:49 -0500 David Lechner <[email protected]> wrote:
Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

Quoted 5 lines
Quoted 3 lines

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

See settling-time-us in adc.yaml. I'd forgotten we had that ;)

I got some more feedback on this and this may indeed be something we want to tune at runtime after all.

Quoted 7 lines

I'm not really sure where it fits in though. On AD112C14 that I am working on, the DELAY register value adds a delay (for settling time) in addition to some other intrinsic delays. I'm pretty sure ADS1262 is similar.

So one question is do we want a usespace control to be the total delay or just the additional delay?

Total I think.

Quoted 5 lines

And when the delay takes effect depends on other things. Normally the delay only happens before the first sample after any other parameters change. If we read the same channel again with the same config, then there won't be any added delay. But if input chopping is enabled, then this delay happens on every conversion.

Hmm. That is awkward. I guess the best we could do is either to document it as 'may be skipped if channel setup is unchanged either via explicit channel or parameter change, or via chopping'. I kind of think of chopping as advanced channel sequencing - inX-inY being switched to inY-inX with a scale *= -1.

Quoted 4 lines

I'm a bit on the fence of if we should extend the definition of convdelay for this or if we should propose a new settling time attribute. I'll have to think about it some more.

Smells different enough that we shouldn't smash the two together.

Quoted 2 lines

Maybe something like in_voltageY_calibsettlingtime?

calib might be reasonable if it was a tweak to a fixed settling time and like other calib stuff would not necessarily have any scaling.

If it's the whole thing and in seconds then in_voltageY_settlingtime should be enough I think.

Jonathan

Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

author
#31 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 34 lines · Jonathan Cameron
Quoted 31 lines · On Mon, 6 Jul 2026 11:19:40 -0500 David Lechner <[email protected]> wrote:
Quoted 30 lines · Jonathan Cameron
Quoted 26 lines · On Tue, 30 Jun 2026 13:44:49 -0500 David Lechner <[email protected]> wrote:
Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

See settling-time-us in adc.yaml. I'd forgotten we had that ;)

I got some more feedback on this and this may indeed be something we want to tune at runtime after all.

I'm not really sure where it fits in though. On AD112C14 that I am working on, the DELAY register value adds a delay (for settling time) in addition to some other intrinsic delays. I'm pretty sure ADS1262 is similar.

It is! there is a fixed 52 usecs delay after starting conversions.

Quoted 13 lines
Quoted 4 lines

So one question is do we want a usespace control to be the total delay or just the additional delay?

Total I think.

Quoted 5 lines

And when the delay takes effect depends on other things. Normally the delay only happens before the first sample after any other parameters change. If we read the same channel again with the same config, then there won't be any added delay. But if input chopping is enabled, then this delay happens on every conversion.

Quoted 5 lines

Hmm. That is awkward. I guess the best we could do is either to document it as 'may be skipped if channel setup is unchanged either via explicit channel or parameter change, or via chopping'. I kind of think of chopping as advanced channel sequencing - inX-inY being switched to inY-inX with a scale *= -1.

Thinking about it this way, shouldn't there be userspace control for the chopping stuff too? Something like in_voltageY_chop_type, similar to the filter type.

Quoted 7 lines
Quoted 5 lines

I'm a bit on the fence of if we should extend the definition of convdelay for this or if we should propose a new settling time attribute. I'll have to think about it some more.

Smells different enough that we shouldn't smash the two together.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Maybe something like in_voltageY_calibsettlingtime?

calib might be reasonable if it was a tweak to a fixed settling time and like other calib stuff would not necessarily have any scaling.

If it's the whole thing and in seconds then in_voltageY_settlingtime should be enough I think.

+1 for this. in_voltageY_settlingdelay might work too, as both our datasheets call it "delay".

Quoted 16 lines

Jonathan

Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

Signature · 2 lines
Thanks,
 ~ Kurt
maintainer
#32 lore raw

Re: [PATCH v2 5/7] iio: adc: ti-ads1262: Add conversion delay support

Quoted 65 lines · On Mon, 06 Jul 2026 20:38:45 -0500 "Kurt Borja" <[email protected]> wrote:
Quoted 34 lines · Jonathan Cameron
Quoted 31 lines · On Mon, 6 Jul 2026 11:19:40 -0500 David Lechner <[email protected]> wrote:
Quoted 30 lines · Jonathan Cameron
Quoted 26 lines · On Tue, 30 Jun 2026 13:44:49 -0500 David Lechner <[email protected]> wrote:
Quoted 13 lines · Kurt Borja
Quoted 11 lines · Jonathan Cameron
Quoted 2 lines · On Sun, 28 Jun 2026 00:36:06 -0500 Kurt Borja <[email protected]> wrote:

Expose the programmable conversion start delay as a per-channel IIO_CHAN_INFO_CONVDELAY attribute.

Coversion delay was always a somewhere weird bit of ABI. What are the delays relative to in this case?
Is this a device that does simultaneous sampling? Pictures suggest otherwise, and convdelay is currently only defined in that case. We might be able to extend it but it needs some thought.

Quoted 3 lines

The chip has a configurable internal conversion delay to allow for external settling effects. See datasheet section 9.4.3 if you'd like a bit more details.

Since this depends on external components, it sounds like it belongs in the devicetree. I have the same feature in the chip I am working on and was just looking at this and plan to add it to the ti,ads112c14 devicetree patch.

This delay only applies to a "new conversion", i.e. when certain config registers change, and not every conversion, so isn't like the convdelay attribute.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

See settling-time-us in adc.yaml. I'd forgotten we had that ;)

I got some more feedback on this and this may indeed be something we want to tune at runtime after all.

I'm not really sure where it fits in though. On AD112C14 that I am working on, the DELAY register value adds a delay (for settling time) in addition to some other intrinsic delays. I'm pretty sure ADS1262 is similar.

It is! there is a fixed 52 usecs delay after starting conversions.

Quoted 13 lines
Quoted 4 lines

So one question is do we want a usespace control to be the total delay or just the additional delay?

Total I think.

Quoted 5 lines

And when the delay takes effect depends on other things. Normally the delay only happens before the first sample after any other parameters change. If we read the same channel again with the same config, then there won't be any added delay. But if input chopping is enabled, then this delay happens on every conversion.

Quoted 5 lines

Hmm. That is awkward. I guess the best we could do is either to document it as 'may be skipped if channel setup is unchanged either via explicit channel or parameter change, or via chopping'. I kind of think of chopping as advanced channel sequencing - inX-inY being switched to inY-inX with a scale *= -1.

Quoted 3 lines

Thinking about it this way, shouldn't there be userspace control for the chopping stuff too? Something like in_voltageY_chop_type, similar to the filter type.

Good point. Until this came up I was thinking that there was no disadvantage to chopping if it made sense for what was being measured, but here we can see we are trading off acquisition rate. That might be something we can stall for a follow up though as to me turning it off will 'mostly' be the wrong thing to do and hence adding control of that a feature.

Quoted 36 lines
Quoted 8 lines
Quoted 6 lines

I'm a bit on the fence of if we should extend the definition of convdelay for this or if we should propose a new settling time attribute. I'll have to think about it some more.

Smells different enough that we shouldn't smash the two together.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Maybe something like in_voltageY_calibsettlingtime?

calib might be reasonable if it was a tweak to a fixed settling time and like other calib stuff would not necessarily have any scaling.

If it's the whole thing and in seconds then in_voltageY_settlingtime should be enough I think.

+1 for this. in_voltageY_settlingdelay might work too, as both our datasheets call it "delay".

Quoted 16 lines

Jonathan

Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines

But you're right, I should at least also edit the ABI description of this attribute. We can postpone this discussion for a future series.

Quoted 2 lines

Jonathan

author
#33 lore raw

PATCH v2 6/7 iio: adc: ti-ads1262: Add buffer and trigger support

In reply to Kurt Borja

Add triggered buffer support and a data-ready (DRDY) hardware trigger.

---
 drivers/iio/adc/ti-ads1262.c | 265 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 265 insertions(+)
drivers/iio/adc/ti-ads1262.c +265 -0
index 4ae22c1b0b4b7d79..53bc70e0c35a59da 100644
@@ -38,6 +38,9 @@
 #include <asm/byteorder.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #define ADS1262_OPCODE_NOP			0x00
 #define ADS1262_OPCODE_RESET			0x06
@@ -258,6 +261,7 @@ struct ads1262 {
 	const struct ads1262_chip_info *info;
 	struct regmap *regmap;
 	struct iio_dev *indio_dev;
+	struct iio_trigger *trig;
 	struct gpio_desc *reset_gpiod;
 	struct gpio_desc *start_gpiod;
 
@@ -273,6 +277,11 @@ struct ads1262 {
 
 	/* Protects transfer buffers and concurrent SPI transfers */
 	struct mutex xfer_lock;
+	struct spi_message msg;
+	struct spi_transfer xfer[2];
+
+	IIO_DECLARE_BUFFER_WITH_TS(__be32, scan_buffer,
+				   ADS1262_MAX_CHANNEL_COUNT);
 
 	u8 tx[ADS1262_XFER_BUFFER_SZ] __aligned(IIO_DMA_MINALIGN);
 	u8 rx[ADS1262_XFER_BUFFER_SZ] __aligned(IIO_DMA_MINALIGN);
@@ -781,10 +790,250 @@ static const struct iio_info ads1262_iio_info = {
 	.debugfs_reg_access = ads1262_debugfs_reg_access,
 };
 
+static int ads1262_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	unsigned int weight;
+	unsigned long i;
+	int ret;
+
+	weight = bitmap_weight(indio_dev->active_scan_mask,
+			       iio_get_masklength(indio_dev));
+	if (weight == 1) {
+		/*
+		 * A single channel is read by command (RDATA1), so one transfer
+		 * holds the command byte plus the 4 conversion bytes, which end
+		 * up at offset 1 of the rx buffer.
+		 */
+		st->xfer[0].len = 5;
+		st->xfer[0].tx_buf = st->tx;
+		st->xfer[0].rx_buf = st->rx;
+		st->xfer[0].cs_change = 0;
+		spi_message_init_with_transfers(&st->msg, st->xfer, 1);
+
+		i = find_first_bit(indio_dev->active_scan_mask,
+				   iio_get_masklength(indio_dev));
+		ret = ads1262_channel_enable(st, &st->channels[i]);
+		if (ret)
+			return ret;
+	} else {
+		/*
+		 * Multiple channels use software sequencing: each transfer
+		 * rewrites the per-channel configuration registers while
+		 * returning the conversion of the previously enabled channel,
+		 * found at offset 0 of the rx buffer. The registers are not
+		 * contiguous, so the write is split in two bulk steps.
+		 *
+		 * First step: write protocol (2 bytes) + MODE0, MODE1, MODE2,
+		 * INPMUX (4 registers).
+		 */
+		st->xfer[0].len = 6;
+		st->xfer[0].tx_buf = st->tx;
+		st->xfer[0].rx_buf = st->rx;
+		st->xfer[0].cs_change = 1;
+		/*
+		 * Second step: write protocol (2 bytes) + IDACMUX, IDACMAG,
+		 * REFMUX (3 registers).
+		 */
+		st->xfer[1].len = 5;
+		st->xfer[1].tx_buf = st->tx + 6;
+		st->xfer[1].rx_buf = st->rx + 6;
+		spi_message_init_with_transfers(&st->msg, st->xfer, 2);
+
+		regcache_drop_region(st->regmap, ADS1262_MODE0_REG,
+				     ADS1262_INPMUX_REG);
+		regcache_drop_region(st->regmap, ADS1262_IDACMUX_REG,
+				     ADS1262_REFMUX_REG);
+	}
+
+	ret = ads1262_set_runmode(st, ADS1262_RUNMODE_CONTINUOUS);
+	if (ret)
+		return ret;
+
+	ret = spi_optimize_message(st->spi, &st->msg);
+	if (ret)
+		return ret;
+
+	ret = ads1262_dev_start(st);
+	if (ret) {
+		spi_unoptimize_message(&st->msg);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int ads1262_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+
+	ads1262_dev_stop(st);
+	spi_unoptimize_message(&st->msg);
+
+	return 0;
+}
+
+static bool ads1262_validate_scan_mask(struct iio_dev *indio_dev,
+				       const unsigned long *scan_mask)
+{
+	struct ads1262 *st = iio_priv(indio_dev);
+	struct device *dev = &st->spi->dev;
+
+	if (iio_trigger_using_own(indio_dev)) {
+		dev_err_once(dev, "The %s trigger only supports one active channel\n",
+			     st->trig->name);
+		return iio_validate_scan_mask_onehot(indio_dev, scan_mask);
+	}
+
+	return true;
+}
+
+static const struct iio_buffer_setup_ops ads1262_buffer_ops = {
+	.preenable = ads1262_buffer_preenable,
+	.postdisable = ads1262_buffer_postdisable,
+	.validate_scan_mask = ads1262_validate_scan_mask,
+};
+
+static int ads1262_enable_and_read_last(struct ads1262 *st,
+					const struct ads1262_channel *chan,
+					__be32 *val)
+{
+	int ret;
+
+	lockdep_assert_held(&st->xfer_lock);
+
+	if (chan) {
+		guard(mutex)(&st->chan_lock);
+
+		st->tx[0] = ADS1262_MODE0_REG | ADS1262_OPCODE_WREG;
+		st->tx[1] = ADS1262_INPMUX_REG - ADS1262_MODE0_REG;
+		st->tx[2] = FIELD_PREP(ADS1262_MODE0_DELAY_MASK, chan->delay) |
+			    FIELD_PREP(ADS1262_MODE0_INPUT_CHOP_MASK, chan->input_chop) |
+			    FIELD_PREP(ADS1262_MODE0_IDAC_CHOP_MASK, chan->idac_chop) |
+			    FIELD_PREP(ADS1262_MODE0_RUNMODE_MASK, ADS1262_RUNMODE_CONTINUOUS) |
+			    FIELD_PREP(ADS1262_MODE0_REFREV_MASK, chan->ref_reversal);
+		st->tx[3] = FIELD_PREP(ADS1262_MODE1_FILTER_MASK, chan->filter);
+		st->tx[4] = FIELD_PREP(ADS1262_MODE2_DR_MASK, chan->data_rate) |
+			    FIELD_PREP(ADS1262_MODE2_GAIN_MASK, chan->gain) |
+			    FIELD_PREP(ADS1262_MODE2_BYPASS_MASK, chan->pga_bypass);
+		st->tx[5] = FIELD_PREP(ADS1262_INPMUX_MUXP_MASK, chan->input[0]) |
+			    FIELD_PREP(ADS1262_INPMUX_MUXN_MASK, chan->input[1]);
+
+		st->tx[6] = ADS1262_IDACMUX_REG | ADS1262_OPCODE_WREG;
+		st->tx[7] = ADS1262_REFMUX_REG - ADS1262_IDACMUX_REG;
+		st->tx[8] = FIELD_PREP(ADS1262_IDACMUX_MUX1_MASK, chan->idac_mux[0]) |
+			    FIELD_PREP(ADS1262_IDACMUX_MUX2_MASK, chan->idac_mux[1]);
+		st->tx[9] = FIELD_PREP(ADS1262_IDACMAG_MAG1_MASK, chan->idac_mag[0]) |
+			    FIELD_PREP(ADS1262_IDACMAG_MAG2_MASK, chan->idac_mag[1]);
+		st->tx[10] = FIELD_PREP(ADS1262_REFMUX_RMUXP_MASK, chan->reference[0]) |
+			     FIELD_PREP(ADS1262_REFMUX_RMUXN_MASK, chan->reference[1]);
+	} else {
+		memset(st->tx, 0, sizeof(st->tx));
+	}
+
+	ret = spi_sync(st->spi, &st->msg);
+	if (ret)
+		return ret;
+
+	memcpy(val, st->rx, sizeof(*val));
+
+	return 0;
+}
+
+static int ads1262_fill_buffer_mult(struct ads1262 *st)
+{
+	unsigned int chan;
+	__be32 val;
+	int i = -1;
+	int ret;
+
+	/*
+	 * This routine enables and reads channels in a full-duplex fashion.
+	 *
+	 * When a channel is enabled, the previous conversion is clocked out of
+	 * the shift data register on the same transfer (Section 9.4.7.1). This
+	 * allows for low latency software sequencing but forbids any
+	 * communication with the chip in-between or data corruption may occur,
+	 * hence the need to take the xfer_lock for the whole operation.
+	 */
+	guard(mutex)(&st->xfer_lock);
+
+	iio_for_each_active_channel(st->indio_dev, chan) {
+		ret = ads1262_enable_and_read_last(st, &st->channels[chan], &val);
+		if (ret)
+			return ret;
+
+		reinit_completion(&st->drdy);
+
+		if (i > -1)
+			st->scan_buffer[i] = val;
+		i++;
+
+		ads1262_wait_for_conversion(st);
+	}
+
+	return ads1262_enable_and_read_last(st, NULL, &st->scan_buffer[i]);
+}
+
+static int ads1262_fill_buffer_one(struct ads1262 *st)
+{
+	int ret;
+
+	guard(mutex)(&st->xfer_lock);
+
+	/*
+	 * When only one channel is enabled, we can't really avoid SPI activity
+	 * from happening when the auxiliary ADC is in use, thus we have to read
+	 * from the data-holding register (command mode).
+	 */
+	st->tx[0] = ADS1262_OPCODE_RDATA1;
+	ret = spi_sync(st->spi, &st->msg);
+	if (ret)
+		return ret;
+
+	/* In command mode the conversion data is found at offset 1 */
+	memcpy(st->scan_buffer, &st->rx[1], sizeof(*st->scan_buffer));
+
+	return 0;
+}
+
+static irqreturn_t ads1262_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct ads1262 *st = iio_priv(indio_dev);
+	s64 ts = pf->timestamp;
+	unsigned int weight;
+	int ret;
+
+	weight = bitmap_weight(indio_dev->active_scan_mask,
+			       iio_get_masklength(indio_dev));
+
+	memset(st->scan_buffer, 0, sizeof(st->scan_buffer));
+
+	if (weight == 1)
+		ret = ads1262_fill_buffer_one(st);
+	else
+		ret = ads1262_fill_buffer_mult(st);
+	if (ret)
+		goto out_notify_done;
+
+	iio_push_to_buffers_with_ts(indio_dev, st->scan_buffer,
+				    sizeof(st->scan_buffer), ts);
+
+out_notify_done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
+
 static irqreturn_t ads1262_irq_handler(int irq, void *dev_id)
 {
 	struct ads1262 *st = dev_id;
 
+	if (iio_buffer_enabled(st->indio_dev))
+		iio_trigger_poll(st->trig);
+
 	complete(&st->drdy);
 
 	return IRQ_HANDLED;
@@ -1355,7 +1604,23 @@ static int ads1262_spi_probe(struct spi_device *spi)
 	indio_dev->channels = channels;
 	indio_dev->num_channels = num_channels;
 
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      iio_pollfunc_store_time,
+					      ads1262_trigger_handler,
+					      &ads1262_buffer_ops);
+	if (ret)
+		return ret;
+
 	if (spi->irq > 0) {
+		st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d-drdy", info->name,
+						  iio_device_id(indio_dev));
+		if (!st->trig)
+			return -ENOMEM;
+		iio_trigger_set_drvdata(st->trig, st);
+		ret = devm_iio_trigger_register(dev, st->trig);
+		if (ret)
+			return ret;
+
 		ret = devm_request_irq(dev, spi->irq, ads1262_irq_handler,
 				       IRQF_NO_THREAD, info->name, st);
 		if (ret)
Signature · 1 line
2.54.0
maintainer
#34 lore raw

Re: [PATCH v2 6/7] iio: adc: ti-ads1262: Add buffer and trigger support

Quoted 8 lines · On Sun, 28 Jun 2026 00:36:07 -0500 Kurt Borja <[email protected]> wrote:

Add triggered buffer support and a data-ready (DRDY) hardware trigger.

drivers/iio/adc/ti-ads1262.c +3 -0
+static irqreturn_t ads1262_trigger_handler(int irq, void *p)
+{
+	struct iio_poll_func *pf = p;

drivers/iio/adc/ti-ads1262.c static const struct iio_info ads1262_iio_info = { · line 1012

Quoted 10 lines
drivers/iio/adc/ti-ads1262.c +10 -0
+	struct iio_dev *indio_dev = pf->indio_dev;
+	struct ads1262 *st = iio_priv(indio_dev);
+	s64 ts = pf->timestamp;
+	unsigned int weight;
+	int ret;
+
+	weight = bitmap_weight(indio_dev->active_scan_mask,
+			       iio_get_masklength(indio_dev));
+
+	memset(st->scan_buffer, 0, sizeof(st->scan_buffer));

We don't normally care about stale data in scan_buffers. The only thing to be careful of is any stack or heap data leakage (I don't see any of that here) So is this clear needed?

Userspace should know which bits are valid and extract them, thus ignoring anything stale in the gaps.

Quoted 16 lines
drivers/iio/adc/ti-ads1262.c +16 -0
+
+	if (weight == 1)
+		ret = ads1262_fill_buffer_one(st);
+	else
+		ret = ads1262_fill_buffer_mult(st);
+	if (ret)
+		goto out_notify_done;
+
+	iio_push_to_buffers_with_ts(indio_dev, st->scan_buffer,
+				    sizeof(st->scan_buffer), ts);
+
+out_notify_done:
+	iio_trigger_notify_done(indio_dev->trig);
+
+	return IRQ_HANDLED;
+}
author
#35 lore raw

PATCH v2 7/7 iio: adc: Add ti-ads1263-adc2 driver

In reply to Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

---
 MAINTAINERS                       |   2 +
 drivers/iio/adc/Kconfig           |  14 ++
 drivers/iio/adc/Makefile          |   1 +
 drivers/iio/adc/ti-ads1262.c      | 168 ++++++++++++++++-
 drivers/iio/adc/ti-ads1262.h      |  39 ++++
 drivers/iio/adc/ti-ads1263-adc2.c | 379 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 602 insertions(+), 1 deletion(-)
MAINTAINERS +2 -0
index d868b25f2c65bcd9..342c661f079bcf39 100644
@@ -26929,6 +26929,8 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/iio/adc/ti,ads1262.yaml
 F:	drivers/iio/adc/ti-ads1262.c
+F:	drivers/iio/adc/ti-ads1262.h
+F:	drivers/iio/adc/ti-ads1263-adc2.c
 
 TI ADS7924 ADC DRIVER
 M:	Hugo Villeneuve <[email protected]>
drivers/iio/adc/Kconfig +14 -0
index 6051092c20b96731..ab2e8e45f3b442d6 100644
@@ -1817,6 +1817,7 @@ config TI_ADS1262
 	select REGMAP
 	select IIO_BUFFER
 	select IIO_TRIGGERED_BUFFER
+	select AUXILIARY_BUS
 	help
 	  If you say yes here you get support for Texas Instruments ADS1262 and
 	  ADS1263 ADC chips.
@@ -1824,6 +1825,19 @@ config TI_ADS1262
 	  This driver can also be built as a module. If so, the module will be
 	  called ti-ads1262.
 
+config TI_ADS1263_ADC2
+	tristate "Texas Instruments ADS1263 auxiliary ADC (ADC2) driver"
+	depends on TI_ADS1262
+	select AUXILIARY_BUS
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  If you say yes here you get support for Texas Instruments ADS1263
+	  auxiliary ADC (ADC2).
+
+	  This driver can also be built as a module. If so, the module will be
+	  called ti-ads1263-adc2.
+
 config TI_ADS1298
 	tristate "Texas Instruments ADS1298"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index 4b1f89a2317a35f7..4215f56f525349a5 100644
@@ -156,6 +156,7 @@ obj-$(CONFIG_TI_ADS1119) += ti-ads1119.o
 obj-$(CONFIG_TI_ADS112C14) += ti-ads112c14.o
 obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
 obj-$(CONFIG_TI_ADS1262) += ti-ads1262.o
+obj-$(CONFIG_TI_ADS1263_ADC2) += ti-ads1263-adc2.o
 obj-$(CONFIG_TI_ADS1298) += ti-ads1298.o
 obj-$(CONFIG_TI_ADS131E08) += ti-ads131e08.o
 obj-$(CONFIG_TI_ADS131M02) += ti-ads131m02.o
drivers/iio/adc/ti-ads1262.c +167 -1

207 lines not on this page · raw message

drivers/iio/adc/ti-ads1262.h new file +39 -0
new file mode 100644
index 0000000000000000..7a94ffd1fa983f9f
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Texas Instruments ADS1262 ADC driver
+ *
+ * Copyright (C) 2025 Kurt Borja <[email protected]>
+ */
+
+#ifndef _ADS1262_H_
+#define _ADS1262_H_
+
+#include <linux/auxiliary_bus.h>
+#include <linux/types.h>
+
+struct ads1263_adc2_channel {
+	u8 gain;
+	u8 reference;
+	u8 data_rate;
+	u8 input[2];
+};
+
+struct ads1263_adc2_ctx {
+	struct auxiliary_device adev;
+	struct ads1262 *chip;
+
+	/* Protects channel state */
+	struct mutex chan_lock;
+	struct ads1263_adc2_channel *channels;
+	unsigned int num_channels;
+};
+
+int ads1263_adc2_channel_get_scale(struct ads1263_adc2_ctx *ctx, u8 realbits,
+				   u8 gain, u8 ref_source, int *val, int *val2);
+int ads1263_adc2_channel_enable(struct ads1263_adc2_ctx *ctx,
+				const struct ads1263_adc2_channel *chan);
+int ads1263_adc2_start(struct ads1263_adc2_ctx *ctx);
+int ads1263_adc2_stop(struct ads1263_adc2_ctx *ctx);
+int ads1263_adc2_read(struct ads1263_adc2_ctx *ctx, __be32 *val);
+
+#endif
drivers/iio/adc/ti-ads1263-adc2.c new file +379 -0

379 lines not on this page · raw message

Signature · 1 line
2.54.0
reviewer
#36 lore raw

Re: [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver

Quoted 9 lines · Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

Can these just be additional channels in the main iio device rather than a separate iio device?

author
#37 lore raw

Re: [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver

Quoted 4 lines · David Lechner
Quoted 3 lines · Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Quoted 8 lines
Quoted 6 lines

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

Can these just be additional channels in the main iio device rather than a separate iio device?

I guess we can do it, but wouldn't it be quite a mess? I think doing it that way adds a lot of complexity: channel naming, available scan masks (because both ADCs can be sampled at the same time), optimized software sequencing would only work in ADC1 channels, ADC2 doesn't have a DRDY IRQ, etc.

IMO separating both drivers makes everything simpler, easier to understand and easier to maintain in the future.

Signature · 2 lines
Thanks,
 ~ Kurt
reviewer
#38 lore raw

Re: [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver

Quoted 11 lines · Kurt Borja
Quoted 10 lines · David Lechner
Quoted 9 lines · Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

Quoted 8 lines
Quoted 2 lines

Can these just be additional channels in the main iio device rather than a separate iio device?

I guess we can do it, but wouldn't it be quite a mess? I think doing it that way adds a lot of complexity: channel naming, available scan masks (because both ADCs can be sampled at the same time), optimized software sequencing would only work in ADC1 channels, ADC2 doesn't have a DRDY IRQ, etc.

Channel naming is easy, e.g. just add 100 to channel and channel2 for ADC1 and 200 for ADC2.

And if ADC2 is mostly for diagnostics, do we really care about trying to optimize it?

Quoted 4 lines

IMO separating both drivers makes everything simpler, easier to understand and easier to maintain in the future.

Sure, I don't have any strong objection to doing this way. We just usually try to avoid multiple IIO devices for a single chip. Although one of the exceptions to this is when a chip has independent cores. I guess this fits that description, although it is a little muddled due to sharing the same input pins, sensor bias, IDACs and probably a few other things - i.e. doing buffered reads on both cores at the same time requires a static IDAC output to avoid issues.

maintainer
#39 lore raw

Re: [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver

Quoted 32 lines · On Mon, 29 Jun 2026 11:38:26 -0500 David Lechner <[email protected]> wrote:
Quoted 11 lines · Kurt Borja
Quoted 10 lines · David Lechner
Quoted 9 lines · Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

Quoted 8 lines
Quoted 2 lines

Can these just be additional channels in the main iio device rather than a separate iio device?

I guess we can do it, but wouldn't it be quite a mess? I think doing it that way adds a lot of complexity: channel naming, available scan masks (because both ADCs can be sampled at the same time), optimized software sequencing would only work in ADC1 channels, ADC2 doesn't have a DRDY IRQ, etc.

Channel naming is easy, e.g. just add 100 to channel and channel2 for ADC1 and 200 for ADC2.

And if ADC2 is mostly for diagnostics, do we really care about trying to optimize it?

Quoted 4 lines

IMO separating both drivers makes everything simpler, easier to understand and easier to maintain in the future.

Quoted 7 lines

Sure, I don't have any strong objection to doing this way. We just usually try to avoid multiple IIO devices for a single chip. Although one of the exceptions to this is when a chip has independent cores. I guess this fits that description, although it is a little muddled due to sharing the same input pins, sensor bias, IDACs and probably a few other things - i.e. doing buffered reads on both cores at the same time requires a static IDAC output to avoid issues.

There are (I think) still some gaps in the multibuffer support. Ideally we'd have long ago solved those, but without that (I think we can't support different triggers for example) I'm not sure we could do this as a single device if we support buffered capture.

The question that comes to mind is do the usecases for this 'debug' ADC need that support? If it were just sysfs then a single device would be easy to do. On the other side, splitting it is up later isn't something we can easily retrofit. There is precedence for multiple devices like this for sensor hubs (also driven by the lack of complete multibuffer support). That doesn't hit all the isseus here though as I can't immediately think of a case where properties set for one iio_dev effect another (I didn't check though!)

To me the multidevice support is fine - particularly if it's optional
- so the sub driver can be skipped if someone doesn't care about this extra ADC.

Thanks,

Jonathan

author
#40 lore raw

Re: [PATCH v2 7/7] iio: adc: Add ti-ads1263-adc2 driver

Quoted 18 lines · Jonathan Cameron
Quoted 15 lines · On Mon, 29 Jun 2026 11:38:26 -0500 David Lechner <[email protected]> wrote:
Quoted 14 lines · Kurt Borja
Quoted 12 lines · David Lechner
Quoted 9 lines · Kurt Borja

The TI ADS1263 embeds a second 24-bit delta-sigma ADC (ADC2) with its own input mux, reference, gain and sample-rate selection.

Model ADC2 as a separate IIO device on the auxiliary bus: the ti-ads1262 SPI driver instantiates the auxiliary device and exports a small set of TI_ADS1262-namespaced helpers for the conversion and register accesses that must go through the shared bus. ADC2 channels are derived from the parent's configured channels.

Can these just be additional channels in the main iio device rather than a separate iio device?

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

I guess we can do it, but wouldn't it be quite a mess? I think doing it that way adds a lot of complexity: channel naming, available scan masks (because both ADCs can be sampled at the same time), optimized software sequencing would only work in ADC1 channels, ADC2 doesn't have a DRDY IRQ, etc.

Channel naming is easy, e.g. just add 100 to channel and channel2 for ADC1 and 200 for ADC2.

It wouldn't be the end of the world, but it would be confusing without some documentation or without relying on channel labels.

Quoted 3 lines
Quoted 3 lines

And if ADC2 is mostly for diagnostics, do we really care about trying to optimize it?

Oh I meant the ADC1 optimization, the ADC2 has no optimization considerations.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

IMO separating both drivers makes everything simpler, easier to understand and easier to maintain in the future.

Quoted 7 lines
Quoted 7 lines

Sure, I don't have any strong objection to doing this way. We just usually try to avoid multiple IIO devices for a single chip. Although one of the exceptions to this is when a chip has independent cores. I guess this fits that description, although it is a little muddled due to sharing the same input pins, sensor bias, IDACs and probably a few other things - i.e. doing buffered reads on both cores at the same time requires a static IDAC output to avoid issues.

Yes, the IDAC stuff is the most annoying detail. The datasheet claims:

All input configurations (channel select, IDAC, level-shift, sensor bias) are available to ADC2.

and is technically true, but IDAC configuration is not independent so it's really up to the driver to make it "available" to ADC2.

My approach for now is to not support the IDACs in the ADC2. This makes sense for me because I can set a static IDAC output on ADC1 and sample ADC2 on the side.

I can support it later though, shouldn't be too hard. When ADC1 is sampling just one channel we can -EBUSY, when there's more than one channel reads are already synchronized so we can just switch the IDAC without much trouble.

Quoted 10 lines

There are (I think) still some gaps in the multibuffer support. Ideally we'd have long ago solved those, but without that (I think we can't support different triggers for example) I'm not sure we could do this as a single device if we support buffered capture.

The question that comes to mind is do the usecases for this 'debug' ADC need that support? If it were just sysfs then a single device would be easy to do. On the other side, splitting it is up later isn't something we can easily retrofit. There is precedence for

IMO the ability to buffer read ADC2 at a much lower trigger rate is not _absolutely necessary_ but it's still very confortable. And although the code simplification is not that HUGE, it's still significant to me.

Quoted 4 lines

multiple devices like this for sensor hubs (also driven by the lack of complete multibuffer support). That doesn't hit all the isseus here though as I can't immediately think of a case where properties set for one iio_dev effect another (I didn't check though!)

All channel properties are independent, except for the IDAC stuff described above. As for the Sensor Bias (burn-out current stuff), if we end up only having sysfs sampling (_burnoutraw) then it's not really a problem.

Quoted 8 lines

To me the multidevice support is fine - particularly if it's optional
- so the sub driver can be skipped if someone doesn't care about this extra ADC.

Thanks,

Jonathan

Signature · 2 lines
Thanks,
 ~ Kurt