[PATCH v2 09/10] drm/bridge: analogix_dp: Restrict forced connected status only for panel endpoint

Damon Ding <[email protected]>
Newsgroups gmane.linux.drivers.devicetree,gmane.comp.video.dri.devel,gmane.linux.kernel,gmane.linux.ports.arm.rockchip,gmane.linux.ports.arm.kernel
Message-ID <[email protected]>
Limit the shortcut which unconditionally returns connected status when
a next bridge exists. Only apply this logic if the last bridge in the
chain is a panel. For all other cases, rely on analogix_dp_detect_hpd()
to report accurate hotplug state.

Background for the special handling:
- If the chain ends with a DP connector bridge, the connector relies
on analogix_dp to perform detection. We must avoid hardcoding connected
status here.
- For intermediate bridges such as PS8625 / PTN3460 without detect
support [1], historically the bridge connector defaults to connected
via drm_helper_probe_detect() when no per-bridge detect callback
exists. Maintain compatibility by keeping the shortcut exclusively for
panel endpoints.

[1] https://lore.kernel.org/all/4939d55e-b560-4235-8295-adf8e48d9b74-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org/

Reported-by: Heiko Stuebner <[email protected]>
Link: https://lore.kernel.org/all/5209243.oAaWjsssbx@diego/
Signed-off-by: Damon Ding <[email protected]>
---
 .../gpu/drm/bridge/analogix/analogix_dp_core.c   | 16 ++++++++++++++--
 .../gpu/drm/bridge/analogix/analogix_dp_core.h   |  1 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
index f05db455b430..a5a50b9ab8a7 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c
@@ -906,8 +906,15 @@ analogix_dp_bridge_detect(struct drm_bridge *bridge, struct drm_connector *conne
 	struct analogix_dp_device *dp = to_dp(bridge);
 	enum drm_connector_status status = connector_status_disconnected;
 
-	if (dp->plat_data->next_bridge)
-		return connector_status_connected;
+	/*
+	 * Only assume connected when the bridge chain ends with a panel.
+	 * Panel bridges lack a detect callback and historically rely on
+	 * this shortcut. For other next bridge types (e.g., DP connector
+	 * bridges), fall through to analogix_dp_detect_hpd() to report
+	 * accurate hotplug state.
+	 */
+	if (dp->plat_data->next_bridge && dp->last_bridge_is_panel)
+		status = connector_status_connected;
 
 	if (!analogix_dp_detect_hpd(dp))
 		status = connector_status_connected;
@@ -920,6 +927,7 @@ static int analogix_dp_bridge_attach(struct drm_bridge *bridge,
 				     enum drm_bridge_attach_flags flags)
 {
 	struct analogix_dp_device *dp = to_dp(bridge);
+	struct drm_bridge *last_bridge;
 	int ret = 0;
 
 	if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
@@ -934,6 +942,10 @@ static int analogix_dp_bridge_attach(struct drm_bridge *bridge,
 			dev_err(dp->dev, "failed to attach following panel or bridge (%d)\n", ret);
 			return ret;
 		}
+
+		last_bridge = drm_bridge_chain_get_last_bridge(dp->encoder);
+		if (drm_bridge_is_panel(last_bridge))
+			dp->last_bridge_is_panel = true;
 	}
 
 	return 0;
diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
index 2066e575ce10..bcb5674801a2 100644
--- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
+++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h
@@ -168,6 +168,7 @@ struct analogix_dp_device {
 	bool			force_hpd;
 	bool			fast_train_enable;
 	bool			psr_supported;
+	bool			last_bridge_is_panel;
 
 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
 
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.