Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jishnu Prakash" <jishnu.prakash@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
Date: Fri, 20 Nov 2026 09:35:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-224862@kernel.org> (raw)
In-Reply-To: <20261120-pmic5_gen4_adc-v2-3-94d0e1fd6847@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] iio: adc: 32-bit overflow in
  qcom_adc5_gen4_scale_hw_calib_therm()
- [Medium] iio: adc: missing DIV20 channel entries in
  adc5_gen4_chans_pmic
--

commit d8180ae08a5ad388d0cacd9d70b18ca28f1e95bb
Author: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>

iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC

This commit adds support for PMIC5 Gen4 ADC channels, including 16-bit
ratiometric thermistor scaling, a per-channel qcom,adc5-gen4 DT property,
and extended SPMI bus index and SID addressing.

> diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> index be12bb6781cb3..aa06d4d1083ad 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
[ ... ]
> @@ -433,15 +438,60 @@ static const struct adc5_channels adc5_gen3_chans_pmic[ADC5_MAX_CHANNEL] = {
>  					SCALE_HW_CALIB_THERM_100K_PU_PM7)
>  };
>  
> +static const struct adc5_channels adc5_gen4_chans_pmic[ADC5_MAX_CHANNEL] = {
> +	[ADC5_GEN4_OFFSET_REF]		= ADC5_CHAN_VOLT(0, SCALE_HW_CALIB_DEFAULT)
> +	[ADC5_GEN4_1P25VREF]		= ADC5_CHAN_VOLT(0, SCALE_HW_CALIB_DEFAULT)
> +	[ADC5_GEN4_VPH_PWR]		= ADC5_CHAN_VOLT(1, SCALE_HW_CALIB_DEFAULT)
> +	[ADC5_GEN4_VBAT_SNS_QBG]	= ADC5_CHAN_VOLT(1, SCALE_HW_CALIB_DEFAULT)
> +	[ADC5_GEN4_DIE_TEMP]		= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_PMIC_THERM_PM7)
> +	[ADC5_GEN4_AMUX1_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX2_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX3_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX4_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX5_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX6_THM_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX1_GPIO_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX2_GPIO_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX3_GPIO_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX4_GPIO_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +	[ADC5_GEN4_AMUX5_GPIO_100K_PU]	= ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> +};

[Severity: Medium]
Should adc5_gen4_chans_pmic[] include entries for ADC5_GEN4_USB_SNS_DIV20
(0x11) and ADC5_GEN4_VIN_DIV20_MUX (0x12)?

Both macros are added in include/linux/iio/adc/qcom-adc5-gen3-common.h
(matching ADC5_GEN3_USB_SNS_V_16 and ADC5_GEN3_VIN_DIV16_MUX in
adc5_gen3_chans_pmic[]), but without entries here their info_mask remains
0 and adc5_gen3_get_fw_channel_data() rejects those channels with -EINVAL,
failing probe.

[ ... ]

> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
> index b03cf584b1657..5c4052f6f24fd 100644
> --- a/drivers/iio/adc/qcom-vadc-common.c
> +++ b/drivers/iio/adc/qcom-vadc-common.c
[ ... ]
> @@ -556,6 +561,31 @@ static int qcom_vadc7_scale_hw_calib_therm(
>  	return 0;
>  }
>  
> +static int qcom_adc5_gen4_scale_hw_calib_therm(
> +				const struct u32_fract *prescale,
> +				const struct adc5_data *data,
> +				u16 adc_code, int *result_mdec)
> +{
> +	s64 resistance = adc_code;
> +	int ret, result;
> +
> +	if (adc_code >= RATIO_MAX_ADC5_GEN4)
> +		return -EINVAL;
> +
> +	/* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code - ADC code)*/
> +	resistance *= R_PU_100K;
> +	resistance = div64_s64(resistance, RATIO_MAX_ADC5_GEN4 - adc_code);
> +
> +	ret = qcom_vadc_map_voltage_temp(adcmap7_100k, ARRAY_SIZE(adcmap7_100k),
> +					 resistance, &result);

[Severity: Medium]
Can resistance overflow the s32 input parameter of
qcom_vadc_map_voltage_temp() when adc_code is between 0xfffc and 0xfffe?

With 16-bit RATIO_MAX_ADC5_GEN4 (0xffff), adc_code values in 65532..65534
yield a 64-bit resistance between 2,184,400,000 and 6,553,400,000, which
exceeds S32_MAX and wraps negative when passed to
qcom_vadc_map_voltage_temp():

drivers/iio/adc/qcom-vadc-common.c:qcom_vadc_map_voltage_temp() {
	...
	while (i < tablesize && pts[i].x > input)
		i++;

	if (i == 0) {
		*output = pts[0].y;
	} else if (i == tablesize) {
		*output = pts[tablesize - 1].y;
	...
}

Because every table entry's x is positive, a wrapped negative input
advances i to tablesize and reports the hottest temperature in the table
(+130.048 degC) instead of the coldest (-40.960 degC) on a very cold or
open-circuit thermistor reading, which can trigger false critical thermal
trips.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-pmic5_gen4_adc-v2-0-94d0e1fd6847@oss.qualcomm.com?part=3

  reply	other threads:[~2026-11-20  9:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 1/7] dt-bindings: iio: adc: Add "qcom,adc5-gen4" property for ADC channels Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 2/7] iio: adc: qcom-adc5-gen3: Explicitly assign enum values used in hardware Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC Jishnu Prakash
2026-11-20  9:35   ` sashiko-bot [this message]
2026-11-20  9:19 ` [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: " Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Remove Gen3 virtual channel macros Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 6/7] dt-bindings: iio: adc: Add support for QCOM PMIC5 Gen4 ADC Jishnu Prakash
2026-11-20  9:19 ` [PATCH v2 7/7] iio: adc: qcom-spmi-adc5-gen3: Add support for Gen4 ADC master PMICs Jishnu Prakash

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=sashiko-outbox-224862@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jishnu.prakash@oss.qualcomm.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