Skip to content

soc: apple: sleep: T6040 (M4 Pro, J616s) suspend-to-RAM - #2215

Merged
RyanTheTide merged 107 commits into
aurora-silicon:mainfrom
fbalazsy:t6040-sleep
Nov 29, 2026
Merged

RyanTheTide merged 107 commits into
aurora-silicon:mainfrom
fbalazsy:t6040-sleep

Conversation

@fbalazsy

@fbalazsy fbalazsy commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What: suspend-to-RAM on the T6040 (M4 Pro, J616s): the sleep controller's entry and wake sequences, with the board data and register windows in the device tree, and the display pipes, Type-C USB hosts, PCIe ports, GPU firmware and radios brought back after the wake. Current main is merged in.

Tested: J616s M4 Pro (T6040) at 5467f0f9f694, default command line: suspend-to-RAM 5/5 pass, suspend_stats success 5 fail 0, no err-level kernel line, connectors, Wi-Fi, SD, NVMe and Bluetooth back after every wake, 0 failed units. Builds with no new warnings (also W=1 on the changed objects), checkpatch.pl --strict clean, dtbs_check clean on all seven T6040/T6041 boards, the Apple display KUnit suite 146 of 147 pass and 1 skipped, the host tests fail only where main fails on the same toolchain. This run had HDMI attached; the panel and DP over Type-C were covered by the row at 27adf9ac (5/5, three displays). dt_binding_check is clean too.

Risk: one-way (adds DT bindings) · M4 Pro; the shared Apple drivers it changes (sleep core, DCP, DART, PCIe host, NVMe, dwc3 glue, SMC, MCC, BCM4377, brcmfmac) run on all Macs

Not yet: other Macs (none here with these blocks; the T6040 sleep refuses a watchdog or a board it does not know, see below); hibernation is not part of this series.

Details

Adds the T6040 (M4 Pro, J616s) to the sleep driver in the way the T6050 is carried: the entry and wake sequences in sleep-t6040.h wired to the core ops, with the board data and every register window in the device tree and the binding.

On top of the sleep controller itself:

  • the AP pins are put back after the wake by the core's existing apple,pinctrl restore (apple,pinctrl-skip-pins for the pins the sleep leaves alone);
  • the PMP firmware's data range is kept over the sleep (apple,sram-keep);
  • the GP PCIe port clocks are restored with the host disabled in the device tree, whose port DARTs stay bound;
  • the GPU firmware is restarted after the wake;
  • the entry is enabled on the J616s.

Display. The internal and both external display pipes are stopped before the sleep and restarted after it by the display driver:

  • the display power words come from the device tree (apple,t8140-display-power gains the T6041);
  • T6040's external DCPs are brought back after the wake, their links set up again from a work item, with DRM kept off an external firmware until its link is back, and the DP PHYs of the HDMI converter and of an active Type-C route given back for the sleep, so that the connect after the wake powers them on and trains the link again;
  • a desktop 26.x external pipe is powered on before a mode set on its active CRTC;
  • the stop waits on what the hardware and the firmware report (the lowered power words, the DCP's idle state, the firmware's DART-off notification) instead of fixed delays.

USB. A Type-C port's xHCI host is kept over the sleep when nothing else uses the PHY: the PHY holds the controller in reset with its sides down, and at the wake the controller and the PHY are set up again and xHCI starts over, so the USB core reset-resumes the devices. They keep their device numbers and their block and network devices; nothing is disconnected or enumerated again. The power domains of the PHY and the controller go off during the sleep, so the root hubs do lose power and a reset-resume is the lightest resume available. A port that carries DisplayPort, a four-lane DP mode or USB4 is still stopped and started as before. The dwc3 glue now suspends and resumes asynchronously, so the hosts no longer wait for the display's resume.

Merge of main. Four files conflicted; both sides are kept in each (details in the merge commit):

  • hci_bcm4377.c: both sides stopped treating a deferred reprobe after a command timeout as a failure;
  • dcp.c: the T6041 display power note and main's iBoot-only probe, which returns before the note as it did on main;
  • pcie-apple.c: both new fields; main replaced the cold-train helper with apple_pcie_adopted_link_trained_by();
  • t6040-usb2.c: this series' suspend, resume, freeze, poweroff and restore callbacks, now also calling main's suspend-to-idle helper from .suspend and a new .suspend_noirq. The helper returns early for a sleep the platform takes part in, so suspend-to-RAM is unchanged.

The PHY series includes a commit by @RyanTheTide (busy recovery domain handling), cherry-picked with his authorship.

The commit messages were later reworded without changing any tree: 17137a07e2c4 and 27adf9ac were 3f6abac57c40 and 1c958d23, where the results below were recorded.

Since the merge.

  • drm/apple: Report a display back to the T604x wake only on T604x: dcp_hotplug() completed t6041_plugged on every DCP, but dcp_start() initialises it only after the T8132 firmware's early return, so a T8132 DCP and the KUnit hotplug fixture completed an uninitialised completion (the three failing apple-display-hotplug cases). It is now completed only where dcp_t604x_relinks() is true, the only case in which dcp_t6041_recommit() waits for it.
  • four test updates for changes in this series that the host tests had not followed: the bcm4377 resume fixture asks the PCIe host whether power was lost, the native26 retrain test keeps the unlisted mode case to T604x, the brcmf suspend fixture has the link down completion, and the apple-dcp dwc3 teardown fixture has the dwc3-apple match data.

Since the review.

  • soc: apple: sleep: t6040: Take the VDD_CIO request from the device tree: the SMC pmVC request is an optional DT property (apple,vdd-cio-request), documented in the binding and set to 0x101 on the J616s, instead of a value chosen from the board name. A board without it warns once and makes no request.

  • drm/apple: Release the T604x display-power phandle on unload: dcp_unregister() now puts the apple,display-power phandle the first DCP kept.

  • PCI: apple: Drop the s2r_conventional parameter: whether the ports lose power in the sleep is now only the host's match data and its DT (no tunnel, no managed SIDs, no PIO DMA supplier, not root-bus only).

  • drm/apple: Ask the T6040 Type-C PHY for its DP tunnel clock by name: the T6040 PHY exports apple_t6040_dp_tunnel_rate() instead of defining the ATC PHY's symbols when that driver is not built, so both PHYs can be built together. The display driver asks the T6040 PHY first and the ATC PHY when the PHY is not the T6040's (-ENODEV).

  • soc: apple: sleep: t6040: Refuse a watchdog the wake stub does not restart: probe fails when the DT's watchdog is not the AON one the wake stub restarts, instead of falling back to a resume that the watchdog would reset.

  • soc: apple: sleep: t6040: Take the GP PCIe ports from the DT: the GP host's ports come from its child nodes (J616s: 0 and 1, as before); up to four.

  • soc: apple: sleep: t6040: Pass the board's VDD_CIO request to the SMC: pmVC's value is the caller's; the T6040 sends the J616s's 0x101 only on the J616s and warns on any other board.

  • smaller ones: the AOP power word listed twice, dwc3 match data checked, the unused Type-C PHY sleep wrappers dropped, the HDMI +5 V rail kept on when its PHY fails to come back (as the sleep entry leaves it), a comment on the SMC's polled replies after the noirq resume (the poll and the interrupt drain the mailbox under one lock), and two comment and kernel-doc fixes.

This series includes nine commits from #1664 by @AxxzyWasTaken (the G17 GPU sleep and the T6041 display stop/restart with its DART helper), cherry-picked unchanged with their original authorship, so that the series can be built and tested on its own. They will be dropped once #1664 lands.

Known: the longer resume is the USB core's reset-resume of the hubs behind the kept ports (port power-on and debounce times, about 0.4 s per hub level); the devices are usable as soon as it ends.

Evidence

At 17137a07e2c4 (merge of main 037f7bca6822 into 27adf9ac), J616s, 26.6.2 boot firmware, one-shot test boot with the default arguments plus panic=10 (loglevel=7 instead of loglevel=3 quiet):

  • build: 0 errors; no warning in a file this series changes;
  • checkpatch.pl --strict on the four merged files against main: 0 errors, 0 warnings, 0 checks;
  • boot: apple-sleep 502888000.sleep-controller: deep sleep is the default, /sys/power/mem_sleep = s2idle [deep];
  • systemctl --failed: 0 units; no SELinux on this install;
  • err-level kernel log after boot: one line, the SEP's "matching unavailable this boot", which the release kernel on this Mac logs too;
  • suspend-to-RAM: not run yet at this head.

After it, at the current head (the five commits above), not on hardware:

  • Apple display KUnit suite (display.kunitconfig, arm64, LLVM): 147 cases, 146 pass, 1 skipped; the hotplug cases hotplug_connected, hotplug_forced_off and hotplug_without_hpd no longer oops;
  • host tests: bcm4377 resume (47 controls and its 5 mutations), brcmf suspend (38 controls and its 8 mutations), native26 retrain (with its negative control) and the apple-dcp dwc3 teardown pass; every other host test gives the same result as on main;
  • iomfb.o builds with W=1 and no warning; checkpatch.pl --strict on the five commits: 0 errors, 0 warnings, 0 checks.

At 27adf9ac, J616s, 5 suspend-to-RAM cycles in one boot (rtcwake -m mem), with the panel, DP over Type-C and HDMI attached:

check result
rtcwake return code 0 in 5/5
/sys/power/suspend_stats success 5, fail 0
DRM connectors (status, enabled) after the wake same as before in 5/5
Wi-Fi ping after the wake ok in 5/5
SD reader, NVMe after the wake present in 5/5
err-level kernel lines Bluetooth headset reconnects only (ACL packet for unknown connection handle, one failed HCI command)

Earlier, on the series before main moved: two suspend-to-RAM cycles with a USB disk (read-only), an Ethernet dock and two external displays (DP over Type-C, HDMI):

USB hosts stopped for the sleep USB hosts kept (final)
dpm_prepare 338–369 ms 32–35 ms
freeze → CPUs off 1.29–1.32 s 0.99 s
CPUs on → resume done 0.41 s 1.40–1.46 s
USB devices disconnected / enumerated again 15 / 15 0 on the kept ports
USB disk usable after the resume +1.55 s, new block device at the end of the resume, same block device

The internal panel (backlight restored), both external displays, the GPU and the graphical session, the PMP, the audio codec, NVMe, the USB disk and the dock's Ethernet came back. dt_binding_check and dtbs_check for the touched bindings are clean.

@fbalazsy fbalazsy changed the title soc: apple: sleep: T6040 sleep controller, entry not yet enabled soc: apple: sleep: T6040 (M4 Pro, J616s) suspend-to-RAM Nov 19, 2026
@fbalazsy
fbalazsy marked this pull request as ready for review November 20, 2026 22:15
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for this series and the clear before/after table. The entry is fail-closed where it matters: display words that stay up, or a missing storage link, refuse the sleep and undo it.

We select behaviour by a hardware property rather than by the machines it was tested on, so three things before it can go in:

  • drivers/soc/apple/sleep-t6040.h:2374,2376: .machine = "apple,j616s", .cpu_count = 14. The J616s tree already enables &t6040_sleep. Could the driver drop the board string and check the CPU-start geometry against the DT's cpu nodes, so another T6040 board or a 12-core part only needs its DT enabled?
  • drivers/gpu/drm/apple/dcp.c:9863,10633,10672: of_machine_is_compatible("apple,t6040") picks the pipe set and the external restart. The power words already come from the DT; could these too, or carry a comment naming the T6041 hardware difference?
  • drivers/nvme/host/apple.c:3333: .sleep_untested = true means the sleep needs nvme_apple.sleep_untested=1. Your rows ran it; can the flag go?

A suspend-to-RAM row on our own J616s will be the deciding evidence; we'll schedule one on the head once these are addressed.

@fbalazsy

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three are addressed in fast-forward commits on top of 294fd14 (no force-push):

  • CPU inventory (sleep-t6040.h): a53a24d drops .machine, .boot_mpidr and .cpu_count. The probe checks every possible CPU from the DT cpus nodes against the SoC geometry instead: three clusters at MPIDR affinity level 1, the slots of each cluster (E 4, P 6 each), each cluster's first CPU-start bit (0, 4, 10), and no duplicate CPU-start bit. Another T6040 board or a 12-core part only needs its DT enabled.
  • Pipe set / external restart (dcp.c): taken from DT now. 33be9f7 adds apple,t6040-display-power to the apple,t8140-display-power binding, 7e7e584 uses it for the T6040 dcp_power node, and 10d49fc replaces the three of_machine_is_compatible() calls with per-compatible data looked up through the apple,display-power phandle: T6040 has two external pipes (ext0/ext1) and restarts the external DCPs after a wake; T6041 has four and keeps shutting them down. Without such a node the display stays up across a sleep, as before.
  • NVMe (apple.c): b9c96f3 drops .sleep_untested. The data is shared with apple,t6041-nvme-ans2, which is the same block.

Also in this push:

  • 2adecfb: after a wake, the external DCPs set their mode again only once the firmware reports the display plugged, instead of on the first flush. This fixes set_digital_out_mode 0x6 / "failed to retrain active CRTC after hotplug: -22" seen on a Type-C monitor that pulses HPD shortly after waking.
  • 91c50e8: drops the dates from the T6040 sleep comments.

Checks: every commit builds, checkpatch --strict is clean, dt_binding_check passes for the binding, and dtbs_check on t6040-j616s reports nothing new. On J616s at b9c96f3, without nvme_apple.sleep_untested=1: two suspend-to-RAM cycles, both clean; panel, Type-C and HDMI displays all come back; no kernel warnings or errors after wake.

@RyanTheTide

Copy link
Copy Markdown
Contributor

The T6040/T6041 sleep paths in drivers/gpu/drm/apple/dcp.c use a series of fixed waits: msleep(20) after dcp_s2r_stop_streams(), msleep(50) before a readl_poll_timeout() on the same power word, msleep(100) and msleep(25) around the HDMI converter rail and DP PHY in dcp_t6040_fixed_phy_up(), and DCP_S2R_SETTLE_MS/WORDS_MS/STOP_MS documented only as "as measured". Each of these should either wait for the state it is covering (coprocessor status, power-word readback, HPD/link up) with a bounded poll, or cite the hardware/firmware requirement for the value; a delay that cannot be justified should be removed. Fixed waits tuned on one machine tend to fail on the next one. Until then this should stay a draft.

@RyanTheTide
RyanTheTide marked this pull request as draft November 20, 2026 23:53
@fbalazsy

Copy link
Copy Markdown
Contributor Author

One more commit on top: bbdd785 "arm64: dts: apple: t6040: Add the display clock".

The T6040 DCP had no clock, so the firmware's getClockFrequency(0) returned 0 Hz and every start of the internal DCP, at boot and after each wake, logged updateFrequencies EDT ERROR ... Giving up on frequencies. The boot loader's device tree gives disp0's first clock as 712 MHz, the rate the T6041 boards already describe; this adds it as a fixed clock. The external DCPs have no clock there and are left as they are.

checkpatch --strict clean, dtbs_check on t6040-j616s adds nothing; two suspend-to-RAM cycles on J616s with the panel, Type-C and HDMI displays back each time and the message gone.

@fbalazsy

Copy link
Copy Markdown
Contributor Author

The T6040/T6041 sleep paths in drivers/gpu/drm/apple/dcp.c use a series of fixed waits [...]

Thanks, agreed. I sampled the registers each wait could be covering through the unchanged waits over three sleeps on J616s, then replaced them in four fast-forward commits on top of bbdd785 (no force-push):

Wait What it covered (measured) Now
msleep(1) ×2 and msleep(50) while lowering a pipe's power words protection and automatic bits read clear at once; CPU/FE/SYS words off with both gated flags set within 0.4 ms 69d3624: bounded polls on those words, the old values as timeouts
msleep(5) after handing fab6_soc back to automatic it gates itself within 0.4 ms 69d3624: bounded poll on its actual state
msleep(20) after dcp_s2r_stop_streams(), DCP_S2R_STOP_MS, DCP_S2R_WORDS_MS nothing: CPU status/control and the power words read the same from start to end of each wait; the steps before them are synchronous a5fed5d: dropped
DCP_S2R_SETTLE_MS before the mode set the firmware's hotplug report for the panel, 115 ms after the power-on every time b62e4db: waits for that report (1 s bound, then the mode set goes ahead as before, with a warning)
msleep(25) in dcp_t6040_fixed_phy_up() nothing: the T6040 DP PHY has no init/power_on op a10965d: dropped
msleep(100) in dcp_t6040_fixed_phy_up() the converter's HPD read that follows; HPD comes about 1 ms after the rails a10965d: polls the HDMI HPD line, 100 ms bound (probe's rail wait), so an output without a sink waits as before

DCP_S2R_DOWN_MS, the new DCP_S2R_PANEL_MS and DCP_S2R_PLUG_MS are now only timeouts of polls or completions.

Tested on J616s with the panel, a Type-C display and an HDMI TV: four suspend-to-RAM cycles in one boot. All three displays came back each time, the panel's backlight level round-tripped, and none of the new timeout messages appeared. checkpatch --strict is clean and every commit builds.

Two short waits in the firmware stop are still there: usleep_range(4000, 5000) after the A500 call follows the gap macOS leaves before AP/IOP idle, and usleep_range(5000, 6000) after the display DART streams. I'll measure the second one next, so I'm keeping this a draft as you suggested.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, this is what we hoped for. The waits now end on the power words, the idle state, the panel's hotplug report and HPD, and our earlier three points (the board string, the T6040 machine check, the sleep_untested flag) are gone on a10965d.

Three small things for when it leaves draft:

  • dcp.c:10068 usleep_range(4000, 5000): please put the reason you gave (the gap macOS leaves before the AP/IOP idle) in a comment.
  • dcp.c:10065: the DART-streams wait you're measuring.
  • dcp.c:10070-10075: a failed apple_rtkit_idle() is tried again with a thread polling RTKit every 0.5-1 ms. If the mailbox IRQ isn't delivered at that point, please say so in a comment.

We'll run the J616s suspend-to-RAM row once it's ready.

@fbalazsy

Copy link
Copy Markdown
Contributor Author

Three small things for when it leaves draft [...]

Thanks. Before taking it out of draft I reworked the whole series and force-pushed it: a10965d is replaced by 4e2ca17, on the same base (0abc2f3). The 92 development commits are now 19 logical ones: the bindings first, then the SMC, DART, NVMe, PMP, MCC, sleep driver, PHY, dwc3, GPU and display changes, then the DT. Each commit builds on its own.

Your three points

  • usleep_range(4000, 5000) after the A500: replaced with a check instead of a comment. The stop checks the A500 reply, then polls until no call is in flight on any of the firmware's channels (200 ms bound), and only then sends the AP/IOP idle. The gap was there so the idle request would not overtake a call in flight, and the comment now says so.
  • usleep_range(5000, 6000) after the display DART streams: replaced by a new apple_dart_display_streams_idle() in the DART patch. It checks that the streams read disabled, then polls until the DART has no TLB command and no transaction outstanding (atomic poll, DART_T8110_IDLE_TIMEOUT_US). If the DART doesn't drain, the suspend fails.
  • The apple_rtkit_idle() retry with a thread polling RTKit: removed. Across 44 suspend-to-RAM entries over 21 boots on J616s, each stopping every DCP, the first apple_rtkit_idle() never failed. Nothing showed the mailbox IRQ going missing at that point, so the retry had no basis. A failed idle now fails the suspend, as described below.

Other changes from two full reviews of the series

  • Errors are no longer dropped. A DCP whose firmware can't be stopped fails the display subsystem's .suspend. That covers pending display updates that don't settle, a missing A500 reply, calls still in flight, a failed idle and a DART that doesn't drain. The display it was driving is set up again (streams back on, presentation resumed, mode set again or the external link brought back), every DCP already stopped is restarted, and the error is returned.
  • dcp_t6040_fixed_phy_up(): the rails are dropped when the PHY fails, and a GPIO read error ends the HPD poll. The one fixed wait left in the DCP code is the 100 ms rail wait on an HDMI output with no HPD GPIO, the same wait probe uses.
  • The T6040/T6041 DCP power code uses named fields of the power state word instead of literals.
  • apple_dart_display_keep() keeps its state per DART under the DART's lock, only touches streams the DART has, and fails a restore that had no save.
  • sleep-t6040.h: open-coded udelay() loops are now read_poll_timeout_atomic(). Polls that time out at entry are counted and reported after the wake. Fixed delays are named, with the reason given (the PERST# hold cites the CEM T_PERST minimum, as T8140 does).
  • macsmc: WKTP and pmVC are in their own commit. pmp-report, mcc and nvme are separate commits with their own messages.
  • Comments describe the hardware, not the history: no PR references, no "the fixed wait this was", no bring-up notes.
  • DCO: the commits that carry AxxzyWasTaken's or Ryan Murray's code have Co-developed-by/Signed-off-by for them, followed by mine.

Correction

In my earlier comments I said checkpatch --strict was clean and that dtbs_check on t6040-j616s reported nothing new. Both claims were wrong.

  • checkpatch --strict warned on 14 of the old commits: long lines, extern declarations, msleep() under 20 ms, udelay(), the MAINTAINERS order, and binding patches mixed with driver changes.
  • dtbs_check flagged nonposted-mmio on the display PMGR in t6040.dtsi, which apple,pmgr.yaml didn't allow.

Both are fixed now. apple,pmgr.yaml gets the property in its own patch. On every commit, checkpatch --strict reports only:

  • the CamelCase CHECK on pmVC, which is the SMC key's name;
  • the "does MAINTAINERS need updating" warning for sleep-t6040.h, which drivers/soc/apple/* already covers.

dt_binding_check is clean for all three bindings. dtbs_check is clean for j616s, j616s-tether, j614s, j773s, j614c, j616c and j575c. A W=1 build of each commit adds no warnings in changed code.

Tested on J616s at 4e2ca17 (full kernel build, Rust included), with the panel, a Type-C display and an HDMI TV: five suspend-to-RAM cycles in one boot.

  • All three displays came back every time, and the panel's backlight level round-tripped.
  • The USB devices kept their bus and device numbers, the Ethernet adapter kept its address, and the disks kept their block devices.
  • The kernel log shows no warnings and no poll timeouts. The only messages are the external DCP firmware's own updateFrequencies and pmu ram read error lines, which the old head logged too.

That's everything I had for it. It's ready for your J616s suspend-to-RAM run whenever you can schedule one.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the rework and for the correction on checkpatch and dtbs_check. On 4e2ca17 our three points are covered: the 4-5 ms gap is now a wait for no call in flight before the idle, the 5-6 ms wait is apple_dart_display_streams_idle() polling the DART until it drains, and apple_rtkit_idle() is called once with a failure failing the suspend. Unwinding a DCP that can't be stopped, instead of dropping the error, is a good change too.

Two things before our run: GitHub reports the branch as conflicting with integration/aurora, so please rebase it, and take it out of draft when you're ready. We'll then run the J616s suspend-to-RAM row on that head and post it here.

@RyanTheTide

Copy link
Copy Markdown
Contributor

J616s row on 4e2ca17, merged onto a current integration/aurora build (the only conflict was apple_smc_complete() in drivers/mfd/macsmc.c; I kept both sides: the dark-wake counter reset from integration, then your apple_smc_wake_full()). The Stage 2 under test was aura main with this branch's t6040-j616s.dtb.

Result: the kernel hard-hangs early in boot, so no sleep row ran. The sleep controller probes (deep sleep is the default). About 6 s in, the machine stops and the hardware watchdog resets it.

Bisection, one boot each:

  • Same Stage 2 and DTB base, integration kernel without this PR: boots clean. So it isn't the DT or the loader.
  • This PR's kernel with the integration DTB (no sleep node): same hang. So it's driver code, not the new nodes.
  • This PR's kernel with phy-apple-t6040-usb2 kept out: boots.
  • Autoload of phy_apple_t6040_usb2 and dwc3_apple blocked, then loaded by hand with the kernel log streamed off the machine: the PHY module alone loads fine. dwc3_apple hangs it within ~1 s, right after these lines:
    phy-apple-t6040-usb2 38aa90000.phy: Type-C mux: non-DP state 0 -> DP alt mode 0, lane map normal
    phy-apple-t6040-usb2 38aa90000.phy: Type-C mux: non-DP state 4 -> DP alt mode 0, lane map reversed
    
  • Binding the three dwc3 instances one at a time: 382280000.usb and 392280000.usb bind fine. 38a280000.usb hangs.

That port has a USB4 host-to-host link to another Mac (mux state 4 = TYPEC_MODE_USB4). With dynamic debug on, the PHY never printed CIO (USB4/Thunderbolt) mode available, so cio_ok is false on this machine: t6040_cio_probe() returns silently when both CIO lane tables are missing. t6040_dp_mux_set() takes the CIO branch only when cio_ok is set. Otherwise a USB4 state falls through to the non-DP path and calls t6040_usb3_reclaim_locked() on lanes the USB4 link is using. That looks like the hang. The current integration PHY driver keeps the same link up on every boot here.

Suggestion: when t6040_cio_requested(state) is true but CIO isn't available, leave the lanes alone (no USB3 reclaim) and say so once in the log, rather than treating it like a plain USB state.

Happy to run the full row (s2idle x2, deep x5, s2idle after deep, GPU smoke) on the next head.

aronvandepol pushed a commit to aronvandepol/linux that referenced this pull request Nov 21, 2026
A SoC whose own display_off op takes its display pipes down needs no
entry in apple,display-coprocessors, and the core then never marks
display[0] bound. Accept ndisp == 0 in the profile check, and only refuse
for an unbound display coprocessor when the profile names one.

These are the same two hunks as in the T6040 profile (aurora-silicon#2215), so the two
branches merge without a conflict in either order. The T6030 profile
that follows has ndisp == 0.

Signed-off-by: Aron van de Pol <[email protected]>
Assisted-by: LLM (Claude:Opus 5.5)
Claude-Session: https://claude.ai/code/session_016eHgyJKRZBHRz41DTDHS7m
@RyanTheTide

Copy link
Copy Markdown
Contributor

Follow-up on the same J616s: I retested with a local one-hunk guard in t6040_dp_mux_set(). When t6040_cio_requested(state) is true but the CIO branch didn't take the state, it returns before the DP/USB3 path. That's not enough. The guard fires as intended:

phy-apple-t6040-usb2 38aa90000.phy: Type-C mux: USB4/Thunderbolt without CIO here, lanes left as they are

But about 3 s after dwc3_apple binds 38a280000.usb, the USB4 controller on that port goes down, followed by an SMC timeout and the same hard hang:

thunderbolt-apple-acio 389ac0000.cio: RTKit: endpoint discovery failed: -62
thunderbolt-apple-acio 389ac0000.cio: M3 RTKit failed to boot: -62
macsmc 50c600000.smc: Command timed out (434c4b4d0006b010)

So with a live USB4 link on the port, something in the reworked PHY/dwc3 bring-up still touches the shared CIO side: the USB3/PHY power-up, a reset, or a power domain. On the same machine, the integration PHY driver binds that port and the link stays up. The other two ports bind fine with this branch.

Repro: any T6040 port with a USB4 host-to-host (or USB4 device) partner at boot. Happy to run the next head; the full sleep row is ready to go once it boots.

@fbalazsy

fbalazsy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the bisection and the guard test. They narrowed it down.

Your guard stops t6040_dp_mux_set() from touching the lanes, but dwc3_apple still calls phy_power_on() on the USB3 phy when it binds. That path (t6040_usb3_up_locked()) knows only DP and our own CIO as lane owners. So it starts the USB3 coprocessor firmware, and on a hard-recover retry power-cycles the PHY's domains, on lanes that carry the live USB4 link. That fits the router's M3 failing endpoint discovery about 3 s after the bind.

Why the CIO branch didn't take the state: it runs only with the CIO tables and an enabled router whose phys points at this PHY (t6040_cio_router_enabled()). The integration apple,t6040-usb4-acio nodes have no phys, so with that DT a USB4/TBT state always fell through. The integration PHY takes CIO on the state alone.

32af9dc (fast-forward, no force-push) "phy: apple: t6040: Leave a USB4/Thunderbolt port's lanes alone without CIO here":

  • A USB4/TBT state that this PHY doesn't run as CIO sets cio_elsewhere. If USB3 was up, it is taken down and lent. Then the mux returns with no DP crossbar write.
  • t6040_usb3_up_locked() and t6040_usb3_reclaim_locked() treat cio_elsewhere like DP/CIO lane ownership. USB3 stays off until the mux reports a non-USB4 state, and USB2 is unaffected.
  • restore clears it with the rest of the PHY state, since the Type-C controller reports the port again.

checkpatch --strict clean apart from the Reported-by tag's missing Closes: link, W=1 adds nothing. My J616s has no USB4 partner, so the USB4 case is untested here. Could you run it on your head with the host-to-host link? I'll also move the router match to whatever links the integration acio node to its PHY, so that such a port gets CIO from this driver as on integration, instead of only being left alone.

On the rebase: the branch has to be rewritten onto integration/aurora (macsmc as you resolved it; dwc3-apple.c changed on integration too and needs a check). I'll do that as one force-push once it's cleared on my side, and take it out of draft then.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for tracing the bind-time path. On 32af9dc the hang we reported is closed in code. t6040_usb3_up_locked() now returns on cio_elsewhere (t6040-usb2.c:1298) before the PIPE tunables, the hard-recover power cycle and the firmware start. t6040_usb3_reclaim_locked() waits on it (1848), and the mux leaves the lanes alone (2807-2819). It still has to be proven with the USB4 partner attached, see below. Ports with no USB4/TBT partner see no change: the flag is only set when t6040_cio_requested() is true.

Two things in the new commit:

  • t6040_dp_power_on() (1898) refuses only cio_up. With cio_elsewhere set, the mux has cleared dp_alt/dp_two_lanes. A DP power-on on that port would then take the four-lane branch (1922-1931): USB3 down, t6040_dp_phy_init() and t6040_dp_mode_setup() on the lanes carrying the USB4 link. Nothing in that branch checks dp_alt. Could it return -EBUSY for cio_elsewhere as it does for cio_up, so the "no DP crossbar" promise holds for every path, not only the mux?
  • t6040_usb2_restore_early() clears cio_elsewhere (3826), but the comment above it (3786-3788) keeps the partner's Type-C state (orientation, DP alt mode, pin assignment) for the next power-on. cio_elsewhere describes the partner too. If the Type-C controller doesn't send the unchanged USB4 state again after the image, the dwc3 rebind starts USB3 on the live link, as at boot before this fix. Keeping it like dp_alt looks safer, unless the mux is guaranteed to be set again before dwc3 binds.

Still open from before: the branch conflicts with integration/aurora and is in draft. A rebased head is fine. We'll run these J616s rows on it:

  • A USB4/Thunderbolt dock (and a host-to-host partner) attached at boot. Boot completes, the router keeps the link, and the dock enumerates. Then three suspend-to-RAM cycles with the dock re-enumerating after each one. Then unplug, and a USB3 device on the same port to check the port leaves the USB4 state.
  • A USB3 device at SuperSpeed before and after a suspend-to-RAM.
  • A DP alt-mode monitor back after a suspend-to-RAM.
  • Nothing attached: three suspend-to-RAM cycles.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy, a tidy-up pass over the open PRs here. These of yours need something:

If any of these are no longer needed, closing them helps; otherwise a merge or rebase onto integration/aurora is usually all they need. Thanks!

The T6040 (M4 Pro) enters suspend-to-RAM through the same SoC sleep
engine as T8140 and T6050, with three CPU complexes, five display pipes
and two storage PCIe lanes. Describe the registers its entry and wake
write, in the same shape as apple,t8140-sleep: the CPU start/stop block,
the AON watchdog, the CPU complexes' control words, the power gate and
retention voters, the PMU's SPMI controllers, the S2R timer, the
SOC-East and SOC power-word pages, the wake control, the display pipes'
gate and PMC voters and the keep-alive enables.

apple,check-ps-b4-sleep lists, per display pipe, the power words that
have to read off before the sleep engine is armed. apple,pinctrl names
the AP pin controller whose pins the wake restores.

Signed-off-by: fbalazsy <[email protected]>
The T6040 and T6041 display complexes are lowered and raised around a
sleep by the display driver as T8140's is, but they have an internal
pipe and two (T6040) or four (T6041) external pipes, split over a
second PS and power-gate page, with a clock protection table (gapf) and
the display bridge words. Add both compatibles and their register
windows.

Signed-off-by: fbalazsy <[email protected]>
Some PMGR blocks have power state registers that only take non-posted
writes: the T6040 display PMGR's DISP_CPU word is one. The syscon maps
the block with of_iomap(), which honours nonposted-mmio. Allow the
property.

Signed-off-by: fbalazsy <[email protected]>
Two SMC keys take part in a T6040 sleep:

- WKTP, the wake type: the T6041 SMC takes 2 ahead of the other sleep
  notices, and 0 once a wake is a full one. Without the 0 the SMC treats
  all the time awake as a power nap; without the 2 it does not run the
  sleep as one. Write it for the T6041 SMC, and only around a sleep
  that sent the notices.
- pmVC, the VDD_CIO rail request: the SMC drops the rail during the
  sleep transition unless it was asked for it, and the sleep engine's
  hand-over of the ATC ports then races the loss. Export
  apple_smc_request_pmvc() for the sleep controller, which sends it in
  its .begin, ahead of the device suspend.

Signed-off-by: fbalazsy <[email protected]>
The T6041 display DARTs are locked by the display firmware, so the
driver's own suspend neither saves nor restores their TCR and TTBR
words, and after a real sleep the panel stayed black with everything
else up.

Add apple_dart_display_keep(): it saves the words of the given streams
before the sleep, into per-DART storage under the DART's lock, and
writes back after it only what changed, before the display firmware
runs again. Streams the DART doesn't have are ignored and nothing past
them is read; a restore without a save fails with -ENOENT.

Add apple_dart_display_streams_idle(), for the display driver's stop:
after apple_dart_display_streams() turned the streams off, it checks
that they read disabled and polls until the DART has no TLB command and
no transaction outstanding, so the blocks behind it can be powered
down without a fixed wait. apple_dart_idle() is split for it so that a
pending fault doesn't hold the drain up.

Co-developed-by: AxxzyWasTaken <[email protected]>
Signed-off-by: AxxzyWasTaken <[email protected]>
Signed-off-by: fbalazsy <[email protected]>
The T6040 runs the T8132 ANS controller. Give it T8140's sleep values,
as T8132 runs them: the traced firmware stop, a flush of namespace 1 and
the same CC.SHN value (both bits set). After a sleep that cut the power
its firmware takes the whole endpoint map echoed as the last reply of
the warm restart, RTKit's default, so sleep_epmap_last_mask stays 0
instead of T8140's BIT(0).

The firmware stop, the cold restart after the wake and the full
endpoint map ran on the M4 Pro (J616s) across suspend-to-RAM cycles,
with the root filesystem on this controller and its reads and writes
checked after every wake. The controller data is shared with every
apple,t6041-nvme-ans2 controller, which is the same block.

Signed-off-by: fbalazsy <[email protected]>
apple_pmp_report_sleep() withdraws every request it knows of and then
waits up to 50 ms for the PMP to stop acknowledging them. On T6040 that
includes the always-on CPU cluster entries, and the cluster the boot CPU
runs this on can't be released while it does: every sleep ran out the
wait and warned

  PMP still acknowledges withdrawn requests 0x63c00 (ack 0x400)

with only pmp-eacc0 (bit 10) left.

Keep withdrawing these requests, but leave the always-on entries out of
the wait. Nothing in Linux turns their blocks off; whatever the PMP does
with them happens at the sleep's commit.

Signed-off-by: fbalazsy <[email protected]>
Like T8142's, the J616s ADT has no skip-mcc-off-to-s2r. After a wake
every plane of its cache reads 0 ways enabled and 0 powered, so the
resume found plane 0 not ready and left allocation off until the next
boot.

Take the T6041 MCC through the deep sleep as T8142's: ways off after
the write-back, and the boot's way count back at the wake before
allocation is enabled again.

Signed-off-by: fbalazsy <[email protected]>
… sleep

On a T6040 Type-C port in USB4/Thunderbolt, the PHY takes CIO down for
a system sleep and the Type-C controller brings it back after the wake,
when it reads the port again and sets the mux. dwc3-apple restarts a
controller that ran before the sleep from its own resume, which can come
first: with a USB4 partner attached, the core soft reset then runs on a
port with nothing under it, times out, and the port's genpd prepare
keeps failing, so every later sleep is refused.

Before the USB2 device mode, the controller of such a port never ran
(a device role was taken as no role), so nothing restarted at wake. Now
a device role from a USB4 partner starts it, and the order shows up.

Have the T6040 PHY keep the controller in reset with -ENOLINK from the
moment CIO goes down for a sleep until the next mux set, and let the
T6040 glue take that as the wait for the PHY that the T6050 start after
sleep already has: the start is left to the role switch that the Type-C
controller sends right after the mux set. A port without CIO never sees
-ENOLINK, so its start after sleep is unchanged.

Reported by RyanTheTide, J616s with another Mac on a USB4 cable.

Signed-off-by: fbalazsy <[email protected]>
@fbalazsy

Copy link
Copy Markdown
Contributor Author

@RyanTheTide the fix for the USB4-partner regression is pushed: 26656c37 ("usb: dwc3: apple: Wait for CIO before a T6040 USB4 port's start after sleep"), a normal commit on top of 0f47f270.

What it does: when the T6040 PHY takes CIO down for a system sleep, it now keeps the port's controller in reset and returns -ENOLINK from the reset deassert until the Type-C controller sets the mux again after the wake. The T6040 glue treats that like the existing wait-for-PHY path in dwc3_apple_start_after_sleep(). It logs waiting for the Type-C port to start the PHY after the sleep, and the controller starts on the role switch that cd321x sends right after the mux set, so it starts once CIO is back. Before this, it soft-reset the core at 76.667 with nothing underneath. A port that never had CIO up never sees -ENOLINK, so USB-only ports start after a sleep exactly as before. A new KUnit case covers the PHY side.

At this head, on the J616s without a USB4 partner:

  • KUnit (arm64, LLVM), T6040 PHY + ATC PHY + sleep: 97 passed, 1 skipped (was 96 + 1, the new case added).
  • One-shot test kernel built from 26656c37, 5 deep S2R cycles: all returned rc 0 with 0 warnings or errors in the kernel log. eDP, DP and HDMI were connected, enabled and lit on the camera after every wake. Dock Ethernet carrier was up, and the USB tree was identical each time.

I can't exercise the CIO path itself here, so the live-peer row is yours again when you have time: boot with the other Mac on the USB4 cable, a few deep sleeps, and the dwc3-apple 382280000.usb / phy-apple-t6040-usb2 382a90000.phy lines around the first wake. I'd expect the "waiting for the Type-C port" line, then CIO PHY up, then the controller start, and later sleeps no longer refused.

@petrskuta this head has the fix, if you want to do the Studio Display run.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 26656c37

Blockers:

  1. Wait for the 29 queued CI checks (apple-build, host-tests, kunit, KUnit suites, pr-text, readiness) to finish green at 26656c37.
  2. Re-run the lab J616s (T6040) USB4-attached deep-sleep/resume row at exact head 26656c37 to confirm the DWC3/CIO resume ordering fix resolves the prior c2c9e3da USB4-peer regression.

Checked: Delta commit 26656c377b (drivers/phy/apple/t6040-usb2.c, drivers/phy/apple/t6040-recovery-test.c, drivers/usb/dwc3/dwc3-apple.c) over 0f47f270.

Evidence
  • Code audit (0f47f270 -> 26656c37, 0 code blockers):
    • drivers/phy/apple/t6040-usb2.c: tphy->cio_sleep is set under tphy->lock in t6040_usb2_sleep() after t6040_cio_down_locked(), checked in t6040_usb2_reset_deassert() via t6040_dwc3_start_allowed() returning -ENOLINK before releasing DWC3 reset, and cleared under tphy->lock in t6040_dp_mux_set() (and t6040_cio_remove()). Non-CIO ports never set cio_sleep and keep existing resume behavior.
    • drivers/usb/dwc3/dwc3-apple.c: sets .sleep_cio_wait = true on dwc3_apple_t6040_hw so dwc3_apple_start_after_sleep() treats -ENOLINK as the existing sleep_phy_wait deferral path until the Type-C controller re-sets the mux and sends the role switch.
    • drivers/phy/apple/t6040-recovery-test.c: adds t6040_sleep_cio_wait_test KUnit coverage.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 26656c3

The T6040 PHY now holds controller start after CIO teardown and the DWC3 glue defers to the role-switch path. The predicate fixture and no-peer J616s cycles cover the defer flag and the ordinary port path. Please repeat the J616s live USB4-peer row and show mux and role-switch recovery, working USB, and consecutive deep wakes. Include detach across sleep if practical, because the wait also depends on the follow-up mux notification. Current hosted checks remain due.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy row at 26656c37 on the J616s with the USB4 partner (J473 on port 0/0-1, port1 data role device), main Stage 2 DTBs, rtc1 (apple-pmu-rtc) wake: not fixed yet. 2 deep wakes return, then sleeps 3, 4 and 5 are refused (fail 0 -> 3). Boot itself is fine: CIO PHY up, ACIO firmware ready, 0-1 enumerated, Enforcing, 0 failed units.

Your wait works: at the first wake the glue logs waiting for the Type-C port to start the PHY after the sleep, and CIO comes back before the controller starts. The soft reset still times out, 230 ms after CIO is up:

[   28.101472] phy-apple-t6040-usb2 382a90000.phy: suspend: CIO down for system sleep; the Type-C controller brings it back
[   28.110398] PM: suspend exit
[   28.336076] dwc3-apple 382280000.usb: waiting for the Type-C port to start the PHY after the sleep
[   28.600564] phy-apple-t6040-usb2 382a90000.phy: CIO PHY up (mode 2), reverse orientation: xbar 0x7000002/0x21 cfg 0x1b/0x3
[   28.600705] thunderbolt-apple-acio 381ac0000.cio: restarting port after system sleep
[   28.829031] dwc3-apple 382280000.usb: DWC3 controller soft reset failed.
[   28.829414] dwc3-apple 382280000.usb: Failed to initialize DWC3 Core, err=-110
   (sn201202x 1-0c retries: CIO asleep/up twice more, the same -110 each time, then "cable revalidation failed after 3 attempts")

The difference from the boot is the USB2 PHY. At boot the device start on this port runs the USB2 sequence first:

[    5.983236] 382a90000.phy: CIO PHY up (mode 2) ...
[    6.039038] 382a90000.phy: USB2 event status 0x1
[    6.045027] 382a90000.phy: USB2 device sequence complete
[    6.045529] dwc3-apple 382280000.usb: No USB3 device PHY: gadget at high speed

After any of the wakes, 382a90000 never logs USB2 event status / USB2 ... sequence complete again. The other port (392a90000, host) does on every wake (28.103, 42.031). So on the CIO port, t6040_usb2_power_on() does not run t6040_usb2_on_locked() before the core soft reset. Either tphy->powered (or the phy core's power_count) survives the sleep while the CIO-down sleep has taken the USB2 side down with it, or the device-role start after the sleep never reaches phy_power_on(). I didn't instrument which one; a dev_dbg in t6040_usb2_power_on() that logs powered would settle it in one cycle.

At the second wake the mux set came first (cio_sleep cleared), so dwc3_apple_start_after_sleep() ran directly: Failed to start after sleep, err=-110 / USB host recovery failed: -110. From then on every sleep is refused at device_prepare(): genpd_prepare returns -110, as at c2c9e3da.

Possible fixes, your call: clear powered (or set sleep_down) when t6040_usb2_sleep() takes CIO down under a powered USB2 side, so the next start re-runs the device sequence. Or take the device start after the sleep through apple_t6040_atcphy_sleep_power_up(), as the host reinit already does. I'll re-run the same live-partner row on your next head.

Everything else after each completed wake: eDP connected, Wi-Fi ping 3/3, BT powered, NVMe 2.9 GB/s, vkcube OK, 0 GPU firmware crashes. The J616s was restored to its saved default afterwards. Full kernel log and per-cycle rows were kept.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy thank you for all the rounds on this. To stop the back-and-forth we're merging #2215 as it stands at 26656c37 once its CI and the App review finish, together with a plain J616s no-regression row at this head. The one remaining case, deep sleep with a live USB4 link (the USB2 device sequence isn't re-run after the CIO sleep), is tracked as a known gap in #3574. We're writing that follow-up fix now; you're welcome to open your own PR for it or review ours.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: per the maintainers' ruling this merges at 26656c37 with one known gap (linux#3574) once CI, the App review and the plain J616s no-regression row at this head are in.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 26656c3 after hosted CI and the J616s no-USB4 row

Ryan waived the attached USB4 peer row for this PR. The remaining live-link failure is tracked in #3574 and stays with the follow-up. Keep exact-head hosted checks and the J616s boot, s2idle and deep-sleep regression without a USB4 device as merge gates.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy one more data point from the no-regression row at 26656c37 on the J616s (J473 linked over USB4, Edge Stage 2 DTBs): s2idle doesn't come back.

  • rtcwake -d rtc1 -m freeze -s 15 (rtc1 = apple-pmu-rtc): hung 2 of 2 times. No wake, ssh dead, only the Wi-Fi offload still answers ping. Both times it needed a reset over the VDM tether. The journal never persisted. netconsole ends at printk: Suspending console(s).
  • pm_test=devices with the console suspended: passes, so device suspend and resume are fine.
  • With console_suspend=N (set at runtime), 5 of 5 wake normally. It's timing-sensitive, and it sits in the s2idle idle/wake stage, not in a device callback.
  • Our current main build (Edge) on the same Mac, same partner, same rtcwake on rtc1: wakes normally.

I can't tell whether it needs the USB4 partner, because ours can't be unplugged remotely. Could you run a few s2idle cycles on yours without a partner? If it also hangs there, the wake IRQ or deep-WFI handling in s2idle is the place to look. If it doesn't, it's the partner case again, near the s2idle awake-path handling for a running PHY coprocessor.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 26656c3

Checked: The lab J616s with its USB4 peer attached failed two RTC s2idle wake attempts on this head and required recovery both times. The same machine woke from RTC s2idle on its saved Edge kernel. This supersedes my conditional approval because the new result concerns s2idle wake.

Blocker: Identify or fix the s2idle regression and post a successful exact-head comparison with the same RTC and attached topology. Keep the previously tracked deep-sleep issue #3574 in view when interpreting the results.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy paired comparison for the s2idle hang, same J616s, same USB4 partner, same method (console suspended, rtcwake -d rtc1 -m freeze -s 15):

kernel s2idle
main ed00bd11 (this PR's base) 3/3 wake
26656c37 hangs on the first cycle, 4 of 4 tries in total
26656c37, hci_bcm4377 and sdhci-pci unbound first still hangs

So it comes with this series, and it isn't the Bluetooth or SD reader changes. Left in the diff for s2idle: the T6040 sleep profile (does any of it, e.g. deep WFI or the AIC handling, run on an s2idle entry?), pcie-apple, apple-dart, brcmfmac, the DCP wake path, and the PHY's awake-path decision for a running coprocessor. A no-partner s2idle run on yours would tell us whether the USB4 link is needed.

…leep

With a USB4 partner on a T6040 Type-C port, the controller of that port
is stopped for a system sleep (its USB2 side powered off), then the PHY
takes CIO down. After the wake the Type-C controller sets the mux, CIO
comes back, and the role switch starts the controller. Its core soft
reset then times out (-110), in the device and the host role alike, and
from then on genpd refuses every sleep at prepare.

The soft reset runs before dwc3_core_init() powers the PHY on. At boot
the boot loader leaves the USB2 side running, so it passes; after the
CIO sleep nothing has powered it again. Note at the sleep that USB2 was
off, and power it up in the mode dwc3-apple selected before the next
release of the controller's reset. dwc3's own power_on then finds it
powered. Ports that never had CIO up are unchanged.

J616s with a J473 on a USB4 cable, port in the device role: 5/5 deep
s2r with RTC wake, no dwc3 errors, USB tree and USB4 link back after
each (was: 2 wakes, then -110 and every later sleep refused).

Link: aurora-silicon#3574
@RyanTheTide

Copy link
Copy Markdown
Contributor

@fbalazsy a fix for the live-USB4 deep-sleep case (#3574) is ready, as one commit fast-forward from your head 26656c37: branch fix/t6040-cio-sleep-usb2-power, commit 22fc9308 ("phy: apple: t6040: Power USB2 before a controller start after a CIO sleep", +20 lines in t6040-usb2.c).

The cause, from an instrumented row: after the CIO sleep the controller's core soft reset runs before dwc3_core_init() powers the PHY on, and nothing has powered the USB2 side since the stop for the sleep. At boot the boot loader leaves it running, which is why the first start passes. The commit notes at t6040_usb2_sleep() that USB2 was off, and powers it up (t6040_usb2_on_locked(), in the mode dwc3-apple selected) in the reset deassert, before the release. Ports that never had CIO up don't take that path.

Row on the J616s with the J473 on the USB4 cable: 5/5 deep s2r with RTC wake, no dwc3 errors, USB tree, USB4 link and eDP back after each (was 2 wakes, then -110 and every later sleep refused). The tested build had the same code with a dev_info where the commit has dev_dbg. Unrelated to this commit and seen once each in those 5 cycles: a brcmfmac ring 4: r_ptr 0 outside depth 0 and a Bluetooth 0x0c01 tx timeout with a driver rebind.

OK to fast-forward it onto t6040-sleep, as with the earlier two? The s2idle hang above is separate and still open.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Pushed 22fc930 to this branch (fast-forward, your commits untouched): it fixes the live-USB4 deep-sleep case (#3574) by powering USB2 before the controller's start after a CIO sleep; 5/5 deep wakes with the partner linked.
We're fixing the s2idle hang next, on top, the same way.

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Nov 29, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FIX, then re-review at 22fc93081139

Blockers:

  1. Open J616s s2idle wake regression (carried forward from 26656c37): Paired testing on J616s (rtcwake -d rtc1 -m freeze -s 15, console suspended) wakes 3/3 on main (ed00bd11) and hangs 4/4 on 26656c37 (still hangs with hci_bcm4377 and sdhci-pci unbound). Keep this blocked until the s2idle fix lands on top and an exact-head J616s s2idle pass row is posted.
  2. USB2 pre-power unwind gap in 22fc9308 (drivers/phy/apple/t6040-usb2.c:3492-3504): t6040_usb2_reset_deassert() now powers USB2 on (t6040_usb2_on_locked() + tphy->powered = true) before t6040_dwc3_reset_release_locked() and before dwc3_core_init() takes a phy_power_on() reference:
    • If t6040_dwc3_reset_release_locked() returns -EIO (t6040-usb2.c:3502), tphy->powered stays true; dwc3-apple.c:986-1027 then tries phy_set_mode(usb2_phy, PHY_MODE_USB_HOST) in restore_usb2_mode, which fails with -EBUSY (t6040-usb2.c:482).
    • If dwc3_apple_core_init() (dwc3-apple.c:1001) fails before dwc3_core_init() calls phy_power_on() (e.g., dwc3_core_soft_reset() fails), appledwc->core_active is still false so dwc3_apple_core_stop() only calls reset_control_assert() (t6040_usb2_reset_assert()). Because tphy->powered is already true, if (!tphy->powered) (t6040-usb2.c:3447) skips restoring PHY_MODE_USB_HOST and leaves USB2 powered with no phy->power_count owner, locking the port out of host mode with -EBUSY.
    • Fix: roll back t6040_usb2_off_locked() + tphy->powered = false when t6040_dwc3_reset_release_locked() fails after pre-powering, and track unadopted pre-power (cleared in t6040_usb2_power_on()) so t6040_usb2_reset_assert() powers USB2 off and restores host mode if dwc3_core_init() fails before phy_power_on().
  3. Exact-head hosted CI: readiness was cancelled at 22fc9308; rerun the full hosted CI suite once the s2idle and unwind fixes are pushed.

Checked:

  • Audited 22fc9308 (drivers/phy/apple/t6040-usb2.c +20/-0) in context with t6040_usb2_power_on(), t6040_usb2_set_mode(), t6040_usb2_reset_assert(), t6040_cio_remove(), and drivers/usb/dwc3/dwc3-apple.c:
    • Lock and runtime PM discipline in t6040_usb2_reset_deassert() (PM_RUNTIME_ACQUIRE + guard(mutex)(&tphy->lock)) are sound.
    • t6040_usb2_power_on() returns 0 cleanly when tphy->powered is already true, and dwc3-apple.c:951 selects usb2_phy mode before reset_control_deassert() (L985), so the happy path matches the #3574 J616s 5/5 live-USB4 deep S2R pass row.
    • t6040_cio_remove() properly clears cio_sleep_usb2.
  • Checked for Apple material, tool attribution, private serials, and gating: clean.
Evidence
  • Head: 22fc93081139 (base: main, mergeable: MERGEABLE, incremental commit 22fc9308 +20/-0 in drivers/phy/apple/t6040-usb2.c).
  • Unwind paths checked: drivers/phy/apple/t6040-usb2.c:3405-3450, 3467-3511, 472-487; drivers/usb/dwc3/dwc3-apple.c:858-908, 950-1033.
  • Hosted CI at 22fc9308: 11P/1F/0Q (readiness cancelled).

t6040_usb2_suspend() took CIO down for every system sleep, s2idle
included. On main its .suspend only keeps a running coprocessor's power
domains on for s2idle, and s2idle wakes. With the teardown, the J616s
stays in the s2idle loop with no wake (RTC alarm, 4 of 4 tries, reset
needed), with or without a USB4 partner. Device suspend and resume
alone (pm_test=devices) pass. Main's base on the same Mac wakes 3 of 3.

Leave s2idle as on main: no CIO teardown, keep the domains of a running
coprocessor on. Firmware-driven suspend and hibernation keep the
teardown.

J616s with a J473 on the USB4 cable: s2idle 5/5 then deep s2r 3/3 on the
same boot, USB4 link, eDP and Wi-Fi back after each.
…port

22fc930 powers USB2 before a CIO port's controller start only after CIO
went down for a sleep. The same soft reset timeout comes on any start of
that controller after a stop while the port is in CIO: after an s2idle
wake the Type-C controller revalidates the cable, the controller stops
and starts again, and the core soft reset times out (-110) with USB2
off, three times in a row, after which the next sleep is refused.

Note in power_off that USB2 went off while CIO was up, and power it in
the reset deassert of the next start while the port is in CIO. The
boot, where the boot loader leaves USB2 running, and ports without CIO
are unchanged.

J616s with a J473 on the USB4 cable: s2idle 5/5 then deep s2r 3/3 on the
same boot, no dwc3 errors (was: -110 after the first s2idle wake).

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 448e9f5.

Checked: The s2idle path now keeps CIO up, and the change broadens USB2 pre-power to ordinary controller stops on a CIO port. The prior unwind blocker remains: reset release still returns on failure after setting powered, and the delta adds no cleanup for pre-power that the PHY core has not adopted. Cover both failure paths so host mode can be restored. Please post the current-head paired J616s RTC wake row with the attached topology and hosted CI.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Exact-head row at 448e9f5d on the J616s with a J473 linked over USB4, after a fresh boot:

main ed00bd11 26656c37 448e9f5d
s2idle (RTC, 15 s) 3/3 hang 4/4 3/3
deep s2r (RTC), live USB4 link n/a 2/5, then refused 5/5

After every wake: USB tree, USB4 link, eDP, Bluetooth, Wi-Fi and Vulkan were back, with 0 dwc3 errors and 0 GPU firmware crashes. The only kernel error was brcmfmac ring 4: r_ptr 0 outside depth 0 on 2 of the 5 deep wakes, which earlier heads show too.

What the three commits on top of your series do:

448e9f5 powers USB2 in the reset deassert of a CIO port's controller
start, before dwc3_core_init() takes it over with power_on. When that
start fails in between (the reset release does not read back, or the
core init fails and dwc3-apple asserts the reset again), no power_off
comes for it: USB2 stays up and reads powered, the reset assert keeps
the device mode, and set_mode() to host returns -EBUSY, so the port
cannot go back to host.

Track the early power-up until power_on adopts it. If the reset release
fails, hold the reset again and power USB2 off; the reset assert does
the same for a start that failed before power_on. Both then return the
port to host mode and leave the next start powering USB2 first again.
Successful starts are unchanged.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at cbb7738 after hosted CI and the planned J616s sanity row.

Checked: Both failed reset release and reset assertion before PHY adoption now hold controller reset and unwind early USB2 power. The PHY adoption clears the early flag, so reset assertion does not power off an owned PHY. If shutdown readback fails, the existing shutdown_failed guard keeps later mode and power operations fail-closed. The prior J616s wake evidence was at 448e9f5. Keep the exact-head boot and linked s2idle/deep sanity planned by SLEEP-2215.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at cbb7738f. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J616s-s2idle3/3+deep5/5-live-USB4-at-448e9f5d;unwind-fix-error-paths-only. (5) There's no blocking review. (6) Dj was pinged here 509 min ago with no objection. Revert: git revert -m 1 <merge>.

@fbalazsy

Copy link
Copy Markdown
Contributor Author

Exact-head sanity row at cbb7738f (J616s, M4 Pro, T6040), no USB4 partner attached:

  • One-shot test kernel built from cbb7738f. Boot: eDP, DP and HDMI connected, enabled and lit (camera). 0 failed units.
  • Deep S2R, 5 cycles (mem_sleep = deep): rtcwake/suspend_stats success 5, fail 0. 0 warning or error lines in any cycle window. USB tree identical after each wake, dock Ethernet carrier up, Wi-Fi/SD/NVMe/Bluetooth ok. All three displays lit on the camera after every wake. No waiting for the Type-C port / CIO down for system sleep lines, as expected with no USB4 partner.
  • KUnit (arm64, LLVM): T6040 USB2 PHY + ATC PHY + sleep + DART, 97 passed, 1 skipped.

Separately, the data point you asked for on the s2idle wake regression: at 26656c37 (before your 8e0590f2) I reproduced the s2idle hang without any USB4 partner — rtcwake -d rtc1 -m freeze woke twice then hung on the third, so it was the series' own s2idle path, not the partner. I have not re-run s2idle at cbb7738f: an s2idle hang here has no watchdog backstop (the SoC watchdog is stopped in the device freeze before the idle/wake stage), so I'm keeping s2idle off my machine until I have a backstop that auto-resets from a hung suspend. Your 8e0590f2 ("Keep CIO up through s2idle") is the right place; a lab row with the remote-reset tether would confirm it faster than I safely can here.

Thanks for 22fc9308, 448e9f5d and cbb7738f — I reviewed the unwind pair against the -EBUSY path (failed reset release, and reset assert before dwc3_core_init() adopts the PHY) and it covers both, so I dropped the equivalent fix I had staged. No objection to any of them on t6040-sleep.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Post-merge check on the J616s with a J473 linked over USB4: main aa76613 + cbb7738 (same content as f5c9853) boots clean with CIO up, then s2idle and deep s2r each wake on the RTC with the USB4 link, eDP, BT and Wi-Fi back, no dwc3 errors. Thanks again @fbalazsy.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

No-regression M4 Max (J616c, T6041, 32-core GPU) suspend-to-RAM verification row on main (429e7e15f122 + merged #3687/#3688/#3690/#3670) with Aura 54ef935bd24d on macOS 27.2 (26B123, mBoot-20457.41.3):

  • rtcwake -d /dev/rtc1 -m mem -s 15 (mem_sleep=deep): PASS, boot_id unchanged (5ddd3e20-03cb-47a3-a42d-6fb5558562f5).
  • Post-wake recovery verified across all 5 DCPs (internal panel 3456x2234@120 Hz ARGB2101010 + backlight restored), PMP (RTKit re-initialized cleanly), SEP (the enclave is back from its sleep request), GPU (0xf0003ff, gpubench-vk depth 1/2/4 384.9 Gpix/s with 0 faults), ANE (/dev/accel/accel0), Wi-Fi (BCM4388/6), speakerguardd-v2, and 0 failed units.

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

Labels

area:bringup Area from CODEOWNERS (bot) area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) area:power Area from CODEOWNERS (bot) area:usb Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:one-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants