OSDN Git Service

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)
committerSebastian Reichel <sre@kernel.org>
Tue, 16 May 2023 21:02:56 +0000 (23:02 +0200)
commit95339f40a8b652b5b1773def31e63fc53c26378a
tree1d96f1a0640079b67c823665922a17e280a8718b
parent4cbb0d358883a27e432714b5256f0362946f5e25
power: supply: Fix logic checking if system is running from battery

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>
drivers/power/supply/power_supply_core.c