Skip to content

macsmc-input: poll MSLD for lid state, fix spurious s2idle wake#509

Open
areofyl wants to merge 1 commit into
AsahiLinux:fairydustfrom
areofyl:fix/macsmc-lid-polling
Open

macsmc-input: poll MSLD for lid state, fix spurious s2idle wake#509
areofyl wants to merge 1 commit into
AsahiLinux:fairydustfrom
areofyl:fix/macsmc-lid-polling

Conversation

@areofyl
Copy link
Copy Markdown

@areofyl areofyl commented May 31, 2026

SMC lid events (0x7203) show up in the SMC firmware syslog but never actually get delivered to Linux via RTKit notifications. So lid open/close is completely invisible to userspace and logind never knows to suspend.

This switches to polling the MSLD key every second with a delayed_work and reporting SW_LID changes to the input subsystem. Added a 2-poll debounce because MSLD bounces during DP disconnect events.

Also fixes the spurious wake issue. The SMC fires a fake BTN_TOUCHID press+release within ~1ms of entering s2idle (this started happening after plugging in an external monitor, presumably changes some internal SMC state). The original upstream code passes that straight to pm_wakeup_dev_event which wakes the system instantly. Fixed by skipping the first 2 button events after pm_prepare, real presses after that go through normally.

Other stuff:

  • Added a remove callback, the old driver had none so unloading left a dangling notifier and a running delayed_work
  • pm_complete now cancels and reschedules lid_work so polling survives suspend/resume cycles
  • Exposed MSLD as a sysfs attribute (msld_state) for debugging
  • Initialized pending_lid_state from the actual MSLD read at probe so the first poll doesn't report a phantom state change

Tested on M1 MacBook Air (J313), fairydust 6.18.10. Lid close/open, suspend, power button wake all working.

@areofyl areofyl marked this pull request as ready for review June 1, 2026 00:19
SMC lid events (0x7203) show up in the SMC firmware syslog but never
get delivered to Linux via RTKit notifications, so lid open/close is
invisible to userspace.

Switch to polling the MSLD key every second with a delayed_work and
reporting SW_LID when it changes. 2-poll debounce because MSLD bounces
during DP disconnect events.

Also fixes spurious wake: the SMC fires a fake BTN_TOUCHID press+release
within ~1ms of entering s2idle. Skip the first 2 button events after
pm_prepare, real presses after that go through normally.

Other fixes:
- Add remove callback (old driver had none, leaked notifier + work)
- pm_complete cancels and reschedules lid_work so polling survives
  suspend/resume cycles
- Expose MSLD as sysfs attribute (msld_state) for debugging
- Init pending_lid_state from MSLD at probe

Tested on M1 MacBook Air (J313), fairydust 6.18.10.

Signed-off-by: areofyl <areofyl@users.noreply.github.com>
@areofyl areofyl force-pushed the fix/macsmc-lid-polling branch from b69f911 to 1affd03 Compare June 1, 2026 00:24
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