Skip to contentSkip to conversation

drm/msm/dp: fix DisplayPort hotplug, link training, and multi-lane PHY setup

PATCH New Gianfranco Mariotti 2 participants 14 messages Nov 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover drm/msm/dp: fix DisplayPort hotplug, link training, and multi-lane PHY setup

On platforms with a native DisplayPort connector using direct HPD interrupts, DisplayPort initializes on cold boot, but physical cable unplug and re-plug cycles leave the display blank even though link training and stream enable callbacks report success.

This series fixes the underlying PHY lane setup, DPCD link-info caching, SST training-pattern handover, link maintenance completion/stream handling, and HPD / sink_count / runtime-PM / PHY / EDID state tracking issues:

1. Configure PHY voltage swing and pre-emphasis across all active lanes and refresh lanes/link_rate in msm_dp_ctrl_set_vx_px().
2. Zero out cached link_info in msm_dp_panel_read_dpcd() so re-plugging a different sink does not reuse stale rate, use_rate_set, or capability flags.
3. Avoid redundant back-to-back link training in msm_dp_display_prepare_link() and keep DP_TRAINING_PATTERN_SET active until msm_dp_ctrl_on_stream() is ready to switch REG_DP_STATE_CTRL to DP_STATE_CTRL_SEND_VIDEO.
4. Guard msm_dp_ctrl_push_idle(), reinitialize ctrl->video_comp, and keep training pattern active until stream clocks are enabled in msm_dp_ctrl_link_maintenance().
5. Use asynchronous pm_runtime_put() on HPD unplug/notify paths called from msm_dp_display_irq_thread() to avoid a synchronous disable_irq() self-deadlock in msm_dp_pm_runtime_suspend().
6. Track drm_dp_read_sink_count_cap() in link->has_sink_count and keep sink_count and prev_sink_count synchronized across plug and unplug.
7. Keep dp->plugged, AUX transfer enablement, and runtime PM references balanced across plug, unplug, detect, prepare_link, and empty branch dongle notifications.
8. Keep the DP PHY initialized across msm_dp_display_unprepare() and system sleep while a sink remains plugged in (removing now-unused msm_dp_ctrl_reinit_phy()).
9. Re-read EDID on demand in msm_dp_display_get_modes() when edid_blob_ptr is NULL (e.g. after DRM_FORCE_OFF).
10. Dispatch DP_DP_IRQ_HPD_INT_MASK to msm_dp_irq_hpd_handle(), skipping sink requests when mainlink clocks are off and emitting bridge HPD notifications on branch DS_PORT_STATUS_CHANGED events (kept at the end of the series so it can be dropped if superseded by in-flight DRM_CONNECTOR_DP_IRQ_HPD changes).

Changes in v2:
- Add Jens Glathe's Tested-by on unchanged patches 1, 3, and 5.
- Patch 1: clarify commit message regarding persistent ctrl->phy_opts
staleness on link maintenance and update Fixes tag to 937f941ca06f.
- Patch 2: zero out the entire link_info struct (rate, use_rate_set,
and capabilities) before parsing DPCD.
- Patch 4: drop redundant msm_dp_ctrl_configure_source_params() call (as msm-next already calls msm_dp_ctrl_config_ctrl_streams() inside msm_dp_ctrl_link_train(), avoiding unclocked pixel_base access when
no stream is active), guard msm_dp_ctrl_push_idle() and msm_dp_ctrl_clear_training_pattern() / SEND_VIDEO with stream_clks_on,
and update Fixes tag to 8ede2ecc3e5e.
- Reorder and split HPD changes (was patch 7) into four focused patches (patches 6-9):
- Patch 6: DP_SINK_COUNT capability and prev_sink_count synchronization.
- Patch 7: dp->plugged, AUX gate, msm_dp_bridge_detect() runtime PM
release, prepare_link locking, and empty branch dongle handling.
- Patch 8: PHY lifecycle across msm_dp_display_unprepare(), unplug, and system sleep, removing msm_dp_ctrl_reinit_phy().
- Patch 9: on-demand EDID re-read in msm_dp_display_get_modes() and DRM_FORCE_OFF error log suppression.
- Patch 10 (was 5): move to end of series, guard msm_dp_ctrl_handle_sink_request() with ctrl->link_clks_on, guard msm_dp_irq_hpd_handle() with dp->plugged, and handle branch DS_PORT_STATUS_CHANGED connect/disconnect with non-reentrant drm_bridge_hpd_notify().
- Link to v1: https://lore.kernel.org/r/[email protected]

Testing:
Hardware-tested across cold boot, unplug/re-plug, monitor swap (4K60 native DP and DP-to-HDMI branch adapter), connector DPMS/off cycles, and IRQ_HPD link-retrain cycles on a QCS8275 (Monaco) SMARC board (SECO F86) with a native DisplayPort connector running v6.18 + the FROMLIST DP HPD/MST series (Qualcomm Linux / QLI 2.0), then forward-ported and build-tested against msm-next.

Gianfranco Mariotti (10):
drm/msm/dp: configure voltage swing and pre-emphasis for all active
lanes
drm/msm/dp: reset cached link_info before reading DPCD capabilities drm/msm/dp: keep training pattern active until stream video is ready drm/msm/dp: reinit video_comp and guard stream state on link
maintenance
drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking drm/msm/dp: keep PHY initialized while plugged across link unprepare drm/msm/dp: re-read EDID on demand in get_modes when blob is missing drm/msm/dp: dispatch native IRQ_HPD directly to

    msm_dp_irq_hpd_handle()
 drivers/gpu/drm/msm/dp/dp_ctrl.c    |  44 +++---
 drivers/gpu/drm/msm/dp/dp_ctrl.h    |   1 -
 drivers/gpu/drm/msm/dp/dp_display.c | 228 +++++++++++++++++++---------
 drivers/gpu/drm/msm/dp/dp_link.c    |  26 +++-
 drivers/gpu/drm/msm/dp/dp_link.h    |   2 +
 drivers/gpu/drm/msm/dp/dp_panel.c   |  20 ++-
 6 files changed, 215 insertions(+), 106 deletions(-)

base-commit: d024361c631b3f020a26c07d683e5103404b0fbf

Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/10 drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes

msm_dp_ctrl_set_vx_px() only populated voltage[0] and pre[0] in struct phy_configure_opts_dp and relied on phy_opts->dp.lanes and phy_opts->dp.link_rate remaining unchanged since msm_dp_ctrl_enable_mainlink_clocks(), which leaves them stale if link parameters change during link maintenance (e.g. DP_TEST_LINK_TRAINING).

Populate phy_opts->dp.lanes and phy_opts->dp.link_rate from the active link parameters and program voltage swing and pre-emphasis across all active lanes to match the generic PHY DP configuration contract.

Fixes 937f941ca06f ("drm/msm/dp: Use qmp phy for DP PLL and PHY")
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +9 -4
index abd3dcdad03c..b896196cf244 100644
@@ -1374,13 +1374,18 @@ static int msm_dp_ctrl_wait4video_ready(struct msm_dp_ctrl_private *ctrl)
 }
 
 static int msm_dp_ctrl_set_vx_px(struct msm_dp_ctrl_private *ctrl,
-			     u8 v_level, u8 p_level)
+				 u8 v_level, u8 p_level)
 {
 	union phy_configure_opts *phy_opts = &ctrl->phy_opts;
+	int i;
+
+	phy_opts->dp.lanes = ctrl->link->link_params.num_lanes;
+	phy_opts->dp.link_rate = ctrl->link->link_params.rate / 100;
 
-	/* TODO: Update for all lanes instead of just first one */
-	phy_opts->dp.voltage[0] = v_level;
-	phy_opts->dp.pre[0] = p_level;
+	for (i = 0; i < phy_opts->dp.lanes; i++) {
+		phy_opts->dp.voltage[i] = v_level;
+		phy_opts->dp.pre[i] = p_level;
+	}
 	phy_opts->dp.set_voltages = 1;
 	phy_configure(ctrl->phy, phy_opts);
 	phy_opts->dp.set_voltages = 0;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/10 drm/msm/dp: reset cached link_info before reading DPCD capabilities

In reply to Gianfranco Mariotti

Commit ed100aa239be ("drm/msm/dp: Enable support for eDP v1.4+ link rates table") guarded the drm_dp_max_link_rate() fallback in msm_dp_panel_read_dpcd() behind if (!link_info->rate) so eDP v1.4+ SUPPORTED_LINK_RATES entries take precedence when present.

However, link_info is not cleared across hotplug cycles. Once a monitor has been connected and link_info->rate is non-zero, unplugging it and connecting a different DisplayPort sink skips the fallback and reuses stale rate, use_rate_set, and capability flags from the previous sink.

Zero out link_info before parsing DPCD capabilities.

Fixes ed100aa239be ("drm/msm/dp: Enable support for eDP v1.4+ link rates table")
---
 drivers/gpu/drm/msm/dp/dp_panel.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/dp/dp_panel.c +1 -0
index d3468b73fdc3..e633afdf2b47 100644
@@ -195,6 +195,7 @@ static int msm_dp_panel_read_dpcd(struct msm_dp_panel *msm_dp_panel)
 
 	msm_dp_panel->vsc_sdp_supported = drm_dp_vsc_sdp_supported(panel->aux, dpcd);
 	link_info = &msm_dp_panel->link_info;
+	memset(link_info, 0, sizeof(*link_info));
 	link_info->revision = dpcd[DP_DPCD_REV];
 	major = (link_info->revision >> 4) & 0x0f;
 	minor = link_info->revision & 0x0f;
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/10 drm/msm/dp: keep training pattern active until stream video is ready

In reply to Gianfranco Mariotti

Commit ca16db3d18cf ("drm/msm/dp: break up dp_display_enable into two parts") introduced two regressions on DisplayPort re-plug:

1. msm_dp_display_prepare_link() called msm_dp_ctrl_on_link() on every prepare (even when power_on was already true) and unconditionally set force_link_train = true when !power_on, causing msm_dp_ctrl_prepare_stream_on() to immediately re-run link training a second time right after msm_dp_ctrl_on_link() succeeded. Only call msm_dp_ctrl_on_link() when !power_on, and pass force_link_train = false to msm_dp_ctrl_prepare_stream_on() so it only retrains if channel equalization was lost.

2. Splitting msm_dp_ctrl_on_stream() left msm_dp_ctrl_clear_training_pattern() in msm_dp_ctrl_prepare_stream_on(), clearing DP_TRAINING_PATTERN_SET (DPCD 0x102 = 0x00, which re-enables the sink descrambler) ~45 ms before msm_dp_ctrl_on_stream() enables the pixel clock, programs the TU, and switches REG_DP_STATE_CTRL to DP_STATE_CTRL_SEND_VIDEO. During that window the DPTX remains in MR_LINK_TRAINING2 transmitting unscrambled TPS symbols, causing SST monitors to lose symbol lock.

Move msm_dp_ctrl_clear_training_pattern() back into msm_dp_ctrl_on_stream() immediately before DP_STATE_CTRL_SEND_VIDEO.

Fixes ca16db3d18cf ("drm/msm/dp: break up dp_display_enable into two parts")
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    |  6 +++---
 drivers/gpu/drm/msm/dp/dp_display.c | 16 +++++++---------
 2 files changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +3 -3
index b896196cf244..779f743f9418 100644
@@ -2616,9 +2616,6 @@ int msm_dp_ctrl_prepare_stream_on(struct msm_dp_ctrl *msm_dp_ctrl,
 	if (force_link_train || !msm_dp_ctrl_channel_eq_ok(ctrl))
 		msm_dp_ctrl_link_retrain(ctrl, panel);
 
-	/* stop txing train pattern to end link training */
-	msm_dp_ctrl_clear_training_pattern(ctrl, panel, DP_PHY_DPRX);
-
 	return ret;
 }
 
@@ -2663,6 +2660,9 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *
 
 	msm_dp_ctrl_setup_tr_unit(ctrl, panel);
 
+	/* stop txing train pattern to end link training */
+	msm_dp_ctrl_clear_training_pattern(ctrl, panel, DP_PHY_DPRX);
+
 	msm_dp_write_link(ctrl, REG_DP_STATE_CTRL, DP_STATE_CTRL_SEND_VIDEO);
 
 	ret = msm_dp_ctrl_wait4video_ready(ctrl);
drivers/gpu/drm/msm/dp/dp_display.c +7 -9
index bce641d7d893..b8373740275b 100644
@@ -632,7 +632,6 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp)
 {
 	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
 	int rc = 0;
-	bool force_link_train = false;
 
 	drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
 
@@ -650,17 +649,16 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp)
 
 	if (!msm_dp_display->power_on) {
 		msm_dp_display_host_phy_init(dp);
-		force_link_train = true;
-	}
 
-	rc = msm_dp_ctrl_on_link(dp->ctrl, dp->panel);
-	if (rc) {
-		DRM_ERROR("Failed link training (rc=%d)\n", rc);
-		// TODO: schedule drm_connector_set_link_status_property()
-		return rc;
+		rc = msm_dp_ctrl_on_link(dp->ctrl, dp->panel);
+		if (rc) {
+			DRM_ERROR("Failed link training (rc=%d)\n", rc);
+			/* TODO: schedule drm_connector_set_link_status_property() */
+			return rc;
+		}
 	}
 
-	return msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, force_link_train);
+	return msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, false);
 }
 
 static int msm_dp_display_enable(struct msm_dp_display_private *dp,
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 4/10 drm/msm/dp: reinit video_comp and guard stream state on link maintenance

In reply to Gianfranco Mariotti

msm_dp_ctrl_link_maintenance() waits on ctrl->video_comp without reinitializing it first, causing msm_dp_ctrl_wait4video_ready() to consume a stale completion left over from initial stream bring-up.

In addition, if link maintenance runs while no video stream pixel clock is active (for example in the window between msm_dp_display_prepare_link() and msm_dp_ctrl_on_stream()):
- Driving DP_STATE_CTRL_PUSH_IDLE via msm_dp_ctrl_push_idle() without an active stream times out waiting for idle_comp.
- Clearing DP_TRAINING_PATTERN_SET while REG_DP_STATE_CTRL has not yet transitioned to DP_STATE_CTRL_SEND_VIDEO re-enables the sink descrambler against unscrambled TPS symbols, and waiting for video ready cannot succeed.

Guard msm_dp_ctrl_push_idle() on ctrl->stream_clks_on, reinitialize ctrl->video_comp before retraining, and return early after msm_dp_ctrl_setup_main_link() when the stream pixel clock is off so the training pattern stays active until msm_dp_ctrl_on_stream() enables video.

Fixes 8ede2ecc3e5e ("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets")
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +5 -2
index 779f743f9418..7201b7b513a3 100644
@@ -2089,13 +2089,16 @@ static int msm_dp_ctrl_link_maintenance(struct msm_dp_ctrl_private *ctrl,
 	int ret = 0;
 	int training_step = DP_TRAINING_NONE;
 
-	msm_dp_ctrl_push_idle(&ctrl->msm_dp_ctrl);
+	if (ctrl->stream_clks_on[panel->stream_id])
+		msm_dp_ctrl_push_idle(&ctrl->msm_dp_ctrl);
 
 	ctrl->link->phy_params.p_level = 0;
 	ctrl->link->phy_params.v_level = 0;
 
+	reinit_completion(&ctrl->video_comp);
+
 	ret = msm_dp_ctrl_setup_main_link(ctrl, panel, &training_step);
-	if (ret)
+	if (ret || !ctrl->stream_clks_on[panel->stream_id])
 		goto end;
 
 	msm_dp_ctrl_clear_training_pattern(ctrl, panel, DP_PHY_DPRX);
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v2 04/10] drm/msm/dp: reinit video_comp and guard stream state on link maintenance

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/msm/dp: race on stream_clks_on and video_comp in link maintenance --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/msm/dp: race on stream_clks_on and video_comp in link maintenance
--

commit 74fb6ec8be236f906bc006dd2cc6f05e8c05939a
Author: Gianfranco Mariotti <[email protected]>

drm/msm/dp: reinit video_comp and guard stream state on link maintenance

This commit reinitializes ctrl->video_comp in msm_dp_ctrl_link_maintenance() and guards msm_dp_ctrl_push_idle() and the post-training steps on ctrl->stream_clks_on[panel->stream_id].

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c +2 -1
index 779f743f94189..7201b7b513a32 100644
@@ -2089,13 +2089,16 @@ static int msm_dp_ctrl_link_maintenance(struct msm_dp_ctrl_private *ctrl,
 	int ret = 0;
 	int training_step = DP_TRAINING_NONE;
 
-	msm_dp_ctrl_push_idle(&ctrl->msm_dp_ctrl);
+	if (ctrl->stream_clks_on[panel->stream_id])
+		msm_dp_ctrl_push_idle(&ctrl->msm_dp_ctrl);
 
 	ctrl->link->phy_params.p_level = 0;

drivers/gpu/drm/msm/dp/dp_ctrl.c static int msm_dp_ctrl_link_maintenance(struct msm_dp_ctrl_private *ctrl, · line 2104

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c +3 -1
 	ctrl->link->phy_params.v_level = 0;
 
+	reinit_completion(&ctrl->video_comp);
+
 	ret = msm_dp_ctrl_setup_main_link(ctrl, panel, &training_step);
-	if (ret)
+	if (ret || !ctrl->stream_clks_on[panel->stream_id])
 		goto end;
 
 	msm_dp_ctrl_clear_training_pattern(ctrl, panel, DP_PHY_DPRX);

[Severity: Medium]
Can msm_dp_ctrl_link_maintenance() race with msm_dp_ctrl_on_stream() on ctrl->stream_clks_on[panel->stream_id] and ctrl->video_comp?

In msm_dp_display_atomic_enable(), msm_dp_display_prepare_link() is followed immediately by msm_dp_display_enable() -> msm_dp_ctrl_on_stream() on the atomic commit thread without holding dp->plugged_lock. Because msm_dp_ctrl_setup_main_link() sleeps across AUX transactions and fsleep() delays, the stream state can change mid-way through link maintenance:

CPU0 (HPD IRQ thread) CPU1 (atomic commit)
msm_dp_irq_hpd_handle() msm_dp_display_atomic_enable()
msm_dp_ctrl_link_maintenance() msm_dp_display_prepare_link()
stream_clks_on[...] is false
reinit_completion(&video_comp) msm_dp_ctrl_setup_main_link()
... (sleeps in AUX / fsleep) msm_dp_display_enable()
msm_dp_ctrl_on_stream()
msm_dp_ctrl_on_pixel_clk()
stream_clks_on[...] = true
reinit_completion(&video_comp) write DP_STATE_CTRL_SEND_VIDEO msm_dp_ctrl_wait4video_ready()
!stream_clks_on[...] is now false msm_dp_ctrl_clear_training_pattern()
write DP_STATE_CTRL_SEND_VIDEO
msm_dp_ctrl_wait4video_ready() <-- both wait on single video_comp

Conversely, if msm_dp_ctrl_link_maintenance() runs reinit_completion(&ctrl->video_comp) while msm_dp_ctrl_on_stream() is already waiting in msm_dp_ctrl_wait4video_ready() (or just after msm_dp_ctrl_isr() completes video_comp), video_comp.done is reset to 0, causing msm_dp_ctrl_wait4video_ready() to time out with -ETIMEDOUT and fail display bring-up.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#6 lore raw

PATCH v2 5/10 drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread

In reply to Gianfranco Mariotti

msm_dp_pm_runtime_suspend() calls disable_irq(dp->irq). When msm_dp_hpd_unplug_handle() or msm_dp_bridge_hpd_notify() executes from msm_dp_display_irq_thread() (i.e. inside dp->irq's own threaded IRQ handler) and drops the last runtime PM reference via pm_runtime_put_sync(), runtime suspend runs synchronously on the IRQ thread and deadlocks in disable_irq(dp->irq) waiting for the currently executing IRQ thread to finish.

Use asynchronous pm_runtime_put() in msm_dp_hpd_unplug_handle() and msm_dp_bridge_hpd_notify().

Fixes 3ea2d1c3d154 ("drm/msm/dp: turn link_ready into plugged")
Fixes 5043357e75ba ("drm/msm/dp: rework HPD handling")
---
 drivers/gpu/drm/msm/dp/dp_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +2 -2
index b8373740275b..3c15f984b29e 100644
@@ -495,7 +495,7 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 			dp->link->sink_count);
 
 	if (dp->plugged) {
-		pm_runtime_put_sync(&pdev->dev);
+		pm_runtime_put(&pdev->dev);
 		dp->plugged = false;
 	}
 
@@ -1627,5 +1627,5 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 		msm_dp_hpd_unplug_handle(dp);
 	}
 
-	pm_runtime_put_sync(&msm_dp_display->pdev->dev);
+	pm_runtime_put(&msm_dp_display->pdev->dev);
 }
Signature · 1 line
2.25.1
#7 lore raw

PATCH v2 6/10 drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count

In reply to Gianfranco Mariotti

msm_dp_panel_read_link_caps() only checked DP_SINK_COUNT on branch devices (without checking count < 0 for AUX errors or updating panel->link->sink_count when non-zero), while msm_dp_link_parse_sink_status_field() unconditionally read DP_SINK_COUNT on every sink.

On non-branch SST sinks that do not implement DP_SINK_COUNT and return 0 at DPCD 0x200, sink_count stayed 0 or flipped between 1 and 0 on subsequent IRQ_HPD requests, causing msm_dp_display_prepare_link() to bail out with -ENOTCONN or msm_dp_link_process_ds_port_status_change() to misclassify link maintenance pulses as DS_PORT_STATUS_CHANGED.

Query drm_dp_read_sink_count_cap() in msm_dp_panel_read_link_caps() and record it in link->has_sink_count, default sinks without DP_SINK_COUNT support to sink_count = 1, keep sink_count and prev_sink_count synchronized via msm_dp_link_set_sink_count(), and clear both on unplug.

Fixes 8ede2ecc3e5e ("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets")
Fixes b7ba5db9c863 ("drm/msm/dp: Use drm_dp_read_sink_count() helper")
---
 drivers/gpu/drm/msm/dp/dp_display.c |  3 +++
 drivers/gpu/drm/msm/dp/dp_link.c    | 26 +++++++++++++++++++++-----
 drivers/gpu/drm/msm/dp/dp_link.h    |  2 ++
 drivers/gpu/drm/msm/dp/dp_panel.c   | 19 +++++++++++++++----
 4 files changed, 41 insertions(+), 9 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +3 -0
index 3c15f984b29e..7831dd13b067 100644
@@ -477,6 +477,9 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 	if (dp->link->sink_count == 0)
 		msm_dp_display_host_phy_exit(dp);
 
+	dp->link->has_sink_count = false;
+	msm_dp_link_set_sink_count(dp->link, 0);
+
 	/*
 	 * We don't need separate work for disconnect as
 	 * connect/attention interrupts are disabled
drivers/gpu/drm/msm/dp/dp_link.c +21 -5
index 34a91e194a12..b619707b8e3b 100644
@@ -720,12 +720,16 @@ static int msm_dp_link_parse_sink_status_field(struct msm_dp_link_private *link)
 	int ret;
 
 	link->prev_sink_count = link->msm_dp_link.sink_count;
-	ret = drm_dp_read_sink_count(link->aux);
-	if (ret < 0) {
-		DRM_ERROR("DP parse sink count failed\n");
-		return ret;
+	if (link->msm_dp_link.has_sink_count) {
+		ret = drm_dp_read_sink_count(link->aux);
+		if (ret < 0) {
+			DRM_ERROR("DP parse sink count failed\n");
+			return ret;
+		}
+		link->msm_dp_link.sink_count = ret;
+	} else {
+		link->msm_dp_link.sink_count = 1;
 	}
-	link->msm_dp_link.sink_count = ret;
 
 	ret = drm_dp_dpcd_read_link_status(link->aux,
 					   link->link_status);
@@ -1348,3 +1352,15 @@ struct msm_dp_link *msm_dp_link_get(struct device *dev, struct drm_dp_aux *aux)
 
 	return msm_dp_link;
 }
+
+void msm_dp_link_set_sink_count(struct msm_dp_link *msm_dp_link, u8 sink_count)
+{
+	struct msm_dp_link_private *link;
+
+	if (!msm_dp_link)
+		return;
+
+	link = container_of(msm_dp_link, struct msm_dp_link_private, msm_dp_link);
+	msm_dp_link->sink_count = sink_count;
+	link->prev_sink_count = sink_count;
+}
drivers/gpu/drm/msm/dp/dp_link.h +2 -0
index 76125e9c07e9..11be55ade0a8 100644
@@ -72,6 +72,7 @@ struct msm_dp_link {
 	u32 test_response;
 
 	u8 sink_count;
+	bool has_sink_count;
 	struct msm_dp_link_test_video test_video;
 	struct msm_dp_link_test_audio test_audio;
 	struct msm_dp_link_phy_params phy_params;
@@ -112,6 +113,7 @@ static inline u32 msm_dp_link_bit_depth_to_bpp(u32 tbd)
 }
 
 void msm_dp_link_reset_phy_params_vx_px(struct msm_dp_link *msm_dp_link);
+void msm_dp_link_set_sink_count(struct msm_dp_link *msm_dp_link, u8 sink_count);
 u32 msm_dp_link_get_test_bits_depth(struct msm_dp_link *msm_dp_link, u32 bpp);
 int msm_dp_link_process_request(struct msm_dp_link *msm_dp_link);
 int msm_dp_link_get_colorimetry_config(struct msm_dp_link *msm_dp_link);
drivers/gpu/drm/msm/dp/dp_panel.c +15 -4
index e633afdf2b47..0f81aaa7e6db 100644
@@ -332,6 +332,7 @@ int msm_dp_panel_read_link_caps(struct msm_dp_panel *msm_dp_panel,
 {
 	int rc, bw_code;
 	int count;
+	struct drm_dp_desc desc;
 	struct msm_dp_panel_private *panel;
 
 	if (!msm_dp_panel || !connector) {
@@ -356,12 +357,22 @@ int msm_dp_panel_read_link_caps(struct msm_dp_panel *msm_dp_panel,
 		return -EINVAL;
 	}
 
-	if (drm_dp_is_branch(msm_dp_panel->dpcd)) {
+	rc = drm_dp_read_desc(panel->aux, &desc, drm_dp_is_branch(msm_dp_panel->dpcd));
+	if (rc)
+		return rc;
+
+	panel->link->has_sink_count =
+		drm_dp_read_sink_count_cap(connector, msm_dp_panel->dpcd, &desc);
+
+	if (panel->link->has_sink_count) {
 		count = drm_dp_read_sink_count(panel->aux);
-		if (!count) {
-			panel->link->sink_count = 0;
-			return -ENOTCONN;
+		if (count <= 0) {
+			msm_dp_link_set_sink_count(panel->link, 0);
+			return count < 0 ? count : -ENOTCONN;
 		}
+		msm_dp_link_set_sink_count(panel->link, count);
+	} else {
+		msm_dp_link_set_sink_count(panel->link, 1);
 	}
 
 	rc = drm_dp_read_downstream_info(panel->aux, msm_dp_panel->dpcd,
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 7/10 drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking

In reply to Gianfranco Mariotti

Keep dp->plugged, AUX transfer enablement, and runtime PM reference counts balanced across hotplug, detection, and link preparation:

- In msm_dp_hpd_plug_handle(), return early when dp->plugged is already set, unwind AUX transfers, PHY init (if initialized by this call), and runtime PM on DPCD/AUX failures, and keep dp->plugged = true when an empty branch device returns -ENOTCONN so downstream hotplug events remain observable.
- In msm_dp_hpd_unplug_handle(), avoid clearing video_test or disabling AUX transfers when !dp->plugged.
- In msm_dp_bridge_detect(), stop mutating priv->plugged (leaving ownership with the HPD plug/unplug handlers), disable AUX transfers on exit whenever !priv->plugged, and unconditionally drop detect's own runtime PM reference.
- Serialize msm_dp_display_prepare_link() under dp->plugged_lock and require dp->plugged before bringing up the link.
- Preserve dp->plugged in msm_dp_bridge_hpd_notify() when detect reports connector_status_disconnected for an attached empty branch dongle.

Fixes 3ea2d1c3d154 ("drm/msm/dp: turn link_ready into plugged")
Fixes 5043357e75ba ("drm/msm/dp: rework HPD handling")
---
 drivers/gpu/drm/msm/dp/dp_display.c | 71 +++++++++++++++++++----------
 1 file changed, 46 insertions(+), 25 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +46 -25
index 7831dd13b067..a48f42a17365 100644
@@ -408,8 +408,9 @@ static int msm_dp_display_handle_irq_hpd(struct msm_dp_display_private *dp)
 
 static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 {
-	int ret;
 	struct platform_device *pdev = dp->msm_dp_display.pdev;
+	bool phy_deinit;
+	int ret;
 
 	drm_dbg_dp(dp->drm_dev, "Before, type=%d sink_count=%d\n",
 			dp->msm_dp_display.connector_type,
@@ -417,6 +418,9 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	guard(mutex)(&dp->plugged_lock);
 
+	if (dp->plugged)
+		return 0;
+
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret) {
 		DRM_ERROR("failed to pm_runtime_resume\n");
@@ -425,9 +429,16 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	msm_dp_aux_enable_xfers(dp->aux, true);
 
-	msm_dp_display_host_phy_init(dp);
+	phy_deinit = msm_dp_display_host_phy_init(dp);
 
 	ret = msm_dp_display_process_hpd_high(dp);
+	if (ret && ret != -ENOTCONN) {
+		msm_dp_aux_enable_xfers(dp->aux, false);
+		if (phy_deinit)
+			msm_dp_display_host_phy_exit(dp);
+		pm_runtime_put(&pdev->dev);
+		return ret;
+	}
 
 	drm_dbg_dp(dp->drm_dev, "After, type=%d sink_count=%d\n",
 			dp->msm_dp_display.connector_type,
@@ -435,8 +446,8 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	dp->plugged = true;
 
-	return ret;
-};
+	return 0;
+}
 
 static void msm_dp_display_handle_plugged_change(struct msm_dp *msm_dp_display,
 		bool plugged)
@@ -458,10 +469,6 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 
 	guard(mutex)(&dp->plugged_lock);
 
-	dp->panel->video_test = false;
-
-	msm_dp_aux_enable_xfers(dp->aux, false);
-
 	drm_dbg_dp(dp->drm_dev, "Before, type=%d sink_count=%d\n",
 			dp->msm_dp_display.connector_type,
 			dp->link->sink_count);
@@ -469,6 +476,9 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 	if (!dp->plugged)
 		return 0;
 
+	dp->panel->video_test = false;
+	msm_dp_aux_enable_xfers(dp->aux, false);
+
 	/* Don't forget modes for eDP */
 	if (!dp->msm_dp_display.is_edp)
 		drm_edid_connector_update(dp->msm_dp_display.connector, NULL);
@@ -497,10 +507,8 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 			dp->msm_dp_display.connector_type,
 			dp->link->sink_count);
 
-	if (dp->plugged) {
-		pm_runtime_put(&pdev->dev);
-		dp->plugged = false;
-	}
+	dp->plugged = false;
+	pm_runtime_put(&pdev->dev);
 
 	return 0;
 }
@@ -641,13 +649,15 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp)
 	if (msm_dp_display->is_edp)
 		msm_dp_hpd_plug_handle(dp);
 
+	guard(mutex)(&dp->plugged_lock);
+
 	rc = pm_runtime_resume_and_get(&msm_dp_display->pdev->dev);
 	if (rc) {
 		DRM_ERROR("failed to pm_runtime_resume\n");
 		return rc;
 	}
 
-	if (dp->link->sink_count == 0)
+	if (!dp->plugged || dp->link->sink_count == 0)
 		return -ENOTCONN;
 
 	if (!msm_dp_display->power_on) {
@@ -926,26 +936,22 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge,
 	DRM_DEBUG_DP("aux link status: %x\n", ret);
 	if (!priv->plugged && !ret) {
 		DRM_DEBUG_DP("aux not connected\n");
-		priv->plugged = false;
 		goto end;
 	}
 
 	ret = drm_dp_read_dpcd_caps(priv->aux, dpcd);
 	if (ret) {
 		DRM_DEBUG_DP("failed to read caps\n");
-		priv->plugged = false;
 		goto end;
 	}
 
 	ret = drm_dp_read_desc(priv->aux, &desc, drm_dp_is_branch(dpcd));
 	if (ret) {
 		DRM_DEBUG_DP("failed to read desc\n");
-		priv->plugged = false;
 		goto end;
 	}
 
 	status = connector_status_connected;
-	priv->plugged = true;
 
 	if (drm_dp_read_sink_count_cap(connector, dpcd, &desc)) {
 		int sink_count = drm_dp_read_sink_count(priv->aux);
@@ -958,18 +964,17 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge,
 
 end:
 	/*
-	 * If we detected the DPRX, leave the controller on so that it doesn't
-	 * lose the state.
+	 * Leave AUX and PHY enabled when the HPD plug handler already owns a
+	 * plugged sink; always release detect's own runtime PM reference.
 	 */
 	if (!priv->plugged) {
-		if (phy_deinit) {
-			msm_dp_aux_enable_xfers(priv->aux, false);
+		msm_dp_aux_enable_xfers(priv->aux, false);
+		if (phy_deinit)
 			msm_dp_display_host_phy_exit(priv);
-		}
-
-		pm_runtime_put_sync(&dp->pdev->dev);
 	}
 
+	pm_runtime_put(&dp->pdev->dev);
+
 	return status;
 }
 
@@ -1598,6 +1603,22 @@ void msm_dp_bridge_hpd_disable(struct drm_bridge *bridge)
 	pm_runtime_put_sync(&msm_dp_display->pdev->dev);
 }
 
+static bool msm_dp_display_is_dongle_plugged(struct msm_dp_display_private *dp,
+					     u32 hpd_link_status)
+{
+	u8 rev;
+
+	guard(mutex)(&dp->plugged_lock);
+
+	if (!dp->plugged || !dp->link->has_sink_count || dp->link->sink_count)
+		return false;
+
+	if (hpd_link_status != ISR_DISCONNECTED)
+		return true;
+
+	return !drm_dp_dpcd_read_byte(dp->aux, DP_DPCD_REV, &rev);
+}
+
 void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 			      struct drm_connector *connector,
 			      enum drm_connector_status status)
@@ -1626,7 +1647,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 		} else {
 			msm_dp_hpd_plug_handle(dp);
 		}
-	} else {
+	} else if (!msm_dp_display_is_dongle_plugged(dp, hpd_link_status)) {
 		msm_dp_hpd_unplug_handle(dp);
 	}
 
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH v2 07/10] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/msm/dp: early return in msm_dp_hpd_plug_handle() skips branch sink init - [Medium] drm/msm/dp…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/msm/dp: early return in msm_dp_hpd_plug_handle() skips branch sink init
- [Medium] drm/msm/dp: stale sink_count in msm_dp_display_is_dongle_plugged() on unplug
--

commit f7be63be5e39d6eb47128f66765be92b0a077052
Author: Gianfranco Mariotti <[email protected]>

drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking

This commit updates hotplug, connector detection, and link preparation in the MSM DP driver to balance dp->plugged state, AUX transfer enablement, and runtime PM reference counting.

Quoted 44 lines
drivers/gpu/drm/msm/dp/dp_display.c +13 -2
index 7831dd13b0674..a48f42a173657 100644
@@ -408,8 +408,9 @@ static int msm_dp_display_handle_irq_hpd(struct msm_dp_display_private *dp)
 
 static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 {
-	int ret;
 	struct platform_device *pdev = dp->msm_dp_display.pdev;
+	bool phy_deinit;
+	int ret;
 
 	drm_dbg_dp(dp->drm_dev, "Before, type=%d sink_count=%d\n",
 			dp->msm_dp_display.connector_type,
@@ -417,6 +418,9 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	guard(mutex)(&dp->plugged_lock);
 
+	if (dp->plugged)
+		return 0;
+
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret) {
 		DRM_ERROR("failed to pm_runtime_resume\n");
@@ -425,9 +429,16 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	msm_dp_aux_enable_xfers(dp->aux, true);
 
-	msm_dp_display_host_phy_init(dp);
+	phy_deinit = msm_dp_display_host_phy_init(dp);
 
 	ret = msm_dp_display_process_hpd_high(dp);
+	if (ret && ret != -ENOTCONN) {
+		msm_dp_aux_enable_xfers(dp->aux, false);
+		if (phy_deinit)
+			msm_dp_display_host_phy_exit(dp);
+		pm_runtime_put(&pdev->dev);
+		return ret;
+	}
 
 	drm_dbg_dp(dp->drm_dev, "After, type=%d sink_count=%d\n",
 			dp->msm_dp_display.connector_type,

drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp) · line 450

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_display.c +2 -2
@@ -435,8 +446,8 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	dp->plugged = true;
 
-	return ret;
-};
+	return 0;
+}

[Severity: High]
Does the early return when dp->plugged is true skip downstream sink initialization when a monitor is later plugged into an already-attached empty branch device?

When an empty branch dongle is connected first, msm_dp_panel_read_link_caps() sets dp->link->sink_count = 0 and returns -ENOTCONN before reading EDID, and msm_dp_hpd_plug_handle() sets dp->plugged = true. When a downstream monitor is connected afterward and msm_dp_bridge_hpd_notify() calls msm_dp_hpd_plug_handle() (for example on external Type-C HPD where hpd_link_status is ISR_DISCONNECTED, or via drm_bridge_connector_detect()), msm_dp_hpd_plug_handle() returns early without running msm_dp_display_process_hpd_high(). Because msm_dp_bridge_detect() only reads DP_SINK_COUNT into a local variable, dp->link->sink_count stays 0, EDID is never read, and msm_dp_display_prepare_link() fails with -ENOTCONN.

[ ... ]

Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_display.c +16 -0
@@ -1598,6 +1603,22 @@ void msm_dp_bridge_hpd_disable(struct drm_bridge *bridge)
 	pm_runtime_put_sync(&msm_dp_display->pdev->dev);
 }
 
+static bool msm_dp_display_is_dongle_plugged(struct msm_dp_display_private *dp,
+					     u32 hpd_link_status)
+{
+	u8 rev;
+
+	guard(mutex)(&dp->plugged_lock);
+
+	if (!dp->plugged || !dp->link->has_sink_count || dp->link->sink_count)
+		return false;
+
+	if (hpd_link_status != ISR_DISCONNECTED)
+		return true;
+
+	return !drm_dp_dpcd_read_byte(dp->aux, DP_DPCD_REV, &rev);
+}
+
 void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 			      struct drm_connector *connector,
 			      enum drm_connector_status status)

drivers/gpu/drm/msm/dp/dp_display.c void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge, · line 1652

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -1
@@ -1626,7 +1647,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 		} else {
 			msm_dp_hpd_plug_handle(dp);
 		}
-	} else {
+	} else if (!msm_dp_display_is_dongle_plugged(dp, hpd_link_status)) {
 		msm_dp_hpd_unplug_handle(dp);
 	}

[Severity: Medium]
Can msm_dp_display_is_dongle_plugged() see a stale non-zero dp->link->sink_count when a downstream monitor is unplugged from an attached branch dongle?

When a downstream monitor is disconnected and detection runs through drm_bridge_connector_detect() -> msm_dp_bridge_detect() without a prior native IRQ_HPD pulse updating dp->link->sink_count, msm_dp_bridge_detect() reads DP_SINK_COUNT == 0 into a local variable and returns connector_status_disconnected while dp->link->sink_count remains >= 1. msm_dp_display_is_dongle_plugged() then returns false and msm_dp_bridge_hpd_notify() calls msm_dp_hpd_unplug_handle(), tearing down dp->plugged, AUX transfers, and runtime PM for the still-attached dongle.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#10 lore raw

PATCH v2 8/10 drm/msm/dp: keep PHY initialized while plugged across link unprepare

In reply to Gianfranco Mariotti

When a DisplayPort output is disabled while a sink remains physically plugged in (e.g. DPMS off or connector force-off), msm_dp_display_unprepare() calls msm_dp_display_host_phy_exit() whenever sink_count != 0, leaving the PHY uninitialized while dp->plugged and AUX transfers remain enabled. Subsequent AUX transactions (from IRQ_HPD or connector re-detection) then stall and time out with -ETIMEDOUT. For the sink_count == 0 case, msm_dp_ctrl_reinit_phy() bypassed msm_dp_ctrl_phy_reset(), triggering spurious DP_INTR_PLL_UNLOCKED AUX interrupts.

Serialize msm_dp_display_unprepare() under dp->plugged_lock, replace the sink_count split and now-unused msm_dp_ctrl_reinit_phy() with msm_dp_display_host_phy_exit() followed by msm_dp_display_host_phy_init() whenever dp->plugged is true, exit the PHY in msm_dp_hpd_unplug_handle() whenever !power_on, and balance PHY exit/init across system sleep in msm_dp_pm_runtime_suspend()/resume().

Fixes 3ea2d1c3d154 ("drm/msm/dp: turn link_ready into plugged")
Fixes 1bda647ce61b ("drm/msm/dp: move link-level teardown from display_disable to display_unprepare")
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    | 13 ------------
 drivers/gpu/drm/msm/dp/dp_ctrl.h    |  1 -
 drivers/gpu/drm/msm/dp/dp_display.c | 33 ++++++++++++++++-------------
 3 files changed, 18 insertions(+), 29 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +0 -13
index 7201b7b513a3..1b2ab7db28cb 100644
@@ -2679,19 +2679,6 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *
 	return ret;
 }
 
-void msm_dp_ctrl_reinit_phy(struct msm_dp_ctrl *msm_dp_ctrl)
-{
-	struct msm_dp_ctrl_private *ctrl;
-	struct phy *phy;
-
-	ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl);
-	phy = ctrl->phy;
-
-	/* aux channel down, reinit phy */
-	phy_exit(phy);
-	phy_init(phy);
-}
-
 void msm_dp_ctrl_off_link(struct msm_dp_ctrl *msm_dp_ctrl,
 			  struct msm_dp_panel *panel)
 {
drivers/gpu/drm/msm/dp/dp_ctrl.h +0 -1
index 80d9258501b4..ea3a42e9b624 100644
@@ -56,7 +56,6 @@ void msm_dp_ctrl_core_clk_disable(struct msm_dp_ctrl *msm_dp_ctrl);
 void msm_dp_ctrl_enable_irq(struct msm_dp_ctrl *msm_dp_ctrl);
 void msm_dp_ctrl_disable_irq(struct msm_dp_ctrl *msm_dp_ctrl);
 
-void msm_dp_ctrl_reinit_phy(struct msm_dp_ctrl *msm_dp_ctrl);
 bool msm_dp_ctrl_stream_clks_on(struct msm_dp_ctrl *dp_ctrl,
 				enum msm_dp_stream_id stream_id);
 #endif /* _DP_CTRL_H_ */
drivers/gpu/drm/msm/dp/dp_display.c +18 -15
index a48f42a17365..d3f4b5a9e723 100644
@@ -483,8 +483,7 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 	if (!dp->msm_dp_display.is_edp)
 		drm_edid_connector_update(dp->msm_dp_display.connector, NULL);
 
-	/* triggered by irq_hdp with sink_count = 0 */
-	if (dp->link->sink_count == 0)
+	if (!dp->msm_dp_display.power_on)
 		msm_dp_display_host_phy_exit(dp);
 
 	dp->link->has_sink_count = false;
@@ -1330,10 +1329,9 @@ static int msm_dp_pm_runtime_suspend(struct device *dev)
 
 	disable_irq(dp->irq);
 
-	if (dp->msm_dp_display.is_edp) {
-		msm_dp_display_host_phy_exit(dp);
+	msm_dp_display_host_phy_exit(dp);
+	if (dp->msm_dp_display.is_edp)
 		msm_dp_aux_hpd_disable(dp->aux);
-	}
 	msm_dp_display_host_deinit(dp);
 
 	return 0;
@@ -1349,12 +1347,15 @@ static int msm_dp_pm_runtime_resume(struct device *dev)
 	 *
 	 * for DP, only host controller is enabled here.
 	 * HPD block is enabled at msm_dp_bridge_hpd_enable()
-	 * PHY will be enabled at plugin handler later
+	 * PHY will be enabled at plugin handler later, or restored here
+	 * across system suspend if a sink is already plugged in
 	 */
 	msm_dp_display_host_init(dp);
 	if (dp->msm_dp_display.is_edp) {
 		msm_dp_aux_hpd_enable(dp->aux);
 		msm_dp_display_host_phy_init(dp);
+	} else if (dp->plugged) {
+		msm_dp_display_host_phy_init(dp);
 	}
 
 	enable_irq(dp->irq);
@@ -1533,19 +1534,21 @@ static void msm_dp_display_unprepare(struct msm_dp_display_private *dp)
 {
 	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
 
-	/* dongle is still connected but sinks are disconnected */
-	if (dp->link->sink_count == 0)
-		msm_dp_link_psm_config(dp->link, &dp->panel->link_info, true);
+	scoped_guard(mutex, &dp->plugged_lock) {
+		/* dongle is still connected but sinks are disconnected */
+		if (dp->link->sink_count == 0 && dp->plugged)
+			msm_dp_link_psm_config(dp->link, &dp->panel->link_info,
+					       true);
 
-	msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
+		msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
 
-	if (dp->link->sink_count == 0)
-		/* re-init the PHY so that we can listen to Dongle disconnect */
-		msm_dp_ctrl_reinit_phy(dp->ctrl);
-	else
+		/* Keep PHY initialized for AUX and IRQ_HPD while a sink remains plugged */
 		msm_dp_display_host_phy_exit(dp);
+		if (dp->plugged)
+			msm_dp_display_host_phy_init(dp);
 
-	msm_dp_display->power_on = false;
+		msm_dp_display->power_on = false;
+	}
 
 	pm_runtime_put_sync(&msm_dp_display->pdev->dev);
 
Signature · 1 line
2.25.1
#11 lore raw

Re: [PATCH v2 08/10] drm/msm/dp: keep PHY initialized while plugged across link unprepare

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/msm/dp: unbalanced link and PHY teardown when atomic_enable fails - [High] drm/msm/dp: race on…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/msm/dp: unbalanced link and PHY teardown when atomic_enable fails
- [High] drm/msm/dp: race on power_on in msm_dp_hpd_unplug_handle() exits powered PHY
--

commit 0a488765100dee43f3575efbfcd59d2d2be4bb48
Author: Gianfranco Mariotti <[email protected]>

drm/msm/dp: keep PHY initialized while plugged across link unprepare

This commit keeps the DP PHY initialized across link unprepare while a sink remains plugged in, exits the PHY on unplug when power_on is false, and balances PHY exit and init across runtime PM suspend and resume.

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +0 -0
index a48f42a173657..d3f4b5a9e723f 100644

drivers/gpu/drm/msm/dp/dp_display.c static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp) · line 489

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -2
@@ -483,8 +483,7 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 	if (!dp->msm_dp_display.is_edp)
 		drm_edid_connector_update(dp->msm_dp_display.connector, NULL);
 
-	/* triggered by irq_hdp with sink_count = 0 */
-	if (dp->link->sink_count == 0)
+	if (!dp->msm_dp_display.power_on)
 		msm_dp_display_host_phy_exit(dp);
 
 	dp->link->has_sink_count = false;

[Severity: High]
Can an unplug during modeset enable cause msm_dp_hpd_unplug_handle() to exit the PHY while it is powered on and msm_dp_ctrl_on_stream() is running?

msm_dp_display_prepare_link() powers on the PHY and enables link clocks under dp->plugged_lock, then drops the lock while msm_dp_display->power_on is still false. msm_dp_display_enable() then runs msm_dp_ctrl_on_stream() and sets power_on = true without holding dp->plugged_lock:

CPU0 CPU1
msm_dp_display_atomic_enable()
msm_dp_display_prepare_link()

    lock(&dp->plugged_lock)
    msm_dp_ctrl_on_link()
      phy_power_on(phy)
    unlock(&dp->plugged_lock)
                                      msm_dp_hpd_unplug_handle()
                                        lock(&dp->plugged_lock)
                                        if (!dp->msm_dp_display.power_on)
                                          msm_dp_display_host_phy_exit(dp)
                                            ...
                                            phy_exit(phy)  <-- PHY is powered on
  msm_dp_display_enable()
    msm_dp_ctrl_on_stream()
    msm_dp_display->power_on = true

This resets the PHY/PLL and calls phy_exit() while phy->power_count is 1 and msm_dp_ctrl_on_stream() is accessing link and stream registers clocked by the PHY PLL.

[ ... ]

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_display.c +6 -6
@@ -1533,19 +1534,21 @@ static void msm_dp_display_unprepare(struct msm_dp_display_private *dp)
 {
 	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
 
-	/* dongle is still connected but sinks are disconnected */
-	if (dp->link->sink_count == 0)
-		msm_dp_link_psm_config(dp->link, &dp->panel->link_info, true);
+	scoped_guard(mutex, &dp->plugged_lock) {
+		/* dongle is still connected but sinks are disconnected */
+		if (dp->link->sink_count == 0 && dp->plugged)
+			msm_dp_link_psm_config(dp->link, &dp->panel->link_info,
+					       true);
 
-	msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
+		msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
 
-	if (dp->link->sink_count == 0)
-		/* re-init the PHY so that we can listen to Dongle disconnect */

drivers/gpu/drm/msm/dp/dp_display.c static void msm_dp_display_unprepare(struct msm_dp_display_private *dp) · line 1551

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -3
-		msm_dp_ctrl_reinit_phy(dp->ctrl);
-	else
+		/* Keep PHY initialized for AUX and IRQ_HPD while a sink remains plugged */
 		msm_dp_display_host_phy_exit(dp);
+		if (dp->plugged)
+			msm_dp_display_host_phy_init(dp);
 
-	msm_dp_display->power_on = false;
+		msm_dp_display->power_on = false;
+	}

[Severity: High]
What happens in msm_dp_display_atomic_post_disable() when an earlier msm_dp_display_atomic_enable() failed and left msm_dp_display->power_on false?

If msm_dp_display_prepare_link() fails (returning -ENOTCONN or failing link training in msm_dp_ctrl_on_link(), where msm_dp_ctrl_deinitialize_mainlink() already disables link clocks and calls phy_power_off()), a later msm_dp_display_atomic_post_disable() still calls msm_dp_display_unprepare() unconditionally. Because msm_dp_display_unprepare() does not check power_on, msm_dp_ctrl_off_link() accesses REG_DP_MAINLINK_CTRL with link clocks off, calls clk_bulk_disable_unprepare() on already-disabled link clocks, and calls phy_power_off() when phy->power_count is already 0 (decrementing it to -1 so subsequent phy_power_on() calls never invoke phy->ops->power_on()).

Conversely, if msm_dp_display_prepare_link() succeeds (leaving the PHY powered on) and msm_dp_display_enable() fails in msm_dp_ctrl_on_stream(), power_on is also false, so an unplug or the eDP msm_dp_hpd_unplug_handle() call at the start of msm_dp_display_atomic_post_disable() now sees !dp->msm_dp_display.power_on and calls msm_dp_display_host_phy_exit() -> phy_exit() before msm_dp_display_unprepare() calls phy_power_off().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#12 lore raw

PATCH v2 9/10 drm/msm/dp: re-read EDID on demand in get_modes when blob is missing

In reply to Gianfranco Mariotti

When a DisplayPort connector is forced off (DRM_FORCE_OFF), drm_helper_probe_single_connector_modes() clears connector->edid_blob_ptr, and drm_edid_read_ddc() returns NULL if HPD plug runs while the connector is forced off.

Since commit db6f98b9515f ("drm/msm/dp: remove cached drm_edid from panel"), msm_dp_display_get_modes() only calls drm_edid_connector_add_modes() on the existing edid_blob_ptr, so re-enabling detection without physically replugging the cable falls back to 640x480.

Re-read EDID via drm_edid_read_ddc() in msm_dp_display_get_modes() when a sink is plugged in with a NULL edid_blob_ptr, and suppress the false "panel edid read failed" error log when connector->force is DRM_FORCE_OFF.

Fixes db6f98b9515f ("drm/msm/dp: remove cached drm_edid from panel")
---
 drivers/gpu/drm/msm/dp/dp_display.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +17 -2
index d3f4b5a9e723..fd9d5f176329 100644
@@ -290,7 +290,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)
 	drm_edid_connector_update(connector, drm_edid);
 
 	if (!drm_edid) {
-		DRM_ERROR("panel edid read failed\n");
+		if (connector->force != DRM_FORCE_OFF)
+			DRM_ERROR("panel edid read failed\n");
 		/* check edid read fail is due to unplug */
 		if (!msm_dp_aux_is_link_connected(dp->aux))
 			return -ETIMEDOUT;
@@ -810,6 +811,7 @@ enum drm_mode_status msm_dp_display_mode_valid(struct msm_dp *dp,
 int msm_dp_display_get_modes(struct msm_dp *dp)
 {
 	struct msm_dp_display_private *msm_dp_display;
+	struct drm_connector *connector;
 
 	if (!dp) {
 		DRM_ERROR("invalid params\n");
@@ -817,8 +819,21 @@ int msm_dp_display_get_modes(struct msm_dp *dp)
 	}
 
 	msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
+	connector = msm_dp_display->panel->connector;
 
-	return drm_edid_connector_add_modes(msm_dp_display->panel->connector);
+	guard(mutex)(&msm_dp_display->plugged_lock);
+
+	if (msm_dp_display->plugged && msm_dp_display->link->sink_count &&
+	    !connector->edid_blob_ptr) {
+		const struct drm_edid *drm_edid;
+
+		drm_edid = drm_edid_read_ddc(connector, &msm_dp_display->aux->ddc);
+		drm_edid_connector_update(connector, drm_edid);
+		msm_dp_display->audio_supported = connector->display_info.has_audio;
+		drm_edid_free(drm_edid);
+	}
+
+	return drm_edid_connector_add_modes(connector);
 }
 
 bool msm_dp_display_check_video_test(struct msm_dp *dp)
Signature · 1 line
2.25.1
#13 lore raw

PATCH v2 10/10 drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle()

In reply to Gianfranco Mariotti

msm_dp_display_irq_thread() forwards DP_DP_IRQ_HPD_INT_MASK via drm_bridge_hpd_notify(..., connector_status_connected), relying on msm_dp_bridge_hpd_notify() to observe ISR_IRQ_HPD_PULSE_COUNT in REG_DP_DP_HPD_INT_STATUS[STATE_STATUS].

Because an IRQ_HPD short pulse lasts 0.5-1.0 ms, STATE_STATUS has already returned to DP_DP_HPD_STATE_STATUS_CONNECTED by the time the threaded IRQ handler runs, misrouting the short pulse to msm_dp_hpd_plug_handle() instead of msm_dp_irq_hpd_handle().

Dispatch DP_DP_IRQ_HPD_INT_MASK directly to msm_dp_irq_hpd_handle():
- Guard msm_dp_irq_hpd_handle() with dp->plugged and skip sink requests in msm_dp_ctrl_handle_sink_request() while mainlink clocks are off.
- On DS_PORT_STATUS_CHANGED from a branch device, update or clear downstream sink state and invoke drm_bridge_hpd_notify() after releasing dp->plugged_lock when called from the IRQ thread (skipping re-entrant notification when called from msm_dp_bridge_hpd_notify()).

Fixes 5043357e75ba ("drm/msm/dp: rework HPD handling")
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    |  5 ++
 drivers/gpu/drm/msm/dp/dp_display.c | 86 +++++++++++++++++++++--------
 2 files changed, 68 insertions(+), 23 deletions(-)
drivers/gpu/drm/msm/dp/dp_ctrl.c +5 -0
index 1b2ab7db28cb..2b5e085afbcb 100644
@@ -2329,6 +2329,11 @@ void msm_dp_ctrl_handle_sink_request(struct msm_dp_ctrl *msm_dp_ctrl,
 	}
 
 	ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl);
+	if (!ctrl->link_clks_on) {
+		drm_dbg_dp(ctrl->drm_dev, "link clocks off, skipping sink request\n");
+		return;
+	}
+
 	sink_request = ctrl->link->sink_request;
 
 	if (sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
drivers/gpu/drm/msm/dp/dp_display.c +63 -23

112 lines not on this page · raw message

Signature · 1 line
2.25.1