Skip to contentSkip to conversation

drm/i2c: tda998x: use irq for connection status and EDID read

PATCH Superseded Jean-Francois Moine 3 participants 6 messages Jan 9, 2014 – Jan 17, 2014

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 13/28 drm/i2c: tda998x: use irq for connection status and EDID read

This patch adds the optional treatment of the tda998x IRQ.

The interrupt function is used to know the display connection status without polling and to speedup reading the EDID.

---
 drivers/gpu/drm/i2c/tda998x_drv.c            | 116 +++++++++++++++++++--
 .../devicetree/bindings/drm/i2c/tda998x.txt  |   3 +++
 2 file changed, 108 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/drm/i2c/tda998x.txt +3 -0
index f07339e1..83d7880 100644
@@ -4,6 +4,7 @@ Required properties;
   - compatible: must be "nxp,tda998x"
 
 Optional properties:
+  - interrupts: interrupt number for HDMI exchanges - default: by polling
   - video-ports: 24 bits value - default: <0x230145>
 
 Example:
@@ -11,6 +12,8 @@ Example:
 	tda998x: hdmi-encoder {
 		compatible = "nxp,tda998x";
 		reg = <0x70>;
+		interrupt-parent = <&gpio0>;
+		interrupts = <27 2>;		/* falling edge */
 		pinctrl-0 = <&pmx_camera>;
 		pinctrl-names = "default";
 	};
drivers/gpu/drm/i2c/tda998x_drv.c +105 -11

191 lines not on this page · raw message

Signature · 6 lines
Ken ar c'hentañ	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

drivers/gpu/drm/i2c/tda998x_drv.c read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk) · line 1046

Quoted 5 lines · Jean-Francois Moine
drivers/gpu/drm/i2c/tda998x_drv.c +5 -0
+	if (priv->int_irq != NO_IRQ) {
+		priv->wq_edid_wait = 1;
+		i = wait_event_timeout(priv->wq_edid,
+					!priv->wq_edid_wait,
+					msecs_to_jiffies(100));

This looks wrong on two counts.

First, this is racy. What you're expecting is that this function is called before the EDID is read, in order for wq_edid_wait to be set. You're then hoping that the interrupt is received afterwards.

What if this function wasn't called before the EDID read interrupt occurred? We time out.

Secondly, what happens if this function is called more than once? The second time, we won't see an interrupt, because no state has changed.

This approach is just too buggy. Please re-work it to be race free and safe. You need to maintain a flag which indicates when there is valid EDID data present - set this when the device indicates that's the case, and clear it on disconnect. Then the above becomes a wait_event_timeout() based on that.

The last thing which needs to be considered here is whether it's possible to use wait_event_interruptible_timeout() in this path, but that requires a bit of research into whether DRM is able to restart a call to this function after handling a signal.

drivers/gpu/drm/i2c/tda998x_drv.c tda998x_encoder_init(struct i2c_client *client, · line 1318

Quoted 9 lines
drivers/gpu/drm/i2c/tda998x_drv.c +5 -0
@@ -1250,6 +1311,39 @@ tda998x_encoder_init(struct i2c_client *client,
 		priv->vip_cntrl_2 = video;
 	}
 
+	/* install the optional HDMI connect IRQ */
+	priv->int_irq = irq_of_parse_and_map(np, 0);
+	if (priv->int_irq < 0)
+		priv->int_irq = NO_IRQ;
+	if (priv->int_irq != NO_IRQ) {

NAK. Do not use NO_IRQ. Use <= 0 instead, or just test against zero for no IRQ. It would also be nice to offer this facility to non-DT platforms via client->irq. Not every arch in the Linux kernel uses DT.

Quoted 16 lines
drivers/gpu/drm/i2c/tda998x_drv.c +16 -0
+
+		/* init read EDID waitqueue */
+		init_waitqueue_head(&priv->wq_edid);
+/*		priv->wq_edid_wait = 0;	*/
+
+		/* clear pending interrupts */
+		reg_read(priv, REG_INT_FLAGS_0);
+		reg_read(priv, REG_INT_FLAGS_1);
+		reg_read(priv, REG_INT_FLAGS_2);
+
+		ret = request_threaded_irq(priv->int_irq, NULL,
+					   tda998x_irq_thread,
+					   IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					   "tda998x-int", priv);
+		if (ret) {
+			dev_err(&client->dev, "failed to request IRQ#%u: %d\n",

drivers/gpu/drm/i2c/tda998x_drv.c tda998x_encoder_init(struct i2c_client *client, · line 1344

Quoted 10 lines
drivers/gpu/drm/i2c/tda998x_drv.c +10 -0
+				priv->int_irq, ret);
+			goto fail;
+		}
+
+		/* enable HPD irq */
+		cec_write(priv, REG_CEC_RXSHPDINTENA,
+				CEC_RXSHPDLEV_HPD | CEC_RXSHPDLEV_RXSENS);
+
+		/* treat the first irq if any */
+		msleep(10);

This comment makes no sense, and doesn't describe what this delay is actually here for, and why 10ms is the right amount of time to wait.

Signature · 7 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 5 lines · Russell King - ARM Linux
Quoted 4 lines · Jean-Francois Moine
drivers/gpu/drm/i2c/tda998x_drv.c +0 -0
@@ -1250,6 +1311,39 @@ tda998x_encoder_init(struct i2c_client *client,
  		priv->vip_cntrl_2 = video;
  	}
 
Quoted 9 lines

drivers/gpu/drm/i2c/tda998x_drv.c tda998x_encoder_init(struct i2c_client *client, · line 1318

Quoted 5 lines
drivers/gpu/drm/i2c/tda998x_drv.c +5 -0
+	/* install the optional HDMI connect IRQ */
+	priv->int_irq = irq_of_parse_and_map(np, 0);
+	if (priv->int_irq < 0)
+		priv->int_irq = NO_IRQ;
+	if (priv->int_irq != NO_IRQ) {

NAK. Do not use NO_IRQ. Use <= 0 instead, or just test against zero for no IRQ. It would also be nice to offer this facility to non-DT platforms via client->irq. Not every arch in the Linux kernel uses DT.

At least for the DT part, I'd suggest to not ask for interrupt directly but use a proper gpios property. The can of course be converted to priv->int_irq in some tda998x_dt_probe.

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 3 lines · On Sat, 11 Jan 2014 19:35:21 +0100 Sebastian Hesselbarth…

At least for the DT part, I'd suggest to not ask for interrupt directly but use a proper gpios property. The can of course be converted to priv->int_irq in some tda998x_dt_probe.

May you give me more information?

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/
#4 lore raw
Quoted 8 lines · Jean-Francois Moine
Quoted 3 lines · On Sat, 11 Jan 2014 19:35:21 +0100 Sebastian Hesselbarth…

At least for the DT part, I'd suggest to not ask for interrupt directly but use a proper gpios property. The can of course be converted to priv->int_irq in some tda998x_dt_probe.

May you give me more information?

Sure, see [1].

[1] http://lists.freedesktop.org/archives/dri-devel/2013-May/038822.html

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 8 lines · On Sun, 12 Jan 2014 20:26:21 +0100 Sebastian Hesselbarth…
Quoted 7 lines · Jean-Francois Moine
Quoted 3 lines · On Sat, 11 Jan 2014 19:35:21 +0100 Sebastian Hesselbarth…

At least for the DT part, I'd suggest to not ask for interrupt directly but use a proper gpios property. The can of course be converted to priv->int_irq in some tda998x_dt_probe.

Quoted 5 lines
Quoted 1 line

May you give me more information?

Sure, see [1].

[1] http://lists.freedesktop.org/archives/dri-devel/2013-May/038822.html

Thanks for the link, but I still don't see the advantage of the gpio (which value?) over the irq number.

Signature · 2 lines
Ken ar c'henta?	|	      ** Breizh ha Linux atav! **
Jef		|		http://moinejf.free.fr/