]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
power: supply: Fix logic checking if system is running from battery
authorMario Limonciello <mario.limonciello@amd.com>
Tue, 16 May 2023 18:25:40 +0000 (13:25 -0500)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Mon, 2 Oct 2023 15:19:04 +0000 (17:19 +0200)
commite0f63c16a5bf3b628816bedacd3ac31d5aaa8dba
tree4a33bb023adda38cea61ee54feda9eb551422f98
parentc8c5ccc87d5f36ea5fa7930ab0a0c552a9623cab
power: supply: Fix logic checking if system is running from battery

BugLink: https://bugs.launchpad.net/bugs/2033931
[ Upstream commit 95339f40a8b652b5b1773def31e63fc53c26378a ]

The logic used for power_supply_is_system_supplied() counts all power
supplies and assumes that the system is running from AC if there is
either a non-battery power-supply reporting to be online or if no
power-supplies exist at all.

The second rule is for desktop systems, that don't have any
battery/charger devices. These systems will incorrectly report to be
powered from battery once a device scope power-supply is registered
(e.g. a HID device), since these power-supplies increase the counter.

Apart from HID devices, recent dGPUs provide UCSI power supplies on a
desktop systems. The dGPU by default doesn't have anything plugged in so
it's 'offline'. This makes power_supply_is_system_supplied() return 0
with a count of 1 meaning all drivers that use this get a wrong judgement.

To fix this case adjust the logic to also examine the scope of the power
supply. If the power supply is deemed a device power supply, then don't
count it.

Cc: Evan Quan <Evan.Quan@amd.com>
Suggested-by: Lijo Lazar <Lijo.Lazar@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/power/supply/power_supply_core.c