From d536afe6b520702a974f8ceb20327ea918ef49dd Mon Sep 17 00:00:00 2001 From: Muness Castle <931+muness@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:49:10 -0500 Subject: [PATCH 1/2] thunderbolt: apple: T6020 deep sleep with a router attached T6020 deep sleep removes the CIO power domains, and the ATC PHY is shared with DWC3, as on T8103. Use the T8103 handling: tear a connected router down before tasks freeze, ahead of DWC3's PM notifier, with the router in ACIO sleep before its domains go; restart the port at once after the wake; stop a started router before reboot. Release the displays behind the port before the router, as T6050 does, and make that a hardware flag. With the displays released from the router's teardown instead, a dock's second display stayed dark after the second of two sleeps. Signed-off-by: Muness Castle <931+muness@users.noreply.github.com> --- drivers/thunderbolt/apple.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index cb3a94977182a..2da77fed0a49e 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -190,6 +190,11 @@ struct apple_cio_hw { * before DWC3's default-priority PM notifier queues its PHY shutdown. */ bool phy_shared_with_dwc3; + /* + * Release the displays behind the port before its router is put to sleep for a deep + * sleep, not from the router's teardown. + */ + bool sleep_displays_first; const struct apple_dpin_policy *dp; }; @@ -224,7 +229,19 @@ static const struct apple_cio_hw apple_cio_t8122_hw = { .dp = &apple_dpin_m1, }; +/* + * T6020 deep sleep removes the CIO power domains and shares the ATC PHY with DWC3, as on + * T8103. Release the displays behind a connected router first, then put the router into ACIO + * sleep and tear it down before tasks freeze (ahead of DWC3's PM notifier), and request fresh + * cable state immediately on wake. Stop a started router before reboot. + */ static const struct apple_cio_hw apple_cio_t6020_hw = { + .sleep_removes_domains = true, + .restart_on_wake = true, + .phy_shared_with_dwc3 = true, + .stop_at_reboot = true, + .sleep_router_on_stop = true, + .sleep_displays_first = true, .dp = &apple_dpin_m2, }; @@ -4276,14 +4293,14 @@ static int apple_cio_sleep_release_displays(struct apple_cio *acio, bool pause) if (!busy) break; if (ktime_after(ktime_get(), deadline)) { - dev_err(acio->dev, "T6050 sleep: the displays behind this port are not released after %lld ms (DP IN %#x still busy, %#x asked): the port stays up and the sleep is refused\n", + dev_err(acio->dev, "sleep: the displays behind this port are not released after %lld ms (DP IN %#x still busy, %#x asked): the port stays up and the sleep is refused\n", ktime_ms_delta(ktime_get(), start), busy, asked); return -EBUSY; } usleep_range(1000, 2000); } if (asked || pause) - dev_info(acio->dev, "T6050 sleep: %u display request(s) behind this port ended in %lld ms, before %s (DP IN %#x)%s\n", + dev_info(acio->dev, "sleep: %u display request(s) behind this port ended in %lld ms, before %s (DP IN %#x)%s\n", hweight32(asked), ktime_ms_delta(ktime_get(), start), pause ? "any port's power-off" : "the router", asked, pause && acio->sleep_dp_paused ? "; new tunnels wait for the end of the sleep" : ""); @@ -4303,7 +4320,8 @@ static int apple_cio_sleep_teardown(struct apple_cio *acio) if (acio->removing || acio->resume_recovery_failed || !acio->current_cable_info) return 0; - if (apple_cio_t6050_sleep(acio) && READ_ONCE(t6050_sleep_dp_first)) { + if (acio->hw->sleep_displays_first || + (apple_cio_t6050_sleep(acio) && READ_ONCE(t6050_sleep_dp_first))) { released = apple_cio_sleep_release_displays(acio, false); if (released < 0) return released; From d213952fee30591cf750697b2d02c920a24b8285 Mon Sep 17 00:00:00 2001 From: Muness Castle <931+muness@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:41:35 -0500 Subject: [PATCH 2/2] thunderbolt: apple: cover T6020 deep sleep in the ACIO host test T6020 now tears its router down for deep sleep and releases its displays first. Check its flags and that deep sleep removes its domains while s2idle and freeze keep them, and add negative controls for the two flags that decide its sleep handling. Signed-off-by: Muness Castle <931+muness@users.noreply.github.com> --- tools/asahi/pciec-policy-tests.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index c253f04eff9ed..2e204f30f07c1 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -1281,6 +1281,7 @@ def test_pm_order(out, acio): bool psd_power_cycle; bool stop_at_reboot; bool sleep_router_on_stop; + bool sleep_displays_first; const struct apple_dpin_policy *dp; }; struct notifier_block { int (*notifier_call)(void); int priority; }; @@ -1362,29 +1363,36 @@ def test_pm_order(out, acio): assert(t8122->phy_shared_with_dwc3 && t8103->phy_shared_with_dwc3); assert(t8103->psd_power_cycle && t8103->stop_at_reboot && t8103->sleep_router_on_stop); assert(t8122->dp == &apple_dpin_m1 && t8103->dp == &apple_dpin_m1); + assert(!t8122->sleep_displays_first && !t8103->sleep_displays_first); + assert(t6020->sleep_removes_domains && t6020->restart_on_wake); + assert(t6020->phy_shared_with_dwc3 && t6020->stop_at_reboot && t6020->sleep_router_on_stop); + assert(t6020->sleep_displays_first && !t6020->psd_power_cycle); + assert(t6020->dp == &apple_dpin_m2); struct apple_cio acio_t8122 = { .hw = t8122 }; struct apple_cio acio_t8103 = { .hw = t8103 }; struct apple_cio acio_t6020 = { .hw = t6020 }; - /* mem_sleep=deep + mem tears down T8103 and T8122 ACIO, leaves T6020 unchanged. */ + /* mem_sleep=deep + mem tears down T8103, T8122 and T6020 ACIO. */ default_s2idle = false; no_platform = false; assert(apple_cio_sleep_removes_domains(&acio_t8122)); assert(apple_cio_sleep_removes_domains(&acio_t8103)); - assert(!apple_cio_sleep_removes_domains(&acio_t6020)); + assert(apple_cio_sleep_removes_domains(&acio_t6020)); /* s2idle keeps the port up. */ default_s2idle = true; no_platform = false; assert(!apple_cio_sleep_removes_domains(&acio_t8122)); assert(!apple_cio_sleep_removes_domains(&acio_t8103)); + assert(!apple_cio_sleep_removes_domains(&acio_t6020)); /* freeze keeps the port up even when mem_sleep=deep is the default. */ default_s2idle = false; no_platform = true; assert(!apple_cio_sleep_removes_domains(&acio_t8122)); assert(!apple_cio_sleep_removes_domains(&acio_t8103)); + assert(!apple_cio_sleep_removes_domains(&acio_t6020)); /* Shared ATC PHY: ACIO PM notifier must run before DWC3's. */ struct dwc3_apple dwc = { 0 }; @@ -1394,7 +1402,7 @@ def test_pm_order(out, acio): assert(!chain[i]->notifier_call()); assert(pci_off && phy_off); - puts("PASS: T8103/T8122 ACIO deep-sleep teardown, freeze/s2idle preservation, and DWC3 PM order"); + puts("PASS: T8103/T8122/T6020 ACIO deep-sleep teardown, freeze/s2idle preservation, and DWC3 PM order"); return 0; } ''' @@ -1440,6 +1448,11 @@ def test_t8122_cio_sleep(out, acio): 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n' '\t.sleep_removes_domains = true,\n', 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n'), + 't6020-drop-sleep-removes-domains': ( + 'static const struct apple_cio_hw apple_cio_t6020_hw = {\n' + '\t.sleep_removes_domains = true,\n', + 'static const struct apple_cio_hw apple_cio_t6020_hw = {\n'), + 't6020-drop-displays-first': ('\t.sleep_displays_first = true,\n', ''), 't8122-drop-phy-shared': ( 'static const struct apple_cio_hw apple_cio_t8122_hw = {\n' '\t.sleep_removes_domains = true,\n'