devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/6] Battery temperature ADC plumbing on Qualcomm platforms
@ 2025-10-10 11:21 Luca Weiss
  2025-10-10 11:21 ` [PATCH RFC 1/6] iio: adc: qcom-spmi-adc5: Add battery thermal channels Luca Weiss
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Luca Weiss @ 2025-10-10 11:21 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Laxman Dewangan,
	Bjorn Andersson, Konrad Dybcio, Hans de Goede, Jens Reidel,
	Casey Connolly
  Cc: ~postmarketos/upstreaming, phone-devel, linux-arm-msm, linux-iio,
	linux-kernel, linux-pm, devicetree, Luca Weiss

This is an RFC which implements a potential solution to get battery
temperature readings working on for example smartphones with Qualcomm
SoCs.

The solution chosen in downstream Qualcomm kernels is exposing
ADC_BAT_THERM_PU* in the ADC driver as temperature channels with the
lookup table ("struct vadc_map_pt") for the specific NTC found in a
device's battery patched to adjust the lookup table.

The high level solution proposed here:
* ADC driver provides temperature channel in (milli)volt as IIO channel
* generic-adc-thermal driver converts voltage to temperature based on
  provided lookup table from DT (driver has one IIO channel input, one
  IIO channel output)
* The fuel gauge driver can use that temperature IIO channel to expose
  battery temperature via the power supply device

Variants/alternatives considered:

1. Do not implement IIO device in generic-adc-thermal

Without an IIO channel and using thermal zone directly it becomes more
difficult. You cannot get thermal zone by reference (e.g.
thermal-sensors = <&foo>;). The function thermal_zone_get_zone_by_name()
exists but lookup by name is kinda clunky. Adding by-phandle support
might be possible but is lots of work. It also doesn't really look like
thermal-sensor is really meant to be used by other drivers. E.g.
there's also no "thermal-sensor-names" property to designate passing
multiple thermal sensors. So I believe IIO is a better fitting API for
this.

2. Expose IIO channel as temperature in ADC driver

This would require passing in the temperature lookup table somehow to
the ADC driver via DT. I think this passes too many details about the
hardware that's connected into the ADC driver. While possible, at least
for Qcom ADC there's no precedent yet.

3. Add temperature-lookup-table as property to simple-battery

Since the NTC is a part of the battery pack, adding a
temperature-lookup-table property to simple-battery would make sense
instead of having this lookup table be standalone in the
generic-adc-thermal node. However being able to re-use the existing code
in generic-adc-thermal lead me to the current proposal.

Signed-off-by: Luca Weiss <luca.weiss@fairphone.com>
---
Luca Weiss (6):
      iio: adc: qcom-spmi-adc5: Add battery thermal channels
      dt-bindings: thermal: generic-adc: Document #io-channel-cells
      thermal/drivers/generic-adc: Register as IIO device
      thermal/drivers/generic-adc: Allow probe without TZ registration
      arm64: dts: qcom: pm7250b: Define battery temperature ADC channels
      arm64: dts: qcom: sm7225-fairphone-fp4: Add battery temperature node

 .../bindings/thermal/generic-adc-thermal.yaml      |  4 ++
 arch/arm64/boot/dts/qcom/pm7250b.dtsi              | 24 +++++++
 arch/arm64/boot/dts/qcom/sm7225-fairphone-fp4.dts  | 83 ++++++++++++++++++++++
 drivers/iio/adc/qcom-spmi-adc5.c                   |  6 ++
 drivers/iio/adc/qcom-vadc-common.c                 | 16 +++++
 drivers/thermal/thermal-generic-adc.c              | 68 ++++++++++++++++--
 include/linux/iio/adc/qcom-vadc-common.h           |  3 +
 7 files changed, 198 insertions(+), 6 deletions(-)
---
base-commit: 6063257da111c7639d020c5f15bfb37fb839d8b6
change-id: 20251010-bat-temp-adc-8539bf0b85bc

Best regards,
-- 
Luca Weiss <luca.weiss@fairphone.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-10-12 18:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 11:21 [PATCH RFC 0/6] Battery temperature ADC plumbing on Qualcomm platforms Luca Weiss
2025-10-10 11:21 ` [PATCH RFC 1/6] iio: adc: qcom-spmi-adc5: Add battery thermal channels Luca Weiss
2025-10-10 11:22 ` [PATCH RFC 2/6] dt-bindings: thermal: generic-adc: Document #io-channel-cells Luca Weiss
2025-10-10 11:22 ` [PATCH RFC 3/6] thermal/drivers/generic-adc: Register as IIO device Luca Weiss
2025-10-12 18:41   ` Jonathan Cameron
2025-10-10 11:22 ` [PATCH RFC 4/6] thermal/drivers/generic-adc: Allow probe without TZ registration Luca Weiss
2025-10-10 11:22 ` [PATCH RFC 5/6] arm64: dts: qcom: pm7250b: Define battery temperature ADC channels Luca Weiss
2025-10-10 11:22 ` [PATCH RFC 6/6] arm64: dts: qcom: sm7225-fairphone-fp4: Add battery temperature node Luca Weiss
2025-10-10 14:40 ` [PATCH RFC 0/6] Battery temperature ADC plumbing on Qualcomm platforms Nuno Sá
2025-10-10 20:56 ` David Lechner
2025-10-11  9:52   ` Hans de Goede
2025-10-12 18:24     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).