Add support for ADA4355
cover Add support for ADA4355
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.
ADA4355 is partially similar to AD9467 in that both chips contain high performance ADCs and output data through pairs of LVDS data output pins. Though, ADA4355 is also different from AD9467 such that squeezing ADA4355 support into the same device driver would probably lead to a lot of rework.
According to LLM, AD9467 vs ADA4355 main differences are:
┌───────────────┬────────────────────────────────────┬────────────────────────────────────────────┐ │ │ AD9467 │ ADA4355 │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ │ A standalone 16-bit IF-sampling │ A complete current-in to bits µModule: │ │ Type │ ADC │ TIA, LPF, ADC driver (FDA), 14-bit ADC, │ │ │ │ LDO and all passives │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ │ Differential voltage, 2.0–2.5 V │ Single-ended current. Linear range is │ │ Input │ p-p programmable, 530 Ω / 3.5 pF, │ −80…+800 µA at TZ=2 kΩ (scales ÷10 per │ │ │ 900 MHz full-power BW │ gain step), survives 40 mA, 2 pF │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ │ SPI: reg 0x18 full-scale (2.0–2.5 │ Pins only: GSEL1/GSEL0 pick TZ (01=2 k, │ │ Gain/range │ V p-p), 0x0F external VREF, 0x2C │ 10=20 k, 00=200 k, 11 reserved), FSEL │ │ control │ AC/DC coupling, 0x36/0x107 buffer │ picks the LPF (100 MHz / 1 MHz). They have │ │ │ current │ no pull resistors and must be driven │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ Bandwidth │ 900 MHz │ TIA 43 / 18 / 1.6 MHz (per TZ), then LPF │ │ │ │ 100 or 1 MHz │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ │ │ Offset: 0 µA gives +0.825 V at the ADC, │ │ Transfer │ Bipolar around mid-scale │ and full scale is 1.65 V/TZ toward −0.825 │ │ function │ │ V. In practice the signal is unipolar and │ │ │ │ inverted │ ├───────────────┼────────────────────────────────────┼────────────────────────────────────────────┤ │ Applications │ Radar, wireless, instrumentation │ ToF/LiDAR, OTDR, mass spec, optical │ │ │ │ sensing (10 ns pulses) │ └───────────────┴────────────────────────────────────┴────────────────────────────────────────────┘
The most relevant differences at SPI and register map level are:
┌────────────────┬───────────────────────┬───────────────────────────────────────────────────────┐ │ │ AD9467 │ ADA4355 │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ Chip ID │ 0x50, plus a speed │ 0x8B │ │ │ grade in 0x02 │ │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ Start-up │ Nothing mandatory │ Mandatory sequence: 0x00=0x00, 0x05=0x02, 0x22=0x03, │ │ │ │ 0x05=0x31 │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ Device index │ — │ Selects data channel, DCO and FCO │ │ (0x05) │ │ │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ Test modes │ Modes 0000–0111 only, │ Adds 1000 user pattern (with PATT1/PATT2 regs │ │ (0x0D) │ no user pattern │ 0x19–0x1C), 1-/0-bit toggle, 1× sync, one-bit-high │ │ │ │ and mixed-frequency modes │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ Analog-side │ VREF, coupling, │ None. The datasheet says the registers "configure and │ │ registers │ buffer current, │ control the ADC only" │ │ │ offset (0x10) │ │ ├────────────────┼───────────────────────┼───────────────────────────────────────────────────────┤ │ │ │ DCS on/off in 0x09. Digital reset (0x08 = 0x03 then │ │ Other │ — │ 0x00) is required if the clock was not stable at │ │ │ │ power-up │ └────────────────┴───────────────────────┴───────────────────────────────────────────────────────┘
This patch series was assisted by LLM and introduces some code duplication from AD9467 into ADA4355. Though, my estimation is that this is going to keep things easier to maintain than adding ADA4355 support into ad9467.c.
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 | 798 ++++++++++++++++++ drivers/iio/adc/adi-axi-adc.c | 66 ++ drivers/iio/industrialio-backend.c | 23 + include/linux/iio/backend.h | 22 + 9 files changed, 1034 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml create mode 100644 drivers/iio/adc/ada4355.c
base-commit: 94921bc9eb214f838481faa847cda5c42e486013
Signature · 1 line
2.39.2
PATCH 1/5 iio: backend: Add calibration source interface
Some ADC front-ends send data over a configurable number of LVDS serial lanes and may also need to have the data frame calibrated before capture can start.
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.
--- drivers/iio/industrialio-backend.c | 23 +++++++++++++++++++++++ include/linux/iio/backend.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+)
drivers/iio/industrialio-backend.c +23 -0
@@ -869,6 +869,29 @@ 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 +* %IIO_BACKEND_CALIB_SOURCE_DATA_LANE. +* +* Restrict the error reported through iio_backend_chan_status() to a single +* source of the digital interface so that each lane can be calibrated +* independently. Backends are expected to report every error source again +* once %IIO_BACKEND_CALIB_SOURCE_NONE is selected. +* +* 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
include/linux/iio/backend.h +22 -0
@@ -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);
Signature · 1 line
2.39.2
PATCH 2/5 dt-bindings: iio: adc: Add AXI ADA4355 IP CORE
In reply to Marcelo SchmittThe AXI ADA4355 IP core provides the HDL interface to ADA4355 and similar 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.
Document a compatible string for the AXI ADA4355 IP core.
--- Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/adc/adi,axi-adc.yaml +1 -0
@@ -38,6 +38,7 @@ properties: - adi,axi-ad408x - adi,axi-ad7606x - adi,axi-ad485x + - adi,axi-ada4355 reg: maxItems: 1
Signature · 1 line
2.39.2
PATCH 3/5 iio: adc: adi-axi-adc: Support AXI ADA4355 IP core
In reply to Marcelo SchmittThe 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.
--- drivers/iio/adc/adi-axi-adc.c | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
drivers/iio/adc/adi-axi-adc.c +66 -0
@@ -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);
Signature · 1 line
2.39.2
PATCH 4/5 dt-bindings: iio: adc: Add ADA4355
In reply to Marcelo SchmittThe 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.
--- .../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
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +104 -0
@@ -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 <[email protected]> + +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>; + }; + };
MAINTAINERS +7 -0
@@ -1794,6 +1794,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 <[email protected]> +L: [email protected] +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 <[email protected]> L: [email protected]
Signature · 1 line
2.39.2
PATCH 5/5 iio: adc: Add support for ADA4355 and similar ADCs
In reply to Marcelo SchmittThe 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.
--- MAINTAINERS | 1 + drivers/iio/adc/Kconfig | 11 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ada4355.c | 798 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 811 insertions(+) create mode 100644 drivers/iio/adc/ada4355.c
MAINTAINERS +1 -0
@@ -1800,6 +1800,7 @@ L: [email protected] 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 <[email protected]>
drivers/iio/adc/Kconfig +11 -0
@@ -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
drivers/iio/adc/Makefile +1 -0
@@ -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
drivers/iio/adc/ada4355.c new file +798 -0
798 lines not on this page · raw message
Signature · 1 line
2.39.2
[email protected]
AI reviewRe: [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] iio: adc: ada4355: backend channel 0 left disabled after calibration - [High] iio: adc: ada4355…
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [High] iio: adc: ada4355: backend channel 0 left disabled after calibration
- [High] iio: adc: ada4355: 1000x scale error in ada4355_fill_scale_tb()
- [Medium] iio: adc: ada4355: negative sampling freq wraps in ada4355_write_raw()
- [Medium] iio: adc: ada4355: missing cleanup on error in ada4355_calibrate()
- [Medium] iio: adc: ada4355: power supply regulators not enabled in ada4355_probe()
- [Low] iio: adc: ada4355: inconsistent st->lock usage in read and debugfs paths
--
commit 3d8753d370ebe3f8cd0cc6198719fc1f9fb5fb1d
Author: Marcelo Schmitt <[email protected]>
iio: adc: Add support for ADA4355 and similar ADCs
This commit adds an IIO ADC driver for the Analog Devices ADA4355 and ADA4356 current-input ADCs, using SPI for configuration and an IIO backend for LVDS data capture.
Quoted 5 lines
drivers/iio/adc/ada4355.c new file +0
-0
[ ... ]
Quoted 18 lines
drivers/iio/adc/ada4355.c new file +18
-0+/* 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 */ +};
[ ... ]
Quoted 20 lines
drivers/iio/adc/ada4355.c new file +20
-0+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) +{ +u64 numerator, denominator; +u32 rem;
drivers/iio/adc/ada4355.c line 181
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ + 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 *MILLI ; + denominator =BIT_ULL (st->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; + } +}
[Severity: High]
Does multiplying ADA4355_ADC_SPAN_mV by MILLI here make st->scale_tb[][] 1000 times too large?
ADA4355_ADC_SPAN_mV is already in millivolts (2000 mV) and chip_info->gain_options[i] is in Ohms, so dividing ADA4355_ADC_SPAN_mV by gain_options[i] directly gives the full-scale current in milliamps. The extra MILLI factor reports microamps per LSB instead of milliamps per LSB (for example, -0.061035156 mA/LSB instead of -0.000061035 mA/LSB at 2000 Ohms).
Quoted 5 lines
drivers/iio/adc/ada4355.c new file +5
-0+ +static int ada4355_get_scale (struct ada4355_state *st,int *val,int *val2) +{ + *val = st->scale_tb[st->scale_idx][0 ]; + *val2 = st->scale_tb[st->scale_idx][1 ];
drivers/iio/adc/ada4355.c line 196
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ +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);
[Severity: Low]
Should ada4355_get_scale() and ada4355_debugfs_reg_access() also take st->lock?
ada4355_set_scale() and ada4355_update_clock() both run under IIO_DEV_ACQUIRE_DIRECT_MODE() in ada4355_write_raw() and take st->lock, whereas ada4355_get_scale() reads st->scale_idx twice without st->lock and ada4355_debugfs_reg_access() accesses st->regmap without serializing against the multi-register reset and calibration sequences in ada4355_update_clock().
[ ... ]
Quoted 2 lines
drivers/iio/adc/ada4355.c new file +2
-0+static int ada4355_calibrate_prepare (struct ada4355_state *st) +{
[ ... ]
Quoted 9 lines
drivers/iio/adc/ada4355.c new file +9
-0+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,
drivers/iio/adc/ada4355.c line 388
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ 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 ); +}
[Severity: High]
Does disabling backend channel 0 in ada4355_calibrate_stop() leave the channel disabled during buffered captures?
Nothing else in the driver calls iio_backend_chan_enable(st->back, 0):ada4355_iio_info does not implement update_scan_mode and no buffer setup ops are registered. Once ada4355_calibrate_stop() disables channel 0 (or if the backend does not set IIO_BACKEND_CAP_CALIBRATION and skips ada4355_calibrate() altogether), backend channel 0 stays disabled when userspace starts a buffered capture.
[ ... ]
Quoted 24 lines
drivers/iio/adc/ada4355.c new file +24
-0+static int ada4355_calibrate (struct ada4355_state *st) +{ +unsigned int lane; +int ret; + +/* 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 (lane =0 ; lane <ADA4355_MAX_DATA_LANES ; lane++) {\
drivers/iio/adc/ada4355.c line 474
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ ret =ada4355_calibrate_lane (st, +IIO_BACKEND_CALIB_SOURCE_DATA_LANE , + lane, + lane *ADA4355_MAX_TEST_POINTS ); +if (ret) +return ret; + } + +return ada4355_calibrate_stop (st); +}
[Severity: Medium]
If ada4355_calibrate_lane() fails during a runtime clock update in ada4355_update_clock(), does returning early here leave the ADC in ADA4355_TEST_MODE_USER and the backend calibration source enabled?
[ ... ]
Quoted 8 lines
drivers/iio/adc/ada4355.c new file +8
-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);
drivers/iio/adc/ada4355.c line 550
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+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 (!in_range (r_clk,1 ,ADA4355_MAX_SAMP_RATE_SPS )) +return -ERANGE ; + +return ada4355_update_clock (st, r_clk);
[Severity: Medium]
Can a negative or zero val in ada4355_write_raw() reprogram the clock instead of returning an error?
clk_round_rate() takes an unsigned long rate, so a negative val sign-extends to a large unsigned value and rounds down to the clock provider's maximum rate (and 0 rounds up to its minimum rate). If that rounded rate falls within [1, ADA4355_MAX_SAMP_RATE_SPS], ada4355_update_clock() applies it.
[ ... ]
drivers/iio/adc/ada4355.c line 730
Quoted 11 lines
drivers/iio/adc/ada4355.c new file +11
-0+ 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; + st->chan = &ada4355_channel; + + ret =ada4355_setup (st, chip_info);
[Severity: Medium]
Should ada4355_probe() enable the vcc-supply, vea-supply, and ved-supply regulators before accessing the device in ada4355_setup()?
The DT binding in Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml requires vcc-supply and lists vea-supply and ved-supply as optional supplies, but the driver never requests or enables them, leaving the chip unpowered on boards where those regulators are not always-on.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v1 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE
In reply to Marcelo Schmittpw-bot: not-applicable
Re: [PATCH v1 4/5] dt-bindings: iio: adc: Add ADA4355
In reply to Marcelo SchmittQuoted 4 lines · Marcelo Schmitt
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.
Please explain why the 4356 differs rom the 4355 such that it cannot use a fallback compatible.
Thanks,
Conor.
pw-bot: changes-requested
Quoted 139 lines
Signed-off-by Marcelo Schmitt <[email protected]>--- .../bindings/iio/adc/adi,ada4355.yaml | 104 ++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ada4355.yamlDocumentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +104
-0@@ -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 <[email protected]> + +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>; + }; + };MAINTAINERS +7
-0@@ -1794,6 +1794,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 <[email protected]> +L: [email protected] +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 <[email protected]> L: [email protected]Signature · 1 line
2.39.2
Jonathan Cameron
maintainerRe: [PATCH v1 1/5] iio: backend: Add calibration source interface
In reply to Marcelo SchmittQuoted 23 lines · On Wed, 18 Nov 2026 10:03:17 -0300 Marcelo Schmitt…
Some ADC front-ends send data over a configurable number of LVDS serial lanes and may also need to have the data frame calibrated before capture can start.
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.
Signed-off-by Marcelo Schmitt <[email protected]>--- drivers/iio/industrialio-backend.c | 23 +++++++++++++++++++++++ include/linux/iio/backend.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+)drivers/iio/industrialio-backend.c +1
-0@@ -869,6 +869,29 @@ int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us) }EXPORT_SYMBOL_NS_GPL (iio_backend_interface_data_align,"IIO_BACKEND" ); +/**
drivers/iio/industrialio-backend.c int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us) · line 882
Quoted 10 lines
drivers/iio/industrialio-backend.c +10
-0+* 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 +* %IIO_BACKEND_CALIB_SOURCE_DATA_LANE. +* +* Restrict the error reported through iio_backend_chan_status() to a single +* source of the digital interface so that each lane can be calibrated +* independently. Backends are expected to report every error source again +* once %IIO_BACKEND_CALIB_SOURCE_NONE is selected.
I don't follow this description at all. If there is more than one how does it report 'every' error source?
Add some explanation, probably to the commit message on how the flow using this works. We might need more info here as well.
Quoted 69 lines
drivers/iio/industrialio-backend.c +12
-0+* +* 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 include/linux/iio/backend.h +22
-0@@ -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);
Jonathan Cameron
maintainerRe: [PATCH v1 4/5] dt-bindings: iio: adc: Add ADA4355
In reply to Conor DooleyQuoted 8 lines · On Wed, 18 Nov 2026 17:39:46 +0000 Conor Dooley <[email protected]> wrote:
Quoted 4 lines · Marcelo Schmitt
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.
Please explain why the 4356 differs rom the 4355 such that it cannot use a fallback compatible.
Also mention it in the patch description!
I was briefly very confused at Conor's comment :)
Quoted 143 lines
Thanks,
Conor.
pw-bot: changes-requestedQuoted 139 lines
Signed-off-by Marcelo Schmitt <[email protected]>--- .../bindings/iio/adc/adi,ada4355.yaml | 104 ++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 111 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ada4355.yamlDocumentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +104
-0@@ -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 <[email protected]> + +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>; + }; + };MAINTAINERS +7
-0@@ -1794,6 +1794,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 <[email protected]> +L: [email protected] +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 <[email protected]> L: [email protected]Signature · 1 line
2.39.2
Jonathan Cameron
maintainerRe: [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs
In reply to Marcelo SchmittQuoted 10 lines · On Wed, 18 Nov 2026 10:04:33 -0300 Marcelo Schmitt…
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 <[email protected]>
I'm feeling lazy, and it's a v1 so I haven't actually looked at what sashiko found to see if it is right. But it found stuff..
https://sashiko.dev/#/patchset/cover.1795003864.git.marcelo.schmitt%40analog.com
A few things I noticed inline.
Quoted 19 lines
drivers/iio/adc/ada4355.c new file +13
-0@@ -0,0 +1,798 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Analog Devices ADA4355 device driver +* +* Copyright (C) 2026 Analog Devices, Inc. +* Author: Marcelo Schmitt <[email protected]> +* +* Expanded and improved version made on top of preliminary code from: +* Antoniu Miclaus <[email protected]> +* Pop Ioan Daniel <[email protected]> +*/ + +#include <linux/bitfield.h>
drivers/iio/adc/ada4355.c line 23
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+#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/kernel.h>
No to including this in new code. Need to use more specific includes and not that catch all unless this really does use one of the things still defined in there.
drivers/iio/adc/ada4355.c line 36
Quoted 13 lines
drivers/iio/adc/ada4355.c new file +13
-0+#include <linux/minmax.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/property.h> +#include <linux/regmap.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> +#include <linux/iio/sysfs.h>
Is that used? I maybe missed something.
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+/* +* 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) +{
drivers/iio/adc/ada4355.c line 409
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+struct device *dev = &st->spi->dev; +unsigned int point, val, cnt; +bool stat; +int ret; + + ret =iio_backend_calibration_source_set (st->back, source, lane); +if (ret) +return ret; + +for (point =0 ; point <ADA4355_MAX_TEST_POINTS ; point++) {
for (unsigned int point = 0;
Quoted 45 lines
drivers/iio/adc/ada4355.c new file +45
-0+ 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) +{ +unsigned int lane; +int ret; + +/* 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
drivers/iio/adc/ada4355.c line 464
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+* 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 (lane =0 ; lane <ADA4355_MAX_DATA_LANES ; lane++) {
for (unsigned int lane = 0; lane < ADA4355_MAX_DATA_LANES; lane++) {Going to take a while for us to all train ourselves to prefer this style but it is both acceptable and once or twice Linus has said he prefers keeping the scope tightly defined like this.
Quoted 18 lines
drivers/iio/adc/ada4355.c new file +16
-0+ ret =ada4355_calibrate_lane (st, +IIO_BACKEND_CALIB_SOURCE_DATA_LANE , + lane, + lane *ADA4355_MAX_TEST_POINTS ); +if (ret) +return ret; + } + +return ada4355_calibrate_stop (st); +} + +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);
drivers/iio/adc/ada4355.c line 547
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+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 (!in_range (r_clk,1 ,ADA4355_MAX_SAMP_RATE_SPS ))
This is a little odd as in_range takes start + length.
That happens to work here because the start is 1. I'd
just check <1 || > MAX_SAMP_RATE_SPS.
Quoted 52 lines
drivers/iio/adc/ada4355.c new file +51
-0+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_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 );
drivers/iio/adc/ada4355.c line 630
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+if (ret) +return ret; + + ret =regmap_read (st->regmap,ADA4355_CHIP_ID_REG , &id); +if (ret) +return ret; + +if (id != chip_info->id) +dev_warn (dev,"Mismatch CHIP_ID, got 0x%X, expected 0x%X\n" , + id, chip_info->id);
Given we want fallback compatibles to work if appropriate, I'd relax that to dev_info. And say something about unknown id. Mismatch sounds scary.
Quoted 14 lines
drivers/iio/adc/ada4355.c new file +14
-0+ + 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,
drivers/iio/adc/ada4355.c line 654
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ ADA4355_OUTPUT_MODE_TWOSCOMP); +if (ret) +return ret; + + ret =regmap_write (st->regmap,ADA4355_RESOLUTION_SAMPLE_RATE_REG , +ADA4355_125_RATE ); +if (ret) +return ret; + +return 0 ;
return regmap_write();
Quoted 31 lines
drivers/iio/adc/ada4355.c new file +30
-0+} + +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 ;
drivers/iio/adc/ada4355.c line 728
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ + 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; + st->chan = &ada4355_channel;
Why in two places? If you just want it in the scale table calc, pass it in directly. Don't think it is used after that.
drivers/iio/adc/ada4355.c line 760
Quoted 4 lines
drivers/iio/adc/ada4355.c new file +4
-0+ ret =ada4355_interface_setup (st); +if (ret) +return dev_err_probe (dev, ret, +"failed to setup the digital interface\n" );
Go a bit longer. As long as it's not too far past 80 I don't mind. Particularly when the end bit is the tail end of an error message.
Quoted 9 lines
drivers/iio/adc/ada4355.c new file +9
-0+ +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); +}
Re: [PATCH v1 4/5] dt-bindings: iio: adc: Add ADA4355
In reply to Jonathan CameronHello,
Quoted 12 lines · Jonathan Cameron
Quoted 8 lines · On Wed, 18 Nov 2026 17:39:46 +0000 Conor Dooley <[email protected]> wrote:
Quoted 4 lines · Marcelo Schmitt
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.
Please explain why the 4356 differs rom the 4355 such that it cannot use a fallback compatible.
4356 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.
Will provide this explanation in v2.
Quoted 3 lines
Also mention it in the patch description!
I was briefly very confused at Conor's comment :)
Thanks,
Marcelo
Re: [PATCH v1 1/5] iio: backend: Add calibration source interface
In reply to Jonathan CameronQuoted 40 lines · Jonathan Cameron
Quoted 23 lines · On Wed, 18 Nov 2026 10:03:17 -0300 Marcelo Schmitt…
Some ADC front-ends send data over a configurable number of LVDS serial lanes and may also need to have the data frame calibrated before capture can start.
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.
Signed-off-by Marcelo Schmitt <[email protected]>--- drivers/iio/industrialio-backend.c | 23 +++++++++++++++++++++++ include/linux/iio/backend.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+)drivers/iio/industrialio-backend.c +1
-0@@ -869,6 +869,29 @@ int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us) }EXPORT_SYMBOL_NS_GPL (iio_backend_interface_data_align,"IIO_BACKEND" ); +/** drivers/iio/industrialio-backend.c int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us) · line 882
Quoted 10 lines
drivers/iio/industrialio-backend.c +10
-0+* 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 +* %IIO_BACKEND_CALIB_SOURCE_DATA_LANE. +* +* Restrict the error reported through iio_backend_chan_status() to a single +* source of the digital interface so that each lane can be calibrated +* independently. Backends are expected to report every error source again +* once %IIO_BACKEND_CALIB_SOURCE_NONE is selected. I don't follow this description at all. If there is more than one how does it report 'every' error source?
Quoted 2 lines
Add some explanation, probably to the commit message on how the flow using this works. We might need more info here as well.
I've complemented the explanation about this new backend operation. I'll try to further improve for v2 if the description below is still sounding confusing.
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.
sashiko comments seem to apply. Will, fix those for v2.
Thanks,
Marcelo