[PATCH v2 0/2] hwmon: (applesmc) add charge_control_end_threshold support
From: Jordan Brough
Date: Fri Sep 18 2026 - 13:54:24 EST
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@xxxxxxxxxx [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