-
Notifications
You must be signed in to change notification settings - Fork 110
power: supply: macsmc: support charge_behaviour on newer SMC firmware #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bits/110-smc
Are you sure you want to change the base?
power: supply: macsmc: support charge_behaviour on newer SMC firmware #435
Conversation
|
Oh sorry just realised there's an unrelated 2-line whitespace change in |
Newer Apple SMC firmware (found on M3 devices and updated M1/M2) has removed the legacy `CH0C` (Inhibit Charge) and `CH0I` (Force Discharge) keys. Reading these missing keys results in -EIO (-5) errors, causing the `charge_behaviour` sysfs property to fail completely. This patch adds support for the new `CHTE` key used for charge inhibition on these devices. For now, it seems that `auto` and `inhibit-charge` are the only possible behaviours to set using this new key, however further macOS tracing may reveal additional behaviour states in future. Changes: 1. Detects the presence of `CHTE`, `CH0C`, and `CH0I` during probe. 2. Only exposes `force_discharge` capability if `CH0I` is actually present. 3. Implements read/write support for `CHTE` using raw byte buffers (this is to avoid endianness issues with the kernel's u32 helpers) Fully backwards compatible with both old and new firmwares. Tested on M3 with new firmware. Signed-off-by: Michael Reeves <michael.reeves077@gmail.com>
49a85dd to
aee3b28
Compare
|
Just moved a comment to a more logical place. |
|
thanks a ton for looking into this issue! i upgraded MacOS earlier today and was extremely disappointed to find out about this regression. this patch does fix the |
|
Thank you for testing this out! I can't reproduce the |
|
somehow the error seems to be gone now. i did find out that i was loading the wrong device trees due to a minor corner case in my distro's kernel install hooks, but i haven't fixed the issue and yet the empty read on either way, it seems to be working fine now. thanks again for looking into this! |
|
Tested on 16-inch M2 Pro 2023. Before applying this patch, setting the charge threshold is flaky, and there are a lot of the following logs: These are all gone now. Thanks for working on this! |
|
I sent this driver upstream, including this and other improvements: https://lore.kernel.org/asahi/20260105-b4-macsmc-power-v1-0-62954c42a555@gmail.com, though it will probably take several weeks of review, then several weeks for it to land here, so I'll leave this open in case anyone wants just the charge_behaviour patch so optimised charging works, though feel free to close if it's better to wait for upstream. Happy to help, it was fun reverse engineering to find out how to fix this. |
Newer Apple SMC firmware (found on M3 devices and updated M1/M2) has removed the legacy
CH0C(Inhibit Charge) andCH0I(Force Discharge) keys. Reading these missing keys results in -EIO (-5) errors, causing thecharge_behavioursysfs property to fail completely.This patch adds support for the new
CHTEkey used for charge inhibition on these devices.For now, it seems that
autoandinhibit-chargeare the only possible behaviours to set using this new key, however further macOS tracing may reveal additional behaviour states in future.Changes:
CHTE,CH0C, andCH0Iduring probe.force_dischargecapability ifCH0Iis actually present.CHTEusing raw byte buffers (this is to avoid endianness issues with the kernel's u32 helpers)Fully backwards compatible with both old and new firmwares. Tested on M3 with new firmware.