* [PATCH v2 0/3] Add IIO backend support for AD7779
@ 2025-08-06 19:24 Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 1/3] iio: adc: adi-axi-adc: add axi_adc_num_lanes_set Ioana Risteiu
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Ioana Risteiu @ 2025-08-06 19:24 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
Cc: Ioana Risteiu
- Add axi_adc_num_lanes_set in the adi_axi_adc_ops structure to support
setting number of lanes used by AXI ADC.
- Add the generic io-backends property to the AD7779 binding to enable
support for the IIO backend framework.
- Add the adi,num-lanes property to set the number of lanes used by
AD7779.
- Add a new functionality to ad7779 driver that streams data through data
output interface using IIO backend interface.
Ioana Risteiu (3):
iio: adc: adi-axi-adc: add axi_adc_num_lanes_set
dt-bindings: iio: adc: add IIO backend support
iio: adc: update ad7779 to use IIO backend
.../bindings/iio/adc/adi,ad7779.yaml | 34 ++-
drivers/iio/adc/ad7779.c | 242 +++++++++++++-----
drivers/iio/adc/adi-axi-adc.c | 1 +
3 files changed, 217 insertions(+), 60 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/3] iio: adc: adi-axi-adc: add axi_adc_num_lanes_set
2025-08-06 19:24 [PATCH v2 0/3] Add IIO backend support for AD7779 Ioana Risteiu
@ 2025-08-06 19:24 ` Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support Ioana Risteiu
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
2 siblings, 0 replies; 9+ messages in thread
From: Ioana Risteiu @ 2025-08-06 19:24 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
Cc: Ioana Risteiu
Add axi_adc_num_lanes_set in the adi_axi_adc_ops structure to support
setting number of lanes used by AXI ADC.
Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
drivers/iio/adc/adi-axi-adc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 2d86bb0e08a7..20bb59c24acf 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -617,6 +617,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
.chan_status = axi_adc_chan_status,
.interface_type_get = axi_adc_interface_type_get,
.oversampling_ratio_set = axi_adc_oversampling_ratio_set,
+ .num_lanes_set = axi_adc_num_lanes_set,
.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
};
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support
2025-08-06 19:24 [PATCH v2 0/3] Add IIO backend support for AD7779 Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 1/3] iio: adc: adi-axi-adc: add axi_adc_num_lanes_set Ioana Risteiu
@ 2025-08-06 19:24 ` Ioana Risteiu
2025-08-08 6:52 ` Krzysztof Kozlowski
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
2 siblings, 1 reply; 9+ messages in thread
From: Ioana Risteiu @ 2025-08-06 19:24 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
Cc: Ioana Risteiu
Add the generic io-backends property to the AD7779 binding to enable
support for the IIO backend framework.
Also add the adi,num-lanes property to set the number of lanes used by
AD7779.
Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
.../bindings/iio/adc/adi,ad7779.yaml | 34 ++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
index 044f92f39cfa..4205ac29c824 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
@@ -80,11 +80,27 @@ properties:
reset-gpios:
maxItems: 1
+ io-backends:
+ maxItems: 1
+
+ adi,num-lanes:
+ description: |
+ Number of lanes on which the data is sent on the output when the data
+ output interface is used.
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [1, 2, 4]
+ default: 4
+
required:
- compatible
- reg
- clocks
- - interrupts
+
+oneOf:
+ - required:
+ - interrupts
+ - required:
+ - io-backends
unevaluatedProperties: false
@@ -107,4 +123,20 @@ examples:
clocks = <&adc_clk>;
};
};
+
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ spi {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ adc@0 {
+ compatible = "adi,ad7779";
+ reg = <0>;
+ start-gpios = <&gpio0 87 GPIO_ACTIVE_LOW>;
+ reset-gpios = <&gpio0 93 GPIO_ACTIVE_LOW>;
+ clocks = <&adc_clk>;
+ io-backends = <&iio_backend>;
+ };
+ };
...
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
2025-08-06 19:24 [PATCH v2 0/3] Add IIO backend support for AD7779 Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 1/3] iio: adc: adi-axi-adc: add axi_adc_num_lanes_set Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support Ioana Risteiu
@ 2025-08-06 19:25 ` Ioana Risteiu
2025-08-06 20:36 ` Andy Shevchenko
` (2 more replies)
2 siblings, 3 replies; 9+ messages in thread
From: Ioana Risteiu @ 2025-08-06 19:25 UTC (permalink / raw)
To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
Cc: Ioana Risteiu
Add a new functionality to ad7779 driver that streams data through data
output interface using IIO backend interface.
Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
drivers/iio/adc/ad7779.c | 242 +++++++++++++++++++++++++++++----------
1 file changed, 183 insertions(+), 59 deletions(-)
diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c
index 845adc510239..a69fda1f4581 100644
--- a/drivers/iio/adc/ad7779.c
+++ b/drivers/iio/adc/ad7779.c
@@ -31,6 +31,8 @@
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/backend.h>
+
#define AD7779_SPI_READ_CMD BIT(7)
#define AD7779_DISABLE_SD BIT(7)
@@ -116,6 +118,12 @@
#define AD7779_CRC8_POLY 0x07
DECLARE_CRC8_TABLE(ad7779_crc8_table);
+enum ad7779_data_lines {
+ AD7779_4LINES = 4,
+ AD7779_2LINES = 2,
+ AD7779_1LINE = 1,
+};
+
enum ad7779_filter {
AD7779_SINC3,
AD7779_SINC5,
@@ -157,6 +165,8 @@ struct ad7779_state {
u8 reg_rx_buf[3];
u8 reg_tx_buf[3];
u8 reset_buf[8];
+
+ struct iio_backend *back;
};
static const char * const ad7779_filter_type[] = {
@@ -630,12 +640,38 @@ static int ad7779_reset(struct iio_dev *indio_dev, struct gpio_desc *reset_gpio)
return ret;
}
+static int ad7779_update_scan_mode(struct iio_dev *indio_dev,
+ const unsigned long *scan_mask)
+{
+ struct ad7779_state *st = iio_priv(indio_dev);
+ unsigned int c;
+ int ret;
+
+ for (c = 0; c < AD7779_NUM_CHANNELS; c++) {
+ if (test_bit(c, scan_mask))
+ ret = iio_backend_chan_enable(st->back, c);
+ else
+ ret = iio_backend_chan_disable(st->back, c);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static const struct iio_info ad7779_info = {
.read_raw = ad7779_read_raw,
.write_raw = ad7779_write_raw,
.debugfs_reg_access = &ad7779_reg_access,
};
+static const struct iio_info ad7779_info_data = {
+ .read_raw = ad7779_read_raw,
+ .write_raw = ad7779_write_raw,
+ .debugfs_reg_access = &ad7779_reg_access,
+ .update_scan_mode = &ad7779_update_scan_mode,
+};
+
static const struct iio_enum ad7779_filter_enum = {
.items = ad7779_filter_type,
.num_items = ARRAY_SIZE(ad7779_filter_type),
@@ -650,7 +686,7 @@ static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
{ }
};
-#define AD777x_CHAN_S(index, _ext_info) \
+#define AD777X_CHAN_S(index, _ext_info) \
{ \
.type = IIO_VOLTAGE, \
.info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) | \
@@ -669,32 +705,33 @@ static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
}, \
}
-#define AD777x_CHAN_NO_FILTER_S(index) \
- AD777x_CHAN_S(index, NULL)
+#define AD777X_CHAN_NO_FILTER_S(index) \
+ AD777X_CHAN_S(index, NULL)
+
+#define AD777X_CHAN_FILTER_S(index) \
+ AD777X_CHAN_S(index, ad7779_ext_filter)
-#define AD777x_CHAN_FILTER_S(index) \
- AD777x_CHAN_S(index, ad7779_ext_filter)
static const struct iio_chan_spec ad7779_channels[] = {
- AD777x_CHAN_NO_FILTER_S(0),
- AD777x_CHAN_NO_FILTER_S(1),
- AD777x_CHAN_NO_FILTER_S(2),
- AD777x_CHAN_NO_FILTER_S(3),
- AD777x_CHAN_NO_FILTER_S(4),
- AD777x_CHAN_NO_FILTER_S(5),
- AD777x_CHAN_NO_FILTER_S(6),
- AD777x_CHAN_NO_FILTER_S(7),
+ AD777X_CHAN_NO_FILTER_S(0),
+ AD777X_CHAN_NO_FILTER_S(1),
+ AD777X_CHAN_NO_FILTER_S(2),
+ AD777X_CHAN_NO_FILTER_S(3),
+ AD777X_CHAN_NO_FILTER_S(4),
+ AD777X_CHAN_NO_FILTER_S(5),
+ AD777X_CHAN_NO_FILTER_S(6),
+ AD777X_CHAN_NO_FILTER_S(7),
IIO_CHAN_SOFT_TIMESTAMP(8),
};
static const struct iio_chan_spec ad7779_channels_filter[] = {
- AD777x_CHAN_FILTER_S(0),
- AD777x_CHAN_FILTER_S(1),
- AD777x_CHAN_FILTER_S(2),
- AD777x_CHAN_FILTER_S(3),
- AD777x_CHAN_FILTER_S(4),
- AD777x_CHAN_FILTER_S(5),
- AD777x_CHAN_FILTER_S(6),
- AD777x_CHAN_FILTER_S(7),
+ AD777X_CHAN_FILTER_S(0),
+ AD777X_CHAN_FILTER_S(1),
+ AD777X_CHAN_FILTER_S(2),
+ AD777X_CHAN_FILTER_S(3),
+ AD777X_CHAN_FILTER_S(4),
+ AD777X_CHAN_FILTER_S(5),
+ AD777X_CHAN_FILTER_S(6),
+ AD777X_CHAN_FILTER_S(7),
IIO_CHAN_SOFT_TIMESTAMP(8),
};
@@ -752,6 +789,126 @@ static int ad7779_conf(struct ad7779_state *st, struct gpio_desc *start_gpio)
return 0;
}
+static int ad7779_set_data_lines(struct iio_dev *indio_dev,
+ unsigned int num_lanes)
+{
+ struct ad7779_state *st = iio_priv(indio_dev);
+ int ret;
+
+ ret = ad7779_set_sampling_frequency(st, num_lanes * AD7779_DEFAULT_SAMPLING_1LINE);
+ if (ret)
+ return ret;
+
+ ret = iio_backend_num_lanes_set(st->back, num_lanes);
+ if (ret)
+ return ret;
+
+ return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
+ AD7779_DOUT_FORMAT_MSK,
+ FIELD_PREP(AD7779_DOUT_FORMAT_MSK, 2 - ilog2(num_lanes)));
+}
+
+static int ad7779_conf_channels(struct iio_dev *indio_dev, const struct ad7779_state *st)
+{
+ struct iio_chan_spec *channels;
+ struct device *dev = &st->spi->dev;
+ int num_channels = ARRAY_SIZE(ad7779_channels);
+
+ channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL);
+ if (!channels)
+ return -ENOMEM;
+
+ memcpy(channels, st->chip_info->channels, num_channels * sizeof(struct iio_chan_spec));
+
+ for (int i = 0; i < 8; i++)
+ channels[i].scan_type.endianness = IIO_CPU;
+
+ indio_dev->channels = channels;
+
+ return 0;
+}
+
+static int setup_irq(struct ad7779_state *st, struct iio_dev *indio_dev)
+{
+ int ret;
+ struct device *dev = &st->spi->dev;
+
+ indio_dev->info = &ad7779_info;
+ indio_dev->channels = st->chip_info->channels;
+
+ st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
+ iio_device_id(indio_dev));
+ if (!st->trig)
+ return -ENOMEM;
+
+ st->trig->ops = &ad7779_trigger_ops;
+
+ iio_trigger_set_drvdata(st->trig, st);
+
+ ret = devm_request_irq(dev, st->spi->irq, iio_trigger_generic_data_rdy_poll,
+ IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name,
+ st->trig);
+ if (ret)
+ return dev_err_probe(dev, ret, "request IRQ %d failed\n",
+ st->spi->irq);
+
+ ret = devm_iio_trigger_register(dev, st->trig);
+ if (ret)
+ return ret;
+
+ indio_dev->trig = iio_trigger_get(st->trig);
+
+ init_completion(&st->completion);
+
+ ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+ &iio_pollfunc_store_time,
+ &ad7779_trigger_handler,
+ &ad7779_buffer_setup_ops);
+ if (ret)
+ return ret;
+
+ ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
+ AD7779_DCLK_CLK_DIV_MSK,
+ FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7));
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int setup_back(struct ad7779_state *st, struct iio_dev *indio_dev)
+{
+ struct device *dev = &st->spi->dev;
+ int ret = -EINVAL;
+ int num_lanes;
+
+ indio_dev->info = &ad7779_info_data;
+
+ ret = ad7779_conf_channels(indio_dev, st);
+ if (ret)
+ return ret;
+
+ st->back = devm_iio_backend_get(dev, NULL);
+ if (IS_ERR(st->back)) {
+ dev_err_probe(dev, ret, "failed to get iio backend");
+ return PTR_ERR(st->back);
+ }
+
+ ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
+ if (ret)
+ return ret;
+
+ ret = devm_iio_backend_enable(dev, st->back);
+ if (ret)
+ return ret;
+
+ ret = device_property_read_u32(dev, "adi,num-lanes", &num_lanes);
+ if (ret < 0)
+ return ad7779_set_data_lines(indio_dev, 4);
+
+ return ad7779_set_data_lines(indio_dev, num_lanes);
+}
+
static int ad7779_probe(struct spi_device *spi)
{
struct iio_dev *indio_dev;
@@ -760,9 +917,6 @@ static int ad7779_probe(struct spi_device *spi)
struct device *dev = &spi->dev;
int ret = -EINVAL;
- if (!spi->irq)
- return dev_err_probe(dev, ret, "DRDY irq not present\n");
-
indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
@@ -804,45 +958,14 @@ static int ad7779_probe(struct spi_device *spi)
return ret;
indio_dev->name = st->chip_info->name;
- indio_dev->info = &ad7779_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = ARRAY_SIZE(ad7779_channels);
- st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
- iio_device_id(indio_dev));
- if (!st->trig)
- return -ENOMEM;
-
- st->trig->ops = &ad7779_trigger_ops;
-
- iio_trigger_set_drvdata(st->trig, st);
-
- ret = devm_request_irq(dev, spi->irq, iio_trigger_generic_data_rdy_poll,
- IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name,
- st->trig);
- if (ret)
- return dev_err_probe(dev, ret, "request IRQ %d failed\n",
- st->spi->irq);
-
- ret = devm_iio_trigger_register(dev, st->trig);
- if (ret)
- return ret;
-
- indio_dev->trig = iio_trigger_get(st->trig);
-
- init_completion(&st->completion);
-
- ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
- &iio_pollfunc_store_time,
- &ad7779_trigger_handler,
- &ad7779_buffer_setup_ops);
- if (ret)
- return ret;
+ if (device_property_present(dev, "io-backends"))
+ ret = setup_back(st, indio_dev);
+ else
+ ret = setup_irq(st, indio_dev);
- ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
- AD7779_DCLK_CLK_DIV_MSK,
- FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7));
if (ret)
return ret;
@@ -936,3 +1059,4 @@ module_spi_driver(ad7779_driver);
MODULE_AUTHOR("Ramona Alexandra Nechita <ramona.nechita@analog.com>");
MODULE_DESCRIPTION("Analog Devices AD7779 ADC");
MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BACKEND");
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
@ 2025-08-06 20:36 ` Andy Shevchenko
2025-08-09 19:37 ` Jonathan Cameron
2025-08-09 19:48 ` Jonathan Cameron
2025-08-11 6:46 ` Dan Carpenter
2 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-08-06 20:36 UTC (permalink / raw)
To: Ioana Risteiu
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
On Wed, Aug 06, 2025 at 10:25:00PM +0300, Ioana Risteiu wrote:
> Add a new functionality to ad7779 driver that streams data through data
> output interface using IIO backend interface.
...
> +enum ad7779_data_lines {
> + AD7779_4LINES = 4,
> + AD7779_2LINES = 2,
> + AD7779_1LINE = 1,
Reversed ordering in enum is not a thing I see everyday in C, maybe a bit
confusing to the reader.
> +};
Seems like it's 1:1, why enum at all?
...
> -#define AD777x_CHAN_S(index, _ext_info) \
> +#define AD777X_CHAN_S(index, _ext_info) \
> { \
> .type = IIO_VOLTAGE, \
> .info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) | \
Unneeded change.
...
> -#define AD777x_CHAN_NO_FILTER_S(index) \
> - AD777x_CHAN_S(index, NULL)
> +#define AD777X_CHAN_NO_FILTER_S(index) \
> + AD777X_CHAN_S(index, NULL)
Why?!
> +#define AD777X_CHAN_FILTER_S(index) \
> + AD777X_CHAN_S(index, ad7779_ext_filter)
>
> -#define AD777x_CHAN_FILTER_S(index) \
> - AD777x_CHAN_S(index, ad7779_ext_filter)
Ditto.
> static const struct iio_chan_spec ad7779_channels[] = {
> - AD777x_CHAN_NO_FILTER_S(0),
> - AD777x_CHAN_NO_FILTER_S(1),
> - AD777x_CHAN_NO_FILTER_S(2),
> - AD777x_CHAN_NO_FILTER_S(3),
> - AD777x_CHAN_NO_FILTER_S(4),
> - AD777x_CHAN_NO_FILTER_S(5),
> - AD777x_CHAN_NO_FILTER_S(6),
> - AD777x_CHAN_NO_FILTER_S(7),
> + AD777X_CHAN_NO_FILTER_S(0),
> + AD777X_CHAN_NO_FILTER_S(1),
> + AD777X_CHAN_NO_FILTER_S(2),
> + AD777X_CHAN_NO_FILTER_S(3),
> + AD777X_CHAN_NO_FILTER_S(4),
> + AD777X_CHAN_NO_FILTER_S(5),
> + AD777X_CHAN_NO_FILTER_S(6),
> + AD777X_CHAN_NO_FILTER_S(7),
> IIO_CHAN_SOFT_TIMESTAMP(8),
> };
Ditto.
> static const struct iio_chan_spec ad7779_channels_filter[] = {
> - AD777x_CHAN_FILTER_S(0),
> - AD777x_CHAN_FILTER_S(1),
> - AD777x_CHAN_FILTER_S(2),
> - AD777x_CHAN_FILTER_S(3),
> - AD777x_CHAN_FILTER_S(4),
> - AD777x_CHAN_FILTER_S(5),
> - AD777x_CHAN_FILTER_S(6),
> - AD777x_CHAN_FILTER_S(7),
> + AD777X_CHAN_FILTER_S(0),
> + AD777X_CHAN_FILTER_S(1),
> + AD777X_CHAN_FILTER_S(2),
> + AD777X_CHAN_FILTER_S(3),
> + AD777X_CHAN_FILTER_S(4),
> + AD777X_CHAN_FILTER_S(5),
> + AD777X_CHAN_FILTER_S(6),
> + AD777X_CHAN_FILTER_S(7),
> IIO_CHAN_SOFT_TIMESTAMP(8),
> };
Ditto.
...
> +static int ad7779_conf_channels(struct iio_dev *indio_dev, const struct ad7779_state *st)
> +{
> + struct iio_chan_spec *channels;
> + struct device *dev = &st->spi->dev;
> + int num_channels = ARRAY_SIZE(ad7779_channels);
> +
> + channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL);
Doesn't sound like a right place for devm. Is this function called only at probe stage?
> + if (!channels)
> + return -ENOMEM;
> +
> + memcpy(channels, st->chip_info->channels, num_channels * sizeof(struct iio_chan_spec));
kmemdup_array()?
> + for (int i = 0; i < 8; i++)
Why i is signed?
What is the magic 8? ARRAY_SIZE()?
> + channels[i].scan_type.endianness = IIO_CPU;
> +
> + indio_dev->channels = channels;
> +
> + return 0;
> +}
...
> + if (ret)
> + return ret;
> +
> + return 0;
return ...
...
> + st->back = devm_iio_backend_get(dev, NULL);
> + if (IS_ERR(st->back)) {
> + dev_err_probe(dev, ret, "failed to get iio backend");
Huh?!
> + return PTR_ERR(st->back);
Pattern is
return dev_err_probe(...);
> + }
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support
2025-08-06 19:24 ` [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support Ioana Risteiu
@ 2025-08-08 6:52 ` Krzysztof Kozlowski
0 siblings, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2025-08-08 6:52 UTC (permalink / raw)
To: Ioana Risteiu
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
On Wed, Aug 06, 2025 at 10:24:59PM +0300, Ioana Risteiu wrote:
> Add the generic io-backends property to the AD7779 binding to enable
> support for the IIO backend framework.
>
> Also add the adi,num-lanes property to set the number of lanes used by
> AD7779.
>
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
> ---
> .../bindings/iio/adc/adi,ad7779.yaml | 34 ++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
> index 044f92f39cfa..4205ac29c824 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
> @@ -80,11 +80,27 @@ properties:
> reset-gpios:
> maxItems: 1
>
> + io-backends:
> + maxItems: 1
> +
> + adi,num-lanes:
I see @Rob already reviewed one other binding with adi,num-lanes instead
of asking to re-use PCI num-lanes property, so I guess this is fine.
> + description: |
Drop |
> + Number of lanes on which the data is sent on the output when the data
> + output interface is used.
> + $ref: /schemas/types.yaml#/definitions/uint32
> + enum: [1, 2, 4]
> + default: 4
> +
> required:
> - compatible
> - reg
> - clocks
> - - interrupts
> +
> +oneOf:
> + - required:
> + - interrupts
> + - required:
> + - io-backends
>
> unevaluatedProperties: false
>
> @@ -107,4 +123,20 @@ examples:
> clocks = <&adc_clk>;
> };
> };
> +
> + - |
> + #include <dt-bindings/gpio/gpio.h>
> + spi {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + adc@0 {
> + compatible = "adi,ad7779";
> + reg = <0>;
> + start-gpios = <&gpio0 87 GPIO_ACTIVE_LOW>;
> + reset-gpios = <&gpio0 93 GPIO_ACTIVE_LOW>;
> + clocks = <&adc_clk>;
> + io-backends = <&iio_backend>;
Make it complete if you add completely new example - num-lanes.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
2025-08-06 20:36 ` Andy Shevchenko
@ 2025-08-09 19:37 ` Jonathan Cameron
0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2025-08-09 19:37 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Ioana Risteiu, Lars-Peter Clausen, Michael Hennerich,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Ramona Nechita, linux-iio,
devicetree, linux-kernel
>
> > +static int ad7779_conf_channels(struct iio_dev *indio_dev, const struct ad7779_state *st)
> > +{
> > + struct iio_chan_spec *channels;
> > + struct device *dev = &st->spi->dev;
> > + int num_channels = ARRAY_SIZE(ad7779_channels);
> > +
> > + channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL);
>
> Doesn't sound like a right place for devm. Is this function called only at probe stage?
Yup. So probably wants a name that doesn't sound like a runtime thing. setup_channels maybe?
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
2025-08-06 20:36 ` Andy Shevchenko
@ 2025-08-09 19:48 ` Jonathan Cameron
2025-08-11 6:46 ` Dan Carpenter
2 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2025-08-09 19:48 UTC (permalink / raw)
To: Ioana Risteiu
Cc: Lars-Peter Clausen, Michael Hennerich, David Lechner,
Nuno Sá, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Ramona Nechita, linux-iio, devicetree, linux-kernel
On Wed, 6 Aug 2025 22:25:00 +0300
Ioana Risteiu <Ioana.Risteiu@analog.com> wrote:
> Add a new functionality to ad7779 driver that streams data through data
> output interface using IIO backend interface.
>
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
Hi Ionna,
>
> +static int ad7779_set_data_lines(struct iio_dev *indio_dev,
> + unsigned int num_lanes)
> +{
> + struct ad7779_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = ad7779_set_sampling_frequency(st, num_lanes * AD7779_DEFAULT_SAMPLING_1LINE);
> + if (ret)
> + return ret;
> +
> + ret = iio_backend_num_lanes_set(st->back, num_lanes);
> + if (ret)
> + return ret;
> +
> + return ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
> + AD7779_DOUT_FORMAT_MSK,
> + FIELD_PREP(AD7779_DOUT_FORMAT_MSK, 2 - ilog2(num_lanes)));
> +}
> +
> +static int ad7779_conf_channels(struct iio_dev *indio_dev, const struct ad7779_state *st)
As per other branch of thread. This needs a name that makes it more
obvious it's a probe time setup rather that anything to do with configuring
channels at runtime.
> +{
> + struct iio_chan_spec *channels;
> + struct device *dev = &st->spi->dev;
> + int num_channels = ARRAY_SIZE(ad7779_channels);
> +
> + channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL);
devm_kmemdup_array()?
> + if (!channels)
> + return -ENOMEM;
> +
> + memcpy(channels, st->chip_info->channels, num_channels * sizeof(struct iio_chan_spec));
> +
> + for (int i = 0; i < 8; i++)
Andy got this, but make sure to get that 8 from somewhere. It's num_channels I think.
Though given most of this code collapses into a single call to devm_kmemdup_array()
I think that local variable may not make much sense. ARRAY_SIZE may be clearer.
> + channels[i].scan_type.endianness = IIO_CPU;
> +
> + indio_dev->channels = channels;
> +
> + return 0;
> +}
> +
> +static int setup_irq(struct ad7779_state *st, struct iio_dev *indio_dev)
As below. Do this in a precursor patch and give it a better name!
Pretty much everything in IIO driver gets namespaced with a driver
specific prefix. Makes future problems with new generic functions
much less likely and makes it clear what is local to the driver.
> +{
> + int ret;
> + struct device *dev = &st->spi->dev;
> +
> + indio_dev->info = &ad7779_info;
> + indio_dev->channels = st->chip_info->channels;
> +
> + st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> + iio_device_id(indio_dev));
> + if (!st->trig)
> + return -ENOMEM;
> +
> + st->trig->ops = &ad7779_trigger_ops;
> +
> + iio_trigger_set_drvdata(st->trig, st);
> +
> + ret = devm_request_irq(dev, st->spi->irq, iio_trigger_generic_data_rdy_poll,
> + IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name,
> + st->trig);
> + if (ret)
> + return dev_err_probe(dev, ret, "request IRQ %d failed\n",
> + st->spi->irq);
> +
> + ret = devm_iio_trigger_register(dev, st->trig);
> + if (ret)
> + return ret;
> +
> + indio_dev->trig = iio_trigger_get(st->trig);
> +
> + init_completion(&st->completion);
> +
> + ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> + &iio_pollfunc_store_time,
> + &ad7779_trigger_handler,
> + &ad7779_buffer_setup_ops);
> + if (ret)
> + return ret;
> +
> + ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
> + AD7779_DCLK_CLK_DIV_MSK,
> + FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7));
return ad7779_spi_write_mask...
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +static int setup_back(struct ad7779_state *st, struct iio_dev *indio_dev)
> +{
> + struct device *dev = &st->spi->dev;
> + int ret = -EINVAL;
> + int num_lanes;
> +
> + indio_dev->info = &ad7779_info_data;
> +
> + ret = ad7779_conf_channels(indio_dev, st);
> + if (ret)
> + return ret;
> +
> + st->back = devm_iio_backend_get(dev, NULL);
> + if (IS_ERR(st->back)) {
> + dev_err_probe(dev, ret, "failed to get iio backend");
ret == 0 which isn't what you want.
> + return PTR_ERR(st->back);
I think Andy pointed this out as well. I'm not being too careful to not
duplicate unless I happen to remember he covered something in the earlier
review.
> + }
> +
> + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
> + if (ret)
> + return ret;
> +
> + ret = devm_iio_backend_enable(dev, st->back);
> + if (ret)
> + return ret;
> +
> + ret = device_property_read_u32(dev, "adi,num-lanes", &num_lanes);
> + if (ret < 0)
Whilst it's a bit fiddly as this is an array read underneath, the fact
num_lanes is not null is enough to ensure if (ret) is fine here.
> + return ad7779_set_data_lines(indio_dev, 4);
> +
> + return ad7779_set_data_lines(indio_dev, num_lanes);
> +}
> +
> static int ad7779_probe(struct spi_device *spi)
> {
> struct iio_dev *indio_dev;
> @@ -760,9 +917,6 @@ static int ad7779_probe(struct spi_device *spi)
> struct device *dev = &spi->dev;
> int ret = -EINVAL;
>
> - if (!spi->irq)
> - return dev_err_probe(dev, ret, "DRDY irq not present\n");
> -
> indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> if (!indio_dev)
> return -ENOMEM;
> @@ -804,45 +958,14 @@ static int ad7779_probe(struct spi_device *spi)
> return ret;
>
> indio_dev->name = st->chip_info->name;
> - indio_dev->info = &ad7779_info;
> indio_dev->modes = INDIO_DIRECT_MODE;
> - indio_dev->channels = st->chip_info->channels;
> indio_dev->num_channels = ARRAY_SIZE(ad7779_channels);
>
> - st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> - iio_device_id(indio_dev));
> - if (!st->trig)
> - return -ENOMEM;
> -
> - st->trig->ops = &ad7779_trigger_ops;
> -
> - iio_trigger_set_drvdata(st->trig, st);
> -
> - ret = devm_request_irq(dev, spi->irq, iio_trigger_generic_data_rdy_poll,
> - IRQF_ONESHOT | IRQF_NO_AUTOEN, indio_dev->name,
> - st->trig);
> - if (ret)
> - return dev_err_probe(dev, ret, "request IRQ %d failed\n",
> - st->spi->irq);
> -
> - ret = devm_iio_trigger_register(dev, st->trig);
> - if (ret)
> - return ret;
> -
> - indio_dev->trig = iio_trigger_get(st->trig);
> -
> - init_completion(&st->completion);
> -
> - ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
> - &iio_pollfunc_store_time,
> - &ad7779_trigger_handler,
> - &ad7779_buffer_setup_ops);
> - if (ret)
> - return ret;
> + if (device_property_present(dev, "io-backends"))
> + ret = setup_back(st, indio_dev);
> + else
> + ret = setup_irq(st, indio_dev);
Do the factoring out of the setup_irq stuff in a precursor patch.
Then this one will just make it conditional as part of adding the new backend stuff.
setup_irq isn't a good name. It does a bunch of things that aren't
directly related to the irq. Prefix the function as well
ad7779_setup_without_backend() maybe?
>
> - ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
> - AD7779_DCLK_CLK_DIV_MSK,
> - FIELD_PREP(AD7779_DCLK_CLK_DIV_MSK, 7));
> if (ret)
> return ret;
>
> @@ -936,3 +1059,4 @@ module_spi_driver(ad7779_driver);
> MODULE_AUTHOR("Ramona Alexandra Nechita <ramona.nechita@analog.com>");
> MODULE_DESCRIPTION("Analog Devices AD7779 ADC");
> MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS("IIO_BACKEND");
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
2025-08-06 20:36 ` Andy Shevchenko
2025-08-09 19:48 ` Jonathan Cameron
@ 2025-08-11 6:46 ` Dan Carpenter
2 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2025-08-11 6:46 UTC (permalink / raw)
To: oe-kbuild, Ioana Risteiu, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Ramona Nechita,
linux-iio, devicetree, linux-kernel
Cc: lkp, oe-kbuild-all, Ioana Risteiu
Hi Ioana,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ioana-Risteiu/iio-adc-adi-axi-adc-add-axi_adc_num_lanes_set/20250807-032923
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20250806192502.10120-4-Ioana.Risteiu%40analog.com
patch subject: [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend
config: x86_64-randconfig-161-20250809 (https://download.01.org/0day-ci/archive/20250809/202508090909.tqDX7ah1-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
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>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202508090909.tqDX7ah1-lkp@intel.com/
smatch warnings:
drivers/iio/adc/ad7779.c:893 setup_back() warn: passing zero to 'dev_err_probe'
vim +/dev_err_probe +893 drivers/iio/adc/ad7779.c
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 879 static int setup_back(struct ad7779_state *st, struct iio_dev *indio_dev)
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 880 {
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 881 struct device *dev = &st->spi->dev;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 882 int ret = -EINVAL;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 883 int num_lanes;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 884
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 885 indio_dev->info = &ad7779_info_data;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 886
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 887 ret = ad7779_conf_channels(indio_dev, st);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 888 if (ret)
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 889 return ret;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 890
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 891 st->back = devm_iio_backend_get(dev, NULL);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 892 if (IS_ERR(st->back)) {
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 @893 dev_err_probe(dev, ret, "failed to get iio backend");
s/ret/PTR_ERR(st->back)/
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 894 return PTR_ERR(st->back);
Change this to:
if (IS_ERR(st->back))
return dev_err_probe(dev, PTR_ERR(st->back),
"failed to get iio backend");
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 895 }
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 896
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 897 ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 898 if (ret)
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 899 return ret;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 900
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 901 ret = devm_iio_backend_enable(dev, st->back);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 902 if (ret)
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 903 return ret;
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 904
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 905 ret = device_property_read_u32(dev, "adi,num-lanes", &num_lanes);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 906 if (ret < 0)
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 907 return ad7779_set_data_lines(indio_dev, 4);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 908
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 909 return ad7779_set_data_lines(indio_dev, num_lanes);
1d61d2e4f96ac5 Ioana Risteiu 2025-08-06 910 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-08-11 6:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 19:24 [PATCH v2 0/3] Add IIO backend support for AD7779 Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 1/3] iio: adc: adi-axi-adc: add axi_adc_num_lanes_set Ioana Risteiu
2025-08-06 19:24 ` [PATCH v2 2/3] dt-bindings: iio: adc: add IIO backend support Ioana Risteiu
2025-08-08 6:52 ` Krzysztof Kozlowski
2025-08-06 19:25 ` [PATCH v2 3/3] iio: adc: update ad7779 to use IIO backend Ioana Risteiu
2025-08-06 20:36 ` Andy Shevchenko
2025-08-09 19:37 ` Jonathan Cameron
2025-08-09 19:48 ` Jonathan Cameron
2025-08-11 6:46 ` Dan Carpenter
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).