linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] iio: adc: ad7173: add SPI offload support
@ 2025-06-20 22:20 David Lechner
  2025-06-20 22:20 ` [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes David Lechner
                   ` (8 more replies)
  0 siblings, 9 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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.

---
David Lechner (9):
      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: 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                   | 281 +++++++++++++--------
 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, 330 insertions(+), 112 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] 25+ messages in thread

* [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-22 14:37   ` Jonathan Cameron
  2025-06-20 22:20 ` [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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 4c5f8d29a559fea7226b84141bcb148fb801f62c..6cd3645eaaf38a23d5b6479ac598b6d276cfd81a 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] 25+ messages in thread

* [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
  2025-06-20 22:20 ` [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-23  6:51   ` Andy Shevchenko
  2025-06-20 22:20 ` [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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.

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad_sigma_delta.c       | 15 ++++++++-------
 include/linux/iio/adc/ad_sigma_delta.h | 10 +++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 6cd3645eaaf38a23d5b6479ac598b6d276cfd81a..1657f64f1c0465b249adcc8a70dda8faf4a90565 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,7 +186,7 @@ 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;
+	u8 *buf;
 	unsigned int size;
 	int ret;
 
@@ -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) {
@@ -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] 25+ messages in thread

* [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
  2025-06-20 22:20 ` [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes David Lechner
  2025-06-20 22:20 ` [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-22 14:39   ` Jonathan Cameron
  2025-06-23  6:54   ` Andy Shevchenko
  2025-06-20 22:20 ` [PATCH 4/9] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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 once 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).

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad_sigma_delta.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 1657f64f1c0465b249adcc8a70dda8faf4a90565..fa792c800c80f960aca75b28a60cb2588e69fe7d 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)
 	unsigned int size;
 	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:
@@ -552,9 +553,8 @@ 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(indio_dev->channels[0].scan_type.realbits +
+				 indio_dev->channels[0].scan_type.shift);
 
 	if (sigma_delta->info->data_reg != 0)
 		data_reg = sigma_delta->info->data_reg;
@@ -616,7 +616,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(indio_dev->channels[0].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] 25+ messages in thread

* [PATCH 4/9] iio: adc: ad_sigma_delta: refactor setting read address
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (2 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-20 22:20 ` [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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 fa792c800c80f960aca75b28a60cb2588e69fe7d..883cc02d4099908644af523bcf66c0178fbd0e55 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -100,6 +100,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)
 {
@@ -120,9 +128,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);
@@ -281,9 +287,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] 25+ messages in thread

* [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message()
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (3 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 4/9] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-22 14:50   ` Jonathan Cameron
  2025-06-23  6:57   ` Andy Shevchenko
  2025-06-20 22:20 ` [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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       | 74 ++++++++++++++++------------------
 include/linux/iio/adc/ad_sigma_delta.h |  3 ++
 2 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 883cc02d4099908644af523bcf66c0178fbd0e55..a9b97f5d4107a2e1bb74877d30403445e9b04a44 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -458,8 +458,10 @@ 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;
+	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;
 
@@ -493,7 +495,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 * scan_type->storagebits, 8);
 	samples_buf_size += sizeof(int64_t);
 	samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
 				    samples_buf_size, GFP_KERNEL);
@@ -501,6 +503,27 @@ 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);
+	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;
@@ -520,6 +543,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;
 }
@@ -541,7 +565,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)
@@ -550,51 +577,20 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	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(indio_dev->channels[0].scan_type.realbits +
 				 indio_dev->channels[0].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] 25+ messages in thread

* [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (4 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-27 19:59   ` Rob Herring (Arm)
  2025-06-20 22:20 ` [PATCH 7/9] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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.

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] 25+ messages in thread

* [PATCH 7/9] spi: offload trigger: add ADI Util Sigma-Delta SPI driver
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (5 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
  2025-06-20 22:20 ` [PATCH 9/9] iio: adc: ad7173: " David Lechner
  8 siblings, 0 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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] 25+ messages in thread

* [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (6 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 7/9] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
@ 2025-06-20 22:20 ` David Lechner
  2025-06-22 15:00   ` Jonathan Cameron
                     ` (2 more replies)
  2025-06-20 22:20 ` [PATCH 9/9] iio: adc: ad7173: " David Lechner
  8 siblings, 3 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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       | 160 +++++++++++++++++++++++----------
 include/linux/iio/adc/ad_sigma_delta.h |  14 +++
 2 files changed, 129 insertions(+), 45 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index a9b97f5d4107a2e1bb74877d30403445e9b04a44..449b0756be96d3f864a6e7f070467ad7311bf7d5 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -14,11 +14,13 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/spi/offload/consumer.h>
 #include <linux/spi/spi.h>
 #include <linux/types.h>
 #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/sysfs.h>
@@ -460,8 +462,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;
 
@@ -489,23 +490,33 @@ 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 * scan_type->storagebits, 8);
-	samples_buf_size += sizeof(int64_t);
-	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);
-	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 * scan_type->storagebits, 8);
+		samples_buf_size += sizeof(int64_t);
+		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);
+
+		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) {
@@ -521,6 +532,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;
@@ -537,7 +550,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;
 
@@ -552,10 +577,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);
@@ -670,7 +700,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;
 	}
@@ -703,17 +734,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;
@@ -733,14 +753,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;
 }
@@ -760,12 +799,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);
 }
@@ -828,6 +884,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;
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] 25+ messages in thread

* [PATCH 9/9] iio: adc: ad7173: add SPI offload support
  2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
                   ` (7 preceding siblings ...)
  2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
@ 2025-06-20 22:20 ` David Lechner
  8 siblings, 0 replies; 25+ messages in thread
From: David Lechner @ 2025-06-20 22:20 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] 25+ messages in thread

* Re: [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes
  2025-06-20 22:20 ` [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes David Lechner
@ 2025-06-22 14:37   ` Jonathan Cameron
  2025-06-23  6:50     ` Andy Shevchenko
  0 siblings, 1 reply; 25+ messages in thread
From: Jonathan Cameron @ 2025-06-22 14:37 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, 20 Jun 2025 17:20:07 -0500
David Lechner <dlechner@baylibre.com> wrote:

> 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 4c5f8d29a559fea7226b84141bcb148fb801f62c..6cd3645eaaf38a23d5b6479ac598b6d276cfd81a 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>
Andy normally points this out (and may well do here) but in
general if we are tidying up headers we should try to drop includes
of kernel.h if favour of more specific headers.

Doesn't need to be in same patch as this one though!

This is trivial and correct as it stands and would want to be
done as a precursor to any actual changes anyway.

> +#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
>  
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
  2025-06-20 22:20 ` [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
@ 2025-06-22 14:39   ` Jonathan Cameron
  2025-06-23  6:54   ` Andy Shevchenko
  1 sibling, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2025-06-22 14:39 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, 20 Jun 2025 17:20:09 -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 once instance, we also avoid the temporary assignment to a variable

In one instance

(don't bother fixing that unless doing a v2 for some other reason)

> as it was confusing that reg_size was being used with two different
> units (bits and bytes).
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/adc/ad_sigma_delta.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 1657f64f1c0465b249adcc8a70dda8faf4a90565..fa792c800c80f960aca75b28a60cb2588e69fe7d 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)
>  	unsigned int size;
>  	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:
> @@ -552,9 +553,8 @@ 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(indio_dev->channels[0].scan_type.realbits +
> +				 indio_dev->channels[0].scan_type.shift);
>  
>  	if (sigma_delta->info->data_reg != 0)
>  		data_reg = sigma_delta->info->data_reg;
> @@ -616,7 +616,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(indio_dev->channels[0].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++;
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message()
  2025-06-20 22:20 ` [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
@ 2025-06-22 14:50   ` Jonathan Cameron
  2025-06-23  6:57   ` Andy Shevchenko
  1 sibling, 0 replies; 25+ messages in thread
From: Jonathan Cameron @ 2025-06-22 14:50 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, 20 Jun 2025 17:20:11 -0500
David Lechner <dlechner@baylibre.com> wrote:

> 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).
Nice.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
A query inline that is really about what the existing code is doing.
Also a request for duplicating the comment about extra padding as that
is unusual!

Jonathan

> ---
>  drivers/iio/adc/ad_sigma_delta.c       | 74 ++++++++++++++++------------------
>  include/linux/iio/adc/ad_sigma_delta.h |  3 ++
>  2 files changed, 38 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 883cc02d4099908644af523bcf66c0178fbd0e55..a9b97f5d4107a2e1bb74877d30403445e9b04a44 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -458,8 +458,10 @@ 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;
> +	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;
>  
> @@ -493,7 +495,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 * scan_type->storagebits, 8);

What is this doing?  Storage bits as the name suggests is in bits but this superficially
seems to be treating it like it was in bytes.

The ALIGN() is I think just about the timestamp alignment.


>  	samples_buf_size += sizeof(int64_t);
>  	samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
>  				    samples_buf_size, GFP_KERNEL);
> @@ -501,6 +503,27 @@ 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);
> +	xfer[1].rx_buf = &sigma_delta->rx_buf[scan_size == 3 ? 1 : 0];

This is black magic.  Comment needed I think on why the offset in rx_buf.

> +	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;
> @@ -520,6 +543,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,51 +577,20 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	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(indio_dev->channels[0].scan_type.realbits +
>  				 indio_dev->channels[0].scan_type.shift);
> +	/* For 24-bit data, there is an extra byte of padding. */
> +	status_pos = reg_size + (reg_size == 3 ? 1 : 0);

Ah. I guess this applies above as well.  I'd duplicate the comment.

>  
> -	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,
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
  2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
@ 2025-06-22 15:00   ` Jonathan Cameron
  2025-06-22 16:14     ` David Lechner
  2025-06-23 10:21   ` kernel test robot
  2025-06-23 13:55   ` kernel test robot
  2 siblings, 1 reply; 25+ messages in thread
From: Jonathan Cameron @ 2025-06-22 15:00 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, 20 Jun 2025 17:20:14 -0500
David Lechner <dlechner@baylibre.com> wrote:

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

A few queries inline that again are more about the original code than what
you change here.

Jonathan

> ---
>  drivers/iio/adc/ad_sigma_delta.c       | 160 +++++++++++++++++++++++----------
>  include/linux/iio/adc/ad_sigma_delta.h |  14 +++
>  2 files changed, 129 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index a9b97f5d4107a2e1bb74877d30403445e9b04a44..449b0756be96d3f864a6e7f070467ad7311bf7d5 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -14,11 +14,13 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/spi/offload/consumer.h>
>  #include <linux/spi/spi.h>
>  #include <linux/types.h>
>  #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/sysfs.h>
> @@ -460,8 +462,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;
>  
> @@ -489,23 +490,33 @@ 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 * scan_type->storagebits, 8);
> -	samples_buf_size += sizeof(int64_t);
> -	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);
> -	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 * scan_type->storagebits, 8);

The code I queried earlier is moved here, so make sure to carry through
any changes if it is indeed wrong!

> +		samples_buf_size += sizeof(int64_t);
> +		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);
> +
> +		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) {

> @@ -670,7 +700,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)

Is this defensive or can we actually get here with out a trigger?
I would have thought in the offload case (so no trigger here) we'd not call this
function at all.  Mind you, can't we get here with no trigger when doing
a calibration or simple read normally?  

> +			iio_trigger_poll(sigma_delta->trig);
>  
>  		return IRQ_HANDLED;
>  	}



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
  2025-06-22 15:00   ` Jonathan Cameron
@ 2025-06-22 16:14     ` David Lechner
  0 siblings, 0 replies; 25+ messages in thread
From: David Lechner @ 2025-06-22 16:14 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/22/25 10:00 AM, Jonathan Cameron wrote:
> On Fri, 20 Jun 2025 17:20:14 -0500
> David Lechner <dlechner@baylibre.com> wrote:
> 
>> Add SPI offload support to the ad_sigma_delta module.
>>

...

>> @@ -670,7 +700,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)
> 
> Is this defensive or can we actually get here with out a trigger?
> I would have thought in the offload case (so no trigger here) we'd not call this
> function at all.  Mind you, can't we get here with no trigger when doing
> a calibration or simple read normally?  

The difference is that with SPI offload, sigma_delta->trig is NULL
but without SPI offload, it is never NULL. iio_trigger_poll() doesn't
check for NULL and would crash with NULL pointer dereference.

During calibration and single conversion the poll function isn't
attached to the trigger, so I guess that is why it didn't really
hurt to call iio_trigger_poll() in that case.

> 
>> +			iio_trigger_poll(sigma_delta->trig);
>>  
>>  		return IRQ_HANDLED;
>>  	}
> 
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes
  2025-06-22 14:37   ` Jonathan Cameron
@ 2025-06-23  6:50     ` Andy Shevchenko
  0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2025-06-23  6:50 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 Sun, Jun 22, 2025 at 03:37:33PM +0100, Jonathan Cameron wrote:
> On Fri, 20 Jun 2025 17:20:07 -0500
> David Lechner <dlechner@baylibre.com> wrote:

...

> >  #include <linux/kernel.h>
> Andy normally points this out (and may well do here) but in
> general if we are tidying up headers we should try to drop includes
> of kernel.h if favour of more specific headers.
> 
> Doesn't need to be in same patch as this one though!
> 
> This is trivial and correct as it stands and would want to be
> done as a precursor to any actual changes anyway.

Yeah, kernel.h in the (leaf) drivers is a red flag to me.
But replacing it is out of scope of this patch and may be
done separately. My only point that please do it rather
sooner.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
  2025-06-20 22:20 ` [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
@ 2025-06-23  6:51   ` Andy Shevchenko
  2025-06-23 21:48     ` David Lechner
  0 siblings, 1 reply; 25+ messages in thread
From: Andy Shevchenko @ 2025-06-23  6:51 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 20, 2025 at 05:20:08PM -0500, David Lechner wrote:
> 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.

...

>  	unsigned int reset_length = sigma_delta->info->num_resetclks;
> -	uint8_t *buf;
> +	u8 *buf;
>  	unsigned int size;
>  	int ret;

Wondering if in the cases like this we may make it to be reversed xmas tree.

	unsigned int reset_length = sigma_delta->info->num_resetclks;
	unsigned int size;
	u8 *buf;
	int ret;

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
  2025-06-20 22:20 ` [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
  2025-06-22 14:39   ` Jonathan Cameron
@ 2025-06-23  6:54   ` Andy Shevchenko
  2025-06-27 23:36     ` David Lechner
  1 sibling, 1 reply; 25+ messages in thread
From: Andy Shevchenko @ 2025-06-23  6:54 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 20, 2025 at 05:20:09PM -0500, David Lechner 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 once 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).

...

> -	size = DIV_ROUND_UP(reset_length, 8);
> +	size = BITS_TO_BYTES(reset_length);
>  	buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
>  	if (!buf)
>  		return -ENOMEM;

Hmm... On the rough glance this sounds like some kind of bitmap
and hence bitmap_zalloc() (and other bitmap APIs), but I am not
sure.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message()
  2025-06-20 22:20 ` [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
  2025-06-22 14:50   ` Jonathan Cameron
@ 2025-06-23  6:57   ` Andy Shevchenko
  1 sibling, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2025-06-23  6:57 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 20, 2025 at 05:20:11PM -0500, David Lechner wrote:
> 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).

...

>  	samples_buf_size += sizeof(int64_t);

Missed conversion in the second patch?

I have done search for these as

	git grep -n 'u?int[0-9][0-9]?_t' -- $FILE(s)


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
  2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
  2025-06-22 15:00   ` Jonathan Cameron
@ 2025-06-23 10:21   ` kernel test robot
  2025-06-23 13:55   ` kernel test robot
  2 siblings, 0 replies; 25+ messages in thread
From: kernel test robot @ 2025-06-23 10:21 UTC (permalink / raw)
  To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Mark Brown
  Cc: oe-kbuild-all, linux-iio, linux-kernel, devicetree, linux-spi,
	David Lechner

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on d02f330b0c78bcf76643fbb7d3215a58b181f829]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/iio-adc-ad_sigma_delta-sort-includes/20250621-063127
base:   d02f330b0c78bcf76643fbb7d3215a58b181f829
patch link:    https://lore.kernel.org/r/20250620-iio-adc-ad7173-add-spi-offload-support-v1-8-0766f6297430%40baylibre.com
patch subject: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
config: x86_64-buildonly-randconfig-004-20250621 (https://download.01.org/0day-ci/archive/20250623/202506231738.CgeNexV4-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250623/202506231738.CgeNexV4-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506231738.CgeNexV4-lkp@intel.com/

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> WARNING: modpost: module ad_sigma_delta uses symbol devm_iio_dmaengine_buffer_setup_with_handle from namespace IIO_DMAENGINE_BUFFER, but does not import it.

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
  2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
  2025-06-22 15:00   ` Jonathan Cameron
  2025-06-23 10:21   ` kernel test robot
@ 2025-06-23 13:55   ` kernel test robot
  2 siblings, 0 replies; 25+ messages in thread
From: kernel test robot @ 2025-06-23 13:55 UTC (permalink / raw)
  To: David Lechner, Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Mark Brown
  Cc: oe-kbuild-all, linux-iio, linux-kernel, devicetree, linux-spi,
	David Lechner

Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on d02f330b0c78bcf76643fbb7d3215a58b181f829]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/iio-adc-ad_sigma_delta-sort-includes/20250621-063127
base:   d02f330b0c78bcf76643fbb7d3215a58b181f829
patch link:    https://lore.kernel.org/r/20250620-iio-adc-ad7173-add-spi-offload-support-v1-8-0766f6297430%40baylibre.com
patch subject: [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support
config: x86_64-buildonly-randconfig-001-20250621 (https://download.01.org/0day-ci/archive/20250623/202506232119.aLbzgQow-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250623/202506232119.aLbzgQow-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506232119.aLbzgQow-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: module ad_sigma_delta uses symbol devm_iio_dmaengine_buffer_setup_with_handle from namespace IIO_DMAENGINE_BUFFER, but does not import it.

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
  2025-06-23  6:51   ` Andy Shevchenko
@ 2025-06-23 21:48     ` David Lechner
  2025-06-24  7:20       ` Andy Shevchenko
  0 siblings, 1 reply; 25+ messages in thread
From: David Lechner @ 2025-06-23 21:48 UTC (permalink / raw)
  To: Andy Shevchenko
  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 Mon, Jun 23, 2025 at 12:51 AM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Fri, Jun 20, 2025 at 05:20:08PM -0500, David Lechner wrote:
> > 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.
>
> ...
>
> >       unsigned int reset_length = sigma_delta->info->num_resetclks;
> > -     uint8_t *buf;
> > +     u8 *buf;
> >       unsigned int size;
> >       int ret;
>
> Wondering if in the cases like this we may make it to be reversed xmas tree.

Fine with me as long as Jonathan doesn't mind the noise since it looks
like I will be doing a v2 anyway.

>
>         unsigned int reset_length = sigma_delta->info->num_resetclks;
>         unsigned int size;
>         u8 *buf;
>         int ret;
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t
  2025-06-23 21:48     ` David Lechner
@ 2025-06-24  7:20       ` Andy Shevchenko
  0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2025-06-24  7:20 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 Mon, Jun 23, 2025 at 03:48:30PM -0600, David Lechner wrote:
> On Mon, Jun 23, 2025 at 12:51 AM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Fri, Jun 20, 2025 at 05:20:08PM -0500, David Lechner wrote:
> > > Replace uint8_t with u8 in the ad_sigma_delta driver.

...

> > >       unsigned int reset_length = sigma_delta->info->num_resetclks;
> > > -     uint8_t *buf;
> > > +     u8 *buf;
> > >       unsigned int size;
> > >       int ret;
> >
> > Wondering if in the cases like this we may make it to be reversed xmas tree.
> 
> Fine with me as long as Jonathan doesn't mind the noise since it looks
> like I will be doing a v2 anyway.

I mean the cases when you touch already the variables and this won't be any
*additional* churn to what the change has.

> >         unsigned int reset_length = sigma_delta->info->num_resetclks;
> >         unsigned int size;
> >         u8 *buf;
> >         int ret;

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI
  2025-06-20 22:20 ` [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
@ 2025-06-27 19:59   ` Rob Herring (Arm)
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring (Arm) @ 2025-06-27 19:59 UTC (permalink / raw)
  To: David Lechner
  Cc: Michael Hennerich, Mark Brown, linux-kernel, devicetree,
	Andy Shevchenko, Jonathan Cameron, Krzysztof Kozlowski, linux-spi,
	Conor Dooley, linux-iio, Nuno Sá


On Fri, 20 Jun 2025 17:20:12 -0500, David Lechner wrote:
> 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.
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  .../trigger-source/adi,util-sigma-delta-spi.yaml   | 49 ++++++++++++++++++++++
>  MAINTAINERS                                        |  5 +++
>  2 files changed, 54 insertions(+)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
  2025-06-23  6:54   ` Andy Shevchenko
@ 2025-06-27 23:36     ` David Lechner
  0 siblings, 0 replies; 25+ messages in thread
From: David Lechner @ 2025-06-27 23:36 UTC (permalink / raw)
  To: Andy Shevchenko
  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 6/23/25 1:54 AM, Andy Shevchenko wrote:
> On Fri, Jun 20, 2025 at 05:20:09PM -0500, David Lechner 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 once 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).
> 
> ...
> 
>> -	size = DIV_ROUND_UP(reset_length, 8);
>> +	size = BITS_TO_BYTES(reset_length);
>>  	buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
>>  	if (!buf)
>>  		return -ENOMEM;
> 
> Hmm... On the rough glance this sounds like some kind of bitmap
> and hence bitmap_zalloc() (and other bitmap APIs), but I am not
> sure.
> 

I looked at it, but I don't think it is worth changing. It is
really counting clock cycles, not bits.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2025-06-27 23:36 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 22:20 [PATCH 0/9] iio: adc: ad7173: add SPI offload support David Lechner
2025-06-20 22:20 ` [PATCH 1/9] iio: adc: ad_sigma_delta: sort includes David Lechner
2025-06-22 14:37   ` Jonathan Cameron
2025-06-23  6:50     ` Andy Shevchenko
2025-06-20 22:20 ` [PATCH 2/9] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
2025-06-23  6:51   ` Andy Shevchenko
2025-06-23 21:48     ` David Lechner
2025-06-24  7:20       ` Andy Shevchenko
2025-06-20 22:20 ` [PATCH 3/9] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro David Lechner
2025-06-22 14:39   ` Jonathan Cameron
2025-06-23  6:54   ` Andy Shevchenko
2025-06-27 23:36     ` David Lechner
2025-06-20 22:20 ` [PATCH 4/9] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
2025-06-20 22:20 ` [PATCH 5/9] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
2025-06-22 14:50   ` Jonathan Cameron
2025-06-23  6:57   ` Andy Shevchenko
2025-06-20 22:20 ` [PATCH 6/9] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
2025-06-27 19:59   ` Rob Herring (Arm)
2025-06-20 22:20 ` [PATCH 7/9] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
2025-06-20 22:20 ` [PATCH 8/9] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
2025-06-22 15:00   ` Jonathan Cameron
2025-06-22 16:14     ` David Lechner
2025-06-23 10:21   ` kernel test robot
2025-06-23 13:55   ` kernel test robot
2025-06-20 22:20 ` [PATCH 9/9] iio: adc: ad7173: " David Lechner

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).