mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/3] hwmon: (applesmc) add charge_control_end_threshold support
@ 2026-09-30 22:26 Jordan Brough
  2026-09-30 22:26 ` [PATCH v3 1/3] ACPI: battery: add acpi_ prefix to the battery hook API Jordan Brough
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jordan Brough @ 2026-09-30 22:26 UTC (permalink / raw)
  To: Rafael J. Wysocki, Guenter Roeck, Henrik Rydberg
  Cc: Jordan Brough, chrome-platform, ibm-acpi-devel, linux-acpi,
	linux-hwmon, linux-kernel, linux-pm, platform-driver-x86

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


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

end of thread, other threads:[~2026-10-01 13:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30 22:26 [PATCH v3 0/3] hwmon: (applesmc) add charge_control_end_threshold support Jordan Brough
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-10-01 13:19   ` Mark Pearson
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

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®