From: Baihan Li <libaihan@huawei.com>
The issue is that drm_connector_helper_detect_from_ddc() returns wrong
status when plugging or unplugging the monitor. Use HPD pin status in
DP's detect_ctx() for real physcal monitor in/out, and implementation
a complete DP detection including read DPCD, check if it's a branch
device and its sink count for different situations.
Fixes: 3c7623fb5bb6 ("drm/hisilicon/hibmc: Enable this hot plug detect of irq feature")
Signed-off-by: Baihan Li <libaihan@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
---
ChangeLog:
v6 -> v7:
- add the check about branch devices, suggested by Dmitry Baryshkov.
v5 -> v6:
- use HPD status in DP detect_ctx(), suggested by Dmitry Baryshkov.
v4 -> v5:
- fix the commit message and DP detect_ctx(), suggested by Dmitry Baryshkov.
---
drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h | 3 ++
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c | 12 +++++++
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h | 6 ++++
drivers/gpu/drm/hisilicon/hibmc/dp/dp_reg.h | 3 ++
.../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c | 34 +++++++++++++++++--
5 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
index 4add05c7f161..7954a883435c 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
@@ -40,6 +40,9 @@ struct hibmc_dp_dev {
struct mutex lock; /* protects concurrent RW in hibmc_dp_reg_write_field() */
struct hibmc_dp_link link;
u8 dpcd[DP_RECEIVER_CAP_SIZE];
+ struct drm_dp_desc desc;
+ bool is_branch;
+ int hpd_status;
void __iomem *serdes_base;
};
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
index 8f0daec7d174..bd3d73075629 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
@@ -2,6 +2,7 @@
// Copyright (c) 2024 Hisilicon Limited.
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/delay.h>
#include "dp_config.h"
#include "dp_comm.h"
@@ -305,3 +306,14 @@ void hibmc_dp_set_cbar(struct hibmc_dp *dp, const struct hibmc_dp_cbar_cfg *cfg)
hibmc_dp_reg_write_field(dp_dev, HIBMC_DP_COLOR_BAR_CTRL, BIT(0), cfg->enable);
writel(HIBMC_DP_SYNC_EN_MASK, dp_dev->base + HIBMC_DP_TIMING_SYNC_CTRL);
}
+
+void hibmc_dp_update_hpd_status(struct hibmc_dp *dp)
+{
+ int status;
+
+ readl_poll_timeout(dp->dp_dev->base + HIBMC_DP_HPD_STATUS, status,
+ FIELD_GET(HIBMC_DP_HPD_CUR_STATE, status) != dp->dp_dev->hpd_status,
+ 1000, 100000); /* DP spec says 100ms */
+
+ dp->dp_dev->hpd_status = FIELD_GET(HIBMC_DP_HPD_CUR_STATE, status);
+}
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
index 665f5b166dfb..1e2214aece6a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
@@ -14,6 +14,11 @@
struct hibmc_dp_dev;
+enum hibmc_hpd_status {
+ HIBMC_HPD_OUT,
+ HIBMC_HPD_IN,
+};
+
enum hibmc_dp_cbar_pattern {
CBAR_COLOR_BAR,
CBAR_WHITE,
@@ -60,5 +65,6 @@ void hibmc_dp_reset_link(struct hibmc_dp *dp);
void hibmc_dp_hpd_cfg(struct hibmc_dp *dp);
void hibmc_dp_enable_int(struct hibmc_dp *dp);
void hibmc_dp_disable_int(struct hibmc_dp *dp);
+void hibmc_dp_update_hpd_status(struct hibmc_dp *dp);
#endif
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_reg.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_reg.h
index 394b1e933c3a..64306abcd986 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_reg.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_reg.h
@@ -24,6 +24,9 @@
#define HIBMC_DP_CFG_AUX_READY_DATA_BYTE GENMASK(16, 12)
#define HIBMC_DP_CFG_AUX GENMASK(24, 17)
+#define HIBMC_DP_HPD_STATUS 0x98
+#define HIBMC_DP_HPD_CUR_STATE GENMASK(7, 4)
+
#define HIBMC_DP_PHYIF_CTRL0 0xa0
#define HIBMC_DP_CFG_SCRAMBLE_EN BIT(0)
#define HIBMC_DP_CFG_PAT_SEL GENMASK(7, 4)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
index d06832e62e96..6792cd0b64b2 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
@@ -12,6 +12,7 @@
#include "hibmc_drm_drv.h"
#include "dp/dp_hw.h"
+#include "dp/dp_comm.h"
#define DP_MASKED_SINK_HPD_PLUG_INT BIT(2)
@@ -34,9 +35,36 @@ static int hibmc_dp_connector_get_modes(struct drm_connector *connector)
static int hibmc_dp_detect(struct drm_connector *connector,
struct drm_modeset_acquire_ctx *ctx, bool force)
{
- mdelay(200);
+ struct hibmc_dp *dp = to_hibmc_dp(connector);
+ struct hibmc_dp_dev *dp_dev = dp->dp_dev;
+ int ret;
+
+ if (dp->irq_status) {
+ if (dp_dev->hpd_status != HIBMC_HPD_IN)
+ return connector_status_disconnected;
+ }
+
+ ret = drm_dp_read_dpcd_caps(dp_dev->aux, dp_dev->dpcd);
+ if (ret)
+ return connector_status_disconnected;
+
+ dp_dev->is_branch = drm_dp_is_branch(dp_dev->dpcd);
- return drm_connector_helper_detect_from_ddc(connector, ctx, force);
+ ret = drm_dp_read_desc(dp_dev->aux, &dp_dev->desc, dp_dev->is_branch);
+ if (ret)
+ return connector_status_disconnected;
+
+ if (!dp_dev->is_branch)
+ return connector_status_connected;
+
+ if (drm_dp_read_sink_count_cap(connector, dp_dev->dpcd, &dp_dev->desc) &&
+ dp_dev->dpcd[DP_DOWNSTREAM_PORT_0] & DP_DS_PORT_HPD) {
+ ret = drm_dp_read_sink_count(dp_dev->aux);
+ if (ret > 0)
+ return connector_status_connected;
+ }
+
+ return connector_status_disconnected;
}
static const struct drm_connector_helper_funcs hibmc_dp_conn_helper_funcs = {
@@ -128,6 +156,8 @@ irqreturn_t hibmc_dp_hpd_isr(int irq, void *arg)
hibmc_dp_reset_link(&priv->dp);
}
+ hibmc_dp_update_hpd_status(&priv->dp);
+
if (dev->registered)
drm_connector_helper_hpd_irq_event(&priv->dp.connector);
--
2.33.0
Hi Yongbang, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-misc/drm-misc-next] [also build test WARNING on linus/master v6.17-rc7 next-20250923] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Yongbang-Shi/drm-hisilicon-hibmc-fix-dp-probabilistical-detect-errors-after-HPD-irq/20250923-211652 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20250923130411.2522339-2-shiyongbang%40huawei.com patch subject: [PATCH v7 drm-dp 1/4] drm/hisilicon/hibmc: fix dp probabilistical detect errors after HPD irq config: s390-randconfig-001-20250924 (https://download.01.org/0day-ci/archive/20250924/202509241625.o4mNleVb-lkp@intel.com/config) compiler: s390-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250924/202509241625.o4mNleVb-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202509241625.o4mNleVb-lkp@intel.com/ All warnings (new ones prefixed by >>): drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c: In function 'hibmc_dp_detect': >> drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c:61:18: warning: array subscript 128 is above array bounds of 'u8[15]' {aka 'unsigned char[15]'} [-Warray-bounds] dp_dev->dpcd[DP_DOWNSTREAM_PORT_0] & DP_DS_PORT_HPD) { ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ vim +61 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c 34 35 static int hibmc_dp_detect(struct drm_connector *connector, 36 struct drm_modeset_acquire_ctx *ctx, bool force) 37 { 38 struct hibmc_dp *dp = to_hibmc_dp(connector); 39 struct hibmc_dp_dev *dp_dev = dp->dp_dev; 40 int ret; 41 42 if (dp->irq_status) { 43 if (dp_dev->hpd_status != HIBMC_HPD_IN) 44 return connector_status_disconnected; 45 } 46 47 ret = drm_dp_read_dpcd_caps(dp_dev->aux, dp_dev->dpcd); 48 if (ret) 49 return connector_status_disconnected; 50 51 dp_dev->is_branch = drm_dp_is_branch(dp_dev->dpcd); 52 53 ret = drm_dp_read_desc(dp_dev->aux, &dp_dev->desc, dp_dev->is_branch); 54 if (ret) 55 return connector_status_disconnected; 56 57 if (!dp_dev->is_branch) 58 return connector_status_connected; 59 60 if (drm_dp_read_sink_count_cap(connector, dp_dev->dpcd, &dp_dev->desc) && > 61 dp_dev->dpcd[DP_DOWNSTREAM_PORT_0] & DP_DS_PORT_HPD) { 62 ret = drm_dp_read_sink_count(dp_dev->aux); 63 if (ret > 0) 64 return connector_status_connected; 65 } 66 67 return connector_status_disconnected; 68 } 69 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.