Devicetree
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Add support for ADA4355
@ 2026-11-27 21:51 Marcelo Schmitt
  2026-11-27 21:51 ` [PATCH v2 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:51 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1

ADA4355 (and ADA4356) are programmable transimpedance, current to bits receivers.
ADA4356 main difference from ADA4355 is the set of configurable transimpedance
(Tz) options which result in different scaling to miliampere units.

Change log v1 -> v2:
[device tree]
- Added explanation about why the parts can have a fallback compatible.
[IIO]
- Improved backend interface documentation.
- Fixed mistake on the scale to mA.
- Made reads to the mA scale also synch with scale write operations.
- Set buffer setup ops to enable backend channel.
- Enabled vcc supply.
- Stop calibration on lane calibration error.
- Removed unneeded includes
- Alternative in_range check.
- Declaring loop counters within loop declaration.
- Unknown chip ID message update.
- No longer keeping extra IIO channel pointer in state struct.

Previous submissions:
  v1: https://lore.kernel.org/linux-iio/cover.1795003864.git.marcelo.schmitt@analog.com/


With best regards,
Marcelo


Marcelo Schmitt (5):
  iio: backend: Add calibration source interface
  dt-bindings: iio: adc: Add AXI ADA4355 IP CORE
  iio: adc: adi-axi-adc: Support AXI ADA4355 IP core
  dt-bindings: iio: adc: Add ADA4355
  iio: adc: Add support for ADA4355 and similar ADCs

 .../bindings/iio/adc/adi,ada4355.yaml         | 104 +++
 .../bindings/iio/adc/adi,axi-adc.yaml         |   1 +
 MAINTAINERS                                   |   8 +
 drivers/iio/adc/Kconfig                       |  11 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/ada4355.c                     | 822 ++++++++++++++++++
 drivers/iio/adc/adi-axi-adc.c                 |  66 ++
 drivers/iio/industrialio-backend.c            |  28 +
 include/linux/iio/backend.h                   |  22 +
 9 files changed, 1063 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
 create mode 100644 drivers/iio/adc/ada4355.c


base-commit: 39508411b82d4dc29dd245bb471ec9ecc1111c9d
-- 
2.53.0


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

* [PATCH v2 1/5] iio: backend: Add calibration source interface
  2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
@ 2026-11-27 21:51 ` Marcelo Schmitt
  2026-11-27 21:52 ` [PATCH v2 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE Marcelo Schmitt
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:51 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1

Some ADC front-ends group and send data from a single channel over a
configurable number of LVDS serial lanes and may also need to perform a
data frame calibration before capture can start. During a channel interface
calibration, the front-end device driver usually requests the channel
status multiple times to find out the optimal calibration point.

However, the backend channel status interface doesn't provide which
specific serial lane or data frame flagged errors when they occur. The lack
of error source information prevents proper calibration of channels
comprised of multiple serial lanes.

Instead, the backend may have a separate error source mask configuration to
restrict which digital interface source will have its errors reported
through iio_backend_chan_status(). With that, each serial lane can be
calibrated independently, enabling multiple lane LVDS channels to be
properly calibrated and supported.

Add a backend operation for selecting the calibration source (data lane or
data frame) so that device drivers can perform the calibration of both the
data frame and data lanes. Backends are expected to report every error
source when IIO_BACKEND_CALIB_SOURCE_NONE is selected.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 drivers/iio/industrialio-backend.c | 28 ++++++++++++++++++++++++++++
 include/linux/iio/backend.h        | 22 ++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 7cc227818618..aaf11cceb145 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -869,6 +869,34 @@ int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us)
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_interface_data_align, "IIO_BACKEND");
 
+/**
+ * iio_backend_calibration_source_set - Select the monitored error source.
+ * @back: Backend device
+ * @source: Error source to monitor.
+ * @lane: Data lane to monitor. Only meaningful for when
+ *	  @source == IIO_BACKEND_CALIB_SOURCE_DATA_LANE.
+ *
+ * Some ADC front-ends group and send data from a single channel over a
+ * configurable number of LVDS serial lanes and may also need to perform a data
+ * frame calibration before capture can start. However, the backend channel
+ * status interface doesn't provide which specific serial lane or data frame has
+ * flagged errors when they occur. Instead, the backend may have an error mask
+ * setting to restrict which digital interface source may have errors reported
+ * through iio_backend_chan_status(). This is useful for channels that are made
+ * out of multiple physical data lanes so that each data lane can be calibrated
+ * individually.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_calibration_source_set(struct iio_backend *back,
+				       enum iio_backend_calib_source source,
+				       unsigned int lane)
+{
+	return iio_backend_op_call(back, calibration_source_set, source, lane);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_calibration_source_set, "IIO_BACKEND");
+
 /**
  * iio_backend_num_lanes_set - Number of lanes enabled.
  * @back: Backend device
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 93d5f2073cc3..5a59bc1025da 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -76,6 +76,20 @@ enum iio_backend_interface_type {
 	IIO_BACKEND_INTERFACE_MAX
 };
 
+/**
+ * enum iio_backend_calib_source - Digital interface error source
+ * @IIO_BACKEND_CALIB_SOURCE_NONE: Report every error source.
+ * @IIO_BACKEND_CALIB_SOURCE_DATA_LANE: Report errors of a single data lane.
+ * @IIO_BACKEND_CALIB_SOURCE_FRAME: Report errors of the frame signal.
+ * @IIO_BACKEND_CALIB_SOURCE_MAX: Number of error sources.
+ */
+enum iio_backend_calib_source {
+	IIO_BACKEND_CALIB_SOURCE_NONE,
+	IIO_BACKEND_CALIB_SOURCE_DATA_LANE,
+	IIO_BACKEND_CALIB_SOURCE_FRAME,
+	IIO_BACKEND_CALIB_SOURCE_MAX
+};
+
 enum iio_backend_filter_type {
 	IIO_BACKEND_FILTER_TYPE_DISABLED,
 	IIO_BACKEND_FILTER_TYPE_SINC1,
@@ -132,6 +146,8 @@ enum iio_backend_capabilities {
  * @debugfs_reg_access: Read or write register value of backend.
  * @filter_type_set: Set filter type.
  * @interface_data_align: Perform the data alignment process.
+ * @calibration_source_set: Select the error source monitored during
+ *			    interface calibration.
  * @num_lanes_set: Set the number of lanes enabled.
  * @crc_enable: Enable direction-specific CRC handling.
  * @crc_disable: Disable direction-specific CRC handling.
@@ -190,6 +206,9 @@ 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_us);
+	int (*calibration_source_set)(struct iio_backend *back,
+				      enum iio_backend_calib_source source,
+				      unsigned int lane);
 	int (*num_lanes_set)(struct iio_backend *back, unsigned int num_lanes);
 	int (*crc_enable)(struct iio_backend *back);
 	int (*crc_disable)(struct iio_backend *back);
@@ -240,6 +259,9 @@ 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_us);
+int iio_backend_calibration_source_set(struct iio_backend *back,
+				       enum iio_backend_calib_source source,
+				       unsigned int lane);
 int iio_backend_num_lanes_set(struct iio_backend *back, unsigned int num_lanes);
 int iio_backend_crc_enable(struct iio_backend *back);
 int iio_backend_crc_disable(struct iio_backend *back);
-- 
2.53.0


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

* [PATCH v2 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE
  2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
  2026-11-27 21:51 ` [PATCH v2 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
@ 2026-11-27 21:52 ` Marcelo Schmitt
  2026-11-27 21:52 ` [PATCH v2 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core Marcelo Schmitt
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:52 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1, Conor Dooley

The AXI ADA4355 IP core provides the HDL interface to the ADA4355 and
similar designs. It differs from the generic AXI ADC core by including an
extra register to report data synchronization errors.

Document a compatible string for the AXI ADA4355 IP core.

Link: https://analogdevicesinc.github.io/hdl/library/axi_ada4355/index.html
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
index e91e421a3d6b..fe0f526b0ee2 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml
@@ -38,6 +38,7 @@ properties:
       - adi,axi-ad408x
       - adi,axi-ad7606x
       - adi,axi-ad485x
+      - adi,axi-ada4355
 
   reg:
     maxItems: 1
-- 
2.53.0


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

* [PATCH v2 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core
  2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
  2026-11-27 21:51 ` [PATCH v2 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
  2026-11-27 21:52 ` [PATCH v2 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE Marcelo Schmitt
@ 2026-11-27 21:52 ` Marcelo Schmitt
  2026-11-27 21:52 ` [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
  2026-11-27 21:53 ` [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
  4 siblings, 0 replies; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:52 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1

The AXI ADA4355 IP core provides the HDL interface to ADA4355 devices. It
differs from the generic AXI ADC core in its register layout and requires
a data frame setup step in which the number of active serial lanes is
programmed.

Add a separate backend operation for the AXI ADA4355 IP core and register
it as a new compatible of the adi-axi-adc driver.

Link: https://analogdevicesinc.github.io/hdl/library/axi_ada4355/index.html
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 drivers/iio/adc/adi-axi-adc.c | 66 +++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 4b77b7169d95..965dd6dc4bb8 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -67,6 +67,10 @@
 #define ADI_AXI_ADC_REG_DRP_STATUS		0x0074
 #define   ADI_AXI_ADC_DRP_LOCKED		BIT(17)
 
+#define ADI_AXI_ADC_REG_LVDS			0x00c8
+#define   ADI_AXI_ADC_LVDS_FRAME_ERROR		BIT(2)
+#define   ADI_AXI_ADC_LVDS_LANE_ERROR		GENMASK(1, 0)
+
 /* ADC Channel controls */
 
 #define ADI_AXI_REG_CHAN_CTRL(c)		(0x0400 + (c) * 0x40)
@@ -486,6 +490,34 @@ static int axi_adc_ad408x_interface_data_align(struct iio_backend *back,
 					1, timeout_us);
 }
 
+static int axi_adc_ada4355_calibration_source_set(struct iio_backend *back,
+						  enum iio_backend_calib_source source,
+						  unsigned int lane)
+{
+	struct adi_axi_adc_state *st = iio_backend_get_priv(back);
+	u32 val;
+
+	switch (source) {
+	case IIO_BACKEND_CALIB_SOURCE_NONE:
+		val = 0;
+		break;
+	case IIO_BACKEND_CALIB_SOURCE_FRAME:
+		val = ADI_AXI_ADC_LVDS_FRAME_ERROR;
+		break;
+	case IIO_BACKEND_CALIB_SOURCE_DATA_LANE:
+		if (BIT(lane) & ~ADI_AXI_ADC_LVDS_LANE_ERROR)
+			return -EINVAL;
+		val = BIT(lane);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_LVDS,
+				  ADI_AXI_ADC_LVDS_FRAME_ERROR |
+				  ADI_AXI_ADC_LVDS_LANE_ERROR, val);
+}
+
 static int axi_adc_num_lanes_set(struct iio_backend *back,
 				 unsigned int num_lanes)
 {
@@ -722,6 +754,34 @@ static const struct iio_backend_info axi_ad408x = {
 	.caps = IIO_BACKEND_CAP_BUFFER | IIO_BACKEND_CAP_ENABLE,
 };
 
+static const struct iio_backend_ops adi_ada4355_ops = {
+	.enable = axi_adc_enable,
+	.disable = axi_adc_disable,
+	.data_format_set = axi_adc_data_format_set,
+	.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,
+	.iodelay_set = axi_adc_iodelays_set,
+	.test_pattern_set = axi_adc_test_pattern_set,
+	.chan_status = axi_adc_chan_status,
+	.interface_type_get = axi_adc_interface_type_get,
+	.oversampling_ratio_set = axi_adc_oversampling_ratio_set,
+	.interface_data_align = axi_adc_ad408x_interface_data_align,
+	.calibration_source_set = axi_adc_ada4355_calibration_source_set,
+	.num_lanes_set = axi_adc_num_lanes_set,
+	.debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
+	.debugfs_print_chan_status = iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status),
+};
+
+static const struct iio_backend_info axi_ada4355 = {
+	.name = "axi-ada4355",
+	.ops = &adi_ada4355_ops,
+	.caps = IIO_BACKEND_CAP_CALIBRATION | IIO_BACKEND_CAP_BUFFER |
+		IIO_BACKEND_CAP_ENABLE,
+};
+
 static int adi_axi_adc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -841,12 +901,18 @@ static const struct axi_adc_info adi_axi_ad408x = {
 	.backend_info = &axi_ad408x,
 };
 
+static const struct axi_adc_info adi_axi_ada4355 = {
+	.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
+	.backend_info = &axi_ada4355,
+};
+
 /* Match table for of_platform binding */
 static const struct of_device_id adi_axi_adc_of_match[] = {
 	{ .compatible = "adi,axi-adc-10.0.a", .data = &adc_generic },
 	{ .compatible = "adi,axi-ad408x", .data = &adi_axi_ad408x },
 	{ .compatible = "adi,axi-ad485x", .data = &adi_axi_ad485x },
 	{ .compatible = "adi,axi-ad7606x", .data = &adc_ad7606 },
+	{ .compatible = "adi,axi-ada4355", .data = &adi_axi_ada4355 },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match);
-- 
2.53.0


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

* [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355
  2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
                   ` (2 preceding siblings ...)
  2026-11-27 21:52 ` [PATCH v2 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core Marcelo Schmitt
@ 2026-11-27 21:52 ` Marcelo Schmitt
  2026-11-27 22:07   ` sashiko-bot
  2026-11-27 21:53 ` [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
  4 siblings, 1 reply; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:52 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1

The ADA4355 is an integrated analog front-end and 14-bit analog-to-digital
converter with a serial LVDS data interface.

Document how to describe ADA4355 devices in device tree.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
ADA4356 has a different set of selectable input configurations that leads to a
different scaling factor to get to milliampere units. A system with ADA4356
matching/fallingback to a device driver only supporting ADA4355 would get the
wrong _scale from the IIO device driver. Users would not be able to accurately
read data in milliampere units. ADA4355 cannot fallback to ADA4356 for the same
reason.

 .../bindings/iio/adc/adi,ada4355.yaml         | 104 ++++++++++++++++++
 MAINTAINERS                                   |   7 ++
 2 files changed, 111 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
new file mode 100644
index 000000000000..d169619fef25
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
@@ -0,0 +1,104 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,ada4355.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices Transimpedance Current to Bits Receiver
+
+maintainers:
+  - Marcelo Schmitt <marcelo.schmitt@analog.com>
+
+description: |
+  ADA4355 programmable transimpedance, current to bits receiver and similar data
+  converters.
+  Specifications can be found at:
+    https://www.analog.com/media/en/technical-documentation/data-sheets/ada4355.pdf
+    https://www.analog.com/media/en/technical-documentation/data-sheets/ada4356.pdf
+
+$ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - adi,ada4355
+      - adi,ada4356
+
+  reg:
+    maxItems: 1
+
+  spi-max-frequency:
+    maximum: 50000000
+
+  spi-3wire: true
+
+  spi-cpha: true
+
+  vcc-supply:
+    description: 3.3V power supply.
+
+  vea-supply:
+    description: 1.8V analog power supply to ADC.
+
+  ved-supply:
+    description: 1.8V digital power supply to ADC.
+
+  clocks:
+    maxItems: 1
+
+  adi,vld-en-gpios:
+    description: GPIO connected to the VLDEN pin for VLD output enable.
+
+  adi,gsel-gpios:
+    description:
+      GPIOs connected to the GSEL0 and GSEL1 pins, in that order, for
+      transimpedance gain selection.
+    minItems: 2
+    maxItems: 2
+
+  adi,lfp-gpios:
+    description:
+      GPIO connected to FSEL for internal low pass filter bandwidth selection.
+
+  io-backends:
+    description:
+      The AXI ADC IP block connected to the D+/- and DCO+/- lines of the
+      ADC. An example backend can be found at
+      http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - vcc-supply
+  - spi-3wire
+  - spi-cpha
+  - clocks
+  - adi,vld-en-gpios
+  - adi,gsel-gpios
+  - adi,lfp-gpios
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        adc@0 {
+            compatible = "adi,ada4355";
+            reg = <0>;
+            spi-max-frequency = <100000>;
+            spi-3wire;
+            spi-cpha;
+            vcc-supply = <&supply_3_3V>;
+            clocks = <&ref_clk>;
+            adi,vld-en-gpios = <&gpio0 89 GPIO_ACTIVE_HIGH>;
+            adi,gsel-gpios = <&gpio0 86 GPIO_ACTIVE_HIGH>,
+                             <&gpio0 87 GPIO_ACTIVE_HIGH>;
+            adi,lfp-gpios = <&gpio0 88 GPIO_ACTIVE_HIGH>;
+            io-backends = <&axi_adc>;
+        };
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index e8d3e5a0665b..131ff62949e1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1796,6 +1796,13 @@ W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/amplifiers/adi,ada4250.yaml
 F:	drivers/iio/amplifiers/ada4250.c
 
+ANALOG DEVICES INC ADA4355 DRIVER
+M:	Marcelo Schmitt <marcelo.schmitt@analog.com>
+L:	linux-iio@vger.kernel.org
+S:	Supported
+W:	https://ez.analog.com/linux-software-drivers
+F:	Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
+
 ANALOG DEVICES INC ADE9000 DRIVER
 M:	Antoniu Miclaus <antoniu.miclaus@analog.com>
 L:	linux-iio@vger.kernel.org
-- 
2.53.0


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

* [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs
  2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
                   ` (3 preceding siblings ...)
  2026-11-27 21:52 ` [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
@ 2026-11-27 21:53 ` Marcelo Schmitt
  2026-11-27 22:06   ` sashiko-bot
  4 siblings, 1 reply; 8+ messages in thread
From: Marcelo Schmitt @ 2026-11-27 21:53 UTC (permalink / raw)
  To: linux-iio, linux-kernel, devicetree, linux
  Cc: jic23, Michael.Hennerich, nuno.sa, eblanc, dlechner, andy, robh,
	krzk+dt, conor+dt, olivier.moysan, marcelo.schmitt1

The ADA4355 and AD4356 are 14-bit, 125 MSPS, analog-to-digital converters
with integrated analog front-end. These chips are configured over SPI while
conversion data is streamed over a serial LVDS interface handled by an IIO
backend.

Add an IIO device driver for ADA4355 and similar designs, providing device
configuration, debugfs register access and buffered captures through the
IIO backend framework.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 MAINTAINERS               |   1 +
 drivers/iio/adc/Kconfig   |  11 +
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/ada4355.c | 822 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 835 insertions(+)
 create mode 100644 drivers/iio/adc/ada4355.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 131ff62949e1..0309179ecef1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1802,6 +1802,7 @@ L:	linux-iio@vger.kernel.org
 S:	Supported
 W:	https://ez.analog.com/linux-software-drivers
 F:	Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
+F:	drivers/iio/adc/ada4355.c
 
 ANALOG DEVICES INC ADE9000 DRIVER
 M:	Antoniu Miclaus <antoniu.miclaus@analog.com>
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 1d6ed49041ab..173e50e177fc 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -606,6 +606,17 @@ config AD9467
 	  To compile this driver as a module, choose M here: the module will be
 	  called ad9467.
 
+config ADA4355
+	tristate "Analog Devices ADA4355 uModule Data Acquisition Module"
+	depends on SPI
+	select IIO_BACKEND
+	select REGMAP_SPI
+	help
+	  Say yes here to build support for Analog Devices ADA4355
+	  14-bit, 125MSPS, high-speed dual-channel analog to digital
+	  converters (ADC) that realize a complete current to bits data
+	  acquisition solution.
+
 config ADE9000
 	tristate "Analog Devices Multiphase Energy and Power Quality Monitoring IC Driver"
 	depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 769965295dcc..167967999ba9 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_AD7944) += ad7944.o
 obj-$(CONFIG_AD7949) += ad7949.o
 obj-$(CONFIG_AD799X) += ad799x.o
 obj-$(CONFIG_AD9467) += ad9467.o
+obj-$(CONFIG_ADA4355) += ada4355.o
 obj-$(CONFIG_ADE9000) += ade9000.o
 obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o
 obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o
diff --git a/drivers/iio/adc/ada4355.c b/drivers/iio/adc/ada4355.c
new file mode 100644
index 000000000000..5a3f48036253
--- /dev/null
+++ b/drivers/iio/adc/ada4355.c
@@ -0,0 +1,822 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Analog Devices ADA4355 device driver
+ *
+ * Copyright (C) 2026 Analog Devices, Inc.
+ * Author: Marcelo Schmitt <marcelo.schmitt@analog.com>
+ *
+ * Expanded and improved version made on top of preliminary code from:
+ *	Antoniu Miclaus <antoniu.miclaus@analog.com>
+ *	Pop Ioan Daniel <pop.ioan-daniel@analog.com>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/cleanup.h>
+#include <linux/clk.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/seq_file.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+#include <linux/units.h>
+
+#include <linux/iio/backend.h>
+#include <linux/iio/iio.h>
+
+#define ADA4355_CHIP_CONFIG_REG			0x00
+#define ADA4355_CHIP_ID_REG			0x01
+#define ADA4355_CHIP_ID				0x8B
+
+#define ADA4355_DEVICE_INDEX_REG		0x05
+#define ADA4355_TRANSFER_REG			0xFF
+#define ADA4355_TRANSFER_OVERRIDE		BIT(0)
+
+#define ADA4355_POWER_MODES_REG			0x08
+#define ADA4355_PW_MODE_DIGITAL_RESET		GENMASK(1, 0)
+
+#define ADA4355_TEST_MODE_REG			0x0D
+#define ADA4355_TEST_MODE_MASK			GENMASK(3, 0)
+/* Reset the pattern generator whenever a test mode is selected. */
+#define ADA4355_TEST_MODE_RESET_PN		BIT(6)
+#define ADA4355_TEST_MODE_OFF			0x0
+#define ADA4355_TEST_MODE_ALT_CHECKERBOARD	0x4
+#define ADA4355_TEST_MODE_USER			0x8
+
+#define ADA4355_OUTPUT_MODE_REG			0x14
+#define ADA4355_OUTPUT_MODE_TWOSCOMP		BIT(0)
+
+#define ADA4355_USER_PATT1_LSB_REG		0x19
+#define ADA4355_USER_PATT1_MSB_REG		0x1A
+#define ADA4355_USER_PATT2_LSB_REG		0x1B
+#define ADA4355_USER_PATT2_MSB_REG		0x1C
+#define ADA4355_SERIAL_OUT_DATA_CNTRL_REG	0x21
+#define ADA4355_SERIAL_OUT_LANE_MODE_MASK	GENMASK(6, 4)
+#define ADA4355_DDR_ONE_LANE_WORDWISE		0x4
+#define ADA4355_DDR_TWO_LANE_BITWISE		0x2
+
+#define ADA4355_SERIAL_CHANNEL_STATUS_REG	0x22
+#define ADA4355_RESOLUTION_SAMPLE_RATE_REG	0x100
+#define ADA4355_125_RATE			0x06
+
+/*
+ * Pattern the digital interface is calibrated against. The pattern match
+ * block of the HDL core expects this exact value.
+ */
+#define ADA4355_CALIB_PATTERN			0xFFFC
+
+#define ADA4355_MAX_TEST_POINTS			32
+/*
+ * Number of data lanes of the LVDS interface. The frame signal gets its own
+ * I/O delay line, right after the data ones.
+ */
+#define ADA4355_MAX_DATA_LANES			2
+#define ADA4355_FRAME_LANE			ADA4355_MAX_DATA_LANES
+/* One set of test points per data lane, plus one for the frame signal. */
+#define ADA4355_MAX_CALIB_MAP_SIZE \
+	(ADA4355_MAX_TEST_POINTS * (ADA4355_MAX_DATA_LANES + 1))
+
+#define ADA4355_SYNC_TIMEOUT_US			1000
+/* Time the duty cycle stabilizer loop needs to relock after a rate change. */
+#define ADA4355_DCS_RELOCK_US			5
+
+#define ADA4355_MAX_SAMP_RATE_SPS		(125 * MEGA)
+
+/* ADC differential input span, ±1 V with the 1 V internal reference. */
+#define ADA4355_ADC_SPAN_mV			2000
+/* ADC differential input with no input current flowing. */
+#define ADA4355_ADC_BIAS_mV			825
+
+#define ADA4355_NUM_GSEL_GPIOS			2
+
+enum ada4355_tz_options {
+	ADA4355_TZ0,
+	ADA4355_TZ1,
+	ADA4355_TZ2,
+};
+
+static const unsigned int ada4355_tz_options_ohms[] = {
+	[ADA4355_TZ1] = 2000, /* -80 to +800 uA input range */
+	[ADA4355_TZ2] = 20000, /* -8.0 to +80 uA input range */
+	[ADA4355_TZ0] = 200000, /* -0.8 to +8.0 uA input range */
+};
+
+static const unsigned int ada4356_tz_options_ohms[] = {
+	[ADA4355_TZ1] = 4540, /* 3 to 300 uA input range */
+	[ADA4355_TZ2] = 11000, /* 1 to 100 uA input range */
+	[ADA4355_TZ0] = 133000, /* 0.1 to 10 uA input range */
+};
+
+struct ada4355_chip_info {
+	const char *name;
+	unsigned int id;
+	const unsigned int *gain_options;
+	int gain_options_size;
+};
+
+struct ada4355_state {
+	struct iio_backend *back;
+	struct spi_device *spi;
+	struct regmap *regmap;
+	struct clk *clk;
+	/* GSEL0 and GSEL1, in that order. */
+	struct gpio_descs *gsel;
+	/* Precomputed scale for each gain option, as {integer, nano} pairs. */
+	int scale_tb[ARRAY_SIZE(ada4355_tz_options_ohms)][2];
+	unsigned int scale_tb_size;
+	unsigned int scale_idx;
+	DECLARE_BITMAP(calib_map, ADA4355_MAX_CALIB_MAP_SIZE);
+	unsigned int calib_map_size;
+	/* Protect against concurrent accesses to the device and data content */
+	struct mutex lock;
+};
+
+static const struct regmap_config ada4355_regmap_config = {
+	.reg_bits = 16,
+	.val_bits = 8,
+	.read_flag_mask = BIT(7),
+};
+
+static int ada4355_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg,
+				      unsigned int writeval, unsigned int *readval)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read(st->regmap, reg, readval);
+
+	return regmap_write(st->regmap, reg, writeval);
+}
+
+/*
+ * The ADC output code decreases as the input current increases so the scale to
+ * milliamps is sign reversed.
+ */
+static void ada4355_fill_scale_tb(struct ada4355_state *st,
+				  struct ada4355_chip_info const *chip_info,
+				  const struct iio_chan_spec *chan)
+{
+	u64 numerator, denominator;
+	u32 rem;
+
+	st->scale_tb_size = chip_info->gain_options_size;
+	for (unsigned int i = 0; i < st->scale_tb_size; i++) {
+		numerator = (u64)ADA4355_ADC_SPAN_mV * NANO;
+		denominator = BIT_ULL(chan->scan_type.realbits) * chip_info->gain_options[i];
+		numerator = div64_u64(numerator, denominator);
+		st->scale_tb[i][0] = div_u64_rem(numerator, NANO, &rem);
+		st->scale_tb[i][1] = -(int)rem;
+	}
+}
+
+static int ada4355_get_scale(struct ada4355_state *st, int *val, int *val2)
+{
+	guard(mutex)(&st->lock);
+
+	*val = st->scale_tb[st->scale_idx][0];
+	*val2 = st->scale_tb[st->scale_idx][1];
+
+	return IIO_VAL_INT_PLUS_NANO;
+}
+
+static int ada4355_set_scale(struct ada4355_state *st, int val, int val2)
+{
+	unsigned long gsel;
+	int ret;
+
+	guard(mutex)(&st->lock);
+
+	for (unsigned int i = 0; i < st->scale_tb_size; i++) {
+		if (st->scale_tb[i][0] != val || st->scale_tb[i][1] != val2)
+			continue;
+
+		gsel = i;
+
+		ret = gpiod_multi_set_value_cansleep(st->gsel, &gsel);
+		if (ret)
+			return ret;
+
+		st->scale_idx = i;
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
+/*
+ * The ADC input is biased at ADA4355_ADC_BIAS_mV with no input current, so that
+ * is the code that has to read as zero milliamps.
+ */
+static int ada4355_get_offset(struct iio_chan_spec const *chan, int *val, int *val2)
+{
+	s64 tmp;
+
+	tmp = div_s64(((s64)ADA4355_ADC_BIAS_mV * MICRO) << chan->scan_type.realbits,
+		      ADA4355_ADC_SPAN_mV);
+	*val = div_s64_rem(-tmp, MICRO, val2);
+
+	return IIO_VAL_INT_PLUS_MICRO;
+}
+
+static int ada4355_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan,
+			    int *val, int *val2, long m)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+
+	switch (m) {
+	case IIO_CHAN_INFO_SCALE:
+		return ada4355_get_scale(st, val, val2);
+	case IIO_CHAN_INFO_OFFSET:
+		return ada4355_get_offset(chan, val, val2);
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		*val = clk_get_rate(st->clk);
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ada4355_read_avail(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      const int **vals, int *type, int *length,
+			      long mask)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		*vals = (const int *)st->scale_tb;
+		*type = IIO_VAL_INT_PLUS_NANO;
+		*length = st->scale_tb_size * 2;
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct iio_chan_spec ada4355_channel = {
+	.type = IIO_CURRENT,
+	.info_mask_separate = BIT(IIO_CHAN_INFO_SCALE) |
+			      BIT(IIO_CHAN_INFO_OFFSET) |
+			      BIT(IIO_CHAN_INFO_SAMP_FREQ),
+	.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),
+	.scan_type = {
+		.format = IIO_SCAN_FORMAT_SIGNED_INT,
+		.realbits = 14,
+		.storagebits = 16,
+		.shift = 2,
+	},
+};
+
+static const struct ada4355_chip_info ada4355_chip_info = {
+	.name = "ada4355",
+	.id = ADA4355_CHIP_ID,
+	.gain_options = ada4355_tz_options_ohms,
+	.gain_options_size = ARRAY_SIZE(ada4355_tz_options_ohms),
+};
+
+static const struct ada4355_chip_info ada4356_chip_info = {
+	.name = "ada4356",
+	.id = ADA4355_CHIP_ID,
+	.gain_options = ada4356_tz_options_ohms,
+	.gain_options_size = ARRAY_SIZE(ada4356_tz_options_ohms),
+};
+
+static int ada4355_testmode_set(struct ada4355_state *st, unsigned int test_mode)
+{
+	unsigned int val = 0;
+
+	if (test_mode != ADA4355_TEST_MODE_OFF)
+		val = ADA4355_TEST_MODE_RESET_PN |
+			FIELD_PREP(ADA4355_TEST_MODE_MASK, test_mode);
+
+	return regmap_write(st->regmap, ADA4355_TEST_MODE_REG, val);
+}
+
+/*
+ * Find the maximum number of successful points in a row and get the one in the
+ * middle.
+ */
+static unsigned int ada4355_find_optimal_point(const unsigned long *calib_map,
+					       unsigned int start,
+					       unsigned int nbits,
+					       unsigned int *val)
+{
+	unsigned int bit = start, end, start_cnt, cnt = 0;
+
+	for_each_clear_bitrange_from(bit, end, calib_map, nbits + start) {
+		if (end - bit > cnt) {
+			cnt = end - bit;
+			start_cnt = bit;
+		}
+	}
+
+	if (cnt)
+		*val = start_cnt + cnt / 2;
+
+	return cnt;
+}
+
+static int ada4355_calibrate_prepare(struct ada4355_state *st)
+{
+	struct iio_backend_data_fmt data = {
+		.enable = false,
+	};
+	int ret;
+
+	/*
+	 * The channel spec already accounts for the 14-bit sample being left
+	 * aligned in a 16-bit word, so the backend format conversion stays off
+	 * both during and after the calibration.
+	 */
+	ret = iio_backend_data_format_set(st->back, 0, &data);
+	if (ret)
+		return ret;
+
+	ret = ada4355_testmode_set(st, ADA4355_TEST_MODE_USER);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_USER_PATT1_MSB_REG,
+			   ADA4355_CALIB_PATTERN >> 8);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_USER_PATT1_LSB_REG,
+			   ADA4355_CALIB_PATTERN & 0xFF);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_USER_PATT2_MSB_REG,
+			   ADA4355_CALIB_PATTERN >> 8);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_USER_PATT2_LSB_REG,
+			   ADA4355_CALIB_PATTERN & 0xFF);
+	if (ret)
+		return ret;
+
+	return iio_backend_chan_enable(st->back, 0);
+}
+
+static int ada4355_calibrate_stop(struct ada4355_state *st)
+{
+	int ret;
+
+	ret = iio_backend_calibration_source_set(st->back,
+						 IIO_BACKEND_CALIB_SOURCE_NONE,
+						 0);
+	if (ret)
+		return ret;
+
+	ret = iio_backend_chan_disable(st->back, 0);
+	if (ret)
+		return ret;
+
+	return ada4355_testmode_set(st, ADA4355_TEST_MODE_OFF);
+}
+
+/*
+ * Sweep the I/O delay of one delay line while only the error source fed by
+ * that line is reported, and apply the delay in the middle of the widest run
+ * of valid test points. @offset is where this line's test points start in
+ * @st->calib_map.
+ */
+static int ada4355_calibrate_lane(struct ada4355_state *st,
+				  enum iio_backend_calib_source source,
+				  unsigned int lane, unsigned int offset)
+{
+	struct device *dev = &st->spi->dev;
+	unsigned int val, cnt;
+	bool stat;
+	int ret;
+
+	ret = iio_backend_calibration_source_set(st->back, source, lane);
+	if (ret)
+		return ret;
+
+	for (unsigned int point = 0; point < ADA4355_MAX_TEST_POINTS; point++) {
+		ret = iio_backend_iodelay_set(st->back, lane, point);
+		if (ret)
+			return ret;
+
+		ret = iio_backend_chan_status(st->back, 0, &stat);
+		if (ret)
+			return ret;
+
+		if (stat) {
+			dev_dbg(dev, "Invalid point(%u) for lane %u\n", point,
+				lane);
+			continue;
+		}
+
+		__clear_bit(offset + point, st->calib_map);
+	}
+
+	cnt = ada4355_find_optimal_point(st->calib_map, offset, ADA4355_MAX_TEST_POINTS,
+					 &val);
+	if (!cnt) {
+		dev_err(dev, "No valid delay found for lane %u\n", lane);
+		return -EIO;
+	}
+
+	/* "normalize" the selected value */
+	val -= offset;
+	dev_dbg(dev, "lane %u: selected delay: %u\n", lane, val);
+
+	return iio_backend_iodelay_set(st->back, lane, val);
+}
+
+static int ada4355_calibrate(struct ada4355_state *st)
+{
+	int ret, ret2;
+
+	/* all points invalid */
+	bitmap_fill(st->calib_map, st->calib_map_size);
+
+	ret = ada4355_calibrate_prepare(st);
+	if (ret)
+		return ret;
+
+	/*
+	 * The frame signal has to be aligned first: the pattern match block
+	 * only reports meaningful per-lane errors once the word boundary is
+	 * known.
+	 */
+	ret = ada4355_calibrate_lane(st, IIO_BACKEND_CALIB_SOURCE_FRAME,
+				     ADA4355_FRAME_LANE,
+				     ADA4355_MAX_DATA_LANES * ADA4355_MAX_TEST_POINTS);
+	if (ret)
+		return ret;
+
+	for (unsigned int lane = 0; lane < ADA4355_MAX_DATA_LANES; lane++) {
+		ret = ada4355_calibrate_lane(st,
+					     IIO_BACKEND_CALIB_SOURCE_DATA_LANE,
+					     lane,
+					     lane * ADA4355_MAX_TEST_POINTS);
+		if (ret) {
+			ret2 = ada4355_calibrate_stop(st);
+			if (ret2)
+				dev_err(&st->spi->dev, "calib stop error: %d\n", ret2);
+
+			return ret;
+		}
+	}
+
+	return ada4355_calibrate_stop(st);
+}
+
+/*
+ * The internal state machine needs a stable clock to bring the ADC up. If the
+ * clock was absent or unstable by then, the ADC starts in an unknown state and
+ * only a digital reset recovers it. The same holds for clock instability during
+ * normal operation, a rate change included. Unlike the soft reset of
+ * ADA4355_CHIP_CONFIG_REG, this one leaves the user registers untouched.
+ */
+static int ada4355_digital_reset(struct ada4355_state *st)
+{
+	unsigned int reg;
+	int ret;
+
+	ret = regmap_write(st->regmap, ADA4355_POWER_MODES_REG,
+			   ADA4355_PW_MODE_DIGITAL_RESET);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, ADA4355_POWER_MODES_REG, &reg);
+	if (ret)
+		return ret;
+
+	return regmap_clear_bits(st->regmap, ADA4355_POWER_MODES_REG,
+				 ADA4355_PW_MODE_DIGITAL_RESET);
+}
+
+static int ada4355_update_clock(struct ada4355_state *st, long r_clk)
+{
+	unsigned long sample_rate;
+	int ret;
+
+	/* Avoid unnecessary calibration if the clock won't change. */
+	sample_rate = clk_get_rate(st->clk);
+	if (sample_rate == r_clk)
+		return 0;
+
+	guard(mutex)(&st->lock);
+
+	ret = clk_set_rate(st->clk, r_clk);
+	if (ret)
+		return ret;
+
+	fsleep(ADA4355_DCS_RELOCK_US);
+
+	/*
+	 * Changing the rate under the running state machine counts as clock
+	 * instability, so put the digital side back into a known state.
+	 */
+	ret = ada4355_digital_reset(st);
+	if (ret)
+		return ret;
+
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION))
+		return ada4355_calibrate(st);
+
+	return 0;
+}
+
+static int ada4355_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int val, int val2, long mask)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+	long r_clk;
+
+	IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
+	if (IIO_DEV_ACQUIRE_FAILED(claim))
+		return -EBUSY;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		r_clk = clk_round_rate(st->clk, val);
+		if (r_clk < 1 || r_clk > ADA4355_MAX_SAMP_RATE_SPS)
+			return -ERANGE;
+
+		return ada4355_update_clock(st, r_clk);
+	case IIO_CHAN_INFO_SCALE:
+		return ada4355_set_scale(st, val, val2);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ada4355_write_raw_get_fmt(struct iio_dev *indio_dev,
+				     struct iio_chan_spec const *chan,
+				     long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		return IIO_VAL_INT_PLUS_NANO;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct iio_info ada4355_iio_info = {
+	.read_raw = ada4355_read_raw,
+	.read_avail = ada4355_read_avail,
+	.write_raw = ada4355_write_raw,
+	.write_raw_get_fmt = ada4355_write_raw_get_fmt,
+	.debugfs_reg_access = ada4355_debugfs_reg_access,
+};
+
+static int ada4355_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+
+	return iio_backend_chan_enable(st->back, 0);
+}
+
+static int ada4355_buffer_postdisable(struct iio_dev *indio_dev)
+{
+	struct ada4355_state *st = iio_priv(indio_dev);
+
+	return iio_backend_chan_disable(st->back, 0);
+}
+
+static const struct iio_buffer_setup_ops ada4355_backend_buffer_ops = {
+	.preenable = &ada4355_buffer_preenable,
+	.postdisable = &ada4355_buffer_postdisable,
+};
+
+static int ada4355_setup(struct ada4355_state *st,
+			 struct ada4355_chip_info const *chip_info)
+{
+	struct device *dev = &st->spi->dev;
+	struct gpio_desc *gpio_vld_en;
+	struct gpio_desc *gpio_lfp;
+	unsigned int id;
+	int ret;
+
+	gpio_vld_en = devm_gpiod_get(dev, "adi,vld-en", GPIOD_OUT_LOW);
+	if (IS_ERR(gpio_vld_en))
+		return dev_err_probe(dev, PTR_ERR(gpio_vld_en),
+				     "Failed to find adi,vld-en-gpios\n");
+
+	if (gpio_vld_en) {
+		gpiod_set_value_cansleep(gpio_vld_en, 1);
+		fsleep(1000);
+	}
+
+	gpio_lfp = devm_gpiod_get(dev, "adi,lfp", GPIOD_OUT_LOW);
+	if (IS_ERR(gpio_lfp))
+		return dev_err_probe(dev, PTR_ERR(gpio_lfp),
+				     "Failed to find adi,lfp-gpios\n");
+
+	ret = ada4355_digital_reset(st);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_CHIP_CONFIG_REG, 0x00);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_DEVICE_INDEX_REG, 0x02);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_SERIAL_CHANNEL_STATUS_REG, 0x03);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_DEVICE_INDEX_REG, 0x31);
+	if (ret)
+		return ret;
+
+	ret = regmap_read(st->regmap, ADA4355_CHIP_ID_REG, &id);
+	if (ret)
+		return ret;
+
+	if (id != chip_info->id)
+		dev_info(dev, "unknown chip ID, got 0x%X, expected 0x%X\n",
+			 id, chip_info->id);
+
+	ret = regmap_update_bits(st->regmap, ADA4355_SERIAL_OUT_DATA_CNTRL_REG,
+				 ADA4355_SERIAL_OUT_LANE_MODE_MASK,
+				 FIELD_PREP(ADA4355_SERIAL_OUT_LANE_MODE_MASK,
+					    ADA4355_DDR_TWO_LANE_BITWISE));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(st->regmap, ADA4355_TRANSFER_REG,
+			      ADA4355_TRANSFER_OVERRIDE);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(st->regmap, ADA4355_OUTPUT_MODE_REG,
+			   ADA4355_OUTPUT_MODE_TWOSCOMP);
+	if (ret)
+		return ret;
+
+	return regmap_write(st->regmap, ADA4355_RESOLUTION_SAMPLE_RATE_REG,
+			    ADA4355_125_RATE);
+}
+
+static int ada4355_gain_setup(struct ada4355_state *st)
+{
+	struct device *dev = &st->spi->dev;
+	unsigned long gsel;
+
+	st->gsel = devm_gpiod_get_array(dev, "adi,gsel", GPIOD_OUT_LOW);
+	if (IS_ERR(st->gsel))
+		return dev_err_probe(dev, PTR_ERR(st->gsel),
+				     "Failed to get adi,gsel-gpios\n");
+
+	if (st->gsel->ndescs != ADA4355_NUM_GSEL_GPIOS)
+		return dev_err_probe(dev, -EINVAL,
+				     "Expected %u adi,gsel-gpios, got %u\n",
+				     ADA4355_NUM_GSEL_GPIOS, st->gsel->ndescs);
+
+	/* Start with the widest input current range configuration. */
+	st->scale_idx = ADA4355_TZ1;
+	gsel = ADA4355_TZ1;
+
+	return gpiod_multi_set_value_cansleep(st->gsel, &gsel);
+}
+
+static int ada4355_interface_setup(struct ada4355_state *st)
+{
+	int ret;
+
+	ret = iio_backend_num_lanes_set(st->back, ADA4355_MAX_DATA_LANES);
+	if (ret)
+		return ret;
+
+	return iio_backend_interface_data_align(st->back,
+						ADA4355_SYNC_TIMEOUT_US);
+}
+
+static int ada4355_probe(struct spi_device *spi)
+{
+	const struct ada4355_chip_info *chip_info;
+	struct device *dev = &spi->dev;
+	struct iio_dev *indio_dev;
+	struct ada4355_state *st;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi = spi;
+
+	chip_info = spi_get_device_match_data(spi);
+	if (!chip_info)
+		return -ENODATA;
+
+	st->regmap = devm_regmap_init_spi(spi, &ada4355_regmap_config);
+	if (IS_ERR(st->regmap))
+		return PTR_ERR(st->regmap);
+
+	ret = devm_mutex_init(dev, &st->lock);
+	if (ret)
+		return ret;
+
+	st->calib_map_size = ADA4355_MAX_CALIB_MAP_SIZE;
+
+	st->clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(st->clk))
+		return PTR_ERR(st->clk);
+
+	indio_dev->name = chip_info->name;
+	indio_dev->channels = &ada4355_channel;
+	indio_dev->num_channels = 1;
+	indio_dev->info = &ada4355_iio_info;
+
+	ret = devm_regulator_get_enable(dev, "vcc");
+	if (ret < 0)
+		return dev_err_probe(dev, PTR_ERR(st->back),
+				     "failed to get vcc supply\n");
+
+	ret = ada4355_setup(st, chip_info);
+	if (ret)
+		return ret;
+
+	ada4355_fill_scale_tb(st, chip_info, &ada4355_channel);
+
+	ret = ada4355_gain_setup(st);
+	if (ret)
+		return ret;
+
+	st->back = devm_iio_backend_get(dev, NULL);
+	if (IS_ERR(st->back))
+		return dev_err_probe(dev, PTR_ERR(st->back),
+				     "failed to get IIO backend\n");
+
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_BUFFER)) {
+		indio_dev->setup_ops = &ada4355_backend_buffer_ops;
+		ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
+		if (ret)
+			return ret;
+	}
+
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_ENABLE)) {
+		ret = devm_iio_backend_enable(dev, st->back);
+		if (ret)
+			return ret;
+	}
+
+	ret = ada4355_interface_setup(st);
+	if (ret)
+		return dev_err_probe(dev, ret, "digital interface setup failed\n");
+
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) {
+		ret = ada4355_calibrate(st);
+		if (ret)
+			return ret;
+	}
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct spi_device_id ada4355_id[] = {
+	{ .name = "ada4355", .driver_data = (kernel_ulong_t)&ada4355_chip_info },
+	{ .name = "ada4356", .driver_data = (kernel_ulong_t)&ada4356_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, ada4355_id);
+
+static const struct of_device_id ada4355_of_match[] = {
+	{ .compatible = "adi,ada4355", .data = &ada4355_chip_info },
+	{ .compatible = "adi,ada4356", .data = &ada4356_chip_info },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, ada4355_of_match);
+
+static struct spi_driver ada4355_driver = {
+	.driver = {
+		.name = "ada4355",
+		.of_match_table = ada4355_of_match,
+	},
+	.probe = ada4355_probe,
+	.id_table = ada4355_id,
+};
+module_spi_driver(ada4355_driver);
+
+MODULE_AUTHOR("Marcelo Schmitt <marcelo.schmitt@analog.com>");
+MODULE_DESCRIPTION("Analog Devices ADA4355 device driver");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("IIO_BACKEND");
-- 
2.53.0


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

* Re: [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs
  2026-11-27 21:53 ` [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
@ 2026-11-27 22:06   ` sashiko-bot
  0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-27 22:06 UTC (permalink / raw)
  To: Marcelo Schmitt, devicetree; +Cc: robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] iio: adc: ada4355: pass ret instead of PTR_ERR(st->back) in
  ada4355_probe()
- [Medium] iio: adc: ada4355: missing cleanup on frame error in
  ada4355_calibrate()
- [Medium] iio: adc: ada4355: reject non-positive sampling freq in
  ada4355_write_raw()
- [Medium] iio: adc: ada4355: missing vea and ved supply enable in
  ada4355_probe()
--

commit 16b7c5a177ca16d48ca83a8d082c7d1e3ecf562a
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>

iio: adc: Add support for ADA4355 and similar ADCs

This commit adds an IIO ADC driver for the Analog Devices ADA4355 and
ADA4356 14-bit, 125 MSPS analog-to-digital converters with IIO backend
support.

> diff --git a/drivers/iio/adc/ada4355.c b/drivers/iio/adc/ada4355.c
> new file mode 100644
> index 0000000000000..5a3f480362538
> --- /dev/null
> +++ b/drivers/iio/adc/ada4355.c
> @@ -0,0 +1,822 @@

[ ... ]

> +static int ada4355_calibrate(struct ada4355_state *st)
> +{
> +	int ret, ret2;
> +
> +	/* all points invalid */
> +	bitmap_fill(st->calib_map, st->calib_map_size);
> +
> +	ret = ada4355_calibrate_prepare(st);
> +	if (ret)
> +		return ret;
> +
> +	/*
> +	 * The frame signal has to be aligned first: the pattern match block
> +	 * only reports meaningful per-lane errors once the word boundary is
> +	 * known.
> +	 */
> +	ret = ada4355_calibrate_lane(st, IIO_BACKEND_CALIB_SOURCE_FRAME,
> +				     ADA4355_FRAME_LANE,
> +				     ADA4355_MAX_DATA_LANES * ADA4355_MAX_TEST_POINTS);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Should this error path call ada4355_calibrate_stop(st) like the data-lane
loop below does?  If frame-lane calibration fails during a runtime clock
update (ada4355_write_raw() -> ada4355_update_clock()), returning directly
leaves backend channel 0 enabled and the ADC stuck in
ADA4355_TEST_MODE_USER outputting the 0xFFFC calibration pattern.

[ ... ]

> +static int ada4355_write_raw(struct iio_dev *indio_dev,
> +			     struct iio_chan_spec const *chan,
> +			     int val, int val2, long mask)
> +{
> +	struct ada4355_state *st = iio_priv(indio_dev);
> +	long r_clk;
> +
> +	IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> +	if (IIO_DEV_ACQUIRE_FAILED(claim))
> +		return -EBUSY;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_SAMP_FREQ:
> +		r_clk = clk_round_rate(st->clk, val);
> +		if (r_clk < 1 || r_clk > ADA4355_MAX_SAMP_RATE_SPS)
> +			return -ERANGE;
> +
> +		return ada4355_update_clock(st, r_clk);

[Severity: Medium]
Should val <= 0 be rejected before calling clk_round_rate()?
clk_round_rate() takes an unsigned long, so a negative val wraps to a large
positive rate that the clock provider can clamp into
[1, ADA4355_MAX_SAMP_RATE_SPS] (and 0 can round up to the minimum supported
rate), reconfiguring the ADC clock instead of returning an error.

[ ... ]

> +static int ada4355_probe(struct spi_device *spi)
> +{

[ ... ]

> +	ret = devm_regulator_get_enable(dev, "vcc");
> +	if (ret < 0)
> +		return dev_err_probe(dev, PTR_ERR(st->back),
> +				     "failed to get vcc supply\n");

[Severity: Medium]
Does this pass PTR_ERR(st->back) instead of ret to dev_err_probe()?
st->back is still NULL here, so ada4355_probe() returns 0 on regulator
failure, skipping deferred probe and leaving the device bound without
completing setup or registering the IIO device.

[Severity: Medium]
Should ada4355_probe() also enable the vea and ved supplies?  The
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml binding defines
vea-supply and ved-supply for the 1.8V analog and digital ADC rails, so
boards driving them from external regulators will leave those rails
unpowered.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795816065.git.marcelo.schmitt@analog.com?part=5

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

* Re: [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355
  2026-11-27 21:52 ` [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
@ 2026-11-27 22:07   ` sashiko-bot
  0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-27 22:07 UTC (permalink / raw)
  To: Marcelo Schmitt, devicetree; +Cc: robh, conor+dt

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Low] dt-bindings: iio: adc: missing maxItems on single-pin GPIO
  properties
- [Low] dt-bindings: iio: adc: typo in adi,lfp-gpios property name for
  low-pass filter
- [Low] dt-bindings: iio: adc: adi,gsel-gpios uses minItems/maxItems
  instead of items
- [Low] dt-bindings: iio: adc: copy-pasted pulsar_lvds URL in
  io-backends description
- [Low] dt-bindings: iio: adc: non-canonical property ordering in
  adi,ada4355.yaml
--

commit d52bd9771b5186971c4b9ce320e630e432350d61
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>

dt-bindings: iio: adc: Add ADA4355

This commit adds the Device Tree binding schema for the Analog Devices
ADA4355 and ADA4356 transimpedance current-to-bits receivers and adds a
corresponding entry in MAINTAINERS.

> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
> new file mode 100644
> index 0000000000000..d169619fef25a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml
> @@ -0,0 +1,104 @@

[ ... ]

> +  adi,vld-en-gpios:
> +    description: GPIO connected to the VLDEN pin for VLD output enable.

[Severity: Low]
Does adi,vld-en-gpios need maxItems: 1 (and similarly adi,lfp-gpios
below)?  In dtschema, *-gpios properties must specify their length via
maxItems or items, otherwise make dt_binding_check fails meta-schema
validation.

> +
> +  adi,gsel-gpios:
> +    description:
> +      GPIOs connected to the GSEL0 and GSEL1 pins, in that order, for
> +      transimpedance gain selection.
> +    minItems: 2
> +    maxItems: 2

[Severity: Low]
Since adi,gsel-gpios has a fixed two-entry list for GSEL0 and GSEL1,
should it use an items list with per-entry descriptions instead of
enumerating the pins in a free-form description with minItems and
maxItems?

> +
> +  adi,lfp-gpios:
> +    description:
> +      GPIO connected to FSEL for internal low pass filter bandwidth selection.

[Severity: Low]
Is adi,lfp-gpios a typo for adi,lpf-gpios (low-pass filter) or
adi,fsel-gpios (matching the FSEL pin name)?

> +
> +  io-backends:
> +    description:
> +      The AXI ADC IP block connected to the D+/- and DCO+/- lines of the
> +      ADC. An example backend can be found at
> +      http://analogdevicesinc.github.io/hdl/projects/pulsar_lvds/index.html.
> +    maxItems: 1

[Severity: Low]
Should this URL point to
https://analogdevicesinc.github.io/hdl/library/axi_ada4355/index.html
(from commit "dt-bindings: iio: adc: Add AXI ADA4355 IP CORE") instead
of the PulSAR LVDS project?

> +
> +required:
> +  - compatible
> +  - reg
> +  - vcc-supply
> +  - spi-3wire
> +  - spi-cpha
> +  - clocks
> +  - adi,vld-en-gpios
> +  - adi,gsel-gpios
> +  - adi,lfp-gpios
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    spi {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        adc@0 {
> +            compatible = "adi,ada4355";
> +            reg = <0>;
> +            spi-max-frequency = <100000>;
> +            spi-3wire;
> +            spi-cpha;
> +            vcc-supply = <&supply_3_3V>;
> +            clocks = <&ref_clk>;
> +            adi,vld-en-gpios = <&gpio0 89 GPIO_ACTIVE_HIGH>;
> +            adi,gsel-gpios = <&gpio0 86 GPIO_ACTIVE_HIGH>,
> +                             <&gpio0 87 GPIO_ACTIVE_HIGH>;
> +            adi,lfp-gpios = <&gpio0 88 GPIO_ACTIVE_HIGH>;
> +            io-backends = <&axi_adc>;
> +        };
> +    };

[Severity: Low]
This isn't a bug, but the property order across properties, required and
examples does not follow the canonical DT binding sequence: clocks
belongs right after reg, standard properties such as io-backends go
before vendor-specific adi,* properties, and required lists vcc-supply
before spi-3wire and spi-cpha unlike properties and examples.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795816065.git.marcelo.schmitt@analog.com?part=4

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

end of thread, other threads:[~2026-11-27 22:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 21:51 [PATCH v2 0/5] Add support for ADA4355 Marcelo Schmitt
2026-11-27 21:51 ` [PATCH v2 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
2026-11-27 21:52 ` [PATCH v2 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE Marcelo Schmitt
2026-11-27 21:52 ` [PATCH v2 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core Marcelo Schmitt
2026-11-27 21:52 ` [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
2026-11-27 22:07   ` sashiko-bot
2026-11-27 21:53 ` [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
2026-11-27 22:06   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox