Skip to contentSkip to conversation

Add support for AD4080 ADC

PATCH Superseded Antoniu Miclaus 3 participants 16 messages May 2, 2025 – May 4, 2025

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Antoniu Miclaus

author maintainer
#0 lore raw

v4 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 (10):
iio: backend: add support for filter config
iio: backend: add support for data alignment
iio: backend: add support for number of lanes
dt-bindings: iio: adc: add ad408x axi variant
iio: adc: adi-axi-adc: add filter type config
iio: adc: adi-axi-adc: add data align process
iio: adc: adi-axi-adc: add num lanes support
dt-bindings: iio: adc: add ad4080
iio: adc: ad4080: add driver support
Documetation: ABI: add sinc1 and sinc5+pf1 filter

 Documentation/ABI/testing/sysfs-bus-iio       |   3 +
 .../bindings/iio/adc/adi,ad4080.yaml          |  96 +++
 .../bindings/iio/adc/adi,axi-adc.yaml         |   2 +
 MAINTAINERS                                   |   8 +
 drivers/iio/adc/Kconfig                       |  14 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/ad4080.c                      | 569 ++++++++++++++++++
 drivers/iio/adc/adi-axi-adc.c                 |  90 +++
 drivers/iio/industrialio-backend.c            |  49 ++
 include/linux/iio/backend.h                   |  19 +
 10 files changed, 851 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 v4 1/10 iio: backend: add support for filter config

Add backend support for digital filter type selection.

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.

---
no changes in v4.

 drivers/iio/industrialio-backend.c | 18 ++++++++++++++++++
 include/linux/iio/backend.h        | 13 +++++++++++++
 2 files changed, 31 insertions(+)
drivers/iio/industrialio-backend.c +18 -0
index d4ad36f54090..038c9e1e2857 100644
@@ -778,6 +778,24 @@ static int __devm_iio_backend_get(struct device *dev, struct iio_backend *back)
 	return 0;
 }
 
+/**
+ * iio_backend_filter_type_set - Set filter type
+ * @back: Backend device
+ * @type: Filter type.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_filter_type_set(struct iio_backend *back,
+				enum iio_backend_filter_type type)
+{
+	if (type >= IIO_BACKEND_FILTER_TYPE_MAX)
+		return -EINVAL;
+
+	return iio_backend_op_call(back, filter_type_set, type);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_filter_type_set, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +13 -0
index e45b7dfbec35..5526800f5d4a 100644
@@ -76,6 +76,14 @@ enum iio_backend_interface_type {
 	IIO_BACKEND_INTERFACE_MAX
 };
 
+enum iio_backend_filter_type {
+	IIO_BACKEND_FILTER_TYPE_DISABLED,
+	IIO_BACKEND_FILTER_TYPE_SINC1,
+	IIO_BACKEND_FILTER_TYPE_SINC5,
+	IIO_BACKEND_FILTER_TYPE_SINC5_PLUS_COMP,
+	IIO_BACKEND_FILTER_TYPE_MAX
+};
+
 /**
  * struct iio_backend_ops - operations structure for an iio_backend
  * @enable: Enable backend.
@@ -100,6 +108,7 @@ 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_type_set: Set filter type.
  * @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 +159,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_type_set)(struct iio_backend *back,
+			       enum iio_backend_filter_type type);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -190,6 +201,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_type_set(struct iio_backend *back,
+				enum iio_backend_filter_type type);
 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
#2 lore raw

PATCH v4 2/10 iio: backend: add support for data alignment

In reply to Antoniu Miclaus

Add backend support for staring the capture synchronization. When activated, it initates a proccess that aligns the sample's most significant bit (MSB) based solely on the captured data, without considering any other external signals.

---
changes in v4:
- implement iio_backend_interface_data_align with timeout parameter.

 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 038c9e1e2857..b7cbbc7a8fcd 100644
@@ -796,6 +796,20 @@ int iio_backend_filter_type_set(struct iio_backend *back,
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_filter_type_set, "IIO_BACKEND");
 
+/**
+ * iio_backend_data_align - Perform the data alignment process.
+ * @back: Backend device
+ * @timeout: Timeout value.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout)
+{
+	return iio_backend_op_call(back, interface_data_align, timeout);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_interface_data_align, "IIO_BACKEND");
+
 /**
  * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
  * @back: Backend device
include/linux/iio/backend.h +3 -0
index 5526800f5d4a..452cb2838dad 100644
@@ -109,6 +109,7 @@ enum iio_backend_filter_type {
  * @debugfs_print_chan_status: Print channel status into a buffer.
  * @debugfs_reg_access: Read or write register value of backend.
  * @filter_type_set: Set filter type.
+ * @interface_data_align: Perform the data alignment 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.
@@ -161,6 +162,7 @@ struct iio_backend_ops {
 				  unsigned int writeval, unsigned int *readval);
 	int (*filter_type_set)(struct iio_backend *back,
 			       enum iio_backend_filter_type type);
+	int (*interface_data_align)(struct iio_backend *back, u32 timeout);
 	int (*ddr_enable)(struct iio_backend *back);
 	int (*ddr_disable)(struct iio_backend *back);
 	int (*data_stream_enable)(struct iio_backend *back);
@@ -203,6 +205,7 @@ int devm_iio_backend_request_buffer(struct device *dev,
 				    struct iio_dev *indio_dev);
 int iio_backend_filter_type_set(struct iio_backend *back,
 				enum iio_backend_filter_type type);
+int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout);
 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
#3 lore raw

Re: [PATCH v4 02/10] iio: backend: add support for data alignment

Quoted 7 lines · Antoniu Miclaus

Add backend support for staring the capture synchronization. When activated, it initates a proccess that aligns the sample's most significant bit (MSB) based solely on the captured data, without considering any other external signals.

---

Couple of notes from me...

Quoted 14 lines

changes in v4:
 - implement iio_backend_interface_data_align with timeout parameter. drivers/iio/industrialio-backend.c | 14 ++++++++++++++ include/linux/iio/backend.h        |  3 +++

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

backend.c
index 038c9e1e2857..b7cbbc7a8fcd 100644

drivers/iio/industrialio-backend.c +0 -0
@@ -796,6 +796,20 @@ int iio_backend_filter_type_set(struct iio_backend *back,
  }
  EXPORT_SYMBOL_NS_GPL(iio_backend_filter_type_set, "IIO_BACKEND");
Quoted 6 lines


+/**
+ * iio_backend_data_align - Perform the data alignment process.
+ * @back: Backend device
+ * @timeout: Timeout value.
+ *

dData align is not a straightforward thing so a description is definitely helpful here. Please add one

Quoted 4 lines

+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout)

It would be nice to have a suffix in the time parameter. I would do timeout_us. We should also document/define what happens if 0 is passed. Should we accept it? Should we block indefinitely? For starters, I would likely not accept 0.

Quoted 37 lines
drivers/iio/industrialio-backend.c +5 -0
+{
+	return iio_backend_op_call(back, interface_data_align, timeout);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_interface_data_align, "IIO_BACKEND");
+

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

include/linux/iio/backend.h +1 -0
index 5526800f5d4a..452cb2838dad 100644
@@ -109,6 +109,7 @@ enum iio_backend_filter_type {
   * @debugfs_print_chan_status: Print channel status into a buffer.
   * @debugfs_reg_access: Read or write register value of backend.
   * @filter_type_set: Set filter type.
+ * @interface_data_align: Perform the data alignment 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.
@@ -161,6 +162,7 @@ struct iio_backend_ops {

    unsigned int writeval, unsigned int *readval);
  int (*filter_type_set)(struct iio_backend *back, enum iio_backend_filter_type type);

include/linux/iio/backend.h +1 -0
+	int (*interface_data_align)(struct iio_backend *back, u32 timeout);

  int (*ddr_enable)(struct iio_backend *back); int (*ddr_disable)(struct iio_backend *back); int (*data_stream_enable)(struct iio_backend *back);

include/linux/iio/backend.h +1 -0
@@ -203,6 +205,7 @@ int devm_iio_backend_request_buffer(struct device *dev,
  				    struct iio_dev *indio_dev);
  int iio_backend_filter_type_set(struct iio_backend *back,
  				enum iio_backend_filter_type type);
+int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout);
  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
#4 lore raw

PATCH v4 3/10 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 v4.

 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 b7cbbc7a8fcd..78a957d1fe92 100644
@@ -810,6 +810,23 @@ int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_interface_data_align, "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 452cb2838dad..1ffb200eb3ff 100644
@@ -110,6 +110,7 @@ enum iio_backend_filter_type {
  * @debugfs_reg_access: Read or write register value of backend.
  * @filter_type_set: Set filter type.
  * @interface_data_align: Perform the data alignment process.
+ * @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.
@@ -163,6 +164,7 @@ struct iio_backend_ops {
 	int (*filter_type_set)(struct iio_backend *back,
 			       enum iio_backend_filter_type type);
 	int (*interface_data_align)(struct iio_backend *back, u32 timeout);
+	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);
@@ -206,6 +208,7 @@ int devm_iio_backend_request_buffer(struct device *dev,
 int iio_backend_filter_type_set(struct iio_backend *back,
 				enum iio_backend_filter_type type);
 int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout);
+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
#5 lore raw

PATCH v4 4/10 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.

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

---
no changes in v4.

 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
author maintainer
#6 lore raw

PATCH v4 5/10 iio: adc: adi-axi-adc: add filter type config

In reply to Antoniu Miclaus

Add support for enabling/disabling filter based on the filter type provided.

This feature is specific to the axi ad408x IP core, therefore add new compatible string and corresponding iio_backend_ops.

---
changes in v4:
- update commit message to state that the new compatible is added.
- checking for max value is done in the iio_backend function.

 drivers/iio/adc/adi-axi-adc.c | 38 +++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/iio/adc/adi-axi-adc.c +38 -0
index 61ab7dce43be..2a3a6c3f5e59 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,19 @@ static int axi_adc_ad485x_oversampling_ratio_set(struct iio_backend *back,
 	}
 }
 
+static int axi_adc_ad408x_filter_type_set(struct iio_backend *back,
+					  enum iio_backend_filter_type type)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	if (type)
+		return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				       AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
+
+	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 +596,24 @@ 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_type_set = axi_adc_ad408x_filter_type_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),
+};
+
+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 +729,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
Reviewed-by on v4 5/10
#7 lore raw

Re: [PATCH v4 05/10] iio: adc: adi-axi-adc: add filter type config

Quoted 8 lines · Antoniu Miclaus

Add support for enabling/disabling filter based on the filter type provided.

This feature is specific to the axi ad408x IP core, therefore add new compatible string and corresponding iio_backend_ops.

---

Quoted 81 lines

changes in v4:
 - update commit message to state that the new compatible is added.
 - checking for max value is done in the iio_backend function. drivers/iio/adc/adi-axi-adc.c | 38 +++++++++++++++++++++++++++++++++++

 1 file changed, 38 insertions(+)
drivers/iio/adc/adi-axi-adc.c +1 -0
index 61ab7dce43be..2a3a6c3f5e59 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)

drivers/iio/adc/adi-axi-adc.c +0 -0
@@ -402,6 +403,19 @@ static int axi_adc_ad485x_oversampling_ratio_set(struct
 iio_backend *back,
  	}
  }

drivers/iio/adc/adi-axi-adc.c +13 -0
+static int axi_adc_ad408x_filter_type_set(struct iio_backend *back,
+					  enum iio_backend_filter_type type)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+
+	if (type)
+		return regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3,
+				       AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
+
+	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) {

drivers/iio/adc/adi-axi-adc.c +0 -0
@@ -582,6 +596,24 @@ static const struct iio_backend_info axi_ad485x = {
  	.ops = &adi_ad485x_ops,
  };

drivers/iio/adc/adi-axi-adc.c +11 -0
+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_type_set = axi_adc_ad408x_filter_type_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),

drivers/iio/adc/adi-axi-adc.c +7 -0
+};
+
+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;

drivers/iio/adc/adi-axi-adc.c +0 -0
@@ -697,9 +729,15 @@ static const struct axi_adc_info adc_ad7606 = {
  	.has_child_nodes = true,
  };

drivers/iio/adc/adi-axi-adc.c +5 -0
+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 },

drivers/iio/adc/adi-axi-adc.c +1 -0
+	{ .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 */ }

author maintainer
#8 lore raw

PATCH v4 6/10 iio: adc: adi-axi-adc: add data align process

In reply to Antoniu Miclaus

Add support for starting the sync process used for data capture alignment.

---
changes in v4:
- rework data_align function.
- rename bit definitions/functions.

 drivers/iio/adc/adi-axi-adc.c | 37 +++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/iio/adc/adi-axi-adc.c +37 -0
index 2a3a6c3f5e59..2a79c043c0de 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    ADI_AXI_ADC_CTRL_SYNC_MSK		BIT(3)
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
 #define ADI_AXI_ADC_REG_CNTRL_3			0x004c
@@ -54,6 +55,9 @@
 #define   AXI_AD485X_PACKET_FORMAT_32BIT	0x2
 #define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)
 
+#define ADI_AXI_ADC_REG_SYNC_STATUS		0x0068
+#define   ADI_AXI_ADC_SYNC_STATUS_ADC_SYNC_MSK	BIT(0)
+
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 
@@ -416,6 +420,38 @@ static int axi_adc_ad408x_filter_type_set(struct iio_backend *back,
 				 AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
 }
 
+static int axi_adc_ad408x_interface_data_align(struct iio_backend *back,
+					       u32 timeout)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	bool sync_en;
+	u32 val;
+	int ret;
+
+	ret = regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CTRL,
+			      ADI_AXI_ADC_CTRL_SYNC_MSK);
+	if (ret)
+		return ret;
+
+	do {
+		ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_SYNC_STATUS, &val);
+		if (ret)
+			return ret;
+
+		sync_en = FIELD_GET(ADI_AXI_ADC_SYNC_STATUS_ADC_SYNC_MSK, val);
+
+		if (!sync_en)
+			dev_dbg(st->dev, "Not Locked: Running Bit Slip\n");
+
+		fsleep(500);
+	} while (--timeout && !sync_en);
+
+	if (!timeout)
+		return -ETIMEDOUT;
+
+	return 0;
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -605,6 +641,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.free_buffer = axi_adc_free_buffer,
 	.data_sample_trigger = axi_adc_data_sample_trigger,
 	.filter_type_set = axi_adc_ad408x_filter_type_set,
+	.interface_data_align = axi_adc_ad408x_interface_data_align,
 	.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
#9 lore raw

Re: [PATCH v4 06/10] iio: adc: adi-axi-adc: add data align process

Quoted 59 lines · Antoniu Miclaus

Add support for starting the sync process used for data capture alignment.

---
changes in v4:
 - rework data_align function.
 - rename bit definitions/functions. drivers/iio/adc/adi-axi-adc.c | 37 +++++++++++++++++++++++++++++++++++

 1 file changed, 37 insertions(+)
drivers/iio/adc/adi-axi-adc.c +0 -0
index 2a3a6c3f5e59..2a79c043c0de 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    ADI_AXI_ADC_CTRL_SYNC_MSK BIT(3)
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK BIT(1)

 #define ADI_AXI_ADC_REG_CNTRL_3 0x004c

drivers/iio/adc/adi-axi-adc.c +0 -0
@@ -54,6 +55,9 @@
  #define   AXI_AD485X_PACKET_FORMAT_32BIT	0x2
  #define   AXI_AD408X_CNTRL_3_FILTER_EN_MSK	BIT(0)

drivers/iio/adc/adi-axi-adc.c +3 -0
+#define ADI_AXI_ADC_REG_SYNC_STATUS		0x0068
+#define   ADI_AXI_ADC_SYNC_STATUS_ADC_SYNC_MSK	BIT(0)
+

 #define ADI_AXI_ADC_REG_DRP_STATUS 0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED BIT(17)

drivers/iio/adc/adi-axi-adc.c +0 -0
@@ -416,6 +420,38 @@ static int axi_adc_ad408x_filter_type_set(struct
 iio_backend *back,
  				 AXI_AD408X_CNTRL_3_FILTER_EN_MSK);
  }

drivers/iio/adc/adi-axi-adc.c +15 -0
+static int axi_adc_ad408x_interface_data_align(struct iio_backend *back,
+					       u32 timeout)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	bool sync_en;
+	u32 val;
+	int ret;
+
+	ret = regmap_set_bits(st->regmap, ADI_AXI_ADC_REG_CTRL,
+			      ADI_AXI_ADC_CTRL_SYNC_MSK);
+	if (ret)
+		return ret;
+
+	do {
+		ret = regmap_read(st->regmap, ADI_AXI_ADC_REG_SYNC_STATUS,

&val);

drivers/iio/adc/adi-axi-adc.c +4 -0
+		if (ret)
+			return ret;
+
+		sync_en = FIELD_GET(ADI_AXI_ADC_SYNC_STATUS_ADC_SYNC_MSK,

val);

drivers/iio/adc/adi-axi-adc.c static int axi_adc_ad408x_filter_type_set(struct iio_backend *back, · line 447

Quoted 6 lines
drivers/iio/adc/adi-axi-adc.c +6 -0
+
+		if (!sync_en)
+			dev_dbg(st->dev, "Not Locked: Running Bit Slip\n");
+
+		fsleep(500);
+	} while (--timeout && !sync_en);

Why not regmap_read_poll_timeout()?

- Nuno Sá

Quoted 19 lines
drivers/iio/adc/adi-axi-adc.c +7 -0
+
+	if (!timeout)
+		return -ETIMEDOUT;
+
+	return 0;
+}
+

 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back, struct iio_dev *indio_dev) {

drivers/iio/adc/adi-axi-adc.c +1 -0
@@ -605,6 +641,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
  	.free_buffer = axi_adc_free_buffer,
  	.data_sample_trigger = axi_adc_data_sample_trigger,
  	.filter_type_set = axi_adc_ad408x_filter_type_set,
+	.interface_data_align = axi_adc_ad408x_interface_data_align,
  	.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
#10 lore raw

PATCH v4 7/10 iio: adc: adi-axi-adc: add num lanes support

In reply to Antoniu Miclaus

Add support for setting the number of lanes enabled.

---
changes in v4:
- drop function assignment in axi_adc generic ops.
- rename bit definitions.

 drivers/iio/adc/adi-axi-adc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/iio/adc/adi-axi-adc.c +15 -0
index 2a79c043c0de..64cf72f1c223 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    ADI_AXI_ADC_CTRL_NUM_LANES_MSK	GENMASK(12, 8)
 #define    ADI_AXI_ADC_CTRL_SYNC_MSK		BIT(3)
 #define    ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK	BIT(1)
 
@@ -452,6 +453,19 @@ static int axi_adc_ad408x_interface_data_align(struct iio_backend *back,
 	return 0;
 }
 
+static int axi_adc_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,
+				  ADI_AXI_ADC_CTRL_NUM_LANES_MSK,
+				  FIELD_PREP(ADI_AXI_ADC_CTRL_NUM_LANES_MSK, num_lanes));
+}
+
 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back,
 						 struct iio_dev *indio_dev)
 {
@@ -642,6 +656,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 	.data_sample_trigger = axi_adc_data_sample_trigger,
 	.filter_type_set = axi_adc_ad408x_filter_type_set,
 	.interface_data_align = axi_adc_ad408x_interface_data_align,
+	.num_lanes_set = axi_adc_num_lanes_set,
 	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
 	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
 };
Signature · 1 line
2.49.0
author maintainer
#11 lore raw

PATCH v4 8/10 dt-bindings: iio: adc: add ad4080

In reply to Antoniu Miclaus

Add devicetree bindings for ad4080 family.

---
no changes in v4.

 .../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
author maintainer
#12 lore raw

PATCH v4 9/10 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 v4:
- drop _MSK postfix for bit definitions
- add space before }
- drop writing reserved bit.
- use regmap_set_bits/regmap_clear_bits instead of regmap_write
- use dev_dbg() where applies
- use dev_err() where applies
- use FIELD_PREP when _MSK defines are implied.
- drop explicit statement .shift = 0
- get clk_rate during probe.
- handle IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_SAMP_FREQ in default.
- use the new iio_backend_interface_data_align function
- drop redundant else.
- drop redundat mutex guards.
- rearrange includes.
- rename sinc5+pf1
- use regmap_get_device
- drop outermost ()
- check mode for < 2
- drop st->dec_rate and use functions inline.
- drop ad4080_channels[] and use ad4080_channel instead
- drop redundat if statement for num_lanes.
- use - instead of _ for device properties.
- drop reduandant assignement
- drop indio_dev->modes = INDIO_DIRECT_MODE;
- rename filter_disabled to filter_none.

 MAINTAINERS              |   8 +
 drivers/iio/adc/Kconfig  |  14 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad4080.c | 570 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 593 insertions(+)
 create mode 100644 drivers/iio/adc/ad4080.c
MAINTAINERS +8 -0
index bd04375ab4a2..0038f7a078ae 100644
@@ -1317,6 +1317,14 @@ F:	Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml
 F:	Documentation/iio/ad4030.rst
 F:	drivers/iio/adc/ad4030.c
 
+ANALOG DEVICES INC AD4080 DRIVER
+M:	Antoniu Miclaus <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml
+F:	drivers/iio/adc/ad4080.c
+
 ANALOG DEVICES INC AD4130 DRIVER
 M:	Cosmin Tanislav <[email protected]>
 L:	[email protected]
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 +570 -0

570 lines not on this page · raw message

Signature · 1 line
2.49.0
#13 lore raw

Re: [PATCH v4 09/10] iio: adc: ad4080: add driver support

Quoted 130 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 v4:
 - drop _MSK postfix for bit definitions
 - add space before }
 - drop writing reserved bit.
 - use regmap_set_bits/regmap_clear_bits instead of regmap_write
 - use dev_dbg() where applies
 - use dev_err() where applies
 - use FIELD_PREP when _MSK defines are implied.
 - drop explicit statement .shift = 0
 - get clk_rate during probe.
 - handle IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_SAMP_FREQ in default.
 - use the new iio_backend_interface_data_align function
 - drop redundant else.
 - drop redundat mutex guards.
 - rearrange includes.
 - rename sinc5+pf1
 - use regmap_get_device
 - drop outermost ()
 - check mode for < 2
 - drop st->dec_rate and use functions inline.
 - drop ad4080_channels[] and use ad4080_channel instead
 - drop redundat if statement for num_lanes.
 - use - instead of _ for device properties.
 - drop reduandant assignement
 - drop indio_dev->modes = INDIO_DIRECT_MODE;
 - rename filter_disabled to filter_none.
 MAINTAINERS              |   8 +
 drivers/iio/adc/Kconfig  |  14 +
 drivers/iio/adc/Makefile |   1 +
 drivers/iio/adc/ad4080.c | 570 +++++++++++++++++++++++++++++++++++++++

 4 files changed, 593 insertions(+)

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

MAINTAINERS +0 -0
index bd04375ab4a2..0038f7a078ae 100644
@@ -1317,6 +1317,14 @@

F: Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml
 F: Documentation/iio/ad4030.rst
 F: drivers/iio/adc/ad4030.c

MAINTAINERS +8 -0
+ANALOG DEVICES INC AD4080 DRIVER
+M:	Antoniu Miclaus <[email protected]>
+L:	[email protected]
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/adc/adi,ad4080.yaml
+F:	drivers/iio/adc/ad4080.c
+

 ANALOG DEVICES INC AD4130 DRIVER
 M: Cosmin Tanislav <[email protected]>
 L: [email protected]

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 +25 -0
new file mode 100644
index 000000000000..9168dee9323e
@@ -0,0 +1,570 @@
+// 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/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/iio/backend.h>
+#include <linux/iio/iio.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 5 lines
drivers/iio/adc/ad4080.c new file +5 -0
+static int ad4080_lvds_sync_write(struct ad4080_state *st)
+{
+	struct device *dev = regmap_get_device(st->regmap);
+	int ret;
+

drivers/iio/adc/ad4080.c line 292

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+	ret = regmap_set_bits(st->regmap, AD4080_REG_ADC_DATA_INTF_CONFIG_A,
+			      AD4080_ADC_DATA_INTF_CONFIG_A_INTF_CHK_EN);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_interface_data_align(st->back, 100);
+	if (ret == -ETIMEDOUT)
+		dev_err(dev, "LVDS Sync Timeout.\n");
+	if (ret)
+		return ret;

Hmm I don't think the above two if() to be that helpful... Also, ad4080_lvds_sync_write() seems to be only called from probe, so dev_err_probe()?

Quoted 43 lines
drivers/iio/adc/ad4080.c new file +3 -0
+
+	dev_dbg(dev, "Success: Pattern correct and Locked!\n");
+	return regmap_clear_bits(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +38 -0
+				 AD4080_ADC_DATA_INTF_CONFIG_A_INTF_CHK_EN);
+}
+
+static ssize_t ad4080_get_filter_type(struct iio_dev *dev,
+				      const struct iio_chan_spec *chan)
+{
+	struct ad4080_state *st = iio_priv(dev);
+	unsigned int data;
+	int ret;
+
+	ret = regmap_read(st->regmap, AD4080_REG_FILTER_CONFIG, &data);
+	if (ret)
+		return ret;
+
+	return FIELD_GET(AD4080_FILTER_CONFIG_FILTER_SEL_MSK, data);
+}
+
+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);
+	unsigned int dec_rate;
+	int ret;
+
+	dec_rate = ad4080_get_dec_rate(dev, chan);
+
+	if (mode >= SINC_5 && dec_rate >= 512)
+		return -EINVAL;
+
+	guard(mutex)(&st->lock);
+	ret = iio_backend_filter_type_set(st->back, mode);
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(st->regmap, AD4080_REG_FILTER_CONFIG,
+				 AD4080_FILTER_CONFIG_FILTER_SEL_MSK,
+				

FIELD_PREP(AD4080_FILTER_CONFIG_FILTER_SEL_MSK,

drivers/iio/adc/ad4080.c line 339

Quoted 6 lines
drivers/iio/adc/ad4080.c new file +6 -0
+					    mode));
+	if (ret)
+		return ret;
+
+	st->filter_type = mode;
+

The above is not properly synchronized with ad4080_set_dec_rate(). ad4080_set_dec_rate() also needs to be protected by the same lock otherwise dec_rate can be change under our feet when changing the filter. The same is true for when updating the dec_rate.

I think that for ad4080_set_gec_rate() we do not really need to lock (i.e, regmap should be fine)

Quoted 115 lines
drivers/iio/adc/ad4080.c new file +98 -0
+	return 0;
+}
+
+static int ad4080_read_avail(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     const int **vals, int *type, int *length,
+			     long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+		*vals = ad4080_dec_rate_iio_enum;
+		*length = ARRAY_SIZE(ad4080_dec_rate_iio_enum);
+		*type = IIO_VAL_INT;
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct iio_info ad4080_iio_info = {
+	.debugfs_reg_access = ad4080_reg_access,
+	.read_raw = ad4080_read_raw,
+	.write_raw = ad4080_write_raw,
+	.read_avail = ad4080_read_avail,
+};
+
+static const struct iio_enum ad4080_filter_type_enum = {
+	.items = ad4080_filter_type_iio_enum,
+	.num_items = ARRAY_SIZE(ad4080_filter_type_iio_enum),
+	.set = ad4080_set_filter_type,
+	.get = ad4080_get_filter_type,
+};
+
+static struct iio_chan_spec_ext_info ad4080_ext_info[] = {
+	IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad4080_filter_type_enum),
+	IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL,
+			   &ad4080_filter_type_enum),
+	{ }
+};
+
+static const struct iio_chan_spec ad4080_channel = {
+	.type = IIO_VOLTAGE,
+	.indexed = 1,
+	.channel = 0,
+	.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 = 0,
+	.scan_type = {
+		.sign = 's',
+		.realbits = 20,
+		.storagebits = 32,
+	},
+};
+
+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_channel,
+};
+
+static int ad4080_setup(struct iio_dev *indio_dev)
+{
+	struct ad4080_state *st = iio_priv(indio_dev);
+	struct device *dev = regmap_get_device(st->regmap);
+	unsigned int id;
+	int ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_INTERFACE_CONFIG_A_SW_RESET);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_INTERFACE_CONFIG_A,
+			   AD4080_INTERFACE_CONFIG_A_SDO_ENABLE);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, AD4080_REG_CHIP_TYPE, &id);
+	if (ret)
+		return ret;
+
+	if (id != AD4080_CHIP_ID)
+		dev_info(dev, "Unrecognized CHIP_ID 0x%X\n", id);
+
+	ret = regmap_set_bits(st->regmap, AD4080_REG_GPIO_CONFIG_A,
+			      AD4080_GPIO_CONFIG_A_GPO_1_EN);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, AD4080_REG_GPIO_CONFIG_B,
+			   FIELD_PREP(AD4080_GPIO_CONFIG_B_GPIO_1_SEL_MSK,

3));

drivers/iio/adc/ad4080.c new file +13 -0
+	if (ret)
+		return ret;
+
+	ret = iio_backend_num_lanes_set(st->back, st->num_lanes);
+	if (ret)
+		return ret;
+
+	if (!st->lvds_cnv_en)
+		return 0;
+
+	ret = regmap_update_bits(st->regmap,
+				 AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+				

AD4080_ADC_DATA_INTF_CONFIG_B_LVDS_CNV_CLK_CNT_MSK,

drivers/iio/adc/ad4080.c new file +1 -0
+				

FIELD_PREP(AD4080_ADC_DATA_INTF_CONFIG_B_LVDS_CNV_CLK_CNT_MSK, 7));

drivers/iio/adc/ad4080.c line 455

Quoted 4 lines
drivers/iio/adc/ad4080.c new file +4 -0
+	if (ret)
+		return ret;
+
+	if (st->num_lanes != 1) {

I think st->num_lanes > 1 would make the intent more explicit...

Quoted 23 lines
drivers/iio/adc/ad4080.c new file +1 -0
+		ret = regmap_set_bits(st->regmap,

AD4080_REG_ADC_DATA_INTF_CONFIG_A,

drivers/iio/adc/ad4080.c new file +1 -0
+				     

AD4080_ADC_DATA_INTF_CONFIG_A_SPI_LVDS_LANES);

drivers/iio/adc/ad4080.c new file +18 -0
+		if (ret)
+			return ret;
+	}
+
+	ret = regmap_set_bits(st->regmap,
+			      AD4080_REG_ADC_DATA_INTF_CONFIG_B,
+			      AD4080_ADC_DATA_INTF_CONFIG_B_LVDS_CNV_EN);
+	if (ret)
+		return ret;
+
+	return ad4080_lvds_sync_write(st);
+}
+
+static void ad4080_properties_parse(struct ad4080_state *st)
+{
+	struct device *dev = regmap_get_device(st->regmap);
+
+	st->lvds_cnv_en = device_property_read_bool(dev, "adi,lvds-cnv-

enable");

drivers/iio/adc/ad4080.c line 478

Quoted 3 lines
drivers/iio/adc/ad4080.c new file +3 -0
+
+	st->num_lanes = 1;
+	device_property_read_u32(dev, "adi,num-lanes", &st->num_lanes);

we should validate the value given by DT...

- Nuno Sá

maintainer
#14 lore raw

Re: [PATCH v4 09/10] iio: adc: ad4080: add driver support

In reply to Antoniu Miclaus
Quoted 5 lines · On Fri, 2 May 2025 11:59:04 +0300 Antoniu Miclaus <[email protected]>…

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

One trivial thing I noticed to add to Nuno's much more detailed review!

Quoted 14 lines
drivers/iio/adc/ad4080.c new file +8 -0
new file mode 100644
index 000000000000..9168dee9323e
 
+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;
+
+	if ((st->filter_type >= SINC_5 && mode >= 512) || mode < 2)

drivers/iio/adc/ad4080.c line 236

Quoted 10 lines
drivers/iio/adc/ad4080.c new file +10 -0
+		return -EINVAL;
+
+	ret = regmap_update_bits(st->regmap, AD4080_REG_FILTER_CONFIG,
+				 AD4080_FILTER_CONFIG_SINC_DEC_RATE_MSK,
+				 FIELD_PREP(AD4080_FILTER_CONFIG_SINC_DEC_RATE_MSK,
+					    (ilog2(mode) - 1)));
+	if (ret)
+		return ret;
+
+	return 0;

return regmap_update_bits();

Quoted 1 line

+}

author maintainer
#15 lore raw

PATCH v4 10/10 Documetation: ABI: add sinc1 and sinc5+pf1 filter

In reply to Antoniu Miclaus

Add sinc1 and sinc5+pf1 filter types used for ad4080 device.

Add these two options into the filter_type available attribute.

---
 Documentation/ABI/testing/sysfs-bus-iio | 3 +++
 1 file changed, 3 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +3 -0
index b8838cb92d38..2dfb74b5a990 100644
@@ -2275,6 +2275,8 @@ Description:
 		Reading returns a list with the possible filter modes. Options
 		for the attribute:
 
+		* "sinc1" - The digital sinc1 filter. Fast 1st
+		  conversion time. Poor noise performance.
 		* "sinc3" - The digital sinc3 filter. Moderate 1st
 		  conversion time. Good noise performance.
 		* "sinc4" - Sinc 4. Excellent noise performance. Long
@@ -2290,6 +2292,7 @@ Description:
 		* "sinc3+pf2" - Sinc3 + device specific Post Filter 2.
 		* "sinc3+pf3" - Sinc3 + device specific Post Filter 3.
 		* "sinc3+pf4" - Sinc3 + device specific Post Filter 4.
+		* "sinc5+pf1" - Sinc5 + device specific Post Filter 1.
 
 What:		/sys/bus/iio/devices/iio:deviceX/filter_type
 What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY-voltageZ_filter_type
Signature · 1 line
2.49.0