Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH RFC v3 0/9] power: supply: extension API
@ 2024-09-04 19:25 Thomas Weißschuh
  2024-09-04 19:25 ` [PATCH RFC v3 1/9] power: supply: core: rename psy_has_property() to psy_desc_has_property() Thomas Weißschuh
                   ` (8 more replies)
  0 siblings, 9 replies; 24+ messages in thread
From: Thomas Weißschuh @ 2024-09-04 19:25 UTC (permalink / raw)
  To: Sebastian Reichel, Armin Wolf, Hans de Goede
  Cc: linux-pm, linux-kernel, Thomas Weißschuh

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 5 are preparation patches.
* Patch 6 implements the extension API itself.
* Patch 7 implements a locking scheme for the extension API.
* 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
-----------

* Newly registered properties will not show up in hwmon.
  To do that properly would require some changes in the hwmon core.
  As far as I know, no current driver would extend the hwmon properties anyways.
* 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-control-v2-0-81fb27e1cff4@weissschuh.net/

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
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-extensions-v2-0-2dcd35b012ad@weissschuh.net

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-extensions-v1-0-b45669290bdc@weissschuh.net

---
Thomas Weißschuh (9):
      power: supply: core: rename psy_has_property() to psy_desc_has_property()
      power: supply: core: register thermal zone for battery
      power: supply: hwmon: register battery properties
      power: supply: sysfs: register battery properties
      power: supply: sysfs: rework uevent property loop
      power: supply: core: implement extension API
      power: supply: core: add locking around extension access
      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 | 207 +++++++++++------------------
 drivers/power/supply/power_supply.h        |  18 +++
 drivers/power/supply/power_supply_core.c   | 169 +++++++++++++++++++++--
 drivers/power/supply/power_supply_hwmon.c  |  52 ++++----
 drivers/power/supply/power_supply_leds.c   |   2 +
 drivers/power/supply/power_supply_sysfs.c  |  65 +++++----
 drivers/power/supply/test_power.c          | 104 +++++++++++++++
 include/linux/power_supply.h               |  33 +++++
 8 files changed, 453 insertions(+), 197 deletions(-)
---
base-commit: d8abb73f584772eaafa95a447c90f1c02dba0dec
change-id: 20240602-power-supply-extensions-07d949f509d9

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-09-16 10:58 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 19:25 [PATCH RFC v3 0/9] power: supply: extension API Thomas Weißschuh
2024-09-04 19:25 ` [PATCH RFC v3 1/9] power: supply: core: rename psy_has_property() to psy_desc_has_property() Thomas Weißschuh
2024-09-04 19:56   ` Hans de Goede
2024-09-14  9:30   ` Sebastian Reichel
2024-09-04 19:25 ` [PATCH RFC v3 2/9] power: supply: core: register thermal zone for battery Thomas Weißschuh
2024-09-04 19:56   ` Hans de Goede
2024-09-14  9:29   ` Sebastian Reichel
2024-09-14  9:55     ` Thomas Weißschuh
2024-09-04 19:25 ` [PATCH RFC v3 3/9] power: supply: hwmon: register battery properties Thomas Weißschuh
2024-09-04 19:57   ` Hans de Goede
2024-09-14  9:35   ` Sebastian Reichel
2024-09-04 19:25 ` [PATCH RFC v3 4/9] power: supply: sysfs: " Thomas Weißschuh
2024-09-04 19:57   ` Hans de Goede
2024-09-14  9:43   ` Sebastian Reichel
2024-09-04 19:25 ` [PATCH RFC v3 5/9] power: supply: sysfs: rework uevent property loop Thomas Weißschuh
2024-09-04 19:58   ` Hans de Goede
2024-09-14  9:59   ` Sebastian Reichel
2024-09-04 19:25 ` [PATCH RFC v3 6/9] power: supply: core: implement extension API Thomas Weißschuh
2024-09-14 10:50   ` Sebastian Reichel
2024-09-14 14:25     ` Thomas Weißschuh
2024-09-16 10:58       ` Sebastian Reichel
2024-09-04 19:25 ` [PATCH RFC v3 7/9] power: supply: core: add locking around extension access Thomas Weißschuh
2024-09-04 19:25 ` [PATCH RFC v3 8/9] power: supply: test-power: implement a power supply extension Thomas Weißschuh
2024-09-04 19:25 ` [PATCH RFC v3 9/9] power: supply: cros_charge-control: use power_supply extensions Thomas Weißschuh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox