drm/msm/dp: fix DisplayPort hotplug, link training, and multi-lane PHY setup
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-rate caching, SST training-pattern handover, link maintenance BPC restoration, and HPD / runtime-PM state tracking issues:
1. Configure PHY voltage swing and pre-emphasis across all active lanes in msm_dp_ctrl_set_vx_px() instead of only lane 0.
2. Reset cached link_info->rate and link_info->use_rate_set in msm_dp_panel_read_dpcd() so re-plugging a different sink does not skip drm_dp_max_link_rate().
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. Reinitialize ctrl->video_comp and restore source BPC/format parameters in msm_dp_ctrl_link_maintenance().
5. Dispatch DP_DP_IRQ_HPD_INT_MASK to msm_dp_irq_hpd_handle() instead of misrouting expired 0.5-1.0 ms short pulses to msm_dp_hpd_plug_handle() (kept separate as it can be dropped once Dmitry Baryshkov's and Yongxing Mou's in-flight DRM_CONNECTOR_DP_IRQ_HPD series land).
6. 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().
7. Keep dp->plugged, dp->link->sink_count, AUX transfer enablement, and PHY teardown consistent across plug, detect, unplug, and unprepare.
Testing:
Hardware-tested across cold boot, unplug/re-plug, monitor swap, 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 (7):
drm/msm/dp: configure voltage swing and pre-emphasis for all active
lanes
drm/msm/dp: reset cached link rate before reading DPCD capabilities drm/msm/dp: keep training pattern active until stream video is ready drm/msm/dp: restore source params and reinit video_comp on link
maintenance
drm/msm/dp: dispatch native IRQ_HPD directly to
msm_dp_irq_hpd_handle()
drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread drm/msm/dp: fix HPD plugged and sink_count state tracking across
hotplug
drivers/gpu/drm/msm/dp/dp_ctrl.c | 23 ++++++++---- drivers/gpu/drm/msm/dp/dp_display.c | 55 ++++++++++++++++------------- drivers/gpu/drm/msm/dp/dp_panel.c | 2 ++ 3 files changed, 48 insertions(+), 32 deletions(-)
base-commit: d024361c631b3f020a26c07d683e5103404b0fbf
Signature · 1 line
2.25.1
PATCH 1/7 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] and left phy_opts->dp.lanes and phy_opts->dp.link_rate unset when calling phy_configure(), leaving lanes 1..3 unconfigured on multi-lane links.
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.
--- 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
@@ -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
PATCH 2/7 drm/msm/dp: reset cached link rate before reading DPCD capabilities
In reply to Gianfranco MariottiCommit 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 the stale link rate and use_rate_set flag from the previous sink.
Reset link_info->rate and link_info->use_rate_set before parsing DPCD capabilities.
--- drivers/gpu/drm/msm/dp/dp_panel.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/dp/dp_panel.c +2 -0
@@ -195,6 +195,8 @@ 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; + link_info->rate =0 ; + link_info->use_rate_set = false; link_info->revision = dpcd[DP_DPCD_REV ]; major = (link_info->revision >>4 ) &0x0f ; minor = link_info->revision &0x0f ;
Signature · 1 line
2.25.1
PATCH 3/7 drm/msm/dp: keep training pattern active until stream video is ready
In reply to Gianfranco MariottiCommit 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.
--- 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
@@ -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
@@ -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
PATCH 4/7 drm/msm/dp: restore source params and reinit video_comp on link maintenance
In reply to Gianfranco MariottiIn msm_dp_ctrl_link_maintenance(), msm_dp_ctrl_setup_main_link() calls msm_dp_ctrl_config_ctrl_link(), which resets REG_DP_CONFIGURATION_CTRL to 6 bpc without restoring the active stream's BPC and format via msm_dp_ctrl_configure_source_params(). In addition, ctrl->video_comp is not reinitialized before waiting for video ready.
Reinitialize ctrl->video_comp before retraining the link and restore source parameters via msm_dp_ctrl_configure_source_params() before switching REG_DP_STATE_CTRL to DP_STATE_CTRL_SEND_VIDEO.
--- drivers/gpu/drm/msm/dp/dp_ctrl.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/msm/dp/dp_ctrl.c +4 -0
@@ -2094,10 +2094,14 @@ static int msm_dp_ctrl_link_maintenance(struct msm_dp_ctrl_private *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) goto end; +msm_dp_ctrl_configure_source_params (ctrl, panel); +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 );
Signature · 1 line
2.25.1
PATCH 5/7 drm/msm/dp: dispatch native IRQ_HPD directly to msm_dp_irq_hpd_handle()
In reply to Gianfranco Mariottimsm_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().
---
Note: Kept separate from the msm_dp_ctrl_link_maintenance() fix so this patch can be dropped once Dmitry Baryshkov's and Yongxing Mou's in-flight DRM_CONNECTOR_DP_IRQ_HPD series land.
drivers/gpu/drm/msm/dp/dp_display.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +1 -3
@@ -1015,10 +1015,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); ret =IRQ_HANDLED ;
Signature · 1 line
2.25.1
PATCH 6/7 drm/msm/dp: avoid synchronous runtime PM put from HPD IRQ thread
In reply to Gianfranco Mariottimsm_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().
--- 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
@@ -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; }
@@ -1625,5 +1625,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
PATCH 7/7 drm/msm/dp: fix HPD plugged and sink_count state tracking across hotplug
In reply to Gianfranco MariottiKeep dp->plugged, dp->link->sink_count, AUX transfer enablement, and runtime PM references consistent across DisplayPort hotplug cycles:
- In msm_dp_hpd_plug_handle(), return early if dp->plugged is already set so duplicate plug notifications do not leak runtime PM references, and unwind AUX/PHY/runtime-PM state instead of setting dp->plugged = true when msm_dp_display_process_hpd_high() fails.
- In msm_dp_display_process_hpd_high(), ensure dp->link->sink_count = 1 when a valid EDID is read from a sink that reports sink_count == 0, preventing msm_dp_display_prepare_link() from failing with -ENOTCONN.
- In msm_dp_bridge_detect(), stop mutating priv->plugged (which is paired with the HPD plug/unplug runtime PM reference), and always disable AUX transfers on exit when !priv->plugged even if the PHY was already initialized.
- In msm_dp_hpd_unplug_handle(), reset dp->link->sink_count = 0 on disconnect, and in msm_dp_display_unprepare(), only enter dongle D3 and re-initialize the PHY when dp->link->sink_count == 0 && dp->plugged so a full cable unplug powers down the PHY instead of issuing AUX writes and leaving the PHY active.
--- drivers/gpu/drm/msm/dp/dp_display.c | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +20 -11
@@ -307,6 +307,9 @@ static int msm_dp_display_process_hpd_high(struct msm_dp_display_private *dp) dp->msm_dp_display.psr_supported = dp->panel->psr_cap.version && psr_enabled; dp->audio_supported = info->has_audio; +if (drm_edid && dp->link->sink_count ==0 ) + dp->link->sink_count =1 ; +msm_dp_panel_handle_sink_request (dp->panel, drm_edid);/*
@@ -417,6 +420,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" );
@@ -428,6 +434,12 @@ static int msm_dp_hpd_plug_handle(struct msm_dp_display_private *dp)msm_dp_display_host_phy_init (dp); ret =msm_dp_display_process_hpd_high (dp); +if (ret) { +msm_dp_aux_enable_xfers (dp->aux, false); +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 +447,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)
@@ -477,6 +489,8 @@ 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->sink_count =0 ; +/* * We don't need separate work for disconnect as * connect/attention interrupts are disabled
@@ -923,26 +937,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);
@@ -959,10 +969,9 @@ enum drm_connector_status msm_dp_bridge_detect(struct drm_bridge *bridge,* lose the state. */ 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); }
@@ -1524,12 +1533,12 @@ 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 ) +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); -if (dp->link->sink_count ==0 ) +if (dp->link->sink_count ==0 && dp->plugged)/* re-init the PHY so that we can listen to Dongle disconnect */ msm_dp_ctrl_reinit_phy (dp->ctrl);else
Signature · 1 line
2.25.1
Quoted 8 lines · 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.
This series fixes the underlying PHY lane setup, DPCD link-rate caching, SST training-pattern handover, link maintenance BPC restoration, and HPD / runtime-PM state tracking issues:
Hi Gianfranco,
thanks for this series. I backported it to 7.3.y [1] and tested it on a Lenovo IdeaCentre Mini 01Q8X10 (X1P42100) with 50 rounds of DPMS off/on, first HDMI only (Parade PS186 branch), then HDMI plus a second display behind a Lenovo USB-C dock (40B0, DP alt mode pin D, 2 lanes through two LTTPRs).
Before, external displays behind the HDMI bridge regularly failed to retrain after DPMS wake on 7.2+. With the series, every wake trained once at HBR2, CR/EQ passed on both links, and video came up every round on both outputs. No "already disabled" or PHY power_count issues.
Notes on the backport:
- 2/7 is covered in 7.3 by the link_info memset from Anthony Ruhier's 172c1648222e ("drm/msm/dp: recompute the link capabilities on every sink read"), so I dropped it.
- 5/7: 7.3 already routes native IRQ_HPD via 216110888698 ("drm/msm/dp:
Handle IRQ HPD as a sink request"), so I only carried over the pm_runtime_put() change there.
- 7/7: 7.3 lacks 1bda647ce61b ("drm/msm/dp: move link-level teardown from display_disable to display_unprepare"), so the teardown still lives in msm_dp_display_disable(); I applied the dp->plugged gating there instead of in unprepare.
One observation: on DPMS off, the PS186 still raises an HPD IRQ about 100 ms after the link is disabled, which sends a hotplug uevent per connector, with get_modes reporting "No sink connected". It's harmless here, but some debouncing may be worth adding on top later.
For the series, as tested on X1P42100:
[1] https://github.com/jglathe/linux_ms_dev_kit/tree/jg/ubuntu-qcom-x1e-7.3.y
Best regards,
Jens