mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/bridge: anx7625: switch to drm_edid_read_custom()
@ 2026-11-16  2:37 Xin Ji
  2026-11-16 11:03 ` Jani Nikula
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Ji @ 2026-11-16  2:37 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, Luca Ceresoli, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: bliang, qwen, fshao, Xin Ji, dri-devel, linux-kernel

From: Xin Ji <xji@analogixsemi.com>

Currently, sp_tx_get_edid_block() only reads the base block extension
count at 0x7e and ignores CTA-861 HF-EEODB overrides in block 1. On
displays using HF-EEODB, the driver only reads 2 blocks, which
drm_edid_valid() then rejects due to the size mismatch.
Switch to drm_edid_read_custom() with a per-block read callback so DRM
core handles block count discovery (including HF-EEODB and >4 blocks)
and validation automatically.

Signed-off-by: Xin Ji <xji@analogixsemi.com>
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 172 +++++-----------------
 drivers/gpu/drm/bridge/analogix/anx7625.h |   4 -
 2 files changed, 33 insertions(+), 143 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index c3af88e14f8b..eb503be005e0 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1022,27 +1022,6 @@ static int sp_tx_aux_rd(struct anx7625_data *ctx, u8 len_cmd)
 	return (ret | wait_aux_op_finish(ctx));
 }
 
-static int sp_tx_get_edid_block(struct anx7625_data *ctx)
-{
-	int c = 0;
-	struct device *dev = ctx->dev;
-
-	sp_tx_aux_wr(ctx, 0x7e);
-	sp_tx_aux_rd(ctx, 0x01);
-	c = anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, AP_AUX_BUFF_START);
-	if (c < 0) {
-		DRM_DEV_ERROR(dev, "IO error : access AUX BUFF.\n");
-		return -EIO;
-	}
-
-	DRM_DEV_DEBUG_DRIVER(dev, " EDID Block = %d\n", c + 1);
-
-	if (c > MAX_EDID_BLOCK)
-		c = 1;
-
-	return c;
-}
-
 static int edid_read(struct anx7625_data *ctx,
 		     u8 offset, u8 *pblock_buf)
 {
@@ -1123,18 +1102,16 @@ static int segments_edid_read(struct anx7625_data *ctx,
 	return ret;
 }
 
-static int sp_tx_edid_read(struct anx7625_data *ctx,
-			   u8 *pedid_blocks_buf)
+static int anx7625_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
 {
+	struct anx7625_data *ctx = data;
 	u8 offset;
-	int edid_pos;
-	int count, blocks_num;
-	u8 pblock_buf[MAX_DPCD_BUFFER_SIZE];
-	u8 i, j;
-	int g_edid_break = 0;
-	int ret;
+	int ret, i;
 	struct device *dev = ctx->dev;
 
+	if (len != EDID_LENGTH || block > 255)
+		return -EINVAL;
+
 	/* Address initial */
 	ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
 				AP_AUX_ADDR_7_0, 0x50);
@@ -1147,85 +1124,18 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
 		return -EIO;
 	}
 
-	blocks_num = sp_tx_get_edid_block(ctx);
-	if (blocks_num < 0)
-		return blocks_num;
-
-	count = 0;
-
-	do {
-		switch (count) {
-		case 0:
-		case 1:
-			for (i = 0; i < 8; i++) {
-				offset = (i + count * 8) * MAX_DPCD_BUFFER_SIZE;
-				g_edid_break = edid_read(ctx, offset,
-							 pblock_buf);
-
-				if (g_edid_break < 0)
-					break;
-
-				memcpy(&pedid_blocks_buf[offset],
-				       pblock_buf,
-				       MAX_DPCD_BUFFER_SIZE);
-			}
-
-			break;
-		case 2:
-			offset = 0x00;
-
-			for (j = 0; j < 8; j++) {
-				edid_pos = (j + count * 8) *
-					MAX_DPCD_BUFFER_SIZE;
-
-				if (g_edid_break == 1)
-					break;
-
-				ret = segments_edid_read(ctx, count / 2,
-							 pblock_buf, offset);
-				if (ret < 0)
-					return ret;
-
-				memcpy(&pedid_blocks_buf[edid_pos],
-				       pblock_buf,
-				       MAX_DPCD_BUFFER_SIZE);
-				offset = offset + 0x10;
-			}
-
-			break;
-		case 3:
-			offset = 0x80;
-
-			for (j = 0; j < 8; j++) {
-				edid_pos = (j + count * 8) *
-					MAX_DPCD_BUFFER_SIZE;
-				if (g_edid_break == 1)
-					break;
-
-				ret = segments_edid_read(ctx, count / 2,
-							 pblock_buf, offset);
-				if (ret < 0)
-					return ret;
-
-				memcpy(&pedid_blocks_buf[edid_pos],
-				       pblock_buf,
-				       MAX_DPCD_BUFFER_SIZE);
-				offset = offset + 0x10;
-			}
-
-			break;
-		default:
-			break;
-		}
-
-		count++;
+	DRM_DEV_DEBUG_DRIVER(dev, "Read EDID block %u, len %zu\n", block, len);
 
-	} while (blocks_num >= count);
+	for (i = 0; i < len; i += MAX_DPCD_BUFFER_SIZE) {
+		offset = (block & 1) * EDID_LENGTH + i;
+		if (block < 2)
+			ret = edid_read(ctx, offset, &buf[i]);
+		else
+			ret = segments_edid_read(ctx, block / 2, &buf[i],
+						 offset);
 
-	/* Check edid data */
-	if (!drm_edid_is_valid((struct edid *)pedid_blocks_buf)) {
-		DRM_DEV_ERROR(dev, "WARNING! edid check fail!\n");
-		return -EINVAL;
+		if (ret < 0)
+			return -EIO;
 	}
 
 	/* Reset aux channel */
@@ -1235,7 +1145,7 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
 		return ret;
 	}
 
-	return (blocks_num + 1);
+	return 0;
 }
 
 static void anx7625_power_on(struct anx7625_data *ctx)
@@ -1958,37 +1868,6 @@ static ssize_t anx7625_aux_transfer(struct drm_dp_aux *aux,
 	return ret;
 }
 
-static const struct drm_edid *anx7625_edid_read(struct anx7625_data *ctx)
-{
-	struct device *dev = ctx->dev;
-	u8 *edid_buf;
-	int edid_num;
-
-	if (ctx->cached_drm_edid)
-		goto out;
-
-	edid_buf = kmalloc(FOUR_BLOCK_SIZE, GFP_KERNEL);
-	if (!edid_buf)
-		return NULL;
-
-	pm_runtime_get_sync(dev);
-	_anx7625_hpd_polling(ctx, 5000 * 100);
-	edid_num = sp_tx_edid_read(ctx, edid_buf);
-	pm_runtime_put_sync(dev);
-
-	if (edid_num < 1) {
-		DRM_DEV_ERROR(dev, "Fail to read EDID: %d\n", edid_num);
-		kfree(edid_buf);
-		return NULL;
-	}
-
-	ctx->cached_drm_edid = drm_edid_alloc(edid_buf, edid_num * ONE_BLOCK_SIZE);
-	kfree(edid_buf);
-
-out:
-	return drm_edid_dup(ctx->cached_drm_edid);
-}
-
 static enum drm_connector_status anx7625_sink_detect(struct anx7625_data *ctx)
 {
 	struct device *dev = ctx->dev;
@@ -2647,10 +2526,25 @@ static const struct drm_edid *anx7625_bridge_edid_read(struct drm_bridge *bridge
 {
 	struct anx7625_data *ctx = bridge_to_anx7625(bridge);
 	struct device *dev = ctx->dev;
+	const struct drm_edid *drm_edid;
 
 	DRM_DEV_DEBUG_DRIVER(dev, "drm bridge get edid\n");
 
-	return anx7625_edid_read(ctx);
+	if (ctx->cached_drm_edid)
+		return drm_edid_dup(ctx->cached_drm_edid);
+
+	pm_runtime_get_sync(dev);
+	_anx7625_hpd_polling(ctx, 5000 * 100);
+	ctx->cached_drm_edid = drm_edid_read_custom(connector,
+						    anx7625_get_edid_block,
+						    ctx);
+	drm_edid = drm_edid_dup(ctx->cached_drm_edid);
+	pm_runtime_put_sync(dev);
+
+	if (!drm_edid)
+		DRM_DEV_ERROR(dev, "Fail to read EDID\n");
+
+	return drm_edid;
 }
 
 static void anx7625_bridge_hpd_enable(struct drm_bridge *bridge)
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 957d234ec07c..55615ad274f2 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -424,10 +424,6 @@ enum audio_wd_len {
 
 #define MAX_DPCD_BUFFER_SIZE	16
 
-#define ONE_BLOCK_SIZE      128
-#define FOUR_BLOCK_SIZE     (128 * 4)
-
-#define MAX_EDID_BLOCK	3
 #define EDID_TRY_CNT	3
 #define SUPPORT_PIXEL_CLOCK	300000
 
-- 
2.25.1


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

end of thread, other threads:[~2026-11-16 11:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  2:37 [PATCH] drm/bridge: anx7625: switch to drm_edid_read_custom() Xin Ji
2026-11-16 11:03 ` Jani Nikula
2026-11-16 11:38   ` Xin Ji

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®