mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1 1/3] power: supply: sbs-battery: Fix false presence when registers read zero
@ 2025-12-29  8:56 LI Qingwu
  2025-12-29  8:56 ` [PATCH V1 2/3] dt-bindings: power: sbs-battery: add polling interval property LI Qingwu
  2025-12-29  8:56 ` [PATCH V1 3/3] power: supply: sbs-battery: Add optional status monitoring LI Qingwu
  0 siblings, 2 replies; 9+ messages in thread
From: LI Qingwu @ 2025-12-29  8:56 UTC (permalink / raw)
  To: sre, robh, krzk+dt, conor+dt, linux-pm, devicetree, linux-kernel
  Cc: bsp-development.geo, LI Qingwu

Some platforms return zero for all SBS battery registers when the
battery is physically absent, instead of failing with an I2C error.
This causes the driver to incorrectly report the battery as present.

Add a sanity check: when the status register returns zero, also read
voltage and capacity. Only report the battery as present if at least
one of these is non-zero. This prevents false-positive detection on
systems where unpopulated battery slots return all-zero values.

Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/power/supply/sbs-battery.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index 943c82ee978f..9537b692f9fd 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -594,9 +594,17 @@ static int sbs_get_battery_presence_and_health(
 		return ret;
 	}
 
-	if (psp == POWER_SUPPLY_PROP_PRESENT)
+	if (psp == POWER_SUPPLY_PROP_PRESENT) {
 		val->intval = 1; /* battery present */
-	else { /* POWER_SUPPLY_PROP_HEALTH */
+		if (ret == 0) {
+			int voltage = sbs_read_word_data(
+				client, sbs_data[REG_VOLTAGE].addr);
+			int capacity = sbs_read_word_data(
+				client, sbs_data[REG_CAPACITY].addr);
+			if ((voltage == 0) && (capacity == 0))
+				val->intval = 0;
+		}
+	} else { /* POWER_SUPPLY_PROP_HEALTH */
 		if (sbs_bat_needs_calibration(client)) {
 			val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
 		} else {
-- 
2.43.0


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

end of thread, other threads:[~2025-12-30  9:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-29  8:56 [PATCH V1 1/3] power: supply: sbs-battery: Fix false presence when registers read zero LI Qingwu
2025-12-29  8:56 ` [PATCH V1 2/3] dt-bindings: power: sbs-battery: add polling interval property LI Qingwu
2025-12-29  9:16   ` Krzysztof Kozlowski
2025-12-29  9:50     ` LI Qingwu
2025-12-29 12:47       ` Krzysztof Kozlowski
2025-12-30  9:40         ` LI Qingwu
2025-12-30  9:46           ` Krzysztof Kozlowski
2025-12-29 10:36   ` Rob Herring (Arm)
2025-12-29  8:56 ` [PATCH V1 3/3] power: supply: sbs-battery: Add optional status monitoring LI Qingwu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome