Skip to content

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

Open
areofyl wants to merge 48 commits 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 48 commits into
AsahiLinux:fairydustfrom
areofyl:fix/macsmc-lid-polling

Conversation

@areofyl

@areofyl areofyl commented May 31, 2026

Copy link
Copy Markdown

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
@areofyl areofyl force-pushed the fix/macsmc-lid-polling branch from b69f911 to 1affd03 Compare June 1, 2026 00:24
jannau and others added 28 commits June 2, 2026 21:53
Certain Broadcom bluetooth chips (bcm4377/bcm4378/bcm438) need ACL
streams carrying audio to be set as "high priority" using a vendor
specific command to prevent 10-ish second-long dropouts whenever
something does a device scan. This patch sends the command when the
socket priority is set to TC_PRIO_INTERACTIVE, as BlueZ does for audio.

From experimenting with the hardware - this command is not suitable for
per-skb priority switching, as prioritization is done on the handle
level, with this command reconfiguring certain radio timings, and
dropping to low priority in order to send a low packet on the same
handle as an audio stream is being played on causes the same kind of
dropout it is supposed to avoid. In addition, the hardware is rather
picky about when this command can be sent, as sending it during
connection open results in a timeout. The vendor stacks solve it by
having high-level visibility into what a connection is used for and
sending it from userspace when it is known that an audio stream is
about to start. As we can't have that visibility without introducing a
new ioctl, the socket priority is used as proxy.

Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
The current approach of silently disabling all rust drivers if the
toolchain is missing results in users that try to compile their own
kernels getting a "successful" build and then being confused about where
did their drivers go. In comparison, missing openssl results in a build
failure, not a disappearance of everything that depends on it.

This also means that allyesconfig will depend on rust, but since the
rust experiment concluded with "rust is here to stay", i believe that
allyesconfig should be building rust drivers too.

Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
Apple M3 Pro and Max devices are using 'gp00' keys for GPIO in addition
to 'gP00' keys. Add a second compatible to handle this keys with an
additional macsmc-gpio instance.

Signed-off-by: Janne Grunau <j@jannau.net>
Add support for SMC GPIO keys with a lower letter 'p' via the
"apple,smc-low-gpio" compatible. This adds support for a second
macsmc-gpio controller using 'gp00' keys.
These keys are used on Apple M3 Pro and Max MacBooks in the controller
for keyboard and trackpad and for the built-in DisplayPort to HDMI
converter.

Signed-off-by: Janne Grunau <j@jannau.net>
Apple M3 Pro and Max devices are using 'gp00' keys for GPIO in addition
to 'gP00' keys. These keys are handled by an additional macsmc-gpio
instance using the "apple,smc-low-gpio" compatible.

Signed-off-by: Janne Grunau <j@jannau.net>
- WLAN/BT (SMC PMU GPIO AsahiLinux#13) (all devices)
- ASM3142 (SMC PMU GPIO AsahiLinux#14) (j434, iMac with 4 USB-C ports)
- SD card reader (SMC PMU GPIO AsahiLinux#23) (j504, 14-inch MacBook Pro)

Signed-off-by: Janne Grunau <j@jannau.net>
yuyuyureka and others added 19 commits June 2, 2026 21:54
Signed-off-by: Yureka <yuka@yuka.dev>
The internal keyboard and trackpad HID on MacBook variants
of the Apple M3 (t8122) SoC are connected through a Apple
-developed protocol called DockChannel and mediated by a
coprocessor known as the Multi-Touch Processor (MTP).

This commit adds the nessecary device tree nodes to the
M3's device tree for internal HID to work. It is disabled
by default, to be enabled only in MacBook board files
where it is tested and confirmed to work.

Co-developed-by: Alyssa Milburn <amilburn@zall.org>
Signed-off-by: Alyssa Milburn <amilburn@zall.org>
Signed-off-by: Michael Reeves <michael.reeves077@gmail.com>
Add mtp device nodes for t8122 (M3) based MacBooks.

Signed-off-by: Michael Reeves <michael.reeves077@gmail.com>
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
List trackpad firmware files and activate MTP devices nodes on all
t6030, t6031 and t6034 based MacBooks.

Signed-off-by: Janne Grunau <j@jannau.net>
HDP status for DisplayPort alt-mode is signaled data_status. Track
changes to have a debounced HPD to forward to the DRM KMS driver.

Signed-off-by: Janne Grunau <j@jannau.net>
This is not how dp-altmode support should be implemented but it works
for new. Requires a "displayport" property in the connector node with a
phandle of the connector.

Signed-off-by: Janne Grunau <j@jannau.net>
Enable DP alt mode for all M1 devices:
- Mac Mini (M1): USB-C port next to the HDMI port
- Macbook Pro (M1, 13-inch): front left USB-C port
- Macbook Air (M1, 13-inch): front left USB-C port
- iMac (M1, 2 USB-C ports): back left USB-C port
- iMac (M1, 4 USB-C ports): back right middle USB-C port

Signed-off-by: Janne Grunau <j@jannau.net>
Works around missing suspend/resume handling in ATC phy for DP-altmode.

Signed-off-by: Janne Grunau <j@jannau.net>
Enable DP alt mode for the front left USB-C port of Macbook Air 13 (M2,
13/15-inch) and Macbook Pro (M2, 13-inch).
Can't easily enabled on on the M2 Mac Mini since dcpext is used for the
HDMI port and dcp bringup is troublesome.

Signed-off-by: Janne Grunau <j@jannau.net>
Works around missing suspend/resume handling in ATC phy for DP-altmode.

Signed-off-by: Janne Grunau <j@jannau.net>
Needs more testing, maybe a little unstable and somehow limits the HDMI
out to 1280x720 (to be verified).
Using dcp as display coproc since dcpext is used for the HDMI port.

Signed-off-by: Janne Grunau <j@jannau.net>
Works around missing suspend/resume handling in ATC phy for DP-altmode.

Signed-off-by: Janne Grunau <j@jannau.net>
Blessed dp-altmode port is front left port on j314/j316/j414/j416.

Signed-off-by: Janne Grunau <j@jannau.net>
…ways on

Works around missing suspend/resume handling in ATC phy for DP-altmode.

Signed-off-by: Janne Grunau <j@jannau.net>
DP alt mode for Mac Studio, the blessed port is the back left middle port
(second closest USB-C port to the power connector).

Signed-off-by: Janne Grunau <j@jannau.net>
…s on

Works around missing suspend/resume handling in ATC phy for DP-altmode.

Signed-off-by: Janne Grunau <j@jannau.net>
DP alt mode for Mac Mini M2 Pro, the blessed port is the back right
middle port (second closest USB-C port to the power connector).

Signed-off-by: Janne Grunau <j@jannau.net>
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 1affd03 to 36eff9f Compare June 6, 2026 23:30
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.

5 participants