* [PATCH v3 01/12] iio: adc: ad_sigma_delta: don't overallocate scan buffer
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 02/12] iio: adc: ad_sigma_delta: sort includes David Lechner
` (12 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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] 19+ messages in thread
* [PATCH v3 02/12] iio: adc: ad_sigma_delta: sort includes
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
2025-07-01 21:37 ` [PATCH v3 01/12] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 03/12] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
` (11 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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] 19+ messages in thread
* [PATCH v3 03/12] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
2025-07-01 21:37 ` [PATCH v3 01/12] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
2025-07-01 21:37 ` [PATCH v3 02/12] iio: adc: ad_sigma_delta: sort includes David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 04/12] iio: adc: ad_sigma_delta: use sizeof() in ALIGN() David Lechner
` (10 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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] 19+ messages in thread
* [PATCH v3 04/12] iio: adc: ad_sigma_delta: use sizeof() in ALIGN()
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (2 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 03/12] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 05/12] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
` (9 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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, Andy Shevchenko,
David Lechner
Use sizeof() instead of hardcoding the size of the timestamp in the
ALIGN() macro. This makes it a bit more obvious what the intention of
the code is.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 5362157966d89cbf0e602716aaaf0b78f3921b11..dd15c357d1494bf5718e50e50a514cb4d4556f2b 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -488,7 +488,8 @@ 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 * indio_dev->channels[0].scan_type.storagebits / 8,
+ sizeof(s64));
samples_buf_size += sizeof(s64);
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] 19+ messages in thread
* [PATCH v3 05/12] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (3 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 04/12] iio: adc: ad_sigma_delta: use sizeof() in ALIGN() David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 06/12] iio: adc: ad_sigma_delta: audit included headers David Lechner
` (8 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 dd15c357d1494bf5718e50e50a514cb4d4556f2b..f91f7ae6dfca05cf3ae632a5f19990f3d153b706 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,
+ samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits),
sizeof(s64));
samples_buf_size += sizeof(s64);
samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
@@ -544,6 +546,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;
@@ -553,9 +556,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;
@@ -617,7 +618,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] 19+ messages in thread
* [PATCH v3 06/12] iio: adc: ad_sigma_delta: audit included headers
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (4 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 05/12] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 07/12] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
` (7 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 use 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 f91f7ae6dfca05cf3ae632a5f19990f3d153b706..b5c66a6cc47ec8e36c458fae87309fd30109c0ec 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] 19+ messages in thread
* [PATCH v3 07/12] iio: adc: ad_sigma_delta: refactor setting read address
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (5 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 06/12] iio: adc: ad_sigma_delta: audit included headers David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 08/12] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
` (6 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 b5c66a6cc47ec8e36c458fae87309fd30109c0ec..ce549775ac3d68fd11e660b6b993ac661301756a 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] 19+ messages in thread
* [PATCH v3 08/12] iio: adc: ad_sigma_delta: use spi_optimize_message()
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (6 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 07/12] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 09/12] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
` (5 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 ce549775ac3d68fd11e660b6b993ac661301756a..124c42e19f2e25723b67ea38f7d016f00ff91342 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;
@@ -510,6 +511,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;
@@ -529,6 +552,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;
}
@@ -550,7 +574,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)
@@ -560,50 +587,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] 19+ messages in thread
* [PATCH v3 09/12] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (7 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 08/12] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:37 ` [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
` (4 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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] 19+ messages in thread
* [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (8 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 09/12] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-02 7:57 ` Nuno Sá
2025-07-01 21:37 ` [PATCH v3 11/12] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
` (3 subsequent siblings)
13 siblings, 1 reply; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 | 62 ++++++++++++++++++++++
4 files changed, 69 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..8468c773713a3d203b2e668f340ee3f477b8fb6c
--- /dev/null
+++ b/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2025 Analog Devices Inc.
+ * Copyright (C) 2025 BayLibre, SAS
+ */
+
+#include <linux/clk.h>
+#include <linux/dev_printk.h>
+#include <linux/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>
+#include <linux/spi/offload/types.h>
+#include <linux/types.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] 19+ messages in thread
* Re: [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-07-01 21:37 ` [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
@ 2025-07-02 7:57 ` Nuno Sá
2025-07-02 12:37 ` David Lechner
0 siblings, 1 reply; 19+ messages in thread
From: Nuno Sá @ 2025-07-02 7:57 UTC (permalink / raw)
To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi
On Tue, 2025-07-01 at 16:37 -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.
>
> 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 | 62
> ++++++++++++++++++++++
> 4 files changed, 69 insertions(+), 1 deletion(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index
> 60ba572be7f5b48c0ab1d0d9724e19e335e8761b..4ed4977deb6ddc545be39b5c1d5e9959e9fe
> 64cf 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..e69f060d3875c168a2dc701a372e47b8ffd3
> 3268 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..51f9f16ed734424ff10672a04f2ec166dc63
> 7e0b 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..8468c773713a3d203b2e668f340ee3f477b8
> fb6c
> --- /dev/null
> +++ b/drivers/spi/spi-offload-trigger-adi-util-sigma-delta.c
> @@ -0,0 +1,62 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2025 Analog Devices Inc.
> + * Copyright (C) 2025 BayLibre, SAS
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/dev_printk.h>
> +#include <linux/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>
> +#include <linux/spi/offload/types.h>
> +#include <linux/types.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");
> +
Small nit. Did you consider enabling/disabling the clock on the trigger
enable()/disable() callback? I guess the ref clk will be enabled anyways by
someone else but conceptually kind of makes sense to enable the resource only
when needed.
Not a big deal (at least to me).
- Nuno Sá
> + 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");
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
2025-07-02 7:57 ` Nuno Sá
@ 2025-07-02 12:37 ` David Lechner
0 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-02 12:37 UTC (permalink / raw)
To: Nuno Sá, Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi
On 7/2/25 2:57 AM, Nuno Sá wrote:
> On Tue, 2025-07-01 at 16:37 -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.
>>
>> Signed-off-by: David Lechner <dlechner@baylibre.com>
>> ---
---
>> +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");
>> +
>
> Small nit. Did you consider enabling/disabling the clock on the trigger
> enable()/disable() callback? I guess the ref clk will be enabled anyways by
> someone else but conceptually kind of makes sense to enable the resource only
> when needed.
>
> Not a big deal (at least to me).
>
> - Nuno Sá
>
I thought about it, but we don't do that for any other FPGA IP cores
so I didn't do it here either.
Since they all use the same AXI clock anyway, disabling the clock
here probably doesn't have any effect in practice since there will
always be other users of the same clock keeping it enabled.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v3 11/12] iio: adc: ad_sigma_delta: add SPI offload support
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (9 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 10/12] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
@ 2025-07-01 21:37 ` David Lechner
2025-07-01 21:38 ` [PATCH v3 12/12] iio: adc: ad7173: " David Lechner
` (2 subsequent siblings)
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:37 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 | 165 +++++++++++++++++++++++----------
include/linux/iio/adc/ad_sigma_delta.h | 14 +++
2 files changed, 132 insertions(+), 47 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 124c42e19f2e25723b67ea38f7d016f00ff91342..9d2dba0a0ee6d7fe60c8ea188ed614100419081d 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,25 +497,35 @@ 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),
- sizeof(s64));
- 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),
+ sizeof(s64));
+ 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) {
@@ -530,6 +541,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;
@@ -546,7 +559,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;
@@ -561,10 +586,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);
@@ -679,7 +709,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;
}
@@ -712,17 +743,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;
@@ -742,14 +762,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;
}
@@ -769,12 +808,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);
}
@@ -837,6 +893,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;
@@ -846,3 +916,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] 19+ messages in thread
* [PATCH v3 12/12] iio: adc: ad7173: add SPI offload support
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (10 preceding siblings ...)
2025-07-01 21:37 ` [PATCH v3 11/12] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
@ 2025-07-01 21:38 ` David Lechner
2025-07-02 7:58 ` [PATCH v3 00/12] " Nuno Sá
2025-07-02 8:04 ` Andy Shevchenko
13 siblings, 0 replies; 19+ messages in thread
From: David Lechner @ 2025-07-01 21:38 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] 19+ messages in thread
* Re: [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (11 preceding siblings ...)
2025-07-01 21:38 ` [PATCH v3 12/12] iio: adc: ad7173: " David Lechner
@ 2025-07-02 7:58 ` Nuno Sá
2025-07-02 8:04 ` Andy Shevchenko
13 siblings, 0 replies; 19+ messages in thread
From: Nuno Sá @ 2025-07-02 7:58 UTC (permalink / raw)
To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Mark Brown
Cc: linux-iio, linux-kernel, devicetree, linux-spi, Andy Shevchenko
On Tue, 2025-07-01 at 16:37 -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.
>
> 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 v3:
> - Added extra patch to replace 8 with sizeof(s64) in ALIGN() [4/12]
> - Fixed typo in commit message. [6/12]
> - Fixed includes in spi offload trigger driver. [10/12]
> - Link to v2:
> https://lore.kernel.org/r/20250627-iio-adc-ad7173-add-spi-offload-support-v2-0-f49c55599113@baylibre.com
>
> 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
>
> ---
Hi David,
Great series. Small nit on the new trigger patch but not really important:
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> David Lechner (12):
> 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 sizeof() in ALIGN()
> 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 | 295 +++++++++++++-------
> -
> drivers/spi/Kconfig | 5 +
> drivers/spi/Makefile | 1 +
> .../spi/spi-offload-trigger-adi-util-sigma-delta.c | 62 +++++
> include/linux/iio/adc/ad_sigma_delta.h | 27 +-
> 8 files changed, 345 insertions(+), 114 deletions(-)
> ---
> base-commit: d02f330b0c78bcf76643fbb7d3215a58b181f829
> change-id: 20250620-iio-adc-ad7173-add-spi-offload-support-32a178b666a3
>
> Best regards,
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support
2025-07-01 21:37 [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support David Lechner
` (12 preceding siblings ...)
2025-07-02 7:58 ` [PATCH v3 00/12] " Nuno Sá
@ 2025-07-02 8:04 ` Andy Shevchenko
2025-07-06 10:04 ` Jonathan Cameron
13 siblings, 1 reply; 19+ messages in thread
From: Andy Shevchenko @ 2025-07-02 8:04 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 Tue, Jul 01, 2025 at 04:37:48PM -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.
>
> 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.
This version LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support
2025-07-02 8:04 ` Andy Shevchenko
@ 2025-07-06 10:04 ` Jonathan Cameron
2025-07-06 10:05 ` Jonathan Cameron
0 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2025-07-06 10:04 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 Wed, 2 Jul 2025 11:04:48 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> On Tue, Jul 01, 2025 at 04:37:48PM -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.
> >
> > 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.
>
> This version LGTM,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
Applied 1-7 and 11-12. Mark picked up 8 and 9 from v2.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v3 00/12] iio: adc: ad7173: add SPI offload support
2025-07-06 10:04 ` Jonathan Cameron
@ 2025-07-06 10:05 ` Jonathan Cameron
0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2025-07-06 10:05 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 Sun, 6 Jul 2025 11:04:17 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Wed, 2 Jul 2025 11:04:48 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > On Tue, Jul 01, 2025 at 04:37:48PM -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.
> > >
> > > 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.
> >
> > This version LGTM,
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
>
> Applied 1-7 and 11-12. Mark picked up 8 and 9 from v2.
1-8 and 11-12. 9 and 10 are now the ones that match with 8 and 9 that
Mark picked up. Oops.
>
> Thanks,
>
> Jonathan
>
>
>
^ permalink raw reply [flat|nested] 19+ messages in thread