Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v3 08/15] iio: adc: stm32-adc: add support for stm32mp25
Date: Wed, 30 Sep 2026 14:38:49 +0000	[thread overview]
Message-ID: <20260930143850.42EF51F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930-adc-stm32mp25-v1-v3-8-406834430d72@foss.st.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] iio: adc: stm32-adc: DIFSEL write ignored while ADC is enabled
- [Medium] iio: adc: stm32-adc: incorrect internal channel sampling time for mp25
- [Medium] iio: adc: stm32-adc: missing ADSTP before ADDIS on calibration timeout
- [Low] iio: adc: stm32-adc: implicit subtraction via mask truncation in calibration
--

commit 58980c1da40c7a3d68e78bec0a436a1487c49820
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Subject: iio: adc: stm32-adc: add support for stm32mp25

This commit adds support for the ADC on the STM32MP25 SoC, which features
three ADCs split into two blocks. It introduces diversity regarding IRQs,
clocks, software calibration, internal voltage channels, sampling time,
and trigger lists. A dedicated compatible is used to handle these
differences relative to other STM32 ADCs.

> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index c1979f1f17385..33e41505b2e99 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
[ ... ]
> +static int stm32mp25_adc_calib_get_average_data(struct iio_dev *indio_dev, u32 *average)
> +{
[ ... ]
> +	for (unsigned int i = 0; i < STM32MP25_CALIB_LOOP; i++) {
> +		int ret;
> +		u32 val;
> +
> +		stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADSTART);
> +		ret = stm32_adc_readl_poll_timeout(STM32H7_ADC_CR, val,
> +						   !(val & (STM32H7_ADSTART)),
> +						   100, STM32_ADC_TIMEOUT_US);
> +		if (ret) {
> +			dev_err(&indio_dev->dev, "calibration average error %d\n", ret);
> +			return ret;
> +		}

[Severity: Medium]
If the hardware takes too long and triggers the polling timeout here,
will the ADC become permanently wedged?

When this times out, ADSTART remains 1. The error path bubbles up to
stm32mp25_adc_prepare() and branches to the adc_dis label, calling
stm32h7_adc_disable(). Since ADSTART is still set, attempting to set ADDIS
without first stopping the conversion (by setting ADSTP) causes the hardware
to ignore the ADDIS command.

The polling loop in stm32h7_adc_disable() will then time out as well,
leaving the hardware stuck and unable to be re-enabled later.

[ ... ]
> +static int stm32mp25_adc_calib_differential(struct iio_dev *indio_dev, u32 *calfact)
> +{
[ ... ]
> +	if (!diff_below_zero) {
> +		*calfact |= FIELD_PREP(STM32MP25_CALFACT_D_MASK, average);
> +		stm32_adc_writel(adc, STM32MP25_ADC_CALFACT, *calfact);

[Severity: Low]
Can passing the raw average into FIELD_PREP here result in silent data
corruption?

The average could be >= 0x800. This relies on the 9-bit mask
STM32MP25_CALFACT_D_MASK to implicitly truncate the 12-bit half-scale
offset out of the value.

While functionally this might achieve the expected subtraction for small
offsets, does this violate FIELD_PREP's assumptions and risk static analysis
warnings or runtime assertions?

[ ... ]
> +static int stm32mp25_adc_prepare(struct iio_dev *indio_dev)
> +{
[ ... ]
> +	/* Must enable the ADC before running software-assisted calibration */
> +	ret = stm32h7_adc_enable(indio_dev);
> +	if (ret)
> +		goto pwr_dwn;
> +
> +	/* Always run offset calibration */
> +	ret = stm32mp25_adc_calib(indio_dev);
> +	if (ret)
> +		goto adc_dis;
> +
> +	stm32_adc_int_ch_enable(indio_dev);
> +
> +	stm32_adc_writel(adc, adc->cfg->regs->difsel.reg, adc->difsel);

[Severity: High]
Will writing to the DIFSEL register be ignored by the hardware at this point?

stm32h7_adc_enable() sets ADEN=1, enabling the ADC. The STM32 hardware
write-protects the DIFSEL register while the ADC is enabled.

Does writing DIFSEL after enabling the ADC cause the configuration to be
silently dropped, forcing differential channels to fall back to
single-ended mode and corrupting measurements?

[ ... ]
> +static const unsigned int stm32_adc_min_ts_mp25[STM32_ADC_INT_CH_NB] = {
> +	[STM32_ADC_INT_CH_VDDCORE] = 34,
> +	[STM32_ADC_INT_CH_VDDCPU] = 34,
> +	[STM32_ADC_INT_CH_VREFINT] = 34,
> +	[STM32_ADC_INT_CH_VBAT] = 34,
> +};

[Severity: Medium]
Are these stabilization time values correctly specified in nanoseconds?

This array specifies 34 ns, which causes the driver to select the absolute
minimum sampling time (e.g. 2 clock cycles). Internal channels like VREFINT
and VBAT usually require multiple microseconds to stabilize due to high
source impedance.

Were these values accidentally provided in clock cycles (e.g., 3.4 us at
10 MHz) instead of nanoseconds, leading to highly inaccurate internal voltage
readings?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930-adc-stm32mp25-v1-v3-0-406834430d72@foss.st.com?part=8

  reply	other threads:[~2026-09-30 14:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 14:18 [PATCH v3 00/15] iio: adc: stm32: add support for stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 01/15] dt-bindings: iio: adc: stm32-adc: " Fabrice Gasnier
2026-09-30 14:29   ` sashiko-bot
2026-09-30 21:18   ` Conor Dooley
2026-09-30 14:18 ` [PATCH v3 02/15] iio: adc: stm32-adc: core: manage clock prescaler diversity Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 03/15] iio: adc: stm32-adc: core: configurable number of interrupts Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 04/15] iio: adc: stm32-adc: manage characterization voltage diversity Fabrice Gasnier
2026-09-30 14:54   ` Joshua Crofts
2026-09-30 14:18 ` [PATCH v3 05/15] iio: adc: stm32-adc: rework internal channels data Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 06/15] iio: adc: stm32-adc: add vreg enable option to manage diversity Fabrice Gasnier
2026-09-30 15:01   ` Joshua Crofts
2026-09-30 14:18 ` [PATCH v3 07/15] iio: adc: stm32-adc: preferred style cleanup Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 08/15] iio: adc: stm32-adc: add support for stm32mp25 Fabrice Gasnier
2026-09-30 14:38   ` sashiko-bot [this message]
2026-09-30 14:18 ` [PATCH v3 09/15] iio: adc: stm32-adc: add support for stm32mp23 Fabrice Gasnier
2026-09-30 14:31   ` sashiko-bot
2026-09-30 15:12   ` Joshua Crofts
2026-09-30 14:18 ` [PATCH v3 10/15] iio: adc: stm32-adc: add support for vddgpu on stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 11/15] arm64: dts: st: add vrefint calibration on stm32mp23 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 12/15] arm64: dts: st: add vrefint calibration on stm32mp25 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 13/15] arm64: dts: st: add ADC nodes on stm32mp231 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 14/15] arm64: dts: st: add ADC nodes on stm32mp251 Fabrice Gasnier
2026-09-30 14:18 ` [PATCH v3 15/15] arm64: dts: st: add ADC support on stm32mp257f-ev1 board Fabrice Gasnier

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=20260930143850.42EF51F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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