Skip to content

Keep Thunderbolt USB-C xHCI awake on Intel MacBooks - #7044

Open
shawnyeager wants to merge 5 commits into
omacom:devfrom
shawnyeager:fix-macbook-tb3-usb-hotplug
Open

shawnyeager wants to merge 5 commits into
omacom:devfrom
shawnyeager:fix-macbook-tb3-usb-hotplug

Conversation

@shawnyeager

Copy link
Copy Markdown
Contributor

Summary

On Intel MacBooks whose USB-C ports sit behind an Intel JHL6540 Thunderbolt 3 xHCI controller (8086:15d4), the controller runtime-suspends into D3cold after a device is unplugged. The next plug-in never enumerates — no kernel USB event, no /dev/sd*, nothing for udiskie to mount — until xhci_hcd is rebound.

This is separate from usbcore.autosuspend (already disabled by usb-autosuspend.sh). The PCI device itself is asleep.

Fix

  • New hardware script install/config/hardware/apple/fix-tb-usb-wakeup.sh
  • Installs a udev rule that sets power/control=on and d3cold_allowed=0 on 8086:15d4
  • Gated on Apple DMI + that PCI ID (2016–2017 MacBook Pro / Alpine Ridge)
  • Wired into install/config/all.sh for fresh installs
  • Migration 1786836656.sh applies the same script on existing machines

Tested

Reproduced on Omarchy 4 / MacBookPro14,3 (2017 15" T1):

  • After unplugging a SanDisk USB-C drive, both TB xHCI devices showed enable=0, runtime=suspended
  • A second USB-C drive produced no kernel events until power/control=on and an xhci rebind
  • With the udev rule, the same drive enumerated immediately as /dev/sda

Notes

T2 Macs use different Thunderbolt silicon and already have their own suspend path. This only matches JHL6540 (8086:15d4).

Copilot AI balanced review requested due to automatic review settings August 15, 2026 23:50

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an Apple Intel Thunderbolt USB‑C xHCI “keep awake” workaround by installing a udev rule and wiring it into both the installer and migrations.

Changes:

  • Add a new Apple hardware config script that installs a udev rule for Intel JHL6540 (8086:15d4).
  • Add a migration that applies the same fix via sourcing the config script.
  • Run the new fix as part of the global hardware configuration flow.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
migrations/1786836656.sh New migration to apply the Thunderbolt USB‑C xHCI wake workaround.
install/config/hardware/apple/fix-tb-usb-wakeup.sh New installer script that writes a udev rule and triggers it.
install/config/all.sh Hooks the new Apple workaround into the standard install sequence.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread migrations/1786836656.sh Resolved
Comment thread migrations/1786836656.sh Resolved
omarchybot and others added 2 commits September 28, 2026 04:54
The rule matches ACTION=="add", but udevadm trigger sends "change" unless told otherwise, so on an existing install the migration wrote the rule and left the controller free to suspend until the next boot's coldplug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xhci_pci's probe calls pm_runtime_allow() on Alpine Ridge controllers (XHCI_DEFAULT_PM_RUNTIME_ALLOW), so any probe after the add event -- a rebind, which is how the controller is recovered, or a remove and rescan around suspend -- put power/control back to auto. Matching bind as well writes it again once the driver is attached.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed, with two fixes pushed to your branch. The approach holds, and there's one question below for the maintainer.

Pushed

  • 721c0016: udevadm trigger now passes --action=add. The rule only matches add, but udevadm trigger sends change by default, so on an existing install the migration wrote the rule and left the controller free to suspend until the next reboot. I checked this on a QEMU worker, with your rule pointed at the VM's own xHCI controller. Without --action=add, power/control stayed auto. With it, power/control became on and d3cold_allowed became 0.
  • f9877b7e: the rule now matches ACTION=="add|bind". On 8086:15d4, xhci_pci_common_probe() calls pm_runtime_allow() (the XHCI_DEFAULT_PM_RUNTIME_ALLOW quirk), so every probe after the add event sets power/control back to auto. That includes rebinding xhci_hcd, which is how you recovered the port, and the remove and rescan that suspend workarounds like fix(hardware): prevent ~130s sleep wake stall on MacBook Pro 2016-2017 #9899 and Suspend on 2016-2017 MacBook Pros: keep USB-C and Thunderbolt working across S3 #11570 do. The kernel sends bind after probe finishes, so the rule now reapplies both settings at that point. On the worker, an add-only rule left auto after an unbind/bind, and add|bind left on and 0.

Checked

  • On the worker at f9877b7e, the repository suite (test/omarchy-cli-test.sh) passed, 60 of 60.
  • The migration writes nothing on a non-Apple machine.
  • With the Apple DMI vendor and 8086:15d4 faked, the migration writes the rule, udevadm verify accepts it, and a second run is a clean overwrite.
  • The migration follows the base branch's rules: mode 0644, a leading echo, and $OMARCHY_PATH.

The unplug bug itself needs a JHL6540 MacBook, so it was not reproduced here. Your report is the only evidence so far.

Codex Medium gave a second opinion over two rounds. It found the bind reset: I had not reasoned about it, and I confirmed it in the kernel source. It agreed with the trigger fix. Its last round, on f9877b7e, found nothing more. It can read this session's working files, so where it simply agreed, that isn't guaranteed to be independent.

Open

  • For the maintainer: this targets dev, which is 3.8.5, but the report says it was reproduced on Omarchy 4. Merged only to dev, it never reaches quattro users. A quattro port would go in install/hardware/apple/, wired through install/hardware/all.sh, since the hardware scripts have moved there.
  • For @shawnyeager: could you confirm the port still enumerates after an unplug with the rule at f9877b7e in place? Also, does d3cold_allowed=0 alone fix it, without power/control=on? If it does, the fix could keep runtime suspend and cost less battery.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed a4caa97. Running the leaf with bash instead of source is correct, and nothing new was found.

Checked

  • The migration now matches how migrations/1759913695.sh and migrations/1755494432.sh run their hardware leaves. bin/omarchy-migrate on dev runs each migration with bash and no errexit, so a failure propagates the same way as before.
  • On a QEMU worker at a4caa97, the repository suite (test/omarchy-cli-test.sh) passed, 60 of 60.
  • The migration was run as omarchy-migrate runs it, bash migrations/1786836656.sh. On the worker's own hardware it wrote nothing and exited 0. With the Apple DMI vendor and 8086:15d4 faked, it wrote the rule, udevadm verify accepted it, and a second run was a clean overwrite. sys_vendor no longer reaches the calling shell.

Codex Medium reviewed the new commit and the whole PR, and found nothing. It agreed with the conclusions above, and since it can read this session's working files, that agreement is not guaranteed to be independent.

Waiting on

@shawnyeager, or anyone with a 2016–2017 MacBook Pro that has the JHL6540 controller (lspci -nn | grep 8086:15d4). The unplug bug can't be reproduced without that hardware. Could you test the exact head, a4caa97? From a checkout of this branch:

git fetch https://github.com/shawnyeager/omarchy fix-macbook-tb3-usb-hotplug
git checkout a4caa97e026ec580a94fe3853a9f159f1d8b5b62
bash install/config/hardware/apple/fix-tb-usb-wakeup.sh
grep . /sys/bus/pci/devices/*/power/control | grep -f <(lspci -Dnd 8086:15d4 | cut -d' ' -f1)

The last line should print on for each controller. Then plug in a USB-C drive, unplug it, wait a minute, and plug in another. Reply with whether the second drive appears in lsblk. To undo it, run sudo rm /etc/udev/rules.d/99-omarchy-apple-tb-usb-wakeup.rules and reboot.

The dev versus quattro question from the earlier comment is still open for the maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants