Skip to content

Input: macsmc-input - confirm a lid-open report during system sleep - #1160

Merged
RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
rolotrealanis98:pr/macsmc-input-lid-confirm
Nov 10, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:integration/aurorafrom
rolotrealanis98:pr/macsmc-input-lid-confirm

Conversation

@rolotrealanis98

Copy link
Copy Markdown
Contributor

On the J716s (MacBook Pro 16-inch, M5 Pro) closing the lid starts an s2idle suspend through logind, and the system was awake again 0.7 s later. The SMC itself emits the lid-open event (SMC HID Event: 03 00 01, notification 0x72030001, the same bytes as a real opening) about 230 ms after the close while the lid stays shut; macsmc-input reports it as a hard wakeup, the suspend aborts and logind reads "Lid opened". With no suspend configured, close and open (03 01 00 / 03 00 01) track the lid faithfully, so the false report only comes on the sleep path.

During system sleep (between .prepare and .complete) this patch confirms a lid-open report against the SMC's MSLD key (the one probe reads the initial state from) and ignores one that comes within lid_wake_settle_ms (default 2000 ms, 0 restores today's behaviour) of the sleep's start, measured with CLOCK_BOOTTIME. A held-back report leaves SW_LID closed and .complete resynchronises it from MSLD. Every decision is logged with the event, the time into the sleep and MSLD.

Tested on: J716s, kernel = integration/aurora + the T6050 series + this patch, logind HandleLidSwitch=suspend, SuspendState=mem (s2idle). Lid closed for 30 s: PM: suspend entry -> Timekeeping suspended for 39.477 seconds -> macsmc-input: lid open 72030001 at +40069 ms in sleep, MSLD=0: wakeup -> resume -> Lid opened., suspend_stats success 1 / fail 0, USB and Ethernet back. That run had no spurious report, so the confirm path was exercised and the hold-back path was not. It is now in our daily kernel. drivers/input/misc/macsmc-input.o builds with W=1 (LLVM, arm64) on integration/aurora 4114f76; checkpatch --strict clean.

Dependencies: none.

Open questions:

  • Linux never tells the SMC that the system is going to sleep (no PM callbacks in macsmc.c, no sleep key written), and the false lid-open looks like the SMC reacting to the AP's sleep path without that notice. Does Aurora know an SMC sleep-notify key (what macOS writes on sleep entry and exit)? That would be the real fix, and this filter could then go.
  • Is a module parameter the right knob for the settle time, or would you prefer a fixed value?

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSLD cross-check looks safe for every machine: it only drops an open report that the SMC's own lid key contradicts.

The lid_wake_settle_ms window is a wider change, though. It applies to every machine macsmc-input binds on, not only the J716s. On a machine whose SMC never sends the spurious report, closing the lid and opening it again within 2 s of .prepare now leaves the system asleep: MSLD agrees (0) and ms <= lid_wake_settle_ms, so the real open report is held. If the SMC sends no further lid event, the machine stays suspended until another wake source fires.

Could the settle window be limited to the SoCs where the false report has been seen (match data on the compatible, or a DT property on the input node), with 0 as the default elsewhere? The MSLD check could then stay for all machines.

Also, the hold-back path has not fired on hardware yet. A log from a sleep where it does, with lid after sleep: MSLD=... from .complete, would confirm that SW_LID resyncs as intended.

On the J716s (MacBook Pro 16-inch, M5 Pro) closing the lid starts a
suspend through logind, and the system is awake again 0.7 s later. The
SMC's own syslog shows the cause: about 230 ms after the close
("SMC HID Event: 03 01 00") it reports the lid open ("03 00 01", event
0x72030001, the same bytes as a real opening) while the lid stays shut,
at the same moment as the trackpad coprocessor logs "Sending Cumulus
Report to enter Dependent Mode" (Cumulus is the touch AFE). The driver
takes the report at face value: it is in the sleep window, so it reports
a hard wakeup, pm_system_wakeup() aborts the suspend or ends
suspend-to-idle, and logind then reads "Lid opened".

In the sleep window, between .prepare and .complete, check a lid-open
report before passing it on. Read the SMC's lid key MSLD, the one probe
reads the initial state from: if it says closed, the report is dropped.
If it agrees but the sleep has run for lid_settle_ms or less, the report
does not wake the system either. lid_settle_ms is 2000 on the J716s, the
only machine where the false report has been seen, and 0 everywhere
else, so other machines keep waking on the first open report that MSLD
confirms; the lid_wake_settle_ms module parameter overrides it at load
time (-1 = per-machine default, 0 = never hold). The machine is matched
with of_machine_is_compatible() because macsmc-input is an MFD cell
without a node of its own. A held-back report leaves SW_LID closed, and
.complete reports MSLD again, so the switch matches the SMC after any
wakeup. Each decision is logged with the event, the time into the sleep
and MSLD, so a test can tell which check fired.

The notifier runs in the SMC's RTKit worker and the SMC's replies are
taken from the mailbox interrupt (recv_message_early), so reading a key
there does not wait on the worker. The sleep time is taken from
CLOCK_BOOTTIME, which includes the time suspend-to-idle spends with
timekeeping suspended.

What this does not fix, on the J716s: if MSLD agrees with the false
report, the SMC already counts the lid as open, and the real opening
that follows may send no event at all. The system then stays asleep
until a key, a trackpad click or the power button wakes it, instead of
waking at once.

Not changed: lid-close reports, the power button, and any lid-open
report outside the sleep window.

Tested on the J716s with logind suspending on lid close (s2idle): the
close sleeps ("Timekeeping suspended for 39.477 seconds") and the real
opening wakes it through the confirm path ("lid open 72030001 at +40069
ms in sleep, MSLD=0: wakeup"). No spurious report came during that
sleep, so the hold-back path has not run on hardware yet.

Signed-off-by: Rolando Trevino <rolotrealanis@gmail.com>
Assisted-by: LLM Claude
@rolotrealanis98
rolotrealanis98 force-pushed the pr/macsmc-input-lid-confirm branch from 238be1b to 9423412 Compare November 10, 2026 11:20
@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

Updated (9423412), rebased onto integration/aurora 0227cec.

  • The settle window is now per machine: 2000 ms on apple,j716s, 0 everywhere else, so other machines wake on the first open report that MSLD confirms. The MSLD check still runs on every machine.
  • It is matched with of_machine_is_compatible() in probe. macsmc-input is an MFD cell without a node or OF match of its own (drivers/mfd/macsmc.c), so there is nothing to carry match data or a property; macsmc-hwmon and gpio-macsmc do per-machine quirks the same way. I matched the board, not apple,t6050, because the false report has only been seen on the J716s.
  • lid_wake_settle_ms remains as a load-time override (-1 = per-machine default, 0 = never hold).
  • Compiles with W=1 and no warnings; checkpatch --strict is clean.

The hold-back path still has not fired on hardware: the sleeps logged so far only took the confirm path. I will post a log with lid after sleep: MSLD=... when one does.

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.

2 participants