Devicetree
 help / color / mirror / Atom feed
From: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "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>,
	"Amit Kucheria" <amitk@kernel.org>,
	"Thara Gopinath" <thara.gopinath@gmail.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Daniel Lezcano" <daniel.lezcano@kernel.org>,
	"Zhang Rui" <rui.zhang@intel.com>,
	"Lukasz Luba" <lukasz.luba@arm.com>,
	"Bjorn Andersson" <andersson@kernel.org>,
	"Konrad Dybcio" <konradybcio@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-pm@vger.kernel.org,
	"Kamal Wadhwa" <kamal.wadhwa@oss.qualcomm.com>,
	"Anjelique Melendez" <anjelique.melendez@oss.qualcomm.com>,
	"Manaf Meethalavalappu Pallikunhi"
	<manaf.pallikunhi@oss.qualcomm.com>,
	"Priyansh Jain" <priyansh.jain@oss.qualcomm.com>
Subject: Re: [PATCH 2/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
Date: Thu, 6 Aug 2026 16:22:16 +0530	[thread overview]
Message-ID: <a98d90bd-aa9d-4af3-aa54-3a34300070d4@oss.qualcomm.com> (raw)
In-Reply-To: <20260803011400.1fb6c93a@jic23-huawei>

Hi Jonathan,

On 8/3/2026 5:44 AM, Jonathan Cameron wrote:
> On Fri, 31 Jul 2026 23:36:15 +0530
> Jishnu Prakash <jishnu.prakash@oss.qualcomm.com> 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, so the maximum value of
>> these measurements needs to be updated for Gen4. Add a new scaling
>> function for thermistor channels which use this type of conversion.
>>
>> 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.
>>
>> In addition, it is possible that the master PMIC has ADC of one generation
>> and it needs to communicate with another PMIC with ADC of a different
>> generation.
> 
> "Possible" sounds a bit hypothetical.  Can we state this actually happens
> on some devices?

Considering existing upstream platforms, this is applicable for SM8750. I'll
mention this in the next version of the series.

> 
>> Add new DT properties "qcom,adc5-gen3" and "qcom,adc5-gen4",
>> to distinguish Gen3 channels under a Gen4 master and Gen4 channels
>> under a Gen3 master respectively, to ensure that their conversions are handled
> 
> This line got a bit long. Wrap at 75 chars for commit message.
> 
>> correctly.
>>
>> Co-developed-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com>
>> Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com>
>> Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
>> ---
>>  drivers/iio/adc/qcom-spmi-adc5-gen3.c         | 165 +++++++++++++++++++-------
>>  drivers/iio/adc/qcom-vadc-common.c            |  32 +++++
>>  include/linux/iio/adc/qcom-adc5-gen3-common.h |  44 ++++++-
>>  include/linux/iio/adc/qcom-vadc-common.h      |   4 +
>>  4 files changed, 195 insertions(+), 50 deletions(-)
>>
>> diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
>> index c68c6c5f6aca..810d25b665b1 100644
>> --- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
>> +++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
>> @@ -86,7 +86,9 @@ int adc5_gen3_write(struct adc5_device_data *adc, unsigned int sdam_index,
>>  }
>>  EXPORT_SYMBOL_NS_GPL(adc5_gen3_write, "QCOM_SPMI_ADC5_GEN3");
>>  
>> -static int adc5_gen3_read_voltage_data(struct adc5_chip *adc, u16 *data)
>> +static int adc5_gen3_read_voltage_data(struct adc5_chip *adc,
>> +				       struct adc5_channel_common_prop *prop,
>> +				       u16 *data)
>>  {
>>  	u8 rslt[2];
>>  	int ret;
>> @@ -99,8 +101,10 @@ static int adc5_gen3_read_voltage_data(struct adc5_chip *adc, u16 *data)
>>  	*data = get_unaligned_le16(rslt);
>>  
>>  	if (*data == ADC5_USR_DATA_CHECK) {
> This feels backwards.   We first check for the top bit being
> set then check whether we care if it is set or not.  I think
> checking if we should look at it first makes more sense.  Also
> shorter max line length:
> 
> 	if (!(prop->generation == ADC5_GEN4 && prop->cal_method == ADC5_RATIOMETRIC_CAL)) {
> 		if (*data == ADC5_USR_DATA_CHECK) {
> 	...	

I thought it was more efficient to have the check like this because
there may be several channels satisfying the longer if() check for Gen4
ratiometric channels, but the chance of *data being exactly equal to
the error value ADC5_USR_DATA_CHECK is lower generally. So if I reverse
the checks as you suggested, the outer if() check would pass for every
read done on a channel which is not both Gen4 and ratiometric, which
seems inefficient for an error check.

What do you think, should I make any changes here?


> 
>>  
>> +static const struct adc5_channels adc5_gen4_chans_pmic[ADC5_MAX_CHANNEL] = {
>> +	[ADC5_GEN4_OFFSET_REF]		= ADC5_CHAN_VOLT(0,
>> +						SCALE_HW_CALIB_DEFAULT)
> 
> Probably just go long on these lines and I'm not sure there is enough benefit to
> forcing the alignment though if you really want to it will be more useful with
> them on a single line.

Sure, I'll keep these on single lines.

> 
> 	[ADC5_GEN4_OFFSET_REF] = ADC5_CHAN_VOLT(0, SCALE_HW_CALIB_DEFAULT)
> ...
> 
> 	[ADC5_GEN4_AMUX5_GPIO_100K_PU] = ADC5_CHAN_TEMP(0, SCALE_HW_CALIB_THERM_100K_PU_GEN4)
> 
> Obviously it has been there a while, but having the comma inside ADC_CHAN() macro
> ends up making this look a little odd.
> 
> 
>> +	[ADC5_GEN4_1P25VREF]		= ADC5_CHAN_VOLT(0,
>> +						SCALE_HW_CALIB_DEFAULT)
>> +	[ADC5_GEN4_VPH_PWR]		= ADC5_CHAN_VOLT(1,
> 
>> +
>> +static const struct of_device_id adc5_match_table[] = {
>> +	{
>> +		.compatible = "qcom,spmi-adc5-gen3",
>> +		.data = &adc5_gen3_data_pmic,
>> +	},
>> +	{
>> +		.compatible = "qcom,spmi-adc5-gen4",
>> +		.data = &adc5_gen4_data_pmic,
>> +	},
>> +	{ }
>> +};
>> +MODULE_DEVICE_TABLE(of, adc5_match_table);
> 
> Why has this moved?  I'm not seeing any new references to adc5_match_table
> before where it was before.

I think I moved it with the adc5_data structs by mistake, I'll
move it back.

> 
>> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
>> index b03cf584b165..cb23d0d178c7 100644
>> --- a/drivers/iio/adc/qcom-vadc-common.c
>> +++ b/drivers/iio/adc/qcom-vadc-common.c
> 
>> @@ -341,6 +345,8 @@ static const struct qcom_adc5_scale_type scale_adc5_fn[] = {
>>  					qcom_vadc7_scale_hw_calib_die_temp},
>>  	[SCALE_HW_CALIB_PM5_CHG_TEMP] = {qcom_vadc_scale_hw_chg5_temp},
>>  	[SCALE_HW_CALIB_PM5_SMB_TEMP] = {qcom_vadc_scale_hw_smb_temp},
>> +	[SCALE_HW_CALIB_THERM_100K_PU_GEN4] = {
>> +					qcom_adc5_gen4_scale_hw_calib_therm},
> 
> I don't mind if you want to go a little past 80 chars to avoid doing this sort
> of line break that just makes things harder to read.
> 
>>  };
>>  
>>  static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
>> @@ -556,6 +562,32 @@ 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);
> 
> 	ret = qcom_vadc_map_voltage_temp(adcmap7_100k, ARRAY_SIZE(adcmap7_100k),
> 					 resistance, &result);
> 
> is under 80 chars anyway. 
> 
>> +	if (ret)
>> +		return ret;
>> +
>> +	*result_mdec = result;
>> +
>> +	return 0;
>> +}
>> +
>>  static int qcom_vadc_scale_hw_calib_volt(
>>  				const struct u32_fract *prescale,
>>  				const struct adc5_data *data,
>> diff --git a/include/linux/iio/adc/qcom-adc5-gen3-common.h b/include/linux/iio/adc/qcom-adc5-gen3-common.h
>> index 39cbfcbdb101..5d8e38350827 100644
>> --- a/include/linux/iio/adc/qcom-adc5-gen3-common.h
>> +++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h
>> @@ -40,7 +40,8 @@
>>  
>> +enum adc_generation {
>> +	ADC5_GEN3 = 0,
> 
> Does the value matter anywhere?  If not just leave it unspecified.
> If it does matter because it actually gets written to hardware somewhere
> I'm missing then set GEN4 as well.

It looks like the value does not really matter, I'll
leave it unspecified.

I'll also address your other comments in the next patch series.

Thanks,
Jishnu


> 
>> +	ADC5_GEN4,
>> +};
>> +
> 
> Thanks,
> 
> Jonathan


  reply	other threads:[~2026-08-06 10:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 18:06 [PATCH 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
2026-07-31 18:06 ` [PATCH 1/7] dt-bindings: iio: adc: Add support for QCOM " Jishnu Prakash
2026-08-02 23:49   ` Jonathan Cameron
2026-08-06 10:52     ` Jishnu Prakash
2026-08-06 23:14       ` Jonathan Cameron
2026-08-04  8:20   ` Krzysztof Kozlowski
2026-08-06 10:53     ` Jishnu Prakash
2026-07-31 18:06 ` [PATCH 2/7] iio: adc: qcom-spmi-adc5-gen3: " Jishnu Prakash
2026-08-03  0:14   ` Jonathan Cameron
2026-08-06 10:52     ` Jishnu Prakash [this message]
2026-08-06 23:18       ` Jonathan Cameron
2026-08-07  8:07         ` Jishnu Prakash
2026-07-31 18:06 ` [PATCH 3/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: " Jishnu Prakash
2026-08-03  0:17   ` Jonathan Cameron
2026-08-06 10:52     ` Jishnu Prakash
2026-07-31 18:06 ` [PATCH 4/7] arm64: dts: qcom: Add header file for ADC5 Gen4 channel macros Jishnu Prakash
2026-07-31 18:06 ` [PATCH 5/7] arm64: dts: qcom: pmk8850: Add ADC5 Gen4 peripheral Jishnu Prakash
2026-07-31 18:06 ` [PATCH 6/7] arm64: dts: qcom: glymur: Add ADC support for Glymur CRD Jishnu Prakash
2026-07-31 18:06 ` [PATCH 7/7] arm64: dts: qcom: kaanapali: Add ADC support for Kaanapali boards 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=a98d90bd-aa9d-4af3-aa54-3a34300070d4@oss.qualcomm.com \
    --to=jishnu.prakash@oss.qualcomm.com \
    --cc=amitk@kernel.org \
    --cc=andersson@kernel.org \
    --cc=andy@kernel.org \
    --cc=anjelique.melendez@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=kamal.wadhwa@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=manaf.pallikunhi@oss.qualcomm.com \
    --cc=nuno.sa@analog.com \
    --cc=priyansh.jain@oss.qualcomm.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=thara.gopinath@gmail.com \
    /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