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
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á
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);
> }
© 2016 - 2026 Red Hat, Inc.