mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC v2 0/5] power: supply: extension API
@ 2024-06-08 19:19 Thomas Weißschuh
  2024-06-08 19:19 ` [PATCH RFC v2 1/5] power: supply: sysfs: use power_supply_property_is_writeable() Thomas Weißschuh
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Thomas Weißschuh @ 2024-06-08 19:19 UTC (permalink / raw)
  To: Sebastian Reichel, Armin Wolf
  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 not implemented anymore, can be readded)

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.

For example my upcoming cros_ec charge control driver[0] saves 80 lines
of code with this patchset.

Contents
--------

* Patch 1 and 2 are generic preparation patches, that probably make
  sense without this series.
* Patch 3 implements the extension API itself.
* Patch 4 implements a PoC locking scheme for the extension API.
* Patch 5 adds extension support to test_power.c
* Patch 6 converts the in-tree platform/x86/system76 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?
* Only one extension can be used at a time.
  So far this should be enough, having more would complicate the
  implementation.
* 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 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 (5):
      power: supply: sysfs: use power_supply_property_is_writeable()
      power: supply: core: avoid iterating properties directly
      power: supply: core: implement extension API
      power: supply: test-power: implement a power supply extension
      platform/x86: system76: Use power_supply extension API

 drivers/platform/x86/system76_acpi.c      |  93 ++++++++++++----------
 drivers/power/supply/power_supply.h       |  12 +++
 drivers/power/supply/power_supply_core.c  | 128 ++++++++++++++++++++++++++++--
 drivers/power/supply/power_supply_hwmon.c |  48 +++++------
 drivers/power/supply/power_supply_sysfs.c |  50 +++++++++---
 drivers/power/supply/test_power.c         | 101 +++++++++++++++++++++++
 include/linux/power_supply.h              |  26 ++++++
 7 files changed, 371 insertions(+), 87 deletions(-)
---
base-commit: 061d1af7b0305227182bd9da60c7706c079348b7
change-id: 20240602-power-supply-extensions-07d949f509d9

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


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

end of thread, other threads:[~2024-07-04 10:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-08 19:19 [PATCH RFC v2 0/5] power: supply: extension API Thomas Weißschuh
2024-06-08 19:19 ` [PATCH RFC v2 1/5] power: supply: sysfs: use power_supply_property_is_writeable() Thomas Weißschuh
2024-06-08 19:19 ` [PATCH RFC v2 2/5] power: supply: core: avoid iterating properties directly Thomas Weißschuh
2024-07-04 10:42   ` Sebastian Reichel
2024-06-08 19:19 ` [PATCH RFC v2 3/5] power: supply: core: implement extension API Thomas Weißschuh
2024-06-13 23:11   ` Armin Wolf
2024-06-14  7:02     ` Thomas Weißschuh
2024-06-19 23:14       ` Armin Wolf
2024-06-08 19:19 ` [PATCH RFC v2 4/5] power: supply: test-power: implement a power supply extension Thomas Weißschuh
2024-06-08 19:19 ` [PATCH RFC v2 5/5] platform/x86: system76: Use power_supply extension API Thomas Weißschuh
2024-07-04 10:44 ` (subset) [PATCH RFC v2 0/5] power: supply: " Sebastian Reichel

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

all inboxes | Powered by JetHome®