mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] hwmon: (applesmc) add charge_control_end_threshold support
@ 2026-09-18 17:50 Jordan Brough
  2026-09-18 17:50 ` [PATCH v2 1/2] ACPI: battery: add unified battery hook mechanism for ACPI and SBS batteries Jordan Brough
  2026-09-18 17:50 ` [PATCH v2 2/2] hwmon: (applesmc) add charge_control_end_threshold support Jordan Brough
  0 siblings, 2 replies; 3+ messages in thread
From: Jordan Brough @ 2026-09-18 17:50 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rafael J . Wysocki
  Cc: Thomas Weißschuh, Henrik Rydberg, linux-hwmon, linux-acpi,
	linux-kernel, Jordan Brough

This patch series adds battery charge threshold control support to the
applesmc driver for Intel-based MacBooks, exposing the standard
charge_control_end_threshold sysfs attribute on the battery power supply.

In v1, separate SBS battery hooking functions were introduced in sbs.c.
Following reviewer feedback from Thomas Weißschuh, this version unifies
the ACPI battery hooking mechanism across both ACPI Control Method
batteries (drivers/acpi/battery.c) and ACPI Smart Battery Systems
(drivers/acpi/sbs.c) into a shared helper in drivers/acpi/battery_hook.c
built directly into the ACPI core (acpi.o).

The public consumer API signatures (battery_hook_register(),
battery_hook_unregister(), devm_battery_hook_register()) remain unchanged,
so existing drivers require no modifications while gaining the ability
to hook SBS batteries where present.

Patch 1 extracts the shared hook mechanism into
drivers/acpi/battery_hook.c and integrates both drivers/acpi/battery.c
and drivers/acpi/sbs.c.
Patch 2 adds charge_control_end_threshold support to
drivers/hwmon/applesmc.c with mutex synchronization around SMC register
writes (BCLM and BFCL) and error rollback on extension registration
failure.

Testing:
- Validated on Intel MacBook Air (MacBookAir6,2) with ACPI SBS battery
  (BAT0): verified sysfs threshold read/write, KDE Powerdevil UI
  detection, bounds checking, and hardware MagSafe LED transition between
  amber and green.
- Validated on Lenovo IdeaPad with ACPI Control Method battery (BAT1)
  to check that existing in-tree hook consumers (such as ideapad_laptop
  conservation mode) continue operating as expected.

Changes in v2:
- Unified battery hook infrastructure into drivers/acpi/battery_hook.c
  built into acpi.o, eliminating duplicate hook logic in sbs.c
  (Thomas Weißschuh).
- Kept public consumer API signatures unchanged
  (battery_hook_register/unregister, devm_battery_hook_register).
- Added applesmc_bat_lock mutex to serialize BCLM and BFCL SMC key writes,
  preventing concurrent write desynchronization.
- Added mutex protection and error rollback in applesmc_battery_add()
  to ensure applesmc_hooked_battery is safely handled if extension
  registration fails.
- Added mutex protection for applesmc_bat_get_property() / set_property().
- Note: v1 was acked by Rafael J. Wysocki; the Acked-by tag was dropped
  from Patch 1 in v2 due to the architectural refactoring into
  battery_hook.c.

Link: https://lore.kernel.org/r/20260913231410.416922-1-jordan@brough.org [v1]

Jordan Brough (2):
  ACPI: battery: add unified battery hook mechanism for ACPI and SBS
    batteries
  hwmon: (applesmc) add charge_control_end_threshold support

 drivers/acpi/Makefile       |   1 +
 drivers/acpi/battery.c      | 165 +-----------------------------------
 drivers/acpi/battery_hook.c | 112 ++++++++++++++++++++++++
 drivers/acpi/sbs.c          |   8 +-
 drivers/hwmon/applesmc.c    | 157 ++++++++++++++++++++++++++++++++--
 include/acpi/battery.h      |  10 +++
 6 files changed, 285 insertions(+), 168 deletions(-)
 create mode 100644 drivers/acpi/battery_hook.c

-- 
2.55.0


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

end of thread, other threads:[~2026-09-18 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-18 17:50 [PATCH v2 0/2] hwmon: (applesmc) add charge_control_end_threshold support Jordan Brough
2026-09-18 17:50 ` [PATCH v2 1/2] ACPI: battery: add unified battery hook mechanism for ACPI and SBS batteries Jordan Brough
2026-09-18 17:50 ` [PATCH v2 2/2] hwmon: (applesmc) add charge_control_end_threshold support Jordan Brough

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®