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 v6 05/17] iio: adc: Add AD7768 and AD7768-4 core support
Date: Sun, 6 Sep 2026 11:34:47 +0300 [thread overview]
Message-ID: <ap0lp5THO64olugK@ashevche-desk.local> (raw)
In-Reply-To: <20260904-ad7768-driver-v6-5-e4378f946bfb@analog.com>
On Fri, Sep 04, 2026 at 04:14:57PM +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.
...
> +#define AD7768_INTERFACE_CFG_DCLK_DIV_MSK GENMASK(1, 0)
> +#define AD7768_INTERFACE_CFG_DCLK_DIV(x) (4 - ffs(x))
This looks suspicious, do you mean fls() / ilog2()? because ffs() while it may
work, it gets the first set LSB. Also what if 'x' is too high? I guess you can
rework the only user of that to avoid even ffs()/fls()/ilog2().
...
> +#define AD7768_PREBUF_POS_EN(ch) BIT((ch) * 2)
Perhaps + 0?
#define AD7768_PREBUF_POS_EN(ch) BIT((ch) * 2 + 0)
This will be consistent with the below.
> +#define AD7768_PREBUF_NEG_EN(ch) BIT(((ch) * 2) + 1)
Too many parentheses.
...
> +#define AD7768_REG_OFFSET(ch) (AD7768_REG_OFFSET_BASE + (3 * (ch)))
> +#define AD7768_REG_GAIN(ch) (AD7768_REG_GAIN_BASE + (3 * (ch)))
> +#define AD7768_REG_PHASE(ch) (AD7768_REG_PHASE_BASE + (ch))
> +#define __AD7768_4_REG_MAP(ch) ((ch) < 2 ? (ch) : ((ch) + 2))
(ch) in parentheses make no sense here as it will be evaluated twice. If there
is an expression it might lead to a wrong numbers. Either you need more complex
macro to make evaluation happen once, or just be sure no caller uses an
expression in the parameter in which case the parentheses are not required.
With that being said, the other macros against (ch) also can be reconsidered.
...
> +struct ad7768_chip_info {
> + const char *name;
> + unsigned int num_channels;
> + const struct regmap_config *regmap_config;
> + const unsigned int *available_datalines;
> + unsigned int num_datalines;
> + const u8 *chan_map;
> + u8 prebuf_split;
Even if `pahole` is okay with the layout, I would suggest this one instead
const char *name;
const struct regmap_config *regmap_config;
const unsigned int *available_datalines;
unsigned int num_datalines;
unsigned int num_channels;
const u8 *chan_map;
u8 prebuf_split;
> +};
...
> + return (val >> st->chip_info->prebuf_split) &
> + GENMASK(st->chip_info->prebuf_split - 1, 0);
Can it use field_get()?
...
> +static int ad7768_update_scan_mode(struct iio_dev *indio_dev,
> + const unsigned long *scan_mask)
> +{
> + struct ad7768_state *st = iio_priv(indio_dev);
> + unsigned long channel_mask;
> + unsigned long standby_mask;
> + int ret;
> +
> + channel_mask = ad7768_all_standby_mask(st);
> + standby_mask = channel_mask & ~*scan_mask;
> +
> + /*
> + * 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);
> +
> + ret = regmap_update_bits(st->regmap, AD7768_REG_CH_STANDBY,
> + channel_mask, standby_mask);
> + if (ret)
> + return ret;
> +
> + for (unsigned int c = 0; c < st->chip_info->num_channels; c++) {
c --> ch?
> + if (test_bit(c, scan_mask))
> + ret = iio_backend_chan_enable(st->back, c);
> + else
> + ret = iio_backend_chan_disable(st->back, c);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
...
> + /*
> + * 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;
> + dclk_div_reg = AD7768_INTERFACE_CFG_DCLK_DIV(dclk_div);
So, this one is (4 - ffs(dclk_div)). If num_channels == 1, this will always give 0.
If num_channels == 2, this might give 0, 8, ... Since ffs(0) implementation is defined
to return 0, this will return... 0! So, tell me how this code may return
anything than 0?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-09-06 8:34 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 14:14 [PATCH v6 00/17] iio: adc: Add AD7768/AD7768-4 ADC driver support Janani Sunil
2026-09-04 14:14 ` [PATCH v6 01/17] iio: adc: adi-axi-adc: Initialize state mutex Janani Sunil
2026-09-04 14:14 ` [PATCH v6 02/17] dt-bindings: iio: adc: Add AD7768 Janani Sunil
2026-09-04 17:08 ` Conor Dooley
2026-09-04 14:14 ` [PATCH v6 03/17] iio: backend: Add support for CRC Janani Sunil
2026-09-06 3:50 ` Jonathan Cameron
2026-09-04 14:14 ` [PATCH v6 04/17] iio: adc: adi-axi-adc: " Janani Sunil
2026-09-04 14:14 ` [PATCH v6 05/17] iio: adc: Add AD7768 and AD7768-4 core support Janani Sunil
[not found] ` <20260904143153.9AF1A1F00A3E@smtp.kernel.org>
[not found] ` <178866149408.3402141.12120124355772738970.b4-reply@b4>
2026-09-06 3:05 ` Jonathan Cameron
2026-09-06 3:50 ` Jonathan Cameron
2026-09-06 8:34 ` Andy Shevchenko [this message]
2026-09-04 14:14 ` [PATCH v6 06/17] iio: adc: ad7768: Validate master clock rate Janani Sunil
2026-09-04 14:14 ` [PATCH v6 07/17] iio: adc: ad7768: Add power mode helper Janani Sunil
2026-09-06 3:50 ` Jonathan Cameron
2026-09-04 14:15 ` [PATCH v6 08/17] iio: adc: ad7768: Derive output data rates Janani Sunil
2026-09-04 14:15 ` [PATCH v6 09/17] iio: adc: ad7768: Configure channel sampling profiles Janani Sunil
2026-09-06 3:50 ` Jonathan Cameron
2026-09-04 14:15 ` [PATCH v6 10/17] iio: adc: ad7768: Add sampling frequency controls Janani Sunil
2026-09-04 14:15 ` [PATCH v6 11/17] iio: adc: ad7768: Add per-channel filter controls Janani Sunil
2026-09-04 14:15 ` [PATCH v6 12/17] iio: adc: ad7768: Wait for digital filters to settle Janani Sunil
2026-09-04 14:15 ` [PATCH v6 13/17] iio: adc: ad7768: Add calibration controls Janani Sunil
2026-09-06 3:50 ` Jonathan Cameron
2026-09-04 14:15 ` [PATCH v6 14/17] iio: adc: ad7768: Add per-channel conversion delay Janani Sunil
2026-09-06 3:50 ` Jonathan Cameron
2026-09-04 14:15 ` [PATCH v6 15/17] iio: adc: ad7768: Add VCM regulator support Janani Sunil
2026-09-04 14:15 ` [PATCH v6 16/17] iio: adc: ad7768: Register GPIO auxiliary device Janani Sunil
2026-09-04 14:15 ` [PATCH v6 17/17] Documentation: iio: Add AD7768 Documentation Janani Sunil
2026-09-06 3:50 ` 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=ap0lp5THO64olugK@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox