All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] drm/bridge: lt9611uxc: support displays with up to 4 EDID blocks
@ 2026-11-22  3:26 vishnu.saini
  2026-11-22  3:43 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: vishnu.saini @ 2026-11-22  3:26 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: dri-devel, linux-kernel, venkata.valluru, Jessica Zhang,
	Ravi Agola, Vishnu Saini

From: Ravi Agola <raviagol@qti.qualcomm.com>

The LT9611UXC firmware buffers only two EDID blocks at a time, always at
the same offset (block % 2). Until now the driver read blocks 0 and 1 and
stopped there, so sinks with more than one extension block, such as the
Dell Curved Monitor U4021QW, could not be fully read.

To get blocks 2 and 3, set the EDID ready flag in register 0xb028. This
makes the bridge asynchronously fetch the next pair of blocks from the
sink into the same buffer. The bridge has no "fetch done" status, so the
driver polls the buffer until the new data shows up. Stale data is
detected from the EDID header:

 - Block 0 always starts with the EDID header magic
   (00 ff ff ff ff ff ff 00), so it is accepted once the magic is
   present.
 - Block 2 never carries the magic, so it is accepted once the header
   left over from the previous block 0 is gone.

Poll for EDID availability up to 10 times at 100 ms intervals. This
provides sufficient margin for the observed EDID fetch latency, which
can reach 600-650 ms after the HPD interrupt.

Reset the edid_read flag on HPD disconnect so that the next connect
triggers a fresh EDID fetch.

Also increase the EDID wait time from 500 ms to 1000 ms. On the
Qualcomm rb3gen2 platform the EDID read interrupt sometimes arrives
600-650 ms after the HPD interrupt, which made the EDID read fail.

Signed-off-by: Ravi Agola <raviagol@qti.qualcomm.com>
Signed-off-by: Vishnu Saini <vishnu.saini@oss.qualcomm.com>
---
Changes in v5:
- Updated commit msg and comments [Jani Nikula]
- Rebased onto latest drm-misc-next.
- Link to v4: https://lore.kernel.org/r/20260922-lt9611usc_edid34_misc_next-v4-1-47d5315821fe@oss.qualcomm.com

Changes in v4:
- Rebased onto latest drm-misc-next.
- No functional changes; replied inline to the two Sashiko-bot
  review comments on v3
- Link to v3: https://lore.kernel.org/r/20260722-lt9611usc_edid34_misc_next-v3-1-7ec2bba6ff8e@oss.qualcomm.com

Changes in v3:
- moved edid_read state change inside mutex lock     [sashiko-bot]
- returned -ETIMEOUT when retry_cnt is exhausted without a match.    [Sashiko-bot]
- Increased edid wait timeout from 500ms to 1000ms as edid interrupt is sometimes taking around 650ms time
- Link to v2: https://lore.kernel.org/r/20260624-lt9611usc_edid34_misc_next-v2-1-24ce3f5770b8@oss.qualcomm.com

Changes in v2:
- Removed memcpy and doing edid fetch everytime. Required an update in firmware as well for edid block0 reset.
- Verified patch with existing firmware V5.0.21, patch is not causing any regression if V5.0.21 firmware is used.
- Firmware V5.0.22 is required with this patch to support edid fetch on more than 2 edid block monitors.
- Link to v1: https://lore.kernel.org/r/20260517-lt9611usc_edid34_misc_next-v1-1-5e2fd8c6399b@oss.qualcomm.com
---
 drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 93 +++++++++++++++++++++++++-----
 1 file changed, 78 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
index b3bb7f2cebb3..d5924a8df1f9 100644
--- a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
+++ b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
@@ -28,7 +28,7 @@
 #include <drm/display/drm_hdmi_audio_helper.h>
 
 #define EDID_BLOCK_SIZE	128
-#define EDID_NUM_BLOCKS	2
+#define EDID_NUM_BLOCKS	4
 
 #define FW_FILE "lt9611uxc_fw.bin"
 
@@ -167,6 +167,8 @@ static void lt9611uxc_hpd_work(struct work_struct *work)
 
 	mutex_lock(&lt9611uxc->ocm_lock);
 	connected = lt9611uxc->hdmi_connected;
+	if (!connected)
+		lt9611uxc->edid_read = false;
 	mutex_unlock(&lt9611uxc->ocm_lock);
 
 	drm_bridge_hpd_notify(&lt9611uxc->bridge,
@@ -380,13 +382,39 @@ lt9611uxc_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connect
 static int lt9611uxc_wait_for_edid(struct lt9611uxc *lt9611uxc)
 {
 	return wait_event_interruptible_timeout(lt9611uxc->wq, lt9611uxc->edid_read,
-			msecs_to_jiffies(500));
+			msecs_to_jiffies(1000));
+}
+
+static int lt9611uxc_read_edid_block(struct lt9611uxc *lt9611uxc, unsigned int block,
+				     u8 *buf,  size_t len)
+{
+	int ret;
+
+	lt9611uxc_lock(lt9611uxc);
+
+	regmap_write(lt9611uxc->regmap, 0xb00a, (block % 2) * EDID_BLOCK_SIZE);
+
+	ret = regmap_noinc_read(lt9611uxc->regmap, 0xb0b0, buf, len);
+	if (ret) {
+		dev_err(lt9611uxc->dev, "edid block %d read failed: %d\n", block, ret);
+		lt9611uxc_unlock(lt9611uxc);
+		return -EINVAL;
+	}
+	lt9611uxc_unlock(lt9611uxc);
+
+	return ret;
 }
 
 static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
 {
 	struct lt9611uxc *lt9611uxc = data;
-	int ret;
+	int ret = 0;
+	int retry_cnt = 10;
+	unsigned int edid_ready_flag = 0;
+	bool header_matched;
+	bool edid_valid = false;
+	const u8 edid_header[8] = { 0x00, 0xFF, 0xFF, 0xFF,
+				    0xFF, 0xFF, 0xFF, 0x00 };
 
 	if (len > EDID_BLOCK_SIZE)
 		return -EINVAL;
@@ -394,20 +422,55 @@ static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, siz
 	if (block >= EDID_NUM_BLOCKS)
 		return -EINVAL;
 
-	lt9611uxc_lock(lt9611uxc);
-
-	regmap_write(lt9611uxc->regmap, 0xb00b, 0x10);
-
-	regmap_write(lt9611uxc->regmap, 0xb00a, block * EDID_BLOCK_SIZE);
-
-	ret = regmap_noinc_read(lt9611uxc->regmap, 0xb0b0, buf, len);
-	if (ret)
-		dev_err(lt9611uxc->dev, "edid read failed: %d\n", ret);
+	if (block == 0 || block == 2) {
+
+		lt9611uxc_lock(lt9611uxc);
+
+		edid_ready_flag = (block == 0) ? BIT(0) : BIT(1);
+
+		/*
+		 * The bridge only buffers 2 EDID blocks at a time. Writing
+		 * 0xb028 re-triggers it to fetch a fresh pair of blocks
+		 * (0+1, or 2+3) from the sink over DDC into that buffer, an
+		 * asynchronous operation with no separate "fetch done" flag
+		 * to wait on.
+		 */
+		regmap_write(lt9611uxc->regmap, 0xb028, edid_ready_flag);
+
+		lt9611uxc_unlock(lt9611uxc);
+
+		do {
+			msleep(100);
+			ret = lt9611uxc_read_edid_block(lt9611uxc, block, buf, len);
+			if (ret)
+				break;
+			/*
+			 * Poll for the fetch to complete: block 0 is only
+			 * valid once it carries the EDID header magic, and
+			 * block 2 (an extension block) is only valid once it
+			 * no longer carries that same magic left over from
+			 * the previous fetch at this buffer offset.
+			 */
+			header_matched = (memcmp(edid_header, buf, 8) == 0);
+			edid_valid = (block == 0 && header_matched) ||
+				     (block == 2 && !header_matched);
+			if (edid_valid)
+				break;
+
+		} while (retry_cnt-- > 0);
+
+		if (!ret && !edid_valid)
+			ret = -ETIMEDOUT;
+	} else {
+		ret = lt9611uxc_read_edid_block(lt9611uxc, block, buf, len);
 
-	lt9611uxc_unlock(lt9611uxc);
+		lt9611uxc_lock(lt9611uxc);
+		regmap_write(lt9611uxc->regmap, 0xb028, 0x00);
+		lt9611uxc_unlock(lt9611uxc);
+	}
 
-	return 0;
-};
+	return ret;
+}
 
 static const struct drm_edid *lt9611uxc_bridge_edid_read(struct drm_bridge *bridge,
 							 struct drm_connector *connector)

---
base-commit: c408466a4dfaee4b12587e926c5b85e68c8b3c40
change-id: 20260517-lt9611usc_edid34_misc_next-b02592de0b25

Best regards,
-- 
Vishnu Saini <vishnu.saini@oss.qualcomm.com>


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

* Re: [PATCH v5] drm/bridge: lt9611uxc: support displays with up to 4 EDID blocks
  2026-11-22  3:26 [PATCH v5] drm/bridge: lt9611uxc: support displays with up to 4 EDID blocks vishnu.saini
@ 2026-11-22  3:43 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-22  3:43 UTC (permalink / raw)
  To: vishnu.saini; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/bridge: lt9611uxc: race in lt9611uxc_get_edid_block() SRAM
  polling
- [Medium] drm/bridge: lt9611uxc: 0xb028 not reset in
  lt9611uxc_get_edid_block()
- [Medium] drm/bridge: lt9611uxc: missed edid_read reset in
  lt9611uxc_hpd_work()
- [Medium] drm/bridge: lt9611uxc: concurrent EDID race in
  lt9611uxc_get_edid_block()
--

commit 8673240c50c833c65a09b1b2cab593e96281a4c4
Author: Ravi Agola <raviagol@qti.qualcomm.com>

drm/bridge: lt9611uxc: support displays with up to 4 EDID blocks

This commit extends EDID reading on the LT9611UXC bridge to support up to
4 blocks by triggering paired block fetches via register 0xb028 and
polling the shared two-block SRAM buffer, resets edid_read on HPD
disconnect, and increases the EDID wait timeout to 1000 ms.

> diff --git a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
> index b3bb7f2cebb3b..d5924a8df1f94 100644
> --- a/drivers/gpu/drm/bridge/lontium-lt9611uxc.c
> +++ b/drivers/gpu/drm/bridge/lontium-lt9611uxc.c

[ ... ]

> @@ -167,6 +167,8 @@ static void lt9611uxc_hpd_work(struct work_struct *work)
>  
>  	mutex_lock(&lt9611uxc->ocm_lock);
>  	connected = lt9611uxc->hdmi_connected;
> +	if (!connected)
> +		lt9611uxc->edid_read = false;
>  	mutex_unlock(&lt9611uxc->ocm_lock);
>  
>  	drm_bridge_hpd_notify(&lt9611uxc->bridge,

[Severity: Medium]
Can an HPD disconnect followed by a reconnect before lt9611uxc_hpd_work()
acquires ocm_lock leave lt9611uxc->edid_read stale?

IRQ thread                        kworker
lt9611uxc_irq_thread_handler()
  lt9611uxc_lock()
  /* HPD disconnect */
  lt9611uxc->hdmi_connected = false;
  schedule_work(&lt9611uxc->work)
  lt9611uxc_unlock()
    msleep(50)
                                  lt9611uxc_hpd_work()
                                    mutex_lock(&lt9611uxc->ocm_lock)
lt9611uxc_irq_thread_handler()
  lt9611uxc_lock()
  /* HPD reconnect */
  lt9611uxc->hdmi_connected = true;
  schedule_work(&lt9611uxc->work)
  lt9611uxc_unlock()
                                    connected = lt9611uxc->hdmi_connected;
                                    if (!connected)  <-- skipped
                                      lt9611uxc->edid_read = false;

When an HPD pulse or quick replug happens while ocm_lock is held across
msleep(50) in lt9611uxc_unlock() (or while an earlier work run is still
inside drm_bridge_hpd_notify()), lt9611uxc_hpd_work() only observes
hdmi_connected == true and never clears edid_read.  The subsequent
lt9611uxc_wait_for_edid() then returns immediately instead of waiting for
the new EDID interrupt.  lt9611uxc_bridge_detect() also updates
hdmi_connected without clearing edid_read on disconnect.

Clearing lt9611uxc->edid_read directly where disconnection is observed in
lt9611uxc_irq_thread_handler() and lt9611uxc_bridge_detect() would avoid
missing the transition.

[ ... ]

> @@ -394,20 +422,55 @@ static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, siz
>  	if (block >= EDID_NUM_BLOCKS)
>  		return -EINVAL;
>  
> -	lt9611uxc_lock(lt9611uxc);
> -
> -	regmap_write(lt9611uxc->regmap, 0xb00b, 0x10);
> -
> -	regmap_write(lt9611uxc->regmap, 0xb00a, block * EDID_BLOCK_SIZE);
> -
> -	ret = regmap_noinc_read(lt9611uxc->regmap, 0xb0b0, buf, len);
> -	if (ret)
> -		dev_err(lt9611uxc->dev, "edid read failed: %d\n", ret);
> +	if (block == 0 || block == 2) {
> +
> +		lt9611uxc_lock(lt9611uxc);
> +
> +		edid_ready_flag = (block == 0) ? BIT(0) : BIT(1);
> +
> +		/*
> +		 * The bridge only buffers 2 EDID blocks at a time. Writing
> +		 * 0xb028 re-triggers it to fetch a fresh pair of blocks
> +		 * (0+1, or 2+3) from the sink over DDC into that buffer, an
> +		 * asynchronous operation with no separate "fetch done" flag
> +		 * to wait on.
> +		 */
> +		regmap_write(lt9611uxc->regmap, 0xb028, edid_ready_flag);
> +
> +		lt9611uxc_unlock(lt9611uxc);
> +
> +		do {
> +			msleep(100);
> +			ret = lt9611uxc_read_edid_block(lt9611uxc, block, buf, len);
> +			if (ret)
> +				break;
> +			/*
> +			 * Poll for the fetch to complete: block 0 is only
> +			 * valid once it carries the EDID header magic, and
> +			 * block 2 (an extension block) is only valid once it
> +			 * no longer carries that same magic left over from
> +			 * the previous fetch at this buffer offset.
> +			 */
> +			header_matched = (memcmp(edid_header, buf, 8) == 0);
> +			edid_valid = (block == 0 && header_matched) ||
> +				     (block == 2 && !header_matched);
> +			if (edid_valid)
> +				break;
> +
> +		} while (retry_cnt-- > 0);

[Severity: High]
Can this loop return a partially written EDID block if lt9611uxc_lock()
halts the on-chip MCU after the first 8 bytes of the 256-byte SRAM buffer
have been updated, but before the rest of the block pair has been fetched
over DDC?

Each poll iteration halts the MCU via 0x80ee = 0x01 and reads 128 bytes
from offset 0.  For block 2 in particular, !header_matched becomes true as
soon as the MCU overwrites byte 0 of offset 0, even if bytes 8..127 of
block 2 and bytes 128..255 of companion block 1 or 3 have not been written
to SRAM yet.  The subsequent call for block 1 or block 3 then immediately
reads offset 128 in the else branch with no completion check and clears
0xb028, returning torn or stale EDID data.

> +
> +		if (!ret && !edid_valid)
> +			ret = -ETIMEDOUT;
> +	} else {
> +		ret = lt9611uxc_read_edid_block(lt9611uxc, block, buf, len);
>  
> -	lt9611uxc_unlock(lt9611uxc);
> +		lt9611uxc_lock(lt9611uxc);
> +		regmap_write(lt9611uxc->regmap, 0xb028, 0x00);
> +		lt9611uxc_unlock(lt9611uxc);
> +	}
>  
> -	return 0;
> -};
> +	return ret;
> +}

[Severity: Medium]
Does register 0xb028 stay set to BIT(0) or BIT(1) when a display has 1 or
3 EDID blocks, or when reading block 0 or block 2 fails or is retried?

0xb028 is only reset to 0x00 in the else branch for odd blocks (1 and 3),
but _drm_do_get_edid() stops after block 0 when there are no extensions
and after block 2 when there are 2 extensions:

drivers/gpu/drm/drm_edid.c:_drm_do_get_edid() {
	...
	if (!edid_extension_block_count(edid))
		goto ok;
	...
	num_blocks = edid_block_count(edid);
	for (i = 1; i < num_blocks; i++) {
		void *block = (void *)edid_block_data(edid, i);

		status = edid_block_read(block, i, read_block, context);
	...
}

In addition, if edid_block_check() fails on block 2, edid_block_read()
retries block 2 directly without reading block 3 in between.  Because
0xb028 was not cleared and offset 0 already holds non-header bytes from
the failed attempt rather than block 0's magic header,
(block == 2 && !header_matched) matches immediately on the first poll
iteration without waiting for a fresh fetch.

[Severity: Medium]
What prevents two concurrent EDID reads from clobbering register 0xb028
and the shared two-block hardware buffer across the unlocked polling loop
and between paired block reads?

kworker (HPD notify)              userspace (GETCONNECTOR)
lt9611uxc_bridge_hpd_notify()     drm_bridge_connector_get_modes_edid()
  lt9611uxc_bridge_edid_read()      ...
    lt9611uxc_get_edid_block(blk 2)   lt9611uxc_bridge_edid_read()
      write 0xb028 = BIT(1)             lt9611uxc_get_edid_block(blk 0)
      lt9611uxc_unlock()                  write 0xb028 = BIT(0)
      msleep(100)                         ...
      /* buffer now holds blk 0+1 */
      read_edid_block(blk 2)  <-- sees block 0 header, times out

lt9611uxc_hpd_work() invokes lt9611uxc_bridge_hpd_notify() under
bridge->hpd_mutex without dev->mode_config.mutex, while connector probing
invokes drm_bridge_edid_read() under dev->mode_config.mutex without
bridge->hpd_mutex.  Because ocm_lock is dropped across msleep(100) and
between blocks 0/1 and 2/3, a concurrent reader starting at block 0 can
switch 0xb028 back to BIT(0) (or finish block 1 and write 0x00) while the
first reader is polling block 2 or about to read block 3 from offset 128,
causing spurious -ETIMEDOUT failures or returning block 1 data in place of
block 3.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-lt9611usc_edid34_misc_next-v5-1-00b562fe4a24@oss.qualcomm.com?part=1

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

end of thread, other threads:[~2026-11-22  3:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22  3:26 [PATCH v5] drm/bridge: lt9611uxc: support displays with up to 4 EDID blocks vishnu.saini
2026-11-22  3:43 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.