mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Alexandru Andrieș via B4 Relay" <devnull+alex.andries.aa.gmail.com@kernel.org>
To: Sebastian Reichel <sre@kernel.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>
Cc: "Bjorn Andersson" <andersson@kernel.org>,
	"Konrad Dybcio" <konrad.dybcio@oss.qualcomm.com>,
	"Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>,
	linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Sebastian Reichel" <sebastian.reichel@collabora.com>,
	stable@vger.kernel.org,
	"Alexandru Andrieș" <alex.andries.aa@gmail.com>
Subject: [PATCH 3/3] power: supply: qcom_battmgr: fix negative temperature values
Date: Thu, 19 Nov 2026 00:16:52 +0100	[thread overview]
Message-ID: <20261119-upstream-qcom-battmgr-fixes-v1-v1-3-ca83700c08c1@gmail.com> (raw)
In-Reply-To: <20261119-upstream-qcom-battmgr-fixes-v1-v1-0-ca83700c08c1@gmail.com>

From: Alexandru Andrieș <alex.andries.aa@gmail.com>

Firmware reports battery temperature in signed hundredths of a degree
Celsius, scaled to tenths of a degree for POWER_SUPPLY_PROP_TEMP.
Passing it as unsigned int to DIV_ROUND_CLOSEST(..., 10) in both
qcom_battmgr_sc8280xp_convert_temp() and qcom_battmgr_sm8350_callback()
turns sub-zero values (e.g. -5.00 C, 0xfffffe0c) into 429496680 instead
of -50.

Change status.temperature and qcom_battmgr_sc8280xp_convert_temp() to
int, and cast the SM8350 BATT_TEMP payload to s32 before dividing.

Tested at 35.0 C on a Xiaomi MIX 4 (SM8350); the SC8280XP path and
sub-zero temperatures were not hardware-tested.

Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply")
Cc: stable@vger.kernel.org
Signed-off-by: Alexandru Andrieș <alex.andries.aa@gmail.com>
---
 drivers/power/supply/qcom_battmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/qcom_battmgr.c b/drivers/power/supply/qcom_battmgr.c
index 83e67d22c432..98b658ff6beb 100644
--- a/drivers/power/supply/qcom_battmgr.c
+++ b/drivers/power/supply/qcom_battmgr.c
@@ -278,7 +278,7 @@ struct qcom_battmgr_status {
 	int power_now;
 	unsigned int voltage_now;
 	unsigned int voltage_ocv;
-	unsigned int temperature;
+	int temperature;
 	unsigned int resistance;
 	unsigned int soh_percent;
 
@@ -1250,7 +1250,7 @@ static unsigned int qcom_battmgr_sc8280xp_parse_technology(const char *chemistry
 	return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
 }
 
-static unsigned int qcom_battmgr_sc8280xp_convert_temp(unsigned int temperature)
+static int qcom_battmgr_sc8280xp_convert_temp(int temperature)
 {
 	return DIV_ROUND_CLOSEST(temperature, 10);
 }
@@ -1467,7 +1467,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,
 			break;
 		case BATT_TEMP:
 			val = le32_to_cpu(resp->intval.value);
-			battmgr->status.temperature = DIV_ROUND_CLOSEST(val, 10);
+			battmgr->status.temperature = DIV_ROUND_CLOSEST((s32)val, 10);
 			break;
 		case BATT_TECHNOLOGY:
 			battmgr->info.technology = le32_to_cpu(resp->intval.value);

-- 
2.56.1



      parent reply	other threads:[~2026-11-18 23:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:16 [PATCH 0/3] power: supply: qcom_battmgr: fix SM8350/SM8550 units, acks, and negative temp Alexandru Andrieș via B4 Relay
2026-11-18 23:16 ` [PATCH 1/3] power: supply: qcom_battmgr: set mAh unit for SM8350 and SM8550 Alexandru Andrieș via B4 Relay
2026-12-02  2:45   ` Sebastian Reichel
2026-11-18 23:16 ` [PATCH 2/3] power: supply: qcom_battmgr: complete ack on callback payload errors Alexandru Andrieș via B4 Relay
2026-11-18 23:16 ` Alexandru Andrieș via B4 Relay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119-upstream-qcom-battmgr-fixes-v1-v1-3-ca83700c08c1@gmail.com \
    --to=devnull+alex.andries.aa.gmail.com@kernel.org \
    --cc=alex.andries.aa@gmail.com \
    --cc=andersson@kernel.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=sre@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®