iio: adc: Add support for LTC2378 and similar ADCs
Marcelo Schmitt
maintainerv7 cover iio: adc: Add support for LTC2378 and similar ADCs
This patch series adds support for LTC2378 and similar low noise, low power, high speed, successive approximation register (SAR) ADCs. These ADCs are similar among each other, varying mainly on the amount of precision bits, maximum sample rate, and input configuration (either fully differential or pseudo-differential).
Patch 1 adds device tree documentation for LTC2378.
Patch 2 enables single-shot sample read with a GPIO connected to the LTC2378 CNV pin.
Patch 3 enables high-speed data captures with SPI offloading.
The setup is similar to AD4030, with a specialized PWM generator being used both for SPI offload triggering and conversion start signaling.
Patch 4 enables running buffered data captures without SPI offloading.
Even though these parts are somewhat similar to AD4000, the wiring configuration for LTC parts is different as well as the available HDL for high speed sample rate mode. Because of that, I propose creating a new device driver for supporting LTC2378-like devices.
Specifications can be found at:
https://www.analog.com/media/en/technical-documentation/data-sheets/233818fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236416fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236418f.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236716fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236718f.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236816f.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236818f.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/236918fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237016fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237616fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237618fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237620fb.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237716fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237718fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237720fb.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237816fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237818fa.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237820fb.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/237918fb.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/238016fb.pdf
Previous submissions:
v6: https://lore.kernel.org/linux-iio/[email protected]/
v5: https://lore.kernel.org/linux-iio/[email protected]/
v4: https://lore.kernel.org/linux-iio/[email protected]/
v3: https://lore.kernel.org/linux-iio/[email protected]/
v2: https://lore.kernel.org/linux-iio/[email protected]/
v1: https://lore.kernel.org/linux-iio/[email protected]/
Change log v6 -> v7:
[DT]
No changes in device tree doc.
[IIO]
- Extended single-read critical section scope (holding mutex lock longer).
- Added comment about conversion wait time.
- Now keeping validated offload configurations if conversion rate update fails.
- Imported SPI_OFFLOAD name space.
- Replaced DIV_ROUND_UP() by div_u64() to mitigate config check fail due to different integer rounding.
- When applicable, return early from regulator setup.
- Separate macros for offload and non-offload channels.
- Moved ltc2378_prepare_offload_message() downwards in source code.
- Wrapped transfer buffer declaration comment closer to 80 characters.
- Picked up review tags.
With best regards,
Marcelo
Marcelo Schmitt (4):
dt-bindings: iio: adc: Add ltc2378
iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
iio: adc: ltc2378: Enable high-speed data capture
iio: adc: ltc2378: Enable triggered buffer data capture
.../bindings/iio/adc/adi,ltc2378.yaml | 170 ++++ MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 19 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ltc2378.c | 842 ++++++++++++++++++ 5 files changed, 1040 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ltc2378.yaml create mode 100644 drivers/iio/adc/ltc2378.c
base-commit: aa58ecc73466d0cb8c418de98e2225490bf600e3
Signature · 1 line
2.53.0
Marcelo Schmitt
maintainerPATCH v7 1/4 dt-bindings: iio: adc: Add ltc2378
Document how to describe LTC2378-20 and similar ADCs in device tree.
---
Change log v6 -> v7:
No changes in v7.
.../bindings/iio/adc/adi,ltc2378.yaml | 170 ++++++++++++++++++ MAINTAINERS | 7 + 2 files changed, 177 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ltc2378.yaml
Documentation/devicetree/bindings/iio/adc/adi,ltc2378.yaml new file +170 -0
@@ -0,0 +1,170 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/adi,ltc2378.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices LTC2378 and similar Analog to Digital Converters + +maintainers: + - Marcelo Schmitt <[email protected]> + +description: | + Analog Devices LTC2378 series of ADCs. + Specifications can be found at: + https://www.analog.com/media/en/technical-documentation/data-sheets/233818fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236416fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236418f.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236716fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236718f.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236816f.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236818f.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/236918fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237016fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237616fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237618fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237620fb.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237716fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237718fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237720fb.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237816fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237818fa.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237820fb.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/237918fb.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/238016fb.pdf + +$ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + oneOf: + # Single compatible string match. + - enum: + - adi,ltc2338-18 + - adi,ltc2364-16 + - adi,ltc2364-18 + - adi,ltc2376-16 + - adi,ltc2376-18 + - adi,ltc2376-20 + + # Low sample rate fallback for 16-bit unipolar sensors. + - items: + - enum: + - adi,ltc2370-16 # 2 MSPS + - adi,ltc2368-16 # 1 MSPS + - adi,ltc2367-16 # 500 kSPS + - const: adi,ltc2364-16 # fallback (250 kSPS) + + # Low sample rate fallback for 18-bit unipolar sensors. + - items: + - enum: + - adi,ltc2369-18 # 1.6 MSPS + - adi,ltc2368-18 # 1 MSPS + - adi,ltc2367-18 # 500 kSPS + - const: adi,ltc2364-18 # fallback (250 kSPS) + + # Low sample rate fallback for 16-bit bipolar sensors. + - items: + - enum: + - adi,ltc2380-16 # 2 MSPS + - adi,ltc2378-16 # 1 MSPS + - adi,ltc2377-16 # 500 kSPS + - const: adi,ltc2376-16 # fallback (250 kSPS) + + # Low sample rate fallback for 18-bit bipolar sensors. + - items: + - enum: + - adi,ltc2379-18 # 1.6 MSPS + - adi,ltc2378-18 # 1 MSPS + - adi,ltc2377-18 # 500 kSPS + - const: adi,ltc2376-18 # fallback (250 kSPS) + + # Low sample rate fallback for 20-bit bipolar sensors. + - items: + - enum: + - adi,ltc2378-20 # 1 MSPS + - adi,ltc2377-20 # 500 kSPS + - const: adi,ltc2376-20 # fallback (250 kSPS) + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 100000000 + + vdd-supply: + description: A 2.5V supply that powers the chip (VDD). + + ovdd-supply: + description: + A 1.71V to 5.25V supply that sets the logic level for digital interface. + + ref-supply: + description: + Voltage reference input that determines the scale of ADC conversions. + + refin-supply: + description: + Alternative voltage reference input. + + cnv-gpios: + description: + When provided, this property indicates the GPIO that is connected to the + CNV pin. + maxItems: 1 + + pwms: + description: PWM signal connected to the CNV pin. + maxItems: 1 + + interrupts: + description: + Interrupt for signaling the completion of conversion results. The active + low signal provided on the BUSY pin asserts when ADC conversions finish. + maxItems: 1 + +required: + - compatible + - reg + - vdd-supply + - ovdd-supply + +allOf: + # Except for LTC2338, all designs require a voltage reference input + - if: + properties: + compatible: + not: + contains: + enum: + - adi,ltc2338-18 + then: + required: + - ref-supply + properties: + refin-supply: false + else: + properties: + ref-supply: false + +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 = "adi,ltc2378-20", "adi,ltc2376-20"; + reg = <0>; + spi-max-frequency = <71000000>; + vdd-supply = <&supply_2_5V>; + ovdd-supply = <&supply_3_3V>; + ref-supply = <&supply_5V>; + cnv-gpios = <&gpio0 88 GPIO_ACTIVE_HIGH>; + interrupts = <7 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio>; + }; + };
MAINTAINERS +7 -0
@@ -15343,6 +15343,13 @@ S: Maintained F: Documentation/devicetree/bindings/iio/dac/lltc,ltc1660.yaml F: drivers/iio/dac/ltc1660.c +LTC2378 IIO ADC DRIVER +M: Marcelo Schmitt <[email protected]> +L: [email protected] +S: Supported +W: https://ez.analog.com/linux-software-drivers +F: Documentation/devicetree/bindings/iio/adc/adi,ltc2378.yaml + LTC2664 IIO DAC DRIVER M: Michael Hennerich <[email protected]> M: Kim Seer Paller <[email protected]>
Signature · 1 line
2.53.0
Marcelo Schmitt
maintainerPATCH v7 2/4 iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
In reply to Marcelo SchmittSupport for LTC2378-20 and similar analog-to-digital converters.
---
Change log v6 -> v7:
- Extended single-read critical section scope (holding mutex lock longer).
- Added comment about conversion wait time.
- When applicable, return early from regulator setup.
- Wrapped transfer buffer declaration comment closer to 80 characters.
Some bits related to the SPI transfer buffer are introduced early to minimize the change diff of the followup offload enablement patch.
MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 12 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ltc2378.c | 416 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 430 insertions(+) create mode 100644 drivers/iio/adc/ltc2378.c
MAINTAINERS +1 -0
@@ -15349,6 +15349,7 @@ L: [email protected] S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/adc/adi,ltc2378.yaml +F: drivers/iio/adc/ltc2378.c LTC2664 IIO DAC DRIVER M: Michael Hennerich <[email protected]>
drivers/iio/adc/Kconfig +12 -0
@@ -943,6 +943,18 @@ config LTC2309 This driver can also be built as a module. If so, the module will be called ltc2309. +config LTC2378 + tristate "Analog Devices LTC2378 ADC driver" + depends on SPI + depends on REGULATOR || COMPILE_TEST + depends on GPIOLIB + help + Say yes here to build support for Analog Devices LTC2378-20 and + similar analog to digital converters. + + This driver can also be built as a module. If so, the module will + be called ltc2378. + config LTC2471 tristate "Linear Technology LTC2471 and LTC2473 ADC driver" depends on I2C
drivers/iio/adc/Makefile +1 -0
@@ -81,6 +81,7 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o obj-$(CONFIG_LTC2309) += ltc2309.o +obj-$(CONFIG_LTC2378) += ltc2378.o obj-$(CONFIG_LTC2471) += ltc2471.o obj-$(CONFIG_LTC2485) += ltc2485.o obj-$(CONFIG_LTC2496) += ltc2496.o ltc2497-core.o
drivers/iio/adc/ltc2378.c new file +416 -0
416 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `LTC2378_DIFF_CHANNEL` macro defines an IIO channel that is intended to be differential but…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The LTC2378_DIFF_CHANNEL macro defines an IIO channel that is intended to be differential but lacks the .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1 attributes. --
--- Patch [2]: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs --- commit 5710d5f25b45906977e2522567c1964b1d3219f8
Author: Marcelo Schmitt <[email protected]>
iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
This commit adds a new driver for the Analog Devices LTC2378-20 and similar analog-to-digital converters.
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +0
-0@@ -0,0 +1,416 @@
[ ... ]
drivers/iio/adc/ltc2378.c line 36
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +6
-0+#define LTC2378_DIFF_CHANNEL (_sign, _real_bits, _storage_bits) \ +{ \ + .type = IIO_VOLTAGE, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \
[Severity: Medium]
Does this macro need to set .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1? The name suggests these are differential channels, but without these attributes, the IIO ABI will expose them as single-ended (e.g., in_voltage_raw instead of in_voltage0-voltage1_raw).
Quoted 16 lines
drivers/iio/adc/ltc2378.c new file +16
-0+ .scan_type = { \ + .format = _sign ? IIO_SCAN_FORMAT_SIGNED_INT : \ + IIO_SCAN_FORMAT_UNSIGNED_INT, \ + .realbits = _real_bits, \ + .storagebits = _storage_bits, \ + .shift = _storage_bits - _real_bits, \ + .endianness = IIO_BE, \ + }, \ +} + +#define LTC2378_BIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(1, _real_bits, (((_real_bits) > 16) ? 32 : 16)) + +#define LTC2378_UNIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(0, _real_bits, (((_real_bits) > 16) ? 32 : 16)) +
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Quoted 20 lines · On 07/16, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TheLTC2378_DIFF_CHANNELmacro defines an IIO channel that is intended to be differential but lacks the.differential = 1,.indexed = 1,.channel = 0, and.channel2 = 1attributes. ----- Patch [2]: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs --- commit
5710d5f25b45906977e2522567c1964b1d3219f8
Author: Marcelo Schmitt <[email protected]>iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
This commit adds a new driver for the Analog Devices LTC2378-20 and similar analog-to-digital converters.
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +0
-0@@ -0,0 +1,416 @@[ ... ]
Quoted 12 lines
drivers/iio/adc/ltc2378.c line 36
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +6
-0+#define LTC2378_DIFF_CHANNEL (_sign, _real_bits, _storage_bits) \ +{ \ + .type = IIO_VOLTAGE, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \[Severity: Medium]
Does this macro need to set .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1? The name suggests these are differential channels, but without these attributes, the IIO ABI will expose them as single-ended (e.g.,in_voltage_rawinstead of in_voltage0-voltage1_raw).
For parts with multiple inputs and configurable differential channels (e.g. AD4130-8, MCP3561/2/4R, NAFE13388 [1, 2, 3]), the voltageY-voltageZ ABI helps clarifying what physical inputs make up a channel. For differential only parts, the ABI seems to be flexible by only requiring a 'consistent labeling' (either voltageY or voltageY-voltageZ IIUC). Will set the channel with the differential ABI if maintainers believe that's the best way to have it. Might slightly tweak the channel macros to keep .differential = 0 for pseudo-differential chips (e.g.LTC2369-18).
[1]: https://www.analog.com/media/en/technical-documentation/data-sheets/ad4130-8.pdf
[2]: https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP3561_2_4R-Data-Sheet-DS200006391C.pdf
[3]: https://www.nxp.com/docs/en/data-sheet/NAFE13388.pdf
Quoted 21 lines
Quoted 17 lines
drivers/iio/adc/ltc2378.c new file +16
-0+ .scan_type = { \ + .format = _sign ? IIO_SCAN_FORMAT_SIGNED_INT : \ + IIO_SCAN_FORMAT_UNSIGNED_INT, \ + .realbits = _real_bits, \ + .storagebits = _storage_bits, \ + .shift = _storage_bits - _real_bits, \ + .endianness = IIO_BE, \ + }, \ +} + +#define LTC2378_BIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(1, _real_bits, (((_real_bits) > 16) ? 32 : 16)) + +#define LTC2378_UNIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(0, _real_bits, (((_real_bits) > 16) ? 32 : 16)) +[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Quoted 34 lines · On Fri, 17 Jul 2026 13:38:07 -0300 Marcelo Schmitt…
Quoted 20 lines · On 07/16, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TheLTC2378_DIFF_CHANNELmacro defines an IIO channel that is intended to be differential but lacks the.differential = 1,.indexed = 1,.channel = 0, and.channel2 = 1attributes. ----- Patch [2]: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs --- commit
5710d5f25b45906977e2522567c1964b1d3219f8
Author: Marcelo Schmitt <[email protected]>iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
This commit adds a new driver for the Analog Devices LTC2378-20 and similar analog-to-digital converters.
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +0
-0@@ -0,0 +1,416 @@[ ... ]
Quoted 12 lines
drivers/iio/adc/ltc2378.c line 36
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +6
-0+#define LTC2378_DIFF_CHANNEL (_sign, _real_bits, _storage_bits) \ +{ \ + .type = IIO_VOLTAGE, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \[Severity: Medium]
Does this macro need to set .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1? The name suggests these are differential channels, but without these attributes, the IIO ABI will expose them as single-ended (e.g.,in_voltage_rawinstead of in_voltage0-voltage1_raw).
Quoted 8 lines
For parts with multiple inputs and configurable differential channels (e.g. AD4130-8, MCP3561/2/4R, NAFE13388 [1, 2, 3]), the voltageY-voltageZ ABI helps clarifying what physical inputs make up a channel. For differential only parts, the ABI seems to be flexible by only requiring a 'consistent labeling' (either voltageY or voltageY-voltageZ IIUC). Will set the channel with the differential ABI if maintainers believe that's the best way to have it. Might slightly tweak the channel macros to keep .differential = 0 for pseudo-differential chips (e.g.LTC2369-18).
Whilst I get your point on differential only cases not really requiring the specification of two inputs, I think that does provide a simple indication to users that they are differential channel.
I would prefer that we make them 'look' like differential channels so make up a suitable number for the negative side.
I vaguely recall we did once consider handling these as inX-inX but it seemed a little too weird. Hohum. ABI was designed against the max1363 and I didn't think much about device that always did differential. What can I say, I was young and foolish ;)
Jonathan
Quoted 27 lines
[1]: https://www.analog.com/media/en/technical-documentation/data-sheets/ad4130-8.pdf
[2]: https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/MCP3561_2_4R-Data-Sheet-DS200006391C.pdf
[3]: https://www.nxp.com/docs/en/data-sheet/NAFE13388.pdfQuoted 21 lines
Quoted 17 lines
drivers/iio/adc/ltc2378.c new file +16
-0+ .scan_type = { \ + .format = _sign ? IIO_SCAN_FORMAT_SIGNED_INT : \ + IIO_SCAN_FORMAT_UNSIGNED_INT, \ + .realbits = _real_bits, \ + .storagebits = _storage_bits, \ + .shift = _storage_bits - _real_bits, \ + .endianness = IIO_BE, \ + }, \ +} + +#define LTC2378_BIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(1, _real_bits, (((_real_bits) > 16) ? 32 : 16)) + +#define LTC2378_UNIPOLAR_DIFF_CHANNEL (_real_bits) \ + LTC2378_DIFF_CHANNEL(0, _real_bits, (((_real_bits) > 16) ? 32 : 16)) +[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
TL;DR: Will switch to voltageY-voltageZ ABI.
Quoted 46 lines · Jonathan Cameron
Quoted 34 lines · On Fri, 17 Jul 2026 13:38:07 -0300 Marcelo Schmitt…
Quoted 20 lines · On 07/16, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TheLTC2378_DIFF_CHANNELmacro defines an IIO channel that is intended to be differential but lacks the.differential = 1,.indexed = 1,.channel = 0, and.channel2 = 1attributes. ----- Patch [2]: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs --- commit
5710d5f25b45906977e2522567c1964b1d3219f8
Author: Marcelo Schmitt <[email protected]>iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
This commit adds a new driver for the Analog Devices LTC2378-20 and similar analog-to-digital converters.
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +0
-0@@ -0,0 +1,416 @@[ ... ]
Quoted 12 lines
drivers/iio/adc/ltc2378.c line 36
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +6
-0+#define LTC2378_DIFF_CHANNEL (_sign, _real_bits, _storage_bits) \ +{ \ + .type = IIO_VOLTAGE, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \[Severity: Medium]
Does this macro need to set .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1? The name suggests these are differential channels, but without these attributes, the IIO ABI will expose them as single-ended (e.g.,in_voltage_rawinstead of in_voltage0-voltage1_raw).Quoted 8 lines
For parts with multiple inputs and configurable differential channels (e.g. AD4130-8, MCP3561/2/4R, NAFE13388 [1, 2, 3]), the voltageY-voltageZ ABI helps clarifying what physical inputs make up a channel. For differential only parts, the ABI seems to be flexible by only requiring a 'consistent labeling' (either voltageY or voltageY-voltageZ IIUC). Will set the channel with the differential ABI if maintainers believe that's the best way to have it. Might slightly tweak the channel macros to keep .differential = 0 for pseudo-differential chips (e.g.LTC2369-18).
Quoted 3 lines
Whilst I get your point on differential only cases not really requiring the specification of two inputs, I think that does provide a simple indication to users that they are differential channel.
Agree. The first ADCs I've worked with were single-ended so having to provide the negative input when working with differential ones was something noticeable to me. Though, one applications engineer once called me out for the voltageY-voltageZ naming arguing that a differential channel provided only one input to his application and thus it should be labeled only 'voltageY' or even just 'voltage'. Despite understanding that argument, I share the opinion that an indication of differential channel is helpful. Anyways, besides the possibility for application to display channel names differently in user space, I see we now have .read_label so the whole discussion seems pointless.
Quoted 3 lines
I would prefer that we make them 'look' like differential channels so make up a suitable number for the negative side.
Would it make sense to adjust the ABI doc to encourage the dual numbering for differential channels? So I don't fall the temptation of single index in the future :)
Thanks,
Marcelo
Re: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
Quoted 63 lines · On Sat, 18 Jul 2026 15:48:29 -0300 Marcelo Schmitt…
TL;DR: Will switch to voltageY-voltageZ ABI.
Quoted 46 lines · Jonathan Cameron
Quoted 34 lines · On Fri, 17 Jul 2026 13:38:07 -0300 Marcelo Schmitt…
Quoted 20 lines · On 07/16, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] TheLTC2378_DIFF_CHANNELmacro defines an IIO channel that is intended to be differential but lacks the.differential = 1,.indexed = 1,.channel = 0, and.channel2 = 1attributes. ----- Patch [2]: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs --- commit
5710d5f25b45906977e2522567c1964b1d3219f8
Author: Marcelo Schmitt <[email protected]>iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
This commit adds a new driver for the Analog Devices LTC2378-20 and similar analog-to-digital converters.
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +0
-0@@ -0,0 +1,416 @@[ ... ]
Quoted 12 lines
drivers/iio/adc/ltc2378.c line 36
Quoted 6 lines
drivers/iio/adc/ltc2378.c new file +6
-0+#define LTC2378_DIFF_CHANNEL (_sign, _real_bits, _storage_bits) \ +{ \ + .type = IIO_VOLTAGE, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_index = 0, \[Severity: Medium]
Does this macro need to set .differential = 1, .indexed = 1, .channel = 0, and .channel2 = 1? The name suggests these are differential channels, but without these attributes, the IIO ABI will expose them as single-ended (e.g.,in_voltage_rawinstead of in_voltage0-voltage1_raw).Quoted 8 lines
For parts with multiple inputs and configurable differential channels (e.g. AD4130-8, MCP3561/2/4R, NAFE13388 [1, 2, 3]), the voltageY-voltageZ ABI helps clarifying what physical inputs make up a channel. For differential only parts, the ABI seems to be flexible by only requiring a 'consistent labeling' (either voltageY or voltageY-voltageZ IIUC). Will set the channel with the differential ABI if maintainers believe that's the best way to have it. Might slightly tweak the channel macros to keep .differential = 0 for pseudo-differential chips (e.g.LTC2369-18).
Quoted 3 lines
Whilst I get your point on differential only cases not really requiring the specification of two inputs, I think that does provide a simple indication to users that they are differential channel.
Agree. The first ADCs I've worked with were single-ended so having to provide the negative input when working with differential ones was something noticeable to me. Though, one applications engineer once called me out for the voltageY-voltageZ naming arguing that a differential channel provided only one input to his application and thus it should be labeled only 'voltageY' or even just 'voltage'. Despite understanding that argument, I share the opinion that an indication of differential channel is helpful. Anyways, besides the possibility for application to display channel names differently in user space, I see we now have .read_label so the whole discussion seems pointless.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
I would prefer that we make them 'look' like differential channels so make up a suitable number for the negative side.
Would it make sense to adjust the ABI doc to encourage the dual numbering for differential channels? So I don't fall the temptation of single index in the future :)
Yes. That would be good!
Thanks,
Jonathan
Quoted 4 lines
Thanks,
Marcelo
Re: [PATCH v7 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs
In reply to Marcelo SchmittQuoted 4 lines · On Thu, 16 Jul 2026 18:09:36 -0300 Marcelo Schmitt…
Support for LTC2378-20 and similar analog-to-digital converters.
Reviewed-by David Lechner <[email protected]>Signed-off-by Marcelo Schmitt <[email protected]>
One entirely trivial comment.
Jonathan
Quoted 9 lines
drivers/iio/adc/ltc2378.c new file +3
-0+static int ltc2378_refin_setup (struct device *dev,struct ltc2378_state *st) +{ +int ret;
drivers/iio/adc/ltc2378.c line 285
Quoted 10 lines
drivers/iio/adc/ltc2378.c new file +10
-0+ +/* +* The internal reference buffer amplifies both the internal reference +* and REFIN by a factor of 2. +*/ + ret =devm_regulator_get_enable_read_voltage (dev,"refin" ); +if (ret == -ENODEV ) {/* refin is optional */ + st->ref_uV = st->info->internal_ref_uV *2 ; +return 0 ; + }else if (ret <0 ) {
if (ret < 0)
Quoted 7 lines
drivers/iio/adc/ltc2378.c new file +7
-0+return dev_err_probe (dev, ret,"failed to read refin regulator\n" ); + } + + st->ref_uV = ret *2 ; + +return 0 ; +}
Marcelo Schmitt
maintainerPATCH v7 3/4 iio: adc: ltc2378: Enable high-speed data capture
In reply to Marcelo SchmittMake use of SPI transfer offloading to speed up data capture, enabling data acquisition at faster sample rates (up to 2 MSPS).
---
Change log v6 -> v7:
- Now keeping validated offload configurations if conversion rate update fails.
- Imported SPI_OFFLOAD name space.
- Replaced DIV_ROUND_UP() by div_u64() to mitigate config check fail due to different integer rounding.
- Separate macros for offload and non-offload channels.
- Moved ltc2378_prepare_offload_message() downwards in source code.
drivers/iio/adc/Kconfig | 6 + drivers/iio/adc/ltc2378.c | 403 +++++++++++++++++++++++++++++++++++++- 2 files changed, 406 insertions(+), 3 deletions(-)
drivers/iio/adc/Kconfig +6 -0
@@ -948,6 +948,12 @@ config LTC2378 depends on SPI depends on REGULATOR || COMPILE_TEST depends on GPIOLIB + depends on PWM + select IIO_BUFFER + select IIO_BUFFER_DMA + select IIO_BUFFER_DMAENGINE + select SPI_OFFLOAD + select SPI_OFFLOAD_TRIGGER_PWM help Say yes here to build support for Analog Devices LTC2378-20 and similar analog to digital converters.
drivers/iio/adc/ltc2378.c +400 -3
564 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Integer divide-by-zero leading to kernel panic in `ltc2378_update_conversion_rate` when a sampling…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Integer divide-by-zero leading to kernel panic in ltc2378_update_conversion_rate when a sampling frequency of 1 Hz is requested and the PWM driver rounds the period length above 1 second. --
--- Patch [3]: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture --- commit ef54f2c79f2cac1649922032814adc7fcc5f9684
Author: Marcelo Schmitt <[email protected]>
Subject: iio: adc: ltc2378: Enable high-speed data capture
This commit enables high-speed data capture for the ltc2378 ADC driver by utilizing SPI transfer offloading. It allows data acquisition at faster sample rates up to 2 MSPS.
Quoted 4 lines
drivers/iio/adc/ltc2378.c +0
-0
[ ... ]
Quoted 17 lines
drivers/iio/adc/ltc2378.c +17
-0+/* +* Configure SPI offload PWM trigger. +* The trigger should fire after tBUSYLH + tCONV + tDSDOBUSYL. +* Minimum time needed: TBUSYLH (13ns) + TCONV (part-specific) + TDSDOBUSYL (5ns) +* +* Use the same period as CNV PWM to avoid timing issues. +* Convert back from period to frequency for the SPI offload API. +*/ + offload_period_ns = cnv_wf.period_length_ns; + config.periodic.frequency_hz =div_u64 (HZ_PER_GHZ , offload_period_ns); + min_read_offset =LTC2378_TBUSYLH_NS + st->info->tconv_ns +LTC2378_TDSDOBUSYL_NS ; + offload_offset_ns = min_read_offset; + count =100 ; + do { + config.periodic.offset_ns = offload_offset_ns; + ret = spi_offload_trigger_validate(st->offload_trigger, &config); + if (ret)
drivers/iio/adc/ltc2378.c static int ltc2378_read_raw(struct iio_dev *indio_dev, · line 486
Quoted 10 lines
drivers/iio/adc/ltc2378.c +10
-0+return ret; + offload_offset_ns +=10 ; + }while (count-- && config.periodic.offset_ns < min_read_offset); + +/* Check the minimum CNV to SCLK delay is met */ +if (config.periodic.offset_ns < min_read_offset) +return -EDOM ; + +/* Check the PWM periods remain the same */ + offload_period_ns =div64_u64 (HZ_PER_GHZ , config.periodic.frequency_hz);
[Severity: High]
Could this result in a kernel panic due to an integer division by zero?
If a user writes 1 to the IIO in_voltage_sampling_frequency sysfs attribute, ltc2378_update_conversion_rate() is called with freq_Hz = 1, and the initial requested PWM period is calculated as 1,000,000,000 ns.
If the underlying hardware PWM driver rounds the period slightly upwards (e.g., to 1,000,000,001 ns) during pwm_round_waveform_might_sleep() due to clock granularity, offload_period_ns will exceed HZ_PER_GHZ.
This causes config.periodic.frequency_hz = div_u64(HZ_PER_GHZ, offload_period_ns) to evaluate to 0.
When div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz) is subsequently called, it divides by zero.
Quoted 9 lines
drivers/iio/adc/ltc2378.c +9
-0+if (cnv_wf.period_length_ns != offload_period_ns) +return -EDOM ; + + st->offload_trigger_config = config; + st->cnv_wf = cnv_wf; + st->cnv_Hz =DIV_ROUND_CLOSEST_ULL (HZ_PER_GHZ , cnv_wf.period_length_ns); + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture
Quoted 59 lines · On 07/16, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Integer divide-by-zero leading to kernel panic inltc2378_update_conversion_ratewhen a sampling frequency of 1 Hz is requested and the PWM driver rounds the period length above 1 second. ----- Patch [3]: [PATCH v7 3/4] iio: adc: ltc2378: Enable high-speed data capture --- commit
ef54f2c79f2cac1649922032814adc7fcc5f9684
Author: Marcelo Schmitt <[email protected]>
Subject: iio: adc: ltc2378: Enable high-speed data captureThis commit enables high-speed data capture for the ltc2378 ADC driver by utilizing SPI transfer offloading. It allows data acquisition at faster sample rates up to 2 MSPS.
Quoted 4 lines
drivers/iio/adc/ltc2378.c +0
-0[ ... ]
Quoted 17 lines
drivers/iio/adc/ltc2378.c +17
-0+/* +* Configure SPI offload PWM trigger. +* The trigger should fire after tBUSYLH + tCONV + tDSDOBUSYL. +* Minimum time needed: TBUSYLH (13ns) + TCONV (part-specific) + TDSDOBUSYL (5ns) +* +* Use the same period as CNV PWM to avoid timing issues. +* Convert back from period to frequency for the SPI offload API. +*/ + offload_period_ns = cnv_wf.period_length_ns; + config.periodic.frequency_hz =div_u64 (HZ_PER_GHZ , offload_period_ns); + min_read_offset =LTC2378_TBUSYLH_NS + st->info->tconv_ns +LTC2378_TDSDOBUSYL_NS ; + offload_offset_ns = min_read_offset; + count =100 ; + do { + config.periodic.offset_ns = offload_offset_ns; + ret = spi_offload_trigger_validate(st->offload_trigger, &config); + if (ret)drivers/iio/adc/ltc2378.c static int ltc2378_read_raw(struct iio_dev *indio_dev, · line 486
Quoted 10 lines
drivers/iio/adc/ltc2378.c +10
-0+return ret; + offload_offset_ns +=10 ; + }while (count-- && config.periodic.offset_ns < min_read_offset); + +/* Check the minimum CNV to SCLK delay is met */ +if (config.periodic.offset_ns < min_read_offset) +return -EDOM ; + +/* Check the PWM periods remain the same */ + offload_period_ns =div64_u64 (HZ_PER_GHZ , config.periodic.frequency_hz);[Severity: High]
Could this result in a kernel panic due to an integer division by zero?If a user writes 1 to the IIO
in_voltage_sampling_frequencysysfs attribute,ltc2378_update_conversion_rate()is called withfreq_Hz= 1, and the initial requested PWM period is calculated as 1,000,000,000 ns.If the underlying hardware PWM driver rounds the period slightly upwards (e.g., to 1,000,000,001 ns) during
pwm_round_waveform_might_sleep()due to clock granularity,offload_period_nswill exceedHZ_PER_GHZ.
Quoted 5 lines
This causes config.periodic.frequency_hz =
div_u64(HZ_PER_GHZ, offload_period_ns)to evaluate to 0.When
div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz)is subsequently called, it divides by zero.
If we have cnv_wf.period_length_ns == NSEC_PER_SEC + 1 after the offset_ns loop and config.periodic.frequency_hz == 0 as suggested, then spi_offload_trigger_validate() will fail the frequency_hz check and ltc2378_update_conversion_rate() errors out with -EINVAL before reaching div64_u64(HZ_PER_GHZ, config.periodic.frequency_hz).
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-offload-trigger-pwm.c?h=v7.2-rc3#n48
Quoted 13 lines
Quoted 10 lines
drivers/iio/adc/ltc2378.c +9
-0+if (cnv_wf.period_length_ns != offload_period_ns) +return -EDOM ; + + st->offload_trigger_config = config; + st->cnv_wf = cnv_wf; + st->cnv_Hz =DIV_ROUND_CLOSEST_ULL (HZ_PER_GHZ , cnv_wf.period_length_ns); + +return 0 ; +}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Marcelo Schmitt
maintainerPATCH v7 4/4 iio: adc: ltc2378: Enable triggered buffer data capture
In reply to Marcelo SchmittEnable users to run triggered data captures with LTC2378 and similar ADCs.
---
Change log v6 -> v7:
No changes in v7.
drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/ltc2378.c | 75 +++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 23 deletions(-)
drivers/iio/adc/Kconfig +1 -0
@@ -952,6 +952,7 @@ config LTC2378 select IIO_BUFFER select IIO_BUFFER_DMA select IIO_BUFFER_DMAENGINE + select IIO_TRIGGERED_BUFFER select SPI_OFFLOAD select SPI_OFFLOAD_TRIGGER_PWM help
drivers/iio/adc/ltc2378.c +52 -23
225 lines not on this page · raw message
Signature · 1 line
2.53.0
Quoted 13 lines · Marcelo Schmitt
This patch series adds support for LTC2378 and similar low noise, low power, high speed, successive approximation register (SAR) ADCs. These ADCs are similar among each other, varying mainly on the amount of precision bits, maximum sample rate, and input configuration (either fully differential or pseudo-differential).
Patch 1 adds device tree documentation for LTC2378.
Patch 2 enables single-shot sample read with a GPIO connected to the LTC2378 CNV pin.
Patch 3 enables high-speed data captures with SPI offloading.
The setup is similar to AD4030, with a specialized PWM generator being used both for SPI offload triggering and conversion start signaling.
Quoted 6 lines
Patch 4 enables running buffered data captures without SPI offloading.
Even though these parts are somewhat similar to AD4000, the wiring configuration for LTC parts is different as well as the available HDL for high speed sample rate mode. Because of that, I propose creating a new device driver for supporting LTC2378-like devices.
for patches 2-4.
Signature · 2 lines
With Best Regards, Andy Shevchenko