power: supply: core: implement extension API
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 11 Dec 2024 19:57:55 +0000 (20:57 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sat, 14 Dec 2024 03:22:05 +0000 (04:22 +0100)
commit6037802bbae892f3ad0c7b4c4faee39b967e32b0
tree8624ee53d43a052e331f822836fad282f3157242
parent57e5a9a85bd03d8cc4992cb2e15ca23450e016c4
power: supply: core: implement extension API

Various drivers, mostly in platform/x86 extend the ACPI battery driver
with additional sysfs attributes to implement more UAPIs than are
exposed through ACPI by using various side-channels, like WMI,
nonstandard ACPI or EC communication.

While the created sysfs attributes look similar to the attributes
provided by the powersupply core, there are various deficiencies:

* They don't show up in uevent payload.
* They can't be queried with the standard in-kernel APIs.
* They don't work with triggers.
* The extending driver has to reimplement all of the parsing,
formatting and sysfs display logic.
* Writing a extension driver is completely different from writing a
normal power supply driver.

This extension API avoids all of these issues.
An extension is just a "struct power_supply_ext" with the same kind of
callbacks as in a normal "struct power_supply_desc".

The API is meant to be used via battery_hook_register(), the same way as
the current extensions.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20241211-power-supply-extensions-v6-1-9d9dc3f3d387@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply.h
drivers/power/supply/power_supply_core.c
drivers/power/supply/power_supply_sysfs.c
include/linux/power_supply.h