Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions arch/arm64/boot/dts/apple/t604x-pmgr.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
};

Expand Down Expand Up @@ -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>;
};

Expand Down Expand Up @@ -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>;
};
};
Expand Down Expand Up @@ -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";
};

Expand Down
61 changes: 61 additions & 0 deletions drivers/phy/apple/t6040-usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/suspend.h>
#include <linux/reset-controller.h>
#include <linux/soc/apple/dp-tunnel.h>
#include <linux/soc/apple/rtkit.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading