* [PATCH 0/2] iio: adc: qcom-pm8xxx-xoadc improvements
@ 2025-10-27 17:29 Antony Kurniawan Soemardi
2025-10-27 17:29 ` [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels Antony Kurniawan Soemardi
2025-10-27 17:29 ` [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values Antony Kurniawan Soemardi
0 siblings, 2 replies; 13+ messages in thread
From: Antony Kurniawan Soemardi @ 2025-10-27 17:29 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
Cc: linux-arm-msm, linux-iio, linux-kernel, Antony Kurniawan Soemardi
This small series improves the Qualcomm PM8xxx XOADC driver in two ways:
1. Adds support for reading channel labels through sysfs.
This helps user-space tools identify ADC channels by name.
2. Fixes incorrect calibration values used on msm8960-based devices.
Previously, the driver failed to apply the proper ratiometric scaling
and incorrectly set certain bits in the ADC_ARB_USRP_DIG_PARAM
register. This resulted in inaccurate voltage readings from the IIO
interface. With the fix, calibration values now match downstream
implementations, and readings for channels like USB_VBUS and 125V
are correct.
Tested on Sony Xperia SP.
Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com>
---
Antony Kurniawan Soemardi (2):
iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels
iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values
drivers/iio/adc/qcom-pm8xxx-xoadc.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
base-commit: dcb6fa37fd7bc9c3d2b066329b0d27dedf8becaa
change-id: 20251018-pm8xxx-xoadc-fix-b98f8ff20f57
Best regards,
--
Antony Kurniawan Soemardi <linux@smankusors.com>
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels 2025-10-27 17:29 [PATCH 0/2] iio: adc: qcom-pm8xxx-xoadc improvements Antony Kurniawan Soemardi @ 2025-10-27 17:29 ` Antony Kurniawan Soemardi 2025-10-28 9:55 ` Andy Shevchenko 2025-10-27 17:29 ` [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values Antony Kurniawan Soemardi 1 sibling, 1 reply; 13+ messages in thread From: Antony Kurniawan Soemardi @ 2025-10-27 17:29 UTC (permalink / raw) To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel, Antony Kurniawan Soemardi This allows user-space tools to identify ADC channels by name through the IIO sysfs interface. Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> --- drivers/iio/adc/qcom-pm8xxx-xoadc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index 31f88cf7f7f18297132d152648b312c0fb60608e..8555f34036fb13c41ac720dc02c1dc39876e9198 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -725,8 +725,15 @@ static int pm8xxx_fwnode_xlate(struct iio_dev *indio_dev, return -EINVAL; } +static int pm8xxx_read_label(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, char *label) +{ + return sysfs_emit(label, "%s\n", chan->datasheet_name); +} + static const struct iio_info pm8xxx_xoadc_info = { .fwnode_xlate = pm8xxx_fwnode_xlate, + .read_label = pm8xxx_read_label, .read_raw = pm8xxx_read_raw, }; -- 2.34.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels 2025-10-27 17:29 ` [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels Antony Kurniawan Soemardi @ 2025-10-28 9:55 ` Andy Shevchenko 0 siblings, 0 replies; 13+ messages in thread From: Andy Shevchenko @ 2025-10-28 9:55 UTC (permalink / raw) To: Antony Kurniawan Soemardi Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, linux-arm-msm, linux-iio, linux-kernel On Mon, Oct 27, 2025 at 05:29:16PM +0000, Antony Kurniawan Soemardi wrote: > This allows user-space tools to identify ADC channels by name through > the IIO sysfs interface. ... > +static int pm8xxx_read_label(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, char *label) > +{ > + return sysfs_emit(label, "%s\n", chan->datasheet_name); > +} Hmm... In another thread there is a discussion on label vs. datasheet_name. So, why datasheet name and not something that it's more reliable as a platform description? As far as I understand there many mysterious ways of HW engineering and how to connect available pins to something interesting. Even datasheet names may be quite mislead on a certain platform (due to above). I would expect this to come from DT or another platform description and user space should rely on the information from _there_. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-27 17:29 [PATCH 0/2] iio: adc: qcom-pm8xxx-xoadc improvements Antony Kurniawan Soemardi 2025-10-27 17:29 ` [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels Antony Kurniawan Soemardi @ 2025-10-27 17:29 ` Antony Kurniawan Soemardi 2025-10-27 18:35 ` David Lechner 2025-10-28 9:44 ` Konrad Dybcio 1 sibling, 2 replies; 13+ messages in thread From: Antony Kurniawan Soemardi @ 2025-10-27 17:29 UTC (permalink / raw) To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel, Antony Kurniawan Soemardi On msm8960 phones, the XOADC driver was using incorrect calibration values: absolute calibration dx = 625000 uV, dy = 4 units ratiometric calibration dx = 1800, dy = -29041 units As a result, reading from the IIO bus returned unexpected results: in_voltage_7 (USB_VBUS): 0 in_voltage_10 (125V): 0 The issue was caused by not setting the ratiometric scale (amux_ip_rsv) from the predefined channels. Additionally, the downstream code always set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling those bits caused calibration errors too, so they were removed. With these fixes, calibration now uses the correct values: absolute calibration dx = 625000 uV, dy = 6307 units ratiometric calibration dx = 1800, dy = 18249 units Reading from the IIO bus now returns expected results: in_voltage_7 (USB_VBUS): 4973836 in_voltage_10 (125V): 1249405 [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> --- drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, goto unlock; /* Decimation factor */ - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); + ret = regmap_update_bits(adc->map, + ADC_ARB_USRP_DIG_PARAM, + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, + ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); if (ret) goto unlock; @@ -783,6 +784,7 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev, ch->calibration = VADC_CALIB_ABSOLUTE; /* Everyone seems to use default ("type 2") decimation */ ch->decimation = VADC_DEF_DECIMATION; + ch->amux_ip_rsv = hwchan->amux_ip_rsv; if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { ch->calibration = VADC_CALIB_RATIOMETRIC; -- 2.34.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-27 17:29 ` [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values Antony Kurniawan Soemardi @ 2025-10-27 18:35 ` David Lechner 2025-10-27 19:53 ` Antony Kurniawan Soemardi 2025-10-28 9:44 ` Konrad Dybcio 1 sibling, 1 reply; 13+ messages in thread From: David Lechner @ 2025-10-27 18:35 UTC (permalink / raw) To: Antony Kurniawan Soemardi, Jonathan Cameron, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel On 10/27/25 12:29 PM, Antony Kurniawan Soemardi wrote: > On msm8960 phones, the XOADC driver was using incorrect calibration > values: > absolute calibration dx = 625000 uV, dy = 4 units > ratiometric calibration dx = 1800, dy = -29041 units > > As a result, reading from the IIO bus returned unexpected results: > in_voltage_7 (USB_VBUS): 0 > in_voltage_10 (125V): 0 > > The issue was caused by not setting the ratiometric scale (amux_ip_rsv) > from the predefined channels. Additionally, the downstream code always Mentioning downstream kernels is usually a red flag. :-) We can justify it here though by saying that there is no documentation available other than downstream source code, so we are just using it as a reference. > set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. > That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling > those bits caused calibration errors too, so they were removed. > > With these fixes, calibration now uses the correct values: > absolute calibration dx = 625000 uV, dy = 6307 units > ratiometric calibration dx = 1800, dy = 18249 units > > Reading from the IIO bus now returns expected results: > in_voltage_7 (USB_VBUS): 4973836 > in_voltage_10 (125V): 1249405 Would be useful to mention which hardware you tested with in case it turns out that there is some other hardware that does require the SHIFT0/1 bits to be set. > > [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 > Since this is a fix, it should have a Fixes: tag. And it sounds like possibly two separate fixes. In that case, it should be two separate patches. > Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> > --- > drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 > --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c > +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, > goto unlock; > > /* Decimation factor */ > - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | > - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); > + ret = regmap_update_bits(adc->map, > + ADC_ARB_USRP_DIG_PARAM, > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, > + ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); As a follow-up patch, it would be nice to update the driver to use FIELD_PREP(). I.e. remove ADC_ARB_USRP_DIG_PARAM_DEC_RATE0, ADC_ARB_USRP_DIG_PARAM_DEC_RATE1 and ADC_DIG_PARAM_DEC_SHIFT macros and replace them with one macro: #define ADC_ARB_USRP_DIG_PARAM_DEC_RATE GENMASK(6, 5) Then use it like: ret = regmap_update_bits(adc->map, ADC_ARB_USRP_DIG_PARAM, ADC_ARB_USRP_DIG_PARAM_DEC_RATE, FIELD_PREP(ADC_ARB_USRP_DIG_PARAM_DEC_RATE, ch->decimation)); This should be done for all of the similar multi-bit fields. > if (ret) > goto unlock; > > @@ -783,6 +784,7 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev, > ch->calibration = VADC_CALIB_ABSOLUTE; > /* Everyone seems to use default ("type 2") decimation */ > ch->decimation = VADC_DEF_DECIMATION; > + ch->amux_ip_rsv = hwchan->amux_ip_rsv; > > if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { > ch->calibration = VADC_CALIB_RATIOMETRIC; > ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-27 18:35 ` David Lechner @ 2025-10-27 19:53 ` Antony Kurniawan Soemardi 2025-10-27 20:36 ` David Lechner 0 siblings, 1 reply; 13+ messages in thread From: Antony Kurniawan Soemardi @ 2025-10-27 19:53 UTC (permalink / raw) To: David Lechner, Jonathan Cameron, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel, linux On 10/28/2025 1:35 AM, David Lechner wrote: > On 10/27/25 12:29 PM, Antony Kurniawan Soemardi wrote: >> On msm8960 phones, the XOADC driver was using incorrect calibration >> values: >> absolute calibration dx = 625000 uV, dy = 4 units >> ratiometric calibration dx = 1800, dy = -29041 units >> >> As a result, reading from the IIO bus returned unexpected results: >> in_voltage_7 (USB_VBUS): 0 >> in_voltage_10 (125V): 0 >> >> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) >> from the predefined channels. Additionally, the downstream code always > Mentioning downstream kernels is usually a red flag. :-) > > We can justify it here though by saying that there is no documentation > available other than downstream source code, so we are just using it > as a reference. ah ok, rewording needed then >> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. >> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling >> those bits caused calibration errors too, so they were removed. >> >> With these fixes, calibration now uses the correct values: >> absolute calibration dx = 625000 uV, dy = 6307 units >> ratiometric calibration dx = 1800, dy = 18249 units >> >> Reading from the IIO bus now returns expected results: >> in_voltage_7 (USB_VBUS): 4973836 >> in_voltage_10 (125V): 1249405 > Would be useful to mention which hardware you tested with in case > it turns out that there is some other hardware that does require the > SHIFT0/1 bits to be set. I did mention Sony Xperia SP from cover letter, but I haven't referenced it in this commit yet. Also I tried to search on Github for SHIFT0/1 bits, but couldn't find any usage of them... >> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 >> > Since this is a fix, it should have a Fixes: tag. And it sounds like > possibly two separate fixes. In that case, it should be two separate > patches. Fixes into 63c3ecd946d4ae2879ec0d8c6dcb90132a74d831? >> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> >> --- >> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 >> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, >> goto unlock; >> >> /* Decimation factor */ >> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, >> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | >> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | >> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >> + ret = regmap_update_bits(adc->map, >> + ADC_ARB_USRP_DIG_PARAM, >> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | >> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, >> + ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); > As a follow-up patch, it would be nice to update the driver to use FIELD_PREP(). > > I.e. remove ADC_ARB_USRP_DIG_PARAM_DEC_RATE0, ADC_ARB_USRP_DIG_PARAM_DEC_RATE1 > and ADC_DIG_PARAM_DEC_SHIFT macros and replace them with one macro: > > #define ADC_ARB_USRP_DIG_PARAM_DEC_RATE GENMASK(6, 5) > > Then use it like: > > ret = regmap_update_bits(adc->map, > ADC_ARB_USRP_DIG_PARAM, > ADC_ARB_USRP_DIG_PARAM_DEC_RATE, > FIELD_PREP(ADC_ARB_USRP_DIG_PARAM_DEC_RATE, > ch->decimation)); > > This should be done for all of the similar multi-bit fields. as a follow up patch, you mean next version of this patch series, or separate patch series? >> if (ret) >> goto unlock; >> >> @@ -783,6 +784,7 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev, >> ch->calibration = VADC_CALIB_ABSOLUTE; >> /* Everyone seems to use default ("type 2") decimation */ >> ch->decimation = VADC_DEF_DECIMATION; >> + ch->amux_ip_rsv = hwchan->amux_ip_rsv; >> >> if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { >> ch->calibration = VADC_CALIB_RATIOMETRIC; >> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-27 19:53 ` Antony Kurniawan Soemardi @ 2025-10-27 20:36 ` David Lechner 0 siblings, 0 replies; 13+ messages in thread From: David Lechner @ 2025-10-27 20:36 UTC (permalink / raw) To: Antony Kurniawan Soemardi, Jonathan Cameron, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel On 10/27/25 2:53 PM, Antony Kurniawan Soemardi wrote: > On 10/28/2025 1:35 AM, David Lechner wrote: >> On 10/27/25 12:29 PM, Antony Kurniawan Soemardi wrote: >>> On msm8960 phones, the XOADC driver was using incorrect calibration >>> values: >>> absolute calibration dx = 625000 uV, dy = 4 units >>> ratiometric calibration dx = 1800, dy = -29041 units >>> >>> As a result, reading from the IIO bus returned unexpected results: >>> in_voltage_7 (USB_VBUS): 0 >>> in_voltage_10 (125V): 0 >>> >>> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) >>> from the predefined channels. Additionally, the downstream code always >> Mentioning downstream kernels is usually a red flag. :-) >> >> We can justify it here though by saying that there is no documentation >> available other than downstream source code, so we are just using it >> as a reference. > ah ok, rewording needed then >>> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. >>> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling >>> those bits caused calibration errors too, so they were removed. >>> >>> With these fixes, calibration now uses the correct values: >>> absolute calibration dx = 625000 uV, dy = 6307 units >>> ratiometric calibration dx = 1800, dy = 18249 units >>> >>> Reading from the IIO bus now returns expected results: >>> in_voltage_7 (USB_VBUS): 4973836 >>> in_voltage_10 (125V): 1249405 >> Would be useful to mention which hardware you tested with in case >> it turns out that there is some other hardware that does require the >> SHIFT0/1 bits to be set. > I did mention Sony Xperia SP from cover letter, but I haven't > referenced it in this commit yet. Also I tried to search on Github for > SHIFT0/1 bits, but couldn't find any usage of them... >>> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 >>> >> Since this is a fix, it should have a Fixes: tag. And it sounds like >> possibly two separate fixes. In that case, it should be two separate >> patches. > Fixes into 63c3ecd946d4ae2879ec0d8c6dcb90132a74d831? The correct format is: Fixes: 63c3ecd946d4 ("iio: adc: add a driver for Qualcomm PM8xxx HK/XOADC") See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-changes >>> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> >>> --- >>> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- >>> 1 file changed, 6 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 >>> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, >>> goto unlock; >>> /* Decimation factor */ >>> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | >>> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >>> + ret = regmap_update_bits(adc->map, >>> + ADC_ARB_USRP_DIG_PARAM, >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, >>> + ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >> As a follow-up patch, it would be nice to update the driver to use FIELD_PREP(). >> >> I.e. remove ADC_ARB_USRP_DIG_PARAM_DEC_RATE0, ADC_ARB_USRP_DIG_PARAM_DEC_RATE1 >> and ADC_DIG_PARAM_DEC_SHIFT macros and replace them with one macro: >> >> #define ADC_ARB_USRP_DIG_PARAM_DEC_RATE GENMASK(6, 5) >> >> Then use it like: >> >> ret = regmap_update_bits(adc->map, >> ADC_ARB_USRP_DIG_PARAM, >> ADC_ARB_USRP_DIG_PARAM_DEC_RATE, >> FIELD_PREP(ADC_ARB_USRP_DIG_PARAM_DEC_RATE, >> ch->decimation)); >> >> This should be done for all of the similar multi-bit fields. > as a follow up patch, you mean next version of this patch series, or > separate patch series? Either way is fine. It's just a "nice to have" change. >>> if (ret) >>> goto unlock; >>> @@ -783,6 +784,7 @@ static int pm8xxx_xoadc_parse_channel(struct device *dev, >>> ch->calibration = VADC_CALIB_ABSOLUTE; >>> /* Everyone seems to use default ("type 2") decimation */ >>> ch->decimation = VADC_DEF_DECIMATION; >>> + ch->amux_ip_rsv = hwchan->amux_ip_rsv; >>> if (!fwnode_property_read_u32(fwnode, "qcom,ratiometric", &rsv)) { >>> ch->calibration = VADC_CALIB_RATIOMETRIC; >>> > ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-27 17:29 ` [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values Antony Kurniawan Soemardi 2025-10-27 18:35 ` David Lechner @ 2025-10-28 9:44 ` Konrad Dybcio 2025-10-30 16:57 ` Antony Kurniawan Soemardi 1 sibling, 1 reply; 13+ messages in thread From: Konrad Dybcio @ 2025-10-28 9:44 UTC (permalink / raw) To: Antony Kurniawan Soemardi, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: > On msm8960 phones, the XOADC driver was using incorrect calibration > values: > absolute calibration dx = 625000 uV, dy = 4 units > ratiometric calibration dx = 1800, dy = -29041 units > > As a result, reading from the IIO bus returned unexpected results: > in_voltage_7 (USB_VBUS): 0 > in_voltage_10 (125V): 0 > > The issue was caused by not setting the ratiometric scale (amux_ip_rsv) > from the predefined channels. Additionally, the downstream code always > set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. > That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling > those bits caused calibration errors too, so they were removed. > > With these fixes, calibration now uses the correct values: > absolute calibration dx = 625000 uV, dy = 6307 units > ratiometric calibration dx = 1800, dy = 18249 units > > Reading from the IIO bus now returns expected results: > in_voltage_7 (USB_VBUS): 4973836 > in_voltage_10 (125V): 1249405 > > [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 > > Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> > --- > drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 > --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c > +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, > goto unlock; > > /* Decimation factor */ > - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | > - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); > + ret = regmap_update_bits(adc->map, > + ADC_ARB_USRP_DIG_PARAM, > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 for a "1K" (1/1024?) ratio, although a comment in this file suggests BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be surprised if that is the case The previously set bits are a field called DECI_SEL but are otherwise left undescribed Hope this is useful Konrad ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-28 9:44 ` Konrad Dybcio @ 2025-10-30 16:57 ` Antony Kurniawan Soemardi 2025-10-31 9:00 ` Konrad Dybcio 0 siblings, 1 reply; 13+ messages in thread From: Antony Kurniawan Soemardi @ 2025-10-30 16:57 UTC (permalink / raw) To: Konrad Dybcio, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko Cc: linux-arm-msm, linux-iio, linux-kernel On 10/28/2025 4:44 PM, Konrad Dybcio wrote: > On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: >> On msm8960 phones, the XOADC driver was using incorrect calibration >> values: >> absolute calibration dx = 625000 uV, dy = 4 units >> ratiometric calibration dx = 1800, dy = -29041 units >> >> As a result, reading from the IIO bus returned unexpected results: >> in_voltage_7 (USB_VBUS): 0 >> in_voltage_10 (125V): 0 >> >> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) >> from the predefined channels. Additionally, the downstream code always >> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. >> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling >> those bits caused calibration errors too, so they were removed. >> >> With these fixes, calibration now uses the correct values: >> absolute calibration dx = 625000 uV, dy = 6307 units >> ratiometric calibration dx = 1800, dy = 18249 units >> >> Reading from the IIO bus now returns expected results: >> in_voltage_7 (USB_VBUS): 4973836 >> in_voltage_10 (125V): 1249405 >> >> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 >> >> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> >> --- >> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 >> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, >> goto unlock; >> >> /* Decimation factor */ >> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, >> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | >> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | >> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >> + ret = regmap_update_bits(adc->map, >> + ADC_ARB_USRP_DIG_PARAM, >> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | >> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, > The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 > for a "1K" (1/1024?) ratio, although a comment in this file suggests > BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be > surprised if that is the case > > The previously set bits are a field called DECI_SEL but are otherwise left > undescribed So, do you think we can leave the BIT(0) and BIT(1) as is? I have a feeling that if they aren't set, these changes might prevent the APQ8060 Dragonboard from reading the cm3605 sensor? or maybe not? I mean this one, since the driver was originally tested on that board https://github.com/torvalds/linux/blob/e53642b87a4f4b03a8d7e5f8507fc3cd0c595ea6/arch/arm/boot/dts/qcom/qcom-apq8060-dragonboard.dts#L67-L79 > Hope this is useful > > Konrad Thanks, Antony K. S. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-30 16:57 ` Antony Kurniawan Soemardi @ 2025-10-31 9:00 ` Konrad Dybcio 2025-11-01 9:25 ` Dmitry Baryshkov 0 siblings, 1 reply; 13+ messages in thread From: Konrad Dybcio @ 2025-10-31 9:00 UTC (permalink / raw) To: Antony Kurniawan Soemardi, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Dmitry Baryshkov Cc: linux-arm-msm, linux-iio, linux-kernel On 10/30/25 5:57 PM, Antony Kurniawan Soemardi wrote: > On 10/28/2025 4:44 PM, Konrad Dybcio wrote: >> On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: >>> On msm8960 phones, the XOADC driver was using incorrect calibration >>> values: >>> absolute calibration dx = 625000 uV, dy = 4 units >>> ratiometric calibration dx = 1800, dy = -29041 units >>> >>> As a result, reading from the IIO bus returned unexpected results: >>> in_voltage_7 (USB_VBUS): 0 >>> in_voltage_10 (125V): 0 >>> >>> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) >>> from the predefined channels. Additionally, the downstream code always >>> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. >>> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling >>> those bits caused calibration errors too, so they were removed. >>> >>> With these fixes, calibration now uses the correct values: >>> absolute calibration dx = 625000 uV, dy = 6307 units >>> ratiometric calibration dx = 1800, dy = 18249 units >>> >>> Reading from the IIO bus now returns expected results: >>> in_voltage_7 (USB_VBUS): 4973836 >>> in_voltage_10 (125V): 1249405 >>> >>> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 >>> >>> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> >>> --- >>> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- >>> 1 file changed, 6 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 >>> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, >>> goto unlock; >>> /* Decimation factor */ >>> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | >>> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >>> + ret = regmap_update_bits(adc->map, >>> + ADC_ARB_USRP_DIG_PARAM, >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, >> The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 >> for a "1K" (1/1024?) ratio, although a comment in this file suggests >> BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be >> surprised if that is the case >> >> The previously set bits are a field called DECI_SEL but are otherwise left >> undescribed > > So, do you think we can leave the BIT(0) and BIT(1) as is? I have a feeling > that if they aren't set, these changes might prevent the APQ8060 Dragonboard > from reading the cm3605 sensor? or maybe not? > > I mean this one, since the driver was originally tested on that board > https://github.com/torvalds/linux/blob/e53642b87a4f4b03a8d7e5f8507fc3cd0c595ea6/arch/arm/boot/dts/qcom/qcom-apq8060-dragonboard.dts#L67-L79 +Dmitry would you have that (or similar) board in your museum? Konrad ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-10-31 9:00 ` Konrad Dybcio @ 2025-11-01 9:25 ` Dmitry Baryshkov 2026-01-11 17:31 ` Antony Kurniawan Soemardi 0 siblings, 1 reply; 13+ messages in thread From: Dmitry Baryshkov @ 2025-11-01 9:25 UTC (permalink / raw) To: Konrad Dybcio Cc: Antony Kurniawan Soemardi, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, linux-arm-msm, linux-iio, linux-kernel On Fri, Oct 31, 2025 at 10:00:25AM +0100, Konrad Dybcio wrote: > On 10/30/25 5:57 PM, Antony Kurniawan Soemardi wrote: > > On 10/28/2025 4:44 PM, Konrad Dybcio wrote: > >> On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: > >>> On msm8960 phones, the XOADC driver was using incorrect calibration > >>> values: > >>> absolute calibration dx = 625000 uV, dy = 4 units > >>> ratiometric calibration dx = 1800, dy = -29041 units > >>> > >>> As a result, reading from the IIO bus returned unexpected results: > >>> in_voltage_7 (USB_VBUS): 0 > >>> in_voltage_10 (125V): 0 > >>> > >>> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) > >>> from the predefined channels. Additionally, the downstream code always > >>> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. > >>> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling > >>> those bits caused calibration errors too, so they were removed. > >>> > >>> With these fixes, calibration now uses the correct values: > >>> absolute calibration dx = 625000 uV, dy = 6307 units > >>> ratiometric calibration dx = 1800, dy = 18249 units > >>> > >>> Reading from the IIO bus now returns expected results: > >>> in_voltage_7 (USB_VBUS): 4973836 > >>> in_voltage_10 (125V): 1249405 > >>> > >>> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 > >>> > >>> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> > >>> --- > >>> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- > >>> 1 file changed, 6 insertions(+), 4 deletions(-) > >>> > >>> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > >>> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 > >>> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c > >>> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > >>> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, > >>> goto unlock; > >>> /* Decimation factor */ > >>> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, > >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | > >>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | > >>> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); > >>> + ret = regmap_update_bits(adc->map, > >>> + ADC_ARB_USRP_DIG_PARAM, > >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | > >>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, > >> The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 > >> for a "1K" (1/1024?) ratio, although a comment in this file suggests > >> BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be > >> surprised if that is the case > >> > >> The previously set bits are a field called DECI_SEL but are otherwise left > >> undescribed > > > > So, do you think we can leave the BIT(0) and BIT(1) as is? I have a feeling > > that if they aren't set, these changes might prevent the APQ8060 Dragonboard > > from reading the cm3605 sensor? or maybe not? > > > > I mean this one, since the driver was originally tested on that board > > https://github.com/torvalds/linux/blob/e53642b87a4f4b03a8d7e5f8507fc3cd0c595ea6/arch/arm/boot/dts/qcom/qcom-apq8060-dragonboard.dts#L67-L79 > > +Dmitry would you have that (or similar) board in your museum? I do, but I sadly I didn't test it lately (nor do I remember if I have sensors board or not). I can try testing it next week, if I have time. -- With best wishes Dmitry ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2025-11-01 9:25 ` Dmitry Baryshkov @ 2026-01-11 17:31 ` Antony Kurniawan Soemardi 2026-01-15 7:32 ` Dmitry Baryshkov 0 siblings, 1 reply; 13+ messages in thread From: Antony Kurniawan Soemardi @ 2026-01-11 17:31 UTC (permalink / raw) To: Dmitry Baryshkov, Konrad Dybcio Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, linux-arm-msm, linux-iio, linux-kernel On 11/1/2025 4:25 PM, Dmitry Baryshkov wrote: > On Fri, Oct 31, 2025 at 10:00:25AM +0100, Konrad Dybcio wrote: >> On 10/30/25 5:57 PM, Antony Kurniawan Soemardi wrote: >>> On 10/28/2025 4:44 PM, Konrad Dybcio wrote: >>>> On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: >>>>> On msm8960 phones, the XOADC driver was using incorrect calibration >>>>> values: >>>>> absolute calibration dx = 625000 uV, dy = 4 units >>>>> ratiometric calibration dx = 1800, dy = -29041 units >>>>> >>>>> As a result, reading from the IIO bus returned unexpected results: >>>>> in_voltage_7 (USB_VBUS): 0 >>>>> in_voltage_10 (125V): 0 >>>>> >>>>> The issue was caused by not setting the ratiometric scale (amux_ip_rsv) >>>>> from the predefined channels. Additionally, the downstream code always >>>>> set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. >>>>> That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling >>>>> those bits caused calibration errors too, so they were removed. >>>>> >>>>> With these fixes, calibration now uses the correct values: >>>>> absolute calibration dx = 625000 uV, dy = 6307 units >>>>> ratiometric calibration dx = 1800, dy = 18249 units >>>>> >>>>> Reading from the IIO bus now returns expected results: >>>>> in_voltage_7 (USB_VBUS): 4973836 >>>>> in_voltage_10 (125V): 1249405 >>>>> >>>>> [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 >>>>> >>>>> Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> >>>>> --- >>>>> drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- >>>>> 1 file changed, 6 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>>>> index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 >>>>> --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>>>> +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c >>>>> @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, >>>>> goto unlock; >>>>> /* Decimation factor */ >>>>> - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, >>>>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | >>>>> - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | >>>>> - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); >>>>> + ret = regmap_update_bits(adc->map, >>>>> + ADC_ARB_USRP_DIG_PARAM, >>>>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | >>>>> + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, >>>> The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 >>>> for a "1K" (1/1024?) ratio, although a comment in this file suggests >>>> BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be >>>> surprised if that is the case >>>> >>>> The previously set bits are a field called DECI_SEL but are otherwise left >>>> undescribed >>> So, do you think we can leave the BIT(0) and BIT(1) as is? I have a feeling >>> that if they aren't set, these changes might prevent the APQ8060 Dragonboard >>> from reading the cm3605 sensor? or maybe not? >>> >>> I mean this one, since the driver was originally tested on that board >>> https://github.com/torvalds/linux/blob/e53642b87a4f4b03a8d7e5f8507fc3cd0c595ea6/arch/arm/boot/dts/qcom/qcom-apq8060-dragonboard.dts#L67-L79 >> +Dmitry would you have that (or similar) board in your museum? > I do, but I sadly I didn't test it lately (nor do I remember if I have > sensors board or not). I can try testing it next week, if I have time. > Hi Dmitry, I wanted to follow up and ask whether you’ve had a chance to test the APQ8060 DragonBoard though? (Also happy new year! Eh, it's 12 days late...) Thanks, ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values 2026-01-11 17:31 ` Antony Kurniawan Soemardi @ 2026-01-15 7:32 ` Dmitry Baryshkov 0 siblings, 0 replies; 13+ messages in thread From: Dmitry Baryshkov @ 2026-01-15 7:32 UTC (permalink / raw) To: Antony Kurniawan Soemardi Cc: Konrad Dybcio, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, linux-arm-msm, linux-iio, linux-kernel On Sun, Jan 11, 2026 at 05:31:45PM +0000, Antony Kurniawan Soemardi wrote: > On 11/1/2025 4:25 PM, Dmitry Baryshkov wrote: > > On Fri, Oct 31, 2025 at 10:00:25AM +0100, Konrad Dybcio wrote: > > > On 10/30/25 5:57 PM, Antony Kurniawan Soemardi wrote: > > > > On 10/28/2025 4:44 PM, Konrad Dybcio wrote: > > > > > On 10/27/25 6:29 PM, Antony Kurniawan Soemardi wrote: > > > > > > On msm8960 phones, the XOADC driver was using incorrect calibration > > > > > > values: > > > > > > absolute calibration dx = 625000 uV, dy = 4 units > > > > > > ratiometric calibration dx = 1800, dy = -29041 units > > > > > > > > > > > > As a result, reading from the IIO bus returned unexpected results: > > > > > > in_voltage_7 (USB_VBUS): 0 > > > > > > in_voltage_10 (125V): 0 > > > > > > > > > > > > The issue was caused by not setting the ratiometric scale (amux_ip_rsv) > > > > > > from the predefined channels. Additionally, the downstream code always > > > > > > set the ADC_ARB_USRP_DIG_PARAM register to PM8XXX_ADC_ARB_ANA_DIG [1]. > > > > > > That value does not include the SEL_SHIFT0 and SEL_SHIFT1 bits. Enabling > > > > > > those bits caused calibration errors too, so they were removed. > > > > > > > > > > > > With these fixes, calibration now uses the correct values: > > > > > > absolute calibration dx = 625000 uV, dy = 6307 units > > > > > > ratiometric calibration dx = 1800, dy = 18249 units > > > > > > > > > > > > Reading from the IIO bus now returns expected results: > > > > > > in_voltage_7 (USB_VBUS): 4973836 > > > > > > in_voltage_10 (125V): 1249405 > > > > > > > > > > > > [1] https://github.com/LineageOS/android_kernel_sony_msm8960t/blob/93319b1e5aa343ec1c1aabcb028c5e88c7df7c01/drivers/hwmon/pm8xxx-adc.c#L407-L408 > > > > > > > > > > > > Signed-off-by: Antony Kurniawan Soemardi <linux@smankusors.com> > > > > > > --- > > > > > > drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 ++++++---- > > > > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > > > > > > > > > diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > > > > > > index 8555f34036fb13c41ac720dc02c1dc39876e9198..a53d361456ec36b66d258041877bd96ab37838c4 100644 > > > > > > --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c > > > > > > +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c > > > > > > @@ -503,10 +503,11 @@ static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, > > > > > > goto unlock; > > > > > > /* Decimation factor */ > > > > > > - ret = regmap_write(adc->map, ADC_ARB_USRP_DIG_PARAM, > > > > > > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT0 | > > > > > > - ADC_ARB_USRP_DIG_PARAM_SEL_SHIFT1 | > > > > > > - ch->decimation << ADC_DIG_PARAM_DEC_SHIFT); > > > > > > + ret = regmap_update_bits(adc->map, > > > > > > + ADC_ARB_USRP_DIG_PARAM, > > > > > > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE0 | > > > > > > + ADC_ARB_USRP_DIG_PARAM_DEC_RATE1, > > > > > The PM8921 datasheet suggests a single valid value of BIT(5)=1, BIT(6)=0 > > > > > for a "1K" (1/1024?) ratio, although a comment in this file suggests > > > > > BIT(5)|BIT(6) is also valid and corresponds to 1/4096.. I wouldn't be > > > > > surprised if that is the case > > > > > > > > > > The previously set bits are a field called DECI_SEL but are otherwise left > > > > > undescribed > > > > So, do you think we can leave the BIT(0) and BIT(1) as is? I have a feeling > > > > that if they aren't set, these changes might prevent the APQ8060 Dragonboard > > > > from reading the cm3605 sensor? or maybe not? > > > > > > > > I mean this one, since the driver was originally tested on that board > > > > https://github.com/torvalds/linux/blob/e53642b87a4f4b03a8d7e5f8507fc3cd0c595ea6/arch/arm/boot/dts/qcom/qcom-apq8060-dragonboard.dts#L67-L79 > > > +Dmitry would you have that (or similar) board in your museum? > > I do, but I sadly I didn't test it lately (nor do I remember if I have > > sensors board or not). I can try testing it next week, if I have time. > > > Hi Dmitry, I wanted to follow up and ask whether you’ve had a chance to test > the APQ8060 DragonBoard though? No, after reshuffling of the lab it's still in the box, sorry. > > (Also happy new year! Eh, it's 12 days late...) > > Thanks, -- With best wishes Dmitry ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-01-15 7:32 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-27 17:29 [PATCH 0/2] iio: adc: qcom-pm8xxx-xoadc improvements Antony Kurniawan Soemardi 2025-10-27 17:29 ` [PATCH 1/2] iio: adc: qcom-pm8xxx-xoadc: add support for reading channel labels Antony Kurniawan Soemardi 2025-10-28 9:55 ` Andy Shevchenko 2025-10-27 17:29 ` [PATCH 2/2] iio: adc: qcom-pm8xxx-xoadc: fix incorrect calibration values Antony Kurniawan Soemardi 2025-10-27 18:35 ` David Lechner 2025-10-27 19:53 ` Antony Kurniawan Soemardi 2025-10-27 20:36 ` David Lechner 2025-10-28 9:44 ` Konrad Dybcio 2025-10-30 16:57 ` Antony Kurniawan Soemardi 2025-10-31 9:00 ` Konrad Dybcio 2025-11-01 9:25 ` Dmitry Baryshkov 2026-01-11 17:31 ` Antony Kurniawan Soemardi 2026-01-15 7:32 ` Dmitry Baryshkov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox