[PATCH v8 0/2] iio: Add support for TI ADS1X18 ADCs

Kurt Borja posted 2 patches 1 day, 21 hours ago
.../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                       | 746 +++++++++++++++++++++
5 files changed, 848 insertions(+)
[PATCH v8 0/2] iio: Add support for TI ADS1X18 ADCs
Posted by Kurt Borja 1 day, 21 hours ago
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.

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
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/20251121-ads1x18-v1-0-86db080fc9a4@gmail.com

---
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/20251127-ads1x18-v2-0-2ebfd780b633@gmail.com

---
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/20251128-ads1x18-v3-0-a6ebab815b2d@gmail.com

---
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/20251202-ads1x18-v4-0-8c3580bc273f@gmail.com

---
v6:
  - [Patch 2]:
    - Actually make the changes described above. Sorry for the noise :(.

  - Link to v5: https://lore.kernel.org/r/20251204-ads1x18-v5-0-b6243de766d1@gmail.com

---
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/20251204-ads1x18-v6-0-2ae4a2f8e90c@gmail.com

---
v8:
  - [Patch 2]:
    - Fix commit message (These -> This)
    - Multiply temp scale by 1000 to comply with ABI, which specifies
      final temp calculation is in millidegrees celsius
    - Drop ADS1018_FSR_TO_SCALE() because ABI specifies the final
      voltage calculation in millivolts, and the macro would overflow
      32-bit values while calculating, even after shifting 3 more times
      :(
    - Add comment about gain calculation in struct iio_chip_info
    - Manually list voltage gain in iio_chip_info
    - Use HZ_PER_MHZ instead of MICROHZ_PER_HZ in ads1018_calc_delay()

  - Link to v7: https://lore.kernel.org/r/20251208-ads1x18-v7-0-b1be8dfebfa2@gmail.com

---
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                       | 746 +++++++++++++++++++++
 5 files changed, 848 insertions(+)
---
base-commit: daea3a394a8b425a2dd206ab09eb37f0d1087d35
change-id: 20251012-ads1x18-0d0779d06690

-- 
 ~ Kurt
Re: [PATCH v8 0/2] iio: Add support for TI ADS1X18 ADCs
Posted by Tomas Melin 1 day, 16 hours ago
Hi,

Sorry for coming in late in the cycle, can you please explain why the
driver for ADS1015 could not be extended to support also ADS1x18
devices? Briefly looking into the topic, they seem to be very closely
related.

Have You looked into that alternative?

Thanks,
Tomas



On 12/12/2025 06:25, Kurt Borja wrote:
> 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.
> 
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
> ---
> 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/20251121-ads1x18-v1-0-86db080fc9a4@gmail.com
> 
> ---
> 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/20251127-ads1x18-v2-0-2ebfd780b633@gmail.com
> 
> ---
> 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/20251128-ads1x18-v3-0-a6ebab815b2d@gmail.com
> 
> ---
> 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/20251202-ads1x18-v4-0-8c3580bc273f@gmail.com
> 
> ---
> v6:
>   - [Patch 2]:
>     - Actually make the changes described above. Sorry for the noise :(.
> 
>   - Link to v5: https://lore.kernel.org/r/20251204-ads1x18-v5-0-b6243de766d1@gmail.com
> 
> ---
> 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/20251204-ads1x18-v6-0-2ae4a2f8e90c@gmail.com
> 
> ---
> v8:
>   - [Patch 2]:
>     - Fix commit message (These -> This)
>     - Multiply temp scale by 1000 to comply with ABI, which specifies
>       final temp calculation is in millidegrees celsius
>     - Drop ADS1018_FSR_TO_SCALE() because ABI specifies the final
>       voltage calculation in millivolts, and the macro would overflow
>       32-bit values while calculating, even after shifting 3 more times
>       :(
>     - Add comment about gain calculation in struct iio_chip_info
>     - Manually list voltage gain in iio_chip_info
>     - Use HZ_PER_MHZ instead of MICROHZ_PER_HZ in ads1018_calc_delay()
> 
>   - Link to v7: https://lore.kernel.org/r/20251208-ads1x18-v7-0-b1be8dfebfa2@gmail.com
> 
> ---
> 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                       | 746 +++++++++++++++++++++
>  5 files changed, 848 insertions(+)
> ---
> base-commit: daea3a394a8b425a2dd206ab09eb37f0d1087d35
> change-id: 20251012-ads1x18-0d0779d06690
>
Re: [PATCH v8 0/2] iio: Add support for TI ADS1X18 ADCs
Posted by Kurt Borja 1 day, 12 hours ago
On Fri Dec 12, 2025 at 3:40 AM -05, Tomas Melin wrote:
> Hi,
>
> Sorry for coming in late in the cycle, can you please explain why the
> driver for ADS1015 could not be extended to support also ADS1x18
> devices? Briefly looking into the topic, they seem to be very closely
> related.
>
> Have You looked into that alternative?

Yes, this was discussed in v1.

Although they are related, these two devices do not use the same
protocol and regmap is not a good fit for ADS1X18. We need two different
SPI message structure for driving the two operating modes (direct,
buffer) and the trigger needs some special considerations because
ads1x18 share their drdy interrupt line with the MOSI pin.

We concluded merging the two drivers would be too messy as both
protocols would need a lot of unique code. Not to mention different
triggers, buffers, custom callbacks, etc.

>
> Thanks,
> Tomas

-- 
 ~ Kurt
Re: [PATCH v8 0/2] iio: Add support for TI ADS1X18 ADCs
Posted by Tomas Melin 1 day, 11 hours ago

On 12/12/2025 15:10, Kurt Borja wrote:
> On Fri Dec 12, 2025 at 3:40 AM -05, Tomas Melin wrote:
>> Hi,
>>
>> Sorry for coming in late in the cycle, can you please explain why the
>> driver for ADS1015 could not be extended to support also ADS1x18
>> devices? Briefly looking into the topic, they seem to be very closely
>> related.
>>
>> Have You looked into that alternative?
> 
> Yes, this was discussed in v1.
> 
> Although they are related, these two devices do not use the same
> protocol and regmap is not a good fit for ADS1X18. We need two different
> SPI message structure for driving the two operating modes (direct,
> buffer) and the trigger needs some special considerations because
> ads1x18 share their drdy interrupt line with the MOSI pin.
> 
> We concluded merging the two drivers would be too messy as both
> protocols would need a lot of unique code. Not to mention different
> triggers, buffers, custom callbacks, etc.

This information would be really valuable to put into the cover letter.

Thanks,
Tomas


> 
>>
>> Thanks,
>> Tomas
>