Skip to content

power: supply: macsmc: J700 battery reporting (reworked, 3 patches) - #29

Merged
RyanTheTide merged 3 commits into
aurora-wipfrom
series/neo-j700-smc-power-20260926
Sep 25, 2026
Merged

RyanTheTide merged 3 commits into
aurora-wipfrom
series/neo-j700-smc-power-20260926

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

J700 battery charge and status for macsmc-power, reworked after review. Three commits on aurora-wip (671ad267c).

What changed since the reviewed head (84afce6820e2)

  • The first commit is split in two. The property gating on apple_smc_key_exists() (BITV, B0RC, B0RI, B0RV) is now its own patch, and its message says it applies to every machine. The B0RM byte-order fix is a separate patch.
  • The J700 quirks are decided once at probe as two named flags, instead of by of_machine_is_compatible() on every property read:
    • b0rm_native: B0RM is in native byte order. It is set for one-byte BCF0 firmware, as before, and on J700.
    • status_from_current: report DISCHARGING when B0AC is negative.
    • fw_ge_27 again means only that BCF0 is one byte.
  • The B0RM helper returns u16, and the message explains that change. The key-type detection the reviewer suggested could not be verified from the code, so the J700 case is keyed on the machine compatible, and the message says why.
  • The negative-current status check now replaces only the three CHARGING results (CHNC clear, BMS busy, CHSC fallback). FULL, NOT_CHARGING (charge limit or inhibit) and the existing DISCHARGING cases are decided first, so a battery held at its limit keeps reporting NOT_CHARGING.
  • Parked, not included: the capacity change (5b075f38099c, CAPACITY from B0RM/B0FC instead of BUIC on J700). It would make Linux show a different percentage from macOS, and it gives no J700-specific reason.
  • Messages rewritten with engineering facts only:
    • what an unreadable property costs: a log line on every read, and the battery's change uevents are dropped;
    • the 256 mAh steps and negative values caused by the byte swap;
    • that without BITV the voltage-based emergency shutdown never fires (true on J700 before this series too);
    • what is not yet known.
  • Author and committer are Ryan Murray <[email protected]>, followed by one trailer block: Assisted-by: LLM checkpatch sparse, then Co-authored-by: Claude Opus 5.5 on the two commits whose code changed, then the sign-off.

Checks:

  • Every commit, built on its own: W=1 C=1 compile with LLVM and upstream sparse of macsmc-power.o (and apple.o), no warnings.
  • checkpatch --strict on each patch file: 0 errors. The only warnings are the known ones: the 7.1 tree's Assisted-by format, Co-authored-by as a non-standard signature, and "Unknown commit id" for the in-tree 57694663d658 when run outside a git directory.
  • codespell's dictionary is not installed on the build host. The text was spell-checked against the system word list instead.

Compile-tested only; not run on hardware in this form. A J700 boot should confirm:

  • the four properties are absent and their errors gone (this also confirms that the keys are missing, not merely unreadable);
  • battery change uevents arrive;
  • charge_now moves in 1 mAh steps and stays between 0 and charge_full;
  • the status in four states, recording CHNC and B0AC in each: a weak USB-C source under load (Discharging), a proper adapter (Charging), the 80 % hold (Not charging) and full (Full);
  • the B0AC noise around 0 mA, to decide whether a deadband is needed.

One older-firmware Mac should confirm that the four properties and charge_now are unchanged.

🤖 Generated with Claude Code

RyanTheTide and others added 3 commits September 26, 2026 03:02
…xist

VOLTAGE_MIN_DESIGN, CHARGE_TERM_CURRENT, CONSTANT_CHARGE_CURRENT_MAX
and CONSTANT_CHARGE_VOLTAGE are read from the BITV, B0RC, B0RI and
B0RV keys, and the driver registers them on every machine. When such
a read fails with an SMC error (-EIO), the power supply core logs
"driver failed to report" (rate-limited) for each read of the
property, and power_supply_uevent() gives up at the first failing
property, so no change uevent is sent for the battery at all.

Register these four properties only if their key exists at probe
time. This touches every machine the driver supports; firmware that
has the keys keeps the same properties.

On J700, reads of all four keys fail and the VOLTAGE_MIN_DESIGN errors
flood the kernel log. It has not been confirmed there that the keys
are missing from the key index, which is what apple_smc_key_exists()
checks, rather than present but unreadable.

macsmc_power_critical_work() forces an emergency shutdown when B0AV
drops below BITV. Without a readable BITV that check never fires, as
before this change, and only the BCF0 empty flag starts the orderly
shutdown. This applies to J700, where no key that could replace BITV
is known.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Signed-off-by: Ryan Murray <[email protected]>
Commit 5769466 ("power: supply: macsmc: Support macOS 27 SMC
firmware") infers two firmware changes from one fact: when the BCF0 key
shrinks from four bytes to one, B0RM is taken to switch from the gas
gauge's big-endian pass-through to native byte order.

J700's SMC firmware reports a four-byte BCF0 but a native-endian B0RM.
Swapping it made CHARGE_NOW and ENERGY_NOW move in 256 mAh steps as the
low byte changed, and gave values above CHARGE_FULL or below zero.

Track the B0RM byte order in its own flag, b0rm_native, set at probe
with the one-byte BCF0 layout as before and additionally on J700.
fw_ge_27 now means only that BCF0 is one byte. The J700 case is keyed
on the machine compatible because nothing in the key information the
driver reads distinguishes it: BCF0 has the older size, and the B0RM
key type has not been compared with other firmware.

The helper now returns u16 instead of s16 on every machine. B0RM is an
unsigned mAh count, so a remaining charge below 32768 mAh reads as
before; a larger value, such as a wrongly swapped one, no longer turns
negative.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
A J700 on a low-power USB-C source can have a charge-capable adapter
online, with CHCE and CHCC set, while the system draws more than the
adapter supplies. The battery current B0AC is then negative and the
remaining charge falls. CHCE and CHCC describe the adapter, not the
battery, so where the other SMC flags then lead the driver to report
CHARGING, the status contradicts the battery.

On J700, report DISCHARGING instead of CHARGING when B0AC is negative.
Only the three CHARGING results change: CHNC clear, CHNC holding only
the BMS-busy bit below the charge limit, and the CHSC fallback when
CHNC cannot be read. FULL, NOT_CHARGING for a charge limit or an
inhibit, and the existing DISCHARGING cases are decided first and stay
as they are, so a battery held at its charge limit keeps reporting
NOT_CHARGING. Whether CHNC reports an inhibit in the low-power state
has not been recorded; if it does, the status there stays
NOT_CHARGING. The quirk is decided once at probe, and other machines
keep the current status logic.

B0AC is compared against zero. No noise floor around 0 mA has been
measured, so a net current that hovers around zero can make the status
alternate between CHARGING and DISCHARGING.

Compile-tested only; not run on hardware.

Assisted-by: LLM checkpatch sparse
Co-authored-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide force-pushed the series/neo-j700-smc-power-20260926 branch from 84afce6 to e9f5493 Compare September 25, 2026 17:06
@RyanTheTide RyanTheTide changed the title power: supply: macsmc: report J700 battery charge and status power: supply: macsmc: J700 battery reporting (reworked, 3 patches) Sep 25, 2026
@RyanTheTide
RyanTheTide marked this pull request as ready for review September 25, 2026 17:07
@RyanTheTide
RyanTheTide merged commit 355ec1c into aurora-wip Sep 25, 2026
@RyanTheTide
RyanTheTide deleted the series/neo-j700-smc-power-20260926 branch September 26, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant