power: supply: extension API
From: | Thomas Weißschuh <linux-AT-weissschuh.net> | |
To: | Sebastian Reichel <sre-AT-kernel.org>, Armin Wolf <W_Armin-AT-gmx.de>, Hans de Goede <hdegoede-AT-redhat.com>, Thomas Weißschuh <thomas-AT-weissschuh.net>, Benson Leung <bleung-AT-chromium.org>, Guenter Roeck <groeck-AT-chromium.org> | |
Subject: | [PATCH v4 0/9] power: supply: extension API | |
Date: | Mon, 11 Nov 2024 22:40:02 +0100 | |
Message-ID: | <20241111-power-supply-extensions-v4-0-7240144daa8e@weissschuh.net> | |
Cc: | linux-pm-AT-vger.kernel.org, linux-kernel-AT-vger.kernel.org, chrome-platform-AT-lists.linux.dev, Thomas Weißschuh <linux-AT-weissschuh.net>, Sebastian Reichel <sebastian.reichel-AT-collabora.com> | |
Archive-link: | Article |
Introduce a mechanism for drivers to extend the properties implemented by a power supply. Motivation ---------- 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. * ~Properties can not be properly overriden.~ (Overriding is now explicitly forbidden) The proposed 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. When testing, please enable lockdep to make sure the locking is correct. Contents -------- * Patch 1 to 6 are preparation patches. * Patch 7 implements the extension API itself. * Patch 8 adds extension support to test_power.c * Patch 9 converts the in-tree cros_charge-control driver to the extension API. Open issues ----------- * As this is only useful with the hooks of CONFIG_ACPI_BATTERY, should it also be gated behind this or another config? * Is an rw_semaphore acceptable? [0] https://lore.kernel.org/lkml/20240528-cros_ec-charge-cont... Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- Changes in v4: - Drop RFC state - Integrate locking commit - Reregister hwmon device - Link to v3: https://lore.kernel.org/r/20240904-power-supply-extension... Changes in v3: - Make naming more consistent - Readd locking - Allow multiple active extensions - Allow passing a "void *ext_data" when registering - Switch example driver from system76 to cros_charge-control - Link to v2: https://lore.kernel.org/r/20240608-power-supply-extension... Changes in v2: - Drop locking patch, let's figure out the API first - Allow registration of multiple extensions - Pass extension to extension callbacks as parameter - Disallow property overlap between extensions and core psy - Drop system76/pdx86 maintainers, as the system76 changes are only RFC state anyways - Link to v1: https://lore.kernel.org/r/20240606-power-supply-extension... --- Thomas Weißschuh (9): power: supply: sysfs: print single value in uevent for POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR power: supply: core: rename psy_has_property() to psy_desc_has_property() power: supply: core: introduce power_supply_has_property() power: supply: hwmon: prepare for power supply extensions power: supply: sysfs: prepare for power supply extensions power: supply: sysfs: rework uevent property loop power: supply: core: implement extension API power: supply: test-power: implement a power supply extension power: supply: cros_charge-control: use power_supply extensions drivers/power/supply/cros_charge-control.c | 205 +++++++++++------------------ drivers/power/supply/power_supply.h | 16 +++ drivers/power/supply/power_supply_core.c | 175 ++++++++++++++++++++++-- drivers/power/supply/power_supply_hwmon.c | 50 ++++--- drivers/power/supply/power_supply_sysfs.c | 85 ++++++------ drivers/power/supply/test_power.c | 102 ++++++++++++++ include/linux/power_supply.h | 32 +++++ 7 files changed, 456 insertions(+), 209 deletions(-) --- base-commit: 83bce34420eaf91506957703bf9a31d8581ed6cb change-id: 20240602-power-supply-extensions-07d949f509d9 Best regards, -- Thomas Weißschuh <linux@weissschuh.net>