mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
To: Rob Clark <robin.clark@oss.qualcomm.com>,
	Dmitry Baryshkov <lumag@kernel.org>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	Jessica Zhang <jesszhan0024@gmail.com>,
	Sean Paul <sean@poorly.run>,
	Marijn Suijten <marijn.suijten@somainline.org>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: Yongxing Mou <yongxing.mou@oss.qualcomm.com>,
	Xiangxu Yin <xiangxu.yin@oss.qualcomm.com>,
	Dale Whinham <daleyo@gmail.com>,
	Stephen Boyd <swboyd@chromium.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Jens Glathe <jens.glathe@oldschoolsolutions.biz>,
	linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
Subject: [PATCH v3 07/11] drm/msm/dp: fix HPD plugged, AUX gate, and runtime PM tracking
Date: Thu,  3 Dec 2026 00:46:36 +0100	[thread overview]
Message-ID: <20261202234640.9379-8-gianfranco.mariotti94@gmail.com> (raw)
In-Reply-To: <20261202234640.9379-1-gianfranco.mariotti94@gmail.com>

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


  parent reply	other threads:[~2026-12-02 23:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Gianfranco Mariotti [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202234640.9379-8-gianfranco.mariotti94@gmail.com \
    --to=gianfranco.mariotti94@gmail.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=airlied@gmail.com \
    --cc=andersson@kernel.org \
    --cc=daleyo@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=jens.glathe@oldschoolsolutions.biz \
    --cc=jesszhan0024@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lumag@kernel.org \
    --cc=marijn.suijten@somainline.org \
    --cc=robin.clark@oss.qualcomm.com \
    --cc=sean@poorly.run \
    --cc=simona@ffwll.ch \
    --cc=swboyd@chromium.org \
    --cc=xiangxu.yin@oss.qualcomm.com \
    --cc=yongxing.mou@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®