mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jordan Brough <jordan@brough.org>
To: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	"Rafael J . Wysocki" <rafael@kernel.org>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	"Henrik Rydberg" <rydberg@bitmath.se>,
	linux-hwmon@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Jordan Brough" <jordan@brough.org>
Subject: [PATCH v2 0/2] hwmon: (applesmc) add charge_control_end_threshold support
Date: Fri, 18 Sep 2026 11:50:50 -0600	[thread overview]
Message-ID: <20260918175052.85461-1-jordan@brough.org> (raw)

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


             reply	other threads:[~2026-09-18 17:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 17:50 Jordan Brough [this message]
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

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=20260918175052.85461-1-jordan@brough.org \
    --to=jordan@brough.org \
    --cc=jdelvare@suse.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=linux@weissschuh.net \
    --cc=rafael@kernel.org \
    --cc=rydberg@bitmath.se \
    /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®