Skip to content

macsmc-input: skip spurious BTN_TOUCHID events on s2idle entry#509

Open
areofyl wants to merge 54 commits into
AsahiLinux:fairydustfrom
areofyl:fix/macsmc-lid-polling
Open

macsmc-input: skip spurious BTN_TOUCHID events on s2idle entry#509
areofyl wants to merge 54 commits into
AsahiLinux:fairydustfrom
areofyl:fix/macsmc-lid-polling

Conversation

@areofyl

@areofyl areofyl commented May 31, 2026

Copy link
Copy Markdown

The SMC fires a spurious BTN_TOUCHID press+release within ~1ms of entering s2idle, which triggers pm_wakeup_dev_event and immediately wakes the system back up.

This patch skips the first 2 button events after pm_prepare. The counter resets on pm_complete so normal button handling is restored after resume.

Kernel log showing the spurious events (stock fairydust, no patch):

Jul 03 17:07:51 nimbus kernel: PM: suspend entry (s2idle)
Jul 03 17:07:52 nimbus kernel: macsmc 23e400000.smc: RTKit: syslog message: apComms.cpp:354: SMC HID Event: 01 06 01
Jul 03 17:07:52 nimbus kernel: macsmc 23e400000.smc: RTKit: syslog message: apComms.cpp:354: SMC HID Event: 01 06 00
Jul 03 17:07:52 nimbus kernel: PM: suspend exit

01 06 01 / 01 06 00 = BTN_TOUCHID press/release. This pattern repeats on every suspend attempt.

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

@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
@areofyl areofyl force-pushed the fix/macsmc-lid-polling branch from 1affd03 to 36eff9f Compare June 6, 2026 23:30
jannau and others added 26 commits June 14, 2026 22:40
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>
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.

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
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>
jannau added 16 commits June 14, 2026 22:46
…g cycles

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
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>
@oliverbestmann

oliverbestmann commented Jun 19, 2026

Copy link
Copy Markdown

With this patch, my m1pro does not wake up automatically if i open the lid (with no external screen connected). It did that before. I then need to press the power button for ~1 second for it to turn on again. Previously a short tap on the power button was enough.

@areofyl areofyl closed this Jun 19, 2026
@areofyl

areofyl commented Jun 19, 2026

Copy link
Copy Markdown
Author

With this patch, my m1pro does not wake up automatically if i open the lid (with no external screen connected). It did that before. I then need to press the power button for ~1 second for it to turn on again. Previously a short tap on the power button was enough.

Yeah I'm sorry about that. Lid wake is a known limitation of s2idle on Apple Silicon. Workqueues are frozen during suspend so the kernel can't poll the lid sensor. If it seemed to work before, it was likely a coincidence (the SMC fires spurious events that can wake the system around the same time). There's no clean fix for this without upstream changes to how the SMC delivers lid events.

@areofyl areofyl reopened this Jun 19, 2026
@areofyl areofyl force-pushed the fix/macsmc-lid-polling branch from 36eff9f to 7b924fd Compare June 19, 2026 17:04
@jannau

jannau commented Jun 19, 2026

Copy link
Copy Markdown
Member

On which device are you seeing this? I've never noticed this before and just tested this with uart and no_console_suspend on M1 Macbook Air and 14-inch Macbook Pro without seeing any issues. There is a single lid close event when closing the lid which results in s2idle (if configured so). Then nothing happens until the lid is opened which results in a single lid open event.

Please provide a description on how you noticed the issue and how your device behaves ideally with relevant kernel logs around suspend / lid events. I assume you added a log statement in macsmc_input_event(). Please provide the patch as well.

@areofyl

areofyl commented Jun 19, 2026

Copy link
Copy Markdown
Author

This is on an M1 MacBook Air (t8103) running Gentoo with the fairydust kernel. I don't have UART set up so my logs are from journalctl, but I can try to get better captures.

The issue I hit was the SMC firing a spurious BTN_TOUCHID press+release about 1ms after entering s2idle, which would immediately wake the system back up. The ignore counter in my patch skips those first 2 events so the system stays asleep.

I didn't realize lid events were being delivered reliably via notifications on other machines. On mine they seemed inconsistent, which is why I added MSLD polling. If lid wake works fine through the existing event path on MBA and 14-inch MBP, this polling approach is probably wrong and I should narrow the fix to just the spurious button handling.

I'll try to get proper logs with the stock kernel showing the spurious wake and post them here.

reviczky pushed a commit to reviczky/asahi that referenced this pull request Jun 29, 2026
With 64K page on arm64, verifier_arena_globals1 failed like below:
  ...
  libbpf: map 'arena': failed to create: -E2BIG
  ...
  AsahiLinux#509/1   verifier_arena_globals1/check_reserve1:FAIL
  ...

For 64K page, if the number of arena pages is (1UL << 20), the total
memory will exceed 4G and this will cause map creation failure.
Adjusting ARENA_PAGES based on the actual page size fixed the problem.

Cc: Emil Tsalapatis <emil@etsalapatis.com>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/r/20260113061033.3798549-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
The SMC fires a spurious BTN_TOUCHID press+release within ~1ms of
entering s2idle, which triggers pm_wakeup_dev_event and immediately
wakes the system back up.

Skip the first 2 button events after pm_prepare. The counter resets
on pm_complete so normal button handling is restored after resume.

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 7b924fd to 37faf61 Compare July 4, 2026 00:13
@areofyl areofyl changed the title macsmc-input: poll MSLD for lid state, fix spurious s2idle wake macsmc-input: skip spurious BTN_TOUCHID events on s2idle entry Jul 4, 2026
@areofyl

areofyl commented Jul 4, 2026

Copy link
Copy Markdown
Author

You were right. Lid events are delivered fine via notifications on my machine. I tested with evtest on stock fairydust and SW_LID events show up immediately on lid open/close:

Event: time 1783123862.440018, type 5 (EV_SW), code 0 (SW_LID), value 1
Event: time 1783123867.155555, type 5 (EV_SW), code 0 (SW_LID), value 0

I've dropped the MSLD polling, debounce, and sysfs attribute entirely and narrowed this to just the spurious BTN_TOUCHID fix. The SMC fires 01 06 01 + 01 06 00 (BTN_TOUCHID press+release) within ~1ms of every s2idle entry, which triggers pm_wakeup_dev_event and wakes the system immediately:

Jul 03 17:07:51 nimbus kernel: PM: suspend entry (s2idle)
Jul 03 17:07:52 nimbus kernel: SMC HID Event: 01 06 01
Jul 03 17:07:52 nimbus kernel: SMC HID Event: 01 06 00
Jul 03 17:07:52 nimbus kernel: PM: suspend exit

This reproduces every time on my M1 MacBook Air (J313) running fairydust 6.18.10. The fix just skips the first 2 button events after pm_prepare.

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.

6 participants