iio: Add support for TI ADS1X18 ADCs
Subsystems (3)
Kurt Borja
maintainerv7 cover iio: Add support for TI ADS1X18 ADCs
Hi,
This series adds a new driver for TI ADS1X18 SPI devices.
This is my first time contributing to the IIO subsystem and making dt-bindings documentation, so (don't) go easy on me :p.
As explained in Patch 2 changelog, the DRDY interrupt line is shared with the MOSI pin. This awkward quirk is also found on some Analog Devices sigma-delta SPI ADCs, so the interrupt and trigger design is inspired by those.
Thank you in advance for your reviews.
---
v2:
- [Patch 1]:
- Move MAINTAINERS change here
- Use generic node names: ads1118@0 -> adc@0
- Rename file to ti,ads1118.yaml -> ti,ads1018.yaml
- Drop ti,gain and ti,datarate
- Add spi-cpha and spi-max-frecuency properties as they are fixed in all models
- Add vdd-supply
- Make interrupts and drdy-gpios optional properties
- [Patch 2]:
- Update probe based on dt-bindings changes
- Rename file to ti-ads1x18.c -> ti-ads1018.c
- Rework ads1018_oneshot(), instead of waiting for IRQ wait an appropriate delay before reading again
- Only alloc and register a trigger if we have an IRQ line
- Drop ads1x18->msg_lock in favor of IIO API locks
- Read conver before enabling and after disabling IRQ to ensure CS state is correct
- Add ads1018_read_locked() which takes an additional argument hold_cs to explicitly control CS state in trigger and buffer
- Fix ADS1X18_CHANNELS_MAX limit 9 -> 10
- Call iio_trigger_notify_done() in all IRQ handler paths
- Drop unused includes
- Drop BIT_U16 and GENMASK_U16 macros
- Drop unnecessary named defines
- Use u8 types in ads1018_chan_data
- Rename some struct members for clarity
- Move tx_buf and rx_buf to the end of struct ads1018
- Rework channel handling to just make everything visible and add ADS1018_VOLT_DIFF_CHAN
- Use .scan_index instead of .address in IIO channels
- v1: https://lore.kernel.org/r/[email protected]
---
v3:
- [Patch 1]:
- Use unevaluatedProperties: false
- Drop #address-cells and #size-cells
- [Patch 2]:
- Add kernel-doc to internal API
- Drop bits.h and bitops.h includes
- Add types.h include
- Use unsigned type for data_rate_mode_to_hz
- Rename __ads1018_read_raw() -> ads1018_read_raw_unlocked()
- Rename __ads1018_write_raw() -> ads1018_write_raw_unlocked()
- Rename ads1018_read_locked -> ads1018_read_unlocked() for consistency
- Let ads1018_read_unlocked() take NULL cnv pointers
- Add ads1018_set_trigger_{enable,disable}()
- Refactor ads1018_write_raw_unlocked() loop matching
- Invert ads1018_trigger_handler() logic to follow traditional error handling pattern
- Refactor ads1018_trigger_setup() cleaner
- Make ADS1018_FSR_TO_SCALE() calculation be 32-bit compatible
- Some additionall minor cleanups
- Link to v2: https://lore.kernel.org/r/[email protected]
---
v4:
- [Patch 2]:
- Replaced <linux/byteorder/generic.h> -> <asm/byteorder.h>
- Dropped ADS1018_CFG_DEFAULT
- Fixed long lines
- Added Andy's remark on ADS1018_FSR_TO_SCALE() kernel-doc description.
- Fixed wrong argument on iio_trigger_notify_done():
ads1018->indio_trig -> indio_dev->trig
- Renamed argument in channel macros _addr -> _index
- Changed return type of ads1018_calc_delay() to u32
- Mention @cnv is optional in ads1018_read_unlocked()
- Use 16-bit transmission cycle in ads1018_oneshot()
- Dropped spi_set_drvdata()
- Use full resolution in ADS1018_FSR_TO_SCALE() and subtract 1 inside macro
- Rename ads1018_read_locked() -> ads1018_spi_read_exclusive() for clarity
- Minor style changes
- Link to v3: https://lore.kernel.org/r/[email protected]
---
v5:
- [Patch 2]:
- Fix ADS1018_FSR_TO_SCALE() long description
- In ADS1018_FSR_TO_SCALE() subtract 6 from BIT() argument instead of shifting the value
- Link to v4: https://lore.kernel.org/r/[email protected]
---
v6:
- [Patch 2]:
- Actually make the changes described above. Sorry for the noise :(.
- Link to v5: https://lore.kernel.org/r/[email protected]
---
Changes in v7:
- [Patch 1]:
- Reword description slightly
- [Patch 2]:
- In struct ads1018_chip_info, make pga_mode_to_gain an array
- Drop ads1018_{get,set}_{data_rate,pga}_mode() helpers
- Drop context remark in ads1018_calc_delay
- Prepare device configuration in ads1018_single_shot()
- Let ads1018_calc_delay() take sampling frequency as an argument
- Drop *_unlocked() methods in favor of *_direct_mode()
- Link to v6: https://lore.kernel.org/r/[email protected]
---
Kurt Borja (2):
dt-bindings: iio: adc: Add TI ADS1018/ADS1118
iio: adc: Add ti-ads1018 driver
.../devicetree/bindings/iio/adc/ti,ads1018.yaml | 82 +++ MAINTAINERS | 7 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ti-ads1018.c | 743 +++++++++++++++++++++ 5 files changed, 845 insertions(+)
---
base-commit: f9e05791642810a0cf6237d39fafd6fec5e0b4bb
change-id: 20251012-ads1x18-0d0779d06690
Signature · 1 line
~ Kurt
Kurt Borja
maintainerPATCH v7 1/2 dt-bindings: iio: adc: Add TI ADS1018/ADS1118
Add documentation for Texas Instruments ADS1018 and ADS1118 analog-to-digital converters.
--- .../devicetree/bindings/iio/adc/ti,ads1018.yaml | 82 ++++++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 88 insertions(+)
Documentation/devicetree/bindings/iio/adc/ti,ads1018.yaml new file +82 -0
@@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/adc/ti,ads1018.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI ADS1018/ADS1118 SPI analog to digital converter + +maintainers: + - Kurt Borja <[email protected]> + +description: | + The ADS1018/ADS1118 is a precision, low-power, 12-bit/16-bit, analog to + digital converter (ADC). It integrates a programmable gain amplifier (PGA), + internal voltage reference, oscillator and high-accuracy temperature sensor. + + Datasheets: + - ADS1018: https://www.ti.com/lit/ds/symlink/ads1018.pdf + - ADS1118: https://www.ti.com/lit/ds/symlink/ads1118.pdf + +properties: + compatible: + enum: + - ti,ads1018 + - ti,ads1118 + + reg: + maxItems: 1 + + vdd-supply: true + + spi-max-frequency: + maximum: 4000000 + + spi-cpha: true + + interrupts: + description: DOUT/DRDY (Data Out/Data Ready) line. + maxItems: 1 + + drdy-gpios: + description: + Extra GPIO line connected to DOUT/DRDY (Data Out/Data Ready). This allows + distinguishing between interrupts triggered by the data-ready signal and + interrupts triggered by an SPI transfer. + maxItems: 1 + + '#io-channel-cells': + const: 1 + +required: + - compatible + - reg + - vdd-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + + spi { + #address-cells = <1>; + #size-cells = <0>; + + adc@0 { + compatible = "ti,ads1118"; + reg = <0>; + + spi-max-frequency = <4000000>; + spi-cpha; + + vdd-supply = <&vdd_3v3_reg>; + + interrupts-extended = <&gpio 14 IRQ_TYPE_EDGE_FALLING>; + drdy-gpios = <&gpio 14 GPIO_ACTIVE_LOW>; + }; + };
MAINTAINERS +6 -0
@@ -25646,6 +25646,12 @@ S: Maintained F: Documentation/devicetree/bindings/iio/adc/ti,ads1119.yaml F: drivers/iio/adc/ti-ads1119.c +TI ADS1018 ADC DRIVER +M: Kurt Borja <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/ti,ads1018.yaml + TI ADS7924 ADC DRIVER M: Hugo Villeneuve <[email protected]> L: [email protected]
Signature · 1 line
2.52.0
Kurt Borja
maintainerPATCH v7 2/2 iio: adc: Add ti-ads1018 driver
In reply to Kurt BorjaAdd ti-ads1018 driver for Texas Instruments ADS1018 and ADS1118 SPI analog-to-digital converters.
These chips' MOSI pin is shared with a data-ready interrupt. Defining this interrupt in devicetree is optional, therefore we only create an IIO trigger if one is found.
Handling this interrupt requires some considerations. When enabling the trigger the CS line is tied low (active), thus we need to hold spi_bus_lock() too, to avoid state corruption. This is done inside the set_trigger_state() callback, to let users use other triggers without wasting a bus lock.
--- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ti-ads1018.c | 743 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 757 insertions(+)
MAINTAINERS +1 -0
@@ -25651,6 +25651,7 @@ M: Kurt Borja <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/iio/adc/ti,ads1018.yaml +F: drivers/iio/adc/ti-ads1018.c TI ADS7924 ADC DRIVER M: Hugo Villeneuve <[email protected]>
drivers/iio/adc/Kconfig +12 -0
@@ -1664,6 +1664,18 @@ config TI_ADS1015 This driver can also be built as a module. If so, the module will be called ti-ads1015. +config TI_ADS1018 + tristate "Texas Instruments ADS1018 ADC" + depends on SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + If you say yes here you get support for Texas Instruments ADS1018 and + ADS1118 ADC chips. + + This driver can also be built as a module. If so, the module will be + called ti-ads1018. + config TI_ADS1100 tristate "Texas Instruments ADS1100 and ADS1000 ADC" depends on I2C
drivers/iio/adc/Makefile +1 -0
@@ -145,6 +145,7 @@ obj-$(CONFIG_TI_ADC12138) += ti-adc12138.o obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o +obj-$(CONFIG_TI_ADS1018) += ti-ads1018.o obj-$(CONFIG_TI_ADS1100) += ti-ads1100.o obj-$(CONFIG_TI_ADS1119) += ti-ads1119.o obj-$(CONFIG_TI_ADS124S08) += ti-ads124s08.o
drivers/iio/adc/ti-ads1018.c new file +743 -0
743 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v7 2/2] iio: adc: Add ti-ads1018 driver
Quoted 5 lines · Kurt Borja
Add ti-ads1018 driver for Texas Instruments ADS1018 and ADS1118 SPI analog-to-digital converters.
These chips' MOSI pin is shared with a data-ready interrupt. Defining
Either "This", or "pins are".
Quoted 8 lines
this interrupt in devicetree is optional, therefore we only create an IIO trigger if one is found.
Handling this interrupt requires some considerations. When enabling the trigger the CS line is tied low (active), thus we need to hold
spi_bus_lock()too, to avoid state corruption. This is done inside theset_trigger_state()callback, to let users use other triggers without wasting a bus lock.
...
Quoted 9 lines
drivers/iio/adc/ti-ads1018.c new file +9
-0+/** +* ads1018_calc_delay - Calculates a suitable delay for a single-shot reading +* @hz: Sampling frequency +* +* Calculates an appropriate delay for a single shot reading given a sampling +* frequency. +* +* Return: Delay in microseconds (Always greater than 0). +*/
drivers/iio/adc/ti-ads1018.c line 184
Quoted 10 lines
drivers/iio/adc/ti-ads1018.c new file +10
-0+static u32 ads1018_calc_delay (unsigned int hz) +{ +/* +* Calculate the worst-case sampling rate by subtracting 10% error +* specified in the datasheet... +*/ + hz -=DIV_ROUND_UP (hz,10 ); + +/* ...Then calculate time per sample in microseconds. */ +return DIV_ROUND_UP (MICROHZ_PER_HZ , hz);
If time per sample is in µs, the associated frequency is in MHz, so the correct constant is HZ_PER_MHZ. What did I miss here?
Quoted 1 line
+}
...
drivers/iio/adc/ti-ads1018.c line 738
Quoted 10 lines
drivers/iio/adc/ti-ads1018.c new file +9
-0+static struct spi_driver ads1018_spi_driver = { + .driver = { + .name ="ads1018" , + .of_match_table = ads1018_of_match, + }, + .probe = ads1018_spi_probe, + .id_table = ads1018_spi_match, +}; +
Unneeded blank line.
Quoted 1 line
+module_spi_driver(ads1018_spi_driver);
...
Other than above, LGTM!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kurt Borja
maintainerRe: [PATCH v7 2/2] iio: adc: Add ti-ads1018 driver
On Mon Dec 8, 2025 at 3:19 PM -05, Andy Shevchenko wrote:
...
Quoted 14 lines
Quoted 14 lines
drivers/iio/adc/ti-ads1018.c new file +14
-0+/** +* ads1018_calc_delay - Calculates a suitable delay for a single-shot reading +* @hz: Sampling frequency +* +* Calculates an appropriate delay for a single shot reading given a sampling +* frequency. +* +* Return: Delay in microseconds (Always greater than 0). +*/ +static u32 ads1018_calc_delay (unsigned int hz) +{ +/* +* Calculate the worst-case sampling rate by subtracting 10% error +* specified in the datasheet...
Quoted 8 lines
drivers/iio/adc/ti-ads1018.c line 184
Quoted 5 lines
drivers/iio/adc/ti-ads1018.c new file +5
-0+*/ + hz -=DIV_ROUND_UP (hz,10 ); + +/* ...Then calculate time per sample in microseconds. */ +return DIV_ROUND_UP (MICROHZ_PER_HZ , hz);If time per sample is in µs, the associated frequency is in MHz, so the correct constant is
HZ_PER_MHZ. What did I miss here?
I was very confused about this, but the dimensional analysis works with HZ_PER_MHZ so it should be the right constant. Thanks!
...
Quoted 2 lines
Other than above, LGTM!
Reviewed-by Andy Shevchenko <[email protected]>
Thanks a lot for all your feedback!
I also found that the sysfs ABI specifies millivolt for voltage final calculation and millidegree for temps. I will adjust scales to comply with this in the next version.
Do you have a suggestion for this? I can keep the ADS1018_FSR_TO_SCALE() macro but it will get a bit more complex or I can just hard code the scales and document the calculation. I'm inclined to do the latter.
Signature · 1 line
~ Kurt
Re: [PATCH v7 2/2] iio: adc: Add ti-ads1018 driver
Quoted 1 line · Kurt Borja
On Mon Dec 8, 2025 at 3:19 PM -05, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 5 lines
drivers/iio/adc/ti-ads1018.c line 184
Quoted 2 lines
drivers/iio/adc/ti-ads1018.c new file +2
-0+/* ...Then calculate time per sample in microseconds. */ +return DIV_ROUND_UP (MICROHZ_PER_HZ , hz);If time per sample is in µs, the associated frequency is in MHz, so the correct constant is
HZ_PER_MHZ. What did I miss here?I was very confused about this, but the dimensional analysis works with
HZ_PER_MHZso it should be the right constant. Thanks!
You need to keep in mind the sign of the order of magnitude. Since we don't use floats in the kernel, the small units are represented as divisors in opposite to multipliers. So, the used one is 10⁻⁶, while the proposed one is 10⁶.
...
Quoted 3 lines
Do you have a suggestion for this? I can keep the
ADS1018_FSR_TO_SCALE()macro but it will get a bit more complex or I can just hard code the scales and document the calculation. I'm inclined to do the latter.
I believe we will see based on your next version. Just avoid hard coding magic numbers, and put more comments, ideally with the references to a datasheet section.
Signature · 2 lines
With Best Regards, Andy Shevchenko