From: Jordan Brough <jordan@brough.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
Henrik Rydberg <rydberg@bitmath.org>
Cc: Jordan Brough <jordan@brough.org>,
chrome-platform@lists.linux.dev,
ibm-acpi-devel@lists.sourceforge.net, linux-acpi@vger.kernel.org,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, platform-driver-x86@vger.kernel.org
Subject: [PATCH v3 0/3] hwmon: (applesmc) add charge_control_end_threshold support
Date: Wed, 30 Sep 2026 16:26:32 -0600 [thread overview]
Message-ID: <20260930222650.1883805-1-jordan@brough.org> (raw)
This series adds charge_control_end_threshold to the applesmc driver for
Intel MacBooks, using the power_supply extension API.
Some of these machines have an SBS battery (drivers/acpi/sbs.c), which,
unlike battery.c, has no battery hook mechanism. Patch 2 moves the hook code
into a helper that both drivers use, and patch 3 adds the applesmc support.
Patch 1 is the acpi_ prefix rename of the existing hook functions that Rafael
asked for; it is separate because it touches 18 callers in other subsystems.
The series is based on linux-pm's bleeding-edge branch (4c18627a1dfb). Patch
3 depends on patch 2, so the series would need to go in through the ACPI
tree with an ack from the hwmon side, or I can resend patch 3 once patches 1
and 2 are in, whichever is easier.
Changes in v3 (thanks to Rafael for the review):
- Patch 1 is new: acpi_ prefix for the exported hook functions, with their
callers updated.
- Patch 2:
- Renamed battery_hook.c to battery_hooks.c, built only when ACPI_BATTERY
or ACPI_SBS is, through a hidden ACPI_BATTERY_HOOKS symbol that both
select.
- Renamed the struct and the new functions as suggested, exported the new
functions in the ACPI_BATTERY_HOOKS namespace, used mutex guards and
updated the file header.
- battery_hook_exit() is gone, so hooks now stay registered across a
reload of battery.ko or sbs.ko.
- Patch 3:
- BFCL is only written when the SMC has the key, and the BCLM write is read
back, at the suggestion of Michal Szpakowski, whose MacBookPro13,1 has no
BFCL.
- No BFCL margin at a limit of 100.
- The lower limit of 20 is conservative: 20 works and 10 is not accepted
on the hardware I tried, but I did not find the exact floor. I am happy
to change it.
- Dropped the applesmc_hooked_battery tracking and the mutex in
applesmc_bat_get_property().
- The hook is only registered when CONFIG_ACPI_BATTERY_HOOKS is reachable.
Testing:
- MacBookAir6,2 (SBS battery), on an earlier revision: limits from 20 to 100
match the SMC keys, charging stops at the limit, repeated module reloads
caused no errors, and the threshold was unchanged after a suspend/resume.
- MacBookPro13,1 (SBS battery, no BFCL), by Michal Szpakowski, before the
acpi_ rename: valid limits read back exactly, invalid ones are rejected,
applesmc reload and an acpi-sbs unbind/rebind re-attach the attribute, and
charging stops at the limit.
- Lenovo ideapad FLEX 4-1480 (Control Method battery, ideapad_laptop), on
Fedora's 7.2.7 kernel with the series applied on top (a rebase of the
patches, not this exact tree): the ideapad_laptop hook registers and its
charge_types attribute appears on BAT1, charge_types can be read and
written back unchanged, 25 battery unbind/bind cycles re-attach it each
time, and unloading and reloading ideapad_laptop removes and re-adds it.
There were no warnings in dmesg. That kernel did not have lockdep
enabled.
- Built and linked with ACPI_BATTERY and ACPI_SBS as y/m/n and applesmc as
y/m, and an x86 allmodconfig build of the touched files with W=1 shows no
warnings; each patch builds on its own.
- Applies with git am on linux-pm bleeding-edge, and with git am --3way on
hwmon-next.
Link: https://lore.kernel.org/r/20260918175052.85461-1-jordan@brough.org [v2]
Link: https://lore.kernel.org/r/20260913231410.416922-1-jordan@brough.org [v1]
Jordan Brough (3):
ACPI: battery: add acpi_ prefix to the battery hook API
ACPI: battery: add unified battery hook mechanism for ACPI and SBS
batteries
hwmon: (applesmc) add charge_control_end_threshold support
drivers/acpi/Kconfig | 5 +
drivers/acpi/Makefile | 1 +
drivers/acpi/battery.c | 166 +------------------
drivers/acpi/battery_hooks.c | 159 ++++++++++++++++++
drivers/acpi/sbs.c | 8 +-
drivers/hwmon/Kconfig | 1 +
drivers/hwmon/applesmc.c | 146 ++++++++++++++++
drivers/platform/x86/asus-wmi.c | 4 +-
drivers/platform/x86/ayaneo-ec.c | 2 +-
drivers/platform/x86/dell/dell-laptop.c | 4 +-
drivers/platform/x86/dell/dell-wmi-ddv.c | 2 +-
drivers/platform/x86/fujitsu-laptop.c | 4 +-
drivers/platform/x86/huawei-wmi.c | 4 +-
drivers/platform/x86/lenovo/ideapad-laptop.c | 4 +-
drivers/platform/x86/lenovo/thinkpad_acpi.c | 4 +-
drivers/platform/x86/lenovo/wmi-other.c | 4 +-
drivers/platform/x86/lg-laptop.c | 4 +-
drivers/platform/x86/msi-ec.c | 4 +-
drivers/platform/x86/oxpec.c | 2 +-
drivers/platform/x86/samsung-galaxybook.c | 3 +-
drivers/platform/x86/samsung-laptop.c | 4 +-
drivers/platform/x86/system76_acpi.c | 4 +-
drivers/platform/x86/toshiba_acpi.c | 4 +-
drivers/platform/x86/uniwill/uniwill-acpi.c | 2 +-
drivers/power/supply/cros_charge-control.c | 2 +-
include/acpi/battery.h | 16 +-
26 files changed, 367 insertions(+), 196 deletions(-)
create mode 100644 drivers/acpi/battery_hooks.c
base-commit: 4c18627a1dfbfe537580f831e60218644c94ce12
--
2.56.0
next reply other threads:[~2026-09-30 22:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 22:26 Jordan Brough [this message]
2026-09-30 22:26 ` [PATCH v3 1/3] ACPI: battery: add acpi_ prefix to the battery hook API Jordan Brough
2026-09-30 23:19 ` Armin Wolf
2026-10-01 0:21 ` Jonathan Woithe
2026-10-01 1:14 ` Derek J. Clark
2026-09-30 22:26 ` [PATCH v3 2/3] ACPI: battery: add unified battery hook mechanism for ACPI and SBS batteries Jordan Brough
2026-09-30 22:26 ` [PATCH v3 3/3] hwmon: (applesmc) add charge_control_end_threshold support Jordan Brough
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260930222650.1883805-1-jordan@brough.org \
--to=jordan@brough.org \
--cc=chrome-platform@lists.linux.dev \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rydberg@bitmath.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®