Repository navigation
J700: allow USB wake from s2idle (AIC wake IRQs, dwc3-apple wake IRQ + running xHC, VL122, mt7932 wakeup flag) - #304
Closed
RyanTheTide wants to merge 14 commits into
Closed
RyanTheTide wants to merge 14 commits into
RyanTheTide wants to merge 14 commits into
Conversation
Neither the AIC nor the AIC2/AIC3 irq_chip implements .irq_set_wake or sets IRQCHIP_SKIP_SET_WAKE, so irq_set_irq_wake() fails with -ENXIO for every hardware interrupt on Apple silicon. Drivers that arm their interrupt for wakeup, directly or through dev_pm_set_wake_irq(), are silently left without a wake interrupt: dev_pm_arm_wake_irq() ignores the error, suspend_device_irqs() then disables the line like any other, and an event on it cannot end suspend-to-idle. Only interrupts requested with IRQF_NO_SUSPEND, such as the Apple mailbox interrupts that carry the SMC lid and power button events, are still delivered, which is why those are the only things that wake these machines today. Suspend-to-idle is the only system sleep state on these SoCs. The AIC stays powered in it and delivers unmasked interrupts to the CPUs idling in WFI as usual, so there is no wake logic to program. Set IRQCHIP_SKIP_SET_WAKE on both chips, like the GICv3 driver does, so that enable_irq_wake() succeeds and the IRQ core keeps wake-armed interrupts enabled and turns their next event into a system wakeup. IRQCHIP_MASK_ON_SUSPEND is deliberately not set. The IRQ core already disables the non-wake interrupts lazily, and masks and records any that fire during suspend so they are replayed on resume. Masking them in hardware up front gains nothing on a controller that has no separate wake path, and would risk losing events from the edge-like MSIs that the PCIe controller delivers through the AIC. The FIQ chip is left alone: it only carries per-CPU timer, PMU and fast IPI interrupts, none of which are system wake sources. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
USB devices cannot wake an Apple silicon machine from suspend-to-idle. The glue device is never made wakeup capable, so dwc3_core_probe() records sys_wakeup = false, dwc3_host_init() leaves the xHCI platform device with wakeup disabled, and xhci_suspend() clears the root port wake bits. Nothing arms the controller interrupt for wakeup either, so suspend_device_irqs() disables it like any other device interrupt. The core itself is already kept running across system sleep whenever it is up (it is a syscore device, see dwc3_apple_init()), so the controller is in a state to report port events. What is missing is the wakeup policy and the wake interrupt: - Initialise the glue device as a wakeup source, enabled by default as usb_hcd_pci_probe() does for PCI host controllers. This happens before the first dwc3_core_probe(), which then passes the setting on to the xHCI device as on other dwc3 platforms, so xhci_suspend() keeps the root port wake-on-connect/disconnect/overcurrent bits and the root hubs stay armed for remote wakeup. Userspace can still turn it off through the power/wakeup attribute of the glue device. - While the controller is in host mode, register the core interrupt, which xHCI shares, as the wake interrupt of the glue device, and drop it again when host mode is torn down. The PM core arms it in the noirq phase when wakeup is enabled. Device mode gets no wake interrupt: a gadget is resumed by its host, and arming bus activity there would only cause spurious wakeups. This needs the AIC to accept enable_irq_wake(), which "irqchip/apple-aic: Allow interrupts to wake the system" provides; before it, the interrupt could not be armed at all. Not yet verified on hardware: whether this DWC3 integration raises its interrupt for a port status change after xhci_suspend() has halted the controller (the xHCI specification leaves wake signalling from the halted state to the platform). If it does not, the wake interrupt is armed but never fires, behaviour is otherwise unchanged, and a follow-up has to find the platform wake path instead. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The driver sets no hdev->wakeup callback, so hci_register_dev() leaves
HCI_CONN_FLAG_REMOTE_WAKEUP out of the supported connection flags.
bluetoothd marks paired HID devices as wake-allowed and is refused
("Bad flag given (0x1) vs supported (0xe)") for each of them on every
boot, and hci_suspend_sync() always takes the disconnect-only path.
Return device_may_wakeup() of the PCI function, as hci_bcm4377 does for
the Bluetooth function of the other Apple PCIe combo chips. The flag is
then supported and the setting is honest: wakeup on the PCI function is
off by default, so by default suspend behaves exactly as before. When
userspace enables it, hci_suspend_sync() additionally leaves page scan
and LE passive scan set up for the devices flagged for remote wakeup
before bt7932_suspend() quiesces the transport.
This does not make Bluetooth wake the system yet. What is still
missing, none of which can be verified today:
- bt7932_suspend() quiesces the firmware with the quiesce/restore
handshake. It is not known whether the firmware keeps scanning in
that state and signals the host when a wake-enabled device connects.
- Nothing arms the MSI vector for wakeup, and it could not be armed:
the pcie-apple MSI chips implement no irq_set_wake, so
enable_irq_wake() fails on the MSI as it did on every AIC interrupt.
- pcie-apple has no WAKE# handling, and whether a PME from the function
reaches a host interrupt in suspend-to-idle has not been tested.
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The VIA Labs VL122 USB 2.0 hub (2109:2122) on the J700 never signals a downstream connect while it is runtime suspended, so it was given USB_QUIRK_IGNORE_REMOTE_WAKEUP. That kept it out of runtime suspend, but it also leaves the hub without a wakeup setting at all, so it is never armed for remote wakeup in system sleep. Every USB 2.0 keyboard and mouse on the machine sits behind this hub, so none of them could wake it. The problem is runtime PM, not remote wakeup: mark the hub with HUB_QUIRK_DISABLE_AUTOSUSPEND, as is done for other hubs with broken runtime suspend, and drop the device quirk so its wakeup setting is available again for system sleep. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
xhci_suspend() halts the controller (clears USBCMD.R/S) and saves its state. A halted xHC writes no events to its event ring, so it raises no interrupt either: wake events from a halted controller are a separate signal, which on PCI is PME# and on other platforms a PHY or glue wake interrupt (dwc3-qcom, dwc3-imx8mp, xhci-mtk, xhci-tegra all have one). A platform without such a signal cannot be woken by USB devices from system sleep at all, even when it keeps the controller powered and its interrupt armed for wakeup. For suspend-to-idle there is a simple way out: do not halt the controller. The root hubs are still bus suspended with their wake bits set, so the ports are in U3 and downstream devices are armed for remote wakeup, but a remote wakeup or port change now raises a Port Status Change Event and with it the interrupt, which wakes the system once the platform arms it with enable_irq_wake(). Add a property, "xhci-run-in-s2idle", for glue drivers to request this. xhci-plat then skips xhci_suspend() and xhci_resume() across a system suspend when the target state is suspend-to-idle and the controller may wake the system with a wakeup source below it, the same way it already leaves the controller alone while a sideband instance is active. In all other cases, including hibernation and when wakeup is disabled through power/wakeup, the controller is halted as before. Event handling needs nothing new: until the interrupt is suspended an event goes through xhci_irq(), whose usb_hcd_resume_root_hub() reports a wakeup event and aborts the suspend; once it is armed for wakeup, the first interrupt ends suspend-to-idle and is handled when device interrupts are resumed. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Add a dwc3 software property for glue drivers whose controller stays powered in suspend-to-idle but has no wake signal besides the core interrupt, and pass it on to the xHCI platform device as "xhci-run-in-s2idle". The property array now holds up to seven entries, so make room for them and for the terminating empty entry. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
With the core interrupt armed for wakeup, USB devices still cannot wake the J700 (T8140) from suspend-to-idle. Tested with a USB keyboard behind the on-board VL122 hub and an external hub, with the whole chain from the root hub to the keyboard set to power/wakeup=enabled: a keypress lights the keyboard up again, so it signals remote wakeup and its hubs pass it on, but the xHCI interrupt never fires during the sleep. The reason is that xhci_suspend() halts the controller. A halted xHC writes no events and raises no interrupt; a remote wakeup is then only visible as a platform wake signal, and this controller has none: the DWC3 node has a single interrupt, and the Type-C PHY has none. The core and its power domain are kept up across system sleep anyway (it is a syscore device while it is up), so ask xHCI to keep running in suspend-to-idle when it may wake the system. The remote wakeup then raises a Port Status Change Event on the running controller, and the core interrupt, already armed as the wake interrupt in host mode, ends suspend-to-idle. Not yet verified on hardware with this change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Move the mapping of boolean device properties to quirks, and the decision whether to keep the controller running in suspend-to-idle, into helpers that do not need a probed controller, and test them: every property maps to its quirk, "xhci-run-in-s2idle" included, and the controller keeps running only for suspend-to-idle with the quirk set, wakeup enabled and a wakeup source below it. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Move the filling of the property array for the xHCI platform device into dwc3_host_xhci_properties() and test it: "xhci-run-in-s2idle" is passed on only when the glue asks for it, and with every optional property set the array still ends in an empty entry. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Test that the VL122 hub (2109:2122) no longer has USB_QUIRK_IGNORE_REMOTE_WAKEUP and gets HUB_QUIRK_DISABLE_AUTOSUSPEND instead, and that neighbouring entries still match as before. Move the HUB_QUIRK_* flags to hub.h and add small accessors for the device quirk list and the hub id table that the test can call. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Suspend several times with an RTC alarm (rtc1, the PMU RTC, on the J700) and check after each resume that the sleep lasted until the alarm, that suspend_stats reports no failures, that every USB device is back, that the power/wakeup settings of USB devices, xHCI and DWC3 are unchanged, and that the log has no xHCI resume errors, warnings or oopses. Needs no one at the machine. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
apple_dart_resume() resets every DART on resume, clearing its page table pointers and disabling translation before restoring the saved values. That is only correct when the DART lost power. A DART whose power domain stayed on still has its state, and may still be translating for a consumer that kept running through the sleep: dwc3-apple keeps its core up across system sleep as a syscore device, which holds the shared power domain on, and with xHCI now left running in suspend-to-idle the controller can write events or touch its scratchpad while the DART is resumed. A DMA that hits the reset window faults, and xHCI halts on a Host System Error. Compare the translation registers with the values saved at suspend. When they still match and at least one page table is valid, the DART did not lose power: leave it alone and only invalidate its TLBs. Otherwise reset and restore it as before. A powered-off DART reads back with no valid page table, so it always takes the reset path. The TLBs are flushed with one command per stream rather than one command for a map of all streams. Where the streams of a map are remapped onto its first stream, a map flush only reaches that first stream, which would leave stale entries of every other stream behind. Two consequences beyond the USB case: - The suspend and resume callbacks are shared by runtime PM and system sleep. Every runtime resume of an unlocked DART whose power domain stayed on now also skips the reset and only invalidates the TLBs. This applies to all DARTs the driver handles, on other Apple SoCs as well, including the t8110 ones. - "Retained" is judged only by TCR and TTBR matching the values saved at suspend. On that path the error status and the stream enables are no longer reset; they are left as the DART kept them. The KUnit tests added here need "iommu: apple-dart: Fix the KUnit test after deferred root publication" underneath to build with CONFIG_APPLE_DART_KUNIT_TEST. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…-idle When the controller was left running in suspend-to-idle, resume skips xhci_resume() on the assumption that it is still running. Nothing checks that assumption. If the platform cut power after all, or the controller halted on a Host System Error or Host Controller Error during the sleep (for example a DMA fault while its IOMMU was being resumed), the root hubs are then resumed on a dead controller and USB stays gone until the next cable or role change. Read USBSTS on resume and, when the controller is halted, reports an error, or reads back as all ones, bring it up from scratch through xhci_resume() with power_lost set, as for a controller that lost power in a deeper sleep state. A controller that is still running is left alone as before. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
… wakeup The VIA Labs VL122 USB 2.0 hub on the Apple J700 does not pass a remote wakeup from a downstream device upstream while it is suspended itself, the same limitation that makes it miss downstream connects in runtime suspend. With the whole chain armed and the xHC running in suspend-to-idle, a keypress on a keyboard behind it never reaches the root port: PORTSC stays in U3 without a link state change, with the keyboard behind a dock and behind a plain USB 2.0 hub alike. The hub does see the resume while it is awake: an active hub completes a downstream resume on its port and reports it through its status change endpoint. Keep such a hub awake in suspend-to-idle when a device below it may wake the system, as the USB offload support already does for devices that stay in use. Every device between it and the root hub, the root hub included, stays awake too, so that the root port stays in U0 and the running controller keeps polling the hub's interrupt endpoint. The devices below the hub are suspended as before. A remote wakeup then completes a transfer on the hub's status endpoint, and the controller interrupt, armed for wakeup, ends suspend-to-idle. This needs a controller that keeps running in suspend-to-idle; xhci-plat says so through a new runs_in_s2idle flag of struct usb_hcd. Mark the VL122 with a new USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP; it keeps HUB_QUIRK_DISABLE_AUTOSUSPEND for runtime PM. The cost is an active hub and an active root port while a wake source sits below the hub. Tested on the J700 with a USB keyboard behind the VL122 and a dock, lid open and closed: a keypress ends suspend-to-idle through the xHCI interrupt, 3.7 s from entering suspend when pressed right away. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
This was referenced Oct 15, 2026
Merged
Contributor
Author
|
Superseded by #340 (v4.1 after five review rounds and Sashiko, rebased on aurora-wip, merged). This PR's head is the pre-review line, so it is closed rather than merged. The branch is kept. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the MacBook Neo (J700), only lid-open and the power button can wake the machine from s2idle. In clamshell mode, USB keyboards and mice on a dock can't wake it, and Bluetooth HID can't either. Observed 2026-10-15: lid closed with an external display, suspended, the USB keyboard and mouse did nothing, opening the lid woke it, and bluetoothd logged
Controller resume with wake event 0x0.Root causes
irq-apple-aic.c: neitheraic_chipnoraic2_chiphas.irq_set_wakeorIRQCHIP_SKIP_SET_WAKE, soirq_set_irq_wake()returns-ENXIOfor every hardware IRQ.dev_pm_arm_wake_irq()ignores that error,suspend_device_irqs()disables the line, and nothing can end s2idle. OnlyIRQF_NO_SUSPENDmailbox IRQs survive, and those carry the SMC lid and power-button events. No upstream fix exists: AsahiLinux/linuxasahiand torvalds/linuxmasterhave the same chip definitions.xhci_suspend()clears USBCMD.R/S and saves state. A halted xHC writes no events to its event ring, so its interrupter raises nothing. Wake from a halted xHC is a separate signal: PME# on PCI, or a PHY/glue wake interrupt elsewhere (dwc3-qcomdp/dm_hs_phy_irq+ss_phy_irq, dwc3-imx8mp glue wakeup IRQ, xhci-mtk IPPC wakeup via syscon, xhci-tegra pad wake events through the PMC). Apple's DWC3 has none: theusb@40a280000node has exactly one interrupt on J700 (and every Asahiapple,t8103-dwc3node has one), atcphy has none, and m1n1 parses no wake property from the ADTusb-drdnodes.USB_QUIRK_IGNORE_REMOTE_WAKEUP, which also takes away its wakeup setting for system sleep. Every USB 2.0 keyboard and mouse sits behind it.Changes (one commit each)
IRQCHIP_SKIP_SET_WAKEon the AIC and AIC2/3 chips, the same as GICv3. s2idle is the only sleep state on these SoCs, and the AIC stays powered in it, so there's no wake logic to program.IRQCHIP_MASK_ON_SUSPENDis deliberately left off (the commit message says why), and so is the FIQ chip.usb_hcd_pci_probe(). It is set up beforedwc3_core_probe(), sosys_wakeupcarries the setting to the xHCI device andxhci_suspend()keeps the root-port wake bits. In host mode only, the core IRQ that xHCI shares is registered withdev_pm_set_wake_irq(), and it is cleared when host mode is torn down. The core already stays powered across sleep (syscore), so it needs no PM ops.hdev->wakeupreturnsdevice_may_wakeup()of 01:00.1, the same ashci_bcm4377. This putsHCI_CONN_FLAG_REMOTE_WAKEUPin the supported flags and ends the fourBad flag given (0x1) vs supported (0xe)messages per boot. PCI wakeup is off by default, so suspend behaviour doesn't change by default.HUB_QUIRK_DISABLE_AUTOSUSPENDinhub_id_tableinstead, as for other hubs with broken runtime suspend, so the hub's wakeup setting is available again for system sleep.xhci-run-in-s2idle(quirkXHCI_RUN_IN_S2IDLE). When it is set, the target state is s2idle, and the xHCI device may wake the system with a wakeup source below it (device_may_wakeup() && device_wakeup_path()), xhci-plat skipsxhci_suspend()/xhci_resume(), the same way it already skips them while a sideband instance is active. Root hubs are still bus-suspended with their wake bits set (ports in U3, devices armed for remote wakeup), but a remote wakeup now raises a Port Status Change Event, and with it the interrupt. Hibernation, S3-style targets and wakeup-disabled suspends halt the controller exactly as before. No new event handling is needed: before the IRQ is suspended,xhci_irq()→usb_hcd_resume_root_hub()reports a wakeup event and aborts the suspend; once it is wake-armed, the first IRQ ends s2idle and is replayed when device interrupts resume.dwc3_properties.xhci_run_in_s2idlebit, passed to the xHCI device as the property above. The property array grows to hold the new entry plus the terminating one.Checked and left unchanged
IRQCHIP_SKIP_SET_WAKE, and the parent AIC IRQ is chained. Chained IRQs are never suspended, sodockchannel_init_wakeup()already works without the AIC change.Update 2026-10-15 evening: final line (head 94ae820)
New on top of the seven changes above:
8. usb: xhci: plat: Add KUnit tests for property quirks and suspend-to-idle, usb: dwc3: Add KUnit tests for the xHCI device properties, usb: core: Add KUnit tests for the VIA Labs VL122 hub quirks (LOW).
9. tools: aurora-wake: Add an unattended suspend-to-idle regression test (LOW).
10. iommu/apple-dart: Do not reset a DART that kept its state across sleep (HIGH).
- A DART whose registers survived sleep is left alone and only its TLBs are invalidated, one command per stream. Without this, a DMA from the running xHC could hit the reset window and halt it on a Host System Error.
- This changes resume and runtime PM for every Apple DART, on other SoCs too.
11. usb: xhci: plat: Reinitialise a controller that stopped in suspend-to-idle (MED). USBSTS is checked on resume.
12. usb: core: Keep a hub awake in suspend-to-idle when it cannot pass on wakeup (HIGH). The VL122 does not forward a downstream remote wakeup while it is suspended. It is now kept awake with its path to the root port; the devices below it still suspend. Quirk
USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP, plus aruns_in_s2idleflag on the HCD.Dropped as proven redundant: the earlier "keep the USB 2.0 PHYs awake" commits (892a507a0 / e856ac6da).
The VL122 wording was corrected: the hub's limitation is forwarding remote wakeup and connects while suspended, not runtime suspend as such.
Hardware results
Attended (USB agent and Ryan, 2026-10-15):
Unattended (integration release7, 7.1.12-aurora-rel-g586e9b6fb = aurora-wip content plus this line plus USB polish plus clamshell-mic):
tools/aurora-wake/s2idle-rtc-regression.sh -c 5 -s 20passed 5/5 twice, without-i: the DCP-22is fixed in drm/apple: fix resume with an external display, hold DCP messages in s2idle, DP polish #313.dcp-s2idle-regress.sh6/6), camera at 30 fps, audio, mics and speakerguardd fine, Touch ID listed 3 prints, NVMe and storage in-flight 5/5, Wi-Fi e2e passed on both bands.Not merged yet: validation pending
🤖 Generated with Claude Code