Devicetree
 help / color / mirror / Atom feed
* [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support
@ 2026-12-03 15:19 Janani Sunil
  2026-12-03 15:19 ` [PATCH 01/18] dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties Janani Sunil
                   ` (17 more replies)
  0 siblings, 18 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

This series fixes several issues in the existing AD4170-4 driver and
binding. The series also adds support for the eight differential input
AD4171-8, AD4190-8 and AD4195-8.

Datasheets:
https://www.analog.com/media/en/technical-documentation/data-sheets/ad4171-8.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/ad4190-8.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/ad4195-8.pdf

**Device Overview:**
The AD4171-8, AD4190-8 and AD4195-8 are 24-bit, low noise, multichannel
precision sigma-delta ADCs with an integrated PGA, sinc3/sinc5/sinc5+avg
digital filters, internal 16MHz oscillator, on-chip temperature sensor,
bias voltage generator, low-side power switches and four GPIOs.

Compared to the 4 differential input parts, they double the analog front
end with 16 analog inputs, AIN0 to AIN15, plus a dedicated AINCOM pin,
configurable as 8 differential or 16 single-ended/pseudo-differential
inputs.

**Patch Summary:**
Patches 1-15 are fixes and are placed first so they can be applied
independently of the new device support:
1. Restrict DAC, crystal, extra excitation current and GPIO AC
   excitation properties to AD4170-4 in the binding.
2. Restrict single-channel, common-mode-channel and excitation pin
   inputs to valid codes in the binding.
3. Allow running from the internal oscillator only in the binding.
4. Fix the voltage bias description in the binding.
5. Fix out-of-bounds accesses to pins_fn[].
6. Fix voltage bias programming.
7. Fix an overflow in the sample rate fractional part.
8. Fix the output data rate on AD4190-4 and AD4195-4 (CLOCKDIV).
9. Fix filter_fs adjustment on filter type change.
10. Fix a lock order inversion between st->lock and IIO direct mode.
11. Fix the sinc5 FILTER_FS range on AD4190-4 and AD4195-4.
12. Do not drive XTAL2 (CLK on AD419x) when using the internal clock.
13. Restrict current sources and GPIO AC excitation to the parts that
    have them.
14. Require equal chopped excitation currents.
15. Fix the channel count with 15 external channels.

Patches 16-18 add the new devices:
16. Replace ad4170_iout_pin_tbl with range checks (no functional change).
17. Add the AD4171-8, AD4190-8 and AD4195-8 binding.
18. Add driver support for AD4171-8, AD4190-8 and AD4195-8.

**Testing:**
The driver was hardware tested on a Raspberry Pi 4 using the
EVAL-AD4171-8ARDZ evaluation board, on a v6.12.y kernel with the AD4170-4
driver and this series backported.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
Janani Sunil (18):
      dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties
      dt-bindings: iio: adc: ad4170-4: Restrict channel inputs to valid codes
      dt-bindings: iio: adc: ad4170-4: Allow running from the internal oscillator only
      dt-bindings: iio: adc: ad4170-4: Fix the voltage bias description
      iio: adc: ad4170-4: Fix out-of-bounds accesses to pins_fn[]
      iio: adc: ad4170-4: Fix voltage bias programming
      iio: adc: ad4170-4: Fix overflow in sample rate fractional part
      iio: adc: ad4170-4: Fix output data rate on AD4190-4 and AD4195-4
      iio: adc: ad4170-4: Fix filter_fs adjustment on filter type change
      iio: adc: ad4170-4: Fix lock order inversion with IIO direct mode
      iio: adc: ad4170-4: Fix sinc5 filter FILTER_FS range on AD4190-4 and AD4195-4
      iio: adc: ad4170-4: Do not drive XTAL2 when using the internal clock
      iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts
      iio: adc: ad4170-4: Require equal chopped excitation currents
      iio: adc: ad4170-4: Fix channel count with 15 external channels
      iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl
      dt-bindings: iio: adc: ad4170-4: Add AD4171-8, AD4190-8 and AD4195-8
      iio: adc: ad4170-4: Add support for AD4171-8, AD4190-8 and AD4195-8

 .../devicetree/bindings/iio/adc/adi,ad4170-4.yaml  | 193 +++++++++++++--
 drivers/iio/adc/Kconfig                            |   5 +-
 drivers/iio/adc/ad4170-4.c                         | 265 +++++++++++++--------
 3 files changed, 349 insertions(+), 114 deletions(-)
---
base-commit: fba506008a5b548ad2708bc2765a039cb00a47ab
change-id: 20261203-ad419x-release-93554b60f924

Best regards,
-- 
Janani Sunil <janani.sunil@analog.com>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 01/18] dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 02/18] dt-bindings: iio: adc: ad4170-4: Restrict channel inputs to valid codes Janani Sunil
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The binding also covers AD4190-4 and AD4195-4, which lack the integrated
DAC, the XTAL1/XTAL2 pins and the third and fourth excitation current
sources of AD4170-4. Gate all three on the compatible so only AD4170-4
can select them.

AD4190-4 and AD4195-4 also cannot AC excite a bridge through their GPIO
outputs, their CHOP_ADC AC excitation codes being reserved. Require both
excitation pins and both nonzero excitation currents for AC excited
bridges on those devices, so that chopping of the IOUT0 and IOUT1
excitation currents remains the only AC excitation mode.

Fixes: 1b3cee41235b ("dt-bindings: iio: adc: Add AD4170-4")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 .../devicetree/bindings/iio/adc/adi,ad4170-4.yaml  | 81 ++++++++++++++++++++--
 1 file changed, 75 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
index da93213d12d4..ef5ca2ed8210 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
@@ -134,17 +134,86 @@ properties:
       maximum: 8
 
 allOf:
-  # Some devices don't have integrated DAC
+  # Only AD4170-4 has an integrated DAC. On the other devices, the DAC output is
+  # not routed to the multiplexer either, making mux input number 20 reserved.
   - if:
       properties:
         compatible:
-          contains:
-            enum:
-              - adi,ad4190-4
-              - adi,ad4195-4
+          not:
+            contains:
+              const: adi,ad4170-4
     then:
       properties:
         ldac-gpios: false
+      patternProperties:
+        "^channel@[0-9a-f]$":
+          properties:
+            diff-channels:
+              items:
+                anyOf:
+                  - maximum: 19
+                  - minimum: 21
+
+  # Only AD4170-4 can be clocked by an external crystal. The other devices
+  # have no XTAL1 and XTAL2 pins.
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              const: adi,ad4170-4
+    then:
+      properties:
+        clock-names:
+          const: ext-clk
+
+  # AD4170-4 has four excitation current sources. The other devices have two.
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              const: adi,ad4170-4
+    then:
+      patternProperties:
+        "^channel@[0-9a-f]$":
+          properties:
+            adi,excitation-pin-2: false
+            adi,excitation-pin-3: false
+            adi,excitation-current-2-microamp: false
+            adi,excitation-current-3-microamp: false
+
+  # Only AD4170-4 can AC excite a bridge with its GPIO outputs. On the other
+  # devices, an AC excited bridge needs chopped excitation currents on IOUT0
+  # and IOUT1, which must be nonzero. The driver also requires them to be equal.
+  - if:
+      properties:
+        compatible:
+          not:
+            contains:
+              const: adi,ad4170-4
+    then:
+      patternProperties:
+        "^channel@[0-9a-f]$":
+          if:
+            properties:
+              adi,sensor-type:
+                contains:
+                  const: weighscale
+            required:
+              - adi,sensor-type
+              - adi,excitation-ac
+          then:
+            required:
+              - adi,excitation-pin-0
+              - adi,excitation-pin-1
+              - adi,excitation-current-0-microamp
+              - adi,excitation-current-1-microamp
+            properties:
+              adi,excitation-current-0-microamp:
+                minimum: 1
+              adi,excitation-current-1-microamp:
+                minimum: 1
 
   # Require to specify the interrupt pin when using interrupts
   - if:
@@ -198,7 +267,7 @@ patternProperties:
           17: Internal temperature sensor
           18: (AVDD-AVSS)/5
           19: (IOVDD-DGND)/5
-          20: DAC output
+          20: DAC output (AD4170-4 only)
           21: ALDO
           22: DLDO
           23: AVSS

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 02/18] dt-bindings: iio: adc: ad4170-4: Restrict channel inputs to valid codes
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
  2026-12-03 15:19 ` [PATCH 01/18] dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 03/18] dt-bindings: iio: adc: ad4170-4: Allow running from the internal oscillator only Janani Sunil
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

single-channel and common-mode-channel select the CHANNEL_MAPn AINP_N
and AINM_N inputs just like diff-channels does, but they are not
constrained at all, so any number passes validation. Likewise, the
adi,excitation-pin properties accept codes 9 to 16, which
CURRENT_SOURCEn I_OUT_PIN marks reserved.

Apply the diff-channels constraints to single-channel and
common-mode-channel: AIN0 to AIN8 and the special inputs 17 to 29, with
no DAC output on devices without an integrated DAC. Restrict the
excitation pins to AIN0 to AIN8 and GPIO0 to GPIO3.

Fixes: 1b3cee41235b ("dt-bindings: iio: adc: Add AD4170-4")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 .../devicetree/bindings/iio/adc/adi,ad4170-4.yaml  | 34 +++++++++++++++++-----
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
index ef5ca2ed8210..90ca4e39c216 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
@@ -153,6 +153,14 @@ allOf:
                 anyOf:
                   - maximum: 19
                   - minimum: 21
+            single-channel:
+              anyOf:
+                - maximum: 19
+                - minimum: 21
+            common-mode-channel:
+              anyOf:
+                - maximum: 19
+                - minimum: 21
 
   # Only AD4170-4 can be clocked by an external crystal. The other devices
   # have no XTAL1 and XTAL2 pins.
@@ -283,6 +291,20 @@ patternProperties:
           enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
                  26, 27, 28, 29]
 
+      single-channel:
+        description:
+          Positive input of a pseudo-differential channel. Uses the same input
+          numbers as diff-channels.
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+               26, 27, 28, 29]
+
+      common-mode-channel:
+        description:
+          Negative input of a pseudo-differential channel. Uses the same input
+          numbers as diff-channels.
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+               26, 27, 28, 29]
+
       adi,reference-select:
         description: |
           Select the reference source to use when converting on the
@@ -323,8 +345,7 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        minimum: 0
-        maximum: 20
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
         default: 0
 
       adi,excitation-pin-1:
@@ -332,8 +353,7 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        minimum: 0
-        maximum: 20
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
         default: 0
 
       adi,excitation-pin-2:
@@ -341,8 +361,7 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        minimum: 0
-        maximum: 20
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
         default: 0
 
       adi,excitation-pin-3:
@@ -350,8 +369,7 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        minimum: 0
-        maximum: 20
+        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
         default: 0
 
       adi,excitation-current-0-microamp:

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 03/18] dt-bindings: iio: adc: ad4170-4: Allow running from the internal oscillator only
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
  2026-12-03 15:19 ` [PATCH 01/18] dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties Janani Sunil
  2026-12-03 15:19 ` [PATCH 02/18] dt-bindings: iio: adc: ad4170-4: Restrict channel inputs to valid codes Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 04/18] dt-bindings: iio: adc: ad4170-4: Fix the voltage bias description Janani Sunil
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The binding requires exactly one of clocks and #clock-cells, so a node
that neither takes an external clock nor provides the internal clock
output is rejected, although the driver supports running from the
internal oscillator without exposing it.

Keep the two properties mutually exclusive, since the external clock
input and the internal clock output share the same pin, but allow both
to be absent.

Fixes: 1b3cee41235b ("dt-bindings: iio: adc: Add AD4170-4")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 .../devicetree/bindings/iio/adc/adi,ad4170-4.yaml        | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
index 90ca4e39c216..cf4064b4def9 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
@@ -231,14 +231,14 @@ allOf:
       required:
         - interrupt-names
 
-  # If an external clock is set, the internal clock cannot go out and vice versa
-  - oneOf:
-      - required: [clocks]
-        properties:
-          '#clock-cells': false
-      - required: ['#clock-cells']
-        properties:
-          clocks: false
+  # An external clock input and the internal clock output share the same
+  # pin, so they cannot be used at the same time. Neither is needed when
+  # running from the internal oscillator.
+  - if:
+      required: [clocks]
+    then:
+      properties:
+        '#clock-cells': false
 
 required:
   - compatible

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 04/18] dt-bindings: iio: adc: ad4170-4: Fix the voltage bias description
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (2 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 03/18] dt-bindings: iio: adc: ad4170-4: Allow running from the internal oscillator only Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 05/18] iio: adc: ad4170-4: Fix out-of-bounds accesses to pins_fn[] Janani Sunil
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The bias voltage generator biases the selected inputs to the midpoint
of the analog supplies, (AVDD + AVSS) / 2, as stated in the datasheets.
The adi,vbias-pins description gives (AVDD - AVSS) / 2, which is only
the same voltage when AVSS is at ground and differs with split supplies.

Fixes: 1b3cee41235b ("dt-bindings: iio: adc: Add AD4170-4")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
index cf4064b4def9..4d2d69c5bb9a 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
@@ -125,7 +125,7 @@ properties:
     const: 0
 
   adi,vbias-pins:
-    description: Analog inputs to apply a voltage bias of (AVDD − AVSS) / 2 to.
+    description: Analog inputs to apply a voltage bias of (AVDD + AVSS) / 2 to.
     $ref: /schemas/types.yaml#/definitions/uint32-array
     minItems: 1
     maxItems: 9

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 05/18] iio: adc: ad4170-4: Fix out-of-bounds accesses to pins_fn[]
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (3 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 04/18] dt-bindings: iio: adc: ad4170-4: Fix the voltage bias description Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 06/18] iio: adc: ad4170-4: Fix voltage bias programming Janani Sunil
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

pins_fn[] has one entry per analog input pin, but it is indexed with
unchecked devicetree values. Special inputs such as AVSS and REFOUT are
encoded as 17 to 29, so the VBIAS tests in ad4170_get_ain_voltage_uv()
and ad4170_parse_external_sensor() read past the end of the array
whenever a channel uses one.

Bound the two VBIAS tests and reject out-of-range adi,vbias-pins.

Fixes: 6098df897d13 ("iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index a04ab03f3938..9bad480e69d7 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -984,7 +984,8 @@ static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
 	 * So, we do AVDD - AVSS to compute the DC voltage generated by the bias
 	 * voltage generator.
 	 */
-	if (st->pins_fn[ain_n] & AD4170_PIN_VBIAS) {
+	if (ain_n < AD4170_NUM_ANALOG_PINS &&
+	    st->pins_fn[ain_n] & AD4170_PIN_VBIAS) {
 		int v_diff = st->vrefs_uv[AD4170_AVDD_SUP] - st->vrefs_uv[AD4170_AVSS_SUP];
 		*ain_voltage = v_diff / 2;
 		return 0;
@@ -2144,7 +2145,8 @@ static int ad4170_parse_external_sensor(struct ad4170_state *st,
 	ac_excited = fwnode_property_read_bool(child, "adi,excitation-ac");
 
 	if (s_type == AD4170_THERMOCOUPLE_SENSOR) {
-		if (st->pins_fn[chan->channel2] & AD4170_PIN_VBIAS) {
+		if (chan->channel2 < AD4170_NUM_ANALOG_PINS &&
+		    st->pins_fn[chan->channel2] & AD4170_PIN_VBIAS) {
 			reg_val = BIT(chan->channel2);
 			ret = regmap_write(st->regmap, AD4170_V_BIAS_REG, reg_val);
 			if (ret)
@@ -2568,8 +2570,14 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
 			return dev_err_probe(dev, ret,
 					     "Failed to read vbias pins\n");
 
-		for (i = 0; i < num_vbias_pins; i++)
+		for (i = 0; i < num_vbias_pins; i++) {
+			if (vbias_pins[i] >= AD4170_NUM_ANALOG_PINS)
+				return dev_err_probe(dev, -EINVAL,
+						     "Invalid vbias pin %u\n",
+						     vbias_pins[i]);
+
 			st->pins_fn[vbias_pins[i]] |= AD4170_PIN_VBIAS;
+		}
 	}
 
 	ret = ad4170_parse_channels(indio_dev);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 06/18] iio: adc: ad4170-4: Fix voltage bias programming
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (4 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 05/18] iio: adc: ad4170-4: Fix out-of-bounds accesses to pins_fn[] Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part Janani Sunil
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The adi,vbias-pins are recorded in pins_fn[] when parsing the firmware,
but V_BIAS is only written while setting up a thermocouple with
excitation properties. The bias is therefore never applied for other
channels, each thermocouple write replaces the whole register so a
later channel clears the bias of an earlier one, and a write failure is
logged and then discarded.

Program V_BIAS once with all the listed pins after parsing them, and
fail probe if the write fails.

Fixes: 6098df897d13 ("iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 9bad480e69d7..f353b630834e 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -2114,7 +2114,7 @@ static int ad4170_parse_external_sensor(struct ad4170_state *st,
 					struct iio_chan_spec *chan,
 					unsigned int s_type)
 {
-	unsigned int num_exc_pins, reg_val;
+	unsigned int num_exc_pins;
 	struct device *dev = &st->spi->dev;
 	u32 pins[2], exc_pins[4], exc_curs[4];
 	bool ac_excited;
@@ -2144,15 +2144,6 @@ static int ad4170_parse_external_sensor(struct ad4170_state *st,
 
 	ac_excited = fwnode_property_read_bool(child, "adi,excitation-ac");
 
-	if (s_type == AD4170_THERMOCOUPLE_SENSOR) {
-		if (chan->channel2 < AD4170_NUM_ANALOG_PINS &&
-		    st->pins_fn[chan->channel2] & AD4170_PIN_VBIAS) {
-			reg_val = BIT(chan->channel2);
-			ret = regmap_write(st->regmap, AD4170_V_BIAS_REG, reg_val);
-			if (ret)
-				dev_err_probe(dev, ret, "Failed to set vbias\n");
-		}
-	}
 	if (s_type == AD4170_WEIGH_SCALE_SENSOR)
 		ret = ad4170_setup_bridge(st, child, setup, exc_pins, exc_curs,
 					  num_exc_pins, ac_excited);
@@ -2521,7 +2512,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
 	unsigned int vbias_pins[AD4170_MAX_ANALOG_PINS];
 	struct ad4170_state *st = iio_priv(indio_dev);
 	struct device *dev = &st->spi->dev;
-	unsigned int num_vbias_pins;
+	unsigned int num_vbias_pins, vbias_mask = 0;
 	int reg_data, ret;
 	u32 int_pin_sel;
 	unsigned int i;
@@ -2577,7 +2568,12 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
 						     vbias_pins[i]);
 
 			st->pins_fn[vbias_pins[i]] |= AD4170_PIN_VBIAS;
+			vbias_mask |= BIT(vbias_pins[i]);
 		}
+
+		ret = regmap_write(st->regmap, AD4170_V_BIAS_REG, vbias_mask);
+		if (ret)
+			return dev_err_probe(dev, ret, "Failed to set vbias\n");
 	}
 
 	ret = ad4170_parse_channels(indio_dev);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (5 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 06/18] iio: adc: ad4170-4: Fix voltage bias programming Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 16:22   ` sashiko-bot
  2026-12-03 15:19 ` [PATCH 08/18] iio: adc: ad4170-4: Fix output data rate on AD4190-4 and AD4195-4 Janani Sunil
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

ad4170_fill_sps_tbl() computes the fractional part of each sample rate
with mult_frac(), which works in the type of its first argument. The
remainder times MICRO overflows unsigned int for remainders above 4294,
so the fractional part reported for FILTER_FS 65532 at the 16 MHz main
clock is 7.001085 instead of 7.629860. A slower main clock makes more
entries overflow.

Compute the fractional part with 64-bit arithmetic.

Fixes: a770f70b4f5b ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index f353b630834e..575ac8d61301 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -475,7 +475,8 @@ static void ad4170_fill_sps_tbl(struct ad4170_state *st)
 	for (i = 0; i < ARRAY_SIZE(ad4170_sinc3_filt_fs_tbl); i++) {
 		tmp0 = div_u64_rem(st->mclk_hz, 32 * ad4170_sinc3_filt_fs_tbl[i],
 				   &tmp1);
-		tmp1 = mult_frac(tmp1, MICRO, 32 * ad4170_sinc3_filt_fs_tbl[i]);
+		tmp1 = div_u64((u64)tmp1 * MICRO,
+			       32 * ad4170_sinc3_filt_fs_tbl[i]);
 		/* Fill sinc5+avg filter SPS table */
 		st->sps_tbl[AD4170_SINC5_AVG][i][0] = tmp0; /* Integer part */
 		st->sps_tbl[AD4170_SINC5_AVG][i][1] = tmp1; /* Fractional part */
@@ -488,7 +489,8 @@ static void ad4170_fill_sps_tbl(struct ad4170_state *st)
 	for (i = 0; i < ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl); i++) {
 		tmp0 = div_u64_rem(st->mclk_hz, 32 * ad4170_sinc5_filt_fs_tbl[i],
 				   &tmp1);
-		tmp1 = mult_frac(tmp1, MICRO, 32 * ad4170_sinc5_filt_fs_tbl[i]);
+		tmp1 = div_u64((u64)tmp1 * MICRO,
+			       32 * ad4170_sinc5_filt_fs_tbl[i]);
 		/* Fill sinc5 filter SPS table */
 		st->sps_tbl[AD4170_SINC5][i][0] = tmp0; /* Integer part */
 		st->sps_tbl[AD4170_SINC5][i][1] = tmp1; /* Fractional part */

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 08/18] iio: adc: ad4170-4: Fix output data rate on AD4190-4 and AD4195-4
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (6 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 09/18] iio: adc: ad4170-4: Fix filter_fs adjustment on filter type change Janani Sunil
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The main clock divider (CLOCKDIV in CLOCK_CTRL) defaults to divide-by-1
on the AD4170-4, but to divide-by-2 on the AD4190-4 and AD4195-4. The
driver uses the undivided input clock for the sample rate table and the
conversion timeout. On AD4190-4 and AD4195-4 this doubles the reported
sampling frequencies and halves the calculated settling time.

Add a per-device clock_div to chip_info and divide the main clock by it.
Initialize each channel's FILTER_FS to its reset value of 4. A fixed
default sampling frequency assumes a 16 MHz clock and can make probe fail
with -EINVAL for a valid external clock. For example, with a 12 MHz clock
the default filter on AD4190-4 runs at 46875 samples per second.

The external-clock case was identified during review with Codex.

Fixes: 5731f2a06c0f ("iio: adc: Add basic support for AD4170-4")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 575ac8d61301..0a5d29200ff2 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -194,7 +194,6 @@
 #define AD4170_SPI_INST_PHASE_LEN			2
 #define AD4170_SPI_MAX_XFER_LEN				6
 #define AD4170_NUM_CURRENT_SRC				4
-#define AD4170_DEFAULT_SAMP_RATE			(125 * HZ_PER_KHZ)
 
 #define AD4170_INT_REF_2_5V				2500000
 
@@ -211,6 +210,7 @@
 #define AD4170_SINC5_MIN_FS				1
 #define AD4170_SINC5_MAX_FS				256
 
+#define AD4170_FILTER_FS_REG_DEFAULT			4
 #define AD4170_GAIN_REG_DEFAULT				0x555555
 
 #define AD4170_ADC_CTRL_CONT_READ_EXIT			0xA5
@@ -374,18 +374,22 @@ static const char * const ad4170_sensor_type[] = {
 
 struct ad4170_chip_info {
 	const char *name;
+	unsigned int clock_div;
 };
 
 static const struct ad4170_chip_info ad4170_chip_info = {
 	.name = "ad4170-4",
+	.clock_div = 1,
 };
 
 static const struct ad4170_chip_info ad4190_chip_info = {
 	.name = "ad4190-4",
+	.clock_div = 2,
 };
 
 static const struct ad4170_chip_info ad4195_chip_info = {
 	.name = "ad4195-4",
+	.clock_div = 2,
 };
 
 /*
@@ -437,6 +441,7 @@ static const char * const ad4170_filt_names[] = {
 
 struct ad4170_state {
 	struct mutex lock; /* Protect read-modify-write and multi write sequences */
+	const struct ad4170_chip_info *chip;
 	int vrefs_uv[AD4170_MAX_SUP];
 	u32 mclk_hz;
 	struct ad4170_setup_info setup_infos[AD4170_MAX_SETUPS];
@@ -2479,7 +2484,7 @@ static int ad4170_clock_select(struct iio_dev *indio_dev)
 
 	if (!ext_clk) {
 		/* Use internal clock reference */
-		st->mclk_hz = AD4170_INT_CLOCK_16MHZ;
+		st->mclk_hz = AD4170_INT_CLOCK_16MHZ / st->chip->clock_div;
 		st->clock_ctrl |= FIELD_PREP(AD4170_CLOCK_CTRL_CLOCKSEL_MSK,
 					     AD4170_CLOCK_CTRL_CLOCKSEL_INT_OUT);
 
@@ -2506,6 +2511,8 @@ static int ad4170_clock_select(struct iio_dev *indio_dev)
 				     st->mclk_hz);
 	}
 
+	st->mclk_hz /= st->chip->clock_div;
+
 	return 0;
 }
 
@@ -2622,6 +2629,7 @@ static int ad4170_initial_config(struct iio_dev *indio_dev)
 		chan_info = &st->chan_infos[chan->address];
 
 		setup = &chan_info->setup;
+		setup->filter_fs = AD4170_FILTER_FS_REG_DEFAULT;
 		setup->gain = AD4170_GAIN_REG_DEFAULT;
 		ret = ad4170_write_channel_setup(st, chan->address, false);
 		if (ret)
@@ -2636,12 +2644,6 @@ static int ad4170_initial_config(struct iio_dev *indio_dev)
 			return dev_err_probe(dev, ret,
 					     "Failed to write CHAN_MAP_REG\n");
 
-		ret = ad4170_set_channel_freq(st, chan,
-					      AD4170_DEFAULT_SAMP_RATE, 0);
-		if (ret)
-			return dev_err_probe(dev, ret,
-					     "Failed to set channel freq\n");
-
 		ret = ad4170_fill_scale_tbl(indio_dev, chan);
 		if (ret)
 			return dev_err_probe(dev, ret,
@@ -2934,6 +2936,7 @@ static int ad4170_probe(struct spi_device *spi)
 	if (!chip)
 		return -EINVAL;
 
+	st->chip = chip;
 	indio_dev->name = chip->name;
 	indio_dev->info = &ad4170_info;
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 09/18] iio: adc: ad4170-4: Fix filter_fs adjustment on filter type change
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (7 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 08/18] iio: adc: ad4170-4: Fix output data rate on AD4190-4 and AD4195-4 Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 10/18] iio: adc: ad4170-4: Fix lock order inversion with IIO direct mode Janani Sunil
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

Each digital filter has its own FILTER_FS range, so filter_fs has to be
brought back into range when the filter type changes.
ad4170_set_filter_type() means to clamp filter_fs but passes val, the
requested filter type, to clamp(). Filter type values are 0 to 2, below
both minimums, so the clamp always returns the minimum and writing
filter_type discards the configured sampling frequency, setting it to
500 kSPS or 125 kSPS on AD4170-4.

Clamp filter_fs, as intended.

Fixes: a770f70b4f5b ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 0a5d29200ff2..25a47fae9ebb 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -887,10 +887,12 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
 			return -EBUSY;
 
 		if (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
-			setup->filter_fs = clamp(val, AD4170_SINC3_MIN_FS,
+			setup->filter_fs = clamp(setup->filter_fs,
+						 AD4170_SINC3_MIN_FS,
 						 AD4170_SINC3_MAX_FS);
 		else
-			setup->filter_fs = clamp(val, AD4170_SINC5_MIN_FS,
+			setup->filter_fs = clamp(setup->filter_fs,
+						 AD4170_SINC5_MIN_FS,
 						 AD4170_SINC5_MAX_FS);
 
 		setup->filter &= ~AD4170_FILTER_FILTER_TYPE_MSK;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 10/18] iio: adc: ad4170-4: Fix lock order inversion with IIO direct mode
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (8 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 09/18] iio: adc: ad4170-4: Fix filter_fs adjustment on filter type change Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 11/18] iio: adc: ad4170-4: Fix sinc5 filter FILTER_FS range on AD4190-4 and AD4195-4 Janani Sunil
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

ad4170_read_raw() and ad4170_set_filter_type() take st->lock before
claiming direct mode, while ad4170_write_raw() and the IIO core claim
the mode lock first and then take st->lock. A raw read or filter_type
write racing with a sampling_frequency, calibbias or calibscale write
can deadlock, each holding one of the two locks.

Claim direct mode before taking st->lock in both functions.

Fixes: 5731f2a06c0f ("iio: adc: Add basic support for AD4170-4")
Fixes: a770f70b4f5b ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 25a47fae9ebb..419bef6e16e7 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -882,10 +882,10 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
 	 * filter_fs value affects the ODR (sampling_frequency), changing the
 	 * filter may lead to a change in the sampling frequency.
 	 */
-	scoped_guard(mutex, &st->lock) {
-		if (!iio_device_claim_direct(indio_dev))
-			return -EBUSY;
+	if (!iio_device_claim_direct(indio_dev))
+		return -EBUSY;
 
+	scoped_guard(mutex, &st->lock) {
 		if (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
 			setup->filter_fs = clamp(setup->filter_fs,
 						 AD4170_SINC3_MIN_FS,
@@ -900,8 +900,8 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
 					    filter_type_conf);
 
 		ret = ad4170_write_channel_setup(st, chan->address, false);
-		iio_device_release_direct(indio_dev);
 	}
+	iio_device_release_direct(indio_dev);
 
 	return ret;
 }
@@ -1290,15 +1290,18 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
 	unsigned int pga, fs_idx;
 	int ret;
 
-	guard(mutex)(&st->lock);
-	switch (info) {
-	case IIO_CHAN_INFO_RAW:
+	if (info == IIO_CHAN_INFO_RAW) {
 		if (!iio_device_claim_direct(indio_dev))
 			return -EBUSY;
 
-		ret = ad4170_read_sample(indio_dev, chan, val);
+		scoped_guard(mutex, &st->lock)
+			ret = ad4170_read_sample(indio_dev, chan, val);
 		iio_device_release_direct(indio_dev);
 		return ret;
+	}
+
+	guard(mutex)(&st->lock);
+	switch (info) {
 	case IIO_CHAN_INFO_SCALE:
 		pga = FIELD_GET(AD4170_AFE_PGA_GAIN_MSK, setup->afe);
 		switch (chan->type) {

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 11/18] iio: adc: ad4170-4: Fix sinc5 filter FILTER_FS range on AD4190-4 and AD4195-4
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (9 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 10/18] iio: adc: ad4170-4: Fix lock order inversion with IIO direct mode Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 12/18] iio: adc: ad4170-4: Do not drive XTAL2 when using the internal clock Janani Sunil
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The sinc5 filter of the AD4170-4 accepts FILTER_FS values 1, 2, 4, and
multiples of 4 up to 256, but on the AD4190-4 and AD4195-4 the lowest
allowed value is 4. The driver has a single table of sinc5 FILTER_FS
values, taken from the AD4170-4, so on the AD4190-4 and AD4195-4 it
builds the two highest sinc5 sample rates out of FILTER_FS 1 and 2,
which those parts reject. Both rates are listed in
sampling_frequency_available and either can be written to
sampling_frequency.

The same table supplies the lower bound filter_fs is clamped to when the
sinc5 filter is selected, so the clamp does not lift a FILTER_FS of 1 or
2 to a value the part accepts.

Give the AD4190-4 and AD4195-4 their own sinc5 FILTER_FS table and reach
it through chip_info, and take the clamp lower bound from that table so
it follows the device too.

Fixes: a770f70b4f5b ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 419bef6e16e7..1195fcbf176f 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -207,7 +207,6 @@
 /* Digital filter properties */
 #define AD4170_SINC3_MIN_FS				4
 #define AD4170_SINC3_MAX_FS				65532
-#define AD4170_SINC5_MIN_FS				1
 #define AD4170_SINC5_MAX_FS				256
 
 #define AD4170_FILTER_FS_REG_DEFAULT			4
@@ -337,6 +336,10 @@ static const unsigned int ad4170_sinc5_filt_fs_tbl[] = {
 	1, 2, 4, 8, 12, 16, 20, 40, 48, 80, 100, 256,
 };
 
+static const unsigned int ad4190_sinc5_filt_fs_tbl[] = {
+	4, 8, 12, 16, 20, 40, 48, 80, 100, 256,
+};
+
 static const unsigned int ad4170_iout_pin_tbl[] = {
 	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(0),
 	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(1),
@@ -374,21 +377,29 @@ static const char * const ad4170_sensor_type[] = {
 
 struct ad4170_chip_info {
 	const char *name;
+	const unsigned int *sinc5_filt_fs_tbl;
+	unsigned int sinc5_filt_fs_tbl_size;
 	unsigned int clock_div;
 };
 
 static const struct ad4170_chip_info ad4170_chip_info = {
 	.name = "ad4170-4",
+	.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
 	.clock_div = 1,
 };
 
 static const struct ad4170_chip_info ad4190_chip_info = {
 	.name = "ad4190-4",
+	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
 	.clock_div = 2,
 };
 
 static const struct ad4170_chip_info ad4195_chip_info = {
 	.name = "ad4195-4",
+	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
 	.clock_div = 2,
 };
 
@@ -470,6 +481,7 @@ struct ad4170_state {
 
 static void ad4170_fill_sps_tbl(struct ad4170_state *st)
 {
+	const unsigned int *fs_tbl = st->chip->sinc5_filt_fs_tbl;
 	unsigned int tmp0, tmp1, i;
 
 	/*
@@ -491,11 +503,9 @@ static void ad4170_fill_sps_tbl(struct ad4170_state *st)
 		st->sps_tbl[AD4170_SINC3][i][1] = tmp1; /* Fractional part */
 	}
 	/* Sinc5 filter ODR doesn't use all FILTER_FS bits */
-	for (i = 0; i < ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl); i++) {
-		tmp0 = div_u64_rem(st->mclk_hz, 32 * ad4170_sinc5_filt_fs_tbl[i],
-				   &tmp1);
-		tmp1 = div_u64((u64)tmp1 * MICRO,
-			       32 * ad4170_sinc5_filt_fs_tbl[i]);
+	for (i = 0; i < st->chip->sinc5_filt_fs_tbl_size; i++) {
+		tmp0 = div_u64_rem(st->mclk_hz, 32 * fs_tbl[i], &tmp1);
+		tmp1 = div_u64((u64)tmp1 * MICRO, 32 * fs_tbl[i]);
 		/* Fill sinc5 filter SPS table */
 		st->sps_tbl[AD4170_SINC5][i][0] = tmp0; /* Integer part */
 		st->sps_tbl[AD4170_SINC5][i][1] = tmp1; /* Fractional part */
@@ -892,7 +902,7 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
 						 AD4170_SINC3_MAX_FS);
 		else
 			setup->filter_fs = clamp(setup->filter_fs,
-						 AD4170_SINC5_MIN_FS,
+						 st->chip->sinc5_filt_fs_tbl[0],
 						 AD4170_SINC5_MAX_FS);
 
 		setup->filter &= ~AD4170_FILTER_FILTER_TYPE_MSK;
@@ -1287,7 +1297,7 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
 	struct ad4170_chan_info *chan_info = &st->chan_infos[chan->address];
 	struct ad4170_setup *setup = &chan_info->setup;
 	enum ad4170_filter_type f_type;
-	unsigned int pga, fs_idx;
+	unsigned int pga, fs_idx, fs_size;
 	int ret;
 
 	if (info == IIO_CHAN_INFO_RAW) {
@@ -1340,9 +1350,10 @@ static int ad4170_read_raw(struct iio_dev *indio_dev,
 			*val2 = st->sps_tbl[f_type][fs_idx][1];
 			return IIO_VAL_INT_PLUS_MICRO;
 		case AD4170_SINC5:
+			fs_size = st->chip->sinc5_filt_fs_tbl_size;
 			fs_idx = find_closest(setup->filter_fs,
-					      ad4170_sinc5_filt_fs_tbl,
-					      ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl));
+					      st->chip->sinc5_filt_fs_tbl,
+					      fs_size);
 			*val = st->sps_tbl[f_type][fs_idx][0];
 			*val2 = st->sps_tbl[f_type][fs_idx][1];
 			return IIO_VAL_INT_PLUS_MICRO;
@@ -1455,7 +1466,7 @@ static int ad4170_read_avail(struct iio_dev *indio_dev,
 		case AD4170_SINC5:
 			/* Read sps_tbl here to ensure in bounds array access */
 			*vals = (int *)st->sps_tbl[f_type];
-			*length = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl) * 2;
+			*length = st->chip->sinc5_filt_fs_tbl_size * 2;
 			return IIO_AVAIL_LIST;
 		default:
 			return -EINVAL;
@@ -1503,7 +1514,7 @@ static int ad4170_set_channel_freq(struct ad4170_state *st,
 		filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc3_filt_fs_tbl);
 		break;
 	case AD4170_SINC5:
-		filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl);
+		filt_fs_tbl_size = st->chip->sinc5_filt_fs_tbl_size;
 		break;
 	}
 
@@ -1517,7 +1528,7 @@ static int ad4170_set_channel_freq(struct ad4170_state *st,
 
 	guard(mutex)(&st->lock);
 	if (f_type == AD4170_SINC5)
-		setup->filter_fs = ad4170_sinc5_filt_fs_tbl[i];
+		setup->filter_fs = st->chip->sinc5_filt_fs_tbl[i];
 	else
 		setup->filter_fs = ad4170_sinc3_filt_fs_tbl[i];
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 12/18] iio: adc: ad4170-4: Do not drive XTAL2 when using the internal clock
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (10 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 11/18] iio: adc: ad4170-4: Fix sinc5 filter FILTER_FS range on AD4190-4 and AD4195-4 Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 13/18] iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts Janani Sunil
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

When no external clock is supplied through the clocks property,
ad4170_clock_select() selects CLOCKSEL = 01, which is the internal
oscillator with the clock output routed to the XTAL2 pin on AD4170-4, or
to the CLK pin on AD4190-4 and AD4195-4. That drives the pin at IOVDD
logic level even though nothing requested the clock output, and on
AD4170-4 conflicts with boards that populate a crystal across XTAL1 and
XTAL2 so that either clock source can be selected.

Select CLOCKSEL = 00, internal oscillator with no output, and leave
enabling the clock output to the clock provider.

Fixes: 4e5fde667782 ("iio: adc: ad4170-4: Add clock provider support")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 1195fcbf176f..5ffc845266a2 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -2502,7 +2502,7 @@ static int ad4170_clock_select(struct iio_dev *indio_dev)
 		/* Use internal clock reference */
 		st->mclk_hz = AD4170_INT_CLOCK_16MHZ / st->chip->clock_div;
 		st->clock_ctrl |= FIELD_PREP(AD4170_CLOCK_CTRL_CLOCKSEL_MSK,
-					     AD4170_CLOCK_CTRL_CLOCKSEL_INT_OUT);
+					     AD4170_CLOCK_CTRL_CLOCKSEL_INT);
 
 		if (!device_property_present(&st->spi->dev, "#clock-cells"))
 			return 0;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 13/18] iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (11 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 12/18] iio: adc: ad4170-4: Do not drive XTAL2 when using the internal clock Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 14/18] iio: adc: ad4170-4: Require equal chopped excitation currents Janani Sunil
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The AD4190-4 and AD4195-4 have two excitation current sources instead
of four, and their CHOP_ADC field reserves the GPIO AC excitation codes
10 and 11. The driver allocates current sources across all channels
from four slots regardless of the device, so a third current-excited
channel programs the absent CURRENT_SOURCE2, and an AC-excited bridge
without excitation currents programs a reserved CHOP_ADC value.

Add the number of current sources and GPIO AC excitation support to
chip_info, bound the allocation by the former and reject the GPIO AC
excitation mode on devices without it.

Fixes: 6098df897d13 ("iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 5ffc845266a2..b96b6810e6ac 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -380,6 +380,8 @@ struct ad4170_chip_info {
 	const unsigned int *sinc5_filt_fs_tbl;
 	unsigned int sinc5_filt_fs_tbl_size;
 	unsigned int clock_div;
+	unsigned int num_current_src;
+	bool has_gpio_ac_excitation;
 };
 
 static const struct ad4170_chip_info ad4170_chip_info = {
@@ -387,6 +389,8 @@ static const struct ad4170_chip_info ad4170_chip_info = {
 	.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
 	.clock_div = 1,
+	.num_current_src = 4,
+	.has_gpio_ac_excitation = true,
 };
 
 static const struct ad4170_chip_info ad4190_chip_info = {
@@ -394,6 +398,7 @@ static const struct ad4170_chip_info ad4190_chip_info = {
 	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
 	.clock_div = 2,
+	.num_current_src = 2,
 };
 
 static const struct ad4170_chip_info ad4195_chip_info = {
@@ -401,6 +406,7 @@ static const struct ad4170_chip_info ad4195_chip_info = {
 	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
 	.clock_div = 2,
+	.num_current_src = 2,
 };
 
 /*
@@ -1947,11 +1953,11 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
 		unsigned int pin = exc_pins[i];
 		unsigned int current_src = 0;
 
-		for (j = 0; j < AD4170_NUM_CURRENT_SRC; j++)
+		for (j = 0; j < st->chip->num_current_src; j++)
 			if (st->cur_src_pins[j] == AD4170_CURRENT_SRC_DISABLED)
 				break;
 
-		if (j == AD4170_NUM_CURRENT_SRC)
+		if (j == st->chip->num_current_src)
 			return dev_err_probe(&st->spi->dev, -EINVAL,
 					     "Too many excitation current sources\n");
 
@@ -2040,6 +2046,10 @@ static int ad4170_setup_bridge(struct ad4170_state *st,
 							exc_curs, num_exc_pins,
 							ac_excited);
 
+	if (!st->chip->has_gpio_ac_excitation)
+		return dev_err_probe(&st->spi->dev, -EINVAL,
+				     "AC excitation through GPIOs not supported\n");
+
 	/*
 	 * Else, use predefined ACX1, ACX1 negated, ACX2, ACX2 negated signals
 	 * to AC excite the bridge. Those signals are output on GPIO2, GPIO0,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 14/18] iio: adc: ad4170-4: Require equal chopped excitation currents
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (12 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 13/18] iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 15/18] iio: adc: ad4170-4: Fix channel count with 15 external channels Janani Sunil
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

Excitation current chopping periodically swaps the output pins of a
pair of current sources, which the datasheets state requires both
currents to have the same value. The driver enables chopping without
checking the currents, so a pair with an omitted, zero, or different
current is accepted and chopped. It also accepts three excitation
sources, of which only the first pair can be chopped.

Reject current chopping unless it uses two or four excitation sources
and both currents of each chopped pair are nonzero and equal.

Fixes: 6098df897d13 ("iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index b96b6810e6ac..424be6fb851e 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -1948,6 +1948,20 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
 	unsigned int exc_cur_pair, i, j;
 	int ret;
 
+	if (ac_excited) {
+		if ((num_exc_pins != 2 && num_exc_pins != 4) ||
+		    num_exc_pins > st->chip->num_current_src)
+			return dev_err_probe(&st->spi->dev, -EINVAL,
+					     "Invalid excitation pin count for current chopping: %d\n",
+					     num_exc_pins);
+
+		/* Chopped excitation currents are swapped in pairs of equal value. */
+		for (i = 0; i < num_exc_pins; i += 2)
+			if (!exc_curs[i] || exc_curs[i] != exc_curs[i + 1])
+				return dev_err_probe(&st->spi->dev, -EINVAL,
+						     "Chopped excitation currents must be equal and nonzero\n");
+	}
+
 	for (i = 0; i < num_exc_pins; i++) {
 		unsigned int exc_cur = exc_curs[i];
 		unsigned int pin = exc_pins[i];
@@ -1973,11 +1987,6 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
 	if (!ac_excited)
 		return 0;
 
-	if (num_exc_pins < 2)
-		return dev_err_probe(&st->spi->dev, -EINVAL,
-			"Current chopping requested but only one pin provided: %u\n",
-			exc_pins[0]);
-
 	/*
 	 * Two use cases to handle here:
 	 * - 2 pairs of excitation currents;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 15/18] iio: adc: ad4170-4: Fix channel count with 15 external channels
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (13 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 14/18] iio: adc: ad4170-4: Require equal chopped excitation currents Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl Janani Sunil
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

ad4170_parse_channels() decides whether to append the temperature
channel from the child count already incremented for it. With 15
channel nodes the count reaches the 16 channel limit, so the
temperature channel is skipped while num_channels still accounts for
it. The timestamp lands in slot 15 and the advertised slot 16 is left
zeroed, which duplicates scan index 0 and makes probe fail.

Decide on the temperature channel from the number of channels actually
populated and derive num_channels from it.

Fixes: 03223844b8f2 ("iio: adc: ad4170-4: Add support for internal temperature sensor")
Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 424be6fb851e..7062ef306f58 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -2383,9 +2383,6 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
 	if (num_channels > AD4170_MAX_ADC_CHANNELS)
 		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
 
-	/* Add one for temperature */
-	num_channels = min(num_channels + 1, AD4170_MAX_ADC_CHANNELS);
-
 	chan_num = 0;
 	device_for_each_child_node_scoped(dev, child) {
 		ret = ad4170_parse_channel_node(indio_dev, child, chan_num++);
@@ -2397,7 +2394,7 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
 	 * Add internal temperature sensor channel if the maximum number of
 	 * channels has not been reached.
 	 */
-	if (num_channels < AD4170_MAX_ADC_CHANNELS) {
+	if (chan_num < AD4170_MAX_ADC_CHANNELS) {
 		struct ad4170_setup *setup = &st->chan_infos[chan_num].setup;
 
 		st->chans[chan_num] = ad4170_temp_channel_template;
@@ -2423,9 +2420,8 @@ static int ad4170_parse_channels(struct iio_dev *indio_dev)
 	struct iio_chan_spec ts_chan = IIO_CHAN_SOFT_TIMESTAMP(chan_num);
 
 	st->chans[chan_num] = ts_chan;
-	num_channels = num_channels + 1;
 
-	indio_dev->num_channels = num_channels;
+	indio_dev->num_channels = chan_num + 1;
 	indio_dev->channels = st->chans;
 
 	return 0;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (14 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 15/18] iio: adc: ad4170-4: Fix channel count with 15 external channels Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 17/18] dt-bindings: iio: adc: ad4170-4: Add AD4171-8, AD4190-8 and AD4195-8 Janani Sunil
  2026-12-03 15:19 ` [PATCH 18/18] iio: adc: ad4170-4: Add support for " Janani Sunil
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The valid CURRENT_SOURCEn I_OUT_PIN values are the analog input pins and
GPIO0 to GPIO3, which are two contiguous ranges. Check them directly
instead of looking the pin up in a table listing every value, and check
the pin availability in the same branch that identifies the pin type.

This prepares for devices with a different number of analog input pins,
for which a fixed table of valid pins would no longer fit.

No functional change intended.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/ad4170-4.c | 36 ++++++------------------------------
 1 file changed, 6 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 7062ef306f58..6c3b3b3a387a 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -340,22 +340,6 @@ static const unsigned int ad4190_sinc5_filt_fs_tbl[] = {
 	4, 8, 12, 16, 20, 40, 48, 80, 100, 256,
 };
 
-static const unsigned int ad4170_iout_pin_tbl[] = {
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(0),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(1),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(2),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(3),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(4),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(5),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(6),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(7),
-	AD4170_CURRENT_SRC_I_OUT_PIN_AIN(8),
-	AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0),
-	AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(1),
-	AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(2),
-	AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(3),
-};
-
 static const unsigned int ad4170_iout_current_ua_tbl[] = {
 	0, 10, 50, 100, 250, 500, 1000, 1500,
 };
@@ -1829,19 +1813,8 @@ static int ad4170_gpio_init(struct iio_dev *indio_dev)
 static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
 {
 	struct device *dev = &st->spi->dev;
-	unsigned int i;
-
-	/* Check the pin number is valid */
-	for (i = 0; i < ARRAY_SIZE(ad4170_iout_pin_tbl); i++)
-		if (ad4170_iout_pin_tbl[i] == pin)
-			break;
-
-	if (i == ARRAY_SIZE(ad4170_iout_pin_tbl))
-		return dev_err_probe(dev, -EINVAL,
-				     "Invalid excitation pin: %u\n",
-				     pin);
 
-	/* Check the pin is available */
+	/* Check the pin number is valid and the pin is available */
 	if (pin <= AD4170_MAX_ANALOG_PINS) {
 		if (st->pins_fn[pin] != AD4170_PIN_UNASSIGNED)
 			return dev_err_probe(dev, -EINVAL,
@@ -1849,7 +1822,9 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
 					     pin, st->pins_fn[pin]);
 
 		st->pins_fn[pin] |= AD4170_PIN_CURRENT_OUT;
-	} else {
+		return 0;
+	} else if (in_range(pin, AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0),
+			    AD4170_NUM_GPIO_PINS)) {
 		unsigned int gpio = pin - AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0);
 
 		if (st->gpio_fn[gpio] != AD4170_GPIO_UNASSIGNED)
@@ -1858,9 +1833,10 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
 					     gpio, st->gpio_fn[gpio]);
 
 		st->gpio_fn[gpio] |= AD4170_GPIO_AC_EXCITATION;
+		return 0;
 	}
 
-	return 0;
+	return dev_err_probe(dev, -EINVAL, "Invalid excitation pin: %u\n", pin);
 }
 
 static int ad4170_validate_excitation_pins(struct ad4170_state *st,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 17/18] dt-bindings: iio: adc: ad4170-4: Add AD4171-8, AD4190-8 and AD4195-8
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (15 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  2026-12-03 15:19 ` [PATCH 18/18] iio: adc: ad4170-4: Add support for " Janani Sunil
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The AD4171-8, AD4190-8, and AD4195-8 double the analog front end of the
four differential input devices. They have 16 analog input pins, AIN0 to
AIN15, plus a dedicated AINCOM pin, which CHANNEL_MAPn AINP_N/AINM_N
decodes as codes 01001 to 01111 and 10000. Those codes are reserved on
the four input devices, and V_BIAS and CURRENT_SOURCEn I_OUT_PIN follow
the same pattern.

The common diff-channels, single-channel and common-mode-channel
constraints list the valid inputs of the four differential input
devices, leaving out AIN9 to AIN15 and AINCOM, and the excitation pin
constraints likewise leave out AIN9 to AIN15. Relax them to the full mux
input and I_OUT_PIN ranges and move the four input restrictions into a
conditional on those compatibles.

The AD4190-8 and AD4195-8 share the AD4190-4 feature set, while the
AD4171-8 keeps that of the AD4170-4: an integrated DAC routed to mux
input 20, XTAL1 and XTAL2 pins, and four excitation current sources.

The new devices have sixteen analog inputs and an AINCOM pin instead of
nine analog inputs, which requires distinct chip configuration in the
driver, precluding a fallback to the four differential input devices.
The AD4195-8 only differs from the AD4190-8 in its guaranteed
specifications, but it gets its own compatible to match the AD4195-4,
which has no fallback to the AD4190-4 either.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 .../devicetree/bindings/iio/adc/adi,ad4170-4.yaml  | 124 ++++++++++++++++-----
 1 file changed, 97 insertions(+), 27 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
index 4d2d69c5bb9a..d6ffe2a544fc 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4170-4.yaml
@@ -13,8 +13,11 @@ description: |
   Analog Devices AD4170-4 series of Sigma-delta Analog to Digital Converters.
   Specifications can be found at:
     https://www.analog.com/media/en/technical-documentation/data-sheets/ad4170-4.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/ad4171-8.pdf
     https://www.analog.com/media/en/technical-documentation/data-sheets/ad4190-4.pdf
     https://www.analog.com/media/en/technical-documentation/data-sheets/ad4195-4.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/ad4190-8.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/ad4195-8.pdf
 
 $ref: /schemas/spi/spi-peripheral-props.yaml#
 
@@ -39,8 +42,11 @@ properties:
   compatible:
     enum:
       - adi,ad4170-4
+      - adi,ad4171-8
       - adi,ad4190-4
+      - adi,ad4190-8
       - adi,ad4195-4
+      - adi,ad4195-8
 
   avss-supply:
     description:
@@ -128,20 +134,23 @@ properties:
     description: Analog inputs to apply a voltage bias of (AVDD + AVSS) / 2 to.
     $ref: /schemas/types.yaml#/definitions/uint32-array
     minItems: 1
-    maxItems: 9
+    maxItems: 16
     items:
       minimum: 0
-      maximum: 8
+      maximum: 15
 
 allOf:
-  # Only AD4170-4 has an integrated DAC. On the other devices, the DAC output is
-  # not routed to the multiplexer either, making mux input number 20 reserved.
+  # Only AD4170-4 and AD4171-8 have an integrated DAC. On the other devices, the
+  # DAC output is not routed to the multiplexer either, making mux input number
+  # 20 reserved.
   - if:
       properties:
         compatible:
           not:
             contains:
-              const: adi,ad4170-4
+              enum:
+                - adi,ad4170-4
+                - adi,ad4171-8
     then:
       properties:
         ldac-gpios: false
@@ -162,26 +171,31 @@ allOf:
                 - maximum: 19
                 - minimum: 21
 
-  # Only AD4170-4 can be clocked by an external crystal. The other devices
-  # have no XTAL1 and XTAL2 pins.
+  # Only AD4170-4 and AD4171-8 can be clocked by an external crystal. The other
+  # devices have no XTAL1 and XTAL2 pins.
   - if:
       properties:
         compatible:
           not:
             contains:
-              const: adi,ad4170-4
+              enum:
+                - adi,ad4170-4
+                - adi,ad4171-8
     then:
       properties:
         clock-names:
           const: ext-clk
 
-  # AD4170-4 has four excitation current sources. The other devices have two.
+  # AD4170-4 and AD4171-8 have four excitation current sources. The other
+  # devices have two.
   - if:
       properties:
         compatible:
           not:
             contains:
-              const: adi,ad4170-4
+              enum:
+                - adi,ad4170-4
+                - adi,ad4171-8
     then:
       patternProperties:
         "^channel@[0-9a-f]$":
@@ -191,15 +205,18 @@ allOf:
             adi,excitation-current-2-microamp: false
             adi,excitation-current-3-microamp: false
 
-  # Only AD4170-4 can AC excite a bridge with its GPIO outputs. On the other
-  # devices, an AC excited bridge needs chopped excitation currents on IOUT0
-  # and IOUT1, which must be nonzero. The driver also requires them to be equal.
+  # Only AD4170-4 and AD4171-8 can AC excite a bridge with their GPIO outputs.
+  # On the other devices, an AC excited bridge needs chopped excitation currents
+  # on IOUT0 and IOUT1, which must be nonzero. The driver also requires them to
+  # be equal.
   - if:
       properties:
         compatible:
           not:
             contains:
-              const: adi,ad4170-4
+              enum:
+                - adi,ad4170-4
+                - adi,ad4171-8
     then:
       patternProperties:
         "^channel@[0-9a-f]$":
@@ -223,6 +240,52 @@ allOf:
               adi,excitation-current-1-microamp:
                 minimum: 1
 
+  # Devices with four differential inputs have analog input pins AIN0 to AIN8
+  # only. They have neither AIN9 to AIN15 nor an AINCOM pin.
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,ad4170-4
+              - adi,ad4190-4
+              - adi,ad4195-4
+    then:
+      properties:
+        adi,vbias-pins:
+          maxItems: 9
+          items:
+            maximum: 8
+      patternProperties:
+        "^channel@[0-9a-f]$":
+          properties:
+            diff-channels:
+              items:
+                enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23,
+                       24, 25, 26, 27, 28, 29]
+            single-channel:
+              enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24,
+                     25, 26, 27, 28, 29]
+            common-mode-channel:
+              enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24,
+                     25, 26, 27, 28, 29]
+            adi,excitation-pin-0:
+              anyOf:
+                - maximum: 8
+                - minimum: 17
+            adi,excitation-pin-1:
+              anyOf:
+                - maximum: 8
+                - minimum: 17
+            adi,excitation-pin-2:
+              anyOf:
+                - maximum: 8
+                - minimum: 17
+            adi,excitation-pin-3:
+              anyOf:
+                - maximum: 8
+                - minimum: 17
+
   # Require to specify the interrupt pin when using interrupts
   - if:
       required:
@@ -270,12 +333,15 @@ patternProperties:
           voltage channel. The first value is the positive input and the second
           value is the negative input of the channel.
 
-          Besides the analog input pins AIN0 to AIN8, there are special inputs
-          that can be selected with the following values:
+          The analog input pins are AIN0 to AIN8 on AD4170-4, AD4190-4, and
+          AD4195-4, selected with values 0 to 8. AD4171-8, AD4190-8, and
+          AD4195-8 have AIN0 to AIN15 plus an AINCOM pin, selected with values
+          0 to 15 and 16, respectively. Besides the analog input pins, there
+          are special inputs that can be selected with the following values:
           17: Internal temperature sensor
           18: (AVDD-AVSS)/5
           19: (IOVDD-DGND)/5
-          20: DAC output (AD4170-4 only)
+          20: DAC output (devices with an integrated DAC only)
           21: ALDO
           22: DLDO
           23: AVSS
@@ -288,22 +354,22 @@ patternProperties:
           For the internal temperature sensor, use the input number for both
           inputs (i.e. diff-channels = <17 17>).
         items:
-          enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
-                 26, 27, 28, 29]
+          minimum: 0
+          maximum: 29
 
       single-channel:
         description:
           Positive input of a pseudo-differential channel. Uses the same input
           numbers as diff-channels.
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
-               26, 27, 28, 29]
+        minimum: 0
+        maximum: 29
 
       common-mode-channel:
         description:
           Negative input of a pseudo-differential channel. Uses the same input
           numbers as diff-channels.
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25,
-               26, 27, 28, 29]
+        minimum: 0
+        maximum: 29
 
       adi,reference-select:
         description: |
@@ -345,7 +411,8 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
+        minimum: 0
+        maximum: 20
         default: 0
 
       adi,excitation-pin-1:
@@ -353,7 +420,8 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
+        minimum: 0
+        maximum: 20
         default: 0
 
       adi,excitation-pin-2:
@@ -361,7 +429,8 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
+        minimum: 0
+        maximum: 20
         default: 0
 
       adi,excitation-pin-3:
@@ -369,7 +438,8 @@ patternProperties:
           Analog input to apply excitation current to while the channel
           is active.
         $ref: /schemas/types.yaml#/definitions/uint32
-        enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 17, 18, 19, 20]
+        minimum: 0
+        maximum: 20
         default: 0
 
       adi,excitation-current-0-microamp:

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 18/18] iio: adc: ad4170-4: Add support for AD4171-8, AD4190-8 and AD4195-8
  2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
                   ` (16 preceding siblings ...)
  2026-12-03 15:19 ` [PATCH 17/18] dt-bindings: iio: adc: ad4170-4: Add AD4171-8, AD4190-8 and AD4195-8 Janani Sunil
@ 2026-12-03 15:19 ` Janani Sunil
  17 siblings, 0 replies; 20+ messages in thread
From: Janani Sunil @ 2026-12-03 15:19 UTC (permalink / raw)
  To: Marcelo Schmitt, Nuno Sá, Michael Hennerich,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Ana-Maria Cusco
  Cc: Conor Dooley, linux-iio, linux-kernel, linux, devicetree,
	Janani Sunil, Janani Sunil, Jonathan Cameron

The AD4171-8, AD4190-8, and AD4195-8 are eight differential input members
of the AD4170 family. They expose analog inputs AIN0 to AIN15 plus a
dedicated AINCOM pin. The AD4190-8 and AD4195-8 have no integrated DAC and
share the AD4190-4 sinc5 FS range and clock divider, while the AD4171-8
keeps the AD4170-4 feature set, so its maximum output data rate is
500 kSPS.

Move the remaining per-device difference, the analog pin count, into
chip_info so input validation adapts at runtime. That also lifts the
adi,vbias-pins count limit to the nine analog input pins the four input
devices actually have.

AINCOM (input number 16) can be the positive or negative input of a
channel on these parts. Accept it during channel input validation, and
track its use separately from pins_fn[], which only tracks the regular
analog input pins, so that AINCOM follows the same rules as those pins
when shared between channel inputs and excitation current outputs.

CURRENT_SOURCEn I_OUT_PIN accepts the same set of inputs, so excitation
pin validation follows the analog pin count as well and accepts AINCOM
where it exists.

Signed-off-by: Janani Sunil <janani.sunil@analog.com>
---
 drivers/iio/adc/Kconfig    |  5 +--
 drivers/iio/adc/ad4170-4.c | 85 +++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 76 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 82e2eb652e16..4aff5c620c8c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -149,8 +149,9 @@ config AD4170_4
 	depends on COMMON_CLK
 	depends on GPIOLIB
 	help
-	  Say yes here to build support for Analog Devices AD4170-4 SPI analog
-	  to digital converters (ADC).
+	  Say yes here to build support for Analog Devices AD4170-4, AD4171-8,
+	  AD4190-4, AD4190-8, AD4195-4, and AD4195-8 SPI analog to digital
+	  converters (ADC).
 
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad4170-4.
diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 6c3b3b3a387a..7c16fc784c92 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -139,6 +139,7 @@
 
 /* AD4170_CHAN_MAP_REG constants */
 #define AD4170_CHAN_MAP_AIN(x)			(x)
+#define AD4170_CHAN_MAP_AINCOM			16
 #define AD4170_CHAN_MAP_TEMP_SENSOR		17
 #define AD4170_CHAN_MAP_AVDD_AVSS_P		18
 #define AD4170_CHAN_MAP_AVDD_AVSS_N		18
@@ -184,11 +185,10 @@
 
 /* Device properties and auxiliary constants */
 
-#define AD4170_NUM_ANALOG_PINS				9
 #define AD4170_NUM_GPIO_PINS				4
 #define AD4170_MAX_ADC_CHANNELS				16
 #define AD4170_MAX_IIO_CHANNELS				(AD4170_MAX_ADC_CHANNELS + 1)
-#define AD4170_MAX_ANALOG_PINS				8
+#define AD4170_MAX_ANALOG_PINS				16
 #define AD4170_MAX_SETUPS				8
 #define AD4170_INVALID_SETUP				9
 #define AD4170_SPI_INST_PHASE_LEN			2
@@ -363,8 +363,10 @@ struct ad4170_chip_info {
 	const char *name;
 	const unsigned int *sinc5_filt_fs_tbl;
 	unsigned int sinc5_filt_fs_tbl_size;
+	unsigned int num_analog_pins;
 	unsigned int clock_div;
 	unsigned int num_current_src;
+	bool has_aincom;
 	bool has_gpio_ac_excitation;
 };
 
@@ -372,15 +374,28 @@ static const struct ad4170_chip_info ad4170_chip_info = {
 	.name = "ad4170-4",
 	.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
+	.num_analog_pins = 9,
 	.clock_div = 1,
 	.num_current_src = 4,
 	.has_gpio_ac_excitation = true,
 };
 
+static const struct ad4170_chip_info ad4171_8_chip_info = {
+	.name = "ad4171-8",
+	.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
+	.num_analog_pins = 16,
+	.clock_div = 1,
+	.num_current_src = 4,
+	.has_aincom = true,
+	.has_gpio_ac_excitation = true,
+};
+
 static const struct ad4170_chip_info ad4190_chip_info = {
 	.name = "ad4190-4",
 	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+	.num_analog_pins = 9,
 	.clock_div = 2,
 	.num_current_src = 2,
 };
@@ -389,10 +404,31 @@ static const struct ad4170_chip_info ad4195_chip_info = {
 	.name = "ad4195-4",
 	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
 	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+	.num_analog_pins = 9,
 	.clock_div = 2,
 	.num_current_src = 2,
 };
 
+static const struct ad4170_chip_info ad4190_8_chip_info = {
+	.name = "ad4190-8",
+	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+	.num_analog_pins = 16,
+	.clock_div = 2,
+	.num_current_src = 2,
+	.has_aincom = true,
+};
+
+static const struct ad4170_chip_info ad4195_8_chip_info = {
+	.name = "ad4195-8",
+	.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+	.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+	.num_analog_pins = 16,
+	.clock_div = 2,
+	.num_current_src = 2,
+	.has_aincom = true,
+};
+
 /*
  * There are 8 of each MISC, AFE, FILTER, FILTER_FS, OFFSET, and GAIN
  * configuration registers. That is, there are 8 miscellaneous registers, MISC0
@@ -458,7 +494,8 @@ struct ad4170_state {
 	struct iio_trigger *trig;
 	struct clk_hw int_clk_hw;
 	unsigned int clock_ctrl;
-	unsigned int pins_fn[AD4170_NUM_ANALOG_PINS];
+	unsigned int pins_fn[AD4170_MAX_ANALOG_PINS];
+	unsigned int aincom_fn;
 	int gpio_fn[AD4170_NUM_GPIO_PINS];
 	unsigned int cur_src_pins[AD4170_NUM_CURRENT_SRC];
 	struct gpio_chip gpiochip;
@@ -975,9 +1012,9 @@ static const struct iio_chan_spec ad4170_temp_channel_template = {
 /*
  * Receives the number of a multiplexed AD4170 input (ain_n), and stores the
  * voltage (in µV) of the specified input into ain_voltage. If the input number
- * is a ordinary analog input (AIN0 to AIN8), stores zero into ain_voltage.
- * If a voltage regulator required by a special input is unavailable, return
- * error code. Return 0 on success.
+ * is an ordinary analog input pin, AINCOM, or the temperature sensor, stores
+ * zero into ain_voltage. If a voltage regulator required by a special input is
+ * unavailable, return error code. Return 0 on success.
  */
 static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
 				     int *ain_voltage)
@@ -993,7 +1030,7 @@ static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
 	 * So, we do AVDD - AVSS to compute the DC voltage generated by the bias
 	 * voltage generator.
 	 */
-	if (ain_n < AD4170_NUM_ANALOG_PINS &&
+	if (ain_n < st->chip->num_analog_pins &&
 	    st->pins_fn[ain_n] & AD4170_PIN_VBIAS) {
 		int v_diff = st->vrefs_uv[AD4170_AVDD_SUP] - st->vrefs_uv[AD4170_AVSS_SUP];
 		*ain_voltage = v_diff / 2;
@@ -1056,7 +1093,7 @@ static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
 
 static int ad4170_validate_analog_input(struct ad4170_state *st, int pin)
 {
-	if (pin <= AD4170_MAX_ANALOG_PINS) {
+	if (pin < st->chip->num_analog_pins) {
 		if (st->pins_fn[pin] & AD4170_PIN_CURRENT_OUT)
 			return dev_err_probe(&st->spi->dev, -EINVAL,
 					     "Pin %d already used with fn %u.\n",
@@ -1069,6 +1106,16 @@ static int ad4170_validate_analog_input(struct ad4170_state *st, int pin)
 
 static int ad4170_validate_channel_input(struct ad4170_state *st, int pin, bool com)
 {
+	if (st->chip->has_aincom && pin == AD4170_CHAN_MAP_AINCOM) {
+		if (st->aincom_fn & AD4170_PIN_CURRENT_OUT)
+			return dev_err_probe(&st->spi->dev, -EINVAL,
+					     "AINCOM already used with fn %u.\n",
+					     st->aincom_fn);
+
+		st->aincom_fn |= AD4170_PIN_ANALOG_IN;
+		return 0;
+	}
+
 	/* Check common-mode input pin is mapped to a special input. */
 	if (com && (pin < AD4170_CHAN_MAP_AVDD_AVSS_P || pin > AD4170_CHAN_MAP_REFOUT))
 		return dev_err_probe(&st->spi->dev, -EINVAL,
@@ -1076,7 +1123,7 @@ static int ad4170_validate_channel_input(struct ad4170_state *st, int pin, bool
 				     pin);
 
 	/* Check differential input pin is mapped to a analog input pin. */
-	if (!com && pin > AD4170_MAX_ANALOG_PINS)
+	if (!com && pin >= st->chip->num_analog_pins)
 		return dev_err_probe(&st->spi->dev, -EINVAL,
 				     "Invalid analog input pin number. %d\n",
 				     pin);
@@ -1815,7 +1862,7 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
 	struct device *dev = &st->spi->dev;
 
 	/* Check the pin number is valid and the pin is available */
-	if (pin <= AD4170_MAX_ANALOG_PINS) {
+	if (pin < st->chip->num_analog_pins) {
 		if (st->pins_fn[pin] != AD4170_PIN_UNASSIGNED)
 			return dev_err_probe(dev, -EINVAL,
 					     "Pin %u already used with fn %u\n",
@@ -1834,6 +1881,14 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
 
 		st->gpio_fn[gpio] |= AD4170_GPIO_AC_EXCITATION;
 		return 0;
+	} else if (st->chip->has_aincom && pin == AD4170_CHAN_MAP_AINCOM) {
+		if (st->aincom_fn != AD4170_PIN_UNASSIGNED)
+			return dev_err_probe(dev, -EINVAL,
+					     "AINCOM already used with fn %u\n",
+					     st->aincom_fn);
+
+		st->aincom_fn |= AD4170_PIN_CURRENT_OUT;
+		return 0;
 	}
 
 	return dev_err_probe(dev, -EINVAL, "Invalid excitation pin: %u\n", pin);
@@ -2564,7 +2619,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
 
 	ret = device_property_count_u32(dev, "adi,vbias-pins");
 	if (ret > 0) {
-		if (ret > AD4170_MAX_ANALOG_PINS)
+		if (ret > st->chip->num_analog_pins)
 			return dev_err_probe(dev, -EINVAL,
 					     "Too many vbias pins %u\n", ret);
 
@@ -2578,7 +2633,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
 					     "Failed to read vbias pins\n");
 
 		for (i = 0; i < num_vbias_pins; i++) {
-			if (vbias_pins[i] >= AD4170_NUM_ANALOG_PINS)
+			if (vbias_pins[i] >= st->chip->num_analog_pins)
 				return dev_err_probe(dev, -EINVAL,
 						     "Invalid vbias pin %u\n",
 						     vbias_pins[i]);
@@ -2996,16 +3051,22 @@ static int ad4170_probe(struct spi_device *spi)
 
 static const struct spi_device_id ad4170_id_table[] = {
 	{ .name = "ad4170-4", .driver_data = (kernel_ulong_t)&ad4170_chip_info },
+	{ .name = "ad4171-8", .driver_data = (kernel_ulong_t)&ad4171_8_chip_info },
 	{ .name = "ad4190-4", .driver_data = (kernel_ulong_t)&ad4190_chip_info },
+	{ .name = "ad4190-8", .driver_data = (kernel_ulong_t)&ad4190_8_chip_info },
 	{ .name = "ad4195-4", .driver_data = (kernel_ulong_t)&ad4195_chip_info },
+	{ .name = "ad4195-8", .driver_data = (kernel_ulong_t)&ad4195_8_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ad4170_id_table);
 
 static const struct of_device_id ad4170_of_match[] = {
 	{ .compatible = "adi,ad4170-4", .data = &ad4170_chip_info },
+	{ .compatible = "adi,ad4171-8", .data = &ad4171_8_chip_info },
 	{ .compatible = "adi,ad4190-4", .data = &ad4190_chip_info },
+	{ .compatible = "adi,ad4190-8", .data = &ad4190_8_chip_info },
 	{ .compatible = "adi,ad4195-4", .data = &ad4195_chip_info },
+	{ .compatible = "adi,ad4195-8", .data = &ad4195_8_chip_info },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, ad4170_of_match);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part
  2026-12-03 15:19 ` [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part Janani Sunil
@ 2026-12-03 16:22   ` sashiko-bot
  0 siblings, 0 replies; 20+ messages in thread
From: sashiko-bot @ 2026-12-03 16:22 UTC (permalink / raw)
  To: Janani Sunil; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] iio: ad4170-4: commit message misstates mult_frac() overflow
  type and scope
--

commit 8496654d945dc5fa6e87112d8df24f14ce2e8f43
Author: Janani Sunil <janani.sunil@analog.com>

iio: adc: ad4170-4: Fix overflow in sample rate fractional part

This commit replaces mult_frac() with 64-bit div_u64() arithmetic when
computing the fractional part of sample rates in ad4170_fill_sps_tbl().

> ad4170_fill_sps_tbl() computes the fractional part of each sample rate
> with mult_frac(), which works in the type of its first argument. The
> remainder times MICRO overflows unsigned int for remainders above 4294,

[Severity: Low]
Is this description of the mult_frac() overflow accurate?

mult_frac() in include/linux/math.h preserves typeof(n) in n_, and MICRO in
include/linux/units.h is 1000000UL.  Because r * n_ promotes r to unsigned
long rather than unsigned int, the overflow only happens on 32-bit
architectures where unsigned long is 32 bits.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ad419x-release-v1-0-18578ab50524@analog.com?part=7

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-12-03 16:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:19 [PATCH 00/18] iio: adc: ad4170-4: Fixes and AD4171-8/AD4190-8/AD4195-8 support Janani Sunil
2026-12-03 15:19 ` [PATCH 01/18] dt-bindings: iio: adc: ad4170-4: Restrict AD4170-4 only properties Janani Sunil
2026-12-03 15:19 ` [PATCH 02/18] dt-bindings: iio: adc: ad4170-4: Restrict channel inputs to valid codes Janani Sunil
2026-12-03 15:19 ` [PATCH 03/18] dt-bindings: iio: adc: ad4170-4: Allow running from the internal oscillator only Janani Sunil
2026-12-03 15:19 ` [PATCH 04/18] dt-bindings: iio: adc: ad4170-4: Fix the voltage bias description Janani Sunil
2026-12-03 15:19 ` [PATCH 05/18] iio: adc: ad4170-4: Fix out-of-bounds accesses to pins_fn[] Janani Sunil
2026-12-03 15:19 ` [PATCH 06/18] iio: adc: ad4170-4: Fix voltage bias programming Janani Sunil
2026-12-03 15:19 ` [PATCH 07/18] iio: adc: ad4170-4: Fix overflow in sample rate fractional part Janani Sunil
2026-12-03 16:22   ` sashiko-bot
2026-12-03 15:19 ` [PATCH 08/18] iio: adc: ad4170-4: Fix output data rate on AD4190-4 and AD4195-4 Janani Sunil
2026-12-03 15:19 ` [PATCH 09/18] iio: adc: ad4170-4: Fix filter_fs adjustment on filter type change Janani Sunil
2026-12-03 15:19 ` [PATCH 10/18] iio: adc: ad4170-4: Fix lock order inversion with IIO direct mode Janani Sunil
2026-12-03 15:19 ` [PATCH 11/18] iio: adc: ad4170-4: Fix sinc5 filter FILTER_FS range on AD4190-4 and AD4195-4 Janani Sunil
2026-12-03 15:19 ` [PATCH 12/18] iio: adc: ad4170-4: Do not drive XTAL2 when using the internal clock Janani Sunil
2026-12-03 15:19 ` [PATCH 13/18] iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts Janani Sunil
2026-12-03 15:19 ` [PATCH 14/18] iio: adc: ad4170-4: Require equal chopped excitation currents Janani Sunil
2026-12-03 15:19 ` [PATCH 15/18] iio: adc: ad4170-4: Fix channel count with 15 external channels Janani Sunil
2026-12-03 15:19 ` [PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl Janani Sunil
2026-12-03 15:19 ` [PATCH 17/18] dt-bindings: iio: adc: ad4170-4: Add AD4171-8, AD4190-8 and AD4195-8 Janani Sunil
2026-12-03 15:19 ` [PATCH 18/18] iio: adc: ad4170-4: Add support for " Janani Sunil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox