* [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC
@ 2026-11-20 9:19 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
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash,
Andy Shevchenko
PMIC5 Gen4 ADC is the next generation following PMIC5 Gen3 ADC, with
several hardware changes for improved performance. In software
implementation, it is mostly similar to Gen3 ADC with the following
key differences:
- Increased ratiometric conversion resolution from 14 bits to 16 bits.
- Extended SID field from 4 to 5 bits and addition of a 2-bit bus index
field in the SID register, to support communication with up to 32 PMICs
per bus across up to 4 buses under the latest PMIC arbiter (v8).
This series adds support for the PMIC5 Gen4 ADC:
Patches 1, 3 and 4 add the dt-bindings, IIO ADC driver, and thermal ADC-TM
driver support respectively within the existing files, to support
Gen4 ADC channels under existing master PMICs with Gen3 ADC peripheral.
Patch 2 is a fix to explicitly assign any enum values used in hardware
to avoid issues later from enum modifications in the middle.
Patch 5 is a cleanup to remove Gen3 virtual channel macros after they
have been updated in both the IIO ADC and thermal ADC-TM drivers.
Patches 6 and 7 add the dt-bindings and IIO ADC driver support for
having a master PMIC with Gen4 ADC (with channels under it being Gen4 by
default).
DT patches have been dropped from this series, they will be sent in a
separate series.
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
Changes in v2:
- Made following changes to address comments from Jonathan:
- Split documentation and IIO driver patches to first add support for Gen4
ADC channels under master PMICs with Gen3 ADC peripheral, and then
remaining Gen4 support, for master PMICs with Gen4 ADC peripheral.
- Reversed order of if() checks in adc5_gen3_read_voltage_data.
- Avoided moving adc5_match_table.
- Made formatting fixes in adc5_gen4_chans_pmic and other places to
keep code on a single line.
- Added patch to explicitly assign enums used in HW as Andy suggested.
- Added a cleanup patch to remove replaced ADC Gen3 virtual channel macros.
- Added kernel-doc comments for new members added to struct
adc5_channel_common_prop.
- Link to v1: https://patch.msgid.link/20260731-pmic5_gen4_adc-v1-0-9c49b2eea6f9@oss.qualcomm.com
---
Jishnu Prakash (7):
dt-bindings: iio: adc: Add "qcom,adc5-gen4" property for ADC channels
iio: adc: qcom-adc5-gen3: Explicitly assign enum values used in hardware
iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
thermal: qcom: qcom-spmi-adc-tm5-gen3: Add support for QCOM PMIC5 Gen4 ADC
iio: adc: qcom-spmi-adc5-gen3: Remove Gen3 virtual channel macros
dt-bindings: iio: adc: Add support for QCOM PMIC5 Gen4 ADC
iio: adc: qcom-spmi-adc5-gen3: Add support for Gen4 ADC master PMICs
.../bindings/iio/adc/qcom,spmi-adc5-gen3.yaml | 47 +++++++-
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 133 +++++++++++++++------
drivers/iio/adc/qcom-vadc-common.c | 41 +++++++
drivers/thermal/qcom/qcom-spmi-adc-tm5-gen3.c | 19 ++-
include/linux/iio/adc/qcom-adc5-gen3-common.h | 59 +++++++--
include/linux/iio/adc/qcom-vadc-common.h | 6 +
6 files changed, 251 insertions(+), 54 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20260730-pmic5_gen4_adc-f33d756bba5c
Best regards,
--
Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/7] dt-bindings: iio: adc: Add "qcom,adc5-gen4" property for ADC channels
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
@ 2026-11-20 9:19 ` 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
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
PMIC5 Gen4 ADC is similar to PMIC5 Gen3 ADC, with several changes made for
improved performance, mostly at the hardware level. The main differences
are increased ratiometric conversion resolution (from 14 bits to 16 bits)
and increased bit field width for PMIC SID (to allow communication with an
increased number of PMICs, supported on latest SoCs).
In the Gen3 ADC topology, the ADC peripheral on the master PMIC
communicates with ADCs on other PMICs. It is possible that some of these
other PMICs have ADCs of a different generation and may need to be handled
differently (for example, on SM8750, PMK8550 is the master PMIC with Gen3
ADC peripheral and it communicates with PMIH0108, which has Gen4 ADC).
Add the "qcom,adc5-gen4" ADC channel property to indicate that a channel
is of type Gen4 ADC.
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
.../devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
index 149f4af8f4b8..065b82c41e86 100644
--- a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
@@ -83,6 +83,14 @@ patternProperties:
This property indicates ADC_TM monitoring is done on this channel.
type: boolean
+ qcom,adc5-gen4:
+ description:
+ Indicates channel is of type ADC5 Gen4. This may be needed in cases where the
+ master PMIC has an ADC peripheral of type Gen3, but some of the other PMICs it
+ communicates with have ADC peripherals of type Gen4, so channels of those PMICs
+ need to be marked as Gen4 to ensure their conversions are handled correctly.
+ type: boolean
+
required:
- compatible
- reg
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/7] iio: adc: qcom-adc5-gen3: Explicitly assign enum values used in hardware
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 ` 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
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash,
Andy Shevchenko
Give explicit assignments for enum values meant to be written into hardware
registers to avoid errors due to later additions in the middle of the
enums.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
include/linux/iio/adc/qcom-adc5-gen3-common.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/iio/adc/qcom-adc5-gen3-common.h b/include/linux/iio/adc/qcom-adc5-gen3-common.h
index b3e2c2f50e8f..ec7238e93396 100644
--- a/include/linux/iio/adc/qcom-adc5-gen3-common.h
+++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h
@@ -104,16 +104,16 @@
enum adc5_cal_method {
ADC5_NO_CAL = 0,
- ADC5_RATIOMETRIC_CAL,
- ADC5_ABSOLUTE_CAL,
+ ADC5_RATIOMETRIC_CAL = 1,
+ ADC5_ABSOLUTE_CAL = 2,
};
enum adc5_time_select {
MEAS_INT_DISABLE = 0,
- MEAS_INT_IMMEDIATE,
- MEAS_INT_50MS,
- MEAS_INT_100MS,
- MEAS_INT_1S,
+ MEAS_INT_IMMEDIATE = 1,
+ MEAS_INT_50MS = 2,
+ MEAS_INT_100MS = 3,
+ MEAS_INT_1S = 4,
MEAS_INT_NONE,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
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 ` Jishnu Prakash
2026-11-20 9:35 ` sashiko-bot
2026-11-20 10:14 ` Andy Shevchenko
2026-11-20 9:19 ` [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: " Jishnu Prakash
` (3 subsequent siblings)
6 siblings, 2 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
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.
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. For
example, on SM8750, PMK8550 is the master PMIC with Gen3 ADC and it
communicates with PMIH0108, which has Gen4 ADC. Add a new DT property
"qcom,adc5-gen4" to distinguish Gen4 channels under a Gen3 master, to
ensure that their conversions are handled correctly.
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@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 | 125 ++++++++++++++++++--------
drivers/iio/adc/qcom-vadc-common.c | 30 +++++++
include/linux/iio/adc/qcom-adc5-gen3-common.h | 42 +++++++++
include/linux/iio/adc/qcom-vadc-common.h | 4 +
4 files changed, 164 insertions(+), 37 deletions(-)
diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index be12bb6781cb..aa06d4d1083a 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;
@@ -98,9 +100,11 @@ static int adc5_gen3_read_voltage_data(struct adc5_chip *adc, u16 *data)
*data = get_unaligned_le16(rslt);
- if (*data == ADC5_USR_DATA_CHECK) {
- dev_err(adc->dev, "Invalid data:%#x\n", *data);
- return -EINVAL;
+ if (!(prop->generation == ADC5_GEN4 && prop->cal_method == ADC5_RATIOMETRIC_CAL)) {
+ if (*data == ADC5_USR_DATA_CHECK) {
+ dev_err(adc->dev, "Invalid data:%#x\n", *data);
+ return -EINVAL;
+ }
}
dev_dbg(adc->dev, "voltage raw code:%#x\n", *data);
@@ -131,8 +135,9 @@ static int adc5_gen3_configure(struct adc5_chip *adc,
if (ret)
return ret;
- /* Write SID */
- buf[0] = FIELD_PREP(ADC5_GEN3_SID_MASK, prop->sid);
+ /* Write SID and bus_id*/
+ buf[0] = FIELD_PREP(ADC5_GEN4_BUS_INDEX_MASK, prop->bus_index) |
+ FIELD_PREP(ADC5_GEN4_SID_MASK, prop->sid);
/*
* Use channel 0 by default for immediate conversion and to indicate
@@ -268,7 +273,7 @@ static int adc5_gen3_do_conversion(struct adc5_chip *adc,
return -ETIMEDOUT;
}
- ret = adc5_gen3_read_voltage_data(adc, data_volt);
+ ret = adc5_gen3_read_voltage_data(adc, prop, data_volt);
if (ret)
return ret;
@@ -325,7 +330,7 @@ static int adc5_gen3_fwnode_xlate(struct iio_dev *indio_dev,
int i, v_channel;
for (i = 0; i < adc->nchannels; i++) {
- v_channel = ADC5_GEN3_V_CHAN(adc->chan_props[i].common_props);
+ v_channel = ADC5_GEN4_V_CHAN(adc->chan_props[i].common_props);
if (v_channel == iiospec->args[0])
return i;
}
@@ -351,7 +356,7 @@ static int adc5_gen3_read_raw(struct iio_dev *indio_dev,
return ret;
ret = qcom_adc5_hw_scale(prop->scale_fn_type, prop->prescale,
- adc->data, adc_code_volt, val);
+ prop->data, adc_code_volt, val);
if (ret)
return ret;
@@ -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)
+};
+
+static const struct adc5_data adc5_gen3_data_pmic = {
+ .full_scale_code_volt = 0x70e4,
+ .adc_chans = adc5_gen3_chans_pmic,
+ .info = &adc5_gen3_info,
+ .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
+ { 85, 340, 1360 },
+ .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
+ { 15, 100, 200, 300,
+ 400, 500, 600, 700,
+ 1000, 2000, 4000, 8000,
+ 16000, 32000, 64000, 128000 },
+};
+
+static const struct adc5_data adc5_gen4_data_pmic = {
+ .full_scale_code_volt = 0x70e4,
+ .adc_chans = adc5_gen4_chans_pmic,
+ .info = &adc5_gen3_info,
+ .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
+ { 85, 340, 1360 },
+ .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
+ { 15, 100, 200, 300,
+ 400, 500, 600, 700,
+ 1000, 2000, 4000, 8000,
+ 16000, 32000, 64000, 128000 },
+};
+
static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
struct adc5_channel_prop *prop,
struct fwnode_handle *fwnode)
{
const char *name = fwnode_get_name(fwnode);
- const struct adc5_data *data = adc->data;
+ const struct adc5_data *data;
+ u32 chan, value, sid, bus_index;
struct device *dev = adc->dev;
const char *channel_name;
- u32 chan, value, sid;
u32 varr[2];
int ret;
@@ -452,27 +502,42 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
/*
* Value read from "reg" is virtual channel number
- * virtual channel number = sid << 8 | channel number
+ * virtual channel number = bus index << 13 | sid << 8 | channel number
+ * For ADC5 GEN3 channels, bus index = 0
*/
- sid = FIELD_GET(ADC5_GEN3_VIRTUAL_SID_MASK, chan);
- chan = FIELD_GET(ADC5_GEN3_CHANNEL_MASK, chan);
+ bus_index = FIELD_GET(ADC5_GEN4_V_CHAN_BUS_INDEX_MASK, chan);
+ sid = FIELD_GET(ADC5_GEN4_V_CHAN_SID_MASK, chan);
+ chan = FIELD_GET(ADC5_GEN4_V_CHAN_CHANNEL_MASK, chan);
if (chan >= ADC5_MAX_CHANNEL)
return dev_err_probe(dev, -EINVAL,
"%s invalid channel number %d\n",
name, chan);
+ prop->common_props.bus_index = bus_index;
prop->common_props.channel = chan;
prop->common_props.sid = sid;
- if (!adc->data->adc_chans[chan].info_mask)
+ if (fwnode_property_read_bool(fwnode, "qcom,adc5-gen4")) {
+ prop->common_props.generation = ADC5_GEN4;
+ data = &adc5_gen4_data_pmic;
+ } else {
+ prop->common_props.generation = ADC5_GEN3;
+ data = &adc5_gen3_data_pmic;
+ }
+ prop->common_props.data = data;
+
+ if (!data->adc_chans[chan].info_mask)
return dev_err_probe(dev, -EINVAL, "Channel %#x not supported\n", chan);
channel_name = name;
fwnode_property_read_string(fwnode, "label", &channel_name);
prop->common_props.label = channel_name;
- value = data->decimation[ADC5_DECIMATION_DEFAULT];
+ if (prop->common_props.generation == ADC5_GEN3)
+ value = data->decimation[ADC5_DECIMATION_DEFAULT];
+ else
+ value = data->decimation[ADC5_GEN4_DECIMATION_DEFAULT];
fwnode_property_read_u32(fwnode, "qcom,decimation", &value);
ret = qcom_adc5_decimation_from_dt(value, data->decimation);
if (ret < 0)
@@ -480,7 +545,7 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
chan, value);
prop->common_props.decimation = ret;
- prop->common_props.prescale = adc->data->adc_chans[chan].prescale_index;
+ prop->common_props.prescale = data->adc_chans[chan].prescale_index;
ret = fwnode_property_read_u32_array(fwnode, "qcom,pre-scaling", varr, 2);
if (!ret) {
ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]);
@@ -526,19 +591,6 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
return 0;
}
-static const struct adc5_data adc5_gen3_data_pmic = {
- .full_scale_code_volt = 0x70e4,
- .adc_chans = adc5_gen3_chans_pmic,
- .info = &adc5_gen3_info,
- .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
- { 85, 340, 1360 },
- .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
- { 15, 100, 200, 300,
- 400, 500, 600, 700,
- 1000, 2000, 4000, 8000,
- 16000, 32000, 64000, 128000 },
-};
-
static const struct of_device_id adc5_match_table[] = {
{
.compatible = "qcom,spmi-adc5-gen3",
@@ -554,6 +606,7 @@ static int adc5_get_fw_data(struct adc5_chip *adc)
struct adc5_channel_prop *chan_props;
struct iio_chan_spec *iio_chan;
struct device *dev = adc->dev;
+ const struct adc5_data *data;
unsigned int index = 0;
int ret;
@@ -581,10 +634,11 @@ static int adc5_get_fw_data(struct adc5_chip *adc)
return ret;
chan_props->chip = adc;
- adc_chan = &adc->data->adc_chans[chan_props->common_props.channel];
+ data = chan_props->common_props.data;
+ adc_chan = &data->adc_chans[chan_props->common_props.channel];
chan_props->common_props.scale_fn_type = adc_chan->scale_fn_type;
- iio_chan->channel = ADC5_GEN3_V_CHAN(chan_props->common_props);
+ iio_chan->channel = ADC5_GEN4_V_CHAN(chan_props->common_props);
iio_chan->info_mask_separate = adc_chan->info_mask;
iio_chan->type = adc_chan->type;
iio_chan->address = index;
@@ -696,7 +750,7 @@ int adc5_gen3_get_scaled_reading(struct device *dev,
return qcom_adc5_hw_scale(common_props->scale_fn_type,
common_props->prescale,
- adc->data, adc_code_volt, val);
+ common_props->data, adc_code_volt, val);
}
EXPORT_SYMBOL_NS_GPL(adc5_gen3_get_scaled_reading, "QCOM_SPMI_ADC5_GEN3");
@@ -704,12 +758,9 @@ int adc5_gen3_therm_code_to_temp(struct device *dev,
struct adc5_channel_common_prop *common_props,
u16 code, int *val)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
- struct adc5_chip *adc = iio_priv(indio_dev);
-
return qcom_adc5_hw_scale(common_props->scale_fn_type,
common_props->prescale,
- adc->data, code, val);
+ common_props->data, code, val);
}
EXPORT_SYMBOL_NS_GPL(adc5_gen3_therm_code_to_temp, "QCOM_SPMI_ADC5_GEN3");
diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index b03cf584b165..5c4052f6f24f 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -301,6 +301,10 @@ static const struct u32_fract adc5_prescale_ratios[] = {
{ .numerator = 1, .denominator = 16 },
};
+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);
static int qcom_vadc_scale_hw_calib_volt(
const struct u32_fract *prescale,
const struct adc5_data *data,
@@ -341,6 +345,7 @@ 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},
};
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
@@ -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);
+ 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 ec7238e93396..fa7e08d67f26 100644
--- a/include/linux/iio/adc/qcom-adc5-gen3-common.h
+++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h
@@ -41,6 +41,8 @@
#define ADC5_GEN3_SID 0x4f
#define ADC5_GEN3_SID_MASK GENMASK(3, 0)
+#define ADC5_GEN4_SID_MASK GENMASK(4, 0)
+#define ADC5_GEN4_BUS_INDEX_MASK GENMASK(6, 5)
#define ADC5_GEN3_PERPH_CH 0x50
#define ADC5_GEN3_CHAN_CONV_REQ BIT(7)
@@ -51,6 +53,7 @@
#define ADC5_GEN3_DIG_PARAM 0x52
#define ADC5_GEN3_DIG_PARAM_CAL_SEL_MASK GENMASK(5, 4)
#define ADC5_GEN3_DIG_PARAM_DEC_RATIO_SEL_MASK GENMASK(3, 2)
+#define ADC5_GEN4_DECIMATION_DEFAULT 1
#define ADC5_GEN3_FAST_AVG 0x53
#define ADC5_GEN3_FAST_AVG_CTL_EN BIT(7)
@@ -79,6 +82,13 @@
#define ADC5_GEN3_CHANNEL_MASK GENMASK(7, 0)
#define ADC5_GEN3_V_CHAN(x) \
(FIELD_PREP(ADC5_GEN3_VIRTUAL_SID_MASK, (x).sid) | (x).channel)
+#define ADC5_GEN4_V_CHAN_BUS_INDEX_MASK GENMASK(14, 13)
+#define ADC5_GEN4_V_CHAN_SID_MASK GENMASK(12, 8)
+#define ADC5_GEN4_V_CHAN_CHANNEL_MASK GENMASK(7, 0)
+#define ADC5_GEN4_V_CHAN(x) \
+ (FIELD_PREP(ADC5_GEN4_V_CHAN_BUS_INDEX_MASK, (x).bus_index) | \
+ FIELD_PREP(ADC5_GEN4_V_CHAN_SID_MASK, (x).sid) | \
+ FIELD_PREP(ADC5_GEN4_V_CHAN_CHANNEL_MASK, (x).channel))
/* ADC channels for PMIC5 Gen3 */
#define ADC5_GEN3_REF_GND 0x00
@@ -102,6 +112,27 @@
#define ADC5_MAX_CHANNEL 0xc0
+/* ADC channels for PMIC5 Gen4 */
+#define ADC5_GEN4_OFFSET_REF 0x00
+#define ADC5_GEN4_1P25VREF 0x01
+#define ADC5_GEN4_DIE_TEMP 0x03
+#define ADC5_GEN4_USB_SNS_DIV20 0x11
+#define ADC5_GEN4_VIN_DIV20_MUX 0x12
+#define ADC5_GEN4_VPH_PWR 0x8e
+#define ADC5_GEN4_VBAT_SNS_QBG 0x8f
+/* 100k pull-up channels */
+#define ADC5_GEN4_AMUX1_THM_100K_PU 0x44
+#define ADC5_GEN4_AMUX2_THM_100K_PU 0x45
+#define ADC5_GEN4_AMUX3_THM_100K_PU 0x46
+#define ADC5_GEN4_AMUX4_THM_100K_PU 0x47
+#define ADC5_GEN4_AMUX5_THM_100K_PU 0x48
+#define ADC5_GEN4_AMUX6_THM_100K_PU 0x49
+#define ADC5_GEN4_AMUX1_GPIO_100K_PU 0x4a
+#define ADC5_GEN4_AMUX2_GPIO_100K_PU 0x4b
+#define ADC5_GEN4_AMUX3_GPIO_100K_PU 0x4c
+#define ADC5_GEN4_AMUX4_GPIO_100K_PU 0x4d
+#define ADC5_GEN4_AMUX5_GPIO_100K_PU 0x5e
+
enum adc5_cal_method {
ADC5_NO_CAL = 0,
ADC5_RATIOMETRIC_CAL = 1,
@@ -117,6 +148,11 @@ enum adc5_time_select {
MEAS_INT_NONE,
};
+enum adc_generation {
+ ADC5_GEN3,
+ ADC5_GEN4,
+};
+
/**
* struct adc5_sdam_data - data per SDAM allocated for adc usage
* @base_addr: base address for the ADC SDAM peripheral.
@@ -155,6 +191,9 @@ struct adc5_device_data {
* that is an average of multiple measurements.
* @scale_fn_type: Represents the scaling function to convert voltage
* physical units desired by the client for the channel.
+ * @generation: Generation of the ADC HW of the channel.
+ * @bus_index: SPMI bus index of PMIC owning the channel.
+ * @data: top-level ADC data structure.
*/
struct adc5_channel_common_prop {
unsigned int channel;
@@ -166,6 +205,9 @@ struct adc5_channel_common_prop {
unsigned int hw_settle_time_us;
unsigned int avg_samples;
enum vadc_scale_fn_type scale_fn_type;
+ enum adc_generation generation;
+ unsigned int bus_index;
+ const struct adc5_data *data;
};
/**
diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h
index 3bf4c49726a7..4be682083843 100644
--- a/include/linux/iio/adc/qcom-vadc-common.h
+++ b/include/linux/iio/adc/qcom-vadc-common.h
@@ -54,6 +54,7 @@
#define R_PU_100K 100000
#define RATIO_MAX_ADC7 BIT(14)
+#define RATIO_MAX_ADC5_GEN4 0xffff
/*
* VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
@@ -105,6 +106,8 @@ struct vadc_linear_graph {
* charger temperature.
* @SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5
* SMB1390 temperature.
+ * @SCALE_HW_CALIB_THERM_100K_PU_GEN4: Returns temperature in millidegC using
+ * lookup table for PMIC5 Gen4 ADC. The hardware applies offset/slope to adc code.
*/
enum vadc_scale_fn_type {
SCALE_DEFAULT = 0,
@@ -120,6 +123,7 @@ enum vadc_scale_fn_type {
SCALE_HW_CALIB_PMIC_THERM_PM7,
SCALE_HW_CALIB_PM5_CHG_TEMP,
SCALE_HW_CALIB_PM5_SMB_TEMP,
+ SCALE_HW_CALIB_THERM_100K_PU_GEN4,
/* private: */
SCALE_HW_CALIB_INVALID,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: Add support for QCOM PMIC5 Gen4 ADC
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
` (2 preceding siblings ...)
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:19 ` Jishnu Prakash
2026-11-20 9:19 ` [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Remove Gen3 virtual channel macros Jishnu Prakash
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
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@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-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);
+}
+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;
+
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;
- /* Write SID */
- buf[0] = FIELD_PREP(ADC5_GEN3_SID_MASK, prop->common_props.sid);
+ /* Write SID and bus_id*/
+ buf[0] = FIELD_PREP(ADC5_GEN4_BUS_INDEX_MASK, prop->common_props.bus_index) |
+ FIELD_PREP(ADC5_GEN4_SID_MASK, prop->common_props.sid);
/* Select TM channel and indicate there is an actual conversion request */
buf[1] = ADC5_GEN3_CHAN_CONV_REQ | prop->tm_chan_index;
@@ -252,7 +261,7 @@ static int adc_tm5_gen3_configure(struct adc_tm5_gen3_channel_props *prop,
/* High temperature corresponds to low voltage threshold */
prop->low_thr_en = (high_temp != INT_MAX);
if (prop->low_thr_en) {
- adc_code = qcom_adc_tm5_gen2_temp_res_scale(high_temp);
+ adc_code = tm_scal_fn(high_temp);
put_unaligned_le16(adc_code, &buf[8]);
buf[7] |= ADC5_GEN3_LOW_THR_INT_EN;
}
@@ -260,7 +269,7 @@ static int adc_tm5_gen3_configure(struct adc_tm5_gen3_channel_props *prop,
/* Low temperature corresponds to high voltage threshold */
prop->high_thr_en = (low_temp != -INT_MAX);
if (prop->high_thr_en) {
- adc_code = qcom_adc_tm5_gen2_temp_res_scale(low_temp);
+ adc_code = tm_scal_fn(low_temp);
put_unaligned_le16(adc_code, &buf[10]);
buf[7] |= ADC5_GEN3_HIGH_THR_INT_EN;
}
@@ -306,7 +315,7 @@ static int adc_tm5_register_tzd(struct adc_tm5_gen3_chip *adc_tm5)
int ret;
for (int i = 0; i < adc_tm5->nchannels; i++) {
- channel = ADC5_GEN3_V_CHAN(adc_tm5->chan_props[i].common_props);
+ channel = ADC5_GEN4_V_CHAN(adc_tm5->chan_props[i].common_props);
tzd = devm_thermal_of_zone_register(adc_tm5->dev, channel,
&adc_tm5->chan_props[i],
&adc_tm_ops);
diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h
index 4be682083843..55efad27ed73 100644
--- a/include/linux/iio/adc/qcom-vadc-common.h
+++ b/include/linux/iio/adc/qcom-vadc-common.h
@@ -159,6 +159,8 @@ u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
u16 qcom_adc_tm5_gen2_temp_res_scale(int temp);
+u16 qcom_adc_tm5_gen4_temp_res_scale(int temp);
+
int qcom_adc5_prescaling_from_dt(u32 num, u32 den);
int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 5/7] iio: adc: qcom-spmi-adc5-gen3: Remove Gen3 virtual channel macros
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
` (3 preceding siblings ...)
2026-11-20 9:19 ` [PATCH v2 4/7] thermal: qcom: qcom-spmi-adc-tm5-gen3: " Jishnu Prakash
@ 2026-11-20 9:19 ` 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
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
Now that the Gen3 virtual channel macros have been replaced with Gen4
macros in both main IIO ADC driver and auxiliary ADC_TM driver, remove
the Gen3 macros as they are no longer used.
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
include/linux/iio/adc/qcom-adc5-gen3-common.h | 5 -----
1 file changed, 5 deletions(-)
diff --git a/include/linux/iio/adc/qcom-adc5-gen3-common.h b/include/linux/iio/adc/qcom-adc5-gen3-common.h
index fa7e08d67f26..105b0766a01f 100644
--- a/include/linux/iio/adc/qcom-adc5-gen3-common.h
+++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h
@@ -40,7 +40,6 @@
#define ADC5_GEN3_CONV_ERR_CLR_REQ BIT(0)
#define ADC5_GEN3_SID 0x4f
-#define ADC5_GEN3_SID_MASK GENMASK(3, 0)
#define ADC5_GEN4_SID_MASK GENMASK(4, 0)
#define ADC5_GEN4_BUS_INDEX_MASK GENMASK(6, 5)
@@ -78,10 +77,6 @@
#define ADC5_GEN3_CONV_REQ 0xe5
#define ADC5_GEN3_CONV_REQ_REQ BIT(0)
-#define ADC5_GEN3_VIRTUAL_SID_MASK GENMASK(15, 8)
-#define ADC5_GEN3_CHANNEL_MASK GENMASK(7, 0)
-#define ADC5_GEN3_V_CHAN(x) \
- (FIELD_PREP(ADC5_GEN3_VIRTUAL_SID_MASK, (x).sid) | (x).channel)
#define ADC5_GEN4_V_CHAN_BUS_INDEX_MASK GENMASK(14, 13)
#define ADC5_GEN4_V_CHAN_SID_MASK GENMASK(12, 8)
#define ADC5_GEN4_V_CHAN_CHANNEL_MASK GENMASK(7, 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 6/7] dt-bindings: iio: adc: Add support for QCOM PMIC5 Gen4 ADC
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
` (4 preceding siblings ...)
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 ` 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
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
At present, support is present for Gen4 ADC channels under a master PMIC
with Gen3 ADC. Add a compatible string "qcom,spmi-adc5-gen4" to support a
master PMIC with Gen4 ADC. ADC channels under such a device can be
considered to be of type Gen4 ADC by default.
To support any exceptions (Gen3 ADC channels under a Gen4 master), add the
"qcom,adc5-gen3" ADC channel property, analogous to "qcom,adc5-gen4", to
indicate that a channel is of type Gen3 ADC.
Add constraints to ensure that "qcom,adc5-gen4" and "qcom,adc5-gen3"
channel properties are only valid if the top-level compatible string is
of the opposite type. A channel without either of these properties can be
assumed to be of the same type indicated by the master PMIC's compatible
string.
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
.../bindings/iio/adc/qcom,spmi-adc5-gen3.yaml | 39 +++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
index 065b82c41e86..e79ddc2acca0 100644
--- a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-adc5-gen3.yaml
@@ -21,9 +21,14 @@ description: |
All boards using a particular (SOC + master PMIC) combination will have the
same number of ADC SDAMs supported on that PMIC.
+ PMIC5 Gen4 ADC is similar to Gen3 ADC, with some differences such as
+ improved ratiometric conversion resolution.
+
properties:
compatible:
- const: qcom,spmi-adc5-gen3
+ enum:
+ - qcom,spmi-adc5-gen3
+ - qcom,spmi-adc5-gen4
reg:
items:
@@ -91,6 +96,38 @@ patternProperties:
need to be marked as Gen4 to ensure their conversions are handled correctly.
type: boolean
+ qcom,adc5-gen3:
+ description:
+ Indicates channel is of type ADC5 Gen3. This may be needed in cases where the
+ master PMIC has an ADC peripheral of type Gen4, but some of the other PMICs
+ under it have ADC peripherals of type Gen3.
+ type: boolean
+
+allOf:
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: qcom,spmi-adc5-gen4
+
+ then:
+ patternProperties:
+ "^channel@[0-9a-f]+$":
+ properties:
+ qcom,adc5-gen4: false
+
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: qcom,spmi-adc5-gen3
+
+ then:
+ patternProperties:
+ "^channel@[0-9a-f]+$":
+ properties:
+ qcom,adc5-gen3: false
+
required:
- compatible
- reg
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 7/7] iio: adc: qcom-spmi-adc5-gen3: Add support for Gen4 ADC master PMICs
2026-11-20 9:19 [PATCH v2 0/7] Add support for QCOM SPMI PMIC5 Gen4 ADC Jishnu Prakash
` (5 preceding siblings ...)
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 ` Jishnu Prakash
6 siblings, 0 replies; 10+ messages in thread
From: Jishnu Prakash @ 2026-11-20 9:19 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba
Cc: linux-iio, devicetree, linux-kernel, linux-arm-msm, linux-pm,
Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain, Jishnu Prakash
At present, support is present for Gen4 ADC channels under a master PMIC
with Gen3 ADC, through the ADC channel property "qcom,adc5-gen4". Add a
compatible string "qcom,spmi-adc5-gen4" to support a master PMIC with Gen4
ADC.
For Gen4 master PMIC, add a new DT property "qcom,adc5-gen3" to distinguish
Gen3 channels under a Gen4 master, similar to the channel property
"qcom,adc5-gen4". A channel without either of these properties is
considered to be of the same type indicated by the top-level compatible
string.
Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com>
---
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/qcom-spmi-adc5-gen3.c b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
index aa06d4d1083a..6782e0ab3993 100644
--- a/drivers/iio/adc/qcom-spmi-adc5-gen3.c
+++ b/drivers/iio/adc/qcom-spmi-adc5-gen3.c
@@ -521,9 +521,13 @@ static int adc5_gen3_get_fw_channel_data(struct adc5_chip *adc,
if (fwnode_property_read_bool(fwnode, "qcom,adc5-gen4")) {
prop->common_props.generation = ADC5_GEN4;
data = &adc5_gen4_data_pmic;
- } else {
+ } else if (fwnode_property_read_bool(fwnode, "qcom,adc5-gen3")) {
prop->common_props.generation = ADC5_GEN3;
data = &adc5_gen3_data_pmic;
+ } else {
+ prop->common_props.generation = (adc->data == &adc5_gen3_data_pmic) ?
+ ADC5_GEN3 : ADC5_GEN4;
+ data = adc->data;
}
prop->common_props.data = data;
@@ -596,6 +600,10 @@ 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);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
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
2026-11-20 10:14 ` Andy Shevchenko
1 sibling, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-20 9:35 UTC (permalink / raw)
To: Jishnu Prakash; +Cc: devicetree, robh, conor+dt
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 3/7] iio: adc: qcom-spmi-adc5-gen3: Add support for QCOM PMIC5 Gen4 ADC
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
@ 2026-11-20 10:14 ` Andy Shevchenko
1 sibling, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-11-20 10:14 UTC (permalink / raw)
To: Jishnu Prakash
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Amit Kucheria,
Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba, linux-iio, devicetree, linux-kernel, linux-arm-msm,
linux-pm, Kamal Wadhwa, Anjelique Melendez,
Manaf Meethalavalappu Pallikunhi, Priyansh Jain
On Fri, Nov 20, 2026 at 02:49:43PM +0530, Jishnu Prakash 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.
>
> 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. For
> example, on SM8750, PMK8550 is the master PMIC with Gen3 ADC and it
> communicates with PMIH0108, which has Gen4 ADC. Add a new DT property
> "qcom,adc5-gen4" to distinguish Gen4 channels under a Gen3 master, to
> ensure that their conversions are handled correctly.
>
> 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.
...
> - /* Write SID */
> - buf[0] = FIELD_PREP(ADC5_GEN3_SID_MASK, prop->sid);
> + /* Write SID and bus_id*/
Missed space.
> + buf[0] = FIELD_PREP(ADC5_GEN4_BUS_INDEX_MASK, prop->bus_index) |
> + FIELD_PREP(ADC5_GEN4_SID_MASK, prop->sid);
...
> -static const struct adc5_data adc5_gen3_data_pmic = {
> - .full_scale_code_volt = 0x70e4,
> - .adc_chans = adc5_gen3_chans_pmic,
> - .info = &adc5_gen3_info,
> - .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX])
> - { 85, 340, 1360 },
> - .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX])
> - { 15, 100, 200, 300,
> - 400, 500, 600, 700,
> - 1000, 2000, 4000, 8000,
> - 16000, 32000, 64000, 128000 },
> -};
Seems like this is existing piece and you moved it up. Please, split that part
to a separate prerequisite patch.
...
> +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)
Even if the rest of the file uses this ugly indentation, correct it for a new code.
Not a problem if lines will be a bit longer.
> +{
> + 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)*/
Again, missing space.
> + resistance *= R_PU_100K;
> + resistance = div64_s64(resistance, RATIO_MAX_ADC5_GEN4 - adc_code);
I would put it like this
resistance = div64_s64(adc_code * R_PU_100K, RATIO_MAX_ADC5_GEN4 - adc_code);
OR this
resistance =
div64_s64(adc_code * R_PU_100K, RATIO_MAX_ADC5_GEN4 - adc_code);
(but it still uses two lines, so I find the previous one slightly better).
> + ret = qcom_vadc_map_voltage_temp(adcmap7_100k, ARRAY_SIZE(adcmap7_100k),
> + resistance, &result);
> + if (ret)
> + return ret;
> +
> + *result_mdec = result;
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-20 10:14 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-20 10:14 ` Andy Shevchenko
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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.