]> git.itanic.dy.fi Git - linux-stable/commit
power: supply: bq27xxx: Ensure power_supply_changed() is called on current sign changes
authorHans de Goede <hdegoede@redhat.com>
Sat, 15 Apr 2023 18:23:37 +0000 (20:23 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 13:17:25 +0000 (14:17 +0100)
commit1f40730781865ff93642e9be1e5b6eaff624d601
tree2c40db8e852d1d2cd5bb5bd0e02defe04a89a83a
parent39f6edb6ad3bf157a9cf90136026515c7aac9dd3
power: supply: bq27xxx: Ensure power_supply_changed() is called on current sign changes

commit 939a116142012926e25de0ea6b7e2f8d86a5f1b6 upstream.

On gauges where the current register is signed, there is no charging
flag in the flags register. So only checking flags will not result
in power_supply_changed() getting called when e.g. a charger is plugged
in and the current sign changes from negative (discharging) to
positive (charging).

This causes userspace's notion of the status to lag until userspace
does a poll.

And when a power_supply_leds.c LED trigger is used to indicate charging
status with a LED, this LED will lag until the capacity percentage
changes, which may take many minutes (because the LED trigger only is
updated on power_supply_changed() calls).

Fix this by calling bq27xxx_battery_current_and_status() on gauges with
a signed current register and checking if the status has changed.

Fixes: 297a533b3e62 ("bq27x00: Cache battery registers")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/power/supply/bq27xxx_battery.c
include/linux/power/bq27xxx_battery.h