power: supply: cpcap-battery: Fix low battery check
authorTony Lindgren <tony@atomide.com>
Sun, 7 Apr 2019 18:12:49 +0000 (11:12 -0700)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 15 Apr 2019 20:51:44 +0000 (22:51 +0200)
We need to check current instead of the charge counter to see if
a charger is connected. The charge counter shows the cumulated value
instead of the current charge current and can be negative or positive.

Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/cpcap-battery.c

index 6887870ba32c38b075145500b173052f45226206..d8855078dc1e9765804b5950d5afdd19a8d689f4 100644 (file)
@@ -562,11 +562,11 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)
 
        switch (d->action) {
        case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW:
-               if (latest->counter_uah >= 0)
+               if (latest->current_ua >= 0)
                        dev_warn(ddata->dev, "Battery low at 3.3V!\n");
                break;
        case CPCAP_BATTERY_IRQ_ACTION_POWEROFF:
-               if (latest->counter_uah >= 0) {
+               if (latest->current_ua >= 0) {
                        dev_emerg(ddata->dev,
                                  "Battery empty at 3.1V, powering off\n");
                        orderly_poweroff(true);