Re: [PATCH v5 07/17] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65

[email protected] Tue, 04 Aug 2026 12:08:49 +0000
Newsgroups org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect scaling factor `p1_scale` for sama7d65 temperature calibration data, likely due to swapped numerator and denominator.
--

--- Patch [7]: [PATCH v5 07/17] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65 ---
commit ea05a7089eb84578f2d6135b1c963b5c2be91fdd
Author: Varshini Rajendran <[email protected]>

iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65

Add support for sama7d65 ADC. The differences are highlighted with the
compatible. The calibration data layout is the main difference.

Update Kconfig help text to mention SAMA7 SoC family support.

> diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> --- a/drivers/iio/adc/at91-sama5d2_adc.c
> +++ b/drivers/iio/adc/at91-sama5d2_adc.c

[ ... ]

> @@ -528,6 +528,15 @@ static const struct at91_adc_temp_calib_layout sama7g5_temp_calib = {
>  	.p1_scale = { .numerator = 1000, .denominator = 1 },
>  };
>  
> +static const struct at91_adc_temp_calib_layout sama7d65_temp_calib = {
> +	.tag_idx = 1,
> +	.p1_idx = 3,
> +	.p4_idx = 2,
> +	.p6_idx = 5,
> +	.min_len = 11,
> +	.p1_scale = { .numerator = 1, .denominator = 1000 },
> +};

[Severity: High]
Is this scale correct for the p1 value?

In at91_adc_temp_sensor_init(), the calibration value is scaled like this:

clb->p1 /= layout->p1_scale.denominator;

With a denominator of 1000, the raw NVMEM calibration value will be divided
by 1000. Later in at91_adc_read_temp(), this scaled p1 value is added
directly to a milli-Celsius delta.

If the NVMEM stores p1 in Celsius (like it does for SAMA7G5), dividing by
1000 yields 0 due to integer truncation. If it is already in milli-Celsius,
dividing by 1000 converts it back to Celsius. In either case, adding Celsius
or 0 to a milli-Celsius delta results in an incorrect temperature reading.

Could the numerator and denominator have been accidentally swapped here?

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=7