From 69c61aa579cf294b1dc438c1b1a989104f2d7be6 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 16:35:53 -0300 Subject: [PATCH 01/16] net: atlantic: a sleep after a resume that failed When aq_nic_init() fails in atl_resume_common() ("Boot code hanged", a controller that did not come back from a sleep), the resume returns with the interface still running and the datapath as aq_suspend_common() left it: interrupts freed and the NAPI contexts disabled. The next suspend, or closing the interface, calls aq_nic_stop() again, and its second napi_disable() on each vector waits for ever, holding the RTNL lock. On the Mac Studio (J575c) this hung the deep sleep that followed a wake on which the 10 GbE controller's link had not trained; with the link held down on purpose, "ip link set end0 down" then blocks in napi_disable() from aq_vec_stop(). Mark the datapath from the start of aq_nic_start() to aq_nic_stop(), and make a stop without a start since then return at once. A start that fails part way still sets the mark, so its caller's aq_nic_stop() undoes it as before. A stop after a start is unchanged. The same suspend then asks the absent controller's firmware for its wake-on-LAN state and warns when the request times out (hw_atl2_shared_buffer_finish_ack). aq_nic_deinit() already skips its firmware request for a device that is no longer present; skip aq_nic_set_power()'s the same way. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- .../net/ethernet/aquantia/atlantic/aq_nic.c | 21 ++++++++++++++++++- .../net/ethernet/aquantia/atlantic/aq_nic.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c index 01792f7abf962..a2cd29280201f 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c @@ -516,8 +516,10 @@ int aq_nic_start(struct aq_nic_s *self) aq_vec = self->aq_vec[i]; err = aq_vec_start(aq_vec); if (err < 0) - goto err_exit; + goto err_vec; } + /* All vectors have NAPI enabled; a failure past here is undone by aq_nic_stop(). */ + aq_utils_obj_set(&self->flags, AQ_NIC_FLAG_DPATH_UP); err = aq_reapply_rxnfc_all_rules(self); if (err < 0) @@ -599,6 +601,11 @@ int aq_nic_start(struct aq_nic_s *self) } netif_tx_start_all_queues(self->ndev); + return 0; + +err_vec: + while (i--) + aq_vec_stop(self->aq_vec[i]); err_exit: return err; } @@ -1428,6 +1435,15 @@ int aq_nic_stop(struct aq_nic_s *self) { unsigned int i = 0U; + /* + * Stopped already, with no start since: a resume whose aq_nic_init() failed leaves + * the interface running and its NAPI contexts disabled, and a second napi_disable() + * would wait for ever. + */ + if (!aq_utils_obj_test(&self->flags, AQ_NIC_FLAG_DPATH_UP)) + return 0; + aq_utils_obj_clear(&self->flags, AQ_NIC_FLAG_DPATH_UP); + netif_tx_disable(self->ndev); netif_carrier_off(self->ndev); @@ -1453,6 +1469,9 @@ int aq_nic_stop(struct aq_nic_s *self) void aq_nic_set_power(struct aq_nic_s *self) { + /* A controller that did not come back from a sleep answers no firmware request. */ + if (!pci_device_is_present(self->pdev)) + return; if (self->power_state != AQ_HW_POWER_STATE_D0 || self->aq_hw->aq_nic_cfg->wol) if (likely(self->aq_fw_ops->set_power)) { diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h index ad33f8586532b..d225f997699f6 100644 --- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.h +++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.h @@ -83,6 +83,8 @@ struct aq_nic_cfg_s { #define AQ_NIC_FLAG_STOPPING 0x00000008U #define AQ_NIC_FLAG_RESETTING 0x00000010U #define AQ_NIC_FLAG_CLOSING 0x00000020U +/* From aq_vec_start() completion in aq_nic_start() to aq_nic_stop() */ +#define AQ_NIC_FLAG_DPATH_UP 0x00000040U #define AQ_NIC_PTP_DPATH_UP 0x02000000U #define AQ_NIC_LINK_DOWN 0x04000000U #define AQ_NIC_FLAG_ERR_UNPLUG 0x40000000U From ed75d5aa98424684b542eb9cb58b8b7a57079966 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:40:45 -0300 Subject: [PATCH 02/16] soc: apple: display-gate: T6041 internal DCP without a panel The Mac Studio (J575c, M4 Max) has no panel, so its device tree describes none under the internal DCP. The boot loader hands that DCP over all the same when the board asks for it as the sleep host (apple,sleep-host-stop), and the display driver then keeps it to stop every display processor for suspend-to-RAM before the display power chains go down. Let the T6041 internal gate enable the DCP, its display and PIODMA when no panel is described; the panel is enabled only where there is one. Boards with a panel are unchanged. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/soc/apple/display-gate.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 71422a742f4ab..ea0124f884ec3 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -2288,8 +2288,9 @@ static void __init gate_t6041_internal(void) ret = -EINVAL; nodes[T6041_DISPLAY] = of_find_node_by_path("disp0"); nodes[T6041_PIODMA] = of_get_child_by_name(nodes[T6041_DCP], "piodma"); + /* A Mac with no panel (the J575c) describes none: the DCP then runs without one. */ nodes[T6041_PANEL] = of_get_child_by_name(nodes[T6041_DCP], "panel"); - if (!nodes[T6041_DISPLAY] || !nodes[T6041_PIODMA] || !nodes[T6041_PANEL] || + if (!nodes[T6041_DISPLAY] || !nodes[T6041_PIODMA] || !of_device_is_compatible(nodes[T6041_DISPLAY], gate_soc->display_compat) || !gate_marked(nodes[T6041_DCP]) || !gate_marked(nodes[T6041_DISPLAY]) || !gate_marked(nodes[T6041_PIODMA])) @@ -2319,7 +2320,7 @@ static void __init gate_t6041_internal(void) goto out; for (i = 0; i < ARRAY_SIZE(t6041_enable); i++) { - if (!gate_disabled(nodes[t6041_enable[i]])) { + if (nodes[t6041_enable[i]] && !gate_disabled(nodes[t6041_enable[i]])) { ret = -EBUSY; goto out; } @@ -2338,8 +2339,9 @@ static void __init gate_t6041_internal(void) of_changeset_init(&t6041_gate); for (i = 0; i < ARRAY_SIZE(t6041_enable) && !ret; i++) - ret = of_changeset_update_prop_string(&t6041_gate, nodes[t6041_enable[i]], - "status", "okay"); + if (nodes[t6041_enable[i]]) + ret = of_changeset_update_prop_string(&t6041_gate, nodes[t6041_enable[i]], + "status", "okay"); if (!ret && gate_disabled(nodes[T6041_PIODMA])) ret = of_changeset_update_prop_string(&t6041_gate, nodes[T6041_PIODMA], "status", "okay"); From 665af05f485ec78a98d82a68e4285c2cbe697f6d Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:40:46 -0300 Subject: [PATCH 03/16] drm: apple: dcp: DPAVCTRL ready on an internal processor without a panel On desktop firmware the internal processor announces only the AV controller on interface 5 and the deferred DP controller on interface 7, while an external one opens four interfaces or more. The readiness check told the two apart with dcp_has_panel(), so the J575c's internal processor, which drives no panel, waited for interfaces it never opens and its start timed out. Tell them apart by the processor (dcp_desktop_external()). A processor with a panel is internal either way, so nothing changes where there is a panel. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/gpu/drm/apple/dcp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 983bf74ac69d6..1af8b166d0fbd 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -4862,10 +4862,11 @@ static void dcp_dpavctrl_service_init(struct apple_epic_service *service, d->dpavctrl_late_service = service; /* - * The internal panel announces only the AV controller on interface 5 - * and the deferred DP controller on interface 7. + * The internal processor announces only the AV controller on + * interface 5 and the deferred DP controller on interface 7, with a + * panel or without one (the J575c). */ - if (dcp_has_panel(dcp)) { + if (!dcp_desktop_external(dcp)) { if (d->dpavctrl_av_controller[1] && d->dpavctrl_late_service) complete_all(&d->dpavctrl_ready); } else if (service->ep->num_channels >= 4) { From 49dbb225dc7903661fad97ef63df02e658cab34b Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:40:47 -0300 Subject: [PATCH 04/16] drm: apple: dcp: T6041 internal pipe the firmware took down at start With no display (no panel, no HPD) the firmware of the J575c's internal DCP takes its pipe down itself during start-up, with a D572(0), and Linux never powers it on. A sleep then has nothing to power off: a second set_power_state(0) gets no D572, and the stop for suspend-to-RAM timed out waiting for one. Mark the pipe off when that D572(0) comes outside a sleep on an internal processor that has no panel and is not active, so that the stop takes its "display already off" path. A processor with a panel is left alone, and only the T6041 sleep reads the mark. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/gpu/drm/apple/dcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 1af8b166d0fbd..3b2a28ff86357 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -10470,6 +10470,19 @@ void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) on, READ_ONCE(dcp->s2r_active)); guard(mutex)(&dcp->s2r_dart_lock); + + /* + * With no display at start (no HPD: the J575c's internal DCP drives no + * panel) the firmware takes its pipe down itself, before the start is + * done, and Linux never powers it on. A sleep then has no power-off to + * ask for: a second set_power_state(0) gets no D572. + */ + if (!dcp_desktop_external(dcp) && !dcp_has_panel(dcp) && !on && + !READ_ONCE(dcp->s2r_active) && !dcp->active) { + dev_dbg(dcp->dev, "display pipe off since start-up\n"); + WRITE_ONCE(dcp->pipe_off, true); + } + if (!READ_ONCE(dcp->s2r_active)) return; From 4f3ebc1d81b4b4af450fe7274ec994ae359d7b2e Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:40:48 -0300 Subject: [PATCH 05/16] drm: apple: dcp: T6041 sleep host without a display: no power-on after the wake The pipe of a processor with no display stays down after the wake too: dcp_t6041_recommit() powered it on and then waited for a D575 hotplug that such a processor never sends. Remember that the pipe has been off since start-up, until anything powers it on, and leave it off after the wake: no power-on, no mode set. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/dcp.c | 8 ++++++++ drivers/gpu/drm/apple/iomfb_template.c | 1 + 3 files changed, 11 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 4d92238a28558..b47ff1bc37fe4 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1130,6 +1130,8 @@ struct apple_dcp { * started since: its D572(0) has come and gone, and a second set_power_state(0) gets none. */ bool pipe_off; + /* The firmware took the pipe down at start (no display) and nothing has powered it on. */ + bool pipe_off_since_start; /* Refused its idle with the display off: the firmware still runs, the display is dark. */ bool s2r_refused_off; /* The firmware's secure mailbox, where it has one. */ diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 3b2a28ff86357..5b450e7947ca1 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -10481,6 +10481,7 @@ void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) !READ_ONCE(dcp->s2r_active) && !dcp->active) { dev_dbg(dcp->dev, "display pipe off since start-up\n"); WRITE_ONCE(dcp->pipe_off, true); + WRITE_ONCE(dcp->pipe_off_since_start, true); } if (!READ_ONCE(dcp->s2r_active)) @@ -13890,6 +13891,13 @@ static int dcp_t6041_display_poweron(struct apple_dcp *dcp) ktime_t start = ktime_get(); int ret; + /* + * A pipe the firmware took down at start, with no display, stays down: no power-on, so no + * D575 to wait for, and no mode to set (the J575c's internal DCP, the sleep host). + */ + if (READ_ONCE(dcp->pipe_off_since_start)) + return 0; + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) { WRITE_ONCE(dcp->pipe_off, false); WRITE_ONCE(dcp->afk_power_gen, dcp->afk_power_gen + 1); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 36dca5e1e1463..6adfbeae262ca 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -2691,6 +2691,7 @@ void DCP_FW_NAME(iomfb_poweron)(struct apple_dcp *dcp) #endif dev_info(dcp->dev, "dcp_poweron() starting\n"); WRITE_ONCE(dcp->pipe_off, false); + WRITE_ONCE(dcp->pipe_off_since_start, false); #if DCP_FW_H17(DCP_FW_VER) if (dcp_is_ext26(dcp)) return; /* Native26 publishes A473 only after a successful A413. */ From dd4033cccacd3130be4f4bc809525dee8fa855b0 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:08 -0300 Subject: [PATCH 06/16] dt-bindings: display: apple,t8140-display-power: add apple,dcp to chains A T6041 external display chain may name the display coprocessor it powers. The driver then restarts that coprocessor after the wake from suspend-to-RAM, as T6040 does for its external chains, instead of shutting it down for good. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- .../bindings/display/apple,t8140-display-power.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 974dd84d1cbf7..5affc5c1c587d 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -98,6 +98,14 @@ patternProperties: Byte offsets of the pair of power-gate retention words (A, then B) within the selected pwrgate window. + apple,dcp: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Read on T6041 only, on an external display chain. The display coprocessor + this chain powers, which is then restarted after wake as on T6040. + Without it the coprocessor is shut down for suspend-to-RAM and stays + off after wake. + apple,fabric-domain: $ref: /schemas/types.yaml#/definitions/phandle description: From 8f1da2874c5be2345e51d7873d5ac63af92a2c0a Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:09 -0300 Subject: [PATCH 07/16] drm: apple: dcp: T6041 external DCPs back after the wake through T6040's path T6040's sleep takes its external links down and restarts their DCPs after the wake (dcp_t6040_ext_link_down(), dcp_t6040_ext_start_one()). On T6041 they were shut down for the sleep and stayed off, so external displays stayed dark after it. Send a T6041 external DCP whose display power chain names it (apple,dcp) the same way: - dcp_t6040_relinks() takes the DCP: true on T6040, and on T6041 only for an external DCP with such a chain; - dcp_t6040_ext_chain() finds that chain by the phandle on T6041 (T6040 keeps its ext%u label); - such a chain's child domains are saved by the power word step, as T6040's are; - T6041's display DARTs are locked, so the two of such a DCP keep their TCR/TTBR words across the sleep (apple_dart_display_keep()), as the internal DCP's do; - the external start pass runs on every SoC; without a chain it does nothing. Chains without apple,dcp, and every T6040 path, are unchanged. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/gpu/drm/apple/dcp-internal.h | 5 + drivers/gpu/drm/apple/dcp.c | 134 ++++++++++++++++++-------- drivers/gpu/drm/apple/dcp.h | 2 +- drivers/gpu/drm/apple/iomfb.c | 4 +- tools/asahi/dcpext26-retrain-tests.py | 4 +- 5 files changed, 103 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index b47ff1bc37fe4..1e3af2c1c0fb0 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -320,6 +320,11 @@ struct dcp_t6041_chain { unsigned int num_domains; /* T6040: an external chain's child_saved holds what its stop found */ bool child_valid; + /* + * T6041: the external DCP this chain powers (apple,dcp), restarted after the wake as + * T6040's are; 0 if none, and that DCP stays off after the wake. + */ + phandle dcp; }; /* diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 5b450e7947ca1..bbaa92dcca204 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -8701,6 +8701,13 @@ static int dcp_t6041_parse_chain(struct device *dev, struct dcp_t6041_power *pwr chain->is_main = of_property_read_bool(child, "apple,main-chain"); pg_aux = of_property_read_bool(child, "apple,pwrgate-aux"); + if (!chain->is_main) { + struct device_node *dcp_np __free(device_node) = + of_parse_phandle(child, "apple,dcp", 0); + + if (dcp_np) + chain->dcp = dcp_np->phandle; + } if (of_property_read_u32(child, "apple,gapf-offset", &gapf_off) || (gapf_off & 3) || gapf_off > gapf_size || gapf_size - gapf_off < sizeof(u32)) { @@ -8763,7 +8770,7 @@ static int dcp_t6041_parse_chain(struct device *dev, struct dcp_t6041_power *pwr chain->domains[i] = reg; } - if ((chain->is_main || pwr->t6040) && count > 3) { + if ((chain->is_main || pwr->t6040 || chain->dcp) && count > 3) { chain->child_saved = devm_kcalloc(dev, count - 3, sizeof(*chain->child_saved), GFP_KERNEL); if (!chain->child_saved) @@ -13279,16 +13286,59 @@ static int dcp_t6041_recommit_planes(struct apple_dcp *dcp); */ #define DCP_S2R_PLUG_MS 10000 +/* + * The chain of an external DCP that is restarted after the wake. T6040: by its label, + * apple,dcp-endpoint 1 is ext0. T6041: the chain that names it (apple,dcp), if one does. + */ +static struct dcp_t6041_chain *dcp_t6040_ext_chain(struct apple_dcp *host, + struct apple_dcp *dcp) +{ + struct dcp_t6041_power *pwr = &host->t6041_power; + phandle ph = dcp->dev->of_node ? dcp->dev->of_node->phandle : 0; + char name[16]; + unsigned int i; + + if (!pwr->t6040) { + for (i = 0; i < pwr->num_chains && ph; i++) + if (!pwr->chains[i].is_main && pwr->chains[i].dcp == ph) + return &pwr->chains[i]; + return NULL; + } + if (!dcp->peer_endpoint) + return NULL; + snprintf(name, sizeof(name), "ext%u", dcp->peer_endpoint - 1); + for (i = 0; i < pwr->num_chains; i++) + if (!pwr->chains[i].is_main && !strcmp(pwr->chains[i].name, name)) + return &pwr->chains[i]; + return NULL; +} + /* * T6040 (apple,t6040-display-power): its sleep takes the external links down and back, its * external DCPs being restarted after the wake as the internal one (dcp_t6040_ext_start_one()). - * On T6041 they are shut down and stay off. + * On T6041 only those whose chain names them (apple,dcp) are; the others are shut down and + * stay off. */ -bool dcp_t6040_relinks(void) +bool dcp_t6040_relinks(struct apple_dcp *dcp) { struct apple_dcp *host = READ_ONCE(dcp_t6041_host); - return host && host->t6041_power.t6040; + if (!host || !dcp) + return false; + if (host->t6041_power.t6040) + return true; + return dcp != host && dcp_t6040_ext_chain(host, dcp); +} + +/* + * T6041's display DARTs are locked (apple_dart_display_keep()): an external DCP restarted after + * the wake keeps their words across the sleep, as the internal one does. + */ +static bool dcp_t6041_ext_keeps(struct apple_dcp *dcp) +{ + struct apple_dcp *host = READ_ONCE(dcp_t6041_host); + + return host && !host->t6041_power.t6040 && dcp_t6040_relinks(dcp); } /* The fixed HDMI output of a T6040 external DCP, not lent to a Type-C display. */ @@ -13366,7 +13416,8 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi /* The display DART's streams turned off here, not by a D572(0). */ bool streams_off = false; bool idle_attempted = false; - bool t6040 = dcp_t6040_relinks(); + /* T6040's sleep, or a T6041 external DCP restarted after the wake as T6040's are. */ + bool t6040 = dcp_t6040_relinks(dcp); bool relink; u32 ctrl, status; int ret; @@ -13441,6 +13492,16 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi if (dcp->s2r_dcp_dart && !external) apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true); keep_set = !external; + /* A T6041 external one's too: they are locked as well (dcp_t6041_ext_keeps()). */ + if (relink && dcp_t6041_ext_keeps(dcp)) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, true); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, + DCP_S2R_DCP_STREAMS, true); + keep_set = true; + } /* * As linux#1477 dcp_t6041_s2r_stop: the pipe off through the firmware, then wait for * its calls to settle. No av_service_disconnect: the firmware answered it with an @@ -13653,20 +13714,21 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi { int dart_ret = 0; - if (!external) { - if (keep_set) { - if (dcp->s2r_disp_dart) - apple_dart_display_keep(dcp->s2r_disp_dart, - DCP_S2R_DISP_STREAMS, false); - if (dcp->s2r_dcp_dart) - apple_dart_display_keep(dcp->s2r_dcp_dart, - DCP_S2R_DCP_STREAMS, false); - } - if ((powered_off || streams_off) && dcp->s2r_disp_dart) - dart_ret = apple_dart_display_streams(dcp->s2r_disp_dart, - DCP_S2R_DISP_STREAMS, - true, false); - } + if (keep_set) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, false); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, + DCP_S2R_DCP_STREAMS, false); + } + if (!external && (powered_off || streams_off) && dcp->s2r_disp_dart) + dart_ret = apple_dart_display_streams(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, + true, false); + if (relink && (powered_off || streams_off) && dcp->s2r_disp_dart) + apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, + true, false); dcp_s2r_put_darts(dcp); if (dart_ret) { dev_err(dev, "display DART restore after failed stop failed: %d\n", @@ -13675,9 +13737,6 @@ static int dcp_t6041_stop_dev(struct apple_dcp *dcp, bool external, bool recommi return ret; } } - if (relink && powered_off && dcp->s2r_disp_dart) - apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true, false); - dcp_s2r_put_darts(dcp); iomfb_pause_presentation(dcp, false); if (idle_attempted) { int ap_ret = apple_rtkit_ap_power(dcp->rtk, true); @@ -14387,23 +14446,6 @@ static bool dcp_t6040_word_up(void __iomem *w) 50, 10000); } -/* T6040: the chain of an external DCP, by its label: apple,dcp-endpoint 1 is ext0. */ -static struct dcp_t6041_chain *dcp_t6040_ext_chain(struct apple_dcp *host, - struct apple_dcp *dcp) -{ - struct dcp_t6041_power *pwr = &host->t6041_power; - char name[16]; - unsigned int i; - - if (!dcp->peer_endpoint) - return NULL; - snprintf(name, sizeof(name), "ext%u", dcp->peer_endpoint - 1); - for (i = 0; i < pwr->num_chains; i++) - if (!pwr->chains[i].is_main && !strcmp(pwr->chains[i].name, name)) - return &pwr->chains[i]; - return NULL; -} - /* * T6040: an external DCP after the wake, as the internal one (dcp_t6041_start_one()): its * chain's domains in the same order (SYS, the retention pair, FE, the GAPF protection off, CPU, @@ -14460,6 +14502,13 @@ static int dcp_t6040_ext_start_one(struct device *dev, void *data) of_node_put(piodma); dcp_t6041_dart_dark(dev->of_node, false); dcp_s2r_find_darts(dcp); + /* T6041: the words its locked DARTs had before the sleep (dcp_t6041_stop_one()). */ + if (!host->t6041_power.t6040) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, false); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, false); + } if (dcp->s2r_disp_dart) apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true, false); if (dcp->s2r_dcp_dart) @@ -14633,8 +14682,11 @@ static int dcp_t6041_s2r_step(enum dcp_t6041_step step) dcp_t6041_words = false; ret = driver_for_each_device(&apple_platform_driver.driver, NULL, NULL, dcp_t6041_start_one); - /* T6040: the external DCPs once the internal display runs again. */ - if (!ret && host->t6041_power.t6040) + /* + * The external DCPs once the internal display runs again: on T6040 all of them, + * on T6041 those whose chain names them (dcp_t6040_ext_chain()). + */ + if (!ret) ret = driver_for_each_device(&apple_platform_driver.driver, NULL, host, dcp_t6040_ext_start_one); return ret; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index c68f55fb41835..c945ba19a5397 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -181,7 +181,7 @@ bool dcp_hold_resume_event(struct platform_device *pdev); bool dcp_s2r_firmware_stopped(struct platform_device *pdev); int dcp_t6041_s2r_all(bool start); int dcp_t6041_s2idle(bool start); -bool dcp_t6040_relinks(void); +bool dcp_t6040_relinks(struct apple_dcp *dcp); int iomfb_start_rtkit(struct apple_dcp *dcp); void iomfb_ext26_start(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 46abe27ef302a..2ec1fdbccd781 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -1629,7 +1629,7 @@ static int dcp_retrain_active_crtc(struct apple_connector *connector, (READ_ONCE(dcp->mode_state.valid) || !dcp_has_mode(dcp, &crtc->state->mode))) { ret = 0; - } else if (dcp_t6040_relinks() && crtc && crtc->state && crtc->state->active && + } else if (dcp_t6040_relinks(dcp) && crtc && crtc->state && crtc->state->active && !dcp_mode_settable(dcp, &crtc->state->mode) && !dcp_typec_follows_crtc(dcp)) { /* @@ -2065,7 +2065,7 @@ void dcp_hotplug(struct work_struct *work) * mode list: the plug that follows reads that list, so a link recovery * pending for the old one would only take the new link down. */ - if (!READ_ONCE(connector->connected) && dcp_t6040_relinks()) + if (!READ_ONCE(connector->connected) && dcp_t6040_relinks(dcp)) cancel_delayed_work(&dcp->link_recovery_wq); scoped_guard(mutex, &connector->base.dev->mode_config.mutex) { diff --git a/tools/asahi/dcpext26-retrain-tests.py b/tools/asahi/dcpext26-retrain-tests.py index f4e8e784c2e81..d24c8940e684d 100644 --- a/tools/asahi/dcpext26-retrain-tests.py +++ b/tools/asahi/dcpext26-retrain-tests.py @@ -13,7 +13,7 @@ body = s[a:b] if '--negative-control' in sys.argv: a = body.index('\t} else if (dcp_is_ext26(dcp) && crtc && crtc->state &&') - b = body.index('\t} else if (dcp_t6040_relinks() && crtc && crtc->state &&', a) + b = body.index('\t} else if (dcp_t6040_relinks(dcp) && crtc && crtc->state &&', a) body = body[:a] + body[b:] pre = r''' @@ -46,7 +46,7 @@ #define DRM_MODESET_LOCK_ALL_END(dev, ctx, ret) } while (0) static bool dcp_is_ext26(struct apple_dcp *d) { return d->native; } static bool dcp_has_mode(struct apple_dcp *d, const struct mode *m) { return d->admitted && m->id == 1; } -static bool dcp_t6040_relinks(void) { return t604x; } +static bool dcp_t6040_relinks(struct apple_dcp *d) { return t604x; } static bool dcp_mode_settable(struct apple_dcp *d, const struct mode *m) { return !unlisted; } static bool dcp_typec_follows_crtc(struct apple_dcp *d) { return follows; } static bool dcp_crtc_lost_route(struct drm_crtc *c, struct apple_connector *p) { return lost; } From 061e4f5c09be827be5225951441332fd4d46c7eb Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:46 -0300 Subject: [PATCH 08/16] arm64: dts: apple: t6041-j575c: PCIe windows for deep sleep The T6041 sleep driver sets the ANS link's PCIe up again after the wake from the axi2af, cio3pll, clkgen, phy-block and phy-ip windows of the PCIe node (apple,apcie). Without them it offers no deep sleep ("no PCIe tunables for ANS"). Same blocks, at the same addresses, as on the J614c/J616c. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- arch/arm64/boot/dts/apple/t6041-j575c.dts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index 9ce2d8d884d23..2c274dce2cb35 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -1230,10 +1230,17 @@ <0x4 0x17020000 0x0 0x4000>, <0x4 0x17024000 0x0 0x4000>, <0x4 0x17028000 0x0 0x4000>, - <0x4 0x1702c000 0x0 0x4000>; + <0x4 0x1702c000 0x0 0x4000>, + <0x4 0x16000000 0x0 0x1000000>, + <0x4 0x15046200 0x0 0x4000>, + <0x4 0x15044000 0x0 0x4000>, + <0x4 0x17000000 0x0 0x40000>, + <0x4 0x17040000 0x0 0x28000>; reg-names = "config", "rc", "port0", "port1", "port2", "port3", - "phy0", "phy1", "phy2", "phy3"; + "phy0", "phy1", "phy2", "phy3", + "axi2af", "cio3pll", "clkgen", + "phy-block", "phy-ip"; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; pinctrl-names = "default"; From 97816dfc665dfd9b4c1ce8ac505dd29ef321bd17 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:48 -0300 Subject: [PATCH 09/16] arm64: dts: apple: t6041-j575c: SMC rail mask for deep sleep As on the J614c/J616c, the SMC is given the VDD_CIO rail mask to keep at the sleep commit (apple,sleep-pmvc = <0x101>: port 0 stays powered for atc0_common). Unlike them, no apple,sleep-wake-type: the J575c's SMC has no WKTP key, and writing it fails (-EIO) and aborts the sleep. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- arch/arm64/boot/dts/apple/t6041-j575c.dts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index 2c274dce2cb35..c3fec8a17dac7 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -970,6 +970,8 @@ }; &smc { + /* VDD_CIO mask: bit 8 + bit 0 keeps port 0 powered for atc0_common at commit. */ + apple,sleep-pmvc = <0x101>; status = "okay"; smc_gpio_low: gpio-low { From 0890e7fdc8c4bf939452824718ee509f5588be3e Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:49 -0300 Subject: [PATCH 10/16] arm64: dts: apple: t6041-j575c: system power state for the port controllers The J575c's version of #2174: its four back Type-C port controllers (hpm0-3) take the sleep's system power states (apple,sleep-ssps), as the J614c/J616c's do. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi | 1 + arch/arm64/boot/dts/apple/t6041-j575c.dts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi b/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi index 1fe04fb9e6212..caf74c6cbb877 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi +++ b/arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi @@ -115,6 +115,7 @@ <97 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index c3fec8a17dac7..13c6aceb2c781 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -1474,6 +1474,7 @@ <19 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; typec0: connector { compatible = "usb-c-connector"; @@ -1504,6 +1505,7 @@ <45 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; @@ -1537,6 +1539,7 @@ <71 IRQ_TYPE_EDGE_RISING>; interrupt-names = "irq", "select", "sleep", "wake"; apple,event-irq-in-sleep; + apple,sleep-ssps; /* Retimer set up before Linux keeps SuperSpeed down until replugged. */ apple,reset-inherited-usb2-connection; apple,debug-lock-key = "575J"; From fec6a56632e7ce2168a9d8971ed974fd8f03817b Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Sun, 29 Nov 2026 14:41:50 -0300 Subject: [PATCH 11/16] arm64: dts: apple: t6041-j575c: display power chains and the sleep host Describe the display power chains (apple,t6041-display-power): the four external chains, each naming its DCP so that it is restarted after the wake, and the internal one. The internal DCP drives no panel on the J575c; it is kept as the sleep host (apple,sleep-host-stop) that stops every display processor before the chains go down, with the display clock it needs, as on the J614c/J616c. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- arch/arm64/boot/dts/apple/t6041-j575c.dts | 99 +++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index 13c6aceb2c781..b0c2e21762285 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -2080,6 +2080,105 @@ phandle = <&display>; }; +/* + * The internal DCP runs no panel here. The boot loader hands it over all the + * same, and the display driver keeps it as the sleep host, which stops every + * display processor before the display power chains go down (the J616c's). + */ +/ { + clk_disp0: clock-disp0 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <712000000>; + clock-output-names = "disp0"; + }; + + dcp_power: display-power@5048a9c14 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x048a9c14 0x0 0x8>, + <0x5 0x022a1000 0x0 0x100>, + <0x5 0x0282d000 0x0 0x1000>, + <0x5 0x00578000 0x0 0x1000>, + <0x4 0x03000100 0x0 0x10>; + reg-names = "pmc-dcp", "pwrgate", "pwrgate-aux", "gapf", "axi2af"; + #address-cells = <1>; + #size-cells = <0>; + + chain@0 { + reg = <0>; + label = "ext3"; + apple,dcp = <&dcpext3>; + apple,pwrgate-aux; + apple,gapf-offset = <0x740>; + apple,pwrgate-offsets = <0xfb4 0xfd8>; + power-domains = <&ps_dispext3_sys>, <&ps_dispext3_fe>, <&ps_dispext3_cpu>, + <&ps_dispext3_dbe>, <&ps_dpext3>, <&ps_dispext3_gp0>, + <&ps_dispext3_gp1>, <&ps_dispext3_gpl>, <&ps_dispext3_ppp>, + <&ps_dispext3_dsc>; + }; + + chain@1 { + reg = <1>; + label = "ext2"; + apple,dcp = <&dcpext2>; + apple,pwrgate-aux; + apple,gapf-offset = <0xd80>; + apple,pwrgate-offsets = <0xb34 0xb58>; + power-domains = <&ps_dispext2_sys>, <&ps_dispext2_fe>, <&ps_dispext2_cpu>, + <&ps_dispext2_dbe>, <&ps_dpext2>, <&ps_dispext2_gp0>, + <&ps_dispext2_gp1>, <&ps_dispext2_gpl>, <&ps_dispext2_ppp>, + <&ps_dispext2_dsc>; + }; + + chain@2 { + reg = <2>; + label = "ext1"; + apple,dcp = <&dcpext1>; + apple,pwrgate-aux; + apple,gapf-offset = <0xd00>; + apple,pwrgate-offsets = <0x6b4 0x6d8>; + power-domains = <&ps_dispext1_sys>, <&ps_dispext1_fe>, <&ps_dispext1_cpu>, + <&ps_dispext1_dbe>, <&ps_dpext1>, <&ps_dispext1_gp0>, + <&ps_dispext1_gp1>, <&ps_dispext1_gpl>, <&ps_dispext1_ppp>, + <&ps_dispext1_dsc>; + }; + + chain@3 { + reg = <3>; + label = "ext0"; + apple,dcp = <&dcpext0>; + apple,pwrgate-aux; + apple,gapf-offset = <0x840>; + apple,pwrgate-offsets = <0x234 0x258>; + power-domains = <&ps_dispext0_sys>, <&ps_dispext0_fe>, <&ps_dispext0_cpu>, + <&ps_dispext0_dbe>, <&ps_dpext0>, <&ps_dispext0_gp0>, + <&ps_dispext0_gp1>, <&ps_dispext0_gpl>, <&ps_dispext0_ppp>, + <&ps_dispext0_dsc>; + }; + + chain@4 { + reg = <4>; + label = "main"; + apple,main-chain; + apple,gapf-offset = <0x540>; + apple,pwrgate-offsets = <0x1c 0x60>; + apple,fabric-domain = <&ps_fab6_soc>; + power-domains = <&ps_disp_sys>, <&ps_disp_fe>, <&ps_disp_cpu>, + <&ps_disp_spi>, <&ps_disp_spmi>, <&ps_disp_dbe>, + <&ps_disp_dp>, <&ps_disp_gp0>, <&ps_disp_gp1>, + <&ps_disp_gpl>, <&ps_disp_cmb>, <&ps_disp_ppp>, + <&ps_disp_brc>, <&ps_disp_blc>; + }; + }; +}; + +&dcp { + apple,sleep-host-stop; + apple,display-power = <&dcp_power>; + clocks = <&clk_disp0>; + phandle = <&dcp>; +}; + &disp0_piodma { phandle = <&disp0_piodma>; }; From e9eef9b25292cb6a376ff012fc13c619fe1c4820 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Tue, 1 Dec 2026 09:04:39 -0300 Subject: [PATCH 12/16] dt-bindings: pci: apple,pcie: add apple,no-refclk-gating Document the apple,no-refclk-gating boolean property for root ports whose endpoint requires a continuously running reference clock (matching the ADT no-refclk-gating property, e.g. the AQC113 10 GbE NIC on J575c). Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- Documentation/devicetree/bindings/pci/apple,pcie.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 86c4059480aa5..ef2d4c2c524a0 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -277,6 +277,13 @@ patternProperties: pwren-gpios may be left untrained; the OS then trains it first and adopts it the same way. + apple,no-refclk-gating: + type: boolean + description: + Do not enable dynamic REFCLK gating on this root port. Set when the + endpoint requires a continuously running reference clock (matching + the ADT no-refclk-gating property). + apple,tunable: $ref: '#/$defs/tunable' description: Initialization tuples relative to this port's registers. From 801ddbd58fd977f910efe22e8dd22529258ff52b Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Tue, 1 Dec 2026 09:05:20 -0300 Subject: [PATCH 13/16] PCI: apple: keep clocks ungated during S2R training and honor apple,no-refclk-gating Keep REFCLK and APPCLK ungated while retraining GP PCIe ports on S2R resume, enabling clock gating only after the link reaches L0, matching the T6050 / macOS training sequence. Previously apple_pcie_hib_port_start() enabled REFCLKCGEN and cleared PORT_APPCLK_CGDIS before asserting PORT_LTSSMCTL_START, right after PERST# release. Also honor the DT boolean property apple,no-refclk-gating both at probe (clearing iBoot's initial PHY_LANE_CFG_REFCLKCGEN bits) and after S2R link retraining, so ports whose endpoint requires a continuous reference clock (such as J575c's AQC113 on port 2) never have REFCLK gated. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/pci/controller/pcie-apple.c | 52 ++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 442bbd6d12809..3e514e0e31ab8 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -775,6 +775,7 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; + bool no_refclk_gating; void __iomem *intr2axi; /* adopt_link: this port's */ u8 adopted_bus; /* adopt_link: the secondary bus */ unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ @@ -3314,6 +3315,33 @@ static int apple_pcie_t6030_link_port_dart(struct apple_pcie_port *port) return ret; } +static void apple_pcie_port_enable_cg(struct apple_pcie *pcie, + struct apple_pcie_port *port) +{ + if (pcie->hw->retain_clocks) + return; + + if (port->no_refclk_gating) { + if (pcie->hw->port_refclk) + rmw_set(PORT_REFCLK_CGDIS, + port->base + pcie->hw->port_refclk); + else if (port->phy) + rmw_clear(PHY_LANE_CFG_REFCLKCGEN, + port->phy + PHY_LANE_CFG); + } else { + if (pcie->hw->port_refclk) + rmw_clear(PORT_REFCLK_CGDIS, + port->base + pcie->hw->port_refclk); + else if (port->phy) + rmw_set(PHY_LANE_CFG_REFCLKCGEN, + port->phy + PHY_LANE_CFG); + } + + /* PCIe-C APPCLK state is part of the m1n1 handoff. */ + if (!pcie->hw->tunneled) + rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); +} + static int apple_pcie_setup_port(struct apple_pcie *pcie, struct device_node *np) { @@ -3344,6 +3372,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, port->idx = idx >> 11; port->pcie = pcie; port->np = of_node_get(np); + port->no_refclk_gating = of_property_read_bool(np, "apple,no-refclk-gating"); raw_spin_lock_init(&port->lock); raw_spin_lock_init(&port->irq_lock); @@ -3489,18 +3518,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, } } - if (!pcie->hw->retain_clocks) { - if (pcie->hw->port_refclk) - rmw_clear(PORT_REFCLK_CGDIS, - port->base + pcie->hw->port_refclk); - else if (port->phy) - rmw_set(PHY_LANE_CFG_REFCLKCGEN, - port->phy + PHY_LANE_CFG); - - /* PCIe-C APPCLK state is part of the m1n1 handoff. */ - if (!pcie->hw->tunneled) - rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); - } + apple_pcie_port_enable_cg(pcie, port); ret = apple_pcie_port_setup_irq(port); if (ret) @@ -9927,15 +9945,15 @@ static void apple_pcie_hib_rid2sid(struct apple_pcie *pcie, struct apple_pcie_po mutex_unlock(&pcie->lock); } -/* Once its PHY is ready: clock gating, interrupts and RID-to-SID map, then training. */ +/* Once its PHY is ready: keep clocks un-gated for training, restore IRQs and RID2SID, train. */ static int apple_pcie_hib_port_start(struct apple_pcie *pcie, struct apple_pcie_port *port) { if (!pcie->hw->retain_clocks) { if (pcie->hw->port_refclk) - rmw_clear(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk); + rmw_set(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk); else if (port->phy) - rmw_set(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG); - rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); + rmw_clear(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG); + rmw_set(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); } /* All port interrupts masked and cleared, MSI routing as at probe. */ apple_pcie_tunnel_restore_irq_hw(port); @@ -9964,6 +9982,7 @@ static int apple_pcie_hib_port_trained(struct apple_pcie *pcie, struct apple_pci apple_pcie_port_readl(port, PORT_STATUS), stat); return ret; } + apple_pcie_port_enable_cg(pcie, port); apple_pcie_port_writel(port, BIT(PORT_INT_LINK_UP), PORT_INTSTAT); apple_pcie_port_writel(port, port->saved_intmask, PORT_INTMSK); return 0; @@ -10076,6 +10095,7 @@ static void apple_pcie_hib_ports_phased(struct apple_pcie *pcie) apple_pcie_hib_port_failed(pcie, port, -ETIMEDOUT); continue; } + apple_pcie_port_enable_cg(pcie, port); port->hib_retrained = true; } /* 100 ms after the links before configuration requests (PCIe r5.0, 6.6.1). */ From 79aca93786a2edb2971e5e32bcfb2578b441158f Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Tue, 1 Dec 2026 09:05:21 -0300 Subject: [PATCH 14/16] soc: apple: t6041-sleep: wait for L2 entry and clear full REFCLKCGEN in GP port stop In t6041_gp_ports_stop(), polling APCIE_PORT_L2_BUSY on +0x88 only waits until PME_Turn_Off is queued, not until the link has completed the PME_Turn_Off / PME_TO_Ack handshake and entered L2. On J575c, PORT_LINKSTS_L2 (BIT(6)) asserts 40-79 us after L2_BUSY clears; asserting PERST# immediately interrupted the handshake before L2 entry. Poll PORT_LINKSTS_L2 before asserting PERST# (matching apple_pcie_t6050_port_l2()), and clear both BIT(30) and BIT(31) (REFCLKCGEN) in the PHY lane config register. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- drivers/soc/apple/t6041-sleep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/t6041-sleep.c b/drivers/soc/apple/t6041-sleep.c index a531e13d64698..eef193c53e984 100644 --- a/drivers/soc/apple/t6041-sleep.c +++ b/drivers/soc/apple/t6041-sleep.c @@ -100,6 +100,7 @@ #define APCIE_PORT_PERST_GUARD 0x13c #define APCIE_PORT_LINKSTS 0x208 #define APCIE_PORT_LINKSTS_UP BIT(0) +#define APCIE_PORT_LINKSTS_L2 BIT(6) #define APCIE_PORT_APPCLK 0x800 #define APCIE_PORT_APPCLK_EN BIT(0) #define APCIE_PORT_APPCLK_CGDIS BIT(8) @@ -113,8 +114,9 @@ #define APCIE_PHY_RESET BIT(4) #define APCIE_PHY_EN0 BIT(9) #define APCIE_PHY_EN1 BIT(10) -#define APCIE_PHY_LINK BIT(31) +#define APCIE_PHY_REFCLKCGEN (BIT(30) | BIT(31)) #define APCIE_PORT_STOP_US 5000 +#define APCIE_PORT_L2_WAIT_US 50000 #define APCIE_PERST_HOLD_US 1000 #define GPIO_PIN_DATA BIT(0) @@ -745,6 +747,10 @@ static void t6041_gp_ports_stop(struct t6041_sleep *s) !(v & APCIE_PORT_L2_BUSY), APCIE_PORT_STOP_US)) s->gp_stop_late |= BIT(i); + if (t6041_poll_until_us(port + APCIE_PORT_LINKSTS, v, + v & APCIE_PORT_LINKSTS_L2, + APCIE_PORT_L2_WAIT_US)) + s->gp_stop_late |= BIT(i); } if (s->gp_perst[i] >= 0) { void __iomem *reg = s->gpio + 4 * s->gp_perst[i]; @@ -756,7 +762,7 @@ static void t6041_gp_ports_stop(struct t6041_sleep *s) if (!test_bit(s->gp_perst[i], s->gpio_skip)) s->gpio_pre[s->gp_perst[i]] = v; } - writel(readl(phy) & ~APCIE_PHY_LINK, phy); + writel(readl(phy) & ~APCIE_PHY_REFCLKCGEN, phy); t6041_spin_us(APCIE_PERST_HOLD_US); writel(readl(port + APCIE_PORT_PERST_GUARD) | BIT(8), port + APCIE_PORT_PERST_GUARD); From 5c395bb7533538afc9b40abdbf14a4c711fb8698 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Tue, 1 Dec 2026 09:05:22 -0300 Subject: [PATCH 15/16] arm64: dts: apple: t6041-j575c: disable refclk gating on port 2 (AQC113) Set apple,no-refclk-gating on pci@2,0 (AQC113 10 GbE), matching the J575c ADT pci-bridge2/no-refclk-gating property. Together with waiting for PORT_LINKSTS_L2 in t6041-sleep and keeping clocks ungated during S2R training in pcie-apple, this eliminates the intermittent AQC113 wake loss (#3694): 84/84 consecutive deep-sleep wakes on J575c. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- arch/arm64/boot/dts/apple/t6041-j575c.dts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6041-j575c.dts b/arch/arm64/boot/dts/apple/t6041-j575c.dts index b0c2e21762285..91a5e9f4ae5cd 100644 --- a/arch/arm64/boot/dts/apple/t6041-j575c.dts +++ b/arch/arm64/boot/dts/apple/t6041-j575c.dts @@ -1328,11 +1328,12 @@ }; }; - /* ADT pci-bridge2/lan-10gb: AQC113, PERST AP pin 6, no power */ + /* ADT pci-bridge2/lan-10gb: AQC113, PERST AP pin 6, no-refclk-gating, no power */ port02: pci@2,0 { device_type = "pci"; reg = <0x1000 0 0 0 0>; reset-gpios = <&pinctrl 6 GPIO_ACTIVE_LOW>; + apple,no-refclk-gating; bus-range = <3 3>; #address-cells = <3>; #size-cells = <2>; From 1e0a0ba5b149174d58d5c8d8cf37a2cdd89294c1 Mon Sep 17 00:00:00 2001 From: Roberto Dantas <7robertodantas@gmail.com> Date: Wed, 2 Dec 2026 06:59:34 -0300 Subject: [PATCH 16/16] tools/asahi: afk-compact-start-tests: stub dcp_desktop_external dcp_dpavctrl_service_init() now checks !dcp_desktop_external(dcp) instead of dcp_has_panel(dcp). Add the matching desktop_external field and stub to the afk-compact-start-tests.py harness so the host test compiles and passes. Signed-off-by: Roberto Dantas <7robertodantas@gmail.com> --- tools/asahi/afk-compact-start-tests.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/asahi/afk-compact-start-tests.py b/tools/asahi/afk-compact-start-tests.py index 373cb1f095ed3..4022e01fb3812 100755 --- a/tools/asahi/afk-compact-start-tests.py +++ b/tools/asahi/afk-compact-start-tests.py @@ -255,6 +255,7 @@ def function(text, name): struct dptx_port dptxport[2]; struct dcp_desktop_state *desktop; bool has_panel; + bool desktop_external; }; struct apple_dcp_afkep { @@ -282,6 +283,11 @@ def function(text, name): return dcp->has_panel; } +static bool dcp_desktop_external(struct apple_dcp *dcp) +{ + return dcp->desktop_external; +} + static bool dcp_fw_is_14_7(const struct apple_dcp *dcp) { (void)dcp;