From 991dbe5b22d1df341a65605543e79355ff0c0ab1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 11 Oct 2026 16:23:33 +0200 Subject: [PATCH 1/7] drm: apple: relink a Type-C sink that lost its link to a hub's USB3 A USB-C monitor with a built-in USB hub (EIZO EV2780) intermittently stays dark after a cold boot or a hot-plug on the M1 MacBook Air and the M1 Mac mini. DCP trains the link for the first modeset at about the time the monitor's hub brings its SuperSpeed link up. When the two overlap, the sink loses the link, but DCP still reports the modeset as linked: UnifiedPipeline::mode_set_gated(): 2560x1440@59 Hz link: 1 Then one of two things happens. DCP gives up on its own 2.008 s after asserting HPD: IOMFB: IOAVVideoInterface terminated VideoInterfaceIOAV::unplug_gated(): display HPD removed or it keeps driving the dead link without noticing, while the monitor pulses HPD about 2-4 s later to be detected again. In both cases the CD321x still reports DP alt mode with HPD high, and nothing re-detects the sink. With dwc3 kept off the port, 5 out of 5 boots brought the display up; with it, 3 out of 6 failed. Replay an unplug and replug of the sink when DCP drops a sink that still asserts HPD, or when the sink asks for attention (IRQ_HPD): the link is then retrained after the hub has settled, as a cable replug does. A request from the sink within 4 s after a relink is the sink's late reaction to the loss the relink already handled and is ignored; another relink would only interrupt the new link. A sink request must not be dropped as an unchanged route state either. A connection gets at most three relinks; the replay does not reset that count. Pulsing only DCP's HPD instead, with the connector kept connected, raced with DCP re-detecting the sink on its own and left the display dark on the Mac mini. With this, 8 out of 8 cold boots of the MacBook Air and 8 out of 8 of the Mac mini (EIZO on the port that failed) brought the display up. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp-internal.h | 8 ++ drivers/gpu/drm/apple/dcp.c | 112 +++++++++++++++++- drivers/gpu/drm/apple/iomfb_template.c | 6 + .../selftests/drivers/gpu/apple-dcp/rate.py | 1 + .../drivers/gpu/apple-dcp/transaction.py | 1 + 5 files changed, 126 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 169b2d17af867..adb1125f7b907 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -81,6 +81,8 @@ void dcp_swap_watchdog_complete(struct apple_dcp *dcp); bool dcp_is_usb4_output(struct apple_dcp *dcp); void dcp_retry_placeholder_edid(struct apple_dcp *dcp, const struct drm_edid *drm_edid); +bool dcp_typec_relink(struct apple_dcp *dcp); +bool dcp_typec_sink_relink(struct apple_dcp *dcp); struct dcpav_service_epic; @@ -333,6 +335,12 @@ struct apple_dcp { u64 typec_generation; /* hpd_mutex: identifies the current connection */ u64 placeholder_generation; struct delayed_work placeholder_edid_wq; + /* replugs replayed for a Type-C sink that lost its link */ + u32 relink_tries; + bool relink_active; + unsigned long relink_done; + u64 relink_generation; + struct delayed_work typec_relink_wq; bool use_timestamps; bool vrr_enabled; struct dcp_set_digital_out_mode_req mode; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 8f601bbb91cbe..518d481bd2111 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -1073,7 +1073,8 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * without a word, so a nominated route might never be called at all -- * and the port would then never be routed. */ - if (port->applied_valid && port->applied_alt == state->alt && + if (port->applied_valid && !(dp_status & DP_STATUS_IRQ_HPD) && + port->applied_alt == state->alt && port->applied_mode == state->mode && port->applied_status == dp_status && port->applied_conf == dp_conf) return 0; @@ -1197,7 +1198,7 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, } else if (hpd && dp_data && (dp_data->status & DP_STATUS_IRQ_HPD)) { struct apple_dcp *dcp = port->owner->dcp; - if (dcp->typec_connector) + if (!dcp_typec_sink_relink(dcp) && dcp->typec_connector) dcp_retrain_oob(dcp->typec_connector); } port->hpd = hpd; @@ -2893,6 +2894,109 @@ static void dcp_placeholder_edid_work(struct work_struct *work) mutex_unlock(&dcp->hpd_mutex); } +#define DPTX_RELINK_RETRIES 3 +#define DPTX_RELINK_UNPLUG_MS 1000 +/* a monitor pulses HPD up to about 4 s after it lost the link */ +#define DPTX_RELINK_SETTLE_MS 4000 + +/* + * A USB-C monitor with a built-in hub can lose the DP link when the hub + * brings its SuperSpeed link up right around DCP's link training for the + * first modeset. DCP may then report the sink as unplugged two seconds + * later although it still asserts HPD, or keep driving the dead link + * without noticing while the monitor pulses HPD to be detected again. + * Neither is recovered by anything else: replay an unplug and replug of + * the sink, which retrains the link once the hub has settled, as a cable + * replug does. + * + * The retries cover one connection: the replay itself does not reset them. + */ +static bool dcp_typec_relink_start(struct apple_dcp *dcp, const char *why) +{ + u64 generation = READ_ONCE(dcp->typec_generation); + + /* external H17P recovers through its own lifecycle, see dcp_external_hotplug() */ + if (!dcp_is_typec_output(dcp) || dcp_is_usb4_output(dcp) || + dcp_is_external_h17p(dcp) || + !READ_ONCE(dcp->typec_cable_connected) || + READ_ONCE(dcp->typec_crtc_off) || !dcp->typec_connector) + return false; + + if (dcp->relink_generation != generation) { + dcp->relink_generation = generation; + dcp->relink_tries = 0; + WRITE_ONCE(dcp->relink_active, false); + } + /* the unplug a running relink replays makes DCP report one too */ + if (READ_ONCE(dcp->relink_active)) + return true; + if (dcp->relink_tries >= DPTX_RELINK_RETRIES) + return false; + + dcp->relink_tries++; + WRITE_ONCE(dcp->relink_active, true); + dev_info(dcp->dev, "%s, relinking the Type-C sink (%u/%u)\n", why, + dcp->relink_tries, DPTX_RELINK_RETRIES); + mod_delayed_work(system_freezable_wq, &dcp->typec_relink_wq, 0); + + return true; +} + +/* DCP reported an unplug of a Type-C sink that still asserts HPD */ +bool dcp_typec_relink(struct apple_dcp *dcp) +{ + return dcp_typec_relink_start(dcp, "DCP dropped a sink that asserts HPD"); +} + +/* + * The sink asked for attention: IRQ_HPD or a coalesced HPD pulse. Right + * after a relink that is the sink's late reaction to the loss the relink + * already handled; another relink would only interrupt the new link. + */ +bool dcp_typec_sink_relink(struct apple_dcp *dcp) +{ + unsigned long done = READ_ONCE(dcp->relink_done); + + if (done && time_before(jiffies, done + msecs_to_jiffies(DPTX_RELINK_SETTLE_MS)) && + READ_ONCE(dcp->relink_generation) == READ_ONCE(dcp->typec_generation)) { + dev_info(dcp->dev, "Type-C sink requested attention right after a relink, ignored\n"); + return true; + } + + return dcp_typec_relink_start(dcp, "Type-C sink requested attention"); +} + +static void dcp_typec_relink_work(struct work_struct *work) +{ + struct apple_dcp *dcp = + container_of(to_delayed_work(work), struct apple_dcp, + typec_relink_wq); + struct platform_device *pdev = to_platform_device(dcp->dev); + u64 generation; + + scoped_guard(mutex, &dcp->hpd_mutex) + generation = dcp->typec_generation; + if (generation != dcp->relink_generation || + !READ_ONCE(dcp->typec_cable_connected)) + goto out; + + dcp_dptx_disconnect_oob(pdev, 0); + msleep(DPTX_RELINK_UNPLUG_MS); + + /* a real unplug or replug meanwhile takes over */ + scoped_guard(mutex, &dcp->hpd_mutex) { + if (dcp->typec_generation != generation + 1) + goto out; + } + dcp_dptx_connect_oob(pdev, 0); + + scoped_guard(mutex, &dcp->hpd_mutex) + dcp->relink_generation = dcp->typec_generation; + WRITE_ONCE(dcp->relink_done, jiffies); +out: + WRITE_ONCE(dcp->relink_active, false); +} + static void dcp_typec_reconnect_work(struct work_struct *work) { struct apple_dcp *dcp = @@ -3972,6 +4076,7 @@ static void dcp_disable_typec_work(struct apple_dcp *dcp, bool release_cable) /* Block new enqueues as well as draining users of the AFK endpoints. */ disable_delayed_work_sync(&dcp->typec_reconnect_wq); disable_delayed_work_sync(&dcp->placeholder_edid_wq); + disable_delayed_work_sync(&dcp->typec_relink_wq); cancel_work_sync(&dcp->external_stop_work); } @@ -3979,6 +4084,7 @@ static void dcp_enable_typec_work(struct apple_dcp *dcp) { enable_delayed_work(&dcp->typec_reconnect_wq); enable_delayed_work(&dcp->placeholder_edid_wq); + enable_delayed_work(&dcp->typec_relink_wq); /* A cable can be routed before the DRM component binds. */ if (READ_ONCE(dcp->typec_cable_connected)) mod_delayed_work(system_freezable_wq, &dcp->typec_reconnect_wq, 0); @@ -4393,10 +4499,12 @@ static int dcp_platform_probe(struct platform_device *pdev) dcp_typec_reconnect_work); INIT_DELAYED_WORK(&dcp->placeholder_edid_wq, dcp_placeholder_edid_work); + INIT_DELAYED_WORK(&dcp->typec_relink_wq, dcp_typec_relink_work); INIT_DELAYED_WORK(&dcp->bl_fallback_wq, dcp_work_backlight_fallback); /* Balanced by enable at successful component bind. */ disable_delayed_work(&dcp->typec_reconnect_wq); disable_delayed_work(&dcp->placeholder_edid_wq); + disable_delayed_work(&dcp->typec_relink_wq); platform_set_drvdata(pdev, dcp); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index fd985debcdbe5..e59f9679e90a0 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -1950,6 +1950,12 @@ static void dcpep_cb_hotplug(struct apple_dcp *dcp, u64 *connected) schedule_work(&dcp->vblank_wq); return; } + /* DCP lost a sink which is still attached, see dcp_typec_relink() */ + if (!(*connected) && dcp_typec_relink(dcp)) { + dcp_mode_invalidate(&dcp->mode_state); + schedule_work(&dcp->vblank_wq); + return; + } if (dcp_is_typec_output(dcp) && *connected && dcp->nr_modes) complete_all(&dcp->typec_iomfb_hpd_ready); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 32585f1755845..7145d3b13d229 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -936,6 +936,7 @@ def hotplug(root): #define dcp_mode_invalidate(s) ((s)->valid=false) #define dcp_mode_hotplug(s,c,p) __extension__ ({ (void)(s);if(p)*(p)=(c);1u; }) static void dcp_handle_hotplug_actions(struct apple_dcp *d,unsigned action) { (void)d;(void)action; } +static bool dcp_typec_relink(struct apple_dcp *d) { (void)d;return false; } ''' dcp = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() template = (root / 'drivers/gpu/drm/apple/iomfb_template.c').read_text() diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index 0ec0cc21c26c0..fe4143c84ac57 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -72,6 +72,7 @@ def check(name, unit, cases=((),), negative=False, flags=()): static int connect_calls; static int dcp_dptx_connect_oob(void *dev,unsigned n) { (void)dev;(void)n;connect_calls++;display.external_cable=true;display.dptxport[0].connected=true;display.typec_cable_connected=true;connector.connected=true;return 0; } static void dcp_retrain_oob(struct connector *c) { (void)c; } + static bool dcp_typec_sink_relink(struct apple_dcp *d) { (void)d;return false; } ''' pos=actual.index('static int dcp_typec_route_deactivate(') actual=actual[:pos]+extra+actual[pos:] From 9eab9b12e3ffbe4f5a33c372b7bd5c9968562694 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 11 Oct 2026 18:06:38 +0200 Subject: [PATCH 2/7] usb: typec: tipd: report a coalesced sink HPD pulse as IRQ_HPD A DisplayPort sink that lost the link drops HPD and raises it again to be detected anew. The EIZO EV2780 does so for about 250 ms, which falls within the 500 ms debounce of cd321x_update_work(). The worker then sees DP alt mode with HPD high, the state it already applied, and cd321x_typec_update_mode() returns without telling the mux, so the display driver never learns that the sink wants attention and the display stays dark. The out-of-band DRM hotplug event does not cover this either on the M1 MacBook Air and Mac mini: their connector nodes have no "displayport" reference, so connector_fwnode is NULL. When HPD changed within the debounce window and is high before and after, pass the state on with DP_STATUS_IRQ_HPD set, even though it otherwise matches the applied one. Signed-off-by: Thomas Glanzmann --- drivers/usb/typec/tipd/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index ca6cc92c8b425..91bb1c62b5267 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -679,7 +679,19 @@ static int cd321x_typec_update_mode(struct tps6598x *tps, else dp_data.status &= ~DP_STATUS_HPD_STATE; + /* + * The sink dropped HPD and raised it again within the debounce + * window, as a monitor does after losing the link. The coalesced + * state looks unchanged, so the display side would never hear of + * it: report the pulse as IRQ_HPD. + */ + if ((st->data_status_changed & CD321X_DATA_STATUS_HPD_LEVEL) && + (dp_data.status & DP_STATUS_HPD_STATE) && + (cd321x->dp_status & DP_STATUS_HPD_STATE)) + dp_data.status |= DP_STATUS_IRQ_HPD; + if (cd321x->state_valid && cd321x->state.alt == cd321x->port_altmode_dp && + !(dp_data.status & DP_STATUS_IRQ_HPD) && cd321x->state.mode == mode && cd321x->dp_status == dp_data.status && cd321x->dp_conf == dp_data.conf) From 40483b55ad9242de24301342583f182a4b0e7565 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 12 Oct 2026 13:04:11 +0200 Subject: [PATCH 3/7] drm: apple: do not report a bad link for the HPD a Type-C wake awaits Waking a DP alt mode display from DPMS off with sway ("output * power on") on the M1 Mac mini (Fujitsu E24T-7 Pro on USB-C, which keeps HPD asserted while blanked) power cycles the display about every 750 ms until reboot: dcp_hotplug() connected:1 valid_mode:0 nr_modes:1 dcp_poweron() starting set_digital_out_mode finished dcp_poweroff() done ... With the cable attached, dcp_poweron() reconnects DPTX and waits for IOMFB to report the sink before the commit does its modeset. At that point no mode is valid yet, so dcpep_cb_hotplug() takes the HPD for a sink that asserted HPD only after a failed modeset and sends DCP_HOTPLUG_NOTIFY. dcp_hotplug() then sets the connector's link-status to BAD. wlroots treats a bad link as a disconnect and recreates the output, which disables the CRTC and enables it again. That wake does the same, so the loop never ends. Each round also leaks AFK service slots ("AFK[ep:29]: no reusable service slots") and the system becomes sluggish. Do not take the HPD that dcp_poweron() waits for as a late one: the modeset of the same commit follows. A sink that asserts HPD only after dcp_poweron() stopped waiting is still handled as before. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/dcp.c | 3 +++ drivers/gpu/drm/apple/iomfb_template.c | 9 ++++++++- tools/testing/selftests/drivers/gpu/apple-dcp/rate.py | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index adb1125f7b907..95c86d28675b5 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -448,6 +448,8 @@ struct apple_dcp { bool tb_clock_ok; /* CRTC powered off while the Type-C cable stays attached */ bool typec_crtc_off; + /* dcp_poweron() reconnects DPTX; its own modeset follows the HPD */ + bool typec_poweron_hpd; /* IOMFB reports its video interface ready after DPTX link training. */ struct completion typec_iomfb_hpd_ready; struct delayed_work typec_reconnect_wq; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 518d481bd2111..b05d55f0e2051 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -3460,6 +3460,8 @@ void dcp_poweron(struct platform_device *pdev) if (READ_ONCE(dcp->typec_cable_connected)) { cancel_delayed_work(&dcp->typec_reconnect_wq); dcp->typec_reconnect_tries = 0; + /* the modeset of this commit follows, see dcpep_cb_hotplug() */ + WRITE_ONCE(dcp->typec_poweron_hpd, true); ret = dcp_dptx_connect(dcp, 0); if (ret) mod_delayed_work(system_freezable_wq, @@ -3473,6 +3475,7 @@ void dcp_poweron(struct platform_device *pdev) dev_warn(dcp->dev, "Type-C IOMFB hotplug not ready on wake\n"); } + WRITE_ONCE(dcp->typec_poweron_hpd, false); } } else if (dcp->hdmi_hpd) { bool connected = gpiod_get_value_cansleep(dcp->hdmi_hpd); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index e59f9679e90a0..2136ac8401b13 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -1920,6 +1920,8 @@ void DCP_FW_NAME(iomfb_sleep)(struct apple_dcp *dcp) static void dcpep_cb_hotplug(struct apple_dcp *dcp, u64 *connected) { struct apple_connector *connector = dcp->connector; + /* sampled before complete_all() lets dcp_poweron() clear it */ + bool poweron_hpd = READ_ONCE(dcp->typec_poweron_hpd); unsigned int action; /* DCP issues hotplug_gated callbacks after SetPowerState() calls on @@ -1969,8 +1971,13 @@ static void dcpep_cb_hotplug(struct apple_dcp *dcp, u64 *connected) * A Type-C sink can assert HPD only after a modeset has already failed, * as a TV behind a DP-to-HDMI converter does when it wakes from standby. * The connector state does not change then; re-apply the mode anyway. + * + * Not for the HPD dcp_poweron() waits for: the modeset of that commit + * has not started yet, rather than failed. Reporting the link as bad + * then makes wlroots replace the output, which powers the CRTC off and + * on again, and the next wake does the same, forever. */ - if (*connected && dcp_is_typec_output(dcp) && + if (*connected && dcp_is_typec_output(dcp) && !poweron_hpd && !READ_ONCE(dcp->mode_state.valid) && !READ_ONCE(dcp->mode_state.changing)) { dcp->swap_watchdog_retrains = 0; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 7145d3b13d229..88943830f6544 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -925,7 +925,7 @@ def hotplug(root): struct { bool valid,changing; } mode_state; struct work_struct external_stop_work,vblank_wq; bool external_physically_absent,main_display,typec_crtc_off,external_cable,external_error,external_power_attempted,external_stopped; - bool external_hotplug_pending,external_hotplug_connected; + bool external_hotplug_pending,external_hotplug_connected,typec_poweron_hpd; u64 external_stop_generation,external_rx_generation,external_crtc_generation; unsigned swap_watchdog_retrains;int typec_iomfb_hpd_ready;''') stubs = r''' From 49d3d84ab13a7274fada7c413ce445a2df0553d6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 12 Oct 2026 14:01:54 +0200 Subject: [PATCH 4/7] drm: apple: audio: play into the void without a sink On the M1 Mac mini with two Fujitsu E24T-7 Pro monitors, which have no audio (single-block EDID 1.3), PipeWire logs spa.alsa: hw:0p: snd_pcm_start: No such device or address about 130000 times a second, for hours, as soon as something plays to a DCP audio output: 4.1 million log lines in one boot, with journald dropping most of them, and a core kept busy. Without a sink, opening, configuring and preparing the PCM succeed, as userspace drops an output that fails its probe for good, but START fails with -ENXIO. That does not stop userspace from trying: PipeWire starts playback after its first write and ignores the error, and a stream that never starts never makes it wait, so the next wakeup is immediate and tries again. Any other error ends up in its recovery, which prepares and starts again. Play into the void instead, as HDMI PCMs on other platforms do: without a sink, or once the sink the stream was opened for is gone, START succeeds and the stream runs on the clock, without DMA and without a DCP audio link. The position follows the time since START and a work item reports the periods. The samples are dropped. A stream playing into the void is not stopped as disconnected when a sink goes away; a sink attached later is used by the next stream opened. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/audio.c | 113 ++++++++++++++++++++++++++++++---- 1 file changed, 100 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index ac55f1f30f6ac..d2ef719add54a 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -52,6 +52,11 @@ struct dcp_audio { struct snd_pcm_chmap_elem selected_chmap; struct dcp_sound_cookie selected_cookie; + /* stream runs without a sink, see dcpaud_void_start() */ + bool void_running; + ktime_t void_start; + u64 void_periods; + struct delayed_work void_work; void *elements; void *productattrs; @@ -81,7 +86,7 @@ static const struct snd_pcm_hardware dcp_pcm_hw = { * configured, as HDMI PCMs on other platforms can. Userspace (PipeWire, * PulseAudio) probes the PCM once when the card appears and drops the * output for good if that fails, so a monitor attached later would never - * show up. Starting the stream still fails until a sink is connected. + * show up. The stream then plays into the void, see dcpaud_void_start(). */ static const struct snd_pcm_hardware dcp_pcm_hw_unplugged = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -352,12 +357,10 @@ static int dcp_pcm_hw_params(struct snd_pcm_substream *substream, struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream); int ret; - if (dcpaud->open_unplugged) + /* no sink: the stream runs without DMA, see dcpaud_void_start() */ + if (dcpaud->open_unplugged || !dcpaud_connection_up(dcpaud)) return 0; - if (!dcpaud_connection_up(dcpaud)) - return -ENXIO; - ret = dcpaud_select_cookie(dcpaud, params); if (ret < 0) return ret; @@ -397,16 +400,79 @@ static int dcp_pcm_prepare(struct snd_pcm_substream *substream) struct dcp_audio *dcpaud = substream->pcm->private_data; /* alsa-lib prepares right after hw_params; see dcp_pcm_hw_unplugged */ - if (dcpaud->open_unplugged) + if (dcpaud->open_unplugged || !dcpaud_connection_up(dcpaud)) return 0; - if (!dcpaud_connection_up(dcpaud)) - return -ENXIO; - return dcp_audiosrv_prepare(dcpaud->dcp_dev, &dcpaud->selected_cookie); } +static u64 dcpaud_void_period_ns(struct snd_pcm_runtime *runtime) +{ + return div_u64((u64)runtime->period_size * NSEC_PER_SEC, runtime->rate); +} + +static void dcpaud_void_work(struct work_struct *work) +{ + struct dcp_audio *dcpaud = container_of(to_delayed_work(work), + struct dcp_audio, void_work); + struct snd_pcm_substream *substream = dcpaud->substream; + ktime_t next; + s64 delay; + + snd_pcm_period_elapsed(substream); + + snd_pcm_stream_lock_irq(substream); + if (dcpaud->void_running) { + /* the next period boundary, so that periods do not drift */ + next = ktime_add_ns(dcpaud->void_start, + ++dcpaud->void_periods * + dcpaud_void_period_ns(substream->runtime)); + delay = ktime_to_ns(ktime_sub(next, ktime_get())); + schedule_delayed_work(&dcpaud->void_work, + delay > 0 ? nsecs_to_jiffies(delay) : 0); + } + snd_pcm_stream_unlock_irq(substream); +} + +/* + * Without a sink, DCP has no audio link to start. Failing START does not + * stop userspace from trying: PipeWire retries it on every wakeup, and a + * stream that never starts never makes it wait, so it retries at about + * 130000 times a second for as long as something plays (a monitor + * without audio, or none attached). Play into the void instead, as HDMI + * PCMs elsewhere do: the stream runs on the clock, without DMA, and its + * samples are dropped. A sink attached later gets the next stream opened. + */ +static int dcpaud_void_start(struct snd_pcm_substream *substream) +{ + struct dcp_audio *dcpaud = substream->pcm->private_data; + u64 period_ns = dcpaud_void_period_ns(substream->runtime); + + dev_dbg(dcpaud->dev, "no sink, playing into the void\n"); + dcpaud->void_running = true; + dcpaud->void_start = ktime_get(); + dcpaud->void_periods = 0; + schedule_delayed_work(&dcpaud->void_work, nsecs_to_jiffies(period_ns)); + + return 0; +} + +static snd_pcm_uframes_t dcp_pcm_pointer(struct snd_pcm_substream *substream) +{ + struct dcp_audio *dcpaud = substream->pcm->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; + u64 frames; + + if (!dcpaud->void_running) + return snd_dmaengine_pcm_pointer(substream); + + frames = mul_u64_u32_div(ktime_to_ns(ktime_sub(ktime_get(), + dcpaud->void_start)), + runtime->rate, NSEC_PER_SEC); + return do_div(frames, runtime->buffer_size); +} + static int dcp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct dcp_audio *dcpaud = substream->pcm->private_data; @@ -415,8 +481,8 @@ static int dcp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: - if (!dcpaud_connection_up(dcpaud)) - return -ENXIO; + if (dcpaud->open_unplugged || !dcpaud_connection_up(dcpaud)) + return dcpaud_void_start(substream); WARN_ON(pm_runtime_get_sync(dcpaud->dev) < 0); ret = dcp_audiosrv_startlink(dcpaud->dcp_dev, @@ -427,6 +493,11 @@ static int dcp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: + if (dcpaud->void_running) { + /* sync_stop waits for the work */ + dcpaud->void_running = false; + return 0; + } break; default: @@ -455,6 +526,19 @@ static int dcp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) return 0; } +/* + * ALSA calls this once a stream has stopped, outside the stream lock, before + * the next hw_params, prepare or hw_free and at close. + */ +static int dcp_pcm_sync_stop(struct snd_pcm_substream *substream) +{ + struct dcp_audio *dcpaud = substream->pcm->private_data; + + cancel_delayed_work_sync(&dcpaud->void_work); + + return 0; +} + struct snd_pcm_ops dcp_playback_ops = { .open = dcp_pcm_open, .close = dcp_pcm_close, @@ -462,7 +546,8 @@ struct snd_pcm_ops dcp_playback_ops = { .hw_free = dcp_pcm_hw_free, .prepare = dcp_pcm_prepare, .trigger = dcp_pcm_trigger, - .pointer = snd_dmaengine_pcm_pointer, + .sync_stop = dcp_pcm_sync_stop, + .pointer = dcp_pcm_pointer, }; // Transitional workaround: for the chmap control TLV, advertise options @@ -544,7 +629,8 @@ static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected) if (!connected) { snd_pcm_stream_lock(substream); - if (substream->runtime) + /* a stream without a sink plays on, see dcpaud_void_start() */ + if (substream->runtime && !dcpaud->void_running) snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); snd_pcm_stream_unlock(substream); } @@ -756,6 +842,7 @@ static int dcpaud_probe(struct platform_device *pdev) dcpaud->dev = &pdev->dev; mutex_init(&dcpaud->data_lock); + INIT_DELAYED_WORK(&dcpaud->void_work, dcpaud_void_work); platform_set_drvdata(pdev, dcpaud); return component_add(&pdev->dev, &dcpaud_comp_ops); From 3d3847b6ad8855d0e4d2a9726e9c03a92764febe Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 14 Oct 2026 20:02:50 +0200 Subject: [PATCH 5/7] drm: apple: reset the Type-C relink budget on every DPMS wake A USB-C monitor with a built-in hub drops the DP link right after the first modeset of every DPMS wake, which dcp_typec_relink() recovers by replaying an unplug and replug. Its retry counter is only reset when the Type-C generation changes, i.e. on a real cable replug, so all wakes of one connection share DPTX_RELINK_RETRIES tries: after three wakes the fourth drop is handled as an unplug and the display stays dark until the cable is replugged. The limit exists to stop relink loops within one link bring-up. Reset it in dcp_poweron() when the CRTC comes back from DPMS off. No relink can run while the CRTC is off, dcp_typec_relink_start() refuses then. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b05d55f0e2051..f5fdfd811f729 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2909,7 +2909,8 @@ static void dcp_placeholder_edid_work(struct work_struct *work) * the sink, which retrains the link once the hub has settled, as a cable * replug does. * - * The retries cover one connection: the replay itself does not reset them. + * The retries cover one connection or one DPMS wake: the replay itself + * does not reset them, dcp_poweron() does. */ static bool dcp_typec_relink_start(struct apple_dcp *dcp, const char *why) { @@ -3452,6 +3453,12 @@ void dcp_poweron(struct platform_device *pdev) wait_for_typec_hpd = READ_ONCE(dcp->typec_crtc_off) && READ_ONCE(dcp->typec_cable_connected); WRITE_ONCE(dcp->typec_crtc_off, false); + /* + * A DPMS wake retrains the link like a replug: give it a fresh + * relink budget. No relink runs while the CRTC was off. + */ + if (wait_for_typec_hpd) + dcp->relink_tries = 0; /* * A Type-C CRTC disable releases its DPTX session. Re-establish it From 5459f02178c12f4755395fe177a22de6b23f792d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 14 Oct 2026 21:41:25 +0200 Subject: [PATCH 6/7] drm: apple: do not report a bad link for a powered-off Type-C CRTC Since commit 57f9f3623299 ("drm/apple: fence EDID publication by service lifetime and unblock RX"), the teardown of DCP's AV service schedules the connector hotplug worker to invalidate the EDID. DCP tears that service down whenever a Type-C CRTC is powered off with the display attached (DPMS off). dcp_hotplug() then finds the connector connected without a valid mode and reports the link as bad. wlroots treats a bad link as a disconnect and replaces the output on the next wake, which powers the CRTC off and on again, and that power off does the same: the display never comes back from the first DPMS off (Mac mini, EIZO EV2780 on USB-C). There is no link while the CRTC is off, and dcp_poweron() retrains one on wake. Leave the link status and the CRTC alone then; the EDID is still invalidated. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/iomfb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 1c97639bb6b6c..3f26a40929dcd 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -832,7 +832,15 @@ void dcp_hotplug(struct work_struct *work) * display modes from atomic_flush, so userspace needs to trigger a * flush, or the CRTC gets no signal. */ + /* + * Not for a Type-C CRTC powered off with the display attached: it has + * no link, and dcp_poweron() retrains one on wake. DCP tears its AV + * service down at power off, which lands here; a link reported bad + * then makes wlroots replace the output on wake, which powers the + * CRTC off and on again, and that wake does the same, forever. + */ if (connector->base.state && !READ_ONCE(dcp->mode_state.valid) && connector->connected && + !READ_ONCE(dcp->typec_crtc_off) && !(dcp_is_usb4_output(dcp) && apple_dp_tunnel_t602x())) { drm_connector_set_link_status_property(&connector->base, DRM_MODE_LINK_STATUS_BAD); From d4e92c265019dbfe9723828b93d953c307b73636 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 14 Oct 2026 21:50:50 +0200 Subject: [PATCH 7/7] drm: apple: update connector dimensions without a hotplug Commit 57f9f3623299 ("drm/apple: fence EDID publication by service lifetime and unblock RX") moved the connector dimension update for DisplayAttributes from the RTKit RX worker to the connector hotplug worker. Besides the dimensions, dcp_hotplug() reports the link as bad and retrains an active CRTC without a valid mode. DCP sends DisplayAttributes on every DPTX connect, and a Type-C DPMS wake connects DPTX in dcp_poweron(), before the modeset of its commit. dcp_hotplug() then finds the CRTC being enabled without a valid mode, replays its state (a second modeset) and reports a bad link. wlroots treats that as a disconnect and replaces the output, which powers the CRTC off and on again, and that wake does the same: the display never comes back from the first DPMS off, and every round leaks AFK service slots until the system crawls (Mac mini, EIZO EV2780 on USB-C). Defer the dimension update to a work item of its own, which does what the RX worker did before, outside it. External H17P keeps using the hotplug worker, as its display publication was written for that. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/dcp.c | 30 +++++++++++++++++-- .../selftests/drivers/gpu/apple-dcp/edid.py | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 95c86d28675b5..f914bc88b5975 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -379,6 +379,8 @@ struct apple_dcp { /* Workqueue for sending vblank events when a dcp swap is not possible */ struct work_struct vblank_wq; + /* connector physical dimensions, deferred from the RTKit RX worker */ + struct work_struct dimensions_wq; /* Completes a Type-C swap that DCP dropped, and recovers the pipe. */ struct delayed_work swap_watchdog_wq; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index f5fdfd811f729..472b21c68cbe4 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2138,9 +2138,19 @@ void dcp_set_dimensions(struct apple_dcp *dcp) * This callback runs on the ordered RTKit RX worker. A mode probe * can hold mode_config.mutex while waiting for an AFK reply which * that same worker still has to dispatch. Defer the DRM update. + * + * Not through the hotplug worker except for external H17P: DCP sends + * DisplayAttributes on every DPTX connect, which a Type-C DPMS wake + * does before its modeset. dcp_hotplug() would then report the link + * of the CRTC being enabled as bad, and wlroots replaces the output, + * which powers it off and on again, forever. */ - if (dcp->connector && !READ_ONCE(dcp->quiescing)) - schedule_work(&dcp->connector->hotplug_wq); + if (dcp->connector && !READ_ONCE(dcp->quiescing)) { + if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) + schedule_work(&dcp->connector->hotplug_wq); + else + schedule_work(&dcp->dimensions_wq); + } /* * Fix up any probed modes. Modes are created when parsing @@ -2153,6 +2163,19 @@ void dcp_set_dimensions(struct apple_dcp *dcp) } } +static void dcp_dimensions_work(struct work_struct *work) +{ + struct apple_dcp *dcp = container_of(work, struct apple_dcp, + dimensions_wq); + struct apple_connector *connector = READ_ONCE(dcp->connector); + + if (!connector) + return; + guard(mutex)(&connector->base.dev->mode_config.mutex); + if (READ_ONCE(connector->dcp) == to_platform_device(dcp->dev)) + dcp_update_connector_dimensions(dcp, &connector->base); +} + void dcp_update_connector_dimensions(struct apple_dcp *dcp, struct drm_connector *connector) { @@ -4248,6 +4271,7 @@ static int dcp_comp_bind(struct device *dev, struct device *main, void *data) set_bit(0, dcp->memdesc_map); INIT_WORK(&dcp->vblank_wq, dcp_delayed_vblank); + INIT_WORK(&dcp->dimensions_wq, dcp_dimensions_work); INIT_DELAYED_WORK(&dcp->swap_watchdog_wq, dcp_swap_watchdog); if (dcp->hw.iomfb_method_profile == @@ -4346,6 +4370,7 @@ static void dcp_comp_unbind(struct device *dev, struct device *main, void *data) } cancel_delayed_work_sync(&dcp->typec_reconnect_wq); cancel_work_sync(&dcp->vblank_wq); + cancel_work_sync(&dcp->dimensions_wq); if (dcp->connector) cancel_work_sync(&dcp->connector->hotplug_wq); if (dcp->typec_connector && dcp->typec_connector != dcp->connector) @@ -4406,6 +4431,7 @@ static void dcp_comp_unbind(struct device *dev, struct device *main, void *data) } cancel_delayed_work_sync(&dcp->swap_watchdog_wq); cancel_work_sync(&dcp->vblank_wq); + cancel_work_sync(&dcp->dimensions_wq); devm_clk_put(dev, dcp->clk); dcp->clk = NULL; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index 69ebe810f1c2d..0d2fefa9d5310 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -816,6 +816,7 @@ def function(text, signature): u64 typec_generation; bool typec_cable_connected; struct { size_t length; void *data; u64 av_service_epoch, automatic_connection_sequence; bool automatic_service_pending; struct test_mode_ticket mode_ticket; } chunks; int width_mm,height_mm; struct { int width_mm,height_mm; } panel; + struct work_struct dimensions_wq; unsigned int nr_modes; struct { struct { int width_mm,height_mm; } mode; } modes[1]; struct apple_connector *connector; struct apple_dcp_afkep *dcpavservep,*dptxep,*avep,*systemep,*ibootep,*dptx_controller_ep;