From a9454a5477b4c3be07c6b962e5f61fbfcb9731a7 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 04:24:50 +1100 Subject: [PATCH 1/4] phy: apple: t6040: keep a running coprocessor's domains on through s2idle In suspend-to-idle the Type-C link stays up: the USB4/Thunderbolt router holds its own power domains out of the system transition while a cable is set up, and nothing stops a running PHY coprocessor. genpd still powered off this PHY's domain (common_dp, and phymxwrap above it) in its noirq phase, under the running coprocessor. The link died shortly after resume ("SBX disconnected"), and the detach that followed found a coprocessor that no longer answered: RTKit: AP idle not acknowledged: -62 USB3: PHY coprocessor idle failed: -62 ... RTKit: endpoint discovery failed: -62 sn201202x 1-0c: failed to configure Type-C connection: -62 From then on every start failed the same way until a reboot, hard recoveries included, although a hard recovery brings back a port that never slept. Hold the PHY device out of the whole suspend-to-idle transition, from before its prepare to after its complete, while its coprocessor runs, so genpd leaves its domains on. Sleeps the platform firmware takes part in are left as they were (pm_suspend_no_platform() is false there). Signed-off-by: Ryan Murray --- drivers/phy/apple/t6040-usb2.c | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..c6d567a0b5834 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -285,6 +286,8 @@ struct t6040_usb2_phy { struct completion app_reply; struct t6040_recovery_state recovery; atomic_t drop_next_power_down_ack; + struct notifier_block pm_nb; + bool s2idle_held; /* held out of this suspend-to-idle, see t6040_pm_notify() */ struct dentry *debugfs; enum typec_orientation orientation; bool usb3_up; /* tuned by the coprocessor this power cycle */ @@ -2128,6 +2131,52 @@ static void t6040_rtkit_cleanup(void *data) t6040_rtkit_stop_transport(data); } +/* + * Suspend-to-idle leaves the Type-C link up: the USB4/Thunderbolt router keeps + * its own domains out of the system transition while a cable is set up, and a + * running PHY coprocessor is not stopped either. genpd would still power off + * common_dp (and with it phymxwrap) in its noirq phase once this device has + * suspended, under the running coprocessor: the link then dies after resume and + * the next detach finds a coprocessor that no longer answers (AP idle -62). + * Hold this device out of the whole transition, from before its prepare to + * after its complete, while its coprocessor runs, so its domains stay on. A + * sleep the platform takes part in (firmware suspend) is left as it was. + */ +static int t6040_pm_notify(struct notifier_block *nb, unsigned long action, void *data) +{ + struct t6040_usb2_phy *tphy = container_of(nb, struct t6040_usb2_phy, pm_nb); + + switch (action) { + case PM_SUSPEND_PREPARE: + if (!pm_suspend_no_platform()) + break; + scoped_guard(mutex, &tphy->lock) { + if (tphy->rtk && apple_rtkit_is_running(tphy->rtk)) { + dev_pm_syscore_device(tphy->dev, true); + tphy->s2idle_held = true; + dev_dbg(tphy->dev, "PHY coprocessor running: domains kept on for s2idle\n"); + } + } + break; + case PM_POST_SUSPEND: + scoped_guard(mutex, &tphy->lock) { + if (tphy->s2idle_held) { + dev_pm_syscore_device(tphy->dev, false); + tphy->s2idle_held = false; + } + } + break; + } + return NOTIFY_DONE; +} + +static void t6040_pm_notifier_unregister(void *data) +{ + struct t6040_usb2_phy *tphy = data; + + unregister_pm_notifier(&tphy->pm_nb); +} + static void t6040_mbox_dev_put(void *data) { put_device(data); @@ -2296,6 +2345,14 @@ static int t6040_usb3_probe(struct t6040_usb2_phy *tphy, struct platform_device if (ret) return ret; + tphy->pm_nb.notifier_call = t6040_pm_notify; + ret = register_pm_notifier(&tphy->pm_nb); + if (ret) + return ret; + ret = devm_add_action_or_reset(dev, t6040_pm_notifier_unregister, tphy); + if (ret) + return ret; + ret = t6040_debugfs_init(tphy); if (ret) return ret; From 73dea0df7a51aedda30612268872879f1b8ba2af Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:55:52 +1100 Subject: [PATCH 2/4] dt-bindings: power: apple,pmgr-pwrstate: sleep-wakeup-path covers a running consumer apple,sleep-wakeup-path was written for a consumer that the sleep's final commit stops after the noirq phase. A consumer that keeps running through the whole sleep while it is on the wakeup path needs the same thing from the OS: keep the domain on through system sleep, also when it was off when the power controller probed. Say so in the description. No change in meaning for existing users. Signed-off-by: Ryan Murray --- .../bindings/power/apple,pmgr-pwrstate.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index d8c03b0a12702..537ae7012bc76 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -151,11 +151,12 @@ properties: apple,sleep-wakeup-path: description: - A consumer of this domain is stopped by the system sleep's final commit, - after the noirq phase, and stays on the wakeup path until then. The OS - keeps the domain on through system sleep while a device under it is on - the wakeup path, also when the domain was off when the power controller - probed. Other domains are unaffected. + A consumer of this domain can keep running into system sleep, until the + sleep's final commit after the noirq phase or through the whole sleep, + and is then on the wakeup path. The OS keeps the domain on through + system sleep while a device under it is on the wakeup path, also when + the domain was off when the power controller probed. Other domains are + unaffected. type: boolean apple,firmware-owned: From c1c5e672585dd1578709b21fa901b5936bb2c444 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:55:53 +1100 Subject: [PATCH 3/4] arm64: dts: apple: t604x: mark the ATC common_dp domains sleep-wakeup-path The Type-C PHY coprocessor under atcN_common_dp keeps running through suspend-to-idle while a link is up. Mark the four common_dp domains apple,sleep-wakeup-path so that genpd keeps one on while the PHY puts itself on the awake path, also when the domain was off when the power controller probed (no cable at boot). phymxwrap above it stays on through its subdomain count. Nothing changes for a PHY that is not on the awake path. Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t604x-pmgr.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t604x-pmgr.dtsi b/arch/arm64/boot/dts/apple/t604x-pmgr.dtsi index 977818bca2ec3..daa6811c84111 100644 --- a/arch/arm64/boot/dts/apple/t604x-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t604x-pmgr.dtsi @@ -431,6 +431,8 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc0_common_dp"; + /* The PHY coprocessor can keep running through s2idle. */ + apple,sleep-wakeup-path; power-domains = <&ps_atc0_phymxwrap>; }; @@ -467,6 +469,8 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc1_common_dp"; + /* The PHY coprocessor can keep running through s2idle. */ + apple,sleep-wakeup-path; power-domains = <&ps_atc1_phymxwrap>; }; @@ -503,6 +507,8 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc2_common_dp"; + /* The PHY coprocessor can keep running through s2idle. */ + apple,sleep-wakeup-path; power-domains = <&ps_atc2_phymxwrap>; }; }; @@ -578,6 +584,8 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "atc3_common_dp"; + /* The PHY coprocessor can keep running through s2idle. */ + apple,sleep-wakeup-path; status = "disabled"; }; From e1b79fc07d8e86e9db631754c573a3b894e49238 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:55:53 +1100 Subject: [PATCH 4/4] phy: apple: t6040: hold a running coprocessor's domains via the awake path The PM notifier sampled "coprocessor running" once, at PM_SUSPEND_PREPARE. A coprocessor started later was not held: an attach between PREPARE and the device's suspend, or an attach during a dark wake, where enter_state() runs suspend_devices_and_enter() again without the notifiers (a cable or charger plugged into a closed, sleeping machine). genpd then powered common_dp off under it in noirq, which is the original bug. dev_pm_syscore_device() also kept the device out of the PM core's prepare/late handling altogether. Decide in the device's own .suspend instead, on every suspend pass, and put the device on the awake path with device_set_awake_path() while its coprocessor runs; common_dp carries apple,sleep-wakeup-path, so genpd keeps it (and phymxwrap above it) on. Decide again in .suspend_noirq, which genpd runs before its own awake-path check, for a coprocessor started after .suspend. In noirq a caller holding the PHY lock may be waiting for a coprocessor reply that cannot arrive; the outcome is then unknown, so the domains stay on for that sleep rather than block. The notifier, the syscore flag and the held state go away. Sleeps the platform firmware takes part in are left as they were (pm_suspend_no_platform() is false there). Signed-off-by: Ryan Murray --- drivers/phy/apple/t6040-usb2.c | 86 ++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index c6d567a0b5834..4e995d029785c 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -286,8 +286,6 @@ struct t6040_usb2_phy { struct completion app_reply; struct t6040_recovery_state recovery; atomic_t drop_next_power_down_ack; - struct notifier_block pm_nb; - bool s2idle_held; /* held out of this suspend-to-idle, see t6040_pm_notify() */ struct dentry *debugfs; enum typec_orientation orientation; bool usb3_up; /* tuned by the coprocessor this power cycle */ @@ -2135,48 +2133,61 @@ static void t6040_rtkit_cleanup(void *data) * Suspend-to-idle leaves the Type-C link up: the USB4/Thunderbolt router keeps * its own domains out of the system transition while a cable is set up, and a * running PHY coprocessor is not stopped either. genpd would still power off - * common_dp (and with it phymxwrap) in its noirq phase once this device has - * suspended, under the running coprocessor: the link then dies after resume and - * the next detach finds a coprocessor that no longer answers (AP idle -62). - * Hold this device out of the whole transition, from before its prepare to - * after its complete, while its coprocessor runs, so its domains stay on. A - * sleep the platform takes part in (firmware suspend) is left as it was. + * common_dp (and with it phymxwrap) in its noirq phase under the running + * coprocessor: the link then dies after resume and the next detach finds a + * coprocessor that no longer answers (AP idle -62). Put this device on the + * awake path while its coprocessor runs, so genpd keeps the domains on + * (common_dp carries apple,sleep-wakeup-path). The decision is taken again in + * every suspend pass, dark wakes included, and once more in noirq for a + * coprocessor started after .suspend. A sleep the platform takes part in + * (firmware suspend) is left as it was. */ -static int t6040_pm_notify(struct notifier_block *nb, unsigned long action, void *data) +static void t6040_keep_running_cpu_awake(struct t6040_usb2_phy *tphy, bool noirq) { - struct t6040_usb2_phy *tphy = container_of(nb, struct t6040_usb2_phy, pm_nb); + bool running; - switch (action) { - case PM_SUSPEND_PREPARE: - if (!pm_suspend_no_platform()) - break; - scoped_guard(mutex, &tphy->lock) { - if (tphy->rtk && apple_rtkit_is_running(tphy->rtk)) { - dev_pm_syscore_device(tphy->dev, true); - tphy->s2idle_held = true; - dev_dbg(tphy->dev, "PHY coprocessor running: domains kept on for s2idle\n"); - } - } - break; - case PM_POST_SUSPEND: - scoped_guard(mutex, &tphy->lock) { - if (tphy->s2idle_held) { - dev_pm_syscore_device(tphy->dev, false); - tphy->s2idle_held = false; - } + if (!pm_suspend_no_platform()) + return; + + if (noirq) { + /* + * An attach or detach holding the lock may wait for a coprocessor + * reply that cannot arrive now. Its outcome is unknown: keep the + * domains on for this sleep. + */ + if (!mutex_trylock(&tphy->lock)) { + device_set_awake_path(tphy->dev); + return; } - break; + } else { + mutex_lock(&tphy->lock); + } + running = tphy->rtk && apple_rtkit_is_running(tphy->rtk); + mutex_unlock(&tphy->lock); + + if (running) { + device_set_awake_path(tphy->dev); + dev_dbg(tphy->dev, "PHY coprocessor running: domains kept on for s2idle\n"); } - return NOTIFY_DONE; } -static void t6040_pm_notifier_unregister(void *data) +static int t6040_usb2_suspend(struct device *dev) { - struct t6040_usb2_phy *tphy = data; + t6040_keep_running_cpu_awake(dev_get_drvdata(dev), false); + return 0; +} - unregister_pm_notifier(&tphy->pm_nb); +static int t6040_usb2_suspend_noirq(struct device *dev) +{ + t6040_keep_running_cpu_awake(dev_get_drvdata(dev), true); + return 0; } +static const struct dev_pm_ops t6040_usb2_pm_ops = { + .suspend = t6040_usb2_suspend, + .suspend_noirq = t6040_usb2_suspend_noirq, +}; + static void t6040_mbox_dev_put(void *data) { put_device(data); @@ -2345,14 +2356,6 @@ static int t6040_usb3_probe(struct t6040_usb2_phy *tphy, struct platform_device if (ret) return ret; - tphy->pm_nb.notifier_call = t6040_pm_notify; - ret = register_pm_notifier(&tphy->pm_nb); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, t6040_pm_notifier_unregister, tphy); - if (ret) - return ret; - ret = t6040_debugfs_init(tphy); if (ret) return ret; @@ -2562,6 +2565,7 @@ static struct platform_driver t6040_usb2_driver = { .driver = { .name = "phy-apple-t6040-usb2", .of_match_table = t6040_usb2_of_match, + .pm = pm_sleep_ptr(&t6040_usb2_pm_ops), }, }; module_platform_driver(t6040_usb2_driver);