public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver
@ 2026-03-12  7:41 Yongbang Shi
  2026-03-12  7:41 ` [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect() Yongbang Shi
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Yongbang Shi @ 2026-03-12  7:41 UTC (permalink / raw)
  To: tzimmermann, tiantao6, xinliang.liu, maarten.lankhorst, mripard,
	airlied, daniel, kong.kongxinwei, dmitry.baryshkov
  Cc: liangjian010, chenjianmin, fengsheng5, shiyongbang, helin52,
	shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

There are some bugfix for hibmc-drm driver.

Lin He (4):
  drm/hisilicon/hibmc: add updating link cap in DP detect()
  drm/hisilicon/hibmc: fix no showing when no connectors connected
  drm/hisilicon/hibmc: move display contrl config to hibmc_probe()
  drm/hisilicon/hibmc: use clock to look up the PLL value

 drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h  |  1 +
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h    |  1 +
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c  |  2 +-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c    | 80 +++++++++++--------
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c    | 35 +++++---
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 14 ++++
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  1 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c  | 74 ++++++++---------
 8 files changed, 123 insertions(+), 85 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect()
  2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
@ 2026-03-12  7:41 ` Yongbang Shi
  2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 2/4] drm/hisilicon/hibmc: fix no showing when no connectors connected Yongbang Shi
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Yongbang Shi @ 2026-03-12  7:41 UTC (permalink / raw)
  To: tzimmermann, tiantao6, xinliang.liu, maarten.lankhorst, mripard,
	airlied, daniel, kong.kongxinwei, dmitry.baryshkov
  Cc: liangjian010, chenjianmin, fengsheng5, shiyongbang, helin52,
	shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

In the past, the link cap is updated in link training at encoder enable
stage, but the hibmc_dp_mode_valid() is called before it, which will use
DP link's rate and lanes. So add the hibmc_dp_update_caps() in
hibmc_dp_update_caps() to avoid some potential risks.

Fixes: e6c7c59da494 ("drm/hisilicon/hibmc: add dp mode valid check")
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
Reviewed-by: Tao Tian <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h   | 1 +
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c   | 2 +-
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
index f9ee7ebfec55..f53dac256ee0 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
@@ -69,5 +69,6 @@ int hibmc_dp_link_training(struct hibmc_dp_dev *dp);
 int hibmc_dp_serdes_init(struct hibmc_dp_dev *dp);
 int hibmc_dp_serdes_rate_switch(u8 rate, struct hibmc_dp_dev *dp);
 int hibmc_dp_serdes_set_tx_cfg(struct hibmc_dp_dev *dp, u8 train_set[HIBMC_DP_LANE_NUM_MAX]);
+void hibmc_dp_update_caps(struct hibmc_dp_dev *dp);
 
 #endif
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c
index 0726cb5b736e..8c53f16db516 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_link.c
@@ -325,7 +325,7 @@ static int hibmc_dp_link_downgrade_training_eq(struct hibmc_dp_dev *dp)
 	return hibmc_dp_link_reduce_rate(dp);
 }
 
-static void hibmc_dp_update_caps(struct hibmc_dp_dev *dp)
+void hibmc_dp_update_caps(struct hibmc_dp_dev *dp)
 {
 	dp->link.cap.link_rate = dp->dpcd[DP_MAX_LINK_RATE];
 	if (dp->link.cap.link_rate > DP_LINK_BW_8_1 || !dp->link.cap.link_rate)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
index 616821e3c933..35dff7bfbf76 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
@@ -41,6 +41,8 @@ static bool hibmc_dp_get_dpcd(struct hibmc_dp_dev *dp_dev)
 	if (ret)
 		return false;
 
+	hibmc_dp_update_caps(dp_dev);
+
 	dp_dev->is_branch = drm_dp_is_branch(dp_dev->dpcd);
 
 	ret = drm_dp_read_desc(dp_dev->aux, &dp_dev->desc, dp_dev->is_branch);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH RESEND drm-dp 2/4] drm/hisilicon/hibmc: fix no showing when no connectors connected
  2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
  2026-03-12  7:41 ` [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect() Yongbang Shi
@ 2026-03-12  7:42 ` Yongbang Shi
  2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 3/4] drm/hisilicon/hibmc: move display contrl config to hibmc_probe() Yongbang Shi
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Yongbang Shi @ 2026-03-12  7:42 UTC (permalink / raw)
  To: tzimmermann, tiantao6, xinliang.liu, maarten.lankhorst, mripard,
	airlied, daniel, kong.kongxinwei, dmitry.baryshkov
  Cc: liangjian010, chenjianmin, fengsheng5, shiyongbang, helin52,
	shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

Our chip support KVM over IP feature, so hibmc driver need to support
displaying without any connectors plugged in. If no connectors are
connected, the vdac connector status should be set to 'connected' to
ensure proper KVM display functionality. Additionally, for
previous-generation products that may lack hardware link support and
thus cannot detect the monitor, the same approach should be applied
to ensure VGA display functionality. Add phys_state in the struct of
dp and vdac to check all physical outputs.

For get_modes: using BMC modes for connector if no display is attached to
phys VGA cable, otherwise use EDID modes by drm_connector_helper_get_modes,
because KVM doesn't provide EDID reads.

Fixes: 4c962bc929f1 ("drm/hisilicon/hibmc: Add vga connector detect functions")
Reported-by: Thomas Zimmermann <tzimmermann@suse.de>
Closes: https://lore.kernel.org/all/0eb5c509-2724-4c57-87ad-74e4270d5a5a@suse.de/
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
Reviewed-by: Tao Tian <tiantao6@hisilicon.com>
---
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h    |  1 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c    | 33 ++++++++----
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  1 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c  | 52 ++++++++++++-------
 4 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
index 31316fe1ea8d..dfaeabd05d46 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
@@ -55,6 +55,7 @@ struct hibmc_dp {
 	struct drm_dp_aux aux;
 	struct hibmc_dp_cbar_cfg cfg;
 	u32 irq_status;
+	int phys_state;
 };
 
 int hibmc_dp_hw_init(struct hibmc_dp *dp);
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
index 35dff7bfbf76..8fe2eb51a0b3 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
@@ -61,27 +61,38 @@ static int hibmc_dp_detect(struct drm_connector *connector,
 {
 	struct hibmc_dp *dp = to_hibmc_dp(connector);
 	struct hibmc_dp_dev *dp_dev = dp->dp_dev;
-	int ret;
+	int ret = connector_status_disconnected;
 
 	if (dp->irq_status) {
-		if (dp_dev->hpd_status != HIBMC_HPD_IN)
-			return connector_status_disconnected;
+		if (dp_dev->hpd_status != HIBMC_HPD_IN) {
+			ret = connector_status_disconnected;
+			goto exit;
+		}
 	}
 
-	if (!hibmc_dp_get_dpcd(dp_dev))
-		return connector_status_disconnected;
+	if (!hibmc_dp_get_dpcd(dp_dev)) {
+		ret = connector_status_disconnected;
+		goto exit;
+	}
 
-	if (!dp_dev->is_branch)
-		return connector_status_connected;
+	if (!dp_dev->is_branch) {
+		ret = connector_status_connected;
+		goto exit;
+	}
 
 	if (drm_dp_read_sink_count_cap(connector, dp_dev->dpcd, &dp_dev->desc) &&
 	    dp_dev->downstream_ports[0] & DP_DS_PORT_HPD) {
 		ret = drm_dp_read_sink_count(dp_dev->aux);
-		if (ret > 0)
-			return connector_status_connected;
+		if (ret > 0) {
+			ret = connector_status_connected;
+			goto exit;
+		}
 	}
 
-	return connector_status_disconnected;
+exit:
+	dp->phys_state = ret;
+
+	return ret;
 }
 
 static int hibmc_dp_mode_valid(struct drm_connector *connector,
@@ -243,5 +254,7 @@ int hibmc_dp_init(struct hibmc_drm_private *priv)
 
 	connector->polled = DRM_CONNECTOR_POLL_HPD;
 
+	dp->phys_state = connector_status_disconnected;
+
 	return 0;
 }
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index ca8502e2760c..6abb49b5107b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -31,6 +31,7 @@ struct hibmc_vdac {
 	struct drm_connector connector;
 	struct i2c_adapter adapter;
 	struct i2c_algo_bit_data bit_data;
+	int phys_state;
 };
 
 struct hibmc_drm_private {
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
index 841e81f47b68..502494cba541 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -25,27 +25,19 @@
 static int hibmc_connector_get_modes(struct drm_connector *connector)
 {
 	struct hibmc_vdac *vdac = to_hibmc_vdac(connector);
-	const struct drm_edid *drm_edid;
-	int count;
+	int count = 0;
 
-	drm_edid = drm_edid_read_ddc(connector, &vdac->adapter);
+	if (vdac->phys_state == connector_status_connected)
+		count = drm_connector_helper_get_modes(connector);
 
-	drm_edid_connector_update(connector, drm_edid);
-
-	if (drm_edid) {
-		count = drm_edid_connector_add_modes(connector);
-		if (count)
-			goto out;
+	if (count <= 0) {
+		drm_edid_connector_update(connector, NULL);
+		count = drm_add_modes_noedid(connector,
+					     connector->dev->mode_config.max_width,
+					     connector->dev->mode_config.max_height);
+		drm_set_preferred_mode(connector, 1024, 768);
 	}
 
-	count = drm_add_modes_noedid(connector,
-				     connector->dev->mode_config.max_width,
-				     connector->dev->mode_config.max_height);
-	drm_set_preferred_mode(connector, 1024, 768);
-
-out:
-	drm_edid_free(drm_edid);
-
 	return count;
 }
 
@@ -57,10 +49,32 @@ static void hibmc_connector_destroy(struct drm_connector *connector)
 	drm_connector_cleanup(connector);
 }
 
+static int hibmc_vdac_detect(struct drm_connector *connector,
+			     struct drm_modeset_acquire_ctx *ctx,
+			     bool force)
+{
+	struct hibmc_drm_private *priv = to_hibmc_drm_private(connector->dev);
+	struct hibmc_vdac *vdac = to_hibmc_vdac(connector);
+
+	vdac->phys_state = drm_connector_helper_detect_from_ddc(connector,
+								ctx, force);
+
+	/* If the DP connectors are disconnected, the hibmc_vdac_detect function
+	 * must return a connected state to ensure KVM display functionality.
+	 * Additionally, for previous-generation products that may lack hardware
+	 * link support and thus cannot detect the monitor, hibmc_vdac_detect
+	 * should also return a connected state.
+	 */
+	if (priv->dp.phys_state != connector_status_connected)
+		return connector_status_connected;
+
+	return vdac->phys_state;
+}
+
 static const struct drm_connector_helper_funcs
 	hibmc_connector_helper_funcs = {
 	.get_modes = hibmc_connector_get_modes,
-	.detect_ctx = drm_connector_helper_detect_from_ddc,
+	.detect_ctx = hibmc_vdac_detect,
 };
 
 static const struct drm_connector_funcs hibmc_connector_funcs = {
@@ -130,6 +144,8 @@ int hibmc_vdac_init(struct hibmc_drm_private *priv)
 
 	connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
 
+	vdac->phys_state = connector_status_connected;
+
 	return 0;
 
 err:
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH RESEND drm-dp 3/4] drm/hisilicon/hibmc: move display contrl config to hibmc_probe()
  2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
  2026-03-12  7:41 ` [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect() Yongbang Shi
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 2/4] drm/hisilicon/hibmc: fix no showing when no connectors connected Yongbang Shi
@ 2026-03-12  7:42 ` Yongbang Shi
  2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 4/4] drm/hisilicon/hibmc: use clock to look up the PLL value Yongbang Shi
  2026-03-13  4:23 ` Claude review: Fix some bugs in the hibmc driver Claude Code Review Bot
  4 siblings, 1 reply; 10+ messages in thread
From: Yongbang Shi @ 2026-03-12  7:42 UTC (permalink / raw)
  To: tzimmermann, tiantao6, xinliang.liu, maarten.lankhorst, mripard,
	airlied, daniel, kong.kongxinwei, dmitry.baryshkov
  Cc: liangjian010, chenjianmin, fengsheng5, shiyongbang, helin52,
	shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

If there's no VGA output, this encoder modeset won't be called, which
will cause displaying data from GPU being cut off. It's actually a
common display config for DP and VGA, so move the vdac encoder modeset
to driver load stage.

Fixes: 5294967f4ae4 ("drm/hisilicon/hibmc: Add support for VDAC")
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
Reviewed-by: Tao Tian <tiantao6@hisilicon.com>
---
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 14 ++++++++++++
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c  | 22 -------------------
 2 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 289304500ab0..c7ce44a5370b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -214,6 +214,18 @@ void hibmc_set_current_gate(struct hibmc_drm_private *priv, unsigned int gate)
 	writel(gate, mmio + gate_reg);
 }
 
+static void hibmc_display_ctrl(struct hibmc_drm_private *priv)
+{
+	u32 reg;
+
+	reg = readl(priv->mmio + HIBMC_DISPLAY_CONTROL_HISILE);
+	reg |= HIBMC_DISPLAY_CONTROL_FPVDDEN(1);
+	reg |= HIBMC_DISPLAY_CONTROL_PANELDATE(1);
+	reg |= HIBMC_DISPLAY_CONTROL_FPEN(1);
+	reg |= HIBMC_DISPLAY_CONTROL_VBIASEN(1);
+	writel(reg, priv->mmio + HIBMC_DISPLAY_CONTROL_HISILE);
+}
+
 static void hibmc_hw_config(struct hibmc_drm_private *priv)
 {
 	u32 reg;
@@ -245,6 +257,8 @@ static void hibmc_hw_config(struct hibmc_drm_private *priv)
 	reg |= HIBMC_MSCCTL_LOCALMEM_RESET(1);
 
 	writel(reg, priv->mmio + HIBMC_MISC_CTRL);
+
+	hibmc_display_ctrl(priv);
 }
 
 static int hibmc_hw_map(struct hibmc_drm_private *priv)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
index 502494cba541..b02e9753112b 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c
@@ -85,26 +85,6 @@ static const struct drm_connector_funcs hibmc_connector_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 };
 
-static void hibmc_encoder_mode_set(struct drm_encoder *encoder,
-				   struct drm_display_mode *mode,
-				   struct drm_display_mode *adj_mode)
-{
-	u32 reg;
-	struct drm_device *dev = encoder->dev;
-	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
-
-	reg = readl(priv->mmio + HIBMC_DISPLAY_CONTROL_HISILE);
-	reg |= HIBMC_DISPLAY_CONTROL_FPVDDEN(1);
-	reg |= HIBMC_DISPLAY_CONTROL_PANELDATE(1);
-	reg |= HIBMC_DISPLAY_CONTROL_FPEN(1);
-	reg |= HIBMC_DISPLAY_CONTROL_VBIASEN(1);
-	writel(reg, priv->mmio + HIBMC_DISPLAY_CONTROL_HISILE);
-}
-
-static const struct drm_encoder_helper_funcs hibmc_encoder_helper_funcs = {
-	.mode_set = hibmc_encoder_mode_set,
-};
-
 int hibmc_vdac_init(struct hibmc_drm_private *priv)
 {
 	struct drm_device *dev = &priv->dev;
@@ -127,8 +107,6 @@ int hibmc_vdac_init(struct hibmc_drm_private *priv)
 		goto err;
 	}
 
-	drm_encoder_helper_add(encoder, &hibmc_encoder_helper_funcs);
-
 	ret = drm_connector_init_with_ddc(dev, connector,
 					  &hibmc_connector_funcs,
 					  DRM_MODE_CONNECTOR_VGA,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH RESEND drm-dp 4/4] drm/hisilicon/hibmc: use clock to look up the PLL value
  2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
                   ` (2 preceding siblings ...)
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 3/4] drm/hisilicon/hibmc: move display contrl config to hibmc_probe() Yongbang Shi
@ 2026-03-12  7:42 ` Yongbang Shi
  2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
  2026-03-13  4:23 ` Claude review: Fix some bugs in the hibmc driver Claude Code Review Bot
  4 siblings, 1 reply; 10+ messages in thread
From: Yongbang Shi @ 2026-03-12  7:42 UTC (permalink / raw)
  To: tzimmermann, tiantao6, xinliang.liu, maarten.lankhorst, mripard,
	airlied, daniel, kong.kongxinwei, dmitry.baryshkov
  Cc: liangjian010, chenjianmin, fengsheng5, shiyongbang, helin52,
	shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

In the past, we use width and height to look up our PLL value.
But actually the actual clock check is also necessnary. There are
some resolutions that width and height same, but its clock different.
Add the clock check when using pll_table to determine the PLL value.

Fixes: da52605eea8f ("drm/hisilicon/hibmc: Add support for display engine")
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
Reviewed-by: Tao Tian <tiantao6@hisilicon.com>
---
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c    | 80 +++++++++++--------
 1 file changed, 46 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index 89bed78f1466..8561acbbc3c8 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -22,6 +22,8 @@
 #include "hibmc_drm_drv.h"
 #include "hibmc_drm_regs.h"
 
+#define CLOCK_TOLERANCE 100 /* kHz tolerance */
+
 struct hibmc_display_panel_pll {
 	u64 M;
 	u64 N;
@@ -32,26 +34,43 @@ struct hibmc_display_panel_pll {
 struct hibmc_dislay_pll_config {
 	u64 hdisplay;
 	u64 vdisplay;
+	int clock;
 	u32 pll1_config_value;
 	u32 pll2_config_value;
 };
 
 static const struct hibmc_dislay_pll_config hibmc_pll_table[] = {
-	{640, 480, CRT_PLL1_HS_25MHZ, CRT_PLL2_HS_25MHZ},
-	{800, 600, CRT_PLL1_HS_40MHZ, CRT_PLL2_HS_40MHZ},
-	{1024, 768, CRT_PLL1_HS_65MHZ, CRT_PLL2_HS_65MHZ},
-	{1152, 864, CRT_PLL1_HS_80MHZ_1152, CRT_PLL2_HS_80MHZ},
-	{1280, 768, CRT_PLL1_HS_80MHZ, CRT_PLL2_HS_80MHZ},
-	{1280, 720, CRT_PLL1_HS_74MHZ, CRT_PLL2_HS_74MHZ},
-	{1280, 960, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
-	{1280, 1024, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
-	{1440, 900, CRT_PLL1_HS_106MHZ, CRT_PLL2_HS_106MHZ},
-	{1600, 900, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
-	{1600, 1200, CRT_PLL1_HS_162MHZ, CRT_PLL2_HS_162MHZ},
-	{1920, 1080, CRT_PLL1_HS_148MHZ, CRT_PLL2_HS_148MHZ},
-	{1920, 1200, CRT_PLL1_HS_193MHZ, CRT_PLL2_HS_193MHZ},
+	{640, 480, 25000, CRT_PLL1_HS_25MHZ, CRT_PLL2_HS_25MHZ},
+	{800, 600, 40000, CRT_PLL1_HS_40MHZ, CRT_PLL2_HS_40MHZ},
+	{1024, 768, 65000, CRT_PLL1_HS_65MHZ, CRT_PLL2_HS_65MHZ},
+	{1152, 864, 78750, CRT_PLL1_HS_80MHZ_1152, CRT_PLL2_HS_80MHZ},
+	{1280, 768, 80000, CRT_PLL1_HS_80MHZ, CRT_PLL2_HS_80MHZ},
+	{1280, 720, 74375, CRT_PLL1_HS_74MHZ, CRT_PLL2_HS_74MHZ},
+	{1280, 960, 108000, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
+	{1280, 1024, 108000, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
+	{1440, 900, 105952, CRT_PLL1_HS_106MHZ, CRT_PLL2_HS_106MHZ},
+	{1600, 900, 108000, CRT_PLL1_HS_108MHZ, CRT_PLL2_HS_108MHZ},
+	{1600, 1200, 162500, CRT_PLL1_HS_162MHZ, CRT_PLL2_HS_162MHZ},
+	{1920, 1080, 148750, CRT_PLL1_HS_148MHZ, CRT_PLL2_HS_148MHZ},
+	{1920, 1200, 193750, CRT_PLL1_HS_193MHZ, CRT_PLL2_HS_193MHZ},
 };
 
+static int hibmc_get_best_clock_idx(const struct drm_display_mode *mode)
+{
+	int i, diff;
+
+	for (i = 0; i < ARRAY_SIZE(hibmc_pll_table); i++) {
+		if (hibmc_pll_table[i].hdisplay == mode->hdisplay &&
+		    hibmc_pll_table[i].vdisplay == mode->vdisplay) {
+			diff = abs(mode->clock - hibmc_pll_table[i].clock);
+			if (diff < mode->clock / 100) /* tolerance 1/100 */
+				return i;
+		}
+	}
+
+	return -EOPNOTSUPP;
+}
+
 static int hibmc_plane_atomic_check(struct drm_plane *plane,
 				    struct drm_atomic_state *state)
 {
@@ -214,17 +233,13 @@ static enum drm_mode_status
 hibmc_crtc_mode_valid(struct drm_crtc *crtc,
 		      const struct drm_display_mode *mode)
 {
-	size_t i = 0;
 	int vrefresh = drm_mode_vrefresh(mode);
 
 	if (vrefresh < 59 || vrefresh > 61)
 		return MODE_NOCLOCK;
 
-	for (i = 0; i < ARRAY_SIZE(hibmc_pll_table); i++) {
-		if (hibmc_pll_table[i].hdisplay == mode->hdisplay &&
-		    hibmc_pll_table[i].vdisplay == mode->vdisplay)
-			return MODE_OK;
-	}
+	if (hibmc_get_best_clock_idx(mode) >= 0)
+		return MODE_OK;
 
 	return MODE_BAD;
 }
@@ -281,23 +296,20 @@ static void set_vclock_hisilicon(struct drm_device *dev, u64 pll)
 	writel(val, priv->mmio + CRT_PLL1_HS);
 }
 
-static void get_pll_config(u64 x, u64 y, u32 *pll1, u32 *pll2)
+static void get_pll_config(struct drm_display_mode *mode, u32 *pll1, u32 *pll2)
 {
-	size_t i;
-	size_t count = ARRAY_SIZE(hibmc_pll_table);
-
-	for (i = 0; i < count; i++) {
-		if (hibmc_pll_table[i].hdisplay == x &&
-		    hibmc_pll_table[i].vdisplay == y) {
-			*pll1 = hibmc_pll_table[i].pll1_config_value;
-			*pll2 = hibmc_pll_table[i].pll2_config_value;
-			return;
-		}
+	int idx;
+
+	idx = hibmc_get_best_clock_idx(mode);
+	if (idx < 0) {
+		/* if found none, we use default value */
+		*pll1 = CRT_PLL1_HS_25MHZ;
+		*pll2 = CRT_PLL2_HS_25MHZ;
+		return;
 	}
 
-	/* if found none, we use default value */
-	*pll1 = CRT_PLL1_HS_25MHZ;
-	*pll2 = CRT_PLL2_HS_25MHZ;
+	*pll1 = hibmc_pll_table[idx].pll1_config_value;
+	*pll2 = hibmc_pll_table[idx].pll2_config_value;
 }
 
 /*
@@ -319,7 +331,7 @@ static u32 display_ctrl_adjust(struct drm_device *dev,
 	x = mode->hdisplay;
 	y = mode->vdisplay;
 
-	get_pll_config(x, y, &pll1, &pll2);
+	get_pll_config(mode, &pll1, &pll2);
 	writel(pll2, priv->mmio + CRT_PLL2_HS);
 	set_vclock_hisilicon(dev, pll1);
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Claude review: Fix some bugs in the hibmc driver
  2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
                   ` (3 preceding siblings ...)
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 4/4] drm/hisilicon/hibmc: use clock to look up the PLL value Yongbang Shi
@ 2026-03-13  4:23 ` Claude Code Review Bot
  4 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-03-13  4:23 UTC (permalink / raw)
  To: dri-devel-reviews

Overall Series Review

Subject: Fix some bugs in the hibmc driver
Author: Yongbang Shi <shiyongbang@huawei.com>
Patches: 5
Reviewed: 2026-03-13T14:23:18.053108

---

This is a 4-patch bug-fix series for the hibmc DRM driver from Huawei. The patches address: (1) updating DP link capabilities earlier so mode validation works correctly, (2) ensuring display works when no connectors are physically attached (KVM-over-IP use case), (3) moving display control register configuration to probe time so it's not gated on VGA modeset, and (4) adding clock-based PLL table lookup instead of relying solely on resolution. The changes are reasonable and well-motivated, but there are several issues worth addressing.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Claude review: drm/hisilicon/hibmc: add updating link cap in DP detect()
  2026-03-12  7:41 ` [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect() Yongbang Shi
@ 2026-03-13  4:23   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-03-13  4:23 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Commit message issue:** The commit message says "So add the hibmc_dp_update_caps() in hibmc_dp_update_caps()" which is a copy-paste error — it should say something like "add hibmc_dp_update_caps() in hibmc_dp_get_dpcd()".

The code change itself is straightforward and correct — `hibmc_dp_update_caps()` was `static` and is now exported, and it's called in `hibmc_dp_get_dpcd()` after reading DPCD caps, which runs during `detect()`. This ensures `link.cap.link_rate` and `link.cap.lanes` are populated before `hibmc_dp_mode_valid()` uses them.

No functional concerns with the code.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Claude review: drm/hisilicon/hibmc: fix no showing when no connectors connected
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 2/4] drm/hisilicon/hibmc: fix no showing when no connectors connected Yongbang Shi
@ 2026-03-13  4:23   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-03-13  4:23 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

This is the most complex patch in the series and has several issues:

**1. Comment style violation:** The multi-line comment in `hibmc_vdac_detect()` uses the wrong style for the kernel:
```c
	/* If the DP connectors are disconnected, the hibmc_vdac_detect function
	 * must return a connected state to ensure KVM display functionality.
```
This should start with `/*` on its own line per kernel coding style (though this is a minor nit — some subsystems accept this style).

**2. Race / ordering dependency between DP and VDAC detect:** `hibmc_vdac_detect()` reads `priv->dp.phys_state` to decide whether to force VGA connected. But there's no guarantee about the order in which connectors are polled. If the VGA connector is polled/detected *before* the DP connector, `dp.phys_state` could still hold a stale value from a previous cycle (or the initial `connector_status_disconnected`). On initial boot with DP connected, `dp.phys_state` starts as `connector_status_disconnected`, so the first VGA detect would force-return connected even if DP is actually plugged in but not yet detected.

**3. `drm_connector_helper_get_modes()` usage:** The `get_modes` callback now calls `drm_connector_helper_get_modes()` which reads the EDID via the connector's DDC adapter. The old code explicitly used `drm_edid_read_ddc(connector, &vdac->adapter)`. This should work since the connector was initialized with `drm_connector_init_with_ddc(..., &vdac->adapter)`, but it's worth confirming that `drm_connector_helper_get_modes` will use this DDC adapter path.

**4. Clearing EDID when falling back:** The `drm_edid_connector_update(connector, NULL)` call when falling back to noedid modes is good — it clears stale EDID data.

**5. `drm_dp_read_sink_count` return value reuse:** In `hibmc_dp_detect()`, the variable `ret` is reused to hold both the `drm_dp_read_sink_count()` return value (which can be a negative error or a positive count) and the connector status enum. The `goto exit` path then assigns this to `dp->phys_state`. If `drm_dp_read_sink_count()` returns a negative error, the code falls through to `exit:` with `ret` set to a negative errno, which gets stored in `dp->phys_state`. While the original code had the same issue (it would return `connector_status_disconnected` by falling through), the new code stores a negative errno in `phys_state`, which is neither `connector_status_connected` nor `connector_status_disconnected`. This is a bug — the error case from `drm_dp_read_sink_count` should explicitly set `ret = connector_status_disconnected` before the goto.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Claude review: drm/hisilicon/hibmc: move display contrl config to hibmc_probe()
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 3/4] drm/hisilicon/hibmc: move display contrl config to hibmc_probe() Yongbang Shi
@ 2026-03-13  4:23   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-03-13  4:23 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Typo in subject:** "contrl" should be "control".

**Subject is slightly misleading:** The code actually moves the display control config into `hibmc_hw_config()`, which is called from `hibmc_hw_init()`, which is called from `hibmc_probe()`. The subject implies it's directly in `hibmc_probe()` itself.

The code change is clean — it moves the four register bit-sets from the VDAC encoder `mode_set` callback into `hibmc_hw_config()`. This ensures the display control bits are configured during driver initialization regardless of whether VGA output is active. The fix makes sense for the DP-only scenario described.

No functional issues with the code itself.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Claude review: drm/hisilicon/hibmc: use clock to look up the PLL value
  2026-03-12  7:42 ` [PATCH RESEND drm-dp 4/4] drm/hisilicon/hibmc: use clock to look up the PLL value Yongbang Shi
@ 2026-03-13  4:23   ` Claude Code Review Bot
  0 siblings, 0 replies; 10+ messages in thread
From: Claude Code Review Bot @ 2026-03-13  4:23 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**1. Unused `CLOCK_TOLERANCE` define:** The patch adds `#define CLOCK_TOLERANCE 100` but never uses it. The tolerance check in `hibmc_get_best_clock_idx()` uses `mode->clock / 100` (1% tolerance) instead. The `CLOCK_TOLERANCE` define should either be removed or actually used.

**2. Tolerance logic for low clocks:** The expression `diff < mode->clock / 100` uses integer division. For the 25000 kHz entry, the tolerance is 250 kHz which is fine. But if a mode somehow had a very low clock, the tolerance could round to 0 due to integer division, making the match impossible. Not a practical problem given the table entries, but `<= 0` should be guarded (e.g., `mode->clock / 100` should be at least 1). 

**3. `get_pll_config` now takes non-const mode pointer:**
```c
-static void get_pll_config(u64 x, u64 y, u32 *pll1, u32 *pll2)
+static void get_pll_config(struct drm_display_mode *mode, u32 *pll1, u32 *pll2)
```
The `mode` parameter should be `const struct drm_display_mode *mode` since it's not modified. The `hibmc_get_best_clock_idx` already takes a `const` pointer, so this is just a missed annotation on `get_pll_config`.

**4. Good refactoring:** Consolidating the table lookup into `hibmc_get_best_clock_idx()` and reusing it in both `hibmc_crtc_mode_valid()` and `get_pll_config()` is a nice cleanup that eliminates code duplication.

**5. `hibmc_dislay_pll_config` typo:** The struct name `hibmc_dislay_pll_config` has a typo — it should be `hibmc_display_pll_config`. This is pre-existing and not introduced by this patch, but could be cleaned up while touching this code.

---
Generated by Claude Code Patch Reviewer

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-13  4:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12  7:41 [PATCH RESEND drm-dp 0/4] Fix some bugs in the hibmc driver Yongbang Shi
2026-03-12  7:41 ` [PATCH RESEND drm-dp 1/4] drm/hisilicon/hibmc: add updating link cap in DP detect() Yongbang Shi
2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
2026-03-12  7:42 ` [PATCH RESEND drm-dp 2/4] drm/hisilicon/hibmc: fix no showing when no connectors connected Yongbang Shi
2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
2026-03-12  7:42 ` [PATCH RESEND drm-dp 3/4] drm/hisilicon/hibmc: move display contrl config to hibmc_probe() Yongbang Shi
2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
2026-03-12  7:42 ` [PATCH RESEND drm-dp 4/4] drm/hisilicon/hibmc: use clock to look up the PLL value Yongbang Shi
2026-03-13  4:23   ` Claude review: " Claude Code Review Bot
2026-03-13  4:23 ` Claude review: Fix some bugs in the hibmc driver Claude Code Review Bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox