Add support for ADA4355
v2 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.
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/[email protected]/
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
Signature · 1 line
2.53.0
PATCH v2 1/5 iio: backend: Add calibration source interface
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.
--- drivers/iio/industrialio-backend.c | 28 ++++++++++++++++++++++++++++ include/linux/iio/backend.h | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+)
drivers/iio/industrialio-backend.c +28 -0
@@ -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
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.53.0
PATCH v2 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.53.0
PATCH v2 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 | 822 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 835 insertions(+) create mode 100644 drivers/iio/adc/ada4355.c
MAINTAINERS +1 -0
@@ -1802,6 +1802,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 +822 -0
822 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 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 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.
--- 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.53.0
PATCH v2 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.
---
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
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
@@ -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 <[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.53.0
[email protected]
AI reviewRe: [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs
In reply to Marcelo SchmittThank 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…
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 <[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 14-bit, 125 MSPS analog-to-digital converters with IIO backend support.
Quoted 6 lines
drivers/iio/adc/ada4355.c new file +0
-0@@ -0,0 +1,822 @@
[ ... ]
Quoted 11 lines
drivers/iio/adc/ada4355.c new file +11
-0+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; +
drivers/iio/adc/ada4355.c line 462
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+/* +* 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.
[ ... ]
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 555
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 (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.
[ ... ]
Quoted 2 lines
drivers/iio/adc/ada4355.c new file +2
-0+static int ada4355_probe (struct spi_device *spi) +{
[ ... ]
drivers/iio/adc/ada4355.c line 752
Quoted 4 lines
drivers/iio/adc/ada4355.c new file +4
-0+ 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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355
In reply to Marcelo SchmittThank 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…
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 <[email protected]>
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.
Quoted 6 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +0
-0@@ -0,0 +1,104 @@
[ ... ]
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml line 50
Quoted 2 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +2
-0+ 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.
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml line 57
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +7
-0+ + 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?
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +4
-0+ + 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)?
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml line 68
Quoted 7 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +7
-0+ + 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?
Quoted 26 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +26
-0+ +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;
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml line 104
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,ada4355.yaml new file +10
-0+ 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.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jonathan Cameron
maintainerQuoted 20 lines · On Fri, 27 Nov 2026 18:51:32 -0300 Marcelo Schmitt…
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
- Alternativein_rangecheck.
- Declaring loop counters within loop declaration.
- Unknown chip ID message update.
- No longer keeping extra IIO channel pointer in state struct.
Quoted 2 lines
Previous submissions:
v1: https://lore.kernel.org/linux-iio/[email protected]/
I'm sure you'd check anyway but for anyone else reading along, Sashiko is not at all happy with the binding.
+ some smaller bits in the driver parts.
As such I might take a somewhat more superficial look than otherwise at least partly due to my 483 unread IIO related emails.
Jonathan
Quoted 28 lines
With best regards,
MarceloMarcelo 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.cbase-commit:
39508411b82d4dc29dd245bb471ec9ecc1111c9d
Jonathan Cameron
maintainerRe: [PATCH v2 4/5] dt-bindings: iio: adc: Add ADA4355
In reply to Marcelo SchmittQuoted 5 lines · On Fri, 27 Nov 2026 18:52:57 -0300 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.
Quoted 8 lines
Signed-off-by Marcelo Schmitt <[email protected]>---
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_scalefrom 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.
We'd normally have a short version of this in the commit message as it is useful to capture for the longer term. Provides info to those who may want to add more supported parts.
Otherwise, nothing to add to our friend Sashiko's feedback.
Jonathan
Jonathan Cameron
maintainerRe: [PATCH v2 5/5] iio: adc: Add support for ADA4355 and similar ADCs
In reply to Marcelo SchmittQuoted 4 lines · On Fri, 27 Nov 2026 18:53:17 -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.
I'd be tempted to put a little more in here for what this is intended for. Anyone trying to align this with the datasheet talking about a Programmable Transimpedance Current to Bits Receiver uModule.
Quoted 6 lines
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]>
A few minor things inline.
drivers/iio/adc/ada4355.c
Quoted 7 lines
drivers/iio/adc/ada4355.c new file +1
-0+enum ada4355_tz_options {
I'd spell out what tz is somewhere here. Perhaps as a comment. Transimpedance Amplifier Gain isn't obvious to me!
Quoted 21 lines
drivers/iio/adc/ada4355.c new file +20
-0+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 */ + +static int ada4355_set_scale(struct ada4355_state *st, int val, int val2) +{ + unsigned long gsel; + int ret;
drivers/iio/adc/ada4355.c line 205
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ +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);
Why not iterate over gsel? An unsigned long is fine for the index as well.
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +9
-0+if (ret) +return ret; + + st->scale_idx = i; +return 0 ; + } + +return -EINVAL ; +}
drivers/iio/adc/ada4355.c line 316
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+/* +* 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 ;
Don't mix declarations that assign with ones that don't. It makes for less readable code to save a few lines.
Quoted 32 lines
drivers/iio/adc/ada4355.c new file +32
-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)
drivers/iio/adc/ada4355.c line 358
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+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)
Why not a bulk write after appropriate endian conversion.
Quoted 39 lines
drivers/iio/adc/ada4355.c new file +37
-0+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_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" );
drivers/iio/adc/ada4355.c line 636
Quoted 10 lines
drivers/iio/adc/ada4355.c new file +10
-0+ + 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 );
I started writing a comment about making those magic values meaningful. Then discovered that bit isn't defined except for a note to see the
ADC SPI Startup Sequence Add a comment to say that starting at theCONFIG_REG write above these 4 writes are 'special' and the really are magic value.
Might be better to do this as
/* See ADC SPI START-UP SEQUENCE */
const struct regmap_sequence spi_startup[] = {
REG_SEQ0(ADA4355_CHIP_CONFIG_REG, 0x00),
REG_SEQ0(ADA4355_DEVICE_INDEX_REG, 0x02),
REG_SEQ0(ADA4355_SERIAL_CHANNEL_STATUS_REG, 0x03),
REG_SEQ0(ADA4355_DEVICE_INDEX_REG, 0x31),
};
ret = regmap_multireg_write(st->regmap, spi_startup, ARRAY_SIZE(spi_startup));
if (ret)
return ret;It isn't much more compact (which is why I don't normally encourage use of that approach) but it does make it clear they are considered a sequence that must be fully executed.
Quoted 39 lines
drivers/iio/adc/ada4355.c new file +39
-0+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 ); +}