public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent
@ 2025-12-31  9:31 LI Qingwu
  2025-12-31  9:31 ` [PATCH 2/2] power: supply: sbs-battery: Add support for polling battery status LI Qingwu
  2026-01-30 21:19 ` [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent Sebastian Reichel
  0 siblings, 2 replies; 4+ messages in thread
From: LI Qingwu @ 2025-12-31  9:31 UTC (permalink / raw)
  To: sre, linux-pm, linux-kernel; +Cc: bsp-development.geo, LI Qingwu

The driver reports battery present when status register read succeeds,
without checking the actual register values. Some systems return all
zeros when no battery is connected, causing false presence detection.

Add validation: when status reads zero, cross-check voltage and capacity.
Report battery absent only if all three registers return zero.

Tested on i.MX 8M Plus platform with SBS-compliant battery.

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

diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index 943c82ee978f..0b9ecfc1f3f7 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -594,9 +594,19 @@ 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, capacity;
+
+			voltage = sbs_read_word_data(
+				client, sbs_data[REG_VOLTAGE].addr);
+			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 related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-30 21:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-31  9:31 [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent LI Qingwu
2025-12-31  9:31 ` [PATCH 2/2] power: supply: sbs-battery: Add support for polling battery status LI Qingwu
2026-01-30 21:37   ` Sebastian Reichel
2026-01-30 21:19 ` [PATCH 1/2] power: supply: sbs-battery: Reject all-zero readings as battery absent Sebastian Reichel

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