* [PATCH 0/3] iio: ad7606: add SPI offload support
@ 2025-04-03 16:19 Angelo Dureghello
2025-04-03 16:19 ` [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties Angelo Dureghello
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-03 16:19 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
David Lechner
Cc: Michael Hennerich, linux-iio, devicetree, linux-kernel, linux-doc,
Angelo Dureghello
Add SPI offload support for the ad7606 ADC.
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
Angelo Dureghello (3):
dt-bindings: iio: adc: adi,ad7606: add SPI offload properties
doc: iio: ad7606: describe offload support
iio: adc: ad7606: add SPI offload support
.../devicetree/bindings/iio/adc/adi,ad7606.yaml | 8 +
Documentation/iio/ad7606.rst | 45 +++++
drivers/iio/adc/Kconfig | 2 +
drivers/iio/adc/ad7606.c | 50 ++++-
drivers/iio/adc/ad7606.h | 12 ++
drivers/iio/adc/ad7606_spi.c | 210 +++++++++++++++++++++
include/dt-bindings/iio/adc/adi,ad7606.h | 9 +
7 files changed, 326 insertions(+), 10 deletions(-)
---
base-commit: 8f159ea5a253d40682e041daec007933d6caf01b
change-id: 20250403-wip-bl-spi-offload-ad7606-cfd992d286a4
Best regards,
--
Angelo Dureghello <adureghello@baylibre.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties
2025-04-03 16:19 [PATCH 0/3] iio: ad7606: add SPI offload support Angelo Dureghello
@ 2025-04-03 16:19 ` Angelo Dureghello
2025-04-07 13:21 ` Rob Herring (Arm)
2025-04-03 16:19 ` [PATCH 2/3] doc: iio: ad7606: describe offload support Angelo Dureghello
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-03 16:19 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
David Lechner
Cc: Michael Hennerich, linux-iio, devicetree, linux-kernel, linux-doc,
Angelo Dureghello
From: Angelo Dureghello <adureghello@baylibre.com>
Add #trigger-source-cells property to allow the BUSY output to be
used as a SPI offload trigger source to indicate when a sample is ready
to be read.
Macros are added to adi,ad7606.h for the cell values to help with
readability since they are arbitrary values.
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 8 ++++++++
include/dt-bindings/iio/adc/adi,ad7606.h | 9 +++++++++
2 files changed, 17 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
index 52d3f1ce336783084d601d361779ebc766124f7a..29f12d650442b8ff2eb455306ce59a0e87867ddd 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml
@@ -45,6 +45,14 @@ properties:
"#size-cells":
const: 0
+ '#trigger-source-cells':
+ description: |
+ Cell indicates the output signal: 0 = BUSY, 1 = FIRSTDATA.
+
+ For convenience, macros for these values are available in
+ dt-bindings/iio/adc/adi,ad7606.h.
+ const: 1
+
# According to the datasheet, "Data is clocked in from SDI on the falling
# edge of SCLK, while data is clocked out on DOUTA on the rising edge of
# SCLK". Also, even if not stated textually in the datasheet, it is made
diff --git a/include/dt-bindings/iio/adc/adi,ad7606.h b/include/dt-bindings/iio/adc/adi,ad7606.h
new file mode 100644
index 0000000000000000000000000000000000000000..f38a6d72b6dc2d4067c07d6a5c0377e526219e5c
--- /dev/null
+++ b/include/dt-bindings/iio/adc/adi,ad7606.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+
+#ifndef _DT_BINDINGS_ADI_AD7606_H
+#define _DT_BINDINGS_ADI_AD7606_H
+
+#define AD7606_TRIGGER_EVENT_BUSY 0
+#define AD7606_TRIGGER_EVENT_FRSTDATA 1
+
+#endif /* _DT_BINDINGS_ADI_AD7606_H */
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/3] doc: iio: ad7606: describe offload support
2025-04-03 16:19 [PATCH 0/3] iio: ad7606: add SPI offload support Angelo Dureghello
2025-04-03 16:19 ` [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties Angelo Dureghello
@ 2025-04-03 16:19 ` Angelo Dureghello
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
2025-04-03 16:48 ` [PATCH 0/3] iio: " David Lechner
3 siblings, 0 replies; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-03 16:19 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
David Lechner
Cc: Michael Hennerich, linux-iio, devicetree, linux-kernel, linux-doc,
Angelo Dureghello
From: Angelo Dureghello <adureghello@baylibre.com>
Add a section to the ad7606 documentation describing how to use the
driver with SPI offloading.
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
Documentation/iio/ad7606.rst | 45 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/Documentation/iio/ad7606.rst b/Documentation/iio/ad7606.rst
index 930199e03c67f68296ec83176f9e4f82741fb813..5e02516bab406b6b13d2ebd13a33433e3e86d943 100644
--- a/Documentation/iio/ad7606.rst
+++ b/Documentation/iio/ad7606.rst
@@ -26,6 +26,35 @@ SPI wiring modes
These ADCs can output data on several SDO lines (1/2/4/8). The driver
currently supports only 1 SDO line.
+SPI offload wiring
+------------------
+When used with a SPI offload, the supported wiring configuration is:
+
+.. code-block::
+
+ +-------------+ +-------------+
+ | BUSY |-------->| TRIGGER |
+ | CS |<--------| CS |
+ | | | |
+ | ADC | | SPI |
+ | | | |
+ | SDI |<--------| SDO |
+ | DOUTA |-------->| SDI |
+ | SCLK |<--------| SCLK |
+ | | | |
+ | | +-------------+
+ | CONVST |<--------| PWM |
+ +-------------+ +-------------+
+
+In this case, the ``pwms`` property is required.
+The ``#trigger-source-cells = <1>`` property is also required to connect back
+to the SPI offload. The SPI offload will have ``trigger-sources`` property
+with a cell to indicate the busy signal:
+``<&ad7606 AD4695_TRIGGER_EVENT_BUSY>``.
+
+.. seealso:: `SPI offload support`_
+
+
Parallel wiring mode
--------------------
@@ -123,6 +152,22 @@ Unimplemented features
- CRC indication
- Calibration
+SPI offload support
+===================
+
+To be able to achieve the maximum sample rate, the driver can be used with the
+`AXI SPI Engine`_ to provide SPI offload support.
+
+.. _AXI SPI Engine: https://analogdevicesinc.github.io/hdl/library/spi_engine/index.html
+
+When SPI offload is being used, some attributes will be different.
+
+* ``trigger`` directory is removed.
+* ``sampling_frequency`` attribute is added for setting the sample rate.
+* ``timestamp`` channel is removed.
+* Buffer data format may be different compared to when offload is not used,
+ e.g. the ``in_voltage0_type`` attribute.
+
Device buffers
==============
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-03 16:19 [PATCH 0/3] iio: ad7606: add SPI offload support Angelo Dureghello
2025-04-03 16:19 ` [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties Angelo Dureghello
2025-04-03 16:19 ` [PATCH 2/3] doc: iio: ad7606: describe offload support Angelo Dureghello
@ 2025-04-03 16:19 ` Angelo Dureghello
2025-04-05 15:40 ` Jonathan Cameron
` (2 more replies)
2025-04-03 16:48 ` [PATCH 0/3] iio: " David Lechner
3 siblings, 3 replies; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-03 16:19 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
David Lechner
Cc: Michael Hennerich, linux-iio, devicetree, linux-kernel, linux-doc,
Angelo Dureghello
From: Angelo Dureghello <adureghello@baylibre.com>
Add SPI offload support for this family.
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
drivers/iio/adc/Kconfig | 2 +
drivers/iio/adc/ad7606.c | 50 ++++++++---
drivers/iio/adc/ad7606.h | 12 +++
drivers/iio/adc/ad7606_spi.c | 210 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 264 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 859c77f40f1d1893d0fc92212ad538150f0992c8..df90db609f683217cffaeb605aa9b6f022cf2b9b 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -284,6 +284,8 @@ config AD7606_IFACE_SPI
tristate "Analog Devices AD7606 ADC driver with spi interface support"
depends on SPI
select AD7606
+ select IIO_BUFFER_DMAENGINE
+ select SPI_OFFLOAD
help
Say yes here to build spi interface support for Analog Devices:
ad7605-4, ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 843c30fddc7346d0dec7d791e26ca16e2c1ea0cf..aa6ae2c1b06acfa5d38229827e37fed1c2f82870 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -138,6 +138,7 @@ const struct ad7606_chip_info ad7606_6_info = {
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7606_16bit_chan_scale_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7606_6_info, "IIO_AD7606");
@@ -149,6 +150,7 @@ const struct ad7606_chip_info ad7606_4_info = {
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7606_16bit_chan_scale_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7606_4_info, "IIO_AD7606");
@@ -161,6 +163,7 @@ const struct ad7606_chip_info ad7606b_info = {
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7606_16bit_chan_scale_setup,
.sw_setup_cb = ad7606b_sw_mode_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7606b_info, "IIO_AD7606");
@@ -173,6 +176,7 @@ const struct ad7606_chip_info ad7606c_16_info = {
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7606c_16bit_chan_scale_setup,
.sw_setup_cb = ad7606b_sw_mode_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7606c_16_info, "IIO_AD7606");
@@ -184,6 +188,7 @@ const struct ad7606_chip_info ad7607_info = {
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7607_chan_scale_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7607_info, "IIO_AD7606");
@@ -195,6 +200,7 @@ const struct ad7606_chip_info ad7608_info = {
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7608_chan_scale_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7608_info, "IIO_AD7606");
@@ -206,6 +212,7 @@ const struct ad7606_chip_info ad7609_info = {
.oversampling_avail = ad7606_oversampling_avail,
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7609_chan_scale_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7609_info, "IIO_AD7606");
@@ -218,6 +225,7 @@ const struct ad7606_chip_info ad7606c_18_info = {
.oversampling_num = ARRAY_SIZE(ad7606_oversampling_avail),
.scale_setup_cb = ad7606c_18bit_chan_scale_setup,
.sw_setup_cb = ad7606b_sw_mode_setup,
+ .offload_storagebits = 32,
};
EXPORT_SYMBOL_NS_GPL(ad7606c_18_info, "IIO_AD7606");
@@ -232,6 +240,7 @@ const struct ad7606_chip_info ad7616_info = {
.os_req_reset = true,
.scale_setup_cb = ad7606_16bit_chan_scale_setup,
.sw_setup_cb = ad7616_sw_mode_setup,
+ .offload_storagebits = 16,
};
EXPORT_SYMBOL_NS_GPL(ad7616_info, "IIO_AD7606");
@@ -514,7 +523,7 @@ static int ad7606_pwm_set_high(struct ad7606_state *st)
return ret;
}
-static int ad7606_pwm_set_low(struct ad7606_state *st)
+int ad7606_pwm_set_low(struct ad7606_state *st)
{
struct pwm_state cnvst_pwm_state;
int ret;
@@ -527,8 +536,9 @@ static int ad7606_pwm_set_low(struct ad7606_state *st)
return ret;
}
+EXPORT_SYMBOL_NS_GPL(ad7606_pwm_set_low, "IIO_AD7606");
-static int ad7606_pwm_set_swing(struct ad7606_state *st)
+int ad7606_pwm_set_swing(struct ad7606_state *st)
{
struct pwm_state cnvst_pwm_state;
@@ -538,6 +548,7 @@ static int ad7606_pwm_set_swing(struct ad7606_state *st)
return pwm_apply_might_sleep(st->cnvst_pwm, &cnvst_pwm_state);
}
+EXPORT_SYMBOL_NS_GPL(ad7606_pwm_set_swing, "IIO_AD7606");
static bool ad7606_pwm_is_swinging(struct ad7606_state *st)
{
@@ -626,7 +637,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
* will not happen because IIO_CHAN_INFO_RAW is not supported for the backend.
* TODO: Add support for reading a single value when the backend is used.
*/
- if (!st->back) {
+ if (st->trig) {
ret = wait_for_completion_timeout(&st->completion,
msecs_to_jiffies(1000));
if (!ret) {
@@ -634,7 +645,12 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
goto error_ret;
}
} else {
- fsleep(1);
+ /*
+ * If the BUSY interrupt is not available, wait enough time for
+ * the longest possible conversion (max for the whole family is
+ * around 350us).
+ */
+ fsleep(400);
}
ret = ad7606_read_samples(st);
@@ -1201,7 +1217,7 @@ static int ad7606_probe_channels(struct iio_dev *indio_dev)
bool slow_bus;
int ret, i;
- slow_bus = !st->bops->iio_backend_config;
+ slow_bus = !(st->bops->iio_backend_config || st->offload_en);
indio_dev->num_channels = st->chip_info->num_adc_channels;
/* Slow buses also get 1 more channel for soft timestamp */
@@ -1222,7 +1238,14 @@ static int ad7606_probe_channels(struct iio_dev *indio_dev)
chan->scan_index = i;
chan->scan_type.sign = 's';
chan->scan_type.realbits = st->chip_info->bits;
- chan->scan_type.storagebits = st->chip_info->bits > 16 ? 32 : 16;
+ /*
+ * If in SPI offload mode, storagebits are set based
+ * on the spi-engine hw implementation.
+ */
+ chan->scan_type.storagebits = st->offload_en ?
+ st->chip_info->offload_storagebits :
+ (st->chip_info->bits > 16 ? 32 : 16);
+
chan->scan_type.endianness = IIO_CPU;
if (indio_dev->modes & INDIO_DIRECT_MODE)
@@ -1340,6 +1363,13 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
indio_dev->modes = st->bops->iio_backend_config ? 0 : INDIO_DIRECT_MODE;
indio_dev->name = chip_info->name;
+ /* Using spi-engine with offload support ? */
+ if (st->bops->offload_config) {
+ ret = st->bops->offload_config(dev, indio_dev);
+ if (ret)
+ return ret;
+ }
+
ret = ad7606_probe_channels(indio_dev);
if (ret)
return ret;
@@ -1355,7 +1385,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
}
/* If convst pin is not defined, setup PWM. */
- if (!st->gpio_convst) {
+ if (!st->gpio_convst || st->offload_en) {
st->cnvst_pwm = devm_pwm_get(dev, NULL);
if (IS_ERR(st->cnvst_pwm))
return PTR_ERR(st->cnvst_pwm);
@@ -1394,8 +1424,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
return ret;
indio_dev->setup_ops = &ad7606_backend_buffer_ops;
- } else {
-
+ } else if (!st->offload_en) {
/* Reserve the PWM use only for backend (force gpio_convst definition) */
if (!st->gpio_convst)
return dev_err_probe(dev, -EINVAL,
@@ -1433,7 +1462,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
st->write_scale = ad7606_write_scale_hw;
st->write_os = ad7606_write_os_hw;
- if (st->sw_mode_en) {
+ /* Offload needs 1 DOUT line, applying this setting in sw_setup_cb. */
+ if (st->sw_mode_en || st->offload_en) {
indio_dev->info = &ad7606_info_sw_mode;
st->chip_info->sw_setup_cb(indio_dev);
}
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index f0b262fb4554f0bf244338c98ca585143321d616..89d49551eaf515bab9706c12bff056dfcb707b67 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -60,6 +60,7 @@ typedef int (*ad7606_sw_setup_cb_t)(struct iio_dev *indio_dev);
* @os_req_reset: some devices require a reset to update oversampling
* @init_delay_ms: required delay in milliseconds for initialization
* after a restart
+ * @offload_storagebits: storage bits used by the offload hw implementation
*/
struct ad7606_chip_info {
unsigned int max_samplerate;
@@ -72,6 +73,7 @@ struct ad7606_chip_info {
unsigned int oversampling_num;
bool os_req_reset;
unsigned long init_delay_ms;
+ u8 offload_storagebits;
};
/**
@@ -118,6 +120,8 @@ struct ad7606_chan_scale {
* @trig: The IIO trigger associated with the device.
* @completion: completion to indicate end of conversion
* @data: buffer for reading data from the device
+ * @offload_en: SPI offload enabled
+ * @bus_data: bus-specific variables
* @d16: be16 buffer for reading data from the device
*/
struct ad7606_state {
@@ -145,6 +149,9 @@ struct ad7606_state {
struct iio_trigger *trig;
struct completion completion;
+ bool offload_en;
+ void *bus_data;
+
/*
* DMA (thus cache coherency maintenance) may require the
* transfer buffers to live in their own cache lines.
@@ -165,6 +172,8 @@ struct ad7606_state {
* @read_block: function pointer for reading blocks of data
* @sw_mode_config: pointer to a function which configured the device
* for software mode
+ * @offload_config: function pointer for configuring offload support,
+ * where any
* @reg_read: function pointer for reading spi register
* @reg_write: function pointer for writing spi register
* @update_scan_mode: function pointer for handling the calls to iio_info's
@@ -174,6 +183,7 @@ struct ad7606_state {
struct ad7606_bus_ops {
/* more methods added in future? */
int (*iio_backend_config)(struct device *dev, struct iio_dev *indio_dev);
+ int (*offload_config)(struct device *dev, struct iio_dev *indio_dev);
int (*read_block)(struct device *dev, int num, void *data);
int (*sw_mode_config)(struct iio_dev *indio_dev);
int (*reg_read)(struct ad7606_state *st, unsigned int addr);
@@ -199,6 +209,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
const struct ad7606_bus_ops *bops);
int ad7606_reset(struct ad7606_state *st);
+int ad7606_pwm_set_swing(struct ad7606_state *st);
+int ad7606_pwm_set_low(struct ad7606_state *st);
extern const struct ad7606_chip_info ad7605_4_info;
extern const struct ad7606_chip_info ad7606_8_info;
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
index b2b975fb7fea4d1af6caef59e75ca495501bc140..b086122497eb22042171580878160334f56baa23 100644
--- a/drivers/iio/adc/ad7606_spi.c
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -6,15 +6,31 @@
*/
#include <linux/err.h>
+#include <linux/math.h>
#include <linux/module.h>
+#include <linux/pwm.h>
+#include <linux/spi/offload/consumer.h>
+#include <linux/spi/offload/provider.h>
#include <linux/spi/spi.h>
#include <linux/types.h>
+#include <linux/units.h>
+#include <linux/iio/buffer-dmaengine.h>
#include <linux/iio/iio.h>
+
+#include <dt-bindings/iio/adc/adi,ad7606.h>
+
#include "ad7606.h"
#define MAX_SPI_FREQ_HZ 23500000 /* VDRIVE above 4.75 V */
+struct spi_bus_data {
+ struct spi_offload *offload;
+ struct spi_offload_trigger *offload_trigger;
+ struct spi_transfer offload_xfer;
+ struct spi_message offload_msg;
+};
+
static u16 ad7616_spi_rd_wr_cmd(int addr, char is_write_op)
{
/*
@@ -125,19 +141,211 @@ static int ad7606b_sw_mode_config(struct iio_dev *indio_dev)
AD7606_SINGLE_DOUT);
}
+static const struct spi_offload_config ad7606_spi_offload_config = {
+ .capability_flags = SPI_OFFLOAD_CAP_TRIGGER |
+ SPI_OFFLOAD_CAP_RX_STREAM_DMA,
+};
+
+static int ad7606_spi_offload_buffer_postenable(struct iio_dev *indio_dev)
+{
+ const struct iio_scan_type *scan_type;
+ struct ad7606_state *st = iio_priv(indio_dev);
+ struct spi_bus_data *bus_data = st->bus_data;
+ struct spi_transfer *xfer = &bus_data->offload_xfer;
+ struct spi_device *spi = to_spi_device(st->dev);
+ struct spi_offload_trigger_config config = {
+ .type = SPI_OFFLOAD_TRIGGER_DATA_READY,
+ };
+ int ret;
+
+ scan_type = &indio_dev->channels[0].scan_type;
+
+ xfer->bits_per_word = scan_type->realbits;
+ xfer->offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
+ /*
+ * Using SPI offload, storagebits are related to the spi-engine
+ * hw implementation, can be 16 or 32, so can't be used to compute
+ * struct spi_transfer.len. Using realbits instead.
+ */
+ xfer->len = (scan_type->realbits > 16 ? 4 : 2) *
+ st->chip_info->num_adc_channels;
+
+ spi_message_init_with_transfers(&bus_data->offload_msg, xfer, 1);
+ bus_data->offload_msg.offload = bus_data->offload;
+
+ ret = spi_optimize_message(spi, &bus_data->offload_msg);
+ if (ret) {
+ dev_err(st->dev, "failed to prepare offload, err: %d\n", ret);
+ return ret;
+ }
+
+ ret = spi_offload_trigger_enable(bus_data->offload,
+ bus_data->offload_trigger,
+ &config);
+ if (ret)
+ goto err_unoptimize_message;
+
+ ret = ad7606_pwm_set_swing(st);
+ if (ret)
+ goto err_offload_exit_conversion_mode;
+
+ return 0;
+
+err_offload_exit_conversion_mode:
+ spi_offload_trigger_disable(bus_data->offload,
+ bus_data->offload_trigger);
+
+err_unoptimize_message:
+ spi_unoptimize_message(&bus_data->offload_msg);
+
+ return ret;
+}
+
+static int ad7606_spi_offload_buffer_predisable(struct iio_dev *indio_dev)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ struct spi_bus_data *bus_data = st->bus_data;
+ int ret;
+
+ ret = ad7606_pwm_set_low(st);
+ if (ret)
+ return ret;
+
+ spi_offload_trigger_disable(bus_data->offload,
+ bus_data->offload_trigger);
+ spi_unoptimize_message(&bus_data->offload_msg);
+
+ return 0;
+}
+
+static const struct iio_buffer_setup_ops ad7606_offload_buffer_setup_ops = {
+ .postenable = ad7606_spi_offload_buffer_postenable,
+ .predisable = ad7606_spi_offload_buffer_predisable,
+};
+
+static bool ad7606_spi_offload_trigger_match(
+ struct spi_offload_trigger *trigger,
+ enum spi_offload_trigger_type type,
+ u64 *args, u32 nargs)
+{
+ if (type != SPI_OFFLOAD_TRIGGER_DATA_READY)
+ return false;
+
+ /*
+ * Requires 1 arg:
+ * args[0] is the trigger event.
+ */
+ if (nargs != 1 || args[0] != AD7606_TRIGGER_EVENT_BUSY)
+ return false;
+
+ return true;
+}
+
+static int ad7606_spi_offload_trigger_request(
+ struct spi_offload_trigger *trigger,
+ enum spi_offload_trigger_type type,
+ u64 *args, u32 nargs)
+{
+ /* Should already be validated by match, but just in case. */
+ if (nargs != 1)
+ return -EINVAL;
+
+ return 0;
+}
+
+static int ad7606_spi_offload_trigger_validate(
+ struct spi_offload_trigger *trigger,
+ struct spi_offload_trigger_config *config)
+{
+ if (config->type != SPI_OFFLOAD_TRIGGER_DATA_READY)
+ return -EINVAL;
+
+ return 0;
+}
+
+static const struct spi_offload_trigger_ops ad7606_offload_trigger_ops = {
+ .match = ad7606_spi_offload_trigger_match,
+ .request = ad7606_spi_offload_trigger_request,
+ .validate = ad7606_spi_offload_trigger_validate,
+};
+
+static int ad7606_spi_offload_probe(struct device *dev,
+ struct iio_dev *indio_dev)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ struct spi_device *spi = to_spi_device(dev);
+ struct spi_bus_data *bus_data;
+ struct dma_chan *rx_dma;
+ struct spi_offload_trigger_info trigger_info = {
+ .fwnode = dev_fwnode(dev),
+ .ops = &ad7606_offload_trigger_ops,
+ .priv = st,
+ };
+ int ret;
+
+ bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
+ if (!bus_data)
+ return -ENOMEM;
+ st->bus_data = bus_data;
+
+ bus_data->offload = devm_spi_offload_get(dev, spi,
+ &ad7606_spi_offload_config);
+ ret = PTR_ERR_OR_ZERO(bus_data->offload);
+ if (ret && ret != -ENODEV)
+ return dev_err_probe(dev, ret, "failed to get SPI offload\n");
+ /* Allow main ad7606_probe function to continue. */
+ if (ret == -ENODEV)
+ return 0;
+
+ ret = devm_spi_offload_trigger_register(dev, &trigger_info);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to register offload trigger\n");
+
+ bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
+ bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
+ if (IS_ERR(bus_data->offload_trigger))
+ return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
+ "failed to get offload trigger\n");
+
+ /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
+ rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
+ bus_data->offload);
+ if (IS_ERR(rx_dma))
+ return dev_err_probe(dev, PTR_ERR(rx_dma),
+ "failed to get offload RX DMA\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, PTR_ERR(rx_dma),
+ "failed to setup offload RX DMA\n");
+
+ /* Use offload ops. */
+ indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
+
+ st->offload_en = true;
+
+ return 0;
+}
+
static const struct ad7606_bus_ops ad7606_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block,
};
static const struct ad7606_bus_ops ad7607_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block14to16,
};
static const struct ad7606_bus_ops ad7608_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block18to32,
};
static const struct ad7606_bus_ops ad7616_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block,
.reg_read = ad7606_spi_reg_read,
.reg_write = ad7606_spi_reg_write,
@@ -145,6 +353,7 @@ static const struct ad7606_bus_ops ad7616_spi_bops = {
};
static const struct ad7606_bus_ops ad7606b_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block,
.reg_read = ad7606_spi_reg_read,
.reg_write = ad7606_spi_reg_write,
@@ -153,6 +362,7 @@ static const struct ad7606_bus_ops ad7606b_spi_bops = {
};
static const struct ad7606_bus_ops ad7606c_18_spi_bops = {
+ .offload_config = ad7606_spi_offload_probe,
.read_block = ad7606_spi_read_block18to32,
.reg_read = ad7606_spi_reg_read,
.reg_write = ad7606_spi_reg_write,
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3] iio: ad7606: add SPI offload support
2025-04-03 16:19 [PATCH 0/3] iio: ad7606: add SPI offload support Angelo Dureghello
` (2 preceding siblings ...)
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
@ 2025-04-03 16:48 ` David Lechner
2025-04-07 18:55 ` Jonathan Cameron
3 siblings, 1 reply; 12+ messages in thread
From: David Lechner @ 2025-04-03 16:48 UTC (permalink / raw)
To: Angelo Dureghello, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Jonathan Corbet
Cc: linux-iio, devicetree, linux-kernel, linux-doc
On 4/3/25 11:19 AM, Angelo Dureghello wrote:
> Add SPI offload support for the ad7606 ADC.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
@ 2025-04-05 15:40 ` Jonathan Cameron
2025-04-07 7:41 ` Angelo Dureghello
2025-04-07 18:58 ` Jonathan Cameron
2025-04-14 18:24 ` Jonathan Cameron
2 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2025-04-05 15:40 UTC (permalink / raw)
To: Angelo Dureghello
Cc: Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, David Lechner,
linux-iio, devicetree, linux-kernel, linux-doc
On Thu, 03 Apr 2025 18:19:06 +0200
Angelo Dureghello <adureghello@baylibre.com> wrote:
> From: Angelo Dureghello <adureghello@baylibre.com>
>
> Add SPI offload support for this family.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Hi Angelo,
Code looks fine, but there is a TODO I'd like to know more about
as it sounds 'ominous'.
Otherwise this needs a dt review for patch 1 before I queue it up.
Jonathan
> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> index b2b975fb7fea4d1af6caef59e75ca495501bc140..b086122497eb22042171580878160334f56baa23 100644
> --- a/drivers/iio/adc/ad7606_spi.c
> +++ b/drivers/iio/adc/ad7606_spi.c
> +static int ad7606_spi_offload_probe(struct device *dev,
> + struct iio_dev *indio_dev)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + struct spi_device *spi = to_spi_device(dev);
> + struct spi_bus_data *bus_data;
> + struct dma_chan *rx_dma;
> + struct spi_offload_trigger_info trigger_info = {
> + .fwnode = dev_fwnode(dev),
> + .ops = &ad7606_offload_trigger_ops,
> + .priv = st,
> + };
> + int ret;
> +
> + bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
> + if (!bus_data)
> + return -ENOMEM;
> + st->bus_data = bus_data;
> +
> + bus_data->offload = devm_spi_offload_get(dev, spi,
> + &ad7606_spi_offload_config);
> + ret = PTR_ERR_OR_ZERO(bus_data->offload);
> + if (ret && ret != -ENODEV)
> + return dev_err_probe(dev, ret, "failed to get SPI offload\n");
> + /* Allow main ad7606_probe function to continue. */
> + if (ret == -ENODEV)
> + return 0;
> +
> + ret = devm_spi_offload_trigger_register(dev, &trigger_info);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to register offload trigger\n");
> +
> + bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
> + bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
> + if (IS_ERR(bus_data->offload_trigger))
> + return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
> + "failed to get offload trigger\n");
> +
> + /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
I don't understand this todo. Perhaps some more details?
> + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
> + bus_data->offload);
> + if (IS_ERR(rx_dma))
> + return dev_err_probe(dev, PTR_ERR(rx_dma),
> + "failed to get offload RX DMA\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, PTR_ERR(rx_dma),
> + "failed to setup offload RX DMA\n");
> +
> + /* Use offload ops. */
> + indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
> +
> + st->offload_en = true;
> +
> + return 0;
> +}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-05 15:40 ` Jonathan Cameron
@ 2025-04-07 7:41 ` Angelo Dureghello
0 siblings, 0 replies; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-07 7:41 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, David Lechner,
linux-iio, devicetree, linux-kernel, linux-doc
Hi Jonathan,
On 05.04.2025 16:40, Jonathan Cameron wrote:
> On Thu, 03 Apr 2025 18:19:06 +0200
> Angelo Dureghello <adureghello@baylibre.com> wrote:
>
> > From: Angelo Dureghello <adureghello@baylibre.com>
> >
> > Add SPI offload support for this family.
> >
> > Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> Hi Angelo,
>
> Code looks fine, but there is a TODO I'd like to know more about
> as it sounds 'ominous'.
>
> Otherwise this needs a dt review for patch 1 before I queue it up.
>
> Jonathan
> > diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> > index b2b975fb7fea4d1af6caef59e75ca495501bc140..b086122497eb22042171580878160334f56baa23 100644
> > --- a/drivers/iio/adc/ad7606_spi.c
> > +++ b/drivers/iio/adc/ad7606_spi.c
>
> > +static int ad7606_spi_offload_probe(struct device *dev,
> > + struct iio_dev *indio_dev)
> > +{
> > + struct ad7606_state *st = iio_priv(indio_dev);
> > + struct spi_device *spi = to_spi_device(dev);
> > + struct spi_bus_data *bus_data;
> > + struct dma_chan *rx_dma;
> > + struct spi_offload_trigger_info trigger_info = {
> > + .fwnode = dev_fwnode(dev),
> > + .ops = &ad7606_offload_trigger_ops,
> > + .priv = st,
> > + };
> > + int ret;
> > +
> > + bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
> > + if (!bus_data)
> > + return -ENOMEM;
> > + st->bus_data = bus_data;
> > +
> > + bus_data->offload = devm_spi_offload_get(dev, spi,
> > + &ad7606_spi_offload_config);
> > + ret = PTR_ERR_OR_ZERO(bus_data->offload);
> > + if (ret && ret != -ENODEV)
> > + return dev_err_probe(dev, ret, "failed to get SPI offload\n");
> > + /* Allow main ad7606_probe function to continue. */
> > + if (ret == -ENODEV)
> > + return 0;
> > +
> > + ret = devm_spi_offload_trigger_register(dev, &trigger_info);
> > + if (ret)
> > + return dev_err_probe(dev, ret,
> > + "failed to register offload trigger\n");
> > +
> > + bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
> > + bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
> > + if (IS_ERR(bus_data->offload_trigger))
> > + return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
> > + "failed to get offload trigger\n");
> > +
> > + /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
>
> I don't understand this todo. Perhaps some more details?
>
it was just an initial comment i did, when i started the things
was not clear.
Let me know if you can remove it, or i can send a v2.
Thanks a lot.
Regards,
angelo
> > + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
> > + bus_data->offload);
> > + if (IS_ERR(rx_dma))
> > + return dev_err_probe(dev, PTR_ERR(rx_dma),
> > + "failed to get offload RX DMA\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, PTR_ERR(rx_dma),
> > + "failed to setup offload RX DMA\n");
> > +
> > + /* Use offload ops. */
> > + indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
> > +
> > + st->offload_en = true;
> > +
> > + return 0;
> > +}
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties
2025-04-03 16:19 ` [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties Angelo Dureghello
@ 2025-04-07 13:21 ` Rob Herring (Arm)
0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring (Arm) @ 2025-04-07 13:21 UTC (permalink / raw)
To: Angelo Dureghello
Cc: Jonathan Cameron, David Lechner, Michael Hennerich,
Lars-Peter Clausen, Krzysztof Kozlowski, linux-kernel, linux-iio,
Michael Hennerich, devicetree, Jonathan Corbet, Conor Dooley,
linux-doc
On Thu, 03 Apr 2025 18:19:04 +0200, Angelo Dureghello wrote:
> From: Angelo Dureghello <adureghello@baylibre.com>
>
> Add #trigger-source-cells property to allow the BUSY output to be
> used as a SPI offload trigger source to indicate when a sample is ready
> to be read.
>
> Macros are added to adi,ad7606.h for the cell values to help with
> readability since they are arbitrary values.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> ---
> Documentation/devicetree/bindings/iio/adc/adi,ad7606.yaml | 8 ++++++++
> include/dt-bindings/iio/adc/adi,ad7606.h | 9 +++++++++
> 2 files changed, 17 insertions(+)
>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/3] iio: ad7606: add SPI offload support
2025-04-03 16:48 ` [PATCH 0/3] iio: " David Lechner
@ 2025-04-07 18:55 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2025-04-07 18:55 UTC (permalink / raw)
To: David Lechner
Cc: Angelo Dureghello, Lars-Peter Clausen, Michael Hennerich,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet,
linux-iio, devicetree, linux-kernel, linux-doc
On Thu, 3 Apr 2025 11:48:09 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 4/3/25 11:19 AM, Angelo Dureghello wrote:
> > Add SPI offload support for the ad7606 ADC.
> >
> > Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
> > ---
>
> Reviewed-by: David Lechner <dlechner@baylibre.com>
>
Dropped the todo and applied to the togreg branch of iio.git.
Initially pushed out as testing for 0-day to work it's magic.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
2025-04-05 15:40 ` Jonathan Cameron
@ 2025-04-07 18:58 ` Jonathan Cameron
2025-04-14 18:24 ` Jonathan Cameron
2 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2025-04-07 18:58 UTC (permalink / raw)
To: Angelo Dureghello
Cc: Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, David Lechner,
linux-iio, devicetree, linux-kernel, linux-doc
On Thu, 03 Apr 2025 18:19:06 +0200
Angelo Dureghello <adureghello@baylibre.com> wrote:
> From: Angelo Dureghello <adureghello@baylibre.com>
>
> Add SPI offload support for this family.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Missing import of the IIO_DMAENGINE_BUFFER in the spi module.
Added.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
2025-04-05 15:40 ` Jonathan Cameron
2025-04-07 18:58 ` Jonathan Cameron
@ 2025-04-14 18:24 ` Jonathan Cameron
2025-04-14 19:59 ` Angelo Dureghello
2 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2025-04-14 18:24 UTC (permalink / raw)
To: Angelo Dureghello
Cc: Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, David Lechner,
linux-iio, devicetree, linux-kernel, linux-doc
> +static int ad7606_spi_offload_probe(struct device *dev,
> + struct iio_dev *indio_dev)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + struct spi_device *spi = to_spi_device(dev);
> + struct spi_bus_data *bus_data;
> + struct dma_chan *rx_dma;
> + struct spi_offload_trigger_info trigger_info = {
> + .fwnode = dev_fwnode(dev),
> + .ops = &ad7606_offload_trigger_ops,
> + .priv = st,
> + };
> + int ret;
> +
> + bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
> + if (!bus_data)
> + return -ENOMEM;
> + st->bus_data = bus_data;
> +
> + bus_data->offload = devm_spi_offload_get(dev, spi,
> + &ad7606_spi_offload_config);
> + ret = PTR_ERR_OR_ZERO(bus_data->offload);
> + if (ret && ret != -ENODEV)
> + return dev_err_probe(dev, ret, "failed to get SPI offload\n");
> + /* Allow main ad7606_probe function to continue. */
> + if (ret == -ENODEV)
> + return 0;
> +
> + ret = devm_spi_offload_trigger_register(dev, &trigger_info);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to register offload trigger\n");
> +
> + bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
> + bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
> + if (IS_ERR(bus_data->offload_trigger))
> + return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
> + "failed to get offload trigger\n");
> +
> + /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
> + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
> + bus_data->offload);
> + if (IS_ERR(rx_dma))
> + return dev_err_probe(dev, PTR_ERR(rx_dma),
> + "failed to get offload RX DMA\n");
> +
> + ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
> + rx_dma, IIO_BUFFER_DIRECTION_IN);
> + if (ret)
should be ret; Thanks to 0-day for the report and fixed up.
> + return dev_err_probe(dev, PTR_ERR(rx_dma),
> + "failed to setup offload RX DMA\n");
> +
> + /* Use offload ops. */
> + indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
> +
> + st->offload_en = true;
> +
> + return 0;
> +}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support
2025-04-14 18:24 ` Jonathan Cameron
@ 2025-04-14 19:59 ` Angelo Dureghello
0 siblings, 0 replies; 12+ messages in thread
From: Angelo Dureghello @ 2025-04-14 19:59 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, Michael Hennerich, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Jonathan Corbet, David Lechner,
linux-iio, devicetree, linux-kernel, linux-doc
On 14.04.2025 19:24, Jonathan Cameron wrote:
>
> > +static int ad7606_spi_offload_probe(struct device *dev,
> > + struct iio_dev *indio_dev)
> > +{
> > + struct ad7606_state *st = iio_priv(indio_dev);
> > + struct spi_device *spi = to_spi_device(dev);
> > + struct spi_bus_data *bus_data;
> > + struct dma_chan *rx_dma;
> > + struct spi_offload_trigger_info trigger_info = {
> > + .fwnode = dev_fwnode(dev),
> > + .ops = &ad7606_offload_trigger_ops,
> > + .priv = st,
> > + };
> > + int ret;
> > +
> > + bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
> > + if (!bus_data)
> > + return -ENOMEM;
> > + st->bus_data = bus_data;
> > +
> > + bus_data->offload = devm_spi_offload_get(dev, spi,
> > + &ad7606_spi_offload_config);
> > + ret = PTR_ERR_OR_ZERO(bus_data->offload);
> > + if (ret && ret != -ENODEV)
> > + return dev_err_probe(dev, ret, "failed to get SPI offload\n");
> > + /* Allow main ad7606_probe function to continue. */
> > + if (ret == -ENODEV)
> > + return 0;
> > +
> > + ret = devm_spi_offload_trigger_register(dev, &trigger_info);
> > + if (ret)
> > + return dev_err_probe(dev, ret,
> > + "failed to register offload trigger\n");
> > +
> > + bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
> > + bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
> > + if (IS_ERR(bus_data->offload_trigger))
> > + return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
> > + "failed to get offload trigger\n");
> > +
> > + /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */
> > + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
> > + bus_data->offload);
> > + if (IS_ERR(rx_dma))
> > + return dev_err_probe(dev, PTR_ERR(rx_dma),
> > + "failed to get offload RX DMA\n");
> > +
> > + ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
> > + rx_dma, IIO_BUFFER_DIRECTION_IN);
> > + if (ret)
>
> should be ret; Thanks to 0-day for the report and fixed up.
>
thanks for fixing it.
Regards,
angelo
> > + return dev_err_probe(dev, PTR_ERR(rx_dma),
> > + "failed to setup offload RX DMA\n");
> > +
> > + /* Use offload ops. */
> > + indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
> > +
> > + st->offload_en = true;
> > +
> > + return 0;
> > +}
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-04-14 20:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-03 16:19 [PATCH 0/3] iio: ad7606: add SPI offload support Angelo Dureghello
2025-04-03 16:19 ` [PATCH 1/3] dt-bindings: iio: adc: adi,ad7606: add SPI offload properties Angelo Dureghello
2025-04-07 13:21 ` Rob Herring (Arm)
2025-04-03 16:19 ` [PATCH 2/3] doc: iio: ad7606: describe offload support Angelo Dureghello
2025-04-03 16:19 ` [PATCH 3/3] iio: adc: ad7606: add SPI " Angelo Dureghello
2025-04-05 15:40 ` Jonathan Cameron
2025-04-07 7:41 ` Angelo Dureghello
2025-04-07 18:58 ` Jonathan Cameron
2025-04-14 18:24 ` Jonathan Cameron
2025-04-14 19:59 ` Angelo Dureghello
2025-04-03 16:48 ` [PATCH 0/3] iio: " David Lechner
2025-04-07 18:55 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox