Skip to content

AD5313R device and triggered buffer support#3232

Open
rodrigo455 wants to merge 15 commits intomirror_ci/jic23/iio/testingfrom
staging/ad5313r-jic23-testing
Open

AD5313R device and triggered buffer support#3232
rodrigo455 wants to merge 15 commits intomirror_ci/jic23/iio/testingfrom
staging/ad5313r-jic23-testing

Conversation

@rodrigo455
Copy link
Copy Markdown
Collaborator

@rodrigo455 rodrigo455 commented Apr 1, 2026

PR Description

This series adds support for the AD5313R 10-bit nanoDAC and triggered
buffer support to the ad5686 DAC driver family, along with a number of
driver cleanups.

Initial patches update the device-tree bindings:

  • Add AD5313R compatible entry (SPI variant)
  • Add missing AD5673R/AD5677R entries (I2C variant)
  • Add LDAC GPIO property for async DAC channel loading

Driver cleanups:

  • Refactor include headers (IWYU)
  • Switch to devm_mutex_init()
  • Drop enum chip id in favor of per-device chip_info structs
    exposed to the SPI/I2C bus drivers
  • Introduce bus ops struct with a sync() operation for batching
    bus transfers

New functionality:

  • AD5313R device support
  • LDAC GPIO handling (active-low, held low when unused)
  • SPI bus sync() implementation for batching multiple transfers
  • Triggered buffer support, leveraging LDAC and sync() to flush
    all channel writes atomically

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

This series adds support for the AD5313R 10-bit nanoDAC and triggered
buffer support to the ad5686 DAC driver family, along with a number of
driver cleanups.

Initial patches update the device-tree bindings:
- Add AD5313R compatible entry (SPI variant)
- Add missing AD5673R/AD5677R entries (I2C variant)
- Add LDAC GPIO property for async DAC channel loading

Driver cleanups:
- Refactor include headers (IWYU)
- Switch to devm_mutex_init()
- Drop enum chip id in favor of per-device chip_info structs
  exposed to the SPI/I2C bus drivers
- Introduce bus ops struct with a sync() operation for batching
  bus transfers

New functionality:
- AD5313R device support
- LDAC GPIO handling (active-low, held low when unused)
- SPI bus sync() implementation for batching multiple transfers
- Triggered buffer support, leveraging LDAC and sync() to flush
  all channel writes atomically

# Describe the purpose of this series. The information you put here
# will be used by the project maintainer to make a decision whether
# your patches should be reviewed, and in what priority order. Please be
# very detailed and link to any relevant discussions or sites that the
# maintainer can review to better understand your proposed changes. If you
# only have a single patch in your series, the contents of the cover
# letter will be appended to the "under-the-cut" portion of the patch.

# Lines starting with # will be removed from the cover letter. You can
# use them to add notes or reminders to yourself. If you want to use
# markdown headers in your cover letter, start the line with ">#".

# You can add trailers to the cover letter. Any email addresses found in
# these trailers will be added to the addresses specified/generated
# during the b4 send stage. You can also run "b4 prep --auto-to-cc" to
# auto-populate the To: and Cc: trailers based on the code being
# modified.

To: Michael Hennerich <michael.hennerich@analog.com>
To: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
To: devicetree@vger.kernel.org
To: linux-kernel@vger.kernel.org
To: Michael Auchter <michael.auchter@ni.com>
To: linux-hardening@vger.kernel.org
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Michael Hennerich <Michael.Hennerich@analog.com>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Nuno Sá <nuno.sa@analog.com>
Cc: Andy Shevchenko <andy@kernel.org>
Cc: Rob Herring <robh@kernel.org>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>

--- b4-submit-tracking ---
# This section is used internally by b4 prep for tracking purposes.
{
  "series": {
    "revision": 1,
    "change-id": "20260325-ad5313r-iio-support-882ad39356e1",
    "prefixes": []
  }
}
@rodrigo455 rodrigo455 changed the title Staging/ad5313r jic23 testing AD5313R device and triggered buffer support Apr 1, 2026
@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch from 5da2875 to 71cdaf3 Compare April 1, 2026 23:59
@rodrigo455 rodrigo455 force-pushed the staging/ad5313r-jic23-testing branch from 9e516c8 to 9f44ff1 Compare April 2, 2026 07:22
Copy link
Copy Markdown
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good! Some things more relevant to change but I would say it's mostly upstream ready.

Thanks for taking care of this and bringing one more driver up to date!

Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5696.yaml
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5696.yaml Outdated
Comment thread drivers/iio/dac/ad5686-spi.c
Comment thread drivers/iio/dac/ad5686-spi.c

ret = spi_sync(spi, &bus_data->msg);
if (ret)
return ret;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line

I also wonder if this does not need locking?

Comment thread drivers/iio/dac/ad5686-spi.c Outdated
Comment thread drivers/iio/dac/ad5686.c Outdated
Comment thread drivers/iio/dac/ad5686.c
Comment thread drivers/iio/dac/ad5686.c Outdated
@nunojsa nunojsa mentioned this pull request Apr 2, 2026
8 tasks
Support for AD5673R and AD5677R missing from the device-tree bindings
documentation. The devices have different bit resolutions so no fallback
compatibles are used.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add compatible entry for AD5313R 10-bit nanoDAC. The device has unique
combination of channel count, bit resolution and supported command set,
so that fallback compatibles are not used.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add GPIO property for LDAC pin, used for async loading of DAC channel
data.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add GPIO property for LDAC pin, used for async loading of DAC channel
data.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Apply IWYU principle, replacing unused/generic headers for
specific/missing headers. The resulting include directive list is sorted
accordingly.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Adopt proper mutex lifecycle with devm_mutex_init(), replacing
mutex_init().

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Split chip info table into separate structs and expose them to the spi
i2c drivers. That is the preferrable approach and allows for the drivers
to have knowledge of the device info before the probe function gets
called. Use spi_get_device_match_data() and i2c_get_match_data() to get
chip info struct references. Also, missing entries (AD5673R/AD5677R) are
added to the i2c of_match table.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add of_match table for the SPI device variants to be consistent with the
AD5696 I2C driver.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Add support for AD5313R as a SPI-variant of AD5338R to the AD5686 SPI
driver.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Update device list entries from comment headers for both SPI and I2C
driver files and under Kconfig help text.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Create struct with bus operations, including a sync() operation that will
be used to flush multiple channel writes at once. Auxiliary functions
ad5686_write() and ad5686_read() are created and ad5686_probe() now
receives an ops struct pointer rather than individual read and write
functions. Documentation header of ad5686_state struct is updated
accordingly (adjusting renamed fields and formatting).

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
If wired LADC, should be held low when unused (pin is active-low), which
allows for synchronous DAC updates. This will be used to update all the
channels at the same time when adding buffer support.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
@rodrigo455 rodrigo455 force-pushed the staging/ad5313r-jic23-testing branch from 9f44ff1 to 3469c5e Compare April 2, 2026 14:08
Use of local SPI bus data to manage a collection of SPI transfers and
flush them to the SPI platform driver with the sync() operation. This
allows for faster handling of multiple channel DAC writes, avoiding kernel
overhead per spi_sync() call, which will be helpful when enabling
triggered buffer support.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Trigger handler is implemented by leveraging the LDAC gpio when it is
available. Multiple channel writes can be flushed at once with the sync()
operation.

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
@rodrigo455 rodrigo455 force-pushed the staging/ad5313r-jic23-testing branch from 3469c5e to 4c5c47c Compare April 2, 2026 14:32
@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 7 times, most recently from 59be8ec to 58a740e Compare April 9, 2026 00:12
@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 6 times, most recently from 5546c65 to aa19856 Compare April 15, 2026 00:11
@github-actions
Copy link
Copy Markdown

Automated Kernel Review — AD5313R IIO DAC Series

CI run: https://github.com/analogdevicesinc/linux/actions/runs/24441066096

Reviewed commits aa19856315a7..e05048f77b21 (14 code patches + 1 b4 cover letter).

Build passes cleanly for ARM (W=1, no warnings). DT binding checks (dt_binding_check) pass with no errors.


🐛 Bug: bus_data->size not reset on spi_sync() failure

drivers/iio/dac/ad5686-spi.c, commit 5a685dae

// Current (broken on error path):
ret = spi_sync(spi, &bus_data->msg);
if (ret)
    return ret;          // bus_data->size is NOT reset

bus_data->size = 0;
return 0;

If spi_sync() fails, bus_data->size is left non-zero. On the next call to ad5686_spi_write(), the stale size > 0 check causes spi_message_init() to be skipped, and new transfers are appended to the already-executed (and failed) message — producing a corrupt SPI transaction.

// Fix:
ret = spi_sync(spi, &bus_data->msg);
bus_data->size = 0;      // always reset, even on failure
return ret;

🐛 Bug: adi,ad5685 missing from DT binding

Documentation/devicetree/bindings/iio/dac/adi,ad5686.yaml, commit bf9ff8d1

The of_match table in ad5686-spi.c registers "adi,ad5685" (as well as "adi,ad5685r"), but the binding schema only lists "adi,ad5685r". Any device tree using "adi,ad5685" will fail dt-validate.

Fix: add - adi,ad5685 to the compatible enum in adi,ad5686.yaml.


⚠️ Documentation: LDAC GPIO polarity not stated in DT bindings

adi,ad5686.yaml and adi,ad5696.yaml, commits dbd78e3a / 31ff1408

The driver uses GPIOD_OUT_HIGH as the initial LDAC state and the trigger handler's pulse sequence (set_value(0) to latch, set_value(1) to load) is only correct when the GPIO is declared active-low in the device tree. Without GPIO_ACTIVE_LOW, the LDAC pulse is inverted and DAC outputs will never be updated atomically via the triggered buffer.

The adi,ad5791.yaml binding already models this correctly with:

ldac-gpios = <&gpio_bd 18 GPIO_ACTIVE_LOW>;

Please add a note to the ldac-gpios description in both bindings:

ldac-gpios:
  description:
    LDAC pin to be used as a hardware trigger to update the DAC channels.
    The LDAC pin is active-low; the GPIO must be declared with
    GPIO_ACTIVE_LOW polarity in the device tree.
  maxItems: 1

Style (checkpatch)

All 14 code commits produce:

  • WARNING: Do not use whitespace before Signed-off-by: — extra blank line before each Signed-off-by: tag.
  • Several commits exceed 75 characters in the description body.

These should be fixed before the series is submitted upstream.


Three fixup patches (using --fixup) addressing the two bugs and the documentation gap have been generated and are available in the CI artifacts.

@gastmaier gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 2 times, most recently from 1d05b45 to 815fd21 Compare April 17, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants