Skip to contentSkip to conversation

power: supply: bq27xxx: Report charge full state correctly

PATCH Applied Sicelo A. Mhlongo 2 participants 2 messages Feb 26, 2024 – Feb 27, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: bq27xxx: Report charge full state correctly

When reporting the charging status, the existing code reports the battery as full only when the reported current flowing is exactly 0mA, which is unlikely in practice.

Fix the reporting by giving priority to the battery's full state indication/flag.

Tested on the Nokia N900 with bq27200 fuel gauge.

---
 drivers/power/supply/bq27xxx_battery.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/power/supply/bq27xxx_battery.c +6 -9
index 1c4a9d137744..810f6eb468ad 100644
@@ -1816,17 +1816,14 @@ static int bq27xxx_battery_current_and_status(
 		val_curr->intval = curr;
 
 	if (val_status) {
-		if (curr > 0) {
+		if (bq27xxx_battery_is_full(di, flags))
+			val_status->intval = POWER_SUPPLY_STATUS_FULL;
+		else if (curr > 0)
 			val_status->intval = POWER_SUPPLY_STATUS_CHARGING;
-		} else if (curr < 0) {
+		else if (curr < 0)
 			val_status->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-		} else {
-			if (bq27xxx_battery_is_full(di, flags))
-				val_status->intval = POWER_SUPPLY_STATUS_FULL;
-			else
-				val_status->intval =
-					POWER_SUPPLY_STATUS_NOT_CHARGING;
-		}
+		else
+			val_status->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 	}
 
 	return 0;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Sicelo A. Mhlongo

When reporting the charging status, the existing code reports the battery as full only when the reported current flowing is exactly 0mA, which is unlikely in practice.

Fix the reporting by giving priority to the battery's full state indication/flag.

[...]

Applied, thanks!

[1/1] power: supply: bq27xxx: Report charge full state correctly

      commit: 8fbb11162504f2de167a8ccd2d2c55a849d2c5ea

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>