Skip to content

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

Open
shawnyeager wants to merge 14 commits into
omacom:quattrofrom
shawnyeager:fix-macbook-tb3-usb-hotplug
Open

shawnyeager wants to merge 14 commits into
omacom:quattrofrom
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).

pkwagner and others added 11 commits June 19, 2026 18:05
* Add QR code capture

* Keep the decoded QR value on the clipboard only

Freeze the screen before selecting like the other region captures do,
restrict decoding to QR so stray barcodes can't take the clipboard, and
stop echoing the decoded value to stdout and the notification, since an
otpauth:// secret would otherwise land in the journal and notification
history.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Mark the copied QR value as sensitive

Clipboard history records every selection, so the otpauth:// secret this
command is built to capture would survive in it. --sensitive offers the
x-kde-passwordManagerHint type that the clipboard capture skips on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: David Heinemeier Hansson <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
* Offer the Quattro upgrade from the Update menu

Ship omarchy-upgrade-to-quattro as a command on the dev branch and add
an "Omarchy To Quattro" entry under Update, so the upgrade can be
started from the menu instead of curl | bash.

The Quattro case comes before the *Omarchy* case because the existing
glob would otherwise swallow the new label. The script is the copy that
already ships on rc, so the two branches stay identical.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Invite the Quattro upgrade once after updating

Send a one-time notification when this version lands, and add the mako
rule that turns it into a click target for omarchy-upgrade-to-quattro,
the same way the Wi-Fi, update, and Voxtype invitations work.

The migration tolerates a missing session so an update run without a
desktop doesn't fail on the notification.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Set the version to 3.8.5

dev sits on the Omarchy 3 line alongside master and rc, but its version
file had been bumped to 4.0.0.alpha, so anything reading it reported a
release this branch does not carry. rc moves to 3.8.5 alongside this.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Kernel 7.1 unpacks the initramfs asynchronously, which races /init: the
early /proc, /sys, /dev, and /run mounts fail while unpacking settles, so
plymouthd exits when it can't read /proc/cmdline and encrypted boots fall
back to an unthemed text LUKS prompt. Pin initramfs_async=0 in the Limine
defaults for fresh installs, and drop it into a Limine config plus a UKI
rebuild for existing ones.

Co-Authored-By: Claude Opus 5 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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.

@makoni

makoni commented Nov 25, 2026

Copy link
Copy Markdown

Thanks for tracking this down. The diagnosis that the controller is asleep matches what I see on my MacBookPro14,3, and the cause turns out to be in the kernel, with an upstream fix now queued.

On Apple machines Linux skips _OSC and takes control of every PCIe feature except PME, so no root port runs the PME service. When a device is plugged in, the runtime-suspended xHCI raises PME# and nothing services it. The PCI core's PME poll skips the xHCI while the downstream port above it is suspended too.

Upstream 2d89ca89b01f ("ACPI: PCI: take native PME control on Apple machines"), which Rafael Wysocki queued in linux-pm for 7.5, fixes this. I opened omacom/omarchy-pkgs#3475 (draft) to carry it in linux-omarchy.

I tested it on a MacBookPro14,3 with no udev rule and the kernel's default runtime PM. Here both Alpine Ridge xHCIs and the ports in front of them sit in D3hot rather than D3cold. With the patched kernel, a USB 3 SSD enumerated within a quarter of a second of the root port's PME interrupt, on both controllers. It did so again after an s2idle cycle, once I had set the re-created bridges back to auto. On the stock 7.2.15-4 kernel, with the same bridges at auto, the plug-in produced no kernel message at all. I haven't repeated your exact unplug-then-replug on one controller. Details are in omacom/omarchy-pkgs#3475.

This rule shouldn't conflict with the kernel fix, though I haven't run the two together. It is still useful until a kernel carrying the fix ships, and on the 14,3 it shouldn't be needed after that.

@omarchybot
omarchybot changed the base branch from dev to quattro November 25, 2026 17:24
@omarchybot

Copy link
Copy Markdown
Collaborator

Retargeted this to quattro, the current default branch. The head is still a4caa97e026ec580a94fe3853a9f159f1d8b5b62, but it carries eight unrelated non-merge dev commits absent from quattro, including 40748ce113 (the 3.x upgrade path) and ce9b70988a (the 3.x update filter). The PR now has conflicts. A port also needs to adapt the hardware leaf and its callers to install/hardware/apple/ and install/hardware/all.sh.

GPT-6 in Codex (effort not exposed) checked the diff, ancestry, callers and related PRs. Opus 5.5 High and muse-wonder via pi, thinking high reviewed the same history and overlapping diffs and agreed that this needs a maintainer decision; that agreement is not guaranteed independent. #15537 covers MacBookPro14,1 and adds root-hub/resume handling, so neither PR fully replaces the other. #11570 addresses the separate S3 recovery case.

No code was pushed and no new worker tests ran: the queue rules stop an automatic port when the branch carries unrelated dev history. The September worker results against dev do not validate a quattro port. Hardware confirmation of this exact head is still missing; the November report tested the different kernel patch in draft omacom/omarchy-pkgs#3475.

Waiting on the maintainer to decide how to carry the hardware fix forward without the unrelated history. Any resulting port needs current-base checks and confirmation on affected hardware.

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.

8 participants