From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1D6A280A5A for ; Fri, 10 Oct 2025 11:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760095434; cv=none; b=oyIlkuqMg7Lrcwvd6+kLK3hXrv18Y+Q+yC4RcT7iBhzoehwOhFazKshzLInvAou0o1ctv2yeoO2dA9pcFOQBbVH/VQgE772oFpzdrsO25uikgrXaEc53ugmcI7j/5XnClOGyI6Xkak9gwq4U6sNvSllyNQ1sSvXAYGZrG1UrEgs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760095434; c=relaxed/simple; bh=H5LgljmnkNjvXD6n5IG7Ap4WWlw3CGfBh7hhGFd2RjQ=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=bE8eRO5t+Be3ZzPp4BdHEIZ2Zv9VYhe0PzLfIO/g+TxBiLlTf0uPPNAxcClfDzmNiZas4ahA9JaYp5VpsyfDdEWlfInvXVOIH6kuX44kHxuTiU+vEboBnc4Qd74iAWoNC1pHn1e0QzITN9lXwtWqIXXSIlNN28ydlGDbMDRHc2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fairphone.com; spf=pass smtp.mailfrom=fairphone.com; dkim=pass (2048-bit key) header.d=fairphone.com header.i=@fairphone.com header.b=aG3Gy6mi; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fairphone.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fairphone.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fairphone.com header.i=@fairphone.com header.b="aG3Gy6mi" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-b4f323cf89bso343182866b.2 for ; Fri, 10 Oct 2025 04:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fairphone.com; s=fair; t=1760095430; x=1760700230; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=3+WH0817Ps1vnRuu5RpMwf3DsYHgJQPb6FKq+YW7fXM=; b=aG3Gy6mievSarLUblY8MnPhoFwA24TWyRie0zu0FDAw72b3CC3USj7pflnz8rmOoi7 mJcxBfpQanJv0YRDLT+V9CkoIbF7yMt+rBME24l+T8OZkRWhGW5ciFY70rrXo5l5yQZe enCfzlLwok9bR9N66/5cwlodlNyvu35wyMiZ74c94v5Hvwem9h3daWgXiWErihs27qMm eLGwo8Qi8N9nUtqhKUGQqgEYl1GQe0Vfwiow6YX0UxYznpR9WMno93yOoa8T+urHQbI2 Xo9hyd5Hv/4BHJwkdUYehe5nZj/nMv62ip/xqGijTdZ0WJ93gYyk55Zlrv22zezcYCLN PIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760095430; x=1760700230; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3+WH0817Ps1vnRuu5RpMwf3DsYHgJQPb6FKq+YW7fXM=; b=QIcM8mlJ5GBEwLYWP+kDSk7IeBNa3On9iXyJ+tAWNdB96j63jtF5kBEzmT9DtIK0r7 5mUiYomsOpBETXFBEd6R7eO5KM0lgX+FcqCG9UmtQNPe45jVdNdwgIlgCf6rv4tbFwxJ w1KptAUoFWYDs2uM+6PEsAUxvwzEj696jOFbpQloClaPPaaf7f7HNb4dNUPmmOjC9umt Fuv2J91LATnRgTZuLINHMdSy+n+kSePvOhJRR/1fZ9aMm3lO/AKAIw75llD6lCyQuWI3 5v4Nz1uwRe90egxiEzSbAQvdzHWjkb6VXABxijpFJen3fqUuz+IlyBG/oj2/37Re3EM8 W5DQ== X-Forwarded-Encrypted: i=1; AJvYcCV3vhQnzNh02Krx3Wm9ll2VOYV4ARNCilyRVK6+V6kMFr3E16pZb8aPlBrOJllYeYpipItKcrMq4xGX@vger.kernel.org X-Gm-Message-State: AOJu0YyVctC5xtCSvrOKgRqoC7cUvBIHxkdxLGx/5aTFJIWFzSDaNA/s QhnHEh6AyGktCgvY1oT/70UIn8NkPgivl6p+ZohminLKrvH2kTvKhRMPYYC/m+HOLYA= X-Gm-Gg: ASbGncv4jkMMn6Vj+p6QKVvkiOBdqbUCo0ibzMX6f/1zIV62IvknHI4NRzaFGMgtA0w atJ9ZHmofqNyIZuY13Yp2+cc50jQegQgrIhliTfMJXo+wnFowuOv9kPBbIZTkZNghcgvKAYTII2 +CyhYQAZK3kn5tkU6XiVROpbZXSmSRJ3HgTM+bnBXYG9kHTCcH4SgbBJCyfkcv1Q2gQbgy1l1sf /JIlkgU3uGw5Y2koD7npqb2QHAlqw2WMu9EB0Z772LI3KzJKU1lFFLV70kk9uSUEajNfDKnDRsi qnOWmFZMD1blC6BI134v2bUynkoAHBkXbbkJOvuUFO/F+rHodchvRQfcaH5KOZE35GKYlsPhBIm WqM8hiRmZwyf/EzZyULNmekxOnn/OmC+qLmB932zQLAnAn3Q9uyUZmpUooNQ452+i4jTcfNttKy ugceFdSxWgZXYAo2xJsH02h1iwfDHPvg== X-Google-Smtp-Source: AGHT+IGElPVM7npd0iZwM5139p5UTz/fZNApktIfn5kuKF28780Gdo3rcyMkFKGp/gW1Ak6ZBaU1Dw== X-Received: by 2002:a17:907:86a6:b0:b41:b5df:89bd with SMTP id a640c23a62f3a-b50a9d59b0amr1084043166b.6.1760095430130; Fri, 10 Oct 2025 04:23:50 -0700 (PDT) Received: from [172.16.240.99] (144-178-202-138.static.ef-service.nl. [144.178.202.138]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b55d900bf8csm209905766b.59.2025.10.10.04.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Oct 2025 04:23:49 -0700 (PDT) From: Luca Weiss Subject: [PATCH RFC 0/6] Battery temperature ADC plumbing on Qualcomm platforms Date: Fri, 10 Oct 2025 13:21:58 +0200 Message-Id: <20251010-bat-temp-adc-v1-0-d51ec895dac6@fairphone.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAFbs6GgC/y2MQQ6CMBBFr9LM2jEtpopsSTyAW8OiUwadRQHbS kwId7dRl+//vLdC4iicoFErRF4kyTQWMDsF/uHGO6P0haHSlTXaaCSXMXOY0fUea3s406CptuS hKHPkQd7f3A2ulxa63xj5+Srp/H/IJUY/hSC5Uctxb07QbdsHiZxYBowAAAA= X-Change-ID: 20251010-bat-temp-adc-8539bf0b85bc To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , 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@lists.sr.ht, phone-devel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, Luca Weiss X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760095429; l=3344; i=luca.weiss@fairphone.com; s=20250611; h=from:subject:message-id; bh=H5LgljmnkNjvXD6n5IG7Ap4WWlw3CGfBh7hhGFd2RjQ=; b=KqE1fucyVBMu5pDrzDvyF2Qfx4PQfSPiXKQSTi2ahEjUJqOFT2+W5qVs5saLypTG4U/fyL7it zKBR8HeuueiAJt0bc/93C0oNwirkBkYPymSh2RKCm0IlwVpMQU3uPIs X-Developer-Key: i=luca.weiss@fairphone.com; a=ed25519; pk=O1aw+AAust5lEmgrNJ1Bs7PTY0fEsJm+mdkjExA69q8= 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 (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