Skip to content

iio: dac: Add AD5413 support - #2786

Open
BruceTsaoADI wants to merge 2 commits into
analogdevicesinc:mirror_ci/jic23/iio/testingfrom
BruceTsaoADI:add-ad5413-driver
Open

iio: dac: Add AD5413 support#2786
BruceTsaoADI wants to merge 2 commits into
analogdevicesinc:mirror_ci/jic23/iio/testingfrom
BruceTsaoADI:add-ad5413-driver

Conversation

@BruceTsaoADI

Copy link
Copy Markdown

Summary

This PR adds initial support for the Analog Devices AD5413, a 14-bit single-channel DAC capable of voltage and current output.

Key changes

  • New driver: ad5413.c under drivers/iio/dac/
  • Devicetree binding: adi,ad5413.yaml under Documentation/devicetree/bindings/iio/dac/
  • Integrated with Kconfig and Makefile

Datasheet:

https://www.analog.com/media/en/technical-documentation/data-sheets/ad5413.pdf

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

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 tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly (if there is the case)

@gastmaier gastmaier left a comment

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.

Added the warnings that caused the ci to exit with an error but were not logged

Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
@BruceTsaoADI
BruceTsaoADI force-pushed the add-ad5413-driver branch 3 times, most recently from ba5d87d to 1401608 Compare June 29, 2025 05:51
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
Comment thread drivers/iio/dac/ad5413.c Outdated
@gastmaier

gastmaier commented Jul 4, 2025

Copy link
Copy Markdown
Collaborator

Hi, sorry for the pr failure, I updated the checkout strategy to retry by deepening the fetch until the rebase succeeds.
(It is not mega clear to me why it was failing in the first place, the total depth should be 7 (ahead + behind), but rebase only succeeds with around 24 or so.)

please see CI output, checkpatch is failing for example

Comment thread Documentation/devicetree/bindings/iio/dac/adi,ad5413.yaml Outdated
@BruceTsaoADI

Copy link
Copy Markdown
Author

Hi @dlech, @mhennerich, @nunojsa,

All feedback so far has been addressed in the latest commits.
CI still shows some false positives (e.g. checkpatch whitespace), but local checks pass with --strict and no errors.

Could you kindly take a look and let me know if anything else is required for approval?

Thanks!

@BruceTsaoADI
BruceTsaoADI force-pushed the add-ad5413-driver branch 9 times, most recently from 15694b1 to 8174327 Compare September 14, 2025 09:41
@gastmaier
gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 2 times, most recently from 4674362 to 78b10cd Compare April 27, 2026 00:12
@nunojsa

nunojsa commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

@BruceTsaoADI please properly rebase your patches on top of the target branch.

@gastmaier
gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 8 times, most recently from 6114e4f to e196cfc Compare May 5, 2026 00:12
@gastmaier
gastmaier force-pushed the mirror_ci/jic23/iio/testing branch from e196cfc to fdad854 Compare May 6, 2026 00:11
@BruceTsaoADI

BruceTsaoADI commented May 6, 2026

Copy link
Copy Markdown
Author

@BruceTsaoADI please properly rebase your patches on top of the target branch.

Thanks @nunojsa .

I fetched the latest mirror_ci/jic23/iio/testing target branch and rebased the two AD5413 patches on top of fdad854.

The PR branch has been force-pushed again. CI is now passing and there are no conflicts with the base branch.

@gastmaier
gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 5 times, most recently from ae283b1 to dcb3553 Compare May 11, 2026 00:14

@nunojsa nunojsa left a comment

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.

Here it goes my review

Comment thread drivers/iio/dac/ad5413.c
#include <linux/property.h>
#include <linux/spi/spi.h>
#include <linux/units.h>
#include <linux/util_macros.h>

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.

include paths should be in alphabetical order

Comment thread drivers/iio/dac/ad5413.c Outdated

MODULE_AUTHOR("Bruce Tsao <bruce.tsao@analog.com>");
MODULE_DESCRIPTION("Analog Devices AD5413 DAC");
MODULE_LICENSE("GPL v2");

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.

seems like you have some warnings here

Comment thread drivers/iio/dac/ad5413.c Outdated
{
struct ad5413_state *st;
struct iio_dev *indio_dev;
int ret, i;

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.

ditto

Comment thread drivers/iio/dac/ad5413.c Outdated
return ad5413_spi_write_mask(st,
AD5413_REG_DAC_CONFIG,
AD5413_REG_DAC_CONFIG_OUT_EN_MSK,
FIELD_PREP(AD5413_REG_DAC_CONFIG_OUT_EN_MSK, 1));

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.

still issues with formatting

Comment thread drivers/iio/dac/ad5413.c Outdated

*val = ret;
return IIO_VAL_INT;
}

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.

ditto

Comment thread drivers/iio/dac/ad5413.c Outdated
if (ret < 0) {
return dev_err_probe(&st->spi->dev, ret,
"Failed to initiate a calibration memory refresh\n");
}

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.

no need for brackets

Comment thread drivers/iio/dac/ad5413.c Outdated
/*
* Poll until the bit clears. ad5413_spi_reg_read() returns a negative
* errno on failure, so stop polling on error and propagate it.
*/

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.

I would say you don't need to comment what the API does

Comment thread drivers/iio/dac/ad5413.c Outdated
u32 cmd;

cmd = (u32)AD5413_WR_FLAG_MSK(AD5413_REG_TWO_STAGE_READBACK_SELECT) << 24;
cmd |= (u32)addr << 8;

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.

Same question as before?

Comment thread drivers/iio/dac/ad5413.c Outdated
if (ret < 0)
return ret;

return (be32_to_cpu(st->d32[2]) >> 8) & 0xFFFF;

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.

Oh just noticed this now. Don't mix error codes (returns) with proper read values. It just makes it weird. Just pass in a proper u16 * pointer as a argument and set it:

*val = be32_to_cpu(st->d32[2]) >> 8

Then no need for the mask as we already have an implicit cast to u16

@nunojsa

nunojsa commented May 11, 2026

Copy link
Copy Markdown
Collaborator

@BruceTsaoADI if you rebase again on top of testing so that only your two patches exist, we can trigger a final LLM review on your series before going upstream.

@gastmaier
gastmaier force-pushed the mirror_ci/jic23/iio/testing branch 2 times, most recently from 1719553 to 55ab0e3 Compare May 13, 2026 00:11
@BruceTsaoADI

Copy link
Copy Markdown
Author

Done. Rebased on top of the latest testing with only the two patches. All review comments addressed. Ready for the final LLM review.
Thanks @nunojsa!

@nunojsa

nunojsa commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@BruceTsaoADI we still 135 commits in the PR. You need to base your branch on the branch/tree

@BruceTsaoADI

Copy link
Copy Markdown
Author

Hi @nunojsa,

I've rebased the branch onto the latest testing. The PR now contains only my two patches (dt-bindings + driver). I also addressed two minor items in the driver patch:

  • Fixed a 32-bit overflow in the full-scale slew-time constant (16383 * MICRO → 16383ULL * MICRO).
  • Added a proper commit description to the driver commit.

CI is still red, but the failure is unrelated to this series and happens before my code is compiled. The auto_set_kconfig step fails to load Kconfig:

That file isn't touched by my patches, and the kernel's own Kconfig parser accepts this syntax fine (an arm64 build of the AD5413 driver passes locally). It looks like a pre-existing issue in the CI Kconfig helper on the current testing tip — all four build jobs fail at the same line regardless of arch/compiler.

Could you advise how you'd like to proceed? Thanks!

@BruceTsaoADI

Copy link
Copy Markdown
Author

Updated the driver commit with the following changes:

  • Add SPI CRC-8 support: every frame now carries a CRC byte, and the device
    is configured for SPI mode 1 (CPOL=0, CPHA=1). The device powers up with
    CRC enabled, so the previous version could not probe from a cold boot;
    it now brings the device up directly from power-on.
  • Align the IIO raw value with the 14-bit DAC data field (bits [15:2] of
    DAC_INPUT), so raw, register and scale are consistent.
  • MODULE_LICENSE: "GPL v2" -> "GPL".

Verified on hardware (Raspberry Pi 5 + EVAL-AD5413SDZ): cold-boot probe
succeeds and current output measured correctly (2 mA -> 1.99 V, 8 mA ->
7.94 V across 1 kOhm).

Only current-output mode has been tested so far; voltage-output mode is not
yet tested and I will add voltage testing as soon as possible.

The commit structure is unchanged (dt-bindings + driver).

Document the devicetree bindings for the Analog Devices AD5413, a
single-channel precision DAC controlled via SPI. The device supports
voltage or current output modes and programmable slew-rate control.

Signed-off-by: Bruce Tsao <bruce.tsao@analog.com>
The AD5413 is a single-channel, 14-bit, voltage and current output
digital-to-analog converter (DAC) with programmable output ranges,
slew rate control and on-chip diagnostics.

Add an IIO driver supporting the +-10.5 V voltage range and the
0-24 mA current range, output enable, slew rate control and device
reset over the SPI interface.

The device powers up with the SPI CRC enabled, so every frame carries
a CRC-8 byte and the interface is configured for SPI mode 1. This lets
the driver bring the device up directly from a cold boot without any
pre-conditioning.

Signed-off-by: Bruce Tsao <bruce.tsao@analog.com>
@BruceTsaoADI

Copy link
Copy Markdown
Author

CI is green now. The build failures were due to a missing select CRC8 in the
AD5413 Kconfig entry (the driver uses the crc8 library); added it and all builds pass.

Also: voltage-output mode is now hardware-verified (RPi5 SPI1 + EVAL-AD5413SDZ,
±15V bipolar). Full ±10.5V sweep at VIOUT: 0x0000=-10.4V, 0x4000=-5.19V,
0x8000=0V, 0xC000=+5.19V, 0xFFFC=+10.40V (symmetric, correct polarity,
~0.3% FSR untrimmed). Verified through the loaded driver too: out_voltage_offset
reads -8192 and echo 1950 > out_voltage0_raw gives ~-8V.

Folded one fix into the driver commit: the voltage-channel IIO offset had a
32-bit overflow plus a spurious /1000, yielding 0 instead of -8192; fixed via div_s64.

Both current- and voltage-output modes are now hardware-verified.

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.

4 participants