Skip to contentSkip to conversation

Add support for AD4080 ADC

PATCH Superseded Antoniu Miclaus 4 participants 25 messages Apr 11, 2025 – Apr 25, 2025

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

v2 cover Add support for AD4080 ADC

The AD4080 is a high-speed, low noise, low distortion, 20-bit, Easy Drive, successive approximation register (SAR) analog-to-digital converter (ADC). Maintaining high performance (signal-to-noise and distortion (SINAD) ratio > 90 dBFS) at signal frequencies in excess of 1 MHz enables the AD4080 to service a wide variety of precision, wide bandwidth data acquisition applications.

This driver aims to be extended in the future to support multiple parts that are not released yet:

    AD4081
    AD4082
    AD4083
    AD4084
    AD4085
    AD4086
    AD4087
    AD4088

Antoniu Miclaus (13):
iio: backend: add support for filter config
iio: backend: add support for sync process
iio: backend: add support for self sync
iio: backend: add support for sync status
iio: backend: add support for number of lanes
dt-bindings: iio: adc: add ad408x axi variant
iio: adc: adi-axi-adc: add filter enable/disable
iio: adc: adi-axi-adc: add bitslip enable/disable
iio: adc: adi-axi-adc: add self sync support
iio: adc: adi-axi-adc: add sync status
iio: adc: adi-axi-adc: add num lanes support
dt-bindings: iio: adc: add ad4080
iio: adc: ad4080: add driver support

 .../bindings/iio/adc/adi,ad4080.yaml          |  96 +++
 .../bindings/iio/adc/adi,axi-adc.yaml         |   2 +
 drivers/iio/adc/Kconfig                       |  14 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/ad4080.c                      | 653 ++++++++++++++++++
 drivers/iio/adc/adi-axi-adc.c                 | 115 +++
 drivers/iio/industrialio-backend.c            | 113 +++
 include/linux/iio/backend.h                   |  24 +
 8 files changed, 1018 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml
 create mode 100644 drivers/iio/adc/ad4080.c
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v2 1/13 iio: backend: add support for filter config

Add backend support for digital filter enable/disable.

This setting can be adjusted within the IP cores interfacing devices.

The IP core can be configured based on the state of the actual digital filter configuration of the part.

---
changes in v2:
- improve commit description

 drivers/iio/industrialio-backend.c | 26 ++++++++++++++++++++++++++
 include/linux/iio/backend.h        |  6 ++++++
 2 files changed, 32 insertions(+)
drivers/iio/industrialio-backend.c +26 -0
index d4ad36f54090..ffafe7c73508 100644
@@ -778,6 +778,32 @@ static int __devm_iio_backend_get(struct device *dev, struct iio_backend *back)
 	return 0;
 }
 
+/**
+ * iio_backend_filter_enable - Enable filter
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_filter_enable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, filter_enable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_filter_enable, "IIO_BACKEND");
+
+/**
+ * iio_backend_filter_disable - Disable filter
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_filter_disable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, filter_disable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_filter_disable, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +6 -0
index e45b7dfbec35..7987d9f1cdb3 100644
@@ -100,6 +100,8 @@ enum iio_backend_interface_type {
  * @read_raw: Read a channel attribute from a backend device
  * @debugfs_print_chan_status: Print channel status into a buffer.
  * @debugfs_reg_access: Read or write register value of backend.
+ * @filter_enable: Enable filter.
+ * @filter_disable: Disable filter.
  * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
  * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
  * @data_stream_enable: Enable data stream.
@@ -150,6 +152,8 @@ struct iio_backend_ops {
 					 size_t len);
 	int (*debugfs_reg_access)(struct iio_backend *back, unsigned int reg,
 				  unsigned int writeval, unsigned int *readval);
+	int (*filter_enable)(struct iio_backend *back);
+	int (*filter_disable)(struct iio_backend *back);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -190,6 +194,8 @@ int iio_backend_data_sample_trigger(struct iio_backend *back,
 int devm_iio_backend_request_buffer(struct device *dev,
 				    struct iio_backend *back,
 				    struct iio_dev *indio_dev);
+int iio_backend_filter_enable(struct iio_backend *back);
+int iio_backend_filter_disable(struct iio_backend *back);
 int iio_backend_ddr_enable(struct iio_backend *back);
 int iio_backend_ddr_disable(struct iio_backend *back);
 int iio_backend_data_stream_enable(struct iio_backend *back);
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH v2 01/13] iio: backend: add support for filter config

Hi Antoniu,

I do not have time today for going through all the series but I'll already leave my comment on this on..

Quoted 40 lines · Antoniu Miclaus

Add backend support for digital filter enable/disable.

This setting can be adjusted within the IP cores interfacing devices.

The IP core can be configured based on the state of the actual digital filter configuration of the part.

---
changes in v2:
 - improve commit description drivers/iio/industrialio-backend.c | 26 ++++++++++++++++++++++++++ include/linux/iio/backend.h        |  6 ++++++

 2 files changed, 32 insertions(+)
drivers/iio/industrialio- renamed from drivers/iio/industrialio-backend.c +0 -0

backend.c
index d4ad36f54090..ffafe7c73508 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -778,6 +778,32 @@ static int __devm_iio_backend_get(struct device *dev,
 struct iio_backend *back)
  	return 0;
  }

drivers/iio/industrialio-backend.c +15 -0
+/**
+ * iio_backend_filter_enable - Enable filter
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_filter_enable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, filter_enable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_filter_enable, "IIO_BACKEND");
+
+/**
+ * iio_backend_filter_disable - Disable filter

drivers/iio/industrialio-backend.c static int __devm_iio_backend_get(struct device *dev, struct iio_backend *back) · line 805

Quoted 10 lines
drivers/iio/industrialio-backend.c +10 -0
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_filter_disable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, filter_disable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_filter_disable, "IIO_BACKEND");

This seems to resemble the filter_type IIO attr so I would likely be more explicit in the API naming. Like 'iio_backend_filter_type_set()'. And that also takes me into the more important point. I would consider having this API taking an unsigned int filter_type (or an enum with the same possibilities as defined in the ABI) argument rather than an enable vs disable thing. Like this, we're just thinking about this particular usecase but it can very well happen that in the future some backends might need to know the specific filter being configured. Sure we could change things later on but doing it now is pretty straight so why not :)?

- Nuno Sá

author maintainer
#3 lore raw

PATCH v2 2/13 iio: backend: add support for sync process

In reply to Antoniu Miclaus

Add backend support for enabling/disabling the sync process for devices that have data capture synchronization done through bit-slip (correct data allignment) procedure and not through and external hardware pin. This setting can be adjusted within the IP cores interfacing devices.

---
changes in v2:
- rename function for better clarity.
- improve commit description

 drivers/iio/industrialio-backend.c | 26 ++++++++++++++++++++++++++
 include/linux/iio/backend.h        |  6 ++++++
 2 files changed, 32 insertions(+)
drivers/iio/industrialio-backend.c +26 -0
index ffafe7c73508..60578267643d 100644
@@ -804,6 +804,32 @@ int iio_backend_filter_disable(struct iio_backend *back)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_filter_disable, "IIO_BACKEND");
 
+/**
+ * iio_backend_data_alignment_enable - Enable the sync process.
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_data_alignment_enable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, data_alignment_enable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_data_alignment_enable, "IIO_BACKEND");
+
+/**
+ * iio_backend_data_alignment_disable - Disable the sync process.
+ * @back: Backend device
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_data_alignment_disable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, data_alignment_disable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_data_alignment_disable, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +6 -0
index 7987d9f1cdb3..beff66d18151 100644
@@ -102,6 +102,8 @@ enum iio_backend_interface_type {
  * @debugfs_reg_access: Read or write register value of backend.
  * @filter_enable: Enable filter.
  * @filter_disable: Disable filter.
+ * @data_alignment_enable: Enable sync process.
+ * @data_alignment_disable: Disable sync process.
  * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
  * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
  * @data_stream_enable: Enable data stream.
@@ -154,6 +156,8 @@ struct iio_backend_ops {
 				  unsigned int writeval, unsigned int *readval);
 	int (*filter_enable)(struct iio_backend *back);
 	int (*filter_disable)(struct iio_backend *back);
+	int (*data_alignment_enable)(struct iio_backend *back);
+	int (*data_alignment_disable)(struct iio_backend *back);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -196,6 +200,8 @@ int devm_iio_backend_request_buffer(struct device *dev,
 				    struct iio_dev *indio_dev);
 int iio_backend_filter_enable(struct iio_backend *back);
 int iio_backend_filter_disable(struct iio_backend *back);
+int iio_backend_data_alignment_enable(struct iio_backend *back);
+int iio_backend_data_alignment_disable(struct iio_backend *back);
 int iio_backend_ddr_enable(struct iio_backend *back);
 int iio_backend_ddr_disable(struct iio_backend *back);
 int iio_backend_data_stream_enable(struct iio_backend *back);
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH v2 3/13 iio: backend: add support for self sync

In reply to Antoniu Miclaus

Add iio backend support for self sync enable/disable. When disabled data capture synchronization is done through CNV signal, otherwise through bit-slip.

---
no changes in v2.

 drivers/iio/industrialio-backend.c | 30 ++++++++++++++++++++++++++++++
 include/linux/iio/backend.h        |  6 ++++++
 2 files changed, 36 insertions(+)
drivers/iio/industrialio-backend.c +30 -0
index 60578267643d..cb23433b22c6 100644
@@ -830,6 +830,36 @@ int iio_backend_data_alignment_disable(struct iio_backend *back)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_data_alignment_disable, "IIO_BACKEND");
 
+/**
+ * iio_backend_self_sync_enable - Enable the self sync data capture.
+ * @back: Backend device
+ *
+ * Data capture synchronization is done through bit-slip.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_self_sync_enable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, self_sync_enable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_self_sync_enable, "IIO_BACKEND");
+
+/**
+ * iio_backend_self_sync_disable - Disable the self sync data capture.
+ * @back: Backend device
+ *
+ * Data capture synchronization is done through CNV signal.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_self_sync_disable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, self_sync_disable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_self_sync_disable, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +6 -0
index beff66d18151..6d006cb0da5a 100644
@@ -104,6 +104,8 @@ enum iio_backend_interface_type {
  * @filter_disable: Disable filter.
  * @data_alignment_enable: Enable sync process.
  * @data_alignment_disable: Disable sync process.
+ * @self_sync_enable: Enable the self sync data capture.
+ * @self_sync_disable: Disable the self sync data capture.
  * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
  * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
  * @data_stream_enable: Enable data stream.
@@ -158,6 +160,8 @@ struct iio_backend_ops {
 	int (*filter_disable)(struct iio_backend *back);
 	int (*data_alignment_enable)(struct iio_backend *back);
 	int (*data_alignment_disable)(struct iio_backend *back);
+	int (*self_sync_enable)(struct iio_backend *back);
+	int (*self_sync_disable)(struct iio_backend *back);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -202,6 +206,8 @@ int iio_backend_filter_enable(struct iio_backend *back);
 int iio_backend_filter_disable(struct iio_backend *back);
 int iio_backend_data_alignment_enable(struct iio_backend *back);
 int iio_backend_data_alignment_disable(struct iio_backend *back);
+int iio_backend_self_sync_enable(struct iio_backend *back);
+int iio_backend_self_sync_disable(struct iio_backend *back);
 int iio_backend_ddr_enable(struct iio_backend *back);
 int iio_backend_ddr_disable(struct iio_backend *back);
 int iio_backend_data_stream_enable(struct iio_backend *back);
Signature · 1 line
2.49.0
#5 lore raw

Re: [PATCH v2 03/13] iio: backend: add support for self sync

Quoted 4 lines · Antoniu Miclaus

Add iio backend support for self sync enable/disable. When disabled data capture synchronization is done through CNV signal, otherwise through bit-slip.

It is still not clear what API's will come out of this but you need to improve the commit description (and the API docs). Note that the above is very focused on your use case and you're just using the same names defined in the device docs and hdl IP. While that might be ok for the device drivers commits, it is not that nice for something that "tries" to be more generic.

This is true for all the new API's being introduced...

- Nuno Sá

Quoted 81 lines

---
no changes in v2.
 drivers/iio/industrialio-backend.c | 30 ++++++++++++++++++++++++++++++ include/linux/iio/backend.h        |  6 ++++++

 2 files changed, 36 insertions(+)
drivers/iio/industrialio- renamed from drivers/iio/industrialio-backend.c +0 -0

backend.c
index 60578267643d..cb23433b22c6 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -830,6 +830,36 @@ int iio_backend_data_alignment_disable(struct iio_backend
 *back)
  }
  EXPORT_SYMBOL_NS_GPL(iio_backend_data_alignment_disable, "IIO_BACKEND");

drivers/iio/industrialio-backend.c +30 -0
+/**
+ * iio_backend_self_sync_enable - Enable the self sync data capture.
+ * @back: Backend device
+ *
+ * Data capture synchronization is done through bit-slip.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_self_sync_enable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, self_sync_enable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_self_sync_enable, "IIO_BACKEND");
+
+/**
+ * iio_backend_self_sync_disable - Disable the self sync data capture.
+ * @back: Backend device
+ *
+ * Data capture synchronization is done through CNV signal.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_self_sync_disable(struct iio_backend *back)
+{
+	return iio_backend_op_call(back, self_sync_disable);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_self_sync_disable, "IIO_BACKEND");
+

 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device

include/linux/iio/backend.h +6 -0
index beff66d18151..6d006cb0da5a 100644
@@ -104,6 +104,8 @@ enum iio_backend_interface_type {
   * @filter_disable: Disable filter.
   * @data_alignment_enable: Enable sync process.
   * @data_alignment_disable: Disable sync process.
+ * @self_sync_enable: Enable the self sync data capture.
+ * @self_sync_disable: Disable the self sync data capture.
   * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
   * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
   * @data_stream_enable: Enable data stream.
@@ -158,6 +160,8 @@ struct iio_backend_ops {
  	int (*filter_disable)(struct iio_backend *back);
  	int (*data_alignment_enable)(struct iio_backend *back);
  	int (*data_alignment_disable)(struct iio_backend *back);
+	int (*self_sync_enable)(struct iio_backend *back);
+	int (*self_sync_disable)(struct iio_backend *back);
  	int (*ddr_enable)(struct iio_backend *back);
  	int (*ddr_disable)(struct iio_backend *back);
  	int (*data_stream_enable)(struct iio_backend *back);
@@ -202,6 +206,8 @@ int iio_backend_filter_enable(struct iio_backend *back);
  int iio_backend_filter_disable(struct iio_backend *back);
  int iio_backend_data_alignment_enable(struct iio_backend *back);
  int iio_backend_data_alignment_disable(struct iio_backend *back);
+int iio_backend_self_sync_enable(struct iio_backend *back);
+int iio_backend_self_sync_disable(struct iio_backend *back);
  int iio_backend_ddr_enable(struct iio_backend *back);
  int iio_backend_ddr_disable(struct iio_backend *back);
  int iio_backend_data_stream_enable(struct iio_backend *back);
author maintainer
#6 lore raw

PATCH v2 4/13 iio: backend: add support for sync status

In reply to Antoniu Miclaus

Add iio backend support for synchronization status read.
The return value is a boolean stating if the synchronization is enabled or disabled.

---
no changes in v2.

 drivers/iio/industrialio-backend.c | 14 ++++++++++++++
 include/linux/iio/backend.h        |  3 +++
 2 files changed, 17 insertions(+)
drivers/iio/industrialio-backend.c +14 -0
index cb23433b22c6..0b27f88d6c27 100644
@@ -860,6 +860,20 @@ int iio_backend_self_sync_disable(struct iio_backend *back)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_self_sync_disable, "IIO_BACKEND");
 
+/**
+ * iio_backend_sync_status_get - Read the syncronization status
+ * @back: Backend device
+ * @sync_en: Synchronization status returned (enabled or disabled)
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_sync_status_get(struct iio_backend *back, bool *sync_en)
+{
+	return iio_backend_op_call(back, sync_status_get, sync_en);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_sync_status_get, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +3 -0
index 6d006cb0da5a..9bf03181c5c1 100644
@@ -106,6 +106,7 @@ enum iio_backend_interface_type {
  * @data_alignment_disable: Disable sync process.
  * @self_sync_enable: Enable the self sync data capture.
  * @self_sync_disable: Disable the self sync data capture.
+ * @sync_status_get: Get the syncronization status (enabled/disabled).
  * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
  * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
  * @data_stream_enable: Enable data stream.
@@ -162,6 +163,7 @@ struct iio_backend_ops {
 	int (*data_alignment_disable)(struct iio_backend *back);
 	int (*self_sync_enable)(struct iio_backend *back);
 	int (*self_sync_disable)(struct iio_backend *back);
+	int (*sync_status_get)(struct iio_backend *back, bool *sync_en);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -208,6 +210,7 @@ int iio_backend_data_alignment_enable(struct iio_backend *back);
 int iio_backend_data_alignment_disable(struct iio_backend *back);
 int iio_backend_self_sync_enable(struct iio_backend *back);
 int iio_backend_self_sync_disable(struct iio_backend *back);
+int iio_backend_sync_status_get(struct iio_backend *back, bool *sync_en);
 int iio_backend_ddr_enable(struct iio_backend *back);
 int iio_backend_ddr_disable(struct iio_backend *back);
 int iio_backend_data_stream_enable(struct iio_backend *back);
Signature · 1 line
2.49.0
author maintainer
#7 lore raw

PATCH v2 5/13 iio: backend: add support for number of lanes

In reply to Antoniu Miclaus

Add iio backend support for number of lanes to be enabled.

---
no changes in v2.

 drivers/iio/industrialio-backend.c | 17 +++++++++++++++++
 include/linux/iio/backend.h        |  3 +++
 2 files changed, 20 insertions(+)
drivers/iio/industrialio-backend.c +17 -0
index 0b27f88d6c27..85cb8b0d2f09 100644
@@ -874,6 +874,23 @@ int iio_backend_sync_status_get(struct iio_backend *back, bool *sync_en)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_sync_status_get, "IIO_BACKEND");
 
+/**
+ * iio_backend_num_lanes_set - Number of lanes enabled.
+ * @back: Backend device
+ * @num_lanes: Number of lanes.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_num_lanes_set(struct iio_backend *back, unsigned int num_lanes)
+{
+	if (!num_lanes)
+		return -EINVAL;
+
+	return iio_backend_op_call(back, num_lanes_set, num_lanes);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_num_lanes_set, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +3 -0
index 9bf03181c5c1..cdd39c97ba1a 100644
@@ -107,6 +107,7 @@ enum iio_backend_interface_type {
  * @self_sync_enable: Enable the self sync data capture.
  * @self_sync_disable: Disable the self sync data capture.
  * @sync_status_get: Get the syncronization status (enabled/disabled).
+ * @num_lanes_set: Set the number of lanes enabled.
  * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
  * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
  * @data_stream_enable: Enable data stream.
@@ -164,6 +165,7 @@ struct iio_backend_ops {
 	int (*self_sync_enable)(struct iio_backend *back);
 	int (*self_sync_disable)(struct iio_backend *back);
 	int (*sync_status_get)(struct iio_backend *back, bool *sync_en);
+	int (*num_lanes_set)(struct iio_backend *back, unsigned int num_lanes);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -211,6 +213,7 @@ int iio_backend_data_alignment_disable(struct iio_backend *back);
 int iio_backend_self_sync_enable(struct iio_backend *back);
 int iio_backend_self_sync_disable(struct iio_backend *back);
 int iio_backend_sync_status_get(struct iio_backend *back, bool *sync_en);
+int iio_backend_num_lanes_set(struct iio_backend *back, unsigned int num_lanes);
 int iio_backend_ddr_enable(struct iio_backend *back);
 int iio_backend_ddr_disable(struct iio_backend *back);
 int iio_backend_data_stream_enable(struct iio_backend *back);
Signature · 1 line
2.49.0
author maintainer
#8 lore raw

PATCH v2 6/13 dt-bindings: iio: adc: add ad408x axi variant

In reply to Antoniu Miclaus

Add a new compatible and related bindings for the fpga-based AD408x AXI IP core, a variant of the generic AXI ADC IP.

The AXI AD408x IP is a very similar HDL (fpga) variant of the generic AXI ADC IP, intended to control ad408x familiy.

Although there are some particularities added for extended control of the ad408x devices such as the filter configuration, data capture synchronization procedure and number of lanes enabled.

Wildcard naming is used to match the naming of the published firmware.

---
changes in v2:
- improve commit description.

 Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml +2 -0
index cf74f84d6103..e91e421a3d6b 100644
@@ -27,6 +27,7 @@ description: |
       the ad7606 family.
 
   https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
+  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
 
@@ -34,6 +35,7 @@ properties:
   compatible:
     enum:
       - adi,axi-adc-10.0.a
+      - adi,axi-ad408x
       - adi,axi-ad7606x
       - adi,axi-ad485x
 
Signature · 1 line
2.49.0
maintainer Acked-by on v2 6/13
#9 lore raw

Re: [PATCH v2 06/13] dt-bindings: iio: adc: add ad408x axi variant

Quoted 13 lines · Antoniu Miclaus

Add a new compatible and related bindings for the fpga-based AD408x AXI IP core, a variant of the generic AXI ADC IP.

The AXI AD408x IP is a very similar HDL (fpga) variant of the generic AXI ADC IP, intended to control ad408x familiy.

Although there are some particularities added for extended control of the ad408x devices such as the filter configuration, data capture synchronization procedure and number of lanes enabled.

Wildcard naming is used to match the naming of the published firmware.

Quoted 7 lines

---
changes in v2:
- improve commit description.

 Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 2 ++
 1 file changed, 2 insertions(+)
author maintainer
#10 lore raw

PATCH v2 7/13 iio: adc: adi-axi-adc: add filter enable/disable

In reply to Antoniu Miclaus

Add support for enabling/disabling the filter.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 42 +++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
drivers/iio/adc/adi-axi-adc.c +42 -0
index 61ab7dce43be..d4466e02fc28 100644
@@ -52,6 +52,7 @@
 #define   AXI_AD485X_PACKET_FORMAT_20BIT	0x0
 #define   AXI_AD485X_PACKET_FORMAT_24BIT	0x1
 #define   AXI_AD485X_PACKET_FORMAT_32BIT	0x2
+#define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)
 
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
@@ -402,6 +403,22 @@ static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
 	}
 }
 
+static int axi_adc_ad408x_filter_enable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+			       AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
+}
+
+static int axi_adc_ad408x_filter_disable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_clear_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				 AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -582,6 +599,25 @@ static const struct iio_backend_info axi_ad485x = {
 	.ops = &adi_ad485x_ops,
 };
 
+static const struct iio_backend_ops adi_ad408x_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,
+	.filter_enable = axi_adc_ad408x_filter_enable,
+	.filter_disable = axi_adc_ad408x_filter_disable,
+	.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),
+};
+
+static const struct iio_backend_info axi_ad408x = {
+	.name = "axi-ad408x",
+	.ops = &adi_ad408x_ops,
+};
+
 static int adi_axi_adc_probe(struct platform_device *pdev)
 {
 	struct adi_axi_adc_state *st;
@@ -697,9 +733,15 @@ static const struct axi_adc_info adc_ad7606 = {
 	.has_child_nodes = true,
 };
 
+static const struct axi_adc_info adi_axi_ad408x = {
+	.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
+	.backend_info = &axi_ad408x,
+};
+
 /* 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 },
 	{ /* end of list */ }
Signature · 1 line
2.49.0
author maintainer
#11 lore raw

PATCH v2 8/13 iio: adc: adi-axi-adc: add bitslip enable/disable

In reply to Antoniu Miclaus

Add support for enabling/disabling the sync process.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/iio/adc/adi-axi-adc.c +19 -0
index d4466e02fc28..4625acc313c4 100644
@@ -44,6 +44,7 @@
 #define   ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N	BIT(7)
 
 #define ADI_AXI_ADC_REG_CTRL			0x0044
+#define    AXI_AD408X_CTRL_BITSLIP_EN_MSK	BIT(3)
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
 #define ADI_AXI_ADC_REG_CNTRL_3			0x004c
@@ -419,6 +420,22 @@ static int axi_adc_ad408x_filter_disable(struct iio_backend *back)
 				 AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
 }
 
+static int axi_adc_ad408x_bitslip_enable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CTRL,
+			       AXI_AD408X_CTRL_BITSLIP_EN_MSK);
+}
+
+static int axi_adc_ad408x_bitslip_disable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_clear_bits(st->regmap, ADI_AXI_ADC_REG_CTRL,
+				 AXI_AD408X_CTRL_BITSLIP_EN_MSK);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -609,6 +626,8 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.data_sample_trigger = axi_adc_data_sample_trigger,
 	.filter_enable = axi_adc_ad408x_filter_enable,
 	.filter_disable = axi_adc_ad408x_filter_disable,
+	.data_alignment_enable = axi_adc_ad408x_bitslip_enable,
+	.data_alignment_disable = axi_adc_ad408x_bitslip_disable,
 	.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),
 };
Signature · 1 line
2.49.0
author maintainer
#12 lore raw

PATCH v2 9/13 iio: adc: adi-axi-adc: add self sync support

In reply to Antoniu Miclaus

Add support for data capture synchronization through CNV signal or bit-slip.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/iio/adc/adi-axi-adc.c +19 -0
index 4625acc313c4..017685854895 100644
@@ -53,6 +53,7 @@
 #define   AXI_AD485X_PACKET_FORMAT_20BIT	0x0
 #define   AXI_AD485X_PACKET_FORMAT_24BIT	0x1
 #define   AXI_AD485X_PACKET_FORMAT_32BIT	0x2
+#define   AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK	BIT(1)
 #define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)
 
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
@@ -436,6 +437,22 @@ static int axi_adc_ad408x_bitslip_disable(struct iio_backend *back)
 				 AXI_AD408X_CTRL_BITSLIP_EN_MSK);
 }
 
+static int axi_adc_ad408x_self_sync_enable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+			       AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK);
+}
+
+static int axi_adc_ad408x_self_sync_disable(struct iio_backend *back)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	return regmap_clear_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				 AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK);
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -628,6 +645,8 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.filter_disable = axi_adc_ad408x_filter_disable,
 	.data_alignment_enable = axi_adc_ad408x_bitslip_enable,
 	.data_alignment_disable = axi_adc_ad408x_bitslip_disable,
+	.self_sync_enable = axi_adc_ad408x_self_sync_enable,
+	.self_sync_disable = axi_adc_ad408x_self_sync_disable,
 	.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),
 };
Signature · 1 line
2.49.0
author maintainer
#13 lore raw

PATCH v2 10/13 iio: adc: adi-axi-adc: add sync status

In reply to Antoniu Miclaus

Add support for checking the ADC sync status.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/iio/adc/adi-axi-adc.c +20 -0
index 017685854895..0d12c0121bbc 100644
@@ -56,6 +56,9 @@
 #define   AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK	BIT(1)
 #define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)
 
+#define ADI_AXI_ADC_REG_SYNC_STATUS		0x0068
+#define   ADI_AXI_ADC_SYNC			BIT(0)
+
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 
@@ -453,6 +456,21 @@ static int axi_adc_ad408x_self_sync_disable(struct iio_backend *back)
 				 AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK);
 }
 
+static int axi_adc_sync_status_get(struct iio_backend *back, bool *sync_en)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	int ret;
+	u32 val;
+
+	ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_SYNC_STATUS, &val);
+	if (ret)
+		return ret;
+
+	*sync_en = (bool)FIELD_GET(ADI_AXI_ADC_SYNC, val);
+
+	return 0;
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -600,6 +618,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.test_pattern_set = axi_adc_test_pattern_set,
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
+	.sync_status_get = axi_adc_sync_status_get,
 	.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),
 };
@@ -647,6 +666,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.data_alignment_disable = axi_adc_ad408x_bitslip_disable,
 	.self_sync_enable = axi_adc_ad408x_self_sync_enable,
 	.self_sync_disable = axi_adc_ad408x_self_sync_disable,
+	.sync_status_get = axi_adc_sync_status_get,
 	.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),
 };
Signature · 1 line
2.49.0
maintainer
#14 lore raw

Re: [PATCH v2 10/13] iio: adc: adi-axi-adc: add sync status

Quoted 27 lines · On Fri, 11 Apr 2025 15:36:24 +0300 Antoniu Miclaus…

Add support for checking the ADC sync status.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/iio/adc/adi-axi-adc.c +4 -0
index 017685854895..0d12c0121bbc 100644
@@ -56,6 +56,9 @@
 #define   AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK	BIT(1)
 #define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)
 
+#define ADI_AXI_ADC_REG_SYNC_STATUS		0x0068
+#define   ADI_AXI_ADC_SYNC			BIT(0)
+
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 
@@ -453,6 +456,21 @@ static int axi_adc_ad408x_self_sync_disable(struct iio_backend *back)
 				 AXI_AD408X_CNTRL_3_SELF_SYNC_EN_MSK);
 }
 
+static int axi_adc_sync_status_get(struct iio_backend *back, bool *sync_en)

drivers/iio/adc/adi-axi-adc.c static int axi_adc_ad408x_self_sync_disable(struct iio_backend *back) · line 469

Quoted 10 lines
drivers/iio/adc/adi-axi-adc.c +10 -0
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	int ret;
+	u32 val;
+
+	ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_SYNC_STATUS, &val);
+	if (ret)
+		return ret;
+
+	*sync_en = (bool)FIELD_GET(ADI_AXI_ADC_SYNC, val);

Trivial but implicit casting from a bool to an int is fine. I.e. drop the (bool) as it doesn't add anything.

Quoted 23 lines
drivers/iio/adc/adi-axi-adc.c +6 -0
+
+	return 0;
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -600,6 +618,7 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 	.test_pattern_set = axi_adc_test_pattern_set,
 	.chan_status = axi_adc_chan_status,
 	.interface_type_get = axi_adc_interface_type_get,
+	.sync_status_get = axi_adc_sync_status_get,
 	.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),
 };
@@ -647,6 +666,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.data_alignment_disable = axi_adc_ad408x_bitslip_disable,
 	.self_sync_enable = axi_adc_ad408x_self_sync_enable,
 	.self_sync_disable = axi_adc_ad408x_self_sync_disable,
+	.sync_status_get = axi_adc_sync_status_get,
 	.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),
 };
author maintainer
#15 lore raw

PATCH v2 11/13 iio: adc: adi-axi-adc: add num lanes support

In reply to Antoniu Miclaus

Add support for setting the number of lanes enabled.

---
no changes in v2.

 drivers/iio/adc/adi-axi-adc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/iio/adc/adi-axi-adc.c +15 -0
index 0d12c0121bbc..8576c0c1d024 100644
@@ -44,6 +44,7 @@
 #define   ADI_AXI_ADC_REG_CONFIG_CMOS_OR_LVDS_N	BIT(7)
 
 #define ADI_AXI_ADC_REG_CTRL			0x0044
+#define    AXI_AD408X_CTRL_NUM_LANES_MSK	GENMASK(12, 8)
 #define    AXI_AD408X_CTRL_BITSLIP_EN_MSK	BIT(3)
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
@@ -471,6 +472,19 @@ static int axi_adc_sync_status_get(struct iio_backend *back, bool *sync_en)
 	return 0;
 }
 
+static int axi_adc_ad408x_num_lanes_set(struct iio_backend *back,
+				 unsigned int num_lanes)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	if (!num_lanes)
+		return -EINVAL;
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CTRL,
+				  AXI_AD408X_CTRL_NUM_LANES_MSK,
+				  FIELD_PREP(AXI_AD408X_CTRL_NUM_LANES_MSK, num_lanes));
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -667,6 +681,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.self_sync_enable = axi_adc_ad408x_self_sync_enable,
 	.self_sync_disable = axi_adc_ad408x_self_sync_disable,
 	.sync_status_get = axi_adc_sync_status_get,
+	.num_lanes_set = axi_adc_ad408x_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),
 };
Signature · 1 line
2.49.0
author maintainer
#16 lore raw

PATCH v2 12/13 dt-bindings: iio: adc: add ad4080

In reply to Antoniu Miclaus

Add devicetree bindings for ad4080 family.

---
changes in v2:
- add descripton for spi bus
- use actual pin for clock name
- fix typo in num lanes description
- add iio-backends
- don't make all supplies mandatory

 .../bindings/iio/adc/adi,ad4080.yaml          | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml
Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml new file +96 -0
new file mode 100644
index 000000000000..ed849ba1b77b
@@ -0,0 +1,96 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2025 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ad4080.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices AD4080 20-Bit, 40 MSPS, Differential SAR ADC
+
+maintainers:
+  - Antoniu Miclaus <[email protected]>
+
+description: |
+  The AD4080 is a high speed, low noise, low distortion, 20-bit, Easy Drive,
+  successive approximation register (SAR) analog-to-digital converter (ADC).
+  Maintaining high performance (signal-to-noise and distortion (SINAD) ratio
+  > 90 dBFS) at signal frequencies in excess of 1 MHz enables the AD4080 to
+  service a wide variety of precision, wide bandwidth data acquisition
+  applications.
+
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ad4080.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ad4080
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    description: Configuration of the SPI bus.
+    maximum: 50000000
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: cnv
+
+  vdd33-supply: true
+
+  vdd11-supply: true
+
+  vddldo-supply: true
+
+  iovdd-supply: true
+
+  vrefin-supply: true
+
+  io-backends:
+    maxItems: 1
+
+  adi,lvds-cnv-enable:
+    description: Enable the LVDS signal type on the CNV pin. Default is CMOS.
+    type: boolean
+
+  adi,num-lanes:
+    description:
+      Number of lanes on which the data is sent on the output (DA, DB pins).
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [1, 2]
+    default: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - vdd33-supply
+  - vrefin-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+          compatible = "adi,ad4080";
+          reg = <0>;
+          spi-max-frequency = <10000000>;
+          vdd33-supply = <&vdd33>;
+          vddldo-supply = <&vddldo>;
+          vrefin-supply = <&vrefin>;
+          clocks = <&cnv>;
+          clock-names = "cnv";
+          io-backends = <&iio_backend>;
+        };
+    };
+...
Signature · 1 line
2.49.0
maintainer Reviewed-by on v2 12/13
#17 lore raw

Re: [PATCH v2 12/13] dt-bindings: iio: adc: add ad4080

Quoted 10 lines · Antoniu Miclaus

Add devicetree bindings for ad4080 family.

---
changes in v2:
- add descripton for spi bus
- use actual pin for clock name
- fix typo in num lanes description
- add iio-backends
- don't make all supplies mandatory

Quoted 4 lines
 .../bindings/iio/adc/adi,ad4080.yaml          | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml
author maintainer
#18 lore raw

PATCH v2 13/13 iio: adc: ad4080: add driver support

In reply to Antoniu Miclaus

Add support for AD4080 high-speed, low noise, low distortion, 20-bit, Easy Drive, successive approximation register (SAR) analog-to-digital converter (ADC).

---
changes in v2:
- set num_lanes during probe.
- rename bitslitp to iio_backend_data_alignment_enable
- do ad4080_lvds_sync_write only once during probe.
- use ETIMEDOUT
- rename to cnv instead of adc-clk
- update Kconfig help section
- drop extra blank line.
- replace /** with /* for comments
- drop redundant return 0.
- use dev_dbg during while(--timeout) procedure
- use while (--timeout && !sync_en)
- return -ETIME where applicable and check missing return codes.
- regmap_update_bits used where applicable
- use defines instead of GENMASK inline.
- return FIELD_GET()
- st->filter_enabled = mode and dropping the if else statement.
- remove redundant brackets.
- use OVERSAMPLING_RATIO attribute and drop custom ABI for it
- use already existing filter_type attribute
- fix indentation
- remove comma on 'terminators'
- use dev_err_probe instead of dev_err
- check missing return values.
- rework num_lanes property parse.
- keep ad4080_chip_info since the driver will be extended for more parts in the future (also stated in cover letter).

 drivers/iio/adc/Kconfig  |  14 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad4080.c | 653 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 668 insertions(+)
 create mode 100644 drivers/iio/adc/ad4080.c
drivers/iio/adc/Kconfig +14 -0
index 27413516216c..17df328f5322 100644
@@ -47,6 +47,20 @@ config AD4030
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad4030.
 
+config AD4080
+	tristate "Analog Devices AD4080 high speed ADC"
+	depends on SPI
+	select REGMAP_SPI
+	select IIO_BACKEND
+	help
+	  Say yes here to build support for Analog Devices AD4080
+	  high speed, low noise, low distortion, 20-bit, Easy Drive,
+	  successive approximation register (SAR) analog-to-digital
+	  converter (ADC). Supports iio_backended devices for AD4080.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called ad4080.
+
 config AD4130
 	tristate "Analog Device AD4130 ADC Driver"
 	depends on SPI
drivers/iio/adc/Makefile +1 -0
index 9f26d5eca822..e6efed5b4e7a 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD4000) += ad4000.o
 obj-$(CONFIG_AD4030) += ad4030.o
+obj-$(CONFIG_AD4080) += ad4080.o
 obj-$(CONFIG_AD4130) += ad4130.o
 obj-$(CONFIG_AD4695) += ad4695.o
 obj-$(CONFIG_AD4851) += ad4851.o
drivers/iio/adc/ad4080.c new file +653 -0

653 lines not on this page · raw message

Signature · 1 line
2.49.0
maintainer
#19 lore raw

Re: [PATCH v2 13/13] iio: adc: ad4080: add driver support

Quoted 5 lines · On Fri, 11 Apr 2025 15:36:27 +0300 Antoniu Miclaus…

Add support for AD4080 high-speed, low noise, low distortion, 20-bit, Easy Drive, successive approximation register (SAR) analog-to-digital converter (ADC).

I'll leave the backend stuff to Nuno who has a better feel than me for what fits in that interface. So this is just a review of the rest of this driver.

Various minor comments inline

Thanks,

Jonathan

Quoted 5 lines
drivers/iio/adc/ad4080.c new file +0 -0
new file mode 100644
index 000000000000..3a0b1ad13765

drivers/iio/adc/ad4080.c line 114

Quoted 9 lines
drivers/iio/adc/ad4080.c new file +8 -0
 
+/* AD4080_REG_GPIO_CONFIG_B Bit Definition */
+#define AD4080_GPIO_1_SEL			GENMASK(7, 4)
+#define AD4080_GPIO_0_SEL			GENMASK(3, 0)
+
+/* AD4080_REG_FIFO_CONFIG Bit Definition */
+#define AD4080_FIFO_MODE_MSK			GENMASK(1, 0)
+
+/* AD4080_REG_FILTER_CONFIG Bit Definition */

Better to name the defines to make that association explicit. #define AD4080_FILTER_CONFIG_SINC_DEC_RATE_MSK etc

drivers/iio/adc/ad4080.c line 122

Quoted 8 lines
drivers/iio/adc/ad4080.c new file +8 -0
+#define AD4080_SINC_DEC_RATE_MSK		GENMASK(6, 3)
+#define AD4080_FILTER_SEL_MSK			GENMASK(1, 0)
+
+/* Miscellaneous Definitions */
+#define AD4080_SW_RESET				(BIT(7) | BIT(0))
+#define AD4080_SPI_READ				BIT(7)
+#define BYTE_ADDR_H				GENMASK(15, 8)
+#define BYTE_ADDR_L				GENMASK(7, 0)

Definitely not on those two!

If you are going this you are probably reading into the wrong data type.

drivers/iio/adc/ad4080.c line 139

Quoted 2 lines
drivers/iio/adc/ad4080.c new file +2 -0
+static const unsigned int ad4080_scale_table[][2] = {
+	{6000, 0},
	{ 6000, 0 },

drivers/iio/adc/ad4080.c line 150

Quoted 11 lines
drivers/iio/adc/ad4080.c new file +11 -0
+};
+
+static const char *const ad4080_filter_type_iio_enum[] = {
+	[FILTER_DISABLE]   = "disabled",
+	[SINC_1]           = "sinc1",
+	[SINC_5]           = "sinc5",
+	[SINC_5_COMP]      = "sinc5_plus_compensation",
+};
+
+static const int ad4080_dec_rate_iio_enum[] = {
+	2, 4, 8, 16, 32, 64, 128, 256, 512, 1024

Convention is keep a trailing comma except when we have an explicit terminating entry (NULL etc)

Quoted 9 lines
drivers/iio/adc/ad4080.c new file +9 -0
+
+static int ad4080_set_dec_rate(struct iio_dev *dev,
+			       const struct iio_chan_spec *chan,
+			       unsigned int mode)
+{
+	struct ad4080_state *st = iio_priv(dev);
+	int ret;
+	unsigned int data;
+	unsigned int reg_val;

drivers/iio/adc/ad4080.c line 245

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+
+	if (st->filter_type >= SINC_5 && mode >= 512)
+		return -EINVAL;
+
+	guard(mutex)(&st->lock);
+	ret = regmap_read(st->regmap, AD4080_REG_FILTER_CONFIG, &reg_val);
+	if (ret)
+		return ret;
+
+	data = ((ilog2(mode) - 1) << 3) | (reg_val & AD4080_FILTER_SEL_MSK);

As below. Odd to keep stuff with explicit mask like this rather than more normal masking out what we are placing. &= ~SINC_RET_DATA_MSK; etc

Quoted 29 lines
drivers/iio/adc/ad4080.c new file +28 -0
+	ret = regmap_write(st->regmap, AD4080_REG_FILTER_CONFIG, data);
+	if (ret)
+		return ret;
+
+	st->dec_rate = mode;
+
+	return ret;
+}
 
+static int ad4080_lvds_sync_write(struct ad4080_state *st)
+{
+	unsigned int timeout = 100;
+	bool sync_en;
+	int ret;
+
+	guard(mutex)(&st->lock);
+	if (st->num_lanes == 1)
+		ret = regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK);
+	else
+		ret = regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK |
+				   AD4080_SPI_LVDS_LANES_MSK);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);

drivers/iio/adc/ad4080.c line 328

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit Slip\n");

Maybe sleep a bit before trying again? Tight loops are very dependent on the host CPU which is probably not what you want here.

Quoted 49 lines
drivers/iio/adc/ad4080.c new file +48 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and Locked!\n");
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+					    AD4080_RESERVED_CONFIG_A_MSK);
+		else
+			return regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+					    AD4080_RESERVED_CONFIG_A_MSK |
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+					   AD4080_RESERVED_CONFIG_A_MSK);
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+					   AD4080_RESERVED_CONFIG_A_MSK |
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;
+	}
+}
 
+
+static int ad4080_set_filter_type(struct iio_dev *dev,
+				  const struct iio_chan_spec *chan,
+				  unsigned int mode)
+{
+	struct ad4080_state *st = iio_priv(dev);
+	int ret;
+	unsigned int data;
+	unsigned int reg_val;
+
+	if (mode >= SINC_5 && st->dec_rate >= 512)
+		return -EINVAL;
+
+	guard(mutex)(&st->lock);
+	if (mode)
+		ret = iio_backend_filter_enable(st->back);
+	else
+		ret = iio_backend_filter_disable(st->back);
+	if (ret)

drivers/iio/adc/ad4080.c line 400

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return ret;
+
+	st->filter_en = mode;
+
+	ret = regmap_read(st->regmap, AD4080_REG_FILTER_CONFIG, &reg_val);
+	if (ret)
+		return ret;
+
+	data = (reg_val & AD4080_SINC_DEC_RATE_MSK) |
+	       (mode & AD4080_FILTER_SEL_MSK);

FIELD_PREP() for the second part.
The first is hanging on to one field. Maybe just pull that out with a FIELD_GET() and write it back again with FIELD_PREP? Will be more code, but a little less subtle to read!

Quoted 4 lines
drivers/iio/adc/ad4080.c new file +4 -0
+
+	ret = regmap_write(st->regmap, AD4080_REG_FILTER_CONFIG, data);
+	if (ret)
+		return ret;

drivers/iio/adc/ad4080.c line 444

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +9 -0
+
+	st->filter_type = mode;
+
+	return ret;
+}
 
+static struct iio_chan_spec_ext_info ad4080_ext_info[] = {
+	IIO_ENUM("filter_type",
+		 IIO_SHARED_BY_ALL,
+		 &ad4080_filter_type_enum),

very short line wrap - aim for nearer 80 chars.

drivers/iio/adc/ad4080.c line 448

Quoted 4 lines
drivers/iio/adc/ad4080.c new file +4 -0
+	IIO_ENUM_AVAILABLE("filter_type",
+			   IIO_SHARED_BY_ALL,
+			   &ad4080_filter_type_enum),
+	{}

Trivial preference for

	{ }

drivers/iio/adc/ad4080.c

Quoted 4 lines
drivers/iio/adc/ad4080.c new file +4 -0
+};
+
+#define AD4080_CHAN(_chan, _si, _bits, _sign, _shift)		\
+	{ .type = IIO_VOLTAGE,	

Odd indent. Better perhaps as simpler

	{ \
		.indexed = 1, 

etc. \

drivers/iio/adc/ad4080.c line 463

Quoted 11 lines
drivers/iio/adc/ad4080.c new file +11 -0
+	  .indexed = 1,							\
+	  .channel = _chan,						\
+	  .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE),		\
+	  .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) |	\
+		BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),			\
+	  .info_mask_shared_by_all_available =				\
+		BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),			\
+	  .ext_info = ad4080_ext_info,					\
+	  .scan_index = _si,						\
+	  .scan_type = {						\
+			.sign = _sign,					\

Current indent makes this look really wierd!

drivers/iio/adc/ad4080.c line 471

Quoted 8 lines
drivers/iio/adc/ad4080.c new file +8 -0
+			.realbits = _bits,				\
+			.storagebits = 32,				\
+			.shift = _shift,				\
+	  },								\
+	}
+
+static const struct iio_chan_spec ad4080_channels[] = {
+	AD4080_CHAN(0, 0, 20, 's', 0)

Don't bother with the macro as it doesn't add anything. Just put that stuff all here. That will let you skip setting obvious defaults to 0 like the shift.

Quoted 7 lines
drivers/iio/adc/ad4080.c new file +7 -0
+};
+
+static const struct ad4080_chip_info ad4080_chip_info = {
+	.name = "AD4080",
+	.product_id = AD4080_CHIP_ID,
+	.scale_table = ad4080_scale_table,
+	.num_scales = ARRAY_SIZE(ad4080_scale_table),

drivers/iio/adc/ad4080.c line 505

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +9 -0
+	.num_channels = 1,
+	.channels = ad4080_channels,
+};
+
+static int ad4080_setup(struct iio_dev *indio_dev)
+{
 
+	if (id != AD4080_CHIP_ID)
+		return dev_err_probe(&st->spi->dev, -EINVAL,
+				     "Unrecognized CHIP_ID 0x%X\n", id);

A mismatch on ID should not be treated as an error. That breaks the use of fallback dt compatibles. So convention on these is a dev_info() and carry on anyway. We've left breadcrumbs if things don't work but not our role to make sure it is definitely the right hardware in the firmware description.

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+
+	ret = regmap_set_bits(st->regmap, AD4080_REG_GPIO_CONFIG_A,
+			      AD4080_GPO_1_EN);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_GPIO_CONFIG_B,
+			   FIELD_PREP(AD4080_GPIO_1_SEL, 3));
+	if (ret)
+		return ret;

drivers/iio/adc/ad4080.c line 525

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+
+	ret = iio_backend_num_lanes_set(st->back, st->num_lanes);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_self_sync_enable(st->back);
+	if (ret)
+		return ret;
+
+	if (st->lvds_cnv_en) {

I'd flip this unless you expect to shortly add more optional stuff after this code

	if (!st->lvds_cnv_en)
		return 0;

	..
Quoted 23 lines
drivers/iio/adc/ad4080.c new file +23 -0
+		if (st->num_lanes) {
+			ret = regmap_update_bits(st->regmap,
+						 AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+						 AD4080_LVDS_CNV_CLK_CNT_MSK,
+						 FIELD_PREP(AD4080_LVDS_CNV_CLK_CNT_MSK, 7));
+			if (ret)
+				return ret;
+		}
+
+		ret = regmap_set_bits(st->regmap,
+				      AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+				      AD4080_LVDS_CNV_EN_MSK);
+		if (ret)
+			return ret;
+
+		return ad4080_lvds_sync_write(st);
+	}
+
+	return 0;
+}
+
+static void ad4080_properties_parse(struct ad4080_state *st)
+{

drivers/iio/adc/ad4080.c line 558

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+	unsigned int val;
+	int ret;
+
+	st->lvds_cnv_en = device_property_read_bool(&st->spi->dev,
+						    "adi,lvds-cnv-enable");
+
+	st->num_lanes = 1;
+	ret = device_property_read_u32(&st->spi->dev, "adi,num_lanes", &val);
+	if (!ret)
+		st->num_lanes = val;

Usual trick on these places were we have a default is to pick types correctly and do.

	st->num_lanes = 1;
	device_property_read_u32(&st->spi->dev, "adi,num_lanes", &st->num_lanes);

That is, rely on the call being side effect free on error.

Quoted 1 line

+}

#20 lore raw

Re: [PATCH v2 13/13] iio: adc: ad4080: add driver support

In reply to Antoniu Miclaus

Hi Antoniu,

I still have doubts regarding the new backend API mostly because it's still unclear how it should all work. I had some questions in the first version of the series that were not clarified so I'll likely repeat myself... Please don't rush into a v3 without having this sorted out.

Anyways, see below...

Quoted 107 lines · Antoniu Miclaus

Add support for AD4080 high-speed, low noise, low distortion, 20-bit, Easy Drive, successive approximation register (SAR) analog-to-digital converter (ADC).

---
changes in v2:
 - set num_lanes during probe.
 - rename bitslitp to iio_backend_data_alignment_enable
 - do ad4080_lvds_sync_write only once during probe.
 - use ETIMEDOUT
 - rename to cnv instead of adc-clk
 - update Kconfig help section
 - drop extra blank line.
 - replace /** with /* for comments
 - drop redundant return 0.
 - use dev_dbg during while(--timeout) procedure
 - use while (--timeout && !sync_en)
 - return -ETIME where applicable and check missing return codes.
 - regmap_update_bits used where applicable
 - use defines instead of GENMASK inline.
 - return FIELD_GET()
 - st->filter_enabled = mode and dropping the if else statement.
 - remove redundant brackets.
 - use OVERSAMPLING_RATIO attribute and drop custom ABI for it
 - use already existing filter_type attribute
 - fix indentation
 - remove comma on 'terminators'
 - use dev_err_probe instead of dev_err
 - check missing return values.
 - rework num_lanes property parse.
 - keep ad4080_chip_info since the driver will be extended for more parts in the future (also stated in cover letter). drivers/iio/adc/Kconfig  |  14 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad4080.c | 653 +++++++++++++++++++++++++++++++++++++++

 3 files changed, 668 insertions(+)

 create mode 100644 drivers/iio/adc/ad4080.c

drivers/iio/adc/Kconfig +0 -0
index 27413516216c..17df328f5322 100644
@@ -47,6 +47,20 @@ config AD4030

    To compile this driver as a module, choose M here: the module will be
    called ad4030.

drivers/iio/adc/Kconfig +12 -0
+config AD4080
+	tristate "Analog Devices AD4080 high speed ADC"
+	depends on SPI
+	select REGMAP_SPI
+	select IIO_BACKEND
+	help
+	  Say yes here to build support for Analog Devices AD4080
+	  high speed, low noise, low distortion, 20-bit, Easy Drive,
+	  successive approximation register (SAR) analog-to-digital
+	  converter (ADC). Supports iio_backended devices for AD4080.
+
+	  To compile this driver as a module, choose M here: the module will

be

drivers/iio/adc/Kconfig +2 -0
+	  called ad4080.
+

 config AD4130
  tristate "Analog Device AD4130 ADC Driver" depends on SPI

drivers/iio/adc/Makefile +0 -0
index 9f26d5eca822..e6efed5b4e7a 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o

 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD4000) += ad4000.o
 obj-$(CONFIG_AD4030) += ad4030.o
+obj-$(CONFIG_AD4080) += ad4080.o
 obj-$(CONFIG_AD4130) += ad4130.o
 obj-$(CONFIG_AD4695) += ad4695.o
 obj-$(CONFIG_AD4851) += ad4851.o

drivers/iio/adc/ad4080.c new file +22 -0
new file mode 100644
index 000000000000..3a0b1ad13765
@@ -0,0 +1,653 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Analog Devices AD4080 SPI ADC driver
+ *
+ * Copyright 2025 Analog Devices Inc.
+ */
+
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+#include <linux/units.h>
+

...

Quoted 18 lines
drivers/iio/adc/ad4080.c new file +17 -0
+static int ad4080_read_raw(struct iio_dev *indio_dev,
+			   struct iio_chan_spec const *chan,
+			   int *val, int *val2, long m)
+{
+	struct ad4080_state *st = iio_priv(indio_dev);
+	int dec_rate;
+
+	switch (m) {
+	case IIO_CHAN_INFO_SCALE:
+		return ad4080_get_scale(st, val, val2);
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		if (st->filter_type == SINC_5_COMP)
+			dec_rate = st->dec_rate * 2;
+		else
+			dec_rate = st->dec_rate;
+		if (st->filter_en)
+			*val = DIV_ROUND_CLOSEST(clk_get_rate(st->clk),

dec_rate);

drivers/iio/adc/ad4080.c

Quoted 2 lines
drivers/iio/adc/ad4080.c new file +2 -0
+		else
+			*val = clk_get_rate(st->clk);

Are we expecting the clock rate to change at runtime. Typically, we can just cache the rate during probe and do it "dynamically" if we ever need it.

Quoted 17 lines
drivers/iio/adc/ad4080.c new file +17 -0
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+		*val = ad4080_get_dec_rate(indio_dev, chan);
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ad4080_write_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int val, int val2, long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		return -EINVAL;
+	case IIO_CHAN_INFO_SAMP_FREQ:

drivers/iio/adc/ad4080.c line 300

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return -EINVAL;
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+		return ad4080_set_dec_rate(indio_dev, chan, val);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ad4080_lvds_sync_write(struct ad4080_state *st)
+{

This whole function seems to depend on using the LVDS signal for cnv. Why? If we have CMOS don't we also need some kind of interface alignment/calibration? If not, that's sensible enough that should be stated in a comment.

Quoted 56 lines
drivers/iio/adc/ad4080.c new file +7 -0
+	unsigned int timeout = 100;
+	bool sync_en;
+	int ret;
+
+	guard(mutex)(&st->lock);
+	if (st->num_lanes == 1)
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +4 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK);
+	else
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +17 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK |
+				   AD4080_SPI_LVDS_LANES_MSK);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit

Slip\n");

drivers/iio/adc/ad4080.c new file +4 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and

Locked!\n");

drivers/iio/adc/ad4080.c new file +2 -0
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +3 -0
+					    AD4080_RESERVED_CONFIG_A_MSK);
+		else
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +6 -0
+					    AD4080_RESERVED_CONFIG_A_MSK |
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +5 -0
+					   AD4080_RESERVED_CONFIG_A_MSK);
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c line 355

Quoted 7 lines
drivers/iio/adc/ad4080.c new file +7 -0
+					   AD4080_RESERVED_CONFIG_A_MSK |
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;

So, first the things that I don't really get (also the hdl docs need to be improved FWIW):

* It seems that we can have data alignment or data capture synchronization through an internal AMD FPGA technique called bit-slip or an external signal, right? In here, it seems that we only use bit-slip and never disable it. Is that really the goal?

* This whole process seems to be some kind of calibration at the interface level, right?

* What's the point of the conv clock? Is it only used to get the sample rate? If so, the hdl docs are misleading as it seems that it can be used instead of bit- slip for data capture alignment?

Now, speaking about the backend API's, it looks like that iio_backend_self_sync_enable() and iio_backend_data_alignment_enable() could be merged into one API. From what I can tell, iio_backend_data_alignment_enable() just enables the bit-slip process but that likely does nothing unless the SELF_SYNC bit is also set to bit-slip, right? In fact, we could think about a more generic (less flexible though) API like:

* iio_backend_intf_data_align(back, timeout_us), or
* iio_backend_intf_calib(back, timeout_us), or
* iio_backend_intf_data_capture_sync(back, timeout_us)

On the backend side, you could then enable bit-slip and do the status read (with timeout) and return success or an error code.

The above seems to be pretty much what you're doing but in just one API that makes sense to me.

Of course that the following questions still come to mind:

* Do we need to disable bit-slip after we're done (still fits into the one API model)?
* Do we need a meaningful API to change between the syncing/alignment methods? External signal vs bit-slip?

The above is key to better think of an API. Right now it feels that you're just adding an API for every bit you want to control in this process...

If we end up needing more flexibility for this, we can also consider the existing iio_backend_data_sample_trigger() API. I know is abusing a bit and a stretch but in the end of the day the whole thing is related with aligning, syncing, calibrating the interface for properly sampling data. Even bit-slip (while not a traditional external trigger) looks like some kind of self- adjusting, data-driven trigger mechanism to establish the correct starting point for capturing data. So having two new enums like:

IIO_BACKEND_SAMPLE_TRIGGER_EXT_SIGNAL, IIO_BACKEND_SAMPLE_TRIGGER_BIT_SLIP // or maybe a more generic name like s/BIT_SLIP/INTERNAL

I do not think the above is that horrible :P... But I would really like to get more opinions about this.

Quoted 2 lines
drivers/iio/adc/ad4080.c new file +2 -0
+	}
+}

...

Quoted 42 lines
drivers/iio/adc/ad4080.c new file +41 -0
+static const struct ad4080_chip_info ad4080_chip_info = {
+	.name = "AD4080",
+	.product_id = AD4080_CHIP_ID,
+	.scale_table = ad4080_scale_table,
+	.num_scales = ARRAY_SIZE(ad4080_scale_table),
+	.num_channels = 1,
+	.channels = ad4080_channels,
+};
+
+static int ad4080_setup(struct iio_dev *indio_dev)
+{
+	struct ad4080_state *st = iio_priv(indio_dev);
+	unsigned int id;
+	int ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_SW_RESET);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_SDO_ENABLE_MSK);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, AD4080_REG_CHIP_TYPE, &id);
+	if (ret)
+		return ret;
+
+	if (id != AD4080_CHIP_ID)
+		return dev_err_probe(&st->spi->dev, -EINVAL,
+				     "Unrecognized CHIP_ID 0x%X\n", id);
+
+	ret = regmap_set_bits(st->regmap, AD4080_REG_GPIO_CONFIG_A,
+			      AD4080_GPO_1_EN);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_GPIO_CONFIG_B,
+			   FIELD_PREP(AD4080_GPIO_1_SEL, 3));
+	if (ret)

drivers/iio/adc/ad4080.c line 524

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return ret;
+
+	ret = iio_backend_num_lanes_set(st->back, st->num_lanes);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_self_sync_enable(st->back);
+	if (ret)
+		return ret;
+

AFAIU, the above is enabling bit-slip?

Quoted 22 lines
drivers/iio/adc/ad4080.c new file +4 -0
+	if (st->lvds_cnv_en) {
+		if (st->num_lanes) {
+			ret = regmap_update_bits(st->regmap,
+						

AD4080_REG_ADC_DATA_INTF_CONFIG_B,

drivers/iio/adc/ad4080.c new file +2 -0
+						 AD4080_LVDS_CNV_CLK_CNT_MSK,
+						

FIELD_PREP(AD4080_LVDS_CNV_CLK_CNT_MSK, 7));

drivers/iio/adc/ad4080.c new file +14 -0
+			if (ret)
+				return ret;
+		}
+
+		ret = regmap_set_bits(st->regmap,
+				      AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+				      AD4080_LVDS_CNV_EN_MSK);
+		if (ret)
+			return ret;
+
+		return ad4080_lvds_sync_write(st);
+	}
+
+	return 0;

drivers/iio/adc/ad4080.c line 554

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+}
+
+static void ad4080_properties_parse(struct ad4080_state *st)
+{
+	unsigned int val;
+	int ret;
+
+	st->lvds_cnv_en = device_property_read_bool(&st->spi->dev,
+						    "adi,lvds-cnv-enable");
+

nit: I would probably drop the enable part. The property is about stating that the signal is LVDS instead of CMOS. And IIUC, this should also depend on the existence of st->clk

Quoted 34 lines
drivers/iio/adc/ad4080.c new file +22 -0
+	st->num_lanes = 1;
+	ret = device_property_read_u32(&st->spi->dev, "adi,num_lanes", &val);
+	if (!ret)
+		st->num_lanes = val;
+}
+
+static int ad4080_probe(struct spi_device *spi)
+{
+	struct iio_dev *indio_dev;
+	struct device *dev = &spi->dev;
+	struct ad4080_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi = spi;
+
+	ret = devm_regulator_bulk_get_enable(dev,
+					    

ARRAY_SIZE(ad4080_power_supplies),

drivers/iio/adc/ad4080.c new file +11 -0
+					     ad4080_power_supplies);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get and enable supplies\n");
+
+	st->regmap = devm_regmap_init_spi(spi, &ad4080_regmap_config);
+	if (IS_ERR(st->regmap))
+		return PTR_ERR(st->regmap);
+
+	st->info = spi_get_device_match_data(spi);
+	if (!st->info)

drivers/iio/adc/ad4080.c line 597

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return -ENODEV;
+
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
+
+	st->info = spi_get_device_match_data(spi);
+	if (!st->info)
+		return -ENODEV;
+

The above is duplicated...

drivers/iio/adc/ad4080.c line 609

Quoted 12 lines
drivers/iio/adc/ad4080.c new file +12 -0
+	indio_dev->name = st->info->name;
+	indio_dev->channels = st->info->channels;
+	indio_dev->num_channels = st->info->num_channels;
+	indio_dev->info = &ad4080_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ad4080_properties_parse(st);
+
+	st->clk = devm_clk_get_enabled(&spi->dev, "cnv");
+	if (IS_ERR(st->clk))
+		return PTR_ERR(st->clk);
+

From the datasheet it looks like this clock is optional? Moreover in the IP docs we have the following:

"SELF_SYNC: Controls if the data capture synchronization is done through CNV signal or bit-slip."

So I wonder, is the cnv clock meaning that we want to have capture sync/alignment through that external signal instead of bit-slip?

- Nuno Sá

maintainer
#21 lore raw

Re: [PATCH v2 13/13] iio: adc: ad4080: add driver support

			   AD4080_SPI_LVDS_LANES_MSK);
Quoted 98 lines
Quoted 40 lines
drivers/iio/adc/ad4080.c new file +14 -0
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit

Slip\n");

drivers/iio/adc/ad4080.c new file +4 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and

Locked!\n");

(quoted diff) +2 -0
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +3 -0
+					    AD4080_RESERVED_CONFIG_A_MSK);
+		else
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +6 -0
+					    AD4080_RESERVED_CONFIG_A_MSK |
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +5 -0
+					   AD4080_RESERVED_CONFIG_A_MSK);
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c line 355

Quoted 7 lines
drivers/iio/adc/ad4080.c new file +7 -0
+					   AD4080_RESERVED_CONFIG_A_MSK |
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;  

So, first the things that I don't really get (also the hdl docs need to be improved FWIW):

* It seems that we can have data alignment or data capture synchronization through an internal AMD FPGA technique called bit-slip or an external signal, right? In here, it seems that we only use bit-slip and never disable it. Is that really the goal?

* This whole process seems to be some kind of calibration at the interface level, right?

* What's the point of the conv clock? Is it only used to get the sample rate? If so, the hdl docs are misleading as it seems that it can be used instead of bit- slip for data capture alignment?

Now, speaking about the backend API's, it looks like that iio_backend_self_sync_enable() and iio_backend_data_alignment_enable() could be merged into one API. From what I can tell, iio_backend_data_alignment_enable() just enables the bit-slip process but that likely does nothing unless the SELF_SYNC bit is also set to bit-slip, right? In fact, we could think about a more generic (less flexible though) API like:

* iio_backend_intf_data_align(back, timeout_us), or
* iio_backend_intf_calib(back, timeout_us), or
* iio_backend_intf_data_capture_sync(back, timeout_us)

On the backend side, you could then enable bit-slip and do the status read (with timeout) and return success or an error code.

The above seems to be pretty much what you're doing but in just one API that makes sense to me.

Of course that the following questions still come to mind:

* Do we need to disable bit-slip after we're done (still fits into the one API model)?
* Do we need a meaningful API to change between the syncing/alignment methods? External signal vs bit-slip?

The above is key to better think of an API. Right now it feels that you're just adding an API for every bit you want to control in this process...

If we end up needing more flexibility for this, we can also consider the existing iio_backend_data_sample_trigger() API. I know is abusing a bit and a stretch but in the end of the day the whole thing is related with aligning, syncing, calibrating the interface for properly sampling data. Even bit-slip (while not a traditional external trigger) looks like some kind of self- adjusting, data-driven trigger mechanism to establish the correct starting point for capturing data. So having two new enums like:

Quoted 6 lines

IIO_BACKEND_SAMPLE_TRIGGER_EXT_SIGNAL, IIO_BACKEND_SAMPLE_TRIGGER_BIT_SLIP // or maybe a more generic name like s/BIT_SLIP/INTERNAL

I do not think the above is that horrible :P... But I would really like to get more opinions about this.

Seems reasonable to me to combine the two as long as we have good documentation. Agreed it is kind of deriving a trigger from the signal so turning it on with a trigger type selection doesn't seem unreasonable.

Name tricky though.

Jonathan

Quoted 169 lines
Quoted 3 lines
(quoted diff) +2 -0
+	}
+}  

...

Quoted 42 lines
drivers/iio/adc/ad4080.c new file +41 -0
+static const struct ad4080_chip_info ad4080_chip_info = {
+	.name = "AD4080",
+	.product_id = AD4080_CHIP_ID,
+	.scale_table = ad4080_scale_table,
+	.num_scales = ARRAY_SIZE(ad4080_scale_table),
+	.num_channels = 1,
+	.channels = ad4080_channels,
+};
+
+static int ad4080_setup(struct iio_dev *indio_dev)
+{
+	struct ad4080_state *st = iio_priv(indio_dev);
+	unsigned int id;
+	int ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_SW_RESET);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_SDO_ENABLE_MSK);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, AD4080_REG_CHIP_TYPE, &id);
+	if (ret)
+		return ret;
+
+	if (id != AD4080_CHIP_ID)
+		return dev_err_probe(&st->spi->dev, -EINVAL,
+				     "Unrecognized CHIP_ID 0x%X\n", id);
+
+	ret = regmap_set_bits(st->regmap, AD4080_REG_GPIO_CONFIG_A,
+			      AD4080_GPO_1_EN);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_GPIO_CONFIG_B,
+			   FIELD_PREP(AD4080_GPIO_1_SEL, 3));
+	if (ret)

drivers/iio/adc/ad4080.c line 524

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return ret;
+
+	ret = iio_backend_num_lanes_set(st->back, st->num_lanes);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_self_sync_enable(st->back);
+	if (ret)
+		return ret;
+  

AFAIU, the above is enabling bit-slip?

Quoted 22 lines
drivers/iio/adc/ad4080.c new file +4 -0
+	if (st->lvds_cnv_en) {
+		if (st->num_lanes) {
+			ret = regmap_update_bits(st->regmap,
+						

AD4080_REG_ADC_DATA_INTF_CONFIG_B,

drivers/iio/adc/ad4080.c new file +2 -0
+						 AD4080_LVDS_CNV_CLK_CNT_MSK,
+						

FIELD_PREP(AD4080_LVDS_CNV_CLK_CNT_MSK, 7));

drivers/iio/adc/ad4080.c new file +14 -0
+			if (ret)
+				return ret;
+		}
+
+		ret = regmap_set_bits(st->regmap,
+				      AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+				      AD4080_LVDS_CNV_EN_MSK);
+		if (ret)
+			return ret;
+
+		return ad4080_lvds_sync_write(st);
+	}
+
+	return 0;

drivers/iio/adc/ad4080.c line 554

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+}
+
+static void ad4080_properties_parse(struct ad4080_state *st)
+{
+	unsigned int val;
+	int ret;
+
+	st->lvds_cnv_en = device_property_read_bool(&st->spi->dev,
+						    "adi,lvds-cnv-enable");
+  

nit: I would probably drop the enable part. The property is about stating that the signal is LVDS instead of CMOS. And IIUC, this should also depend on the existence of st->clk

Quoted 34 lines
drivers/iio/adc/ad4080.c new file +22 -0
+	st->num_lanes = 1;
+	ret = device_property_read_u32(&st->spi->dev, "adi,num_lanes", &val);
+	if (!ret)
+		st->num_lanes = val;
+}
+
+static int ad4080_probe(struct spi_device *spi)
+{
+	struct iio_dev *indio_dev;
+	struct device *dev = &spi->dev;
+	struct ad4080_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi = spi;
+
+	ret = devm_regulator_bulk_get_enable(dev,
+					    

ARRAY_SIZE(ad4080_power_supplies),

drivers/iio/adc/ad4080.c new file +11 -0
+					     ad4080_power_supplies);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get and enable supplies\n");
+
+	st->regmap = devm_regmap_init_spi(spi, &ad4080_regmap_config);
+	if (IS_ERR(st->regmap))
+		return PTR_ERR(st->regmap);
+
+	st->info = spi_get_device_match_data(spi);
+	if (!st->info)

drivers/iio/adc/ad4080.c line 597

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return -ENODEV;
+
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
+
+	st->info = spi_get_device_match_data(spi);
+	if (!st->info)
+		return -ENODEV;
+  

The above is duplicated...

drivers/iio/adc/ad4080.c line 609

Quoted 12 lines
drivers/iio/adc/ad4080.c new file +12 -0
+	indio_dev->name = st->info->name;
+	indio_dev->channels = st->info->channels;
+	indio_dev->num_channels = st->info->num_channels;
+	indio_dev->info = &ad4080_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ad4080_properties_parse(st);
+
+	st->clk = devm_clk_get_enabled(&spi->dev, "cnv");
+	if (IS_ERR(st->clk))
+		return PTR_ERR(st->clk);
+  

From the datasheet it looks like this clock is optional? Moreover in the IP docs we have the following:

"SELF_SYNC: Controls if the data capture synchronization is done through CNV signal or bit-slip."

So I wonder, is the cnv clock meaning that we want to have capture sync/alignment through that external signal instead of bit-slip?

- Nuno Sá

author maintainer
#22 lore raw

RE: [PATCH v2 13/13] iio: adc: ad4080: add driver support

In reply to Nuno Sá
Quoted 121 lines
Quoted 36 lines
drivers/iio/adc/ad4080.c new file +5 -0
+	int ret;
+
+	guard(mutex)(&st->lock);
+	if (st->num_lanes == 1)
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +4 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK);
+	else
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +17 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK |
+				   AD4080_SPI_LVDS_LANES_MSK);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit

Slip\n");

drivers/iio/adc/ad4080.c new file +4 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and

Locked!\n");

(quoted diff) +2 -0
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap,
Quoted 2 lines

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK);
Quoted 4 lines
(quoted diff) +2 -0
+		else
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK |
Quoted 7 lines
drivers/iio/adc/ad4080.c new file +5 -0
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK);
Quoted 6 lines
drivers/iio/adc/ad4080.c new file +4 -0
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK |

drivers/iio/adc/ad4080.c line 355

Quoted 6 lines
drivers/iio/adc/ad4080.c new file +6 -0
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;

So, first the things that I don't really get (also the hdl docs need to be improved FWIW):

* It seems that we can have data alignment or data capture synchronization through an internal AMD FPGA technique called bit-slip or an external signal, right? In here, it seems that we only use bit-slip and never disable it. Is that really the goal?

* This whole process seems to be some kind of calibration at the interface level, right?

* What's the point of the conv clock? Is it only used to get the sample rate? If so, the hdl docs are misleading as it seems that it can be used instead of bit- slip for data capture alignment?

Now, speaking about the backend API's, it looks like that iio_backend_self_sync_enable() and iio_backend_data_alignment_enable() could be
merged into one API. From what I can tell, iio_backend_data_alignment_enable()
just enables the bit-slip process but that likely does nothing unless the SELF_SYNC bit is also set to bit-slip, right? In fact, we could think about a more generic (less flexible though) API like:

* iio_backend_intf_data_align(back, timeout_us), or
* iio_backend_intf_calib(back, timeout_us), or
* iio_backend_intf_data_capture_sync(back, timeout_us)

On the backend side, you could then enable bit-slip and do the status read (with
timeout) and return success or an error code.

The above seems to be pretty much what you're doing but in just one API that makes sense to me.

Of course that the following questions still come to mind:

* Do we need to disable bit-slip after we're done (still fits into the one API model)?
* Do we need a meaningful API to change between the syncing/alignment methods?
External signal vs bit-slip?

The above is key to better think of an API. Right now it feels that you're just adding an API for every bit you want to control in this process...

If we end up needing more flexibility for this, we can also consider the existing iio_backend_data_sample_trigger() API. I know is abusing a bit and a stretch but in the end of the day the whole thing is related with aligning, syncing, calibrating the interface for properly sampling data. Even bit-slip (while not a traditional external trigger) looks like some kind of self- adjusting, data-driven trigger mechanism to establish the correct starting point
for capturing data. So having two new enums like:

Quoted 7 lines

IIO_BACKEND_SAMPLE_TRIGGER_EXT_SIGNAL, IIO_BACKEND_SAMPLE_TRIGGER_BIT_SLIP // or maybe a more generic name like
s/BIT_SLIP/INTERNAL

I do not think the above is that horrible :P... But I would really like to get more opinions about this.

There've been some update on the HDL side changing a bit the behavior:
- bitslip_enable is removed, instead the sync bit is used which is already part of the adc common core.
SYNC:
This bit enables capture synchronization. When activated, it initiates an HDL process that aligns the sample's most significant bit (MSB) based solely on the captured data, without considering the AD4080's CNV signal. This bit is self-clearing and should be toggled whenever synchronization is needed (e.g., at boot or after updating the sampling rate).

The SELF_SYNC bit was removed.

SYNC_STATUS bit (which is also part of the common core) has the following behavior:
This bit indicates whether the sample's MSB alignment has been correctly performed and the capture is synchronized. If successful, this bit will be set to 1.

#23 lore raw

Re: [PATCH v2 13/13] iio: adc: ad4080: add driver support

Quoted 152 lines · Antoniu
Quoted 129 lines
Quoted 36 lines
drivers/iio/adc/ad4080.c new file +5 -0
+	int ret;
+
+	guard(mutex)(&st->lock);
+	if (st->num_lanes == 1)
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +4 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK);
+	else
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +17 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK |
+				   AD4080_SPI_LVDS_LANES_MSK);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit

Slip\n");

drivers/iio/adc/ad4080.c new file +4 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and

Locked!\n");

(quoted diff) +2 -0
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap,
Quoted 2 lines

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK);
Quoted 4 lines
(quoted diff) +2 -0
+		else
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK |
Quoted 7 lines
drivers/iio/adc/ad4080.c new file +5 -0
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK);
Quoted 6 lines
drivers/iio/adc/ad4080.c new file +4 -0
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK |

drivers/iio/adc/ad4080.c line 355

Quoted 6 lines
drivers/iio/adc/ad4080.c new file +6 -0
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;

So, first the things that I don't really get (also the hdl docs need to be improved FWIW):

* It seems that we can have data alignment or data capture synchronization through an internal AMD FPGA technique called bit-slip or an external signal,
right? In here, it seems that we only use bit-slip and never disable it. Is that
really the goal?

* This whole process seems to be some kind of calibration at the interface level, right?

* What's the point of the conv clock? Is it only used to get the sample rate? If
so, the hdl docs are misleading as it seems that it can be used instead of bit-
slip for data capture alignment?

Now, speaking about the backend API's, it looks like that iio_backend_self_sync_enable() and iio_backend_data_alignment_enable() could be
merged into one API. From what I can tell, iio_backend_data_alignment_enable()
just enables the bit-slip process but that likely does nothing unless the SELF_SYNC bit is also set to bit-slip, right? In fact, we could think about a
more generic (less flexible though) API like:

* iio_backend_intf_data_align(back, timeout_us), or
* iio_backend_intf_calib(back, timeout_us), or
* iio_backend_intf_data_capture_sync(back, timeout_us)

On the backend side, you could then enable bit-slip and do the status read (with
timeout) and return success or an error code.

The above seems to be pretty much what you're doing but in just one API that makes sense to me.

Of course that the following questions still come to mind:

* Do we need to disable bit-slip after we're done (still fits into the one API
model)?
* Do we need a meaningful API to change between the syncing/alignment methods?
External signal vs bit-slip?

The above is key to better think of an API. Right now it feels that you're just
adding an API for every bit you want to control in this process...

If we end up needing more flexibility for this, we can also consider the existing iio_backend_data_sample_trigger() API. I know is abusing a bit and a
stretch but in the end of the day the whole thing is related with aligning, syncing, calibrating the interface for properly sampling data. Even bit-slip (while not a traditional external trigger) looks like some kind of self- adjusting, data-driven trigger mechanism to establish the correct starting point
for capturing data. So having two new enums like:

Quoted 8 lines

IIO_BACKEND_SAMPLE_TRIGGER_EXT_SIGNAL, IIO_BACKEND_SAMPLE_TRIGGER_BIT_SLIP // or maybe a more generic name like
s/BIT_SLIP/INTERNAL

I do not think the above is that horrible :P... But I would really like to get
more opinions about this.

There've been some update on the HDL side changing a bit the behavior:
- bitslip_enable is removed, instead the sync bit is used which is already part
  of the adc common core.
 SYNC:
       This bit enables capture synchronization. When activated, it initiates an HDL process that aligns the sample's most significant bit (MSB) based
       solely on the captured data, without considering the AD4080's CNV signal.
       This bit is self-clearing and should be toggled whenever synchronization
       is needed (e.g., at boot or after updating the sampling rate).

Quoted 7 lines

The SELF_SYNC bit was removed.

SYNC_STATUS bit (which is also part of the common core) has the following behavior:
      This bit indicates whether the sample's MSB alignment has been correctly performed and the capture is synchronized. If successful, this bit will be set to 1.

So this looks like it would fir in first approach of just one new backend API right?

What about the CNV signal? Is that something we can fully control on the frontend driver (though it also seems that signal is an output of the backend device)?

Thx!
- Nuno Sá

author maintainer
#24 lore raw

RE: [PATCH v2 13/13] iio: adc: ad4080: add driver support

--
Antoniu Miclăuş

Quoted 168 lines

-----Original Message-----
From: Nuno Sá <[email protected]>
Sent: Tuesday, April 22, 2025 2:39 PM
To: Miclaus, Antoniu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 13/13] iio: adc: ad4080: add driver support

[External]

Quoted 69 lines · Antoniu
Quoted 69 lines
Quoted 36 lines
drivers/iio/adc/ad4080.c new file +5 -0
+	int ret;
+
+	guard(mutex)(&st->lock);
+	if (st->num_lanes == 1)
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +4 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK);
+	else
+		ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +17 -0
+				   AD4080_RESERVED_CONFIG_A_MSK |
+				   AD4080_INTF_CHK_EN_MSK |
+				   AD4080_SPI_LVDS_LANES_MSK);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_data_alignment_enable(st->back);
+	if (ret)
+		return ret;
+
+	do {
+		ret = iio_backend_sync_status_get(st->back, &sync_en);
+		if (ret)
+			return ret;
+
+		if (!sync_en)
+			dev_dbg(&st->spi->dev, "Not Locked: Running Bit

Slip\n");

drivers/iio/adc/ad4080.c new file +4 -0
+	} while (--timeout && !sync_en);
+
+	if (timeout) {
+		dev_info(&st->spi->dev, "Success: Pattern correct and

Locked!\n");

(quoted diff) +2 -0
+		if (st->num_lanes == 1)
+			return regmap_write(st->regmap,
Quoted 2 lines

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK);
Quoted 4 lines
(quoted diff) +2 -0
+		else
+			return regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	    AD4080_RESERVED_CONFIG_A_MSK |
Quoted 7 lines
drivers/iio/adc/ad4080.c new file +5 -0
+					    AD4080_SPI_LVDS_LANES_MSK);
+	} else {
+		dev_info(&st->spi->dev, "LVDS Sync Timeout.\n");
+		if (st->num_lanes == 1) {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK);
Quoted 6 lines
drivers/iio/adc/ad4080.c new file +4 -0
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_write(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+

	   AD4080_RESERVED_CONFIG_A_MSK |

drivers/iio/adc/ad4080.c line 355

Quoted 6 lines
drivers/iio/adc/ad4080.c new file +6 -0
+					   AD4080_SPI_LVDS_LANES_MSK);
+			if (ret)
+				return ret;
+		}
+
+		return -ETIMEDOUT;

So, first the things that I don't really get (also the hdl docs need to be improved FWIW):

Quoted 1 line
Quoted 1 line

* It seems that we can have data alignment or data capture

synchronization

Quoted 29 lines
Quoted 29 lines

through an internal AMD FPGA technique called bit-slip or an external signal,
right? In here, it seems that we only use bit-slip and never disable it. Is that
really the goal?

* This whole process seems to be some kind of calibration at the interface level, right?

* What's the point of the conv clock? Is it only used to get the sample rate? If
so, the hdl docs are misleading as it seems that it can be used instead of bit-
slip for data capture alignment?

Now, speaking about the backend API's, it looks like that iio_backend_self_sync_enable() and iio_backend_data_alignment_enable() could be
merged into one API. From what I can tell, iio_backend_data_alignment_enable()
just enables the bit-slip process but that likely does nothing unless the SELF_SYNC bit is also set to bit-slip, right? In fact, we could think about a
more generic (less flexible though) API like:

* iio_backend_intf_data_align(back, timeout_us), or
* iio_backend_intf_calib(back, timeout_us), or
* iio_backend_intf_data_capture_sync(back, timeout_us)

Quoted 5 lines
Quoted 5 lines

On the backend side, you could then enable bit-slip and do the status read (with
timeout) and return success or an error code.

The above seems to be pretty much what you're doing but in just one API

that

Quoted 25 lines
Quoted 25 lines

makes sense to me.

Of course that the following questions still come to mind:

* Do we need to disable bit-slip after we're done (still fits into the one API
model)?
* Do we need a meaningful API to change between the syncing/alignment methods?
External signal vs bit-slip?

The above is key to better think of an API. Right now it feels that you're just
adding an API for every bit you want to control in this process...

If we end up needing more flexibility for this, we can also consider the existing iio_backend_data_sample_trigger() API. I know is abusing a bit and a
stretch but in the end of the day the whole thing is related with aligning, syncing, calibrating the interface for properly sampling data. Even bit-slip (while not a traditional external trigger) looks like some kind of self- adjusting, data-driven trigger mechanism to establish the correct starting point
for capturing data. So having two new enums like:

Quoted 2 lines
Quoted 2 lines

IIO_BACKEND_SAMPLE_TRIGGER_EXT_SIGNAL, IIO_BACKEND_SAMPLE_TRIGGER_BIT_SLIP // or maybe a more generic

name

Quoted 23 lines
Quoted 6 lines

like
s/BIT_SLIP/INTERNAL

I do not think the above is that horrible :P... But I would really like to get
more opinions about this.

There've been some update on the HDL side changing a bit the behavior:
- bitslip_enable is removed, instead the sync bit is used which is already part
  of the adc common core.
 SYNC:
       This bit enables capture synchronization. When activated, it initiates an HDL process that aligns the sample's most significant bit (MSB) based
       solely on the captured data, without considering the AD4080's CNV signal.
       This bit is self-clearing and should be toggled whenever synchronization
       is needed (e.g., at boot or after updating the sampling rate).

The SELF_SYNC bit was removed.

Quoted 8 lines
Quoted 5 lines

SYNC_STATUS bit (which is also part of the common core) has the following behavior:
      This bit indicates whether the sample's MSB alignment has been correctly performed and the capture is synchronized. If successful, this bit will be set to 1.

So this looks like it would fir in first approach of just one new backend API right?

In this particular case, yes, one backend would fit for the sync process. But taking into account that these two features are part also from the common core of the AXI ADC, in other cases they might be used separately.

Quoted 4 lines

What about the CNV signal? Is that something we can fully control on the frontend driver (though it also seems that signal is an output of the backend device)?

The CNV signal is mainly used for sampling (an input pin according to the datasheet - conversion is initiated on the rising edge of the convert signal).
We use it only for determining the sampling frequency.

Quoted 3 lines

Thx!
- Nuno Sá