Repository navigation
power: supply: macsmc: Report net discharge as discharging on every battery - #2303
Conversation
…attery Commit 8c0adb8 ("power: supply: macsmc: Report net discharge on J700 as discharging") reports DISCHARGING instead of CHARGING when the SMC flags say the battery charges but the battery current B0AC is negative. That happens when a charge-capable adapter is online while the system draws more than it supplies: a low-power USB-C source, or a heavy load on a small adapter. It is a property of any battery behind an adapter, not of the J700, but the check was enabled only where of_machine_is_compatible("apple,j700"). Enable it wherever the SMC reports B0AC as a signed 16-bit key ("si16", two bytes), the type the driver already reads it as for CURRENT_NOW on every machine, with negative meaning discharge. An SMC that reports B0AC with another type, or not at all, keeps the flag-only status. Only the CHARGING results change, as in the original commit: FULL, the charge-limit and inhibit NOT_CHARGING results and the existing DISCHARGING cases are decided first. Fixes: 8c0adb8 ("power: supply: macsmc: Report net discharge on J700 as discharging") Signed-off-by: Ryan Murray <[email protected]>
…y machine The manufacture date is left out on the J700 because its battery's BMDT does not follow the YYMMDD-from-1992 layout. The value there is still six ASCII digits, so the value cannot tell the layouts apart, and no difference in the key's reported type or size has been recorded, so nothing the SMC reports can select it yet. Say so in the comment, and point at the SMC key inventory as the data that would let it be keyed on the key's type instead. No functional change. Signed-off-by: Ryan Murray <[email protected]>
|
M2 (J413, T8112) row, on AC: no change from the current kernel. This PR's patch on the production fleet74 driver source (1f710d2), built as a module and swapped in at runtime. Arms stock / this PR / stock, each with
Force-discharge does not reach the new branch, because the SMC already reports not-charging there. The underpowered-adapter case (flags say charging, current negative) still needs a small USB-C source or a heavy load on a low-power adapter with the battery below its limit. This kernel has no SMC key debugfs, so B0AC's type and size were not read. |
|
Still needed: a row with an underpowered USB-C adapter (status flags say charging while current is negative) showing the battery reported as discharging, then ready-marking; the J413 and J616s rows show no change. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at c78bbf25ae5e. The status decision now uses the SMC key type and length and preserves charge-inhibit precedence. The J413 full/current-zero control does not hit the changed branch. Add a J413 rate-limited-adapter sample with current below zero while connected and one normal charging sample.
Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
Verdict: MERGE at 200a711 once the feature row and required hosted checks are in.
Checked: Admission uses signed 16-bit B0AC key metadata and leaves the existing fullness, limit and inhibit precedence in place. A failed current read retains the charging answer. The extracted production charging helper passed 12 host checks across supported/unsupported keys, successful/failed reads and negative/zero/positive current. The change is capability-based and has no DT delta.
The posted J713 and M1 Pro forced-discharge cases are regression coverage. The changed feature needs a row in which the charging flags are still asserted while signed B0AC is negative.
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: macsmc-power reports net discharge as Discharging on every Mac whose SMC gives B0AC as a signed 16-bit key, not only on the J700 (adapter online but supplying less than the system draws). Full, charge-limit and inhibit results are decided first, as before.
Tested: J713 (M4 Air) and M1 Pro at c78bbf2 in the combined one-shot kernel 7.3.0-aurora-dsw2, on adapter: idle
Full/0 mA as on the fleet kernel. Withcharge_behaviour=force-dischargefor 15 s:Dischargingat -315 mA (J713) and -257 mA (M1 Pro), the same status as the fleet kernel (-203/-191 mA). Afterauto: back toFull. J615 (dsw1):Full/0 mA unchanged. 0 failed units, 0 WARN/BUG on all three.Risk: two-way · all Mac laptops (battery status text only)
Not yet: the underpowered-adapter case itself (charge flags set while B0AC is negative): no adapter in the lab reproduces it, and force-discharge clears the charge flags
Evidence
CONFIG_USB_BILLBOARD=m), LLVM 22.1.6 / rustc 1.97.1. Build warnings are the same as main's. This PR's files there are byte-identical to the head 200a711, which is c78bbf2 + a cleanMerge main into sweep/macsmc-power.grub2-reboot, no Stage 2 or DTB change. Each Mac went back to its saved fleet kernel, the test kernel was removed, and production state was verified: saved entry, empty next_entry, Enforcing, 0 failed units.charge_behaviour=force-dischargewindow on both kernels, one 15 s s2idle on the wakeup RTC, error-level dmesg diffed against the fleet kernel's boot. On J713 the one new line (external display processor unusable (probe failed: -110)) comes from main code since 11-25 and shows on other main-based J713 boots too. The others come from the s2idle and match the fleet kernel's own s2idle.Original description
Problem
When a charge-capable adapter is online but supplies less than the system draws, the battery drains while the SMC's charger flags still read as charging. macsmc-power then reported
CHARGING. Commit 8c0adb8 fixed this by checking the sign of the battery current (B0AC), but only on the J700 (drivers/power/supply/macsmc-power.c:1212,status_from_current = of_machine_is_compatible("apple,j700")). Any Mac laptop can hit this with a small USB-C source or a heavy load.Change
si16, two bytes). The driver already reads B0AC that way forcurrent_nowon every machine, with negative meaning discharge. An SMC that reports B0AC with another type, or not at all, keeps the flag-only status.CHARGINGresults change.FULL, the charge-limit and inhibitNOT_CHARGINGresults, and the existingDISCHARGINGcases are decided first, as before.Credit: the original check is from 8c0adb8.
Testing
Compiles clean with the W=1 warning set (
drivers/power/supply/macsmc-power.o). See the build log below.Not run on hardware yet.
Hardware (one-shot test kernel 7.3.0-aurora-swl1 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):
Still to run
On adapter, on Neo (J700), J616s, M1 Pro (J316s) and M2 (J413):
cat /sys/class/power_supply/*/status /sys/class/power_supply/*/current_nowExpected: with a full-power adapter,
Chargingand positivecurrent_now, orFull/Not chargingat the limit. With a low-power source under load,Dischargingand negativecurrent_now. On battery,Dischargingand negativecurrent_now. Also confirm that B0AC issi16size 2 in the SMC key inventory:grep ' B0AC ' /sys/kernel/debug/macsmc-hwmon*/keys(needs the macsmc hwmon PR).Reach and safety
The check now runs on every SoC the driver binds with a battery: T8103, T8112, T6000-T6002, T6020-T6022, T6030-T6034, T8122, T6040/T6041, T6050, T8132 and T8140. Every one of those reads B0AC as s16 for
current_now, with negative meaning discharge. The probe-time type check (si16, size 2) keeps any SMC firmware that reports the key differently on the old behaviour. Desktops have no battery supply, so they are not affected.A net current that hovers around 0 mA can make the status alternate between
ChargingandDischarging. That was already true on J700.Build log
Compiled with the release config's kbuild flags plus the W=1 warning set (clang,
-fsyntax-only):The full kbuild object build in a clean O= tree is pending and will be added here.