From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Marek Vasut" <marex@nabladev.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Cheick Traore" <cheick.traore-ext@st.com>,
"Olivier Moysan" <olivier.moysan@foss.st.com>
Subject: Re: [PATCH v2 07/14] iio: adc: stm32-adc: add support for stm32mp25
Date: Fri, 25 Sep 2026 00:01:03 +0300 [thread overview]
Message-ID: <arWPjx-JKt1IZCZl@ashevche-desk.local> (raw)
In-Reply-To: <20260923-adc-stm32mp25-v1-v2-7-46bc019537c6@foss.st.com>
On Wed, Sep 23, 2026 at 05:39:10PM +0200, Fabrice Gasnier wrote:
> Add support for ADC on STM32MP25 SoC. It has 3 ADCs, split into two blocks:
> - ADC1 & ADC2 are tightly coupled.
> - ADC3 is managed independently.
>
> Trigger list slightly changes between these blocks (ADC1 & ADC2). Other
> differences are found on channels interconnects (similar between ADC2
> and ADC3):
> - ADC1 is connected to 18 external channels + 2 internal channels
> - ADC2 is connected to 14 external channels + 6 internal channels
> - ADC3 is connected to 14 external channels + 6 internal channels
>
> Each ADC is a 12-bits successive approximation analog-to-digital converter,
> with up to 20 multiplexed channels that can be configured as single ended
> or differential. ADC resolution ranges from 6 to 12 bits.
>
> It introduces diversity regarding IRQs, clocks, software calibration
> procedure, internal voltage channels, sampling time (prescaler) and
> trigger list. Most of the architecture, and the driver engine remains
> similar. So, handle the differences w.r.t. other STM32 ADCs family with
> a dedicated compatible and compatible data.
...
> .compatible = "st,stm32mp13-adc-core",
> .data = (void *)&stm32mp13_adc_priv_cfg
> }, {
> - },
> + .compatible = "st,stm32mp25-adc-core",
> + .data = (void *)&stm32mp25_adc_priv_cfg
> + }, {
> + }
Same issue and now it's a regression from maintenance perspective: you added an
unnedeed churn that has to be handled from now on... TL;DR: do add trailing
commas to the non-terminator entries and remove trailing commas in the
terminator entries.
> };
...
> + STM32_EXT23,
> + STM32_EXT24,
> + STM32_EXT25,
> + STM32_EXT26,
> + STM32_EXT27,
> + STM32_EXT28
Same issue and so on...
> };
...
Are you doing patches with an assistance? LLMs might have a problem with the
style issues.
...
> +retry:
> + /* Clears or set CALADDOS (also clear old calibration data if any) */
> + stm32_adc_writel(adc, STM32MP25_ADC_CALFACT,
> + FIELD_PREP(STM32MP25_CALFACT_CALADDOS, *add_offset));
> +
> + ret = stm32mp25_adc_calib_get_average_data(indio_dev, &average);
> + if (ret)
> + return ret;
> +
> + /* Add offset and retry single-ended calibration if the averaged data is zero */
> + if (!average && !*add_offset) {
> + *add_offset = true;
> + goto retry;
> + }
Refactor to avoid a label. It's possible to achieve.
> + if (!average) {
Why not positive conditional?
> + /* If average data is still zero with additional offset, just warn about it */
> + dev_warn(&indio_dev->dev, "Single-ended calibration average: 0\n");
> + } else {
> + u32 calfact = stm32_adc_readl(adc, STM32MP25_ADC_CALFACT);
> +
> + calfact |= FIELD_PREP(STM32MP25_CALFACT_S_MASK, average);
> + stm32_adc_writel(adc, STM32MP25_ADC_CALFACT, calfact);
> + }
...
> +static int stm32mp25_adc_calib(struct iio_dev *indio_dev)
> + struct stm32_adc *adc = iio_priv(indio_dev);
> + bool add_offset = false;
> + bool diff_below_zero;
> + u32 average, calfact;
> + int ret;
> +
> + stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADCAL);
> + /* Use default resolution (e.g. 12 bits) */
> + stm32_adc_clr_bits(adc, STM32H7_ADC_CFGR, STM32MP25_RES_MASK);
> +
> +retry:
> + /* Single ended input calibration */
> + ret = stm32mp25_adc_calib_single_ended_offset(indio_dev, &add_offset);
> + if (ret)
> + goto out;
> +
> + /* Differential input calibration (keep previous CALADDOS value) */
> + stm32_adc_set_bits(adc, STM32H7_ADC_CR, STM32H7_ADCALDIF);
> + ret = stm32mp25_adc_calib_get_average_data(indio_dev, &average);
> + if (ret)
> + goto out;
> +
> + /* Averaged diff data is below 0x800 (half value in 12-bits mode) */
> + diff_below_zero = average < BIT(adc->cfg->adc_info->resolutions[0] - 1);
> +
> + if (diff_below_zero && !add_offset) {
> + /* Retry the whole calibration with additional offset */
> + add_offset = true;
> + goto retry;
> + }
Same comment, refactor to avoid label.
> + calfact = stm32_adc_readl(adc, STM32MP25_ADC_CALFACT);
> +
> + if (diff_below_zero) {
> + /*
> + * Averaged data is still below center value. It needs to be clamped to zero,
> + * so don't use the result here, warn about it.
> + */
> + dev_warn(&indio_dev->dev, "Differential calibration clamped(0): 0x%x\n", average);
> + } else {
> + calfact |= FIELD_PREP(STM32MP25_CALFACT_D_MASK, average);
> + stm32_adc_writel(adc, STM32MP25_ADC_CALFACT, calfact);
> + }
> +
> + dev_dbg(&indio_dev->dev, "set calfact_s=0x%03lx, calfact_d=0x%03lx, calados=%ld\n",
> + FIELD_GET(STM32MP25_CALFACT_S_MASK, calfact),
> + FIELD_GET(STM32MP25_CALFACT_D_MASK, calfact),
> + FIELD_GET(STM32MP25_CALFACT_CALADDOS, calfact));
> +out:
In any case if you ever have a label in the code, name it as an answer to the Q:
"What will be done if I goto *this* label?"
Here it is something like 'out_calibration_stop_and_reset'
(I haven't checked the real code and datasheet, just used below short context).
> + stm32_adc_clr_bits(adc, STM32H7_ADC_CR, STM32H7_ADCAL);
> + stm32_adc_set_res(adc);
> +
> + return ret;
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-09-24 21:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 15:39 [PATCH v2 00/14] iio: adc: stm32: add support for stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 01/14] dt-bindings: iio: adc: stm32-adc: " Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 02/14] iio: adc: stm32-adc: core: manage clock prescaler diversity Fabrice Gasnier
2026-09-27 18:57 ` Jonathan Cameron
2026-09-23 15:39 ` [PATCH v2 03/14] iio: adc: stm32-adc: core: configurable number of interrupts Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 04/14] iio: adc: stm32-adc: manage characterization voltage diversity Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 05/14] iio: adc: stm32-adc: rework internal channels data Fabrice Gasnier
2026-09-23 15:51 ` sashiko-bot
2026-09-24 10:02 ` Fabrice Gasnier
2026-09-24 20:53 ` Andy Shevchenko
2026-09-23 15:39 ` [PATCH v2 06/14] iio: adc: stm32-adc: add vreg enable option to manage diversity Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 07/14] iio: adc: stm32-adc: add support for stm32mp25 Fabrice Gasnier
2026-09-23 16:14 ` sashiko-bot
2026-09-24 21:01 ` Andy Shevchenko [this message]
2026-09-29 16:48 ` Fabrice Gasnier
2026-09-30 8:33 ` Andy Shevchenko
2026-09-30 8:44 ` Fabrice Gasnier
2026-09-30 8:55 ` Andy Shevchenko
2026-09-23 15:39 ` [PATCH v2 08/14] iio: adc: stm32-adc: add support for stm32mp23 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 09/14] iio: adc: stm32: add support for vddgpu on stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-27 19:03 ` Jonathan Cameron
2026-09-23 15:39 ` [PATCH v2 10/14] arm64: dts: st: add vrefint calibration on stm32mp23 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 11/14] arm64: dts: st: add vrefint calibration on stm32mp25 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 12/14] arm64: dts: st: add ADC nodes on stm32mp231 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 13/14] arm64: dts: st: add ADC nodes on stm32mp251 Fabrice Gasnier
2026-09-23 15:39 ` [PATCH v2 14/14] 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=arWPjx-JKt1IZCZl@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andy@kernel.org \
--cc=cheick.traore-ext@st.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=fabrice.gasnier@foss.st.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=marex@nabladev.com \
--cc=mcoquelin.stm32@gmail.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