Re: [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: Add support for QCOM PMIC5 Gen4 ADC
From: Jishnu Prakash
Date: Sun Nov 29 2026 - 09:13:10 EST
Hi Jonathan,
On 11/22/2026 2:37 AM, Jonathan Cameron wrote:
> On Fri, 20 Nov 2026 14:49:44 +0530
> Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx> wrote:
>
>> PMIC5 Gen4 ADC is similar to PMIC5 Gen3 ADC, with several changes made
>> for improved performance, mostly at the hardware level.
>>
>> One significant software change is that ratiometric conversion resolution
>> has been increased from 14 bits to 16 bits. Add a reverse scaling function
>> for Gen4 ADC thermistor channels.
>>
>> In the latest PMIC arbiter version (v8), there can be up to 4 buses
>> under the PMIC arbiter and 32 PMICs under each bus. In order to
>> support communication between ADC on the master PMIC and ADCs on any
>> of the other PMICs, a field of width 2 bits is added for bus index
>> and the bits for SID are extended from 4 to 5 bits, in the SID
>> register. Add support for this.
>>
>> Co-developed-by: Anjelique Melendez <anjelique.melendez@xxxxxxxxxxxxxxxx>
>> Signed-off-by: Anjelique Melendez <anjelique.melendez@xxxxxxxxxxxxxxxx>
>> Signed-off-by: Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx>
>> ---
>> drivers/iio/adc/qcom-vadc-common.c | 11 +++++++++++
>> drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c | 19 ++++++++++++++-----
>> include/linux/iio/adc/qcom-vadc-common.h | 2 ++
>> 3 files changed, 27 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
>> index 5c4052f6f24f..779c2a66a858 100644
>> --- a/drivers/iio/adc/qcom-vadc-common.c
>> +++ b/drivers/iio/adc/qcom-vadc-common.c
>> @@ -718,6 +718,17 @@ u16 qcom_adc_tm5_gen2_temp_res_scale(int temp)
>> }
>> EXPORT_SYMBOL(qcom_adc_tm5_gen2_temp_res_scale);
>>
>> +u16 qcom_adc_tm5_gen4_temp_res_scale(int temp)
>> +{
>> + s64 resistance;
>> +
>> + resistance = qcom_vadc_map_temp_voltage(adcmap7_100k,
>> + ARRAY_SIZE(adcmap7_100k), temp);
>> +
>> + return div64_s64(resistance * RATIO_MAX_ADC5_GEN4, resistance + R_PU_100K);
>
> If you were keeping this (See below) I'd have a helper that does the maths
> called by both the gen2 and gen4 versions. I think it just has that multiplier
> different.
With the changes in struct adc5_data I mentioned in the patch 3 thread,
we can eliminate this function, reusing the existing qcom_adc_tm5_gen2_temp_res_scale
with an additional input argument.
>
>> +}
>> +EXPORT_SYMBOL(qcom_adc_tm5_gen4_temp_res_scale);
>> +
>> int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
>> unsigned int prescale_ratio,
>> const struct adc5_data *data,
>> diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
>> index 910b241fa94d..aeaf13f4fc66 100644
>> --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
>> +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c
>> @@ -207,15 +207,23 @@ static int adc_tm5_gen3_disable_channel(struct adc_tm5_gen3_channel_props *prop)
>> ADC5_GEN3_CONV_REQ, &val, sizeof(val));
>> }
>>
>> +typedef u16 (*temp_res_scale)(int temp);
>> +
>> static int adc_tm5_gen3_configure(struct adc_tm5_gen3_channel_props *prop,
>> int low_temp, int high_temp)
>> {
>> struct adc_tm5_gen3_chip *adc_tm5 = prop->chip;
>> u8 buf[ADC_TM5_GEN3_CONFIG_REGS];
>> + temp_res_scale tm_scal_fn;
>> u8 conv_req;
>> u16 adc_code;
>> int ret;
>>
>> + if (prop->common_props.generation == ADC5_GEN4)
>> + tm_scal_fn = qcom_adc_tm5_gen4_temp_res_scale;
>> + else
>> + tm_scal_fn = qcom_adc_tm5_gen2_temp_res_scale;
>
> A little messy patch ordering wise, but I think those should
> be function pointers in common_props.data and set in the adc
> driver (where it currently sets generation).
>
> That will put all the information in one place rather
> than a mix of data and stuff patched in the code in various
> other places.
>
> For anyone not reading review of previous patch, I want that
> generation value to go away.
>
> However, the two callbacks differ (I think) in only one value.
> Just put that value in the data instead of having two callbacks
> and add a parameter to the function to pass it in.
With the change in struct adc5_data, we can differentiate Gen3
and Gen4 based on the new raw code field added, and that same value
can also be passed as a parameter to qcom_adc_tm5_gen2_temp_res_scale()
as you mentioned here.
Thanks,
Jishnu
>
>> +
>> ret = adc5_gen3_poll_wait_hs(adc_tm5->dev_data, prop->sdam_index);
>> if (ret < 0)
>> return ret;
>> @@ -225,8 +233,9 @@ static int adc_tm5_gen3_configure(struct adc_tm5_gen3_channel_props *prop,
>> if (ret < 0)
>> return ret;
>>