power: supply: bq27xxx: Report charge full state correctly
authorSicelo A. Mhlongo <absicsz@gmail.com>
Mon, 26 Feb 2024 19:37:22 +0000 (21:37 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 27 Feb 2024 20:13:11 +0000 (21:13 +0100)
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.

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
Link: https://lore.kernel.org/r/20240226193722.2173624-1-absicsz@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/bq27xxx_battery.c

index 363428530ee604013c2f9569530fe0995f376c43..abca5683446862551bf83b5f2fdc6a67104c57f0 100644 (file)
@@ -1828,17 +1828,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;