Skip to content

iio: dac: add ad5706 (part 2) - #3327

Open
actorreno wants to merge 7 commits into
dev_ad5706r_1from
dev_ad5706r_2
Open

actorreno wants to merge 7 commits into
dev_ad5706r_1from
dev_ad5706r_2

Conversation

@actorreno

Copy link
Copy Markdown
Contributor

PR Description

This is part 2 of series of patches to fully support ad5706r
refer to part 1 here: #3325

  • Adding device attributes to AD5706R, a quad 16-bit current output digital-to-analog converter with integrated precision reference.

  • Datasheet of AD5706R.

  • Features Implemented:

    • dev_addr, spi cmd can change to communicate up to 4 devices on same bus
    • addr_ascension pertaining to how multibyte registers are accessed
    • single_instr to choose whether streaming or single transaction
    • sampling_frequency for PWM frequency
    • hw_ldac_tg_state for PWM control of low or high
    • hw_ldac_tg_pwm to make the ldac pin into a pwm
    • multi_dac_input_a content for multi select channel load
    • multi_dac_sw_ldac_trigger to trigger the multi channel load
    • mux_out_sel for internal monitoring
    • hw_shutdown_state controls device enable pin

This PR is related to #3096
The upstream asked this to be split.
Part 1 - basic driver
Part 2 - device attributes (this)
Part 3 - Channel attributes
Part 4 - debugfs attributes

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

@actorreno actorreno changed the title iio: dac: ad5706: add device attributes iio: dac: add ad5706 (part 2) May 19, 2026
@actorreno
actorreno marked this pull request as ready for review May 20, 2026 00:53
@actorreno actorreno mentioned this pull request May 20, 2026
4 of 8 tasks
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
@actorreno
actorreno force-pushed the dev_ad5706r_2 branch 4 times, most recently from d76eef2 to 103bf88 Compare May 25, 2026 06:42
@actorreno

Copy link
Copy Markdown
Contributor Author

v2:

  • Replaced custom hw_shutdown_state with IIO_CHAN_INFO_ENABLE
  • Removed runtime-configurable attributes (addr_ascension, single_instr) uses boot defaults
  • mux_out_sel - removed, for future debugfs patch
  • Added proper regulator handling for all power supplies (iovdd, avdd, pvddx)
  • Converted dev_addr to device tree property (adi,device-address)
  • driver only supports single device
  • added decrement mode register offseting for multibyte reg
  • Removed obsolete sysfs documentation

@actorreno
actorreno requested a review from rodrigo455 May 25, 2026 07:07
Document the spi-device-addr property which selects the hardware
device address via the A0 and A1 pins. Up to four AD5706R devices
can share a single SPI chip select by strapping these pins to
different values (0–3).

Also constrain spi-max-frequency to the 25 MHz maximum specified
in the datasheet.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
@actorreno

Copy link
Copy Markdown
Contributor Author

v3 changes and a short summary overall:

New Features:

  • Added toggle and dither channel hierarchy — toggle and dither subchannels are now IIO children of their respective physical channels

Changed in v3 via feedback:

Reorganized:

  • dev_addr - uses spi-device-addr (aligns with ad5529r)
  • addr_ascension - now hardcoded
  • single_instr - driver internally handles
  • hw_shutdown_state - replaced with IIO_CHAN_INFO_ENABLE
  • hw_ldac_tg_state, hw_ldac_tg_pwm, IIO_CHAN_INFO_SAMP_FREQ, IIO_CHAN_INFO_ENABLE
    - placed accordingly with the channel hierarchy

Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
@actorreno

Copy link
Copy Markdown
Contributor Author

v4 changes:

ad5706r:

  • replaced deprecated extend_name with iio_info->read_label() on toggle and dither channels,
  • toggle channels: use .channel = ch + 100 for unique sysfs paths; documented the 100-offset in ABI
  • Dither channels: change type from IIO_CURRENT to IIO_ALTCURRENT
  • Dither IIO_CHAN_INFO_RAW writes to INPUT_B (amplitude), not DITHER_PERIOD
  • Dither channels: add IIO_CHAN_INFO_FREQUENCY for DITHER_PERIOD N divider (N * frequency = sampling_frequency)
  • Dither channels: add IIO_CHAN_INFO_SAMP_FREQ for LDAC PWM rate

ABI:

  • added the toggle offset 100

Comment thread drivers/iio/dac/ad5706r.c Resolved
Add support for the six power supplies (iovdd, avdd, pvdd0–3) using
devm_regulator_bulk_get_enable(). Support an optional external voltage
reference via vref-supply, falling back to the internal bandgap
reference when absent. Add optional hardware reset via reset-gpios
with the required t_RESET_PW (20 ns) and t_RESET_DELAY (200 us) timing.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
The AD5706R supports up to four devices on a shared SPI bus, addressed
by two hardware address pins (A1:A0). Read the device address from the
spi-device-addr DT property and embed it in every SPI command word using
FIELD_PREP(AD5706R_ADDR_PIN_MASK). Also switch to DECREMENT mode for
two-byte register accesses (reg++ before transmit) so the device clocks
out MSB then LSB as required by the datasheet.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
Comment thread drivers/iio/dac/ad5706r.c Resolved
Comment thread drivers/iio/dac/ad5706r.c Resolved
@actorreno
actorreno force-pushed the dev_ad5706r_2 branch 2 times, most recently from e4c1de6 to 0553027 Compare December 4, 2026 02:17
Configure the device on probe: enable async load mode so DAC outputs
update immediately on INPUT A write (no LDAC pulse needed), and put all
channels in normal (non-shutdown) operating mode.

Expose per-channel output enable through IIO_CHAN_INFO_ENABLE. When an
enable-gpios is provided, the OUT_EN register is written to give the
GPIO control over the channel outputs; otherwise the enable attribute
is not writable.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
Add support for the LDAC PWM input, which triggers DAC updates at a
configurable rate. The PWM consumer is initialised at 1 MHz with zero
duty cycle and exposed via IIO_CHAN_INFO_SAMP_FREQ on both physical and
toggle channels.

Add toggle mode: writing 1 to the toggle channel's enable attribute
switches the channel into TOGGLE function mode, alternating between
INPUT A and INPUT B on each LDAC pulse. The toggle channels use a
100-offset on the channel index (channel = phys + 100) to produce
unique sysfs paths without conflicting with physical channel indices.
Add read_label() to report human-readable names (phy0–phy3,
toggle0–toggle3) for both channel types.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

LLM review

This series adds the AD5706R TOGGLE/DITHER channel hierarchy, the LDAC PWM, output enable, regulator and reset handling, the SPI binding properties and the driver documentation. Changes are requested: the LDAC mode is inverted so sysfs writes do not reach the outputs, en=0 does not disable the output when enable-gpios is set, and the dither frequency/phase/amplitude programming does not match the register encoding.

Session: 43821377129

d036599f07955 - add output enable control

LDAC mode: LDAC_SYNC_ASYNC is written GENMASK(3, 0), which selects LDAC-synchronous updates (datasheet Table 45: 0 = updated by a write to DAC_INPUT_A). With the LDAC PWM at 0% duty there are no edges, so raw writes do not reach the outputs. Fixup 0001 writes 0.

Enable with enable-gpios: en writes HW_SHUTDOWN_EN (0x26). HW_SHUTDOWN_EN=0 is normal operation (Table 17), so en=0 does not disable the channel. Without the GPIO en works. Fixup 0001 uses OUT_OP_MODE for en in all cases; the pin still gates through HW_SHUTDOWN_EN.

6479df9fdd1a0 - add dither mode

Dither frequency: DITHER_PERIOD_CHn is a 3-bit code, not a sample count. Codes 0 to 4 give N = 4, 8, 16, 32, 64 (datasheet Table 22). The driver writes N as-is, so N=4 selects 64 samples and N=8 selects 4 samples. Fixup 0002 converts N to the code and rejects N that cannot be programmed.

Dither raw and phase: the two MSBs of INPUT_B are ignored for dither, so the range is [0, 16383]. DITHER_PHASE_CHn is a 2-bit code, so the range is [0, 3]. Fixup 0002 applies both.

a438689bb245 - dt-bindings: document spi properties

CI: the binding has no copyright line, which fails checks/checks. Fixup 0003 adds it.

reset-gpios: the text says a software reset is used when the property is absent. The driver does not issue one. Fixup 0003 corrects it.

fdf2497b4558 - docs: iio: add documentation for ad5706r driver

The en description says it requires enable-gpios; that is wrong in both directions (see above). The toggle en description says "stops the PWM" (it sets 0% duty). The dither raw, phase and frequency ranges and the example do not match the fixed driver. Fixup 0004 corrects them.

Open (not patched, need a decision)

  • spi-device-addr: the binding uses an array schema, but the driver reads one value. The PR thread asks to drop it or use reg with #address-cells until multi-device support exists.
  • OUT_OP_MODE=0xF at probe enables all outputs; the datasheet says they power up high-Z.
  • The PWM is shared by toggle and dither. Disabling toggle on one channel sets 0% duty, which stops the DCK for dither channels.
  • pvdd1-pvdd3 are requested by the bulk get but not required by the binding.

CI warnings

Smatch not found, skipped is an environment gap; smatch was not run. Intermediate commits d036599f, e03afa7b and 6479df9f have lines over 100 columns; the tip has none.

Verification data

Built drivers/iio/dac/ad5706r.o with set_arch gcc_arm, adi_ci_defconfig, auto_set_kconfig and make W=1 at every driver commit and at the tip with the fixups: no warnings. Sparse (C=1) is clean. dt_binding_check passes for the binding. make SPHINXDIRS=iio htmldocs builds the new page. The dither N mapping was checked with a host model. Datasheet: media/en/technical-documentation/data-sheets/ad5705r-ad5706r.md from the docling tree. Hardware, DT probe on a board and smatch were not run.

Suggested patches

  • 0001-fixup-iio-dac-ad5706r-add-output-enable-control.patch (3565a79623d1) - en via OUT_OP_MODE, LDAC async
  • 0002-fixup-iio-dac-ad5706r-add-dither-mode.patch (c9a080ea81e2) - dither N code, amplitude and phase ranges
  • 0003-fixup-dt-bindings-iio-dac-ad5706r-document-spi-prope.patch (d603f3ac0dd0) - copyright line, reset-gpios text
  • 0004-fixup-docs-iio-add-documentation-for-ad5706r-driver.patch (619e04af6821) - documentation for en, dither ranges and example

Apply with:

cd path/to/repository
export GITHUB_TOKEN=ghp_*** # explicit instead of git credentials
apply-patches --repo=analogdevicesinc/linux 43821377129
Install instructions

The following one-liner installs the script if not present already:

curl -fSsL "https://raw.githubusercontent.com/analogdevicesinc/doctools/refs/heads/main/ci/scripts/apply-patches.sh"      -o ~/.local/bin/apply-patches.sh &&   grep -q "/apply-patches.sh" ~/.bashrc || echo "source ~/.local/bin/apply-patches.sh" >> $_ ; . $_

More information at AI Usage.

Add support for dither mode, which superimposes a sine wave on the DAC
output to reduce the effect of ADC quantisation at the system level.

Dither channels are of type IIO_ALTCURRENT with channel indices 0–3,
matching the physical channel they modulate. The dither frequency is
controlled via IIO_CHAN_INFO_FREQUENCY (the N divider written to
DITHER_PERIOD: N * frequency = sampling_frequency). The dither
amplitude is set via IIO_CHAN_INFO_RAW (DITHER_SCALE register).
IIO_CHAN_INFO_SAMP_FREQ is shared with the physical/toggle channels
and reflects the LDAC PWM rate.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
Add documentation for the AD5706R IIO DAC driver describing the channel
hierarchy and operating modes.

Signed-off-by: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
@actorreno

Copy link
Copy Markdown
Contributor Author

v5:

  • splitting commits of main driver code
  • absence of GPIO en now falls back to SW en
  • removed ABI and added ad5706r.rst for documentation

@gastmaier
gastmaier added this pull request to stack #3707 December 4, 2026 08:58
Comment thread drivers/iio/dac/ad5706r.c
}

/* Enable async load mode: DAC output updates immediately on INPUT A write, no LDAC pulse needed */
ret = regmap_write(st->regmap, AD5706R_REG_LDAC_SYNC_ASYNC, GENMASK(3, 0));

@rodrigo455 rodrigo455 Dec 4, 2026 •

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.

llm review is correct. The intended behavior is achieved by writing zeros here.

Comment thread drivers/iio/dac/ad5706r.c

/* Enable OUT_EN pin control only when the pin is driven by enable-gpios */
if (st->out_en_gpio) {
ret = regmap_write(st->regmap, AD5706R_REG_OUT_EN, GENMASK(3, 0));

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 here. HW_SHUTDOWN_EN=0 is normal operation.

Comment thread drivers/iio/dac/ad5706r.c Outdated
ret = regmap_read(st->regmap, reg, &reg_val);
if (ret)
return ret;
*val = !!(reg_val & AD5706R_CH_EN_BIT(chan->channel));

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.

You have set out_en_gpio to LOW in the probe, so the only way to achieve normal operation is:

  • OUT_OP_MODE_CH = 1
  • HW_SHUTDOWN_EN_CH = 0
    and it powers down with:
  • OUT_OP_MODE_CH = 1
  • HW_SHUTDOWN_EN = 1

but if out_en_gpio is not provided, datasheet says to use OUT_EN = IOVDD, but the logic should not rely on that, so in normal operation:

  • OUT_OP_MODE_CH = 1
  • HW_SHUTDOWN_EN_CH = 0
    and it powers down with:
  • OUT_OP_MODE_CH = 0
  • HW_SHUTDOWN_EN_CH = x

Note that judging the power state by looking at HW_SHUTDOWN_EN vs OUT_OP_MODE_CH ... there is an inversion when using HW_SHUTDOWN_EN.

OUT_SWITCH_EN would control a different power mode not covered at this point.

Comment thread drivers/iio/dac/ad5706r.c
n = DIV_ROUND_CLOSEST_ULL(NANO, ldac_pwm_state.period * val);

/* The dither period is encoded as 2^n, where n = 2..6 (4..64) */
if (n < 4 || n > 64 || !is_power_of_2(n))

@rodrigo455 rodrigo455 Dec 4, 2026 •

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.

Instead of returning -EINVAL, I suggest to clamp() the value and use roundup_pow_of_two() or roundown_pow_of_two(), like n = roundup_pow_of_two(clamp(n, 4, 64))... or take ilog2() right after the clamp(), as ilog2() always rounds down. Another approach is find_closest() if using a pre-defined array as reference (4, 8, 16, 32, 64).

Comment thread drivers/iio/dac/ad5706r.c
break;
case AD5706R_CHAN_IDX_TOGGLE_0 ... AD5706R_CHAN_IDX_TOGGLE_3:
case AD5706R_CHAN_IDX_DITHER_0 ... AD5706R_CHAN_IDX_DITHER_3:
reg = AD5706R_REG_FUNC_DAC_INPUT_B_CH(ad5706r_phys_ch(chan));

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.

llm review indicates that range to check for val is different for INPUT_B in dither mode.

Comment thread drivers/iio/dac/ad5706r.c
if (val < 0 || val > AD5706R_DITHER_PHASE_MAX)
return -EINVAL;
reg = AD5706R_REG_FUNC_DITHER_PHASE_CH(ad5706r_phys_ch(chan));
return regmap_write(st->regmap, reg, val);

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.

phase should be in radians, not raw value.

This branch has not been deployed

No deployments
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