mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux@analog.com>,
	<Michael.Hennerich@analog.com>, <nuno.sa@analog.com>,
	<eblanc@baylibre.com>, <dlechner@baylibre.com>, <andy@kernel.org>,
	<robh@kernel.org>, <krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<olivier.moysan@foss.st.com>, <marcelo.schmitt1@gmail.com>
Subject: Re: [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs
Date: Thu, 19 Nov 2026 03:16:59 +0000	[thread overview]
Message-ID: <20261119031659.6a84e737@jic23-hlaptop> (raw)
In-Reply-To: <2f5e83aa17aea08bbff69ca6ef7d32b11368f518.1795003864.git.marcelo.schmitt@analog.com>

On Wed, 18 Nov 2026 10:04:33 -0300
Marcelo Schmitt <marcelo.schmitt@analog.com> wrote:

> 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>
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.

> diff --git a/drivers/iio/adc/ada4355.c b/drivers/iio/adc/ada4355.c
> new file mode 100644
> index 000000000000..7f9f58a14385
> --- /dev/null
> +++ b/drivers/iio/adc/ada4355.c
> @@ -0,0 +1,798 @@
> +// 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/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.

> +#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.





> +/*
> + * 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 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; 

> +		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
> +	 * 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.

> +		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);
> +	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.

> +			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);
> +	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.


> +
> +	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;
> +
> +	ret = regmap_write(st->regmap, ADA4355_RESOLUTION_SAMPLE_RATE_REG,
> +			   ADA4355_125_RATE);
> +	if (ret)
> +		return ret;
> +
> +	return 0;

	return regmap_write();

> +}

> +
> +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;
> +	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.


> +	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.

> +
> +	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);
> +}


      reply	other threads:[~2026-11-19  3:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 13:02 [PATCH v1 0/5] Add support for ADA4355 Marcelo Schmitt
2026-11-18 13:03 ` [PATCH v1 1/5] iio: backend: Add calibration source interface Marcelo Schmitt
2026-11-19  2:57   ` Jonathan Cameron
2026-11-18 13:03 ` [PATCH v1 2/5] dt-bindings: iio: adc: Add AXI ADA4355 IP CORE Marcelo Schmitt
2026-11-18 17:38   ` Conor Dooley
2026-11-18 13:03 ` [PATCH v1 3/5] iio: adc: adi-axi-adc: Support AXI ADA4355 IP core Marcelo Schmitt
2026-11-18 13:04 ` [PATCH v1 4/5] dt-bindings: iio: adc: Add ADA4355 Marcelo Schmitt
2026-11-18 17:39   ` Conor Dooley
2026-11-19  2:59     ` Jonathan Cameron
2026-11-18 13:04 ` [PATCH v1 5/5] iio: adc: Add support for ADA4355 and similar ADCs Marcelo Schmitt
2026-11-19  3:16   ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119031659.6a84e737@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=marcelo.schmitt@analog.com \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®