Skip to contentSkip to conversation

drm/bridge/lontium-lt9611uxc: fix handling of EDID/HPD

PATCH Applied Dmitry Baryshkov 3 participants 9 messages Jan 21, 2021 – Mar 1, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover drm/bridge/lontium-lt9611uxc: fix handling of EDID/HPD

These three patches provide fixes for HPD handling and EDID readout for Lontium lt9611uxc DSI-to-HDMI bridge driver.

Changes since v3:
- Protect hdmi_connected using ocm_mutex
- Remove !! conversion from int to boolean
- Add missing Reviewed-by tags.

Changes since v2:
- Declare lt9611uxc_hpd_work as static

Changes since v1:
- Split first patch into two smaller patches
- Add Fixes tags

Dmitry Baryshkov (3):
drm/bridge/lontium-lt9611uxc: fix waiting for EDID to become available drm/bridge/lontium-lt9611uxc: fix get_edid return code drm/bridge/lontium-lt9611uxc: move HPD notification out of IRQ handler

#1 lore raw

PATCH v4 1/3 drm/bridge/lontium-lt9611uxc: fix waiting for EDID to become available

- Call wake_up() when EDID ready event is received to wake wait_event_interruptible_timeout()

- Increase waiting timeout, reading EDID can take longer than 100ms, so let's be on a safe side.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")
---
 drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/lontium-lt9611uxc.c +4 -2
index 0c98d27f84ac..a59e811f1705 100644
@@ -145,8 +145,10 @@ static irqreturn_t lt9611uxc_irq_thread_handler(int irq, void *dev_id)
 
 	lt9611uxc_unlock(lt9611uxc);
 
-	if (irq_status & BIT(0))
+	if (irq_status & BIT(0)) {
 		lt9611uxc->edid_read = !!(hpd_status & BIT(0));
+		wake_up_all(&lt9611uxc->wq);
+	}
 
 	if (irq_status & BIT(1)) {
 		if (lt9611uxc->connector.dev)
@@ -465,7 +467,7 @@ static enum drm_connector_status lt9611uxc_bridge_detect(struct drm_bridge *brid
 static int lt9611uxc_wait_for_edid(struct lt9611uxc *lt9611uxc)
 {
 	return wait_event_interruptible_timeout(lt9611uxc->wq, lt9611uxc->edid_read,
-			msecs_to_jiffies(100));
+			msecs_to_jiffies(500));
 }
 
 static int lt9611uxc_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len)
Signature · 1 line
2.29.2
Reviewed-by on v4 1/3
#2 lore raw

Re: [PATCH v4 1/3] drm/bridge/lontium-lt9611uxc: fix waiting for EDID to become available

W dniu 22.01.2021 o 00:33, Dmitry Baryshkov pisze:

Quoted 9 lines

- Call wake_up() when EDID ready event is received to wake wait_event_interruptible_timeout()

- Increase waiting timeout, reading EDID can take longer than 100ms, so let's be on a safe side.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")

Regards
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH v4 2/3 drm/bridge/lontium-lt9611uxc: fix get_edid return code

In reply to Dmitry Baryshkov

Return NULL pointer from get_edid() callback rather than ERR_PTR() pointer, as DRM code does NULL checks rather than IS_ERR(). Also while we are at it, return NULL if getting EDID timed out.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")
---
 drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/lontium-lt9611uxc.c +4 -1
index a59e811f1705..b708700e182d 100644
@@ -505,7 +505,10 @@ static struct edid *lt9611uxc_bridge_get_edid(struct drm_bridge *bridge,
 	ret = lt9611uxc_wait_for_edid(lt9611uxc);
 	if (ret < 0) {
 		dev_err(lt9611uxc->dev, "wait for EDID failed: %d\n", ret);
-		return ERR_PTR(ret);
+		return NULL;
+	} else if (ret == 0) {
+		dev_err(lt9611uxc->dev, "wait for EDID timeout\n");
+		return NULL;
 	}
 
 	return drm_do_get_edid(connector, lt9611uxc_get_edid_block, lt9611uxc);
Signature · 1 line
2.29.2
Reviewed-by on v4 2/3
#4 lore raw

Re: [PATCH v4 2/3] drm/bridge/lontium-lt9611uxc: fix get_edid return code

W dniu 22.01.2021 o 00:33, Dmitry Baryshkov pisze:

Quoted 7 lines

Return NULL pointer from get_edid() callback rather than ERR_PTR() pointer, as DRM code does NULL checks rather than IS_ERR(). Also while we are at it, return NULL if getting EDID timed out.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")

Regards
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

PATCH v4 3/3 drm/bridge/lontium-lt9611uxc: move HPD notification out of IRQ handler

In reply to Dmitry Baryshkov

drm hotplug handling code (drm_client_dev_hotplug()) can wait on mutex, thus delaying further lt9611uxc IRQ events processing. It was observed occasionally during bootups, when drm_client_modeset_probe() was waiting for EDID ready event, which was delayed because IRQ handler was stuck trying to deliver hotplug event.
Move hotplug notifications from IRQ handler to separate work to be able to process IRQ events without delays.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")
---
 drivers/gpu/drm/bridge/lontium-lt9611uxc.c | 46 +++++++++++++++++-----
 1 file changed, 37 insertions(+), 9 deletions(-)
drivers/gpu/drm/bridge/lontium-lt9611uxc.c +37 -9
index b708700e182d..fee27952ec6d 100644
@@ -14,6 +14,7 @@
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/wait.h>
+#include <linux/workqueue.h>
 
 #include <sound/hdmi-codec.h>
 
@@ -36,6 +37,7 @@ struct lt9611uxc {
 	struct mutex ocm_lock;
 
 	struct wait_queue_head wq;
+	struct work_struct work;
 
 	struct device_node *dsi0_node;
 	struct device_node *dsi1_node;
@@ -52,6 +54,8 @@ struct lt9611uxc {
 
 	bool hpd_supported;
 	bool edid_read;
+	/* can be accessed from different threads, so protect this with ocm_lock */
+	bool hdmi_connected;
 	uint8_t fw_version;
 };
 
@@ -143,23 +147,41 @@ static irqreturn_t lt9611uxc_irq_thread_handler(int irq, void *dev_id)
 	if (irq_status)
 		regmap_write(lt9611uxc->regmap, 0xb022, 0);
 
-	lt9611uxc_unlock(lt9611uxc);
-
 	if (irq_status & BIT(0)) {
 		lt9611uxc->edid_read = !!(hpd_status & BIT(0));
 		wake_up_all(&lt9611uxc->wq);
 	}
 
 	if (irq_status & BIT(1)) {
-		if (lt9611uxc->connector.dev)
-			drm_kms_helper_hotplug_event(lt9611uxc->connector.dev);
-		else
-			drm_bridge_hpd_notify(&lt9611uxc->bridge, !!(hpd_status & BIT(1)));
+		lt9611uxc->hdmi_connected = hpd_status & BIT(1);
+		schedule_work(&lt9611uxc->work);
 	}
 
+	lt9611uxc_unlock(lt9611uxc);
+
 	return IRQ_HANDLED;
 }
 
+static void lt9611uxc_hpd_work(struct work_struct *work)
+{
+	struct lt9611uxc *lt9611uxc = container_of(work, struct lt9611uxc, work);
+	bool connected;
+
+	if (lt9611uxc->connector.dev)
+		drm_kms_helper_hotplug_event(lt9611uxc->connector.dev);
+	else {
+
+		mutex_lock(&lt9611uxc->ocm_lock);
+		connected = lt9611uxc->hdmi_connected;
+		mutex_unlock(&lt9611uxc->ocm_lock);
+
+		drm_bridge_hpd_notify(&lt9611uxc->bridge,
+				      connected ?
+				      connector_status_connected :
+				      connector_status_disconnected);
+	}
+}
+
 static void lt9611uxc_reset(struct lt9611uxc *lt9611uxc)
 {
 	gpiod_set_value_cansleep(lt9611uxc->reset_gpio, 1);
@@ -447,18 +469,21 @@ static enum drm_connector_status lt9611uxc_bridge_detect(struct drm_bridge *brid
 	struct lt9611uxc *lt9611uxc = bridge_to_lt9611uxc(bridge);
 	unsigned int reg_val = 0;
 	int ret;
-	int connected = 1;
+	bool connected = true;
+
+	lt9611uxc_lock(lt9611uxc);
 
 	if (lt9611uxc->hpd_supported) {
-		lt9611uxc_lock(lt9611uxc);
 		ret = regmap_read(lt9611uxc->regmap, 0xb023, &reg_val);
-		lt9611uxc_unlock(lt9611uxc);
 
 		if (ret)
 			dev_err(lt9611uxc->dev, "failed to read hpd status: %d\n", ret);
 		else
 			connected  = reg_val & BIT(1);
 	}
+	lt9611uxc->hdmi_connected = connected;
+
+	lt9611uxc_unlock(lt9611uxc);
 
 	return connected ?  connector_status_connected :
 				connector_status_disconnected;
@@ -931,6 +956,8 @@ static int lt9611uxc_probe(struct i2c_client *client,
 	lt9611uxc->fw_version = ret;
 
 	init_waitqueue_head(&lt9611uxc->wq);
+	INIT_WORK(&lt9611uxc->work, lt9611uxc_hpd_work);
+
 	ret = devm_request_threaded_irq(dev, client->irq, NULL,
 					lt9611uxc_irq_thread_handler,
 					IRQF_ONESHOT, "lt9611uxc", lt9611uxc);
@@ -967,6 +994,7 @@ static int lt9611uxc_remove(struct i2c_client *client)
 	struct lt9611uxc *lt9611uxc = i2c_get_clientdata(client);
 
 	disable_irq(client->irq);
+	flush_scheduled_work();
 	lt9611uxc_audio_exit(lt9611uxc);
 	drm_bridge_remove(&lt9611uxc->bridge);
 
Signature · 1 line
2.29.2
Reviewed-by on v4 3/3
#6 lore raw

Re: [PATCH v4 3/3] drm/bridge/lontium-lt9611uxc: move HPD notification out of IRQ handler

W dniu 22.01.2021 o 00:33, Dmitry Baryshkov pisze:

Quoted 10 lines

drm hotplug handling code (drm_client_dev_hotplug()) can wait on mutex, thus delaying further lt9611uxc IRQ events processing. It was observed occasionally during bootups, when drm_client_modeset_probe() was waiting for EDID ready event, which was delayed because IRQ handler was stuck trying to deliver hotplug event.
Move hotplug notifications from IRQ handler to separate work to be able to process IRQ events without delays.

Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")

Let's wait till Monday for other comments, then I can queue the patchset.

Regards
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Re: [PATCH v4 3/3] drm/bridge/lontium-lt9611uxc: move HPD notification out of IRQ handler

W dniu 22.01.2021 o 10:34, Andrzej Hajda pisze:

Quoted 9 lines

W dniu 22.01.2021 o 00:33, Dmitry Baryshkov pisze:

Quoted 8 lines

drm hotplug handling code (drm_client_dev_hotplug()) can wait on mutex, thus delaying further lt9611uxc IRQ events processing. It was observed occasionally during bootups, when drm_client_modeset_probe() was waiting for EDID ready event, which was delayed because IRQ handler was stuck trying to deliver hotplug event.
Move hotplug notifications from IRQ handler to separate work to be able to process IRQ events without delays.

Quoted 7 lines
Quoted 2 lines
Fixes 0cbbd5b1a012 ("drm: bridge: add support for lontium LT9611UXC bridge")

Let's wait till Monday for other comments, then I can queue the patchset.

Queued to drm-misc-fixes.

I have fixed missing parentheses in the last patch in lt9611uxc_hpd_work, but apparently sth went wrong and I have merged version without these parentheses :(, can be fixed in another future patchset.

Regards

Andrzej

Quoted 8 lines

Regards
Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://protect2.fireeye.com/v1/url?k=20f4a2d0-7f6f9b96-20f5299f-0cc47a3003e8-b85b502ae8b34801&q=1&e=194b3466-3374-4717-82f7-d4cec3951dd6&u=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
In reply to Dmitry Baryshkov
This series was applied to qcom/linux.git (refs/heads/for-next):

Hello:

This series was applied to qcom/linux.git (refs/heads/for-next):

Quoted 9 lines · On Fri, 22 Jan 2021 02:33:00 +0300 you wrote:

These three patches provide fixes for HPD handling and EDID readout for Lontium lt9611uxc DSI-to-HDMI bridge driver.

Changes since v3:
- Protect hdmi_connected using ocm_mutex
- Remove !! conversion from int to boolean
- Add missing Reviewed-by tags.

[...]

Here is the summary with links:
- [v4,1/3] drm/bridge/lontium-lt9611uxc: fix waiting for EDID to become available

    https://git.kernel.org/qcom/c/053b1b287ccf
  - [v4,2/3] drm/bridge/lontium-lt9611uxc: fix get_edid return code
    https://git.kernel.org/qcom/c/1bb7ab402da4
  - [v4,3/3] drm/bridge/lontium-lt9611uxc: move HPD notification out of IRQ handler
    https://git.kernel.org/qcom/c/bc6fa8676ebb

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html