mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD
@ 2026-12-02 23:46 Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 01/11] drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes Gianfranco Mariotti
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, Gianfranco Mariotti

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. Platforms using an
external HPD bridge (such as USB Type-C AltMode or display-connector
with hpd-gpios) also fail link-rate/lane downshifting, EDID unplug
checks, AUX resets, and branch dongle disconnect checks because internal
HPD state registers remain disabled.

This series fixes the underlying PHY lane setup, DPCD link-info caching,
SST training-pattern handover, link maintenance completion/stream
handling, external-HPD state checks, 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, keep
   training pattern active until stream clocks are enabled in
   msm_dp_ctrl_link_maintenance(), disable the stream pixel clock if
   waiting for video ready fails in msm_dp_ctrl_on_stream(), and
   serialize stream enable/disable under dp->plugged_lock.
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, keep
   sink_count and prev_sink_count synchronized across plug and unplug,
   and reset sink_count if msm_dp_display_process_hpd_high() fails.
7. Keep dp->plugged, AUX transfer enablement, and runtime PM references
   balanced across plug, unplug, detect, prepare_link, and branch dongle
   downstream plug/unplug notifications.
8. Track link preparation via dp->prepared under dp->plugged_lock and
   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. Track internal HPD block enablement via msm_dp_aux_is_hpd_enabled()
    so external-HPD platforms do not abort link-rate/lane downshifting,
    EDID reads, AUX resets, or branch dongle disconnect checks on
    disabled internal HPD status, while keeping msm_dp_bridge_detect()'s
    !priv->plugged && !ret guard unconditional so USB Type-C connectors
    using drm_aux_hpd_bridge stay disconnected until AltMode mux and
    orientation setup notify HPD.
11. 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 v3:
- Patch 4: serialize msm_dp_display_enable(), msm_dp_display_disable(),
  and msm_dp_display_atomic_disable() under dp->plugged_lock so stream
  bring-up and teardown cannot race with msm_dp_ctrl_link_maintenance(),
  and disable the stream pixel clock in msm_dp_ctrl_on_stream() if
  msm_dp_ctrl_wait4video_ready() fails.
- Patch 6: reset dp->link->sink_count to 0 if
  msm_dp_display_process_hpd_high() fails after reading link caps.
- Patch 7: re-run msm_dp_display_process_hpd_high() in
  msm_dp_hpd_plug_handle() when dp->plugged is already set with
  sink_count == 0, reset dp->link->has_sink_count on initial plug error
  unwind, check dp->plugged and sink_count before
  pm_runtime_resume_and_get() in msm_dp_display_prepare_link(), check
  live drm_dp_read_sink_count() and clear downstream sink state in
  msm_dp_display_is_dongle_plugged() when a downstream monitor is
  unplugged from an attached branch dongle via external HPD or detect(),
  and require dp->plugged in msm_dp_display_enable().
- Patch 8: track link preparation explicitly via dp->prepared under
  dp->plugged_lock so msm_dp_display_unprepare() skips link teardown and
  runtime PM put when prepare_link() did not bring up the link, and
  msm_dp_hpd_unplug_handle() does not call phy_exit() while the PHY is
  still powered on.
- Patch 10 (new): track msm_dp_aux_is_hpd_enabled() and check
  drm_dp_dpcd_read_link_status() <= 0 in msm_dp_ctrl_on_link() so
  external-HPD platforms (USB Type-C AltMode, display-connector with
  hpd-gpios) properly downshift link rate/lanes, reset AUX, and handle
  branch dongles without breaking USB-C cold-boot ordering in
  msm_dp_bridge_detect().
- Patch 11 (was 10): reuse msm_dp_display_clear_downstream_sink() in
  msm_dp_display_handle_ds_port_status().
- Link to v2: https://lore.kernel.org/r/20261127101417.24303-1-gianfranco.mariotti94@gmail.com

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,
  guard msm_dp_ctrl_push_idle() and training-pattern clear 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 10 (was 5): move to end of series, guard with link_clks_on and
  dp->plugged, and handle branch DS_PORT_STATUS_CHANGED with
  non-reentrant drm_bridge_hpd_notify().
- Link to v1: https://lore.kernel.org/r/20261121214105.32596-1-gianfranco.mariotti94@gmail.com

Testing:
Hardware-tested across cold boot, unplug/re-plug, monitor swap (4K60
native DP and DP-to-HDMI branch adapters), connector DPMS/off cycles,
and IRQ_HPD link-retrain cycles on:
- QCS8275 (Monaco, SECO F86 SMARC): 4-lane native DisplayPort with
  internal HPD.
- QCS6490 (SC7280, SECO E81 SMARC):
  - Direct 2-lane DisplayPort + USB3 and direct 4-lane DisplayPort over
    the QMP USB3+DP Combo PHY with internal HPD (dp_hot_plug_det) and
    with external GPIO HPD (display-connector hpd-gpios).
  - USB Type-C DisplayPort AltMode via pmic_glink_altmode
    (drm_aux_hpd_bridge) and gpio-sbu-mux (SECO G15 carrier).
All tests were run on v6.18 + the FROMLIST DP HPD/MST series (Qualcomm
Linux / QLI 2.0), then forward-ported and build-tested against msm-next.

Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>

Gianfranco Mariotti (11):
  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: guard internal HPD state checks when external HPD is used
  drm/msm/dp: dispatch native IRQ_HPD directly to
    msm_dp_irq_hpd_handle()

 drivers/gpu/drm/msm/dp/dp_aux.c     |  13 +-
 drivers/gpu/drm/msm/dp/dp_aux.h     |   1 +
 drivers/gpu/drm/msm/dp/dp_ctrl.c    |  62 +++---
 drivers/gpu/drm/msm/dp/dp_ctrl.h    |   1 -
 drivers/gpu/drm/msm/dp/dp_display.c | 299 +++++++++++++++++++++-------
 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 +-
 8 files changed, 310 insertions(+), 114 deletions(-)


base-commit: d024361c631b3f020a26c07d683e5103404b0fbf
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 01/11] drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 02/11] drm/msm/dp: reset cached link_info before reading DPCD capabilities Gianfranco Mariotti
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, Gianfranco Mariotti

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")
Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz> # x1p42100-lenovo-ideacentre-mini
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index abd3dcdad03c..b896196cf244 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -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;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 02/11] drm/msm/dp: reset cached link_info before reading DPCD capabilities
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 01/11] drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 03/11] drm/msm/dp: keep training pattern active until stream video is ready Gianfranco Mariotti
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_panel.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/msm/dp/dp_panel.c b/drivers/gpu/drm/msm/dp/dp_panel.c
index d3468b73fdc3..e633afdf2b47 100644
--- a/drivers/gpu/drm/msm/dp/dp_panel.c
+++ b/drivers/gpu/drm/msm/dp/dp_panel.c
@@ -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;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 03/11] drm/msm/dp: keep training pattern active until stream video is ready
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 01/11] drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 02/11] drm/msm/dp: reset cached link_info before reading DPCD capabilities Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 04/11] drm/msm/dp: reinit video_comp and guard stream state on link maintenance Gianfranco Mariotti
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz> # x1p42100-lenovo-ideacentre-mini
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 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(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index b896196cf244..779f743f9418 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -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);
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index bce641d7d893..b8373740275b 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -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,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 04/11] drm/msm/dp: reinit video_comp and guard stream state on link maintenance
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (2 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 03/11] drm/msm/dp: keep training pattern active until stream video is ready Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 05/11] drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread Gianfranco Mariotti
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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. Also disable the stream pixel clock in msm_dp_ctrl_on_stream()
if msm_dp_ctrl_wait4video_ready() fails so ctrl->stream_clks_on is not
left enabled while power_on remains false, and serialize
msm_dp_display_enable(), msm_dp_display_disable(), and
msm_dp_display_atomic_disable() under dp->plugged_lock so stream
bring-up and teardown cannot race concurrently with
msm_dp_ctrl_link_maintenance().

Fixes: 8ede2ecc3e5e ("drm/msm/dp: Add DP compliance tests on Snapdragon Chipsets")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    | 11 ++++++++---
 drivers/gpu/drm/msm/dp/dp_display.c |  6 ++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index 779f743f9418..12a889a563d7 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -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);
@@ -2666,8 +2669,10 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *
 	msm_dp_write_link(ctrl, REG_DP_STATE_CTRL, DP_STATE_CTRL_SEND_VIDEO);
 
 	ret = msm_dp_ctrl_wait4video_ready(ctrl);
-	if (ret)
+	if (ret) {
+		msm_dp_ctrl_off_pixel_clk(msm_dp_ctrl, panel->stream_id);
 		return ret;
+	}
 
 	mainlink_ready = msm_dp_ctrl_mainlink_ready(ctrl);
 	drm_dbg_dp(ctrl->drm_dev,
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index b8373740275b..d522b7d254b4 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -667,6 +667,8 @@ static int msm_dp_display_enable(struct msm_dp_display_private *dp,
 	int rc = 0;
 	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
 
+	guard(mutex)(&dp->plugged_lock);
+
 	drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
 	if (msm_dp_display->power_on) {
 		drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
@@ -724,6 +726,8 @@ static int msm_dp_display_disable(struct msm_dp_display_private *dp,
 {
 	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
 
+	guard(mutex)(&dp->plugged_lock);
+
 	if (!msm_dp_display->power_on)
 		return 0;
 
@@ -1504,6 +1508,8 @@ void msm_dp_display_atomic_disable(struct msm_dp *dp)
 
 	msm_dp_display = container_of(dp, struct msm_dp_display_private, msm_dp_display);
 
+	guard(mutex)(&msm_dp_display->plugged_lock);
+
 	/*
 	 * If .atomic_enable() bailed out - link training failure is the common
 	 * case - the mainlink was never brought up and ->power_on stayed false.
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 05/11] drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (3 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 04/11] drm/msm/dp: reinit video_comp and guard stream state on link maintenance Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 06/11] drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count Gianfranco Mariotti
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz> # x1p42100-lenovo-ideacentre-mini
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index d522b7d254b4..1b179596d796 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -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;
 	}
 
@@ -1633,5 +1633,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);
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 06/11] drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (4 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 05/11] drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 07/11] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking Gianfranco Mariotti
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 11 +++++++++--
 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, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index 1b179596d796..dfa643380a8e 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -292,8 +292,10 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)
 	if (!drm_edid) {
 		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;
+		if (!msm_dp_aux_is_link_connected(dp->aux)) {
+			rc = -ETIMEDOUT;
+			goto end;
+		}
 	}
 
 	msm_dp_link_process_request(dp->link);
@@ -318,6 +320,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)
 	msm_dp_link_reset_phy_params_vx_px(dp->link);
 
 end:
+	if (rc)
+		msm_dp_link_set_sink_count(dp->link, 0);
 	drm_edid_free(drm_edid);
 	return rc;
 }
@@ -477,6 +481,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
diff --git a/drivers/gpu/drm/msm/dp/dp_link.c b/drivers/gpu/drm/msm/dp/dp_link.c
index 34a91e194a12..b619707b8e3b 100644
--- a/drivers/gpu/drm/msm/dp/dp_link.c
+++ b/drivers/gpu/drm/msm/dp/dp_link.c
@@ -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;
+}
diff --git a/drivers/gpu/drm/msm/dp/dp_link.h b/drivers/gpu/drm/msm/dp/dp_link.h
index 76125e9c07e9..11be55ade0a8 100644
--- a/drivers/gpu/drm/msm/dp/dp_link.h
+++ b/drivers/gpu/drm/msm/dp/dp_link.h
@@ -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);
diff --git a/drivers/gpu/drm/msm/dp/dp_panel.c b/drivers/gpu/drm/msm/dp/dp_panel.c
index e633afdf2b47..0f81aaa7e6db 100644
--- a/drivers/gpu/drm/msm/dp/dp_panel.c
+++ b/drivers/gpu/drm/msm/dp/dp_panel.c
@@ -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,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 07/11] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (5 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 06/11] drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 08/11] drm/msm/dp: keep PHY initialized while plugged across link unprepare Gianfranco Mariotti
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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 (re-running msm_dp_display_process_hpd_high() if sink_count == 0
  so a downstream sink plugged into an already-attached branch dongle is
  detected on external HPD platforms), 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
  check dp->plugged and sink_count before acquiring a runtime PM
  reference or bringing up the link.
- Preserve dp->plugged in msm_dp_bridge_hpd_notify() when detect or
  external HPD reports connector_status_disconnected for an attached
  branch dongle whose downstream sink was unplugged, updating
  sink_count and clearing downstream sink state in place.

Fixes: 3ea2d1c3d154 ("drm/msm/dp: turn link_ready into plugged")
Fixes: 5043357e75ba ("drm/msm/dp: rework HPD handling")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 113 +++++++++++++++++++++-------
 1 file changed, 85 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index dfa643380a8e..d1925594da87 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -412,8 +412,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,
@@ -421,6 +422,15 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)
 
 	guard(mutex)(&dp->plugged_lock);
 
+	if (dp->plugged) {
+		if (!dp->link->sink_count) {
+			ret = msm_dp_display_process_hpd_high(dp);
+			if (ret && ret != -ENOTCONN)
+				return ret;
+		}
+		return 0;
+	}
+
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret) {
 		DRM_ERROR("failed to pm_runtime_resume\n");
@@ -429,9 +439,17 @@ 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) {
+		dp->link->has_sink_count = false;
+		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,
@@ -439,8 +457,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)
@@ -456,16 +474,27 @@ static void msm_dp_display_handle_plugged_change(struct msm_dp *msm_dp_display,
 							plugged);
 }
 
+static void msm_dp_display_clear_downstream_sink(struct msm_dp_display_private *dp)
+{
+	struct msm_dp *msm_dp_display = &dp->msm_dp_display;
+
+	dp->panel->video_test = false;
+	if (!msm_dp_display->is_edp) {
+		drm_edid_connector_update(msm_dp_display->connector, NULL);
+		drm_dp_set_subconnector_property(msm_dp_display->connector,
+						 connector_status_disconnected,
+						 dp->panel->dpcd,
+						 dp->panel->downstream_ports);
+	}
+	msm_dp_display_handle_plugged_change(msm_dp_display, false);
+}
+
 static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 {
 	struct platform_device *pdev = dp->msm_dp_display.pdev;
 
 	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);
@@ -473,6 +502,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);
@@ -501,10 +533,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;
 }
@@ -645,15 +675,17 @@ 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);
+
+	if (!dp->plugged || dp->link->sink_count == 0)
+		return -ENOTCONN;
+
 	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)
-		return -ENOTCONN;
-
 	if (!msm_dp_display->power_on) {
 		msm_dp_display_host_phy_init(dp);
 
@@ -676,6 +708,9 @@ static int msm_dp_display_enable(struct msm_dp_display_private *dp,
 
 	guard(mutex)(&dp->plugged_lock);
 
+	if (!dp->plugged)
+		return -ENOTCONN;
+
 	drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count);
 	if (msm_dp_display->power_on) {
 		drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
@@ -934,26 +969,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);
@@ -966,18 +997,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;
 }
 
@@ -1497,8 +1527,10 @@ void msm_dp_display_atomic_enable(struct msm_dp *msm_dp_display,
 	}
 
 	rc = msm_dp_display_enable(dp, dp->panel);
-	if (rc)
+	if (rc) {
 		DRM_ERROR("DP display enable failed, rc=%d\n", rc);
+		return;
+	}
 
 	rc = msm_dp_display_post_enable(msm_dp_display);
 	if (rc) {
@@ -1608,6 +1640,31 @@ 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)
+{
+	int sink_count;
+
+	guard(mutex)(&dp->plugged_lock);
+
+	if (!dp->plugged || !dp->link->has_sink_count)
+		return false;
+
+	if (!dp->link->sink_count && hpd_link_status != ISR_DISCONNECTED)
+		return true;
+
+	sink_count = drm_dp_read_sink_count(dp->aux);
+	if (sink_count != 0)
+		return false;
+
+	if (dp->link->sink_count) {
+		msm_dp_link_set_sink_count(dp->link, 0);
+		msm_dp_display_clear_downstream_sink(dp);
+	}
+
+	return true;
+}
+
 void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 			      struct drm_connector *connector,
 			      enum drm_connector_status status)
@@ -1636,7 +1693,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);
 	}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 08/11] drm/msm/dp: keep PHY initialized while plugged across link unprepare
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (6 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 07/11] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 09/11] drm/msm/dp: re-read EDID on demand in get_modes when blob is missing Gianfranco Mariotti
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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.

In addition, if msm_dp_display_prepare_link() fails before bringing up
the main link (or if msm_dp_display_enable() fails after link bring-up),
power_on does not reflect whether link clocks and PHY power are active:
unplugging before unprepare could call phy_exit() while the PHY is still
powered on, while msm_dp_display_unprepare() unconditionally called
msm_dp_ctrl_off_link() even when the link was never prepared.

Track link preparation explicitly via dp->prepared under
dp->plugged_lock:
- Set dp->prepared in msm_dp_display_prepare_link() once link training
  and stream preparation succeed, unwinding runtime PM (and link power if
  enabled) on failure.
- Skip msm_dp_display_unprepare() when !dp->prepared; otherwise tear down
  the link, 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, and
  drop prepare's runtime PM reference.
- Exit the PHY in msm_dp_hpd_unplug_handle() only when !dp->prepared, 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")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 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 | 60 +++++++++++++++++++++--------
 3 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index 12a889a563d7..ceff9a99147f 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -2681,19 +2681,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)
 {
diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.h b/drivers/gpu/drm/msm/dp/dp_ctrl.h
index 80d9258501b4..ea3a42e9b624 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.h
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.h
@@ -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_ */
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index d1925594da87..9e3d81ffbe03 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -55,6 +55,7 @@ struct msm_dp_display_private {
 
 	struct mutex plugged_lock;
 	bool plugged;
+	bool prepared;
 
 	struct drm_device *drm_dev;
 
@@ -509,8 +510,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->prepared)
 		msm_dp_display_host_phy_exit(dp);
 
 	dp->link->has_sink_count = false;
@@ -677,6 +677,11 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp)
 
 	guard(mutex)(&dp->plugged_lock);
 
+	if (dp->prepared) {
+		drm_dbg_dp(dp->drm_dev, "Link already setup, return\n");
+		return 0;
+	}
+
 	if (!dp->plugged || dp->link->sink_count == 0)
 		return -ENOTCONN;
 
@@ -693,11 +698,26 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp)
 		if (rc) {
 			DRM_ERROR("Failed link training (rc=%d)\n", rc);
 			/* TODO: schedule drm_connector_set_link_status_property() */
+			pm_runtime_put(&msm_dp_display->pdev->dev);
 			return rc;
 		}
 	}
 
-	return msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, false);
+	rc = msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, false);
+	if (rc) {
+		if (!msm_dp_display->power_on) {
+			msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
+			msm_dp_display_host_phy_exit(dp);
+			if (dp->plugged)
+				msm_dp_display_host_phy_init(dp);
+		}
+		pm_runtime_put(&msm_dp_display->pdev->dev);
+		return rc;
+	}
+
+	dp->prepared = true;
+
+	return 0;
 }
 
 static int msm_dp_display_enable(struct msm_dp_display_private *dp,
@@ -1363,10 +1383,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;
@@ -1382,12 +1401,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);
@@ -1570,19 +1592,25 @@ 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) {
+		if (!dp->prepared)
+			return;
 
-	msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
+		/* 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);
 
-	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
+		msm_dp_ctrl_off_link(dp->ctrl, dp->panel);
+
+		/* 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;
+		dp->prepared = false;
+	}
 
 	pm_runtime_put_sync(&msm_dp_display->pdev->dev);
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 09/11] drm/msm/dp: re-read EDID on demand in get_modes when blob is missing
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (7 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 08/11] drm/msm/dp: keep PHY initialized while plugged across link unprepare Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 10/11] drm/msm/dp: guard internal HPD state checks when external HPD is used Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 11/11] drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle() Gianfranco Mariotti
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_display.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index 9e3d81ffbe03..b83de4c3d234 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -291,7 +291,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)) {
 			rc = -ETIMEDOUT;
@@ -864,6 +865,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");
@@ -871,8 +873,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)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 10/11] drm/msm/dp: guard internal HPD state checks when external HPD is used
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (8 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 09/11] drm/msm/dp: re-read EDID on demand in get_modes when blob is missing Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  2026-12-02 23:46 ` [PATCH v3 11/11] drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle() Gianfranco Mariotti
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, Gianfranco Mariotti

When DisplayPort HPD is handled by a downstream bridge (such as USB
Type-C AltMode or display-connector with hpd-gpios, including behind a
QMP combo PHY drm_aux_bridge), msm_dp_bridge_hpd_enable() is never
called and REG_DP_DP_HPD_CTRL remains disabled. As a result,
msm_dp_aux_is_link_connected() unconditionally reads 0
(ISR_DISCONNECTED) even while a sink is physically connected:

- In msm_dp_ctrl_on_link(), failing DP_TRAINING_1 or DP_TRAINING_2
  immediately breaks out of the training loop instead of downshifting
  the link rate or lane count; in addition, the return value of
  drm_dp_dpcd_read_link_status() was unchecked, leaving link_status
  uninitialized on AUX errors.
- In msm_dp_display_process_hpd_high(), a failed EDID read falsely
  treats the link as unplugged and aborts with -ETIMEDOUT.
- In msm_dp_aux_transfer(), AUX timeouts skip msm_dp_aux_reset().

Track whether the controller's internal HPD block is enabled via
msm_dp_aux_is_hpd_enabled(), gate those internal HPD state checks on it
(also returning false immediately in msm_dp_display_is_dongle_plugged()
when internal HPD is enabled and reports ISR_DISCONNECTED), and check
drm_dp_dpcd_read_link_status() <= 0 in msm_dp_ctrl_on_link(). Keep the
!priv->plugged && !ret guard in msm_dp_bridge_detect() unconditional so
USB Type-C connectors using drm_aux_hpd_bridge stay disconnected until
AltMode mux and orientation setup notify HPD.

Fixes: a8e981ac2d0e ("drm/msm/dp: enable HDP plugin/unplugged interrupts at hpd_enable/disable")
Fixes: 5043357e75ba ("drm/msm/dp: rework HPD handling")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_aux.c     | 13 ++++++++++++-
 drivers/gpu/drm/msm/dp/dp_aux.h     |  1 +
 drivers/gpu/drm/msm/dp/dp_ctrl.c    | 14 ++++++++++----
 drivers/gpu/drm/msm/dp/dp_display.c |  7 ++++++-
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c
index 3825a2fb48e2..74a90d8de167 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.c
+++ b/drivers/gpu/drm/msm/dp/dp_aux.c
@@ -40,6 +40,7 @@ struct msm_dp_aux_private {
 	bool initted;
 	bool is_edp;
 	bool enable_xfers;
+	bool hpd_enabled;
 	u32 offset;
 	u32 segment;
 
@@ -412,7 +413,7 @@ static ssize_t msm_dp_aux_transfer(struct drm_dp_aux *msm_dp_aux,
 				phy_calibrate(aux->phy);
 		}
 		/* reset aux if link is in connected state */
-		if (msm_dp_aux_is_link_connected(msm_dp_aux))
+		if (!aux->hpd_enabled || msm_dp_aux_is_link_connected(msm_dp_aux))
 			msm_dp_aux_reset(aux);
 	} else {
 		aux->retry_cnt = 0;
@@ -606,6 +607,7 @@ void msm_dp_aux_hpd_enable(struct drm_dp_aux *msm_dp_aux)
 
 	/* Enable HPD */
 	msm_dp_write_aux(aux, REG_DP_DP_HPD_CTRL, DP_DP_HPD_CTRL_HPD_EN);
+	aux->hpd_enabled = true;
 }
 
 void msm_dp_aux_hpd_disable(struct drm_dp_aux *msm_dp_aux)
@@ -614,6 +616,7 @@ void msm_dp_aux_hpd_disable(struct drm_dp_aux *msm_dp_aux)
 		container_of(msm_dp_aux, struct msm_dp_aux_private, msm_dp_aux);
 	u32 reg;
 
+	aux->hpd_enabled = false;
 	reg = msm_dp_read_aux(aux, REG_DP_DP_HPD_REFTIMER);
 	reg &= ~DP_DP_HPD_REFTIMER_ENABLE;
 	msm_dp_write_aux(aux, REG_DP_DP_HPD_REFTIMER, reg);
@@ -679,6 +682,14 @@ u32 msm_dp_aux_is_link_connected(struct drm_dp_aux *msm_dp_aux)
 	return status;
 }
 
+bool msm_dp_aux_is_hpd_enabled(struct drm_dp_aux *msm_dp_aux)
+{
+	struct msm_dp_aux_private *aux =
+		container_of(msm_dp_aux, struct msm_dp_aux_private, msm_dp_aux);
+
+	return aux->hpd_enabled;
+}
+
 struct drm_dp_aux *msm_dp_aux_get(struct device *dev,
 			      struct phy *phy,
 			      bool is_edp,
diff --git a/drivers/gpu/drm/msm/dp/dp_aux.h b/drivers/gpu/drm/msm/dp/dp_aux.h
index 4be02e8b4d0b..d3cf281f159a 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.h
+++ b/drivers/gpu/drm/msm/dp/dp_aux.h
@@ -22,6 +22,7 @@ void msm_dp_aux_hpd_intr_enable(struct drm_dp_aux *msm_dp_aux);
 void msm_dp_aux_hpd_intr_disable(struct drm_dp_aux *msm_dp_aux);
 u32 msm_dp_aux_get_hpd_intr_status(struct drm_dp_aux *msm_dp_aux);
 u32 msm_dp_aux_is_link_connected(struct drm_dp_aux *msm_dp_aux);
+bool msm_dp_aux_is_hpd_enabled(struct drm_dp_aux *msm_dp_aux);
 
 struct phy;
 struct drm_dp_aux *msm_dp_aux_get(struct device *dev,
diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index ceff9a99147f..36fc9c6bd9f4 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -2435,10 +2435,13 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl,
 			break;
 		} else if (training_step == DP_TRAINING_1) {
 			/* link train_1 failed */
-			if (!msm_dp_aux_is_link_connected(ctrl->aux))
+			if (msm_dp_aux_is_hpd_enabled(ctrl->aux) &&
+			    !msm_dp_aux_is_link_connected(ctrl->aux))
 				break;
 
-			drm_dp_dpcd_read_link_status(ctrl->aux, link_status);
+			if (drm_dp_dpcd_read_link_status(ctrl->aux,
+							 link_status) <= 0)
+				break;
 
 			rc = msm_dp_ctrl_link_rate_down_shift(ctrl);
 			if (rc < 0) { /* already in RBR = 1.6G */
@@ -2460,10 +2463,13 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl,
 			}
 		} else if (training_step == DP_TRAINING_2) {
 			/* link train_2 failed */
-			if (!msm_dp_aux_is_link_connected(ctrl->aux))
+			if (msm_dp_aux_is_hpd_enabled(ctrl->aux) &&
+			    !msm_dp_aux_is_link_connected(ctrl->aux))
 				break;
 
-			drm_dp_dpcd_read_link_status(ctrl->aux, link_status);
+			if (drm_dp_dpcd_read_link_status(ctrl->aux,
+							 link_status) <= 0)
+				break;
 
 			if (!drm_dp_clock_recovery_ok(link_status,
 					ctrl->link->link_params.num_lanes))
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index b83de4c3d234..b4ea61a88d68 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -294,7 +294,8 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp)
 		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)) {
+		if (msm_dp_aux_is_hpd_enabled(dp->aux) &&
+		    !msm_dp_aux_is_link_connected(dp->aux)) {
 			rc = -ETIMEDOUT;
 			goto end;
 		}
@@ -1693,6 +1694,10 @@ static bool msm_dp_display_is_dongle_plugged(struct msm_dp_display_private *dp,
 	if (!dp->plugged || !dp->link->has_sink_count)
 		return false;
 
+	if (msm_dp_aux_is_hpd_enabled(dp->aux) &&
+	    hpd_link_status == ISR_DISCONNECTED)
+		return false;
+
 	if (!dp->link->sink_count && hpd_link_status != ISR_DISCONNECTED)
 		return true;
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 11/11] drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle()
  2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
                   ` (9 preceding siblings ...)
  2026-12-02 23:46 ` [PATCH v3 10/11] drm/msm/dp: guard internal HPD state checks when external HPD is used Gianfranco Mariotti
@ 2026-12-02 23:46 ` Gianfranco Mariotti
  10 siblings, 0 replies; 12+ messages in thread
From: Gianfranco Mariotti @ 2026-12-02 23:46 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, David Airlie, Simona Vetter
  Cc: Yongxing Mou, Xiangxu Yin, Dale Whinham, Stephen Boyd,
	Bjorn Andersson, Jens Glathe, linux-arm-msm, dri-devel,
	freedreno, linux-kernel, 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")
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c    |  5 ++
 drivers/gpu/drm/msm/dp/dp_display.c | 77 ++++++++++++++++++++---------
 2 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index 36fc9c6bd9f4..39781f619da7 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -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) {
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
index b4ea61a88d68..49aead19bc7e 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -541,32 +541,65 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp)
 	return 0;
 }
 
-static int msm_dp_irq_hpd_handle(struct msm_dp_display_private *dp)
+static int msm_dp_display_handle_ds_port_status(struct msm_dp_display_private *dp,
+						enum drm_connector_status *hpd_status,
+						bool *notify_hpd)
 {
+	int rc;
+
+	if (dp->link->sink_count) {
+		rc = msm_dp_display_process_hpd_high(dp);
+		if (!rc) {
+			*hpd_status = connector_status_connected;
+			*notify_hpd = true;
+		}
+		return rc;
+	}
+
+	msm_dp_display_clear_downstream_sink(dp);
+	*hpd_status = connector_status_disconnected;
+	*notify_hpd = true;
+
+	return 0;
+}
+
+static int msm_dp_irq_hpd_handle(struct msm_dp_display_private *dp, bool notify)
+{
+	enum drm_connector_status hpd_status = connector_status_disconnected;
+	bool notify_hpd = false;
 	u32 sink_request;
 	int rc = 0;
 
-	guard(mutex)(&dp->plugged_lock);
-
-	/* irq_hpd can happen at either connected or disconnected state */
-	drm_dbg_dp(dp->drm_dev, "Before, type=%d, sink_count=%d\n",
-			dp->msm_dp_display.connector_type,
-			dp->link->sink_count);
+	scoped_guard(mutex, &dp->plugged_lock) {
+		if (!dp->plugged)
+			return 0;
+
+		/* irq_hpd can happen at either connected or disconnected state */
+		drm_dbg_dp(dp->drm_dev, "Before, type=%d, sink_count=%d\n",
+			   dp->msm_dp_display.connector_type,
+			   dp->link->sink_count);
+
+		/* check for any test request issued by sink */
+		rc = msm_dp_link_process_request(dp->link);
+		if (!rc) {
+			sink_request = dp->link->sink_request;
+			drm_dbg_dp(dp->drm_dev, "sink_request=%d\n",
+				   sink_request);
+			if (sink_request & DS_PORT_STATUS_CHANGED)
+				rc = msm_dp_display_handle_ds_port_status(dp,
+									  &hpd_status,
+									  &notify_hpd);
+			else
+				rc = msm_dp_display_handle_irq_hpd(dp);
+		}
 
-	/* check for any test request issued by sink */
-	rc = msm_dp_link_process_request(dp->link);
-	if (!rc) {
-		sink_request = dp->link->sink_request;
-		drm_dbg_dp(dp->drm_dev, "sink_request=%d\n", sink_request);
-		if (sink_request & DS_PORT_STATUS_CHANGED)
-			rc = msm_dp_display_process_hpd_high(dp);
-		else
-			rc = msm_dp_display_handle_irq_hpd(dp);
+		drm_dbg_dp(dp->drm_dev, "After, type=%d, sink_count=%d\n",
+			   dp->msm_dp_display.connector_type,
+			   dp->link->sink_count);
 	}
 
-	drm_dbg_dp(dp->drm_dev, "After, type=%d, sink_count=%d\n",
-			dp->msm_dp_display.connector_type,
-			dp->link->sink_count);
+	if (notify && notify_hpd)
+		drm_bridge_hpd_notify(dp->msm_dp_display.bridge, hpd_status);
 
 	return rc;
 }
@@ -1092,10 +1125,8 @@ static irqreturn_t msm_dp_display_irq_thread(int irq, void *dev_id)
 		drm_bridge_hpd_notify(dp->msm_dp_display.bridge,
 				      connector_status_connected);
 
-	/* Send HPD as connected and distinguish it in the notifier */
 	if (hpd_isr_status & DP_DP_IRQ_HPD_INT_MASK)
-		drm_bridge_hpd_notify(dp->msm_dp_display.bridge,
-				      connector_status_connected);
+		msm_dp_irq_hpd_handle(dp, true);
 
 	ret = IRQ_HANDLED;
 
@@ -1737,7 +1768,7 @@ void msm_dp_bridge_hpd_notify(struct drm_bridge *bridge,
 			msm_dp_hpd_unplug_handle(dp);
 			msm_dp_hpd_plug_handle(dp);
 		} else if (hpd_link_status == ISR_IRQ_HPD_PULSE_COUNT) {
-			msm_dp_irq_hpd_handle(dp);
+			msm_dp_irq_hpd_handle(dp, false);
 		} else {
 			msm_dp_hpd_plug_handle(dp);
 		}
-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-02 23:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 23:46 [PATCH v3 00/11] drm/msm/dp: fix DisplayPort hotplug, link training, PHY lifecycle, and external HPD Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 01/11] drm/msm/dp: configure voltage swing and pre-emphasis for all active lanes Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 02/11] drm/msm/dp: reset cached link_info before reading DPCD capabilities Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 03/11] drm/msm/dp: keep training pattern active until stream video is ready Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 04/11] drm/msm/dp: reinit video_comp and guard stream state on link maintenance Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 05/11] drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 06/11] drm/msm/dp: track DP_SINK_COUNT capability and sync prev_sink_count Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 07/11] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 08/11] drm/msm/dp: keep PHY initialized while plugged across link unprepare Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 09/11] drm/msm/dp: re-read EDID on demand in get_modes when blob is missing Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 10/11] drm/msm/dp: guard internal HPD state checks when external HPD is used Gianfranco Mariotti
2026-12-02 23:46 ` [PATCH v3 11/11] drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle() Gianfranco Mariotti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®