linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Add IIO backend support for AD7779
@ 2025-07-28 13:43 Ioana Risteiu
  2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Ioana Risteiu @ 2025-07-28 13:43 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 compatible for the AD777x AXI IP core, a variant of the
   generic AXI ADC IP.
 - Add new compatible string and corresponding iio_backend_ops for AD777x
   axi family.
 - Add the generic io-backends property to the AD7779 binding to enable
   support for the IIO backend framework.
 - Add a new functionality to ad7779 driver that streams data through data
   output interface using IIO backend interface.

Ioana Risteiu (4):
  dt-bindigs: iio: adc: Add ad777x axi variant
  iio: adc: adi-axi-adc: Add support for ad777x
  dt-bindings: iio: adc: Add IIO backend support
  iio: adc: Update ad7779 to use IIO backend

 .../bindings/iio/adc/adi,ad7779.yaml          |  26 +-
 .../bindings/iio/adc/adi,axi-adc.yaml         |   2 +
 drivers/iio/adc/ad7779.c                      | 299 +++++++++++++++---
 drivers/iio/adc/adi-axi-adc.c                 |  25 ++
 4 files changed, 308 insertions(+), 44 deletions(-)

-- 
2.47.2


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

* [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant
  2025-07-28 13:43 [PATCH 0/4] Add IIO backend support for AD7779 Ioana Risteiu
@ 2025-07-28 13:43 ` Ioana Risteiu
  2025-07-28 13:57   ` Jonathan Cameron
  2025-07-30 21:06   ` Rob Herring (Arm)
  2025-07-28 13:43 ` [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x Ioana Risteiu
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Ioana Risteiu @ 2025-07-28 13:43 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 compatible for the AD777x AXI IP core, a variant of the
generic AXI ADC IP.

While sharing some operations with the generic AXI ADC IP, the AD777x
variant has specific requirements such as setting number of lanes.

Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
 Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
index e91e421a3d6b..1265ec5390d1 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
@@ -30,6 +30,7 @@ description: |
   https://analogdevicesinc.github.io/hdl/library/axi_ad408x/index.html
   https://analogdevicesinc.github.io/hdl/library/axi_ad485x/index.html
   http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html
+  https://analogdevicesinc.github.io/hdl/library/axi_ad777x/index.html
 
 properties:
   compatible:
@@ -38,6 +39,7 @@ properties:
       - adi,axi-ad408x
       - adi,axi-ad7606x
       - adi,axi-ad485x
+      - adi,axi-ad777x
 
   reg:
     maxItems: 1
-- 
2.47.2


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

* [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x
  2025-07-28 13:43 [PATCH 0/4] Add IIO backend support for AD7779 Ioana Risteiu
  2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
@ 2025-07-28 13:43 ` Ioana Risteiu
  2025-07-28 14:51   ` Nuno Sá
  2025-07-28 13:43 ` [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support Ioana Risteiu
  2025-07-28 13:43 ` [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend Ioana Risteiu
  3 siblings, 1 reply; 11+ messages in thread
From: Ioana Risteiu @ 2025-07-28 13:43 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 new compatible string and corresponding iio_backend_ops for AD777x
axi family.

Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 2d86bb0e08a7..c4b8ec6d9397 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -670,6 +670,25 @@ static const struct iio_backend_info axi_ad408x = {
 	.ops = &adi_ad408x_ops,
 };
 
+static const struct iio_backend_ops adi_ad777x_ops = {
+	.enable = axi_adc_enable,
+	.disable = axi_adc_disable,
+	.chan_enable = axi_adc_chan_enable,
+	.chan_disable = axi_adc_chan_disable,
+	.request_buffer = axi_adc_request_buffer,
+	.free_buffer = axi_adc_free_buffer,
+	.data_sample_trigger = axi_adc_data_sample_trigger,
+	.chan_status = axi_adc_chan_status,
+	.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),
+	.num_lanes_set = axi_adc_num_lanes_set,
+};
+
+static const struct iio_backend_info axi_ad777x = {
+	.name = "axi-ad777x",
+	.ops = &adi_ad777x_ops,
+};
+
 static int adi_axi_adc_probe(struct platform_device *pdev)
 {
 	struct adi_axi_adc_state *st;
@@ -790,12 +809,18 @@ static const struct axi_adc_info adi_axi_ad408x = {
 	.backend_info = &axi_ad408x,
 };
 
+static const struct axi_adc_info adi_axi_ad777x = {
+	.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
+	.backend_info = &axi_ad777x,
+};
+
 /* Match table for of_platform binding */
 static const struct of_device_id adi_axi_adc_of_match[] = {
 	{ .compatible = "adi,axi-adc-10.0.a", .data = &adc_generic },
 	{ .compatible = "adi,axi-ad408x", .data = &adi_axi_ad408x },
 	{ .compatible = "adi,axi-ad485x", .data = &adi_axi_ad485x },
 	{ .compatible = "adi,axi-ad7606x", .data = &adc_ad7606 },
+	{ .compatible = "adi,axi-ad777x", .data = &adi_axi_ad777x},
 	{ }
 };
 MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match);
-- 
2.47.2


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

* [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support
  2025-07-28 13:43 [PATCH 0/4] Add IIO backend support for AD7779 Ioana Risteiu
  2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
  2025-07-28 13:43 ` [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x Ioana Risteiu
@ 2025-07-28 13:43 ` Ioana Risteiu
  2025-07-30 21:06   ` Rob Herring (Arm)
  2025-07-28 13:43 ` [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend Ioana Risteiu
  3 siblings, 1 reply; 11+ messages in thread
From: Ioana Risteiu @ 2025-07-28 13:43 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.

Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
---
 .../bindings/iio/adc/adi,ad7779.yaml          | 26 ++++++++++++++++++-
 1 file changed, 25 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..4adae4f0ec98 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7779.yaml
@@ -80,11 +80,19 @@ properties:
   reset-gpios:
     maxItems: 1
 
+  io-backends:
+    maxItems: 1
+
 required:
   - compatible
   - reg
   - clocks
-  - interrupts
+
+oneOf:
+  - required:
+      - interrupts
+  - required:
+      - io-backends
 
 unevaluatedProperties: false
 
@@ -107,4 +115,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] 11+ messages in thread

* [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend
  2025-07-28 13:43 [PATCH 0/4] Add IIO backend support for AD7779 Ioana Risteiu
                   ` (2 preceding siblings ...)
  2025-07-28 13:43 ` [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support Ioana Risteiu
@ 2025-07-28 13:43 ` Ioana Risteiu
  2025-07-28 14:10   ` Jonathan Cameron
  2025-07-28 15:11   ` Nuno Sá
  3 siblings, 2 replies; 11+ messages in thread
From: Ioana Risteiu @ 2025-07-28 13:43 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 | 299 +++++++++++++++++++++++++++++++++------
 1 file changed, 256 insertions(+), 43 deletions(-)

diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c
index 845adc510239..872c551eadf6 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,
+	AD7779_2LINES,
+	AD7779_1LINE,
+};
+
 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[] = {
@@ -164,6 +174,12 @@ static const char * const ad7779_filter_type[] = {
 	[AD7779_SINC5] = "sinc5",
 };
 
+static const char * const ad7779_data_lines_modes[] = {
+	[AD7779_4LINES] = "4_data_lines",
+	[AD7779_2LINES] = "2_data_lines",
+	[AD7779_1LINE]  = "1_data_line",
+};
+
 static const char * const ad7779_power_supplies[] = {
 	"avdd1", "avdd2", "avdd4",
 };
@@ -339,6 +355,59 @@ static int ad7779_set_sampling_frequency(struct ad7779_state *st,
 	return 0;
 }
 
+static int ad7779_set_data_lines(struct iio_dev *indio_dev,
+				 struct iio_chan_spec const *chan,
+				 unsigned int mode)
+{
+	struct ad7779_state *st = iio_priv(indio_dev);
+	int ret;
+
+	ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
+				    AD7779_DOUT_FORMAT_MSK,
+				    FIELD_PREP(AD7779_DOUT_FORMAT_MSK, mode));
+	switch (mode) {
+	case AD7779_4LINES:
+		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_FREQ);
+		if (ret)
+			return ret;
+		ret = iio_backend_num_lanes_set(st->back, 4);
+		break;
+	case AD7779_2LINES:
+		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_2LINE);
+		if (ret)
+			return ret;
+		ret = iio_backend_num_lanes_set(st->back, 2);
+		break;
+	case AD7779_1LINE:
+		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_1LINE);
+		if (ret)
+			return ret;
+		ret = iio_backend_num_lanes_set(st->back, 1);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int ad7779_get_data_lines(struct iio_dev *indio_dev,
+				 struct iio_chan_spec const *chan)
+{
+	struct ad7779_state *st = iio_priv(indio_dev);
+	u8 temp;
+	int ret;
+
+	ret = ad7779_spi_read(st, AD7779_REG_DOUT_FORMAT, &temp);
+	if (ret)
+		return ret;
+
+	return FIELD_GET(AD7779_DOUT_FORMAT_MSK, temp);
+}
+
 static int ad7779_get_filter(struct iio_dev *indio_dev,
 			     struct iio_chan_spec const *chan)
 {
@@ -630,12 +699,45 @@ 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_data_lines_enum = {
+	.items = ad7779_data_lines_modes,
+	.num_items = ARRAY_SIZE(ad7779_data_lines_modes),
+	.get = ad7779_get_data_lines,
+	.set = ad7779_set_data_lines,
+};
+
 static const struct iio_enum ad7779_filter_enum = {
 	.items = ad7779_filter_type,
 	.num_items = ARRAY_SIZE(ad7779_filter_type),
@@ -643,6 +745,13 @@ static const struct iio_enum ad7779_filter_enum = {
 	.set = ad7779_set_filter,
 };
 
+static const struct iio_chan_spec_ext_info ad7779_ext_info[] = {
+	IIO_ENUM("data_lines", IIO_SHARED_BY_ALL, &ad7779_data_lines_enum),
+	IIO_ENUM_AVAILABLE("data_lines", IIO_SHARED_BY_ALL,
+			   &ad7779_data_lines_enum),
+	{ }
+};
+
 static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
 	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7779_filter_enum),
 	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL,
@@ -650,6 +759,16 @@ static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
 	{ }
 };
 
+static const struct iio_chan_spec_ext_info ad7779_ext_info_filter[] = {
+	IIO_ENUM("data_lines", IIO_SHARED_BY_ALL, &ad7779_data_lines_enum),
+	IIO_ENUM_AVAILABLE("data_lines", IIO_SHARED_BY_ALL,
+			   &ad7779_data_lines_enum),
+	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7779_filter_enum),
+	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL,
+			   &ad7779_filter_enum),
+	{ }
+};
+
 #define AD777x_CHAN_S(index, _ext_info)					\
 	{								\
 		.type = IIO_VOLTAGE,					\
@@ -669,11 +788,34 @@ static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
 		},							\
 	}
 
+#define AD777X_CHAN(index, _ext_info)					       \
+	{								       \
+		.type = IIO_VOLTAGE,					       \
+		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),       \
+		.address = (index),					       \
+		.indexed = 1,						       \
+		.channel = (index),					       \
+		.scan_index = (index),					       \
+		.ext_info = (_ext_info),				       \
+		.scan_type = {						       \
+			.sign = 's',					       \
+			.realbits = 24,					       \
+			.storagebits = 32,				       \
+		},							       \
+	}
+
 #define AD777x_CHAN_NO_FILTER_S(index)					\
 	AD777x_CHAN_S(index, NULL)
 
+#define AD777X_CHAN_NO_FILTER(index)					       \
+	AD777X_CHAN(index, ad7779_ext_info)
+
 #define AD777x_CHAN_FILTER_S(index)					\
 	AD777x_CHAN_S(index, ad7779_ext_filter)
+
+#define AD777X_CHAN_FILTER(index)					       \
+	AD777X_CHAN(index, ad7779_ext_info_filter)
+
 static const struct iio_chan_spec ad7779_channels[] = {
 	AD777x_CHAN_NO_FILTER_S(0),
 	AD777x_CHAN_NO_FILTER_S(1),
@@ -686,6 +828,17 @@ static const struct iio_chan_spec ad7779_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(8),
 };
 
+static const struct iio_chan_spec ad7779_channels_data[] = {
+	AD777X_CHAN_NO_FILTER(0),
+	AD777X_CHAN_NO_FILTER(1),
+	AD777X_CHAN_NO_FILTER(2),
+	AD777X_CHAN_NO_FILTER(3),
+	AD777X_CHAN_NO_FILTER(4),
+	AD777X_CHAN_NO_FILTER(5),
+	AD777X_CHAN_NO_FILTER(6),
+	AD777X_CHAN_NO_FILTER(7),
+};
+
 static const struct iio_chan_spec ad7779_channels_filter[] = {
 	AD777x_CHAN_FILTER_S(0),
 	AD777x_CHAN_FILTER_S(1),
@@ -698,6 +851,17 @@ static const struct iio_chan_spec ad7779_channels_filter[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(8),
 };
 
+static const struct iio_chan_spec ad7779_channels_filter_data[] = {
+	AD777X_CHAN_FILTER(0),
+	AD777X_CHAN_FILTER(1),
+	AD777X_CHAN_FILTER(2),
+	AD777X_CHAN_FILTER(3),
+	AD777X_CHAN_FILTER(4),
+	AD777X_CHAN_FILTER(5),
+	AD777X_CHAN_FILTER(6),
+	AD777X_CHAN_FILTER(7),
+};
+
 static const struct iio_buffer_setup_ops ad7779_buffer_setup_ops = {
 	.preenable = ad7779_buffer_preenable,
 	.postdisable = ad7779_buffer_postdisable,
@@ -752,6 +916,91 @@ static int ad7779_conf(struct ad7779_state *st, struct gpio_desc *start_gpio)
 	return 0;
 }
 
+static int ad7779_register_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;
+	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, 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 devm_iio_device_register(dev, indio_dev);
+}
+
+static int ad7779_register_back(struct ad7779_state *st, struct iio_dev *indio_dev)
+{
+	struct device *dev = &st->spi->dev;
+	int ret = -EINVAL;
+
+	indio_dev->info = &ad7779_info_data;
+
+	if (strcmp(st->chip_info->name, "ad7771") == 0) {
+		indio_dev->channels = ad7779_channels_filter_data;
+		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_filter_data);
+	} else {
+		indio_dev->channels = ad7779_channels_data;
+		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_data);
+	}
+
+	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 = iio_backend_num_lanes_set(st->back, 4);
+	if (ret)
+		return ret;
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
 static int ad7779_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
@@ -760,8 +1009,8 @@ 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");
+	if (!spi->irq && !device_property_present(dev, "io-backends"))
+		return dev_err_probe(dev, ret, "Either DRDY interrupt or io-backends property required\n");
 
 	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
@@ -804,49 +1053,12 @@ 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;
 
-	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 devm_iio_device_register(dev, indio_dev);
+	if (spi->irq)
+		return ad7779_register_irq(st, indio_dev);
+	else
+		return ad7779_register_back(st, indio_dev);
 }
 
 static int ad7779_suspend(struct device *dev)
@@ -936,3 +1148,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] 11+ messages in thread

* Re: [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant
  2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
@ 2025-07-28 13:57   ` Jonathan Cameron
  2025-07-30 21:06   ` Rob Herring (Arm)
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2025-07-28 13:57 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 Mon, 28 Jul 2025 16:43:33 +0300
Ioana Risteiu <Ioana.Risteiu@analog.com> wrote:

Typo in patch description.  I'll fix it when applying if nothing else comes up.
(bindings)

> Add a new compatible for the AD777x AXI IP core, a variant of the
> generic AXI ADC IP.
> 
> While sharing some operations with the generic AXI ADC IP, the AD777x
> variant has specific requirements such as setting number of lanes.
> 
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
> ---
>  Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> index e91e421a3d6b..1265ec5390d1 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
> @@ -30,6 +30,7 @@ description: |
>    https://analogdevicesinc.github.io/hdl/library/axi_ad408x/index.html
>    https://analogdevicesinc.github.io/hdl/library/axi_ad485x/index.html
>    http://analogdevicesinc.github.io/hdl/library/axi_ad7606x/index.html
> +  https://analogdevicesinc.github.io/hdl/library/axi_ad777x/index.html
>  
>  properties:
>    compatible:
> @@ -38,6 +39,7 @@ properties:
>        - adi,axi-ad408x
>        - adi,axi-ad7606x
>        - adi,axi-ad485x
> +      - adi,axi-ad777x
>  
>    reg:
>      maxItems: 1


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

* Re: [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend
  2025-07-28 13:43 ` [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend Ioana Risteiu
@ 2025-07-28 14:10   ` Jonathan Cameron
  2025-07-28 15:11   ` Nuno Sá
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2025-07-28 14:10 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 Mon, 28 Jul 2025 16:43:36 +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 Ioana,

There is some new ABI (I think) in here.  I'm not clear what it is for and
ABI documentation is missing.

A few other minor comments inline.

Thanks,

Jonathan

> +static int ad7779_set_data_lines(struct iio_dev *indio_dev,
> +				 struct iio_chan_spec const *chan,
> +				 unsigned int mode)
> +{
> +	struct ad7779_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = ad7779_spi_write_mask(st, AD7779_REG_DOUT_FORMAT,
> +				    AD7779_DOUT_FORMAT_MSK,
> +				    FIELD_PREP(AD7779_DOUT_FORMAT_MSK, mode));
> +	switch (mode) {
> +	case AD7779_4LINES:
> +		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_FREQ);
> +		if (ret)
> +			return ret;
> +		ret = iio_backend_num_lanes_set(st->back, 4);
> +		break;
> +	case AD7779_2LINES:
> +		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_2LINE);
> +		if (ret)
> +			return ret;
> +		ret = iio_backend_num_lanes_set(st->back, 2);
> +		break;
> +	case AD7779_1LINE:
> +		ret = ad7779_set_sampling_frequency(st, AD7779_DEFAULT_SAMPLING_1LINE);
> +		if (ret)
> +			return ret;
> +		ret = iio_backend_num_lanes_set(st->back, 1);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +

	return ret;
or better yet, return in the various cases above.


> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}

t struct iio_chan_spec_ext_info ad7779_ext_info_filter[] = {
> +	IIO_ENUM("data_lines", IIO_SHARED_BY_ALL, &ad7779_data_lines_enum),

New ABI.  Needs documentation in Documentation/ABI/testing/sysfs-bus-iio*

I'm not clear why we need to expose it to userspace, and documentation
might explain that to me.


> +	IIO_ENUM_AVAILABLE("data_lines", IIO_SHARED_BY_ALL,
> +			   &ad7779_data_lines_enum),
> +	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7779_filter_enum),
> +	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL,
> +			   &ad7779_filter_enum),
> +	{ }
> +};
>
> +
> +static int ad7779_register_back(struct ad7779_state *st, struct iio_dev *indio_dev)
> +{
> +	struct device *dev = &st->spi->dev;
> +	int ret = -EINVAL;
> +
> +	indio_dev->info = &ad7779_info_data;
> +
> +	if (strcmp(st->chip_info->name, "ad7771") == 0) {

Don't do string matching.  Much preferred to add another pointer + num_channels
to chip_info.  Just add backend_channels, num_backend_channels or something like that.


> +		indio_dev->channels = ad7779_channels_filter_data;
> +		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_filter_data);
> +	} else {
> +		indio_dev->channels = ad7779_channels_data;
> +		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_data);
> +	}
> +
> +	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);
return dev_err_probe() key being that your message here has ret
different to what you return.

> +	}
> +
> +	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 = iio_backend_num_lanes_set(st->back, 4);
> +	if (ret)
> +		return ret;
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}
> +
>  static int ad7779_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -760,8 +1009,8 @@ 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");
> +	if (!spi->irq && !device_property_present(dev, "io-backends"))
> +		return dev_err_probe(dev, ret, "Either DRDY interrupt or io-backends property required\n");

Very long line. break before the string at least.

In the binding you aren't disallowing both the irq and io-backends.
That's fine but I wonder here if we should prioritize io-backends
if both are set? 

>  
>  	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>  	if (!indio_dev)
> @@ -804,49 +1053,12 @@ 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;
>  
> -	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 devm_iio_device_register(dev, indio_dev);

This call happens in bother cases. I'd be tempted to rename the functions
as setup_irq() / setup_back() and keep this call outside of either
function.

> +	if (spi->irq)
> +		return ad7779_register_irq(st, indio_dev);
> +	else
> +		return ad7779_register_back(st, indio_dev);
>  }



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

* Re: [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x
  2025-07-28 13:43 ` [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x Ioana Risteiu
@ 2025-07-28 14:51   ` Nuno Sá
  0 siblings, 0 replies; 11+ messages in thread
From: Nuno Sá @ 2025-07-28 14:51 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 Mon, Jul 28, 2025 at 04:43:34PM +0300, Ioana Risteiu wrote:
> Add new compatible string and corresponding iio_backend_ops for AD777x
> axi family.
> 
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
> ---
>  drivers/iio/adc/adi-axi-adc.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
> index 2d86bb0e08a7..c4b8ec6d9397 100644
> --- a/drivers/iio/adc/adi-axi-adc.c
> +++ b/drivers/iio/adc/adi-axi-adc.c
> @@ -670,6 +670,25 @@ static const struct iio_backend_info axi_ad408x = {
>  	.ops = &adi_ad408x_ops,
>  };
>  
> +static const struct iio_backend_ops adi_ad777x_ops = {
> +	.enable = axi_adc_enable,
> +	.disable = axi_adc_disable,
> +	.chan_enable = axi_adc_chan_enable,
> +	.chan_disable = axi_adc_chan_disable,
> +	.request_buffer = axi_adc_request_buffer,
> +	.free_buffer = axi_adc_free_buffer,
> +	.data_sample_trigger = axi_adc_data_sample_trigger,
> +	.chan_status = axi_adc_chan_status,
> +	.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),
> +	.num_lanes_set = axi_adc_num_lanes_set,
> +};

Hmm looking at the above I wonder about the specific compatible? We
could add one if we want to have more strict validation on the possible 'num_lanes' passed
into axi_adc_num_lanes_set().

- Nuno Sá

> +
> +static const struct iio_backend_info axi_ad777x = {
> +	.name = "axi-ad777x",
> +	.ops = &adi_ad777x_ops,
> +};
> +
>  static int adi_axi_adc_probe(struct platform_device *pdev)
>  {
>  	struct adi_axi_adc_state *st;
> @@ -790,12 +809,18 @@ static const struct axi_adc_info adi_axi_ad408x = {
>  	.backend_info = &axi_ad408x,
>  };
>  
> +static const struct axi_adc_info adi_axi_ad777x = {
> +	.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
> +	.backend_info = &axi_ad777x,
> +};
> +
>  /* Match table for of_platform binding */
>  static const struct of_device_id adi_axi_adc_of_match[] = {
>  	{ .compatible = "adi,axi-adc-10.0.a", .data = &adc_generic },
>  	{ .compatible = "adi,axi-ad408x", .data = &adi_axi_ad408x },
>  	{ .compatible = "adi,axi-ad485x", .data = &adi_axi_ad485x },
>  	{ .compatible = "adi,axi-ad7606x", .data = &adc_ad7606 },
> +	{ .compatible = "adi,axi-ad777x", .data = &adi_axi_ad777x},
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match);
> -- 
> 2.47.2
> 

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

* Re: [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend
  2025-07-28 13:43 ` [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend Ioana Risteiu
  2025-07-28 14:10   ` Jonathan Cameron
@ 2025-07-28 15:11   ` Nuno Sá
  1 sibling, 0 replies; 11+ messages in thread
From: Nuno Sá @ 2025-07-28 15:11 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 Mon, Jul 28, 2025 at 04:43:36PM +0300, Ioana Risteiu 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>
> ---
>  drivers/iio/adc/ad7779.c | 299 +++++++++++++++++++++++++++++++++------
>  1 file changed, 256 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c
> index 845adc510239..872c551eadf6 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);
>

...

>  
> +static const struct iio_chan_spec_ext_info ad7779_ext_info_filter[] = {
> +	IIO_ENUM("data_lines", IIO_SHARED_BY_ALL, &ad7779_data_lines_enum),
> +	IIO_ENUM_AVAILABLE("data_lines", IIO_SHARED_BY_ALL,
> +			   &ad7779_data_lines_enum),
> +	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7779_filter_enum),
> +	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL,
> +			   &ad7779_filter_enum),
> +	{ }
> +};
> +

I guess this can get simpler... Do we really want to control data_lanes
at runtime? From my experience that's a DT parameter and it's not
something you can change at runtime. Often is a synthesis parameter on
the IP core (backend side).


>  #define AD777x_CHAN_S(index, _ext_info)					\
>  	{								\
>  		.type = IIO_VOLTAGE,					\
> @@ -669,11 +788,34 @@ static const struct iio_chan_spec_ext_info ad7779_ext_filter[] = {
>  		},							\
>  	}
>  
> +#define AD777X_CHAN(index, _ext_info)					       \
> +	{								       \
> +		.type = IIO_VOLTAGE,					       \
> +		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),       \
> +		.address = (index),					       \
> +		.indexed = 1,						       \
> +		.channel = (index),					       \
> +		.scan_index = (index),					       \
> +		.ext_info = (_ext_info),				       \
> +		.scan_type = {						       \
> +			.sign = 's',					       \
> +			.realbits = 24,					       \
> +			.storagebits = 32,				       \
> +		},							       \
> +	}
> +
>  #define AD777x_CHAN_NO_FILTER_S(index)					\
>  	AD777x_CHAN_S(index, NULL)
>  
> +#define AD777X_CHAN_NO_FILTER(index)					       \
> +	AD777X_CHAN(index, ad7779_ext_info)
> +
>  #define AD777x_CHAN_FILTER_S(index)					\
>  	AD777x_CHAN_S(index, ad7779_ext_filter)
> +
> +#define AD777X_CHAN_FILTER(index)					       \
> +	AD777X_CHAN(index, ad7779_ext_info_filter)
> +
>  static const struct iio_chan_spec ad7779_channels[] = {
>  	AD777x_CHAN_NO_FILTER_S(0),
>  	AD777x_CHAN_NO_FILTER_S(1),
> @@ -686,6 +828,17 @@ static const struct iio_chan_spec ad7779_channels[] = {
>  	IIO_CHAN_SOFT_TIMESTAMP(8),
>  };
>  
> +static const struct iio_chan_spec ad7779_channels_data[] = {
> +	AD777X_CHAN_NO_FILTER(0),
> +	AD777X_CHAN_NO_FILTER(1),
> +	AD777X_CHAN_NO_FILTER(2),
> +	AD777X_CHAN_NO_FILTER(3),
> +	AD777X_CHAN_NO_FILTER(4),
> +	AD777X_CHAN_NO_FILTER(5),
> +	AD777X_CHAN_NO_FILTER(6),
> +	AD777X_CHAN_NO_FILTER(7),
> +};
> +
>  static const struct iio_chan_spec ad7779_channels_filter[] = {
>  	AD777x_CHAN_FILTER_S(0),
>  	AD777x_CHAN_FILTER_S(1),
> @@ -698,6 +851,17 @@ static const struct iio_chan_spec ad7779_channels_filter[] = {
>  	IIO_CHAN_SOFT_TIMESTAMP(8),
>  };
>  
> +static const struct iio_chan_spec ad7779_channels_filter_data[] = {
> +	AD777X_CHAN_FILTER(0),
> +	AD777X_CHAN_FILTER(1),
> +	AD777X_CHAN_FILTER(2),
> +	AD777X_CHAN_FILTER(3),
> +	AD777X_CHAN_FILTER(4),
> +	AD777X_CHAN_FILTER(5),
> +	AD777X_CHAN_FILTER(6),
> +	AD777X_CHAN_FILTER(7),
> +};
> +
>  static const struct iio_buffer_setup_ops ad7779_buffer_setup_ops = {
>  	.preenable = ad7779_buffer_preenable,
>  	.postdisable = ad7779_buffer_postdisable,
> @@ -752,6 +916,91 @@ static int ad7779_conf(struct ad7779_state *st, struct gpio_desc *start_gpio)
>  	return 0;
>  }
>  
> +static int ad7779_register_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;
> +	indio_dev->num_channels = ARRAY_SIZE(ad7779_channels);
> +

We might be able to get the above in a generic way... See below.

> +	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 devm_iio_device_register(dev, indio_dev);
> +}
> +
> +static int ad7779_register_back(struct ad7779_state *st, struct iio_dev *indio_dev)
> +{
> +	struct device *dev = &st->spi->dev;
> +	int ret = -EINVAL;
> +
> +	indio_dev->info = &ad7779_info_data;
> +
> +	if (strcmp(st->chip_info->name, "ad7771") == 0) {
> +		indio_dev->channels = ad7779_channels_filter_data;
> +		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_filter_data);
> +	} else {
> +		indio_dev->channels = ad7779_channels_data;
> +		indio_dev->num_channels = ARRAY_SIZE(ad7779_channels_data);
> +	}

I wonder if it makes sense to add a new compatible since our userspace
interface will be considerable different (similar to what was done in
[1]? This would make things easier to handle for the above. If not, I
would likely introduce a "has_filter" boolean in chip info for the
above.

> +
> +	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 = iio_backend_num_lanes_set(st->back, 4);
> +	if (ret)
> +		return ret;
> +
> +	return devm_iio_device_register(dev, indio_dev);

The above is repeated in ad7779_register_irq(). You can take it out and
do it in ad7779_probe().

> +}
> +
>  static int ad7779_probe(struct spi_device *spi)
>  {
>  	struct iio_dev *indio_dev;
> @@ -760,8 +1009,8 @@ 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");

The above could be a cleanup patch. I mean just drop the check and let
devm_request_irq() in case an interrupt is not present.

> +	if (!spi->irq && !device_property_present(dev, "io-backends"))
> +		return dev_err_probe(dev, ret, "Either DRDY interrupt or io-backends property required\n");

Then, we could just use device_property_present() to decide which
probing path to follow.

>  
>  	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>  	if (!indio_dev)
> @@ -804,49 +1053,12 @@ 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;
>  
> -	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;
device_property_present> -
> -	return devm_iio_device_register(dev, indio_dev);

Arguably, ad7779_register_irq() could be introduced in a precursor
patch.

> +	if (spi->irq)
> +		return ad7779_register_irq(st, indio_dev);
> +	else
> +		return ad7779_register_back(st, indio_dev);

Redundante else...

- Nuno Sá

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

* Re: [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant
  2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
  2025-07-28 13:57   ` Jonathan Cameron
@ 2025-07-30 21:06   ` Rob Herring (Arm)
  1 sibling, 0 replies; 11+ messages in thread
From: Rob Herring (Arm) @ 2025-07-30 21:06 UTC (permalink / raw)
  To: Ioana Risteiu
  Cc: Nuno Sá, Lars-Peter Clausen, linux-iio, David Lechner,
	Conor Dooley, devicetree, Ramona Nechita, Michael Hennerich,
	Jonathan Cameron, linux-kernel, Andy Shevchenko,
	Krzysztof Kozlowski


On Mon, 28 Jul 2025 16:43:33 +0300, Ioana Risteiu wrote:
> Add a new compatible for the AD777x AXI IP core, a variant of the
> generic AXI ADC IP.
> 
> While sharing some operations with the generic AXI ADC IP, the AD777x
> variant has specific requirements such as setting number of lanes.
> 
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
> ---
>  Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 2 ++
>  1 file changed, 2 insertions(+)
> 

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


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

* Re: [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support
  2025-07-28 13:43 ` [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support Ioana Risteiu
@ 2025-07-30 21:06   ` Rob Herring (Arm)
  0 siblings, 0 replies; 11+ messages in thread
From: Rob Herring (Arm) @ 2025-07-30 21:06 UTC (permalink / raw)
  To: Ioana Risteiu
  Cc: Conor Dooley, linux-kernel, linux-iio, Lars-Peter Clausen,
	Ramona Nechita, David Lechner, Krzysztof Kozlowski,
	Michael Hennerich, Nuno Sá, Jonathan Cameron, devicetree,
	Andy Shevchenko


On Mon, 28 Jul 2025 16:43:35 +0300, Ioana Risteiu wrote:
> Add the generic io-backends property to the AD7779 binding to enable
> support for the IIO backend framework.
> 
> Signed-off-by: Ioana Risteiu <Ioana.Risteiu@analog.com>
> ---
>  .../bindings/iio/adc/adi,ad7779.yaml          | 26 ++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 

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


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

end of thread, other threads:[~2025-07-30 21:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28 13:43 [PATCH 0/4] Add IIO backend support for AD7779 Ioana Risteiu
2025-07-28 13:43 ` [PATCH 1/4] dt-bindigs: iio: adc: Add ad777x axi variant Ioana Risteiu
2025-07-28 13:57   ` Jonathan Cameron
2025-07-30 21:06   ` Rob Herring (Arm)
2025-07-28 13:43 ` [PATCH 2/4] iio: adc: adi-axi-adc: Add support for ad777x Ioana Risteiu
2025-07-28 14:51   ` Nuno Sá
2025-07-28 13:43 ` [PATCH 3/4] dt-bindings: iio: adc: Add IIO backend support Ioana Risteiu
2025-07-30 21:06   ` Rob Herring (Arm)
2025-07-28 13:43 ` [PATCH 4/4] iio: adc: Update ad7779 to use IIO backend Ioana Risteiu
2025-07-28 14:10   ` Jonathan Cameron
2025-07-28 15:11   ` Nuno Sá

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