All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Janani Sunil <janani.sunil@analog.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Olivier Moysan" <olivier.moysan@foss.st.com>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Michael Walle" <mwalle@kernel.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	linux@analog.com, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org,
	jananisunil.dev@gmail.com,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Subject: Re: [PATCH v7 05/17] iio: adc: Add AD7768 and AD7768-4 core support
Date: Fri, 11 Sep 2026 11:14:38 +0300	[thread overview]
Message-ID: <aqO4bj8L6FDB_-2F@ashevche-desk.local> (raw)
In-Reply-To: <20260910-ad7768-driver-v7-5-7f70b07627e1@analog.com>

On Thu, Sep 10, 2026 at 07:36:23PM +0200, Janani Sunil wrote:
> Add core support for the AD7768 and AD7768-4 simultaneous sampling ADCs.
> Configure supplies, clock and reset, use a custom regmap bus for the SPI
> protocol, and parse the enabled channels and input buffer settings from
> devicetree.
> 
> Connect the converter to an IIO backend for buffered capture with CRC,
> provide a fixed safe wideband sampling configuration and add runtime
> power management.

...

> +static const struct regmap_config ad7768_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = AD7768_REG_CHOP_CTRL,
> +	/*
> +	 * Regmap bulk transfers use one starting address, while each register
> +	 * access requires a separate 16-bit SPI frame and reads use an off-frame
> +	 * response. Split bulk transfers into individual register accesses.
> +	 */

Here, or in additional place it might be good to mention why no cache is used.

> +	.use_single_read = true,
> +	.use_single_write = true,
> +	.readable_reg = ad7768_readable_reg,
> +};
> +
> +static const struct regmap_config ad7768_4_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = AD7768_REG_CHOP_CTRL,
> +	/*
> +	 * Regmap bulk transfers use one starting address, while each register
> +	 * access requires a separate 16-bit SPI frame and reads use an off-frame
> +	 * response. Split bulk transfers into individual register accesses.
> +	 */

Ditto.

> +	.use_single_read = true,
> +	.use_single_write = true,
> +	.readable_reg = ad7768_4_readable_reg,
> +};

...

> +	/*
> +	 * DCLK(min) is ODR * channels per DOUTx * 32. With fast mode
> +	 * (fMOD = MCLK / 4) and x64 decimation, this gives:
> +	 * MCLK / DCLK = 8 * data lines / channels.
> +	 */
> +	dclk_div = 8 * st->datalines / st->chip_info->num_channels;
> +	switch (dclk_div) {
> +	case 1:
> +		dclk_div_reg = AD7768_INTERFACE_CFG_DCLK_DIV_1;
> +		break;
> +	case 2:
> +		dclk_div_reg = AD7768_INTERFACE_CFG_DCLK_DIV_2;
> +		break;
> +	case 4:
> +		dclk_div_reg = AD7768_INTERFACE_CFG_DCLK_DIV_4;
> +		break;
> +	case 8:
> +		dclk_div_reg = AD7768_INTERFACE_CFG_DCLK_DIV_8;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}

Yep, this is clearer.

...

> +static int ad7768_parse_config(struct iio_dev *indio_dev,
> +			       struct device *dev)
> +{
> +	struct ad7768_precharge_config precharge_cfg[AD7768_MAX_CHANNEL] = { };
> +	struct ad7768_state *st = iio_priv(indio_dev);
> +	const unsigned int *available_datalines;
> +	bool datalines_valid = false;
> +	struct iio_chan_spec *chan;
> +	unsigned int num_channels;
> +	unsigned long standby_mask;
> +	unsigned int len;
> +	int chan_idx = 0;
> +	int ret;
> +
> +	num_channels = device_get_named_child_node_count(dev, "channel");

> +

Unneeded blank line.

> +	if (num_channels == 0)
> +		return dev_err_probe(dev, -ENOENT, "No channel specified\n");
> +
> +	if (num_channels > st->chip_info->num_channels)
> +		return dev_err_probe(dev, -ENOSPC, "Invalid number of channels\n");
> +
> +	chan = devm_kcalloc(dev, num_channels, sizeof(*chan), GFP_KERNEL);
> +	if (!chan)
> +		return -ENOMEM;
> +
> +	indio_dev->channels = chan;
> +	indio_dev->num_channels = num_channels;
> +
> +	standby_mask = ad7768_all_standby_mask(st);
> +
> +	/*
> +	 * Crystal excitation requires channel 4 on AD7768 or channel 2 on
> +	 * AD7768-4 to remain active.
> +	 */
> +	if (st->clock_source == AD7768_CLOCK_SOURCE_XTAL)
> +		__clear_bit(st->chip_info->num_channels / 2, &standby_mask);

Hmm... I have a déjà vu feeling that I have seen already the same / similar.
If I'm right, this piece can be moved to a helper.

> +	ret = regmap_write(st->regmap, AD7768_REG_CH_STANDBY, standby_mask);
> +	if (ret)
> +		return ret;
> +
> +	device_for_each_named_child_node_scoped(dev, child, "channel") {
> +		u32 channel;
> +
> +		ret = fwnode_property_read_u32(child, "reg", &channel);
> +		if (ret)
> +			return dev_err_probe(dev, ret,
> +					     "Failed to parse reg of %pfwP\n",
> +					     child);
> +
> +		if (channel >= st->chip_info->num_channels)
> +			return dev_err_probe(dev, -ECHRNG,
> +					     "Invalid channel %u in firmware\n",
> +					     channel);
> +
> +		ret = regmap_clear_bits(st->regmap, AD7768_REG_CH_STANDBY,
> +					BIT(channel));
> +		if (ret)
> +			return ret;
> +
> +		precharge_cfg[channel].prebufp_en =
> +			fwnode_property_read_bool(child,
> +						  "adi,prechargebuf-pos-enable");
> +		precharge_cfg[channel].prebufn_en =
> +			fwnode_property_read_bool(child,
> +						  "adi,prechargebuf-neg-enable");
> +		precharge_cfg[channel].refbufp =
> +			fwnode_property_read_bool(child,
> +						  "adi,refbuf-pos-enable");
> +		precharge_cfg[channel].refbufn =
> +			fwnode_property_read_bool(child,
> +						  "adi,refbuf-neg-enable");
> +
> +		chan[chan_idx] = (struct iio_chan_spec) {
> +			.type = IIO_VOLTAGE,
> +			.info_mask_separate = BIT(IIO_CHAN_INFO_SCALE),
> +			.indexed = 1,
> +			.channel = channel,
> +			.scan_index = channel,
> +			.scan_type = {
> +				.sign = 's',
> +				.realbits = 24,
> +				.storagebits = 32,
> +			},
> +		};
> +		chan_idx++;
> +	}
> +
> +	ret = ad7768_configure_precharge_buffers(indio_dev, precharge_cfg);
> +	if (ret)
> +		return ret;
> +
> +	available_datalines = st->chip_info->available_datalines;
> +	len = st->chip_info->num_datalines;

You also can

	const char *propname;
	...
	propname = "adi,data-lines-number";

> +	if (device_property_present(dev, "adi,data-lines-number")) {

	if (device_property_present(dev, propname)) {

> +		ret = device_property_read_u32(dev, "adi,data-lines-number",
> +					       &st->datalines);

		ret = device_property_read_u32(dev, propname, &st->datalines);

> +		if (ret)
> +			return dev_err_probe(dev, ret,
> +					     "Invalid adi,data-lines-number property\n");

			return dev_err_probe(dev, ret, "Invalid %s property\n", propname);

> +	} else {
> +		st->datalines = available_datalines[len - 1];
> +	}
> +
> +	for (unsigned int i = 0; i < len; i++) {
> +		if (available_datalines[i] == st->datalines) {
> +			datalines_valid = true;
> +			break;
> +		}
> +	}
> +
> +	if (!datalines_valid)
> +		return dev_err_probe(dev, -EINVAL,
> +				     "Invalid data-lines-number %d for %s\n",
> +				     st->datalines, st->chip_info->name);

And even here

				     "Invalid %s %d for %s\n", propname,
				     st->datalines, st->chip_info->name);

> +	return ad7768_configure_capture(st);
> +}

...

> +static void ad7768_power_off(void *data)
> +{
> +	struct ad7768_state *st = data;
> +	struct device *dev;
> +	int ret;
> +
> +	dev = regmap_get_device(st->regmap);

Can be assigned directly above

	struct device *dev = regmap_get_device(st->regmap);

> +	ret = ad7768_enter_sleep(st);
> +	if (ret)
> +		dev_err(dev, "Failed to put device to sleep\n");
> +}

...

> +	ret = devm_regulator_get_enable_optional(dev, "avss");
> +	if (ret == -ENODEV) {
> +		/* AVSS may be tied directly to ground instead of a regulator. */

tied --> wired / connected / ...?

> +	} else if (ret) {
> +		return dev_err_probe(dev, ret,
> +				     "Failed to enable AVSS supply\n");

Fine to be on a single line.

> +	}

...

> +static const struct spi_device_id ad7768_spi_id[] = {
> +	{ "ad7768", (kernel_ulong_t)&ad7768_chip_info },
> +	{ "ad7768-4", (kernel_ulong_t)&ad7768_4_chip_info },
> +	{ }

C99 initialisers.

> +};
> +MODULE_DEVICE_TABLE(spi, ad7768_spi_id);

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2026-09-11  8:14 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 17:36 [PATCH v7 00/17] iio: adc: Add AD7768/AD7768-4 ADC driver support Janani Sunil
2026-09-10 17:36 ` [PATCH v7 01/17] iio: adc: adi-axi-adc: Initialize state mutex Janani Sunil
2026-09-10 17:36 ` [PATCH v7 02/17] dt-bindings: iio: adc: Add AD7768 Janani Sunil
2026-09-10 17:43   ` sashiko-bot
2026-09-10 17:36 ` [PATCH v7 03/17] iio: backend: Add support for CRC Janani Sunil
2026-09-11  8:18   ` Andy Shevchenko
2026-09-10 17:36 ` [PATCH v7 04/17] iio: adc: adi-axi-adc: " Janani Sunil
2026-09-11  8:19   ` Andy Shevchenko
2026-09-10 17:36 ` [PATCH v7 05/17] iio: adc: Add AD7768 and AD7768-4 core support Janani Sunil
2026-09-10 17:56   ` sashiko-bot
2026-09-11  8:14   ` Andy Shevchenko [this message]
2026-09-13 20:51   ` Jonathan Cameron
2026-09-10 17:36 ` [PATCH v7 06/17] iio: adc: ad7768: Validate master clock rate Janani Sunil
2026-09-11  8:20   ` Andy Shevchenko
2026-09-10 17:36 ` [PATCH v7 07/17] iio: adc: ad7768: Add power mode helper Janani Sunil
2026-09-10 17:48   ` sashiko-bot
2026-09-11  8:20   ` Andy Shevchenko
2026-09-13 20:51   ` Jonathan Cameron
2026-09-14  8:20     ` Janani Sunil
2026-09-10 17:36 ` [PATCH v7 08/17] iio: adc: ad7768: Derive output data rates Janani Sunil
2026-09-11  8:17   ` Andy Shevchenko
2026-09-10 17:36 ` [PATCH v7 09/17] iio: adc: ad7768: Configure channel sampling profiles Janani Sunil
2026-09-11 16:43   ` Andy Shevchenko
2026-09-10 17:36 ` [PATCH v7 10/17] iio: adc: ad7768: Add sampling frequency controls Janani Sunil
2026-09-10 17:36 ` [PATCH v7 11/17] iio: adc: ad7768: Add per-channel filter controls Janani Sunil
2026-09-10 17:36 ` [PATCH v7 12/17] iio: adc: ad7768: Wait for digital filters to settle Janani Sunil
2026-09-10 17:36 ` [PATCH v7 13/17] iio: adc: ad7768: Add calibration controls Janani Sunil
2026-09-10 17:36 ` [PATCH v7 14/17] iio: adc: ad7768: Add per-channel conversion delay Janani Sunil
2026-09-10 17:36 ` [PATCH v7 15/17] iio: adc: ad7768: Add VCM regulator support Janani Sunil
2026-09-10 17:36 ` [PATCH v7 16/17] iio: adc: ad7768: Register GPIO auxiliary device Janani Sunil
2026-09-11  7:41   ` Bartosz Golaszewski
2026-09-10 17:36 ` [PATCH v7 17/17] Documentation: iio: Add AD7768 Documentation Janani Sunil
2026-09-13 20:51 ` [PATCH v7 00/17] iio: adc: Add AD7768/AD7768-4 ADC driver support Jonathan Cameron

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=aqO4bj8L6FDB_-2F@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=janani.sunil@analog.com \
    --cc=jananisunil.dev@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@analog.com \
    --cc=mwalle@kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.com \
    --cc=p.zabel@pengutronix.de \
    --cc=rdunlap@infradead.org \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=u.kleine-koenig@baylibre.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.