power: supply: bq27xxx: make status more robust
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>
Wed, 3 Mar 2021 09:54:20 +0000 (10:54 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 15 Mar 2021 01:26:03 +0000 (02:26 +0100)
commitc3a6d6a1dfc8a9bf12d79a0b1a30cb24c92a2ddf
treebd00087ebbc263c7ecf368e06729a3aa247b09dc
parentc4d57c22ac65bd503716062a06fad55a01569cac
power: supply: bq27xxx: make status more robust

There are multiple issues in bq27xxx_battery_status():

- On BQ28Q610 is was observed that the "full" flag may be set even while
  the battery is charging or discharging. With the current logic to make
  "full" override everything else, it look a very long time (>20min) for
  the status to change from "full" to "discharging" after unplugging the
  supply on a device with low power consumption
- The POWER_SUPPLY_STATUS_NOT_CHARGING check depends on
  power_supply_am_i_supplied(), which will not work when the supply
  doesn't exist as a separate device known to Linux

We can solve both issues by deriving the status from the current instead
of the flags field. The flags are now only used to distinguish "full"
from "not charging", and to determine the sign of the current on
BQ27XXX_O_ZERO devices.

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/bq27xxx_battery.c