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
24 changes: 21 additions & 3 deletions drivers/thunderbolt/apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

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

Expand Down Expand Up @@ -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" : "");
Expand All @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions tools/asahi/pciec-policy-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down Expand Up @@ -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 };
Expand All @@ -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;
}
'''
Expand Down Expand Up @@ -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'
Expand Down
Loading