omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Pre-T2 battery charge limiting works via SMC BCLM and wants integration

Open rand0mdud3 opened this issue 2 months ago • 11 comments

Counterpart to #10121

#10121 proves charge limiting is unreachable on T2 (no SMC transport). The pre-T2 side is the mirror image: possible, proven below, integrated nowhere.

Evidence (MacBookPro11,5, 2015, pre-T2)

SMC reachable on the legacy port, limit set once to 80:

$ macbook-charge-limit read
BCLM=80 BFCL=80
$ cat /sys/class/power_supply/BAT0/capacity /sys/class/power_supply/BAT0/status
80
Full

The enforcing service itself is long dead (failed state) and the limit still holds across boots -- it lives in SMC firmware, not in a daemon. Charging stops at exactly 80%.

Mechanism

Pre-T2 SMC exposes charge-limit keys (BCLM/BFCL) over the legacy 0x300 I/O port, writable from Linux (prior art: jtbrough/macbook-charge-limit pattern). No sysfs charge_control_* knob exists, so Omarchy has nothing to surface -- no command, no widget, no installer step.

Scope

Pre-T2 Intel Macs carrying BCLM keys (2013-2017 era; exact key availability varies by board and wants a presence probe, not a model list). T2 and Apple Silicon are excluded by physics, per #10121.

The ask: carry the upstream series in the omarchy kernel

Jordan Brough's LKML series ([PATCH 0/2] hwmon: (applesmc) add native charge_control_end_threshold support -- https://lkml.org/lkml/2026/9/13/903) implements exactly this natively and is under review, with an ACK already on patch 1/2. Tested live on this 11,5 from mbox builds: sysfs appears, reads match SMC truth, write round trips verified both directions, fans/temps nominal.

omacom/linux already carries downstream Apple patches (SMC GPIO, Broadcom BT channel priority), so proposing the same treatment: carry these two small patches in the omarchy kernel build until they land upstream, then drop them. That beats a DKMS quirk (per-release rot, proven by the out-of-tree version's history) and makes the manual tool path unnecessary. Offering this 11,5 as the test machine for the carried patches, including across kernel updates.

rand0mdud3 avatar Sep 13 '26 00:09 rand0mdud3

Duplicate check for the record: #3036 and #1289 asked for sysfs-threshold UI (charge_control_end_threshold), which Omarchy has since built for machines that expose those knobs (see the battery-panel charge-limit work). This issue is the complement: pre-T2 Macs expose no sysfs knobs at all, so that UI has nothing to read -- the capability has to come from SMC BCLM first. Different mechanism, different hardware, not a dup.

rand0mdud3 avatar Sep 13 '26 00:09 rand0mdud3

Great work proving this works on pre-T2 hardware. This is a valuable addition for the MacBook crowd on Omarchy.

Where it should live in Omarchy:

  1. ** CLI command** — new subcommand (or flag on existing) that:

    • Probes for BCLM/BFCL presence on first run (legacy SMC port 0x300)
    • If present: writes limit to SMC, returns success
    • If absent: clear message "Not supported on this hardware (T2/Apple Silicon or no BCLM keys)"
    • Persists via SMC firmware — no daemon needed
  2. Bar power widget — show charge limit status when set (read BCLM from SMC), maybe a toggle in the power menu for supported hardware

  3. Installer detection — during , probe for BCLM keys. If found, offer "Enable battery charge limiting (80% recommended)" as an optional step, same way we handle other hardware-specific tweaks.

Implementation notes:

  • Reuse the pattern (jtbrough/macbook-charge-limit) — it's proven, minimal, writes directly to SMC
  • The probe should be safe: read-only check first, only write if user confirms
  • Since it's firmware-persistent, no systemd service/timer needed — huge win
  • Could add to show current limit + whether hardware supports it

Scope: Limit to pre-T2 Intel Macs (2013-2017) where BCLM keys exist. T2+ and Apple Silicon are hard no-go per #10121.

Happy to help prototype the CLI command if you want — the SMC write is straightforward and the Omarchy battery module is the natural home for it.

epastor-seidor avatar Sep 13 '26 00:09 epastor-seidor

Agree with the shape -- matches what we scoped. Two additions: the applesmc driver stays loaded and shares the SMC with no locking, so the prototype should assess contention (writes are rare, but it is the one safety question before this ships to other people's firmware). And yes please on the CLI prototype -- this 11,5 (verified 80% hold) is available to test it the moment it exists.

rand0mdud3 avatar Sep 13 '26 00:09 rand0mdud3

Direction update: I'm pursuing the native route instead of the userspace CLI wrapper. Forked applesmc-next to rand0mdud3/applesmc-next and rewriting it as a minimal diff on current sources -- the existing fork is a full stale copy (zero common hunks with 7.2.3's sbs driver) with known-unfixed races, so the work is a rebase-plus-fixes, not a load-and-ship. If it pans out, Omarchy integration consumes standard sysfs and the whole SMC-contention question disappears.

rand0mdud3 avatar Sep 13 '26 17:09 rand0mdud3

Verified live on the 11,5: with BCLM=80 the MagSafe LED stays orange despite zero charge current -- the LED follows the full-charge threshold, not current flow. Setting BFCL=78 (end minus 2, per the applesmc-next README guidance) flips it green with the battery resting at 80. So any integration must set the pair, not just the end limit.

rand0mdud3 avatar Sep 14 '26 05:09 rand0mdud3

State of the rewrite (rand0mdud3/applesmc-next, branch rebase-7.2-minimal): pure-addition diffs on pristine 7.2.3 (+158 applesmc, ~110 sbs, zero modified lines), #12's fixes folded in, checkpatch-clean, both modules build warning-free. Loaded live on this 11,5: fans/temps identical, all three sysfs nodes present, reads match SMC truth, 85/80 write round trip verified both directions, BFCL LED behavior confirmed above. Caveats: sbs must be reloaded once after applesmc so the hook fires, and this remains out-of-tree DKMS for now -- upstreaming needs a maintainer sponsor, which is a separate conversation.

rand0mdud3 avatar Sep 14 '26 05:09 rand0mdud3

One architecture note for whenever Jordan Brough's LKML series lands ([PATCH 0/2] hwmon: (applesmc) add native charge_control_end_threshold support, currently under review -- https://lkml.org/lkml/2026/9/13/903): Omarchy ships its own kernel, so rather than a DKMS quirk (with the per-release maintenance rot that killed the out-of-tree version), the clean end-state is backporting those two patches into the omarchy kernel build. Until then, the tested interim is the manual path above, not a quirk we'd have to babysit and later retire.

rand0mdud3 avatar Sep 18 '26 17:09 rand0mdud3

Useful counterpart to #10121 (T2 unreachable). Pre-T2 BCLM via SMC is real and sticky.

Charge-limit UI work is already in flight for UPower-style hardware (#12177, #11792, #13205). Integrating macbook-charge-limit / BCLM would need a separate backend — worth a product call on whether pre-T2 SMC is in scope for the power panel or stays a documented manual tool.

jandrusk avatar Oct 13 '26 16:10 jandrusk

Another pre-T2 data point: MacBookAir5,2 has the end-threshold file, and UPower's 80% is not the live limit

Measured 15 November 2026 on the machine this note is from. Read-only. Nothing was written to sysfs, UPower, or the SMC. The SMC key list was not read: key_at_index on applesmc is root-only here, so this neither confirms nor denies BCLM / BFCL on this board.

Machine

DMI MacBookAir5,2, board Mac-2E6FAB96566FE58C (13-inch, Mid 2012)
Omarchy 4.5.0-3
Kernel 7.2.15-1-omarchy
Battery ACPI BAT0, model bq20z451, manufacturer SMP, Li-ion
Driver ACPI battery (ACPI0002). There is no /sys/class/power_supply/macsmc-battery
applesmc bound at /sys/devices/platform/applesmc.768, key_count 424
Power supplies BAT0 and ADP1 only

This is the pre-T2 side of the split in this issue. It is not a T2 Mac (#10121) and not an Apple Silicon Mac. #16651's unit waits on macsmc-battery, which this machine does not have.

What the kernel file says

/sys/class/power_supply/BAT0/charge_control_end_threshold exists and reads 100.

These do not exist on BAT0:

  • charge_control_start_threshold
  • charge_type
  • charge_types

So the "no charge_control_* knob" line in the report is not true on this Air. The end file is there. A start file is not. The file is mode rw-r--r--, so a normal user can read it and only root can write it. It was not written.

What UPower says about the same battery

busctl get-property on /org/freedesktop/UPower/devices/battery_BAT0:

Property Value
ChargeThresholdSupported true
ChargeThresholdEnabled false
ChargeStartThreshold 75
ChargeEndThreshold 80
ChargeThresholdSettingsSupported 2 (end threshold only; the start bit is clear)
State discharging
Percentage 54.9%
Capacity 84.5% of design
EnergyRate 13.2 W
TimeToEmpty 6916 s (about 1 hour 55 minutes) at that moment

upower -i prints the same 75% / 80% pair and charge-threshold-supported: yes. It does not print an enabled flag. The kernel file at the same moment was 100, and ChargeThresholdEnabled was false.

The 75/80 pair is UPower's advertised setting, not a limit the pack is holding. A panel that shows ChargeEndThreshold without also checking ChargeThresholdEnabled and the sysfs file would tell the owner of this Air that charging stops at 80% when the kernel still says 100. That is the same class of mismatch as #7374, on Apple ACPI battery hardware instead of asusctl.

#15431 and #13205 enable the limit through UPower. On this Air that path looks available (ChargeThresholdSupported true, settings flag = end only), but it is not in use. #12177 writes BAT*/charge_control_end_threshold directly, which is the file this Air actually has. None of those three were run here.

Pack readings, same moment

Sysfs, µAh / µV / µA. Temperature is the kernel's deci-celsius value.

status Discharging
capacity 46 (percent; UPower's energy percentage at the same time was 54.9, so the two percent figures do not match)
cycle_count 400
temp 254 (25.4°C)
voltage_min_design 7,600,000 µV
voltage_now 7,224,000 µV
current_now 2,027,000 µA
current_avg 2,129,000 µA
charge_full_design 7,200,000 µAh
charge_full 6,086,000 µAh (84.5% of design, same health figure UPower reports)
charge_now 3,325,000 µAh

Instantaneous draw from voltage_now × current_now is about 14.6 W. UPower's EnergyRate was 13.2 W. Either way this is a session-length number, not a charge-limit number. Capping the end threshold at 80 would stop the pack earlier and make each charge shorter. It does not lower this draw.

What this does not show

  • Whether writing charge_control_end_threshold sticks, survives a reboot, or stops charging. Not written.
  • Whether BCLM or BFCL exist among the 424 SMC keys, or what they contain. Not read.
  • Whether the percentage disagreement (sysfs capacity 46, UPower 54.9) is a unit or smoothing bug. Both were sampled once, a few seconds apart, while current was about 2 A, so they are not a controlled pair.
  • Any runtime tuning. Nothing in Omarchy on this install is capping charge or changing the power profile for this model. power-profiles-daemon is the active power daemon; that only says which daemon is running, not that a Mac-specific policy is applied.

The useful check still open on this board is a root read of the SMC charge keys, then a write of the end threshold to 80 with the charger connected, then a read of both the sysfs file and the SMC key. That is the difference between "the file exists" and "this Air enforces BCLM the way the 2015 MacBookPro11,5 in the report does."

andyholst avatar Nov 15 '26 20:11 andyholst

Your Air is the mirror image of this 11,5, and together the two make the UPower-vs-sysfs mismatch concrete.

Same release, same kernel family, pre-T2, read-only:

your MacBookAir5,2 this MacBookPro11,5
sysfs charge_control_end_threshold 100 80 (real BCLM, firmware-persistent)
sysfs charge_control_start_threshold absent 0
UPower ChargeThresholdSupported true false
UPower ChargeStartThreshold / ChargeEndThreshold 75 / 80 (hwdb defaults) 0 / 0
driver in-tree applesmc applesmc 0.2.0 from DKMS (updates/dkms)

So on one pre-T2 machine UPower invents a 75–80 % limit the hardware does not have, and on the other it reports no threshold at all while sysfs holds a live 80 % that the firmware enforces. Neither matches the hardware, in opposite directions — UPower here reads Supported=false even though charge_control_end_threshold is readable and non-100.

That matters beyond display, because bin/omarchy-battery-status:93-98 takes the limit from UPower first and only falls back to sysfs when UPower reports nothing:

threshold_end=$(awk '/charge-end-threshold:/ …' <<<"$battery_info")
[[ -n $threshold_end || ! -r $battery_path/charge_control_end_threshold ]] || threshold_end=$(<"$battery_path/charge_control_end_threshold")

On your unit that line picks 80 (phantom) over 100 (sysfs); on mine it picks nothing from UPower and correctly falls back to 80. Reversing the preference — sysfs when it is readable, UPower as the fallback — would fix your case and leave mine unchanged, and it is the same defect that https://github.com/omacom/omarchy/issues/16653 and https://github.com/omacom/omarchy/issues/7374 describe from the timing and hwdb sides.

Two notes from this board for the integration ask in the issue: the end-threshold here comes only from the out-of-tree DKMS module, not from linux-omarchy's in-tree applesmc (no charge_control_end_threshold string in it), so a stock pre-T2 Mac still has no knob; and charge_control_start_threshold is exposed by that module and reads 0, which is what makes the panel show Holding at 0-80% rather than a single number.

rand0mdud3 avatar Nov 16 '26 04:11 rand0mdud3

A correction worth checking on the two reports above, since it decides whether this issue is still an ask for Omarchy at all.

The in-tree applesmc in linux-omarchy 7.2.15-2 does not carry the charge_control_* attributes. Read from the packaged module rather than a running system, since this machine's in-tree copies are removed:

$ tar --zstd -xf linux-omarchy-7.2.15-2-x86_64.pkg.tar.zst … applesmc.ko.zst
$ zstd -dc applesmc.ko.zst | strings | grep -iE 'charge|threshold'
Apple SMC Battery Charge Control
applesmc-charge-control
has_battery_charge_limit
has_battery_charge_limit_led
acpi_battery_hook_register / acpi_battery_hook_unregister
applesmc: failed to update MagSafe LED threshold (BFCL): %d

That is the ACPI battery-hook series (the 0803/0804/0805 patches) and the BFCL LED work — it registers a battery hook, and there is no charge_control_end_threshold string at all. The charge_control_* device attributes come from the out-of-tree applesmc-next 0.2.0 instead:

AppleSMC Battery Charge Extension
dev_attr_charge_control_end_threshold / …_start_threshold / …_full_threshold

So on a machine where applesmc is the in-tree module, sysfs has no charge_control_end_threshold — which is exactly what this 11,5 showed before the DKMS module was installed, and what a stock pre-T2 Mac should still show.

For the two reports that say in-tree exposes it (MacBookAir5,2 in https://github.com/omacom/omarchy/issues/11593#issuecomment-6907146199, MacBookPro12,1 in https://github.com/omacom/omarchy/pull/16685#issuecomment-7045989025), one command settles which module is actually providing it:

modinfo -n applesmc      # updates/dkms/applesmc.ko.zst (DKMS) vs kernel/drivers/hwmon/applesmc.ko.zst (in-tree)

If those units resolve to updates/dkms/, then the in-tree support described in the reports is the DKMS module, and this issue's ask — carry the SMC charge-limiting series so a stock pre-T2 Mac has the knob — is still open rather than already solved. Worth having straight before #16685 relies on the "sysfs 100 vs UPower 75/80" case as evidence about in-tree behaviour.

Machine note, since it affects the comparison: on this box both kernel/drivers/hwmon/applesmc.ko.zst and kernel/drivers/acpi/sbs.ko.zst are missing from disk (flagged by pacman -Qkk as the only two altered files in both linux and linux-omarchy), left over from the SMC work here. Everything above was therefore read from the package contents, not from the installed modules.

rand0mdud3 avatar Nov 21 '26 19:11 rand0mdud3