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: 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"; }; diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index 50d82116aac2d..4e995d029785c 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 @@ -2128,6 +2129,65 @@ 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 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 void t6040_keep_running_cpu_awake(struct t6040_usb2_phy *tphy, bool noirq) +{ + bool running; + + 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; + } + } 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"); + } +} + +static int t6040_usb2_suspend(struct device *dev) +{ + t6040_keep_running_cpu_awake(dev_get_drvdata(dev), false); + return 0; +} + +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); @@ -2505,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);