iio: adc: ad4000: Add SPI offload support
Marcelo Schmitt
maintainerv4 cover iio: adc: ad4000: Add SPI offload support
This patch series extends the ad4000 driver to support SPI offloading. In addition to that, ad4000 IIO documentation is expanded to:
- list PulSAR parts supported by the ad4000 driver.
- describe some characteristics of AD4000 IIO device.
- describe changes when SPI offload is being used.
Change log v3 -> v4
[IIO driver]
- No longer changing spi_device CS timing parameters.
- SPI offload messages now set only one transfer.
- Degraded offload_xfers from array to single entry field.
- Adjusted ad4000_spi_offload_setup() comment.
- Dropped t_quiet1_ns since it's not used anymore.
- Fixed include order.
- Fixed typo: withouth -> without.
[Documentation]
- Picked up review tags.
- Made phrase about SPI offload engine more generic.
- Complemented SPI offload section with supported wiring configurations.
Change log v2 -> v3
- Dropped patch 1 of v2 series and reverted buffer endianness and SPI transfer bits_per_word configurations to the way they were in v1.
- Removed dummy transfer in ad4000_prepare_offload_turbo_message().
- Unified offload message preparation.
- Removed spi->cs_hold.value to use cs_inactive to set CNV/CS high time.
- Adjusted max sample rate for AD7983 and AD7984.
- Dropped AD4000_TCONV_NS and made all time related constants a time_spec field.
- Removed _offl param from _CHANNELS() macros and added a comment about that.
- Commented IIO_BE check in ad4000_prepare_3wire_mode_message().
- Now using predisable to balance with postenable.
- Put spi/offload/consumer.h include right after spi/spi.h.
- Removed unrelated brackets in info_mask_separate_available assignment
- Added blank line after if.
Change log v1 -> v2
- Fixed passing inappropriate pointer instead of ret to dev_err_probe()
- [new patch] Set transfer bits_per_word to have data in CPU endianness
- Set iio_dev num_channels close to where channels is set.
- Complement offload message comment about first sample being invalid
- Document why the first buffer sample is invalid when offloading
- Added blank line before a 'simple return'.
Link to v3: https://lore.kernel.org/linux-iio/[email protected]/
Link to v2: https://lore.kernel.org/linux-iio/[email protected]/
Link to v1: https://lore.kernel.org/linux-iio/[email protected]/
Marcelo Schmitt (4):
iio: adc: ad4000: Add support for SPI offload
Documentation: iio: ad4000: Add new supported parts
Documentation: iio: ad4000: Add IIO Device characteristics section
Documentation: iio: ad4000: Describe offload support
Documentation/iio/ad4000.rst | 91 ++++++++- drivers/iio/adc/Kconfig | 7 +- drivers/iio/adc/ad4000.c | 382 +++++++++++++++++++++++++++++++---- 3 files changed, 444 insertions(+), 36 deletions(-)
base-commit: 9f36acefb2621d980734a5bb7d74e0e24e0af166
prerequisite-patch-id: 3d517eef53a799adba5922815fe684b913e36773
Signature · 1 line
2.47.2
Marcelo Schmitt
maintainerPATCH v4 1/4 iio: adc: ad4000: Add support for SPI offload
FPGA HDL projects can include a PWM generator in addition to SPI-Engine. The PWM IP is used to trigger SPI-Engine offload modules that in turn set SPI-Engine to execute transfers to poll data from the ADC. That allows data to be read at the maximum sample rates. Also, it is possible to set a specific sample rate by setting the proper PWM duty cycle and related state parameters, thus allowing an adjustable ADC sample rate when a PWM (offload trigger) is used in combination with SPI-Engine.
Add support for SPI offload.
--- drivers/iio/adc/Kconfig | 7 +- drivers/iio/adc/ad4000.c | 382 +++++++++++++++++++++++++++++++++++---- 2 files changed, 354 insertions(+), 35 deletions(-)
drivers/iio/adc/Kconfig +6 -1
@@ -25,10 +25,15 @@ config AD4000 tristate "Analog Devices AD4000 ADC Driver" depends on SPI select IIO_BUFFER + select IIO_BUFFER_DMAENGINE select IIO_TRIGGERED_BUFFER + select SPI_OFFLOAD help Say yes here to build support for Analog Devices AD4000 high speed - SPI analog to digital converters (ADC). + SPI analog to digital converters (ADC). If intended to use with + SPI offloading support, it is recommended to enable + CONFIG_SPI_AXI_SPI_ENGINE, CONFIG_PWM_AXI_PWMGEN, and + CONFIG_SPI_OFFLOAD_TRIGGER_PWM. To compile this driver as a module, choose M here: the module will be called ad4000.
drivers/iio/adc/ad4000.c +348 -34
775 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH v4 1/4] iio: adc: ad4000: Add support for SPI offload
Quoted 8 lines · Marcelo Schmitt
FPGA HDL projects can include a PWM generator in addition to SPI-Engine. The PWM IP is used to trigger SPI-Engine offload modules that in turn set SPI-Engine to execute transfers to poll data from the ADC. That allows data to be read at the maximum sample rates. Also, it is possible to set a specific sample rate by setting the proper PWM duty cycle and related state parameters, thus allowing an adjustable ADC sample rate when a PWM (offload trigger) is used in combination with SPI-Engine.
Quoted 4 lines
Add support for SPI offload.
Signed-off-by Marcelo Schmitt <[email protected]>---
I think I spotted a bug. With that fixed...
drivers/iio/adc/ad4000.c static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, · line 944
Quoted 4 lines
drivers/iio/adc/ad4000.c +0
-0@@ -690,6 +942,15 @@ static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, xfers[1 ].rx_buf = &st->scan.data; xfers[1 ].len =BITS_TO_BYTES (chan->scan_type.storagebits);
Now this needs to be:
xfer->len = chan->scan_type.realbits > 16 ? 4 : 2;
Otherwise when there is SPI offload, this could read 2 words because storagebits is always == 32.
Quoted 12 lines
drivers/iio/adc/ad4000.c +9
-0+ +/* +* If the device is set up for SPI offloading, IIO channel scan_type is +* set to IIO_CPU. When that is the case, use larger SPI word sizes for +* single-shot reads too. Thus, sample data can be correctly handled in +* ad4000_single_conversion() according to scan_type endianness. +*/ +if (chan->scan_type.endianness !=IIO_BE ) + xfers[1 ].bits_per_word = chan->scan_type.realbits; xfers[1 ].delay.value = st->time_spec->t_quiet2_ns; xfers[1 ].delay.unit =SPI_DELAY_UNIT_NSECS ;
Re: [PATCH v4 1/4] iio: adc: ad4000: Add support for SPI offload
Quoted 25 lines · David Lechner
Quoted 8 lines · Marcelo Schmitt
FPGA HDL projects can include a PWM generator in addition to SPI-Engine. The PWM IP is used to trigger SPI-Engine offload modules that in turn set SPI-Engine to execute transfers to poll data from the ADC. That allows data to be read at the maximum sample rates. Also, it is possible to set a specific sample rate by setting the proper PWM duty cycle and related state parameters, thus allowing an adjustable ADC sample rate when a PWM (offload trigger) is used in combination with SPI-Engine.
Quoted 4 lines
Add support for SPI offload.
Signed-off-by Marcelo Schmitt <[email protected]>---
I think I spotted a bug. With that fixed...
Reviewed-by David Lechner <[email protected]>drivers/iio/adc/ad4000.c static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, · line 944
Quoted 4 lines
drivers/iio/adc/ad4000.c +0
-0@@ -690,6 +942,15 @@ static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, xfers[1 ].rx_buf = &st->scan.data; xfers[1 ].len =BITS_TO_BYTES (chan->scan_type.storagebits);Now this needs to be:
Quoted 4 lines
xfer->len = chan->scan_type.realbits > 16 ? 4 : 2;Otherwise when there is SPI offload, this could read 2 words because storagebits is always == 32.
I've just tested both versions with ADAQ4003 and with AD7687. There's no practical difference between the suggestion and what already is in IIO testing. I don't mind sending a patch with the change, but don't think it fixes anything.
Thanks,
Marcelo
Jonathan Cameron
maintainerRe: [PATCH v4 1/4] iio: adc: ad4000: Add support for SPI offload
Quoted 28 lines · On Thu, 10 Apr 2025 12:08:27 -0300 Marcelo Schmitt…
Quoted 27 lines · David Lechner
Quoted 8 lines · Marcelo Schmitt
FPGA HDL projects can include a PWM generator in addition to SPI-Engine. The PWM IP is used to trigger SPI-Engine offload modules that in turn set SPI-Engine to execute transfers to poll data from the ADC. That allows data to be read at the maximum sample rates. Also, it is possible to set a specific sample rate by setting the proper PWM duty cycle and related state parameters, thus allowing an adjustable ADC sample rate when a PWM (offload trigger) is used in combination with SPI-Engine.
Quoted 4 lines
Add support for SPI offload.
Signed-off-by Marcelo Schmitt <[email protected]>---
I think I spotted a bug. With that fixed...
Reviewed-by David Lechner <[email protected]>drivers/iio/adc/ad4000.c static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, · line 944
Quoted 4 lines
drivers/iio/adc/ad4000.c +0
-0@@ -690,6 +942,15 @@ static int ad4000_prepare_3wire_mode_message(struct ad4000_state *st, xfers[1 ].rx_buf = &st->scan.data; xfers[1 ].len =BITS_TO_BYTES (chan->scan_type.storagebits);Now this needs to be:
xfer->len = chan->scan_type.realbits > 16 ? 4 : 2;
Quoted 7 lines
Quoted 2 lines
Otherwise when there is SPI offload, this could read 2 words because storagebits is always == 32.
I've just tested both versions with ADAQ4003 and with AD7687. There's no practical difference between the suggestion and what already is in IIO testing. I don't mind sending a patch with the change, but don't think it fixes anything.
If it is an unnecessary over read in some cases, probably sensible to either reduce the length or add a comment on why we don't care.
Jonathan
Quoted 3 lines
Thanks,
Marcelo
Marcelo Schmitt
maintainerPATCH v4 2/4 Documentation: iio: ad4000: Add new supported parts
In reply to Marcelo SchmittCommit <c3948d090080> ("iio: adc: ad4000: Add support for PulSAR devices"), extended the ad4000 driver supports many single-channel PulSAR devices.
Update IIO ad4000 documentation with the extra list of supported devices.
--- Documentation/iio/ad4000.rst | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
Documentation/iio/ad4000.rst +16 -1
@@ -4,7 +4,7 @@ AD4000 driver ============= -Device driver for Analog Devices Inc. AD4000 series of ADCs. +Device driver for Analog Devices Inc. AD4000 series of ADCs and similar devices. Supported devices =================
@@ -25,6 +25,21 @@ Supported devices * `AD4022 <https://www.analog.com/AD4022>`_ * `ADAQ4001 <https://www.analog.com/ADAQ4001>`_ * `ADAQ4003 <https://www.analog.com/ADAQ4003>`_ +* `AD7685 <https://www.analog.com/AD7685>`_ +* `AD7686 <https://www.analog.com/AD7686>`_ +* `AD7687 <https://www.analog.com/AD7687>`_ +* `AD7688 <https://www.analog.com/AD7688>`_ +* `AD7690 <https://www.analog.com/AD7690>`_ +* `AD7691 <https://www.analog.com/AD7691>`_ +* `AD7693 <https://www.analog.com/AD7693>`_ +* `AD7942 <https://www.analog.com/AD7942>`_ +* `AD7946 <https://www.analog.com/AD7946>`_ +* `AD7980 <https://www.analog.com/AD7980>`_ +* `AD7982 <https://www.analog.com/AD7982>`_ +* `AD7983 <https://www.analog.com/AD7983>`_ +* `AD7984 <https://www.analog.com/AD7984>`_ +* `AD7988-1 <https://www.analog.com/AD7988-1>`_ +* `AD7988-5 <https://www.analog.com/AD7988-5>`_ Wiring connections ------------------
Signature · 1 line
2.47.2
Marcelo Schmitt
maintainerPATCH v4 3/4 Documentation: iio: ad4000: Add IIO Device characteristics section
In reply to Marcelo SchmittComplement ad4000 IIO driver documentation with considerations about ``_scale_available`` attribute and table of typical channel attributes.
--- Documentation/iio/ad4000.rst | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
Documentation/iio/ad4000.rst +47 -0
@@ -144,3 +144,50 @@ Set ``adi,sdi-pin`` to ``"cs"`` to select this mode. ^ | | +--------------------| SCLK | +-------------+ + +IIO Device characteristics +========================== + +The AD4000 series driver supports differential and pseudo-differential ADCs. + +The span compression feature available in AD4000 series devices can be +enabled/disabled by changing the ``_scale_available`` attribute of the voltage +channel. Note that span compression configuration requires writing to AD4000 +configuration register, which is only possible when the ADC is wired in 3-wire +turbo mode, and the SPI controller is ``SPI_MOSI_IDLE_HIGH`` capable. If those +conditions are not met, no ``_scale_available`` attribute is provided. + +Besides that, differential and pseudo-differential voltage channels present +slightly different sysfs interfaces. + +Pseudo-differential ADCs +------------------------ + +Typical voltage channel attributes of a pseudo-differential AD4000 series device: + ++-------------------------------------------+------------------------------------------+ +| Voltage Channel Attributes | Description | ++===========================================+==========================================+ +| ``in_voltage0_raw`` | Raw ADC output code. | ++-------------------------------------------+------------------------------------------+ +| ``in_voltage0_offset`` | Offset to convert raw value to mV. | ++-------------------------------------------+------------------------------------------+ +| ``in_voltage0_scale`` | Scale factor to convert raw value to mV. | ++-------------------------------------------+------------------------------------------+ +| ``in_voltage0_scale_available`` | Toggles input span compression | ++-------------------------------------------+------------------------------------------+ + +Differential ADCs +----------------- + +Typical voltage channel attributes of a differential AD4000 series device: + ++-------------------------------------------+------------------------------------------+ +| Voltage Channel Attributes | Description | ++===========================================+==========================================+ +| ``in_voltage0-voltage1_raw`` | Raw ADC output code. | ++-------------------------------------------+------------------------------------------+ +| ``in_voltage0-voltage1_scale`` | Scale factor to convert raw value to mV. | ++-------------------------------------------+------------------------------------------+ +| ``in_voltage0-voltage1_scale_available`` | Toggles input span compression | ++-------------------------------------------+------------------------------------------+
Signature · 1 line
2.47.2
Marcelo Schmitt
maintainerPATCH v4 4/4 Documentation: iio: ad4000: Describe offload support
In reply to Marcelo SchmittWhen SPI offloading is supported, the IIO device provides different sysfs interfaces to allow using the adjusting the sample rate. Document SPI offload support for AD4000 and similar devices.
--- Documentation/iio/ad4000.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Documentation/iio/ad4000.rst +27 -0
@@ -191,3 +191,30 @@ Typical voltage channel attributes of a differential AD4000 series device: +-------------------------------------------+------------------------------------------+ | ``in_voltage0-voltage1_scale_available`` | Toggles input span compression | +-------------------------------------------+------------------------------------------+ + +SPI offload support +------------------- + +To be able to achieve the maximum sample rate, the driver can be used with SPI +offload engines such as the one usually present in `AXI SPI Engine`_, to provide +SPI offload support. + +.. _AXI SPI Engine: http://analogdevicesinc.github.io/hdl/projects/pulsar_adc/index.html + +To keep up with SPI offloading transfer speeds, the ADC must be connected either +in 3-wire turbo mode or in 3-wire without busy indicator mode and have SPI +controller CS line connected to the CNV pin. + +When set for SPI offload support, the IIO device will provide different +interfaces. + +* Either ``in_voltage0_sampling_frequency`` or + ``in_voltage0-voltage1_sampling_frequency`` file is provided to allow setting + the sample rate. +* IIO trigger device is not provided (no ``trigger`` directory). +* ``timestamp`` channel is not provided. + +Also, because the ADC output has a one sample latency (delay) when the device is +wired in "3-wire" mode and only one transfer per sample is done when using SPI +offloading, the first data sample in the buffer is not valid because it contains +the output of an earlier conversion result.
Signature · 1 line
2.47.2
Quoted 5 lines · On Thu, 27 Mar 2025 18:24:14 -0300 Marcelo Schmitt…
This patch series extends the ad4000 driver to support SPI offloading. In addition to that, ad4000 IIO documentation is expanded to:
- list PulSAR parts supported by the ad4000 driver.
- describe some characteristics of AD4000 IIO device.
- describe changes when SPI offload is being used.
I left it to sit for a week to see if anyone else had remaining comments. Seems not on this occasion.
Applied to the tesing branch of iio.git which I'll shortly rebase on rc1 once available.
Thanks,
Jonathan
Quoted 57 lines
Change log v3 -> v4
[IIO driver]
- No longer changingspi_deviceCS timing parameters.
- SPI offload messages now set only one transfer.
- Degradedoffload_xfersfrom array to single entry field.
- Adjustedad4000_spi_offload_setup()comment.
- Droppedt_quiet1_nssince it's not used anymore.
- Fixed include order.
- Fixed typo: withouth -> without.
[Documentation]
- Picked up review tags.
- Made phrase about SPI offload engine more generic.
- Complemented SPI offload section with supported wiring configurations.Change log v2 -> v3
- Dropped patch 1 of v2 series and reverted buffer endianness and SPI transferbits_per_wordconfigurations to the way they were in v1.
- Removed dummy transfer inad4000_prepare_offload_turbo_message().
- Unified offload message preparation.
- Removedspi->cs_hold.valueto usecs_inactiveto set CNV/CS high time.
- Adjusted max sample rate for AD7983 and AD7984.
- DroppedAD4000_TCONV_NSand made all time related constants atime_specfield.
- Removed_offlparam from_CHANNELS()macros and added a comment about that.
- CommentedIIO_BEcheck inad4000_prepare_3wire_mode_message().
- Now using predisable to balance with postenable.
- Putspi/offload/consumer.hinclude right afterspi/spi.h.
- Removed unrelated brackets ininfo_mask_separate_availableassignment
- Added blank line after if.Change log v1 -> v2
- Fixed passing inappropriate pointer instead of ret todev_err_probe()
- [new patch] Set transferbits_per_wordto have data in CPU endianness
- Setiio_devnum_channelsclose to where channels is set.
- Complement offload message comment about first sample being invalid
- Document why the first buffer sample is invalid when offloading
- Added blank line before a 'simple return'.Link to v3: https://lore.kernel.org/linux-iio/[email protected]/
Link to v2: https://lore.kernel.org/linux-iio/[email protected]/
Link to v1: https://lore.kernel.org/linux-iio/[email protected]/Marcelo Schmitt (4):
iio: adc: ad4000: Add support for SPI offload
Documentation: iio: ad4000: Add new supported parts
Documentation: iio: ad4000: Add IIO Device characteristics section
Documentation: iio: ad4000: Describe offload supportDocumentation/iio/ad4000.rst | 91 ++++++++- drivers/iio/adc/Kconfig | 7 +- drivers/iio/adc/ad4000.c | 382 +++++++++++++++++++++++++++++++---- 3 files changed, 444 insertions(+), 36 deletions(-)base-commit:
9f36acefb2621d980734a5bb7d74e0e24e0af166
prerequisite-patch-id:3d517eef53a799adba5922815fe684b913e36773