From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=160.236.52.242 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039600; b=ah/lNoMAfCVw+iR4c1dh/7i5yD1/R6Mz8GY7ggwvC3Ai0DFQ1MSgXQD9Ut+CI0HVmuaD aFxdaqW4L0LqktwfQ1pEWyBpfBo3ryMwOpVK5wANeJnfp+VH09gW3eG4L5VOhtSrvBx7o R24XWNBQQDdtW3Z3eClmcY1GFO44s2XhIRtikvxp7LnEze2zICMloJlZ2/V7yH4b5Pfae N7lLYhDe4/PucnRNXTkcGdgoZhVn/kSU0CI8rvzQSIWYVIUOLCO1gB1DVpXbqmiy7O0rp dyqwKoYAyauQKTmtg4bsNL+ozbH0Xbwu2FZbnWpxTUD4Twh7MTykQcJ9OeUPahftACA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796039600; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-HM-Tid:X-HM-MType:X-HM-Spam-Status:DKIM-Signature; bh=gmZHWIOlyYgqDIirQ48xhqOjkBCiYW5Z/q+rVf0qEZU=; b=kzD5MivEFEvEebSrkXkfvmsEyFCbXIquAgPfr63z+8+nrXZoeV4zALC1FbtqQRrmJ63a T9x66bmQrXIjX0VgdQFl1NRAs8S/ho2iT6mWFvd02Tu4rh+kLkjwoGQtLnKV95dT08Qcw NUs0mM3762Rwmx0PLLnQ9WaNJOd5RgWoi0O+gkpwnQcPN77iSwpTSpczSNqqZo3UeSb7R uKfikBCz/826tEtBMUJt4v41Uvl0gFKi+bVZvbfb4Pvgg2W7rhLbw09fz7o4OHytYTb6+ BaFM5FxBeu2qG3wmtrWBPZmNRaPEBzHjQOqKzOVtb2+lB7AsQdt+dFpkTCtWuN3YMDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=rock-chips.com; spf=pass smtp.mailfrom=rock-chips.com; dkim=pass header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=iJ27Fd0g; arc=none smtp.remote-ip=160.236.52.242 Received: from mail-m16023652242.xmail.ntesmail.com (mail-m16023652242.xmail.ntesmail.com [160.236.52.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30822606C421; Mon, 30 Nov 2026 11:53:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 30822606C421 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=iJ27Fd0g Received: from zyb-HP-ProDesk-680-G2-MT.. (unknown [61.154.14.86]) by smtp.qiye.163.com (Hmail) with ESMTP id 568433e71; Mon, 30 Nov 2026 19:53:07 +0800 (GMT+08:00) From: Damon Ding To: Andrzej Hajda , Neil Armstrong , Robert Foss , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jingoo Han , Inki Dae , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Peter Griffin , Alim Akhtar , Heiko Stuebner , Sandy Huang , Andy Yan Cc: Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Dmitry Baryshkov , Marek Szyprowski , Chaoyi Chen , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, Damon Ding Subject: [PATCH v8 19/20] drm/bridge: analogix_dp: Handle HPD notification from downstream bridge Date: Mon, 30 Nov 2026 19:51:51 +0800 Message-Id: <20261130115152.1797928-20-damon.ding@rock-chips.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130115152.1797928-1-damon.ding@rock-chips.com> References: <20261130115152.1797928-1-damon.ding@rock-chips.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Tid: 0aa22c4d35e703a8kunm7cbe3259a518b9 X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlDSB0YVhoaTRpNTx5CGRkdGFYVFA kWGhdVEwETFhoSFyQUDg9ZV1kYEgtZQVlNSlVKTk9VSk9VQ01ZV1kWGg8SFR0UWUFZT0tIVUpLSE pKQk1VSktLVUpCWQY+ DKIM-Signature: a=rsa-sha256; b=iJ27Fd0gHR4FZoRMPGP7NsA0wINIMd/wVABb24+PR4/JxusCDEsdeF6y9GMUpprmlgfJcYVEsrP51sPiPplC2wcHgNeyvDjs1YRblMemK8I1Qr9VdLnO3OnFxstnJIE9zF1xXgIqe9ygvtIbgzdhRSCNemvkI6srKsQpy5REyhk=; s=default; c=relaxed/relaxed; d=rock-chips.com; v=1; bh=gmZHWIOlyYgqDIirQ48xhqOjkBCiYW5Z/q+rVf0qEZU=; h=date:mime-version:subject:message-id:from; When the display pipeline includes a display-connector bridge with hpd-gpios configured, the connector's hotplug status is managed by the display-connector bridge through its GPIO, not by the Analogix DP controller's native HPD. In this configuration, the DP controller's internal HPD polling in analogix_dp_detect_hpd() does not reflect the actual connection state. At attach time, detect whether a downstream bridge provides HPD events (DRM_BRIDGE_OP_HPD) while none of them provides detection (DRM_BRIDGE_OP_DETECT). When found, switch to hpd notify mode: mute the controller's native HPD interrupts and skip their initialization, and use the downstream notifications only as a trigger to probe the sink over the AUX channel, treating it as connected when its DPCD can be read back. The probe result is cached and refreshed by both the notify and the detect paths, so that the reported state always comes from the hardware and the stale echo cannot overwrite it. Suggested-by: Heiko Stuebner Link: https://lore.kernel.org/all/5609825.iZASKD2KPV@diego/ Signed-off-by: Damon Ding --- Changes in v3: - Introduce hpd_notify_mode flag to skip native HPD operations when HPD comes from a downstream bridge. Changes in v4: - Add Tested-by tag. Changes in v5: - Return the connector status directly from analogix_dp_bridge_detect() in the hpd notify mode, to avoid the race where the hpd_notify() echo of the detect path overwrites a newer notification cached by analogix_dp_bridge_notify(). (Sashiko) Changes in v6: - Return the cached connection status instead of connector->status from analogix_dp_bridge_detect(), as connector->status may still be unknown before the first HPD notification or stale after the sysfs state forcing. (Sashiko) - Add Tested-by tag. Changes in v7: - Probe the sink over the AUX channel in the hpd notify mode instead of relying on the notified status, refreshing the cached state in both the .hpd_notify and the detect path. (Sashiko) - Exclude the hpd notify mode from analogix_dp_supports_hpd(), so that neither DRM_BRIDGE_OP_HPD is declared nor the hotplug IRQ is enabled for the muted native interrupts. (Sashiko) - Skip the HPD polling and the AUX probe where they are not needed in the hpd notify mode and the other modes respectively. - Drop the Tested-by tag, as the design of this patch changed significantly in this version. Changes in v8: - Report the cached sink state from analogix_dp_bridge_detect() and probe the sink only in analogix_dp_bridge_notify(), so that each connector probe triggers a single AUX transfer instead of multiple redundant probes, and there is no concurrent update of the cached state. (Sashiko) - Probe the sink directly in analogix_dpaux_wait_hpd_asserted() in the hpd notify mode, so that it no longer polls a value nothing refreshes. (Sashiko) --- .../drm/bridge/analogix/analogix_dp_core.c | 60 ++++++++++++++++++- .../drm/bridge/analogix/analogix_dp_core.h | 2 + .../gpu/drm/bridge/analogix/analogix_dp_reg.c | 21 ++++--- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c index dcec2ac7508a..1223c9288d12 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c @@ -48,7 +48,7 @@ static const bool verify_fast_training; */ static bool analogix_dp_supports_hpd(struct analogix_dp_device *dp) { - if (dp->force_connected_mode || dp->force_hpd) + if (dp->force_connected_mode || dp->force_hpd || dp->hpd_notify_mode) return false; if (dp->hpd_gpiod) @@ -86,10 +86,29 @@ static void analogix_dp_init_dp(struct analogix_dp_device *dp) analogix_dp_init_aux(dp); } +static bool analogix_dp_probe_sink(struct analogix_dp_device *dp) +{ + u8 dpcd_rev = 0; + int ret; + + ret = pm_runtime_resume_and_get(dp->dev); + if (ret) + return false; + + ret = drm_dp_dpcd_readb(&dp->aux, DP_DPCD_REV, &dpcd_rev); + + pm_runtime_put_autosuspend(dp->dev); + + return ret == 1 && dpcd_rev != 0; +} + static int analogix_dp_detect_hpd(struct analogix_dp_device *dp) { int timeout_loop = 0; + if (dp->hpd_notify_mode) + return 0; + while (timeout_loop < DP_TIMEOUT_LOOP_COUNT) { if (analogix_dp_get_plug_in_status(dp) == 0) return 0; @@ -931,6 +950,10 @@ 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->hpd_notify_mode) + return dp->connection_notified ? connector_status_connected : + connector_status_disconnected; + if (dp->force_connected_mode) return connector_status_connected; @@ -963,6 +986,21 @@ static bool analogix_dp_bridge_force_connected(struct analogix_dp_device *dp) return force_connected; } +static bool analogix_dp_has_downstream_hpd(struct analogix_dp_device *dp) +{ + bool hpd_bridge = false; + + drm_for_each_bridge_in_chain_from(dp->bridge.next_bridge, bridge) { + if (bridge->ops & DRM_BRIDGE_OP_DETECT) + return false; + + if (bridge->ops & DRM_BRIDGE_OP_HPD) + hpd_bridge = true; + } + + return hpd_bridge; +} + static int analogix_dp_bridge_attach(struct drm_bridge *bridge, struct drm_encoder *encoder, enum drm_bridge_attach_flags flags) @@ -991,6 +1029,7 @@ static int analogix_dp_bridge_attach(struct drm_bridge *bridge, * accurate hotplug state. */ dp->force_connected_mode = analogix_dp_bridge_force_connected(dp); + dp->hpd_notify_mode = analogix_dp_has_downstream_hpd(dp); } return 0; @@ -1287,6 +1326,17 @@ static void analogix_dp_bridge_atomic_post_disable(struct drm_bridge *bridge, DRM_ERROR("Failed to enable psr (%d)\n", ret); } +static void analogix_dp_bridge_notify(struct drm_bridge *bridge, struct drm_connector *connector, + enum drm_connector_status status) +{ + struct analogix_dp_device *dp = to_dp(bridge); + + if (!dp->hpd_notify_mode) + return; + + dp->connection_notified = analogix_dp_probe_sink(dp); +} + static void analogix_dp_bridge_hpd_enable(struct drm_bridge *bridge) { } @@ -1307,6 +1357,7 @@ static const struct drm_bridge_funcs analogix_dp_bridge_funcs = { .attach = analogix_dp_bridge_attach, .edid_read = analogix_dp_bridge_edid_read, .detect = analogix_dp_bridge_detect, + .hpd_notify = analogix_dp_bridge_notify, .hpd_enable = analogix_dp_bridge_hpd_enable, .hpd_disable = analogix_dp_bridge_hpd_disable, }; @@ -1451,7 +1502,12 @@ static int analogix_dpaux_wait_hpd_asserted(struct drm_dp_aux *aux, unsigned lon if (dp->force_hpd) return 0; - pm_runtime_get_sync(dp->dev); + if (dp->hpd_notify_mode) + return analogix_dp_probe_sink(dp) ? 0 : -ETIMEDOUT; + + ret = pm_runtime_resume_and_get(dp->dev); + if (ret) + return ret; ret = readx_poll_timeout(analogix_dp_get_plug_in_status, dp, val, !val, wait_us / 100, wait_us); diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h index 2ac92b2bac0a..04db14a91074 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.h @@ -171,6 +171,8 @@ struct analogix_dp_device { bool fast_train_enable; bool psr_supported; bool force_connected_mode; + bool hpd_notify_mode; + bool connection_notified; u8 dpcd[DP_RECEIVER_CAP_SIZE]; diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c index 2faeaa835397..f31300867bed 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c @@ -193,7 +193,7 @@ void analogix_dp_config_interrupt(struct analogix_dp_device *dp) writel(0, dp->reg_base + ANALOGIX_DP_COMMON_INT_MASK_2); writel(0, dp->reg_base + ANALOGIX_DP_COMMON_INT_MASK_3); - if (dp->hpd_gpiod) { + if (dp->hpd_gpiod || dp->hpd_notify_mode) { analogix_dp_mute_hpd_interrupt(dp, HPD_IRQ_ALL); return; } @@ -435,7 +435,7 @@ void analogix_dp_init_hpd(struct analogix_dp_device *dp) { u32 reg; - if (dp->hpd_gpiod) + if (dp->hpd_gpiod || dp->hpd_notify_mode) return; analogix_dp_clear_hotplug_interrupts(dp, HPD_IRQ_ALL); @@ -533,16 +533,15 @@ int analogix_dp_get_plug_in_status(struct analogix_dp_device *dp) { u32 reg; - if (dp->hpd_gpiod) { - if (gpiod_get_value(dp->hpd_gpiod)) - return 0; - } else { - reg = readl(dp->reg_base + ANALOGIX_DP_SYS_CTL_3); - if (reg & HPD_STATUS) - return 0; - } + if (dp->hpd_gpiod) + return gpiod_get_value(dp->hpd_gpiod) ? 0 : -EINVAL; + + if (dp->hpd_notify_mode) + return dp->connection_notified ? 0 : -EINVAL; + + reg = readl(dp->reg_base + ANALOGIX_DP_SYS_CTL_3); - return -EINVAL; + return (reg & HPD_STATUS) ? 0 : -EINVAL; } void analogix_dp_enable_sw_function(struct analogix_dp_device *dp) -- 2.34.1