* [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support
@ 2025-06-27 23:39 David Lechner
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
` (11 more replies)
0 siblings, 12 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:39 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Here comes another series for adding SPI offload support to an ADC.
The primary target is AD411x, but since this uses the ad_sigma_delta
shared module, a lot of this series is focused on that.
To start with, we have some cleanups to the ad_sigma_delta code, so feel
free to pick these up as they are ready as they generally stand on their
own.
Then before adding proper SPI offload support, we make use of
spi_optimize_message() to reduce CPU usage of all users of this driver
during buffered reads.
Also there is a new dt-binding and driver for a special SPI offload
trigger FPGA IP core that is used in this particular setup.
Then finally actual SPI offload support is added to the ad_sigma_delta
module and the ad7173 driver.
This was tested using EVAL-AD4112ARDZ on a DE10-Nano.
---
Changes in v2:
- New patch to fix overallocation of buffer size. [1/11]
- Also change int64_t to s64. [3/11]
- Fix typo in commit message. [4/11]
- Factor out scan_type to reduce line wraps. [4/11]
- New patch to clean up include more. [5/11]
- Duplicate comment about odd case of 24-bit data. [7/11]
- Fixed missing MODULE_IMPORT_NS() [10/11]
- Link to v1: https://lore.kernel.org/r/20250620-iio-adc-ad7173-add-spi-offload-support-v1-0-0766f6297430@baylibre.com
---
David Lechner (11):
iio: adc: ad_sigma_delta: don't overallocate scan buffer
iio: adc: ad_sigma_delta: sort includes
iio: adc: ad_sigma_delta: use u8 instead of uint8_t
iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
iio: adc: ad_sigma_delta: audit included headers
iio: adc: ad_sigma_delta: refactor setting read address
iio: adc: ad_sigma_delta: use spi_optimize_message()
dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
spi: offload trigger: add ADI Util Sigma-Delta SPI driver
iio: adc: ad_sigma_delta: add SPI offload support
iio: adc: ad7173: add SPI offload support
.../trigger-source/adi,util-sigma-delta-spi.yaml | 49 ++++
MAINTAINERS | 7 +-
drivers/iio/adc/ad7173.c | 13 +
drivers/iio/adc/ad_sigma_delta.c | 294 +++++++++++++--------
drivers/spi/Kconfig | 5 +
drivers/spi/Makefile | 1 +
.../spi/spi-offload-trigger-adi-util-sigma-delta.c | 59 +++++
include/linux/iio/adc/ad_sigma_delta.h | 27 +-
8 files changed, 341 insertions(+), 114 deletions(-)
---
base-commit: d02f330b0c78bcf76643fbb7d3215a58b181f829
change-id: 20250620-iio-adc-ad7173-add-spi-offload-support-32a178b666a3
Best regards,
--
David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
@ 2025-06-27 23:39 ` David Lechner
2025-06-28 14:55 ` Jonathan Cameron
2025-06-27 23:39 ` [PATCH v2 02/11] iio: adc: ad_sigma_delta: sort includes David Lechner
` (10 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:39 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Fix overallocating the size of the scan buffer by converting bits to
bytes. The size is meant to be in bytes, so scanbits needs to be
divided by 8.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 4c5f8d29a559fea7226b84141bcb148fb801f62c..6b3ef7ef403e00804abeb81025ed293b188e492b 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -489,7 +489,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
return ret;
}
- samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits, 8);
+ samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
samples_buf_size += sizeof(int64_t);
samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
samples_buf_size, GFP_KERNEL);
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 02/11] iio: adc: ad_sigma_delta: sort includes
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
@ 2025-06-27 23:39 ` David Lechner
2025-06-27 23:39 ` [PATCH v2 03/11] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
` (9 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:39 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Sort includes in alphabetical order and fix grouping before we add more.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 6b3ef7ef403e00804abeb81025ed293b188e492b..5cdd73160c6d6d4d9308eaa3a5aec14529475676 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -7,24 +7,22 @@
*/
#include <linux/align.h>
-#include <linux/interrupt.h>
#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
-#include <linux/err.h>
-#include <linux/module.h>
+#include <linux/unaligned.h>
+#include <linux/iio/adc/ad_sigma_delta.h>
+#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
-#include <linux/iio/buffer.h>
-#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/trigger.h>
#include <linux/iio/triggered_buffer.h>
-#include <linux/iio/adc/ad_sigma_delta.h>
-
-#include <linux/unaligned.h>
-
#define AD_SD_COMM_CHAN_MASK 0x3
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 03/11] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
2025-06-27 23:39 ` [PATCH v2 02/11] iio: adc: ad_sigma_delta: sort includes David Lechner
@ 2025-06-27 23:39 ` David Lechner
2025-06-27 23:40 ` [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
` (8 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:39 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Replace uint8_t with u8 in the ad_sigma_delta driver.
Technically, uint8_t comes from the C standard library, while u8 is a
Linux kernel type. Since we don't use the C standard library in the
kernel, we should use the kernel types instead.
There is also one instance where int64_t is replaced with s64.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 17 +++++++++--------
include/linux/iio/adc/ad_sigma_delta.h | 10 +++++-----
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 5cdd73160c6d6d4d9308eaa3a5aec14529475676..5362157966d89cbf0e602716aaaf0b78f3921b11 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
+#include <linux/types.h>
#include <linux/unaligned.h>
#include <linux/iio/adc/ad_sigma_delta.h>
@@ -38,7 +39,7 @@
* @sigma_delta: The sigma delta device
* @comm: New value for the communications register
*/
-void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm)
+void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, u8 comm)
{
/* Some variants use the lower two bits of the communications register
* to select the channel */
@@ -59,7 +60,7 @@ EXPORT_SYMBOL_NS_GPL(ad_sd_set_comm, "IIO_AD_SIGMA_DELTA");
int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
unsigned int size, unsigned int val)
{
- uint8_t *data = sigma_delta->tx_buf;
+ u8 *data = sigma_delta->tx_buf;
struct spi_transfer t = {
.tx_buf = data,
.len = size + 1,
@@ -99,9 +100,9 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
EXPORT_SYMBOL_NS_GPL(ad_sd_write_reg, "IIO_AD_SIGMA_DELTA");
static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
- unsigned int reg, unsigned int size, uint8_t *val)
+ unsigned int reg, unsigned int size, u8 *val)
{
- uint8_t *data = sigma_delta->tx_buf;
+ u8 *data = sigma_delta->tx_buf;
int ret;
struct spi_transfer t[] = {
{
@@ -185,8 +186,8 @@ EXPORT_SYMBOL_NS_GPL(ad_sd_read_reg, "IIO_AD_SIGMA_DELTA");
int ad_sd_reset(struct ad_sigma_delta *sigma_delta)
{
unsigned int reset_length = sigma_delta->info->num_resetclks;
- uint8_t *buf;
unsigned int size;
+ u8 *buf;
int ret;
size = DIV_ROUND_UP(reset_length, 8);
@@ -454,7 +455,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int i, slot, samples_buf_size;
unsigned int channel;
- uint8_t *samples_buf;
+ u8 *samples_buf;
int ret;
if (sigma_delta->num_slots == 1) {
@@ -488,7 +489,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
}
samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
- samples_buf_size += sizeof(int64_t);
+ samples_buf_size += sizeof(s64);
samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
samples_buf_size, GFP_KERNEL);
if (!samples_buf)
@@ -543,7 +544,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
- uint8_t *data = sigma_delta->rx_buf;
+ u8 *data = sigma_delta->rx_buf;
unsigned int transfer_size;
unsigned int sample_size;
unsigned int sample_pos;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index f242b285081b8d304ca25ae95337425e5842269a..5056677c9941afadc2383febbcafeb02e23a4f44 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -94,7 +94,7 @@ struct ad_sigma_delta {
bool bus_locked;
bool keep_cs_asserted;
- uint8_t comm;
+ u8 comm;
const struct ad_sigma_delta_info *info;
unsigned int active_slots;
@@ -105,7 +105,7 @@ struct ad_sigma_delta {
bool status_appended;
/* map slots to channels in order to know what to expect from devices */
unsigned int *slots;
- uint8_t *samples_buf;
+ u8 *samples_buf;
/*
* DMA (thus cache coherency maintenance) requires the
@@ -114,8 +114,8 @@ struct ad_sigma_delta {
* 'rx_buf' is up to 32 bits per sample + 64 bit timestamp,
* rounded to 16 bytes to take into account padding.
*/
- uint8_t tx_buf[4] __aligned(IIO_DMA_MINALIGN);
- uint8_t rx_buf[16] __aligned(8);
+ u8 tx_buf[4] __aligned(IIO_DMA_MINALIGN);
+ u8 rx_buf[16] __aligned(8);
};
static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
@@ -177,7 +177,7 @@ static inline int ad_sigma_delta_postprocess_sample(struct ad_sigma_delta *sd,
return 0;
}
-void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, uint8_t comm);
+void ad_sd_set_comm(struct ad_sigma_delta *sigma_delta, u8 comm);
int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
unsigned int size, unsigned int val);
int ad_sd_read_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (2 preceding siblings ...)
2025-06-27 23:39 ` [PATCH v2 03/11] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-28 14:56 ` Jonathan Cameron
2025-06-27 23:40 ` [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers David Lechner
` (7 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Use the BITS_TO_BYTES() macro instead of dividing by 8 to convert bits
to bytes.
This makes it more obvious what unit conversion is taking place.
In one instance, we also avoid the temporary assignment to a variable
as it was confusing that reg_size was being used with two different
units (bits and bytes).
scan_type is factored out to reduce line wrapping.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 5362157966d89cbf0e602716aaaf0b78f3921b11..64ed8aeb71f7c6ca19fff0438fa5ccce0c1d8f8f 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -7,6 +7,7 @@
*/
#include <linux/align.h>
+#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/interrupt.h>
@@ -190,7 +191,7 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta)
u8 *buf;
int ret;
- size = DIV_ROUND_UP(reset_length, 8);
+ size = BITS_TO_BYTES(reset_length);
buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -419,7 +420,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
data_reg = AD_SD_REG_DATA;
ret = ad_sd_read_reg(sigma_delta, data_reg,
- DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8),
+ BITS_TO_BYTES(chan->scan_type.realbits + chan->scan_type.shift),
&raw_sample);
out:
@@ -453,6 +454,7 @@ EXPORT_SYMBOL_NS_GPL(ad_sigma_delta_single_conversion, "IIO_AD_SIGMA_DELTA");
static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
{
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
+ const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
unsigned int i, slot, samples_buf_size;
unsigned int channel;
u8 *samples_buf;
@@ -488,7 +490,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
return ret;
}
- samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
+ samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
samples_buf_size += sizeof(s64);
samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
samples_buf_size, GFP_KERNEL);
@@ -543,6 +545,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
+ const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
u8 *data = sigma_delta->rx_buf;
unsigned int transfer_size;
@@ -552,9 +555,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
unsigned int reg_size;
unsigned int data_reg;
- reg_size = indio_dev->channels[0].scan_type.realbits +
- indio_dev->channels[0].scan_type.shift;
- reg_size = DIV_ROUND_UP(reg_size, 8);
+ reg_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
if (sigma_delta->info->data_reg != 0)
data_reg = sigma_delta->info->data_reg;
@@ -616,7 +617,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
}
}
- sample_size = indio_dev->channels[0].scan_type.storagebits / 8;
+ sample_size = BITS_TO_BYTES(scan_type->storagebits);
sample_pos = sample_size * sigma_delta->current_slot;
memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size);
sigma_delta->current_slot++;
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (3 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-30 9:02 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 06/11] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
` (6 subsequent siblings)
11 siblings, 1 reply; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Drop linux/iio/sysfs.h since it is unused and replace linux/kernel.h
with more explicit headers. There are a couple of other headers added
weren't covered by kernel.h, like linux/gpio/consumer.h that are added
since the module makes used of those APIs as well.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 64ed8aeb71f7c6ca19fff0438fa5ccce0c1d8f8f..ab34ff5e09146535fd6edbd288888c3afb0188a7 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -7,21 +7,28 @@
*/
#include <linux/align.h>
+#include <linux/bitmap.h>
#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/completion.h>
#include <linux/device.h>
#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/find.h>
+#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
-#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/property.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
#include <linux/types.h>
#include <linux/unaligned.h>
#include <linux/iio/adc/ad_sigma_delta.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/trigger.h>
#include <linux/iio/triggered_buffer.h>
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 06/11] iio: adc: ad_sigma_delta: refactor setting read address
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (4 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-27 23:40 ` [PATCH v2 07/11] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
` (5 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Refactor code to set the read address in a separate function.
This code is already duplicated twice and we will need to use it a third
time in a later commit.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index ab34ff5e09146535fd6edbd288888c3afb0188a7..d8101f5d443f957a398e66db1dad0d1f73c16078 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -107,6 +107,14 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
}
EXPORT_SYMBOL_NS_GPL(ad_sd_write_reg, "IIO_AD_SIGMA_DELTA");
+static void ad_sd_set_read_reg_addr(struct ad_sigma_delta *sigma_delta, u8 reg,
+ u8 *data)
+{
+ data[0] = reg << sigma_delta->info->addr_shift;
+ data[0] |= sigma_delta->info->read_mask;
+ data[0] |= sigma_delta->comm;
+}
+
static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
unsigned int reg, unsigned int size, u8 *val)
{
@@ -127,9 +135,7 @@ static int ad_sd_read_reg_raw(struct ad_sigma_delta *sigma_delta,
spi_message_init(&m);
if (sigma_delta->info->has_registers) {
- data[0] = reg << sigma_delta->info->addr_shift;
- data[0] |= sigma_delta->info->read_mask;
- data[0] |= sigma_delta->comm;
+ ad_sd_set_read_reg_addr(sigma_delta, reg, data);
spi_message_add_tail(&t[0], &m);
}
spi_message_add_tail(&t[1], &m);
@@ -288,9 +294,7 @@ static int ad_sigma_delta_clear_pending_event(struct ad_sigma_delta *sigma_delta
if (sigma_delta->info->has_registers) {
unsigned int data_reg = sigma_delta->info->data_reg ?: AD_SD_REG_DATA;
- data[0] = data_reg << sigma_delta->info->addr_shift;
- data[0] |= sigma_delta->info->read_mask;
- data[0] |= sigma_delta->comm;
+ ad_sd_set_read_reg_addr(sigma_delta, data_reg, data);
t[0].tx_buf = data;
spi_message_add_tail(&t[0], &m);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 07/11] iio: adc: ad_sigma_delta: use spi_optimize_message()
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (5 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 06/11] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-27 23:40 ` [PATCH v2 08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
` (4 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Use spi_optimize_message() to improve the performance of buffered reads.
By setting up the SPI message and pre-optimizing it in the buffer
postenable callback, we can reduce overhead during each sample read.
A rough estimate shows that this reduced the CPU usage of the interrupt
handler thread from 22% to 16% using an EVAL-AD4112ARDZ board on a
DE10-Nano (measuring a single channel at the default 6.2 kHz sample
rate).
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 72 ++++++++++++++++------------------
include/linux/iio/adc/ad_sigma_delta.h | 3 ++
2 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d8101f5d443f957a398e66db1dad0d1f73c16078..30ae7ef6d3f9f686b02176508813c689e6fb92f2 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -466,8 +466,9 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
{
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
+ struct spi_transfer *xfer = sigma_delta->sample_xfer;
unsigned int i, slot, samples_buf_size;
- unsigned int channel;
+ unsigned int channel, scan_size;
u8 *samples_buf;
int ret;
@@ -509,6 +510,28 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
return -ENOMEM;
sigma_delta->samples_buf = samples_buf;
+ scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
+ /* For 24-bit data, there is an extra byte of padding. */
+ xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
+ xfer[1].len = scan_size + (sigma_delta->status_appended ? 1 : 0);
+ xfer[1].cs_change = 1;
+
+ if (sigma_delta->info->has_registers) {
+ xfer[0].tx_buf = &sigma_delta->sample_addr;
+ xfer[0].len = 1;
+
+ ad_sd_set_read_reg_addr(sigma_delta,
+ sigma_delta->info->data_reg ?: AD_SD_REG_DATA,
+ &sigma_delta->sample_addr);
+ spi_message_init_with_transfers(&sigma_delta->sample_msg, xfer, 2);
+ } else {
+ spi_message_init_with_transfers(&sigma_delta->sample_msg,
+ &xfer[1], 1);
+ }
+
+ ret = spi_optimize_message(sigma_delta->spi, &sigma_delta->sample_msg);
+ if (ret)
+ return ret;
spi_bus_lock(sigma_delta->spi->controller);
sigma_delta->bus_locked = true;
@@ -528,6 +551,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
err_unlock:
spi_bus_unlock(sigma_delta->spi->controller);
+ spi_unoptimize_message(&sigma_delta->sample_msg);
return ret;
}
@@ -549,7 +573,10 @@ static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev)
ad_sigma_delta_disable_all(sigma_delta);
sigma_delta->bus_locked = false;
- return spi_bus_unlock(sigma_delta->spi->controller);
+ spi_bus_unlock(sigma_delta->spi->controller);
+ spi_unoptimize_message(&sigma_delta->sample_msg);
+
+ return 0;
}
static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
@@ -559,50 +586,19 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
u8 *data = sigma_delta->rx_buf;
- unsigned int transfer_size;
unsigned int sample_size;
unsigned int sample_pos;
unsigned int status_pos;
unsigned int reg_size;
- unsigned int data_reg;
+ int ret;
reg_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
+ /* For 24-bit data, there is an extra byte of padding. */
+ status_pos = reg_size + (reg_size == 3 ? 1 : 0);
- if (sigma_delta->info->data_reg != 0)
- data_reg = sigma_delta->info->data_reg;
- else
- data_reg = AD_SD_REG_DATA;
-
- /* Status word will be appended to the sample during transfer */
- if (sigma_delta->status_appended)
- transfer_size = reg_size + 1;
- else
- transfer_size = reg_size;
-
- switch (reg_size) {
- case 4:
- case 2:
- case 1:
- status_pos = reg_size;
- ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[0]);
- break;
- case 3:
- /*
- * Data array after transfer will look like (if status is appended):
- * data[] = { [0][sample][sample][sample][status] }
- * Keeping the first byte 0 shifts the status position by 1 byte to the right.
- */
- status_pos = reg_size + 1;
-
- /* We store 24 bit samples in a 32 bit word. Keep the upper
- * byte set to zero. */
- ad_sd_read_reg_raw(sigma_delta, data_reg, transfer_size, &data[1]);
- break;
-
- default:
- dev_err_ratelimited(&indio_dev->dev, "Unsupported reg_size: %u\n", reg_size);
+ ret = spi_sync_locked(sigma_delta->spi, &sigma_delta->sample_msg);
+ if (ret)
goto irq_handled;
- }
/*
* For devices sampling only one channel at
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 5056677c9941afadc2383febbcafeb02e23a4f44..2037bb68b44115681ff48f66b580b63f50c2ea9e 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -105,6 +105,8 @@ struct ad_sigma_delta {
bool status_appended;
/* map slots to channels in order to know what to expect from devices */
unsigned int *slots;
+ struct spi_message sample_msg;
+ struct spi_transfer sample_xfer[2];
u8 *samples_buf;
/*
@@ -116,6 +118,7 @@ struct ad_sigma_delta {
*/
u8 tx_buf[4] __aligned(IIO_DMA_MINALIGN);
u8 rx_buf[16] __aligned(8);
+ u8 sample_addr;
};
static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (6 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 07/11] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
` (3 subsequent siblings)
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Add new binding for the ADI Util Sigma-Delta SPI FPGA IP Core.
This is used to trigger a SPI offload based on a RDY signal from the
ADC while masking out other signals on the same line.
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
.../trigger-source/adi,util-sigma-delta-spi.yaml | 49 ++++++++++++++++++++++
MAINTAINERS | 5 +++
2 files changed, 54 insertions(+)
diff --git a/Documentation/devicetree/bindings/trigger-source/adi,util-sigma-delta-spi.yaml b/Documentation/devicetree/bindings/trigger-source/adi,util-sigma-delta-spi.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..ea466179551cb0d8f8e1cf01f91101b88734da88
--- /dev/null
+++ b/Documentation/devicetree/bindings/trigger-source/adi,util-sigma-delta-spi.yaml
@@ -0,0 +1,49 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2025 Analog Devices, Inc.
+# Copyright (c) 2025 BayLibre, SAS
+
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/trigger-source/adi,util-sigma-delta-spi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices Util Sigma-Delta SPI IP Core
+
+maintainers:
+ - David Lechner <dlechner@baylibre.com>
+
+description:
+ The Util Sigma-Delta SPI is an FPGA IP core from Analog Devices that provides
+ a SPI offload trigger from the RDY signal of the combined DOUT/RDY pin of
+ the sigma-delta family of ADCs.
+ https://analogdevicesinc.github.io/hdl/library/util_sigma_delta_spi/index.html
+
+properties:
+ compatible:
+ const: adi,util-sigma-delta-spi
+
+ reg:
+ maxItems: 1
+
+ clocks:
+ maxItems: 1
+
+ '#trigger-source-cells':
+ const: 0
+
+required:
+ - compatible
+ - reg
+ - clocks
+ - '#trigger-source-cells'
+
+additionalProperties: false
+
+examples:
+ - |
+ trigger@40000 {
+ reg = <0x40000 0x1000>;
+ compatible = "adi,util-sigma-delta-spi";
+ clocks = <&clk 0>;
+ #trigger-source-cells = <0>;
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index ea082c6be8acd5081d95bbada99ae47793f206e5..60ba572be7f5b48c0ab1d0d9724e19e335e8761b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25176,6 +25176,11 @@ W: https://github.com/srcres258/linux-doc
T: git git://github.com/srcres258/linux-doc.git doc-zh-tw
F: Documentation/translations/zh_TW/
+TRIGGER SOURCE - ADI UTIL SIGMA DELTA SPI
+M: David Lechner <dlechner@baylibre.com>
+S: Maintained
+F: Documentation/devicetree/bindings/trigger-source/adi,util-sigma-delta-spi.yaml
+
TRIGGER SOURCE - PWM
M: David Lechner <dlechner@baylibre.com>
S: Maintained
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (7 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-28 15:02 ` Jonathan Cameron
2025-06-30 9:05 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 10/11] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
` (2 subsequent siblings)
11 siblings, 2 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Add a new driver for the ADI Util Sigma-Delta SPI FPGA IP core.
This is used to trigger a SPI offload based on a RDY signal from an ADC
while masking out other signals on the same line.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
MAINTAINERS | 2 +-
drivers/spi/Kconfig | 5 ++
drivers/spi/Makefile | 1 +
.../spi/spi-offload-trigger-adi-util-sigma-delta.c | 59 ++++++++++++++++++++++
4 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 60ba572be7f5b48c0ab1d0d9724e19e335e8761b..4ed4977deb6ddc545be39b5c1d5e9959e9fe64cf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23357,7 +23357,7 @@ F: include/linux/mtd/spi-nor.h
SPI OFFLOAD
R: David Lechner <dlechner@baylibre.com>
-F: drivers/spi/spi-offload-trigger-pwm.c
+F: drivers/spi/spi-offload-trigger-*.c
F: drivers/spi/spi-offload.c
F: include/linux/spi/offload/
K: spi_offload
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index c51da3fc3604977b05388687e5e64a58370186c4..e69f060d3875c168a2dc701a372e47b8ffd33268 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -1355,6 +1355,11 @@ if SPI_OFFLOAD
comment "SPI Offload triggers"
+config SPI_OFFLOAD_TRIGGER_ADI_UTIL_SD
+ tristate "SPI offload trigger using ADI sigma-delta utility"
+ help
+ SPI offload trigger from ADI sigma-delta utility FPGA IP block.
+
config SPI_OFFLOAD_TRIGGER_PWM
tristate "SPI offload trigger using PWM"
depends on PWM
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 4ea89f6fc531625060255ecff237470927e1f041..51f9f16ed734424ff10672a04f2ec166dc637e0b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -170,3 +170,4 @@ obj-$(CONFIG_SPI_SLAVE_SYSTEM_CONTROL) += spi-slave-system-control.o
# SPI offload triggers
obj-$(CONFIG_SPI_OFFLOAD_TRIGGER_PWM) += spi-offload-trigger-pwm.o
+obj-$(CONFIG_SPI_OFFLOAD_TRIGGER_ADI_UTIL_SD) += spi-offload-trigger-adi-util-sigma-delta.o
diff --git a/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c b/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c
new file mode 100644
index 0000000000000000000000000000000000000000..035d088d4d33d6d32146a340381bb167f080e085
--- /dev/null
+++ b/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2025 Analog Devices Inc.
+ * Copyright (C) 2025 BayLibre, SAS
+ */
+
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/spi/offload/provider.h>
+
+static bool adi_util_sigma_delta_match(struct spi_offload_trigger *trigger,
+ enum spi_offload_trigger_type type,
+ u64 *args, u32 nargs)
+{
+ return type == SPI_OFFLOAD_TRIGGER_DATA_READY && nargs == 0;
+}
+
+static const struct spi_offload_trigger_ops adi_util_sigma_delta_ops = {
+ .match = adi_util_sigma_delta_match,
+};
+
+static int adi_util_sigma_delta_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct spi_offload_trigger_info info = {
+ .fwnode = dev_fwnode(dev),
+ .ops = &adi_util_sigma_delta_ops,
+ };
+ struct clk *clk;
+
+ clk = devm_clk_get_enabled(dev, NULL);
+ if (IS_ERR(clk))
+ return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n");
+
+ return devm_spi_offload_trigger_register(dev, &info);
+}
+
+static const struct of_device_id adi_util_sigma_delta_of_match_table[] = {
+ { .compatible = "adi,util-sigma-delta-spi", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, adi_util_sigma_delta_of_match_table);
+
+static struct platform_driver adi_util_sigma_delta_driver = {
+ .probe = adi_util_sigma_delta_probe,
+ .driver = {
+ .name = "adi-util-sigma-delta-spi",
+ .of_match_table = adi_util_sigma_delta_of_match_table,
+ },
+};
+module_platform_driver(adi_util_sigma_delta_driver);
+
+MODULE_AUTHOR("David Lechner <dlechner@baylibre.com>");
+MODULE_DESCRIPTION("ADI Sigma-Delta SPI offload trigger utility driver");
+MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 10/11] iio: adc: ad_sigma_delta: add SPI offload support
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (8 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-06-27 23:40 ` [PATCH v2 11/11] iio: adc: ad7173: " David Lechner
2025-07-02 13:27 ` (subset) [PATCH v2 00/11] " Mark Brown
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Add SPI offload support to the ad_sigma_delta module.
When the SPI controller has SPI offload capabilities, the module will
now use that for buffered reads instead of the RDY interrupt trigger.
Drivers that use the ad_sigma_delta module will have to opt into this
by setting supports_spi_offload since each driver will likely need
additional changes before SPI offload can be used. This will allow us
to gradually enable SPI offload support for each driver.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 163 +++++++++++++++++++++++----------
include/linux/iio/adc/ad_sigma_delta.h | 14 +++
2 files changed, 131 insertions(+), 46 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 30ae7ef6d3f9f686b02176508813c689e6fb92f2..38ed52644563c8d1869b12bcf25c4d63be35dd17 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -20,6 +20,7 @@
#include <linux/module.h>
#include <linux/property.h>
#include <linux/slab.h>
+#include <linux/spi/offload/consumer.h>
#include <linux/spi/spi.h>
#include <linux/spinlock.h>
#include <linux/string.h>
@@ -27,6 +28,7 @@
#include <linux/unaligned.h>
#include <linux/iio/adc/ad_sigma_delta.h>
+#include <linux/iio/buffer-dmaengine.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger_consumer.h>
@@ -467,8 +469,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
struct spi_transfer *xfer = sigma_delta->sample_xfer;
- unsigned int i, slot, samples_buf_size;
- unsigned int channel, scan_size;
+ unsigned int i, slot, channel;
u8 *samples_buf;
int ret;
@@ -496,24 +497,34 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
sigma_delta->active_slots = slot;
sigma_delta->current_slot = 0;
- if (sigma_delta->active_slots > 1) {
- ret = ad_sigma_delta_append_status(sigma_delta, true);
- if (ret)
- return ret;
- }
+ if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
+ xfer[1].offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
+ xfer[1].bits_per_word = scan_type->realbits;
+ xfer[1].len = spi_bpw_to_bytes(scan_type->realbits);
+ } else {
+ unsigned int samples_buf_size, scan_size;
- samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
- samples_buf_size += sizeof(s64);
- samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
- samples_buf_size, GFP_KERNEL);
- if (!samples_buf)
- return -ENOMEM;
+ if (sigma_delta->active_slots > 1) {
+ ret = ad_sigma_delta_append_status(sigma_delta, true);
+ if (ret)
+ return ret;
+ }
- sigma_delta->samples_buf = samples_buf;
- scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
- /* For 24-bit data, there is an extra byte of padding. */
- xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
- xfer[1].len = scan_size + (sigma_delta->status_appended ? 1 : 0);
+ samples_buf_size =
+ ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
+ samples_buf_size += sizeof(s64);
+ samples_buf = devm_krealloc(&sigma_delta->spi->dev,
+ sigma_delta->samples_buf,
+ samples_buf_size, GFP_KERNEL);
+ if (!samples_buf)
+ return -ENOMEM;
+
+ sigma_delta->samples_buf = samples_buf;
+ scan_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
+ /* For 24-bit data, there is an extra byte of padding. */
+ xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];
+ xfer[1].len = scan_size + (sigma_delta->status_appended ? 1 : 0);
+ }
xfer[1].cs_change = 1;
if (sigma_delta->info->has_registers) {
@@ -529,6 +540,8 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
&xfer[1], 1);
}
+ sigma_delta->sample_msg.offload = sigma_delta->offload;
+
ret = spi_optimize_message(sigma_delta->spi, &sigma_delta->sample_msg);
if (ret)
return ret;
@@ -545,7 +558,19 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
if (ret)
goto err_unlock;
- ad_sd_enable_irq(sigma_delta);
+ if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
+ struct spi_offload_trigger_config config = {
+ .type = SPI_OFFLOAD_TRIGGER_DATA_READY,
+ };
+
+ ret = spi_offload_trigger_enable(sigma_delta->offload,
+ sigma_delta->offload_trigger,
+ &config);
+ if (ret)
+ goto err_unlock;
+ } else {
+ ad_sd_enable_irq(sigma_delta);
+ }
return 0;
@@ -560,10 +585,15 @@ static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev)
{
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
- reinit_completion(&sigma_delta->completion);
- wait_for_completion_timeout(&sigma_delta->completion, HZ);
+ if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
+ spi_offload_trigger_disable(sigma_delta->offload,
+ sigma_delta->offload_trigger);
+ } else {
+ reinit_completion(&sigma_delta->completion);
+ wait_for_completion_timeout(&sigma_delta->completion, HZ);
- ad_sd_disable_irq(sigma_delta);
+ ad_sd_disable_irq(sigma_delta);
+ }
sigma_delta->keep_cs_asserted = false;
ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
@@ -678,7 +708,8 @@ static irqreturn_t ad_sd_data_rdy_trig_poll(int irq, void *private)
if ((!sigma_delta->rdy_gpiod || gpiod_get_value(sigma_delta->rdy_gpiod)) &&
ad_sd_disable_irq(sigma_delta)) {
complete(&sigma_delta->completion);
- iio_trigger_poll(sigma_delta->trig);
+ if (sigma_delta->trig)
+ iio_trigger_poll(sigma_delta->trig);
return IRQ_HANDLED;
}
@@ -711,17 +742,6 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de
unsigned long irq_flags = irq_get_trigger_type(sigma_delta->irq_line);
int ret;
- if (dev != &sigma_delta->spi->dev) {
- dev_err(dev, "Trigger parent should be '%s', got '%s'\n",
- dev_name(dev), dev_name(&sigma_delta->spi->dev));
- return -EFAULT;
- }
-
- sigma_delta->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
- iio_device_id(indio_dev));
- if (sigma_delta->trig == NULL)
- return -ENOMEM;
-
init_completion(&sigma_delta->completion);
sigma_delta->irq_dis = true;
@@ -741,14 +761,33 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de
if (ret)
return ret;
- iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
+ if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
+ sigma_delta->offload_trigger =
+ devm_spi_offload_trigger_get(dev, sigma_delta->offload,
+ SPI_OFFLOAD_TRIGGER_DATA_READY);
+ if (IS_ERR(sigma_delta->offload_trigger))
+ return dev_err_probe(dev, PTR_ERR(sigma_delta->offload_trigger),
+ "Failed to get SPI offload trigger\n");
+ } else {
+ if (dev != &sigma_delta->spi->dev)
+ return dev_err_probe(dev, -EFAULT,
+ "Trigger parent should be '%s', got '%s'\n",
+ dev_name(dev), dev_name(&sigma_delta->spi->dev));
- ret = devm_iio_trigger_register(dev, sigma_delta->trig);
- if (ret)
- return ret;
+ sigma_delta->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+ indio_dev->name, iio_device_id(indio_dev));
+ if (!sigma_delta->trig)
+ return -ENOMEM;
- /* select default trigger */
- indio_dev->trig = iio_trigger_get(sigma_delta->trig);
+ iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
+
+ ret = devm_iio_trigger_register(dev, sigma_delta->trig);
+ if (ret)
+ return ret;
+
+ /* select default trigger */
+ indio_dev->trig = iio_trigger_get(sigma_delta->trig);
+ }
return 0;
}
@@ -768,12 +807,29 @@ int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indi
if (!sigma_delta->slots)
return -ENOMEM;
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- &iio_pollfunc_store_time,
- &ad_sd_trigger_handler,
- &ad_sd_buffer_setup_ops);
- if (ret)
- return ret;
+ if (ad_sigma_delta_has_spi_offload(sigma_delta)) {
+ struct dma_chan *rx_dma;
+
+ rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
+ sigma_delta->offload);
+ if (IS_ERR(rx_dma))
+ return dev_err_probe(dev, PTR_ERR(rx_dma),
+ "Failed to get RX DMA channel\n");
+
+ ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
+ rx_dma, IIO_BUFFER_DIRECTION_IN);
+ if (ret)
+ return dev_err_probe(dev, ret, "Cannot setup DMA buffer\n");
+
+ indio_dev->setup_ops = &ad_sd_buffer_setup_ops;
+ } else {
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ &iio_pollfunc_store_time,
+ &ad_sd_trigger_handler,
+ &ad_sd_buffer_setup_ops);
+ if (ret)
+ return ret;
+ }
return devm_ad_sd_probe_trigger(dev, indio_dev);
}
@@ -836,6 +892,20 @@ int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
return sigma_delta->irq_line;
}
+ if (info->supports_spi_offload) {
+ struct spi_offload_config offload_config = {
+ .capability_flags = SPI_OFFLOAD_CAP_TRIGGER |
+ SPI_OFFLOAD_CAP_RX_STREAM_DMA,
+ };
+ int ret;
+
+ sigma_delta->offload = devm_spi_offload_get(&spi->dev, spi,
+ &offload_config);
+ ret = PTR_ERR_OR_ZERO(sigma_delta->offload);
+ if (ret && ret != -ENODEV)
+ return dev_err_probe(&spi->dev, ret, "Failed to get SPI offload\n");
+ }
+
iio_device_set_drvdata(indio_dev, sigma_delta);
return 0;
@@ -845,3 +915,4 @@ EXPORT_SYMBOL_NS_GPL(ad_sd_init, "IIO_AD_SIGMA_DELTA");
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
MODULE_DESCRIPTION("Analog Devices Sigma-Delta ADCs");
MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS("IIO_DMAENGINE_BUFFER");
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 2037bb68b44115681ff48f66b580b63f50c2ea9e..6e70a412e218d54bbf9bb6861b1a4cc89be868e8 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -31,6 +31,8 @@ struct ad_sigma_delta;
struct device;
struct gpio_desc;
struct iio_dev;
+struct spi_offload;
+struct spi_offload_trigger;
/**
* struct ad_sigma_delta_info - Sigma Delta driver specific callbacks and options
@@ -47,6 +49,10 @@ struct iio_dev;
* @has_registers: true if the device has writable and readable registers, false
* if there is just one read-only sample data shift register.
* @has_named_irqs: Set to true if there is more than one IRQ line.
+ * @supports_spi_offload: Set to true if the driver supports SPI offload. Often
+ * special considerations are needed for scan_type and other channel
+ * info, so individual drivers have to set this to let the core
+ * code know that it can use SPI offload if it is available.
* @addr_shift: Shift of the register address in the communications register.
* @read_mask: Mask for the communications register having the read bit set.
* @status_ch_mask: Mask for the channel number stored in status register.
@@ -65,6 +71,7 @@ struct ad_sigma_delta_info {
int (*postprocess_sample)(struct ad_sigma_delta *, unsigned int raw_sample);
bool has_registers;
bool has_named_irqs;
+ bool supports_spi_offload;
unsigned int addr_shift;
unsigned int read_mask;
unsigned int status_ch_mask;
@@ -108,6 +115,8 @@ struct ad_sigma_delta {
struct spi_message sample_msg;
struct spi_transfer sample_xfer[2];
u8 *samples_buf;
+ struct spi_offload *offload;
+ struct spi_offload_trigger *offload_trigger;
/*
* DMA (thus cache coherency maintenance) requires the
@@ -121,6 +130,11 @@ struct ad_sigma_delta {
u8 sample_addr;
};
+static inline bool ad_sigma_delta_has_spi_offload(struct ad_sigma_delta *sd)
+{
+ return sd->offload != NULL;
+}
+
static inline int ad_sigma_delta_set_channel(struct ad_sigma_delta *sd,
unsigned int channel)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH v2 11/11] iio: adc: ad7173: add SPI offload support
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (9 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 10/11] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
@ 2025-06-27 23:40 ` David Lechner
2025-07-02 13:27 ` (subset) [PATCH v2 00/11] " Mark Brown
11 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-06-27 23:40 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, David Lechner
Enable SPI offload support for the AD7173 ADC driver.
The scan_type used for SPI offload is assuming that we are using the
ad411x_ad717x HDL project [1] which always stores data words in 32-bits.
Link: https://analogdevicesinc.github.io/hdl/projects/ad411x_ad717x/index.html [1]
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad7173.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/iio/adc/ad7173.c b/drivers/iio/adc/ad7173.c
index 010339c2b7044da4b36dc894a38a145c2fcccd6a..580d4bf3366b193fa0f13d0a28886d390e1295b8 100644
--- a/drivers/iio/adc/ad7173.c
+++ b/drivers/iio/adc/ad7173.c
@@ -748,6 +748,7 @@ static const struct ad_sigma_delta_info ad7173_sigma_delta_info_4_slots = {
.set_mode = ad7173_set_mode,
.has_registers = true,
.has_named_irqs = true,
+ .supports_spi_offload = true,
.addr_shift = 0,
.read_mask = BIT(6),
.status_ch_mask = GENMASK(3, 0),
@@ -764,6 +765,7 @@ static const struct ad_sigma_delta_info ad7173_sigma_delta_info_8_slots = {
.set_mode = ad7173_set_mode,
.has_registers = true,
.has_named_irqs = true,
+ .supports_spi_offload = true,
.addr_shift = 0,
.read_mask = BIT(6),
.status_ch_mask = GENMASK(3, 0),
@@ -1585,6 +1587,11 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
if (st->info->data_reg_only_16bit)
chan_arr[chan_index].scan_type = ad4113_scan_type;
+ if (ad_sigma_delta_has_spi_offload(&st->sd)) {
+ chan_arr[chan_index].scan_type.storagebits = 32;
+ chan_arr[chan_index].scan_type.endianness = IIO_CPU;
+ }
+
chan_index++;
}
@@ -1675,6 +1682,12 @@ static int ad7173_fw_parse_channel_config(struct iio_dev *indio_dev)
if (st->info->data_reg_only_16bit)
chan_arr[chan_index].scan_type = ad4113_scan_type;
+ /* Assuming SPI offload is ad411x_ad717x HDL project. */
+ if (ad_sigma_delta_has_spi_offload(&st->sd)) {
+ chan_arr[chan_index].scan_type.storagebits = 32;
+ chan_arr[chan_index].scan_type.endianness = IIO_CPU;
+ }
+
chan_index++;
}
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
@ 2025-06-28 14:55 ` Jonathan Cameron
2025-06-28 15:04 ` Jonathan Cameron
0 siblings, 1 reply; 24+ messages in thread
From: Jonathan Cameron @ 2025-06-28 14:55 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On Fri, 27 Jun 2025 18:39:57 -0500
David Lechner <dlechner@baylibre.com> wrote:
> Fix overallocating the size of the scan buffer by converting bits to
> bytes. The size is meant to be in bytes, so scanbits needs to be
> divided by 8.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> drivers/iio/adc/ad_sigma_delta.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 4c5f8d29a559fea7226b84141bcb148fb801f62c..6b3ef7ef403e00804abeb81025ed293b188e492b 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -489,7 +489,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
> return ret;
> }
>
> - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits, 8);
> + samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
Seems like a good place for BITS_TO_BYTES() from bitops.h. Given we have another 8
kicking around in the same code line it might be a tiny bit confusing as / 8
If everything else is good I'll tweak this whilst applying (and add the include if needed).
> samples_buf_size += sizeof(int64_t);
> samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
> samples_buf_size, GFP_KERNEL);
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-06-27 23:40 ` [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
@ 2025-06-28 14:56 ` Jonathan Cameron
2025-06-30 8:59 ` Andy Shevchenko
0 siblings, 1 reply; 24+ messages in thread
From: Jonathan Cameron @ 2025-06-28 14:56 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On Fri, 27 Jun 2025 18:40:00 -0500
David Lechner <dlechner@baylibre.com> wrote:
> Use the BITS_TO_BYTES() macro instead of dividing by 8 to convert bits
> to bytes.
>
> This makes it more obvious what unit conversion is taking place.
>
> In one instance, we also avoid the temporary assignment to a variable
> as it was confusing that reg_size was being used with two different
> units (bits and bytes).
>
> scan_type is factored out to reduce line wrapping.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
>
> - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
> + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
Ah. You do it here. Fair enough and no problem wrt to patch 1 then.
> samples_buf_size += sizeof(s64);
> samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
> samples_buf_size, GFP_KERNEL);
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
@ 2025-06-28 15:02 ` Jonathan Cameron
2025-07-01 20:57 ` David Lechner
2025-06-30 9:05 ` Andy Shevchenko
1 sibling, 1 reply; 24+ messages in thread
From: Jonathan Cameron @ 2025-06-28 15:02 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On Fri, 27 Jun 2025 18:40:05 -0500
David Lechner <dlechner@baylibre.com> wrote:
> Add a new driver for the ADI Util Sigma-Delta SPI FPGA IP core.
>
> This is used to trigger a SPI offload based on a RDY signal from an ADC
> while masking out other signals on the same line.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
Hi David, Mark,
This looks fine to me and I'm not immediately spotting any
build requirements to mean this (and binding in previous patch)
need to go through IIO with the rest of the series? Shall I leave
this for Mark to pick up through the SPI tree if he is happy with it?
I'm happy with the rest of the series, but won't pick it up for
a little while to give Andy (+ anyone else who wishes to) time to
take a look at v2.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer
2025-06-28 14:55 ` Jonathan Cameron
@ 2025-06-28 15:04 ` Jonathan Cameron
0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2025-06-28 15:04 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On Sat, 28 Jun 2025 15:55:21 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Fri, 27 Jun 2025 18:39:57 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
> > Fix overallocating the size of the scan buffer by converting bits to
> > bytes. The size is meant to be in bytes, so scanbits needs to be
> > divided by 8.
> >
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---
> > drivers/iio/adc/ad_sigma_delta.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> > index 4c5f8d29a559fea7226b84141bcb148fb801f62c..6b3ef7ef403e00804abeb81025ed293b188e492b 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -489,7 +489,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
> > return ret;
> > }
> >
> > - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits, 8);
> > + samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
>
> Seems like a good place for BITS_TO_BYTES() from bitops.h. Given we have another 8
> kicking around in the same code line it might be a tiny bit confusing as / 8
>
> If everything else is good I'll tweak this whilst applying (and add the include if needed).
Found it in patch 4. No problem doing it there. 'Maybe' a hint in the description would
have been a nice to have, but not particularly important.
>
> > samples_buf_size += sizeof(int64_t);
> > samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
> > samples_buf_size, GFP_KERNEL);
> >
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-06-28 14:56 ` Jonathan Cameron
@ 2025-06-30 8:59 ` Andy Shevchenko
2025-06-30 13:33 ` David Lechner
0 siblings, 1 reply; 24+ messages in thread
From: Andy Shevchenko @ 2025-06-30 8:59 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Michael Hennerich, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Mark Brown,
linux-iio, linux-kernel, devicetree, linux-spi
On Sat, Jun 28, 2025 at 03:56:43PM +0100, Jonathan Cameron wrote:
> On Fri, 27 Jun 2025 18:40:00 -0500
> David Lechner <dlechner@baylibre.com> wrote:
...
> > - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
> > + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
>
> Ah. You do it here. Fair enough and no problem wrt to patch 1 then.
Hmm... Should the second 8 be something like sizeof(unsigned long lone) for
semantic distinguishing with 8-bit bytes?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers
2025-06-27 23:40 ` [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers David Lechner
@ 2025-06-30 9:02 ` Andy Shevchenko
0 siblings, 0 replies; 24+ messages in thread
From: Andy Shevchenko @ 2025-06-30 9:02 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown, linux-iio, linux-kernel, devicetree, linux-spi
On Fri, Jun 27, 2025 at 06:40:01PM -0500, David Lechner wrote:
> Drop linux/iio/sysfs.h since it is unused and replace linux/kernel.h
> with more explicit headers. There are a couple of other headers added
> weren't covered by kernel.h, like linux/gpio/consumer.h that are added
> since the module makes used of those APIs as well.
s/used/use/
> Signed-off-by: David Lechner <dlechner@baylibre.com>
...
> #include <linux/align.h>
> +#include <linux/bitmap.h>
> #include <linux/bitops.h>
bitops.h is implied by bitmap.h, but I'm fine with this being left untouched.
> +#include <linux/cleanup.h>
> +#include <linux/completion.h>
> #include <linux/device.h>
> #include <linux/err.h>
> +#include <linux/export.h>
> +#include <linux/find.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/interrupt.h>
> -#include <linux/kernel.h>
> #include <linux/module.h>
> +#include <linux/property.h>
> #include <linux/slab.h>
> #include <linux/spi/spi.h>
> +#include <linux/spinlock.h>
> +#include <linux/string.h>
> #include <linux/types.h>
> #include <linux/unaligned.h>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
2025-06-28 15:02 ` Jonathan Cameron
@ 2025-06-30 9:05 ` Andy Shevchenko
1 sibling, 0 replies; 24+ messages in thread
From: Andy Shevchenko @ 2025-06-30 9:05 UTC (permalink / raw)
To: David Lechner
Cc: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown, linux-iio, linux-kernel, devicetree, linux-spi
On Fri, Jun 27, 2025 at 06:40:05PM -0500, David Lechner wrote:
> Add a new driver for the ADI Util Sigma-Delta SPI FPGA IP core.
>
> This is used to trigger a SPI offload based on a RDY signal from an ADC
> while masking out other signals on the same line.
...
> +#include <linux/clk.h>
> +#include <linux/device.h>
Really? I though about dev_printk.h...
+ err.h
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/spi/offload/provider.h>
+ types.h
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-06-30 8:59 ` Andy Shevchenko
@ 2025-06-30 13:33 ` David Lechner
2025-07-01 13:47 ` Andy Shevchenko
0 siblings, 1 reply; 24+ messages in thread
From: David Lechner @ 2025-06-30 13:33 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Cameron
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On 6/30/25 3:59 AM, Andy Shevchenko wrote:
> On Sat, Jun 28, 2025 at 03:56:43PM +0100, Jonathan Cameron wrote:
>> On Fri, 27 Jun 2025 18:40:00 -0500
>> David Lechner <dlechner@baylibre.com> wrote:
>
> ...
>
>>> - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
>>> + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
>>
>> Ah. You do it here. Fair enough and no problem wrt to patch 1 then.
>
> Hmm... Should the second 8 be something like sizeof(unsigned long lone) for
> semantic distinguishing with 8-bit bytes?
>
Yeah, I considered to use sizeof(s64) to match the next line, but it
it seems like a separate change, so in the end I decided against doing
it in this patch and it seems too small of a thing for a separate patch.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-06-30 13:33 ` David Lechner
@ 2025-07-01 13:47 ` Andy Shevchenko
2025-07-01 17:36 ` Jonathan Cameron
0 siblings, 1 reply; 24+ messages in thread
From: Andy Shevchenko @ 2025-07-01 13:47 UTC (permalink / raw)
To: David Lechner
Cc: Jonathan Cameron, Michael Hennerich, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown, linux-iio, linux-kernel, devicetree, linux-spi
On Mon, Jun 30, 2025 at 08:33:59AM -0500, David Lechner wrote:
> On 6/30/25 3:59 AM, Andy Shevchenko wrote:
> > On Sat, Jun 28, 2025 at 03:56:43PM +0100, Jonathan Cameron wrote:
> >> On Fri, 27 Jun 2025 18:40:00 -0500
> >> David Lechner <dlechner@baylibre.com> wrote:
...
> >>> - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
> >>> + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
> >>
> >> Ah. You do it here. Fair enough and no problem wrt to patch 1 then.
> >
> > Hmm... Should the second 8 be something like sizeof(unsigned long lone) for
> > semantic distinguishing with 8-bit bytes?
>
> Yeah, I considered to use sizeof(s64) to match the next line, but it
> it seems like a separate change, so in the end I decided against doing
> it in this patch and it seems too small of a thing for a separate patch.
The problem in not the size of the change, the problem is that semantically
those 8:s are _different_ and code readability will be much better if we make
them so explicitly.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-07-01 13:47 ` Andy Shevchenko
@ 2025-07-01 17:36 ` Jonathan Cameron
0 siblings, 0 replies; 24+ messages in thread
From: Jonathan Cameron @ 2025-07-01 17:36 UTC (permalink / raw)
To: Andy Shevchenko
Cc: David Lechner, Michael Hennerich, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Mark Brown,
linux-iio, linux-kernel, devicetree, linux-spi
On Tue, 1 Jul 2025 16:47:02 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Mon, Jun 30, 2025 at 08:33:59AM -0500, David Lechner wrote:
> > On 6/30/25 3:59 AM, Andy Shevchenko wrote:
> > > On Sat, Jun 28, 2025 at 03:56:43PM +0100, Jonathan Cameron wrote:
> > >> On Fri, 27 Jun 2025 18:40:00 -0500
> > >> David Lechner <dlechner@baylibre.com> wrote:
>
> ...
>
> > >>> - samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
> > >>> + samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
> > >>
> > >> Ah. You do it here. Fair enough and no problem wrt to patch 1 then.
> > >
> > > Hmm... Should the second 8 be something like sizeof(unsigned long lone) for
> > > semantic distinguishing with 8-bit bytes?
> >
> > Yeah, I considered to use sizeof(s64) to match the next line, but it
> > it seems like a separate change, so in the end I decided against doing
> > it in this patch and it seems too small of a thing for a separate patch.
>
> The problem in not the size of the change, the problem is that semantically
> those 8:s are _different_ and code readability will be much better if we make
> them so explicitly.
Agreed. It's not so bad once we are down to just one magic 8 (ball :) but
definitely makes sense to give them both explicit meaning.
A tiny follow up patch, or rolling it in here with a comment in the patch
description would both be fine.
Jonathan
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-06-28 15:02 ` Jonathan Cameron
@ 2025-07-01 20:57 ` David Lechner
0 siblings, 0 replies; 24+ messages in thread
From: David Lechner @ 2025-07-01 20:57 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Michael Hennerich, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Mark Brown, linux-iio,
linux-kernel, devicetree, linux-spi
On 6/28/25 10:02 AM, Jonathan Cameron wrote:
> On Fri, 27 Jun 2025 18:40:05 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
>> Add a new driver for the ADI Util Sigma-Delta SPI FPGA IP core.
>>
>> This is used to trigger a SPI offload based on a RDY signal from an ADC
>> while masking out other signals on the same line.
>>
>> Signed-off-by: David Lechner <dlechner@baylibre.com>
> Hi David, Mark,
>
> This looks fine to me and I'm not immediately spotting any
> build requirements to mean this (and binding in previous patch)
> need to go through IIO with the rest of the series? Shall I leave
> this for Mark to pick up through the SPI tree if he is happy with it?
Sounds reasonable to me. There is no build-time dependency.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: (subset) [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
` (10 preceding siblings ...)
2025-06-27 23:40 ` [PATCH v2 11/11] iio: adc: ad7173: " David Lechner
@ 2025-07-02 13:27 ` Mark Brown
11 siblings, 0 replies; 24+ messages in thread
From: Mark Brown @ 2025-07-02 13:27 UTC (permalink / raw)
To: Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
David Lechner
Cc: linux-iio, linux-kernel, devicetree, linux-spi
On Fri, 27 Jun 2025 18:39:56 -0500, David Lechner wrote:
> Here comes another series for adding SPI offload support to an ADC.
>
> The primary target is AD411x, but since this uses the ad_sigma_delta
> shared module, a lot of this series is focused on that.
>
> To start with, we have some cleanups to the ad_sigma_delta code, so feel
> free to pick these up as they are ready as they generally stand on their
> own.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
commit: e47a324d6f07c9ef252cfce1f14cfa5110cbed99
[09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
commit: 3fcd3d2fe44dc9dfca20b6aed117f314a50ba0ff
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2025-07-02 13:27 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
2025-06-28 14:55 ` Jonathan Cameron
2025-06-28 15:04 ` Jonathan Cameron
2025-06-27 23:39 ` [PATCH v2 02/11] iio: adc: ad_sigma_delta: sort includes David Lechner
2025-06-27 23:39 ` [PATCH v2 03/11] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
2025-06-27 23:40 ` [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
2025-06-28 14:56 ` Jonathan Cameron
2025-06-30 8:59 ` Andy Shevchenko
2025-06-30 13:33 ` David Lechner
2025-07-01 13:47 ` Andy Shevchenko
2025-07-01 17:36 ` Jonathan Cameron
2025-06-27 23:40 ` [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers David Lechner
2025-06-30 9:02 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 06/11] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
2025-06-27 23:40 ` [PATCH v2 07/11] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
2025-06-27 23:40 ` [PATCH v2 08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
2025-06-28 15:02 ` Jonathan Cameron
2025-07-01 20:57 ` David Lechner
2025-06-30 9:05 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 10/11] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
2025-06-27 23:40 ` [PATCH v2 11/11] iio: adc: ad7173: " David Lechner
2025-07-02 13:27 ` (subset) [PATCH v2 00/11] " Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).