Skip to contentSkip to conversation

drm/bridge: adv7511: Allow IRQ to share GPIO pins

PATCH Superseded Adam Ford 2 participants 6 messages Feb 28, 2024 – Mar 3, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Adam Ford

author
#0 lore raw

PATCH 1/2 drm/bridge: adv7511: Allow IRQ to share GPIO pins

The IRQ registration currently assumes that the GPIO is dedicated to it, but that may not necessarily be the case. If the board has another device sharing the IRQ, it won't be registered and the hot-plug detect fails. This is easily fixed by add the IRQF_SHARED flag.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +2 -1
index b5518ff97165..21f08b2ae265 100644
@@ -1318,7 +1318,8 @@ static int adv7511_probe(struct i2c_client *i2c)
 
 		ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
 						adv7511_irq_handler,
-						IRQF_ONESHOT, dev_name(dev),
+						IRQF_ONESHOT | IRQF_SHARED,
+						dev_name(dev),
 						adv7511);
 		if (ret)
 			goto err_unregister_audio;
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 2/2 arm64: dts: imx8mp-beacon-kit: Enable HDMI bridge HPD

The DSI to HDMI bridge supports hot-plut-detect, but the driver didn't previously support a shared IRQ GPIO. With the driver updated, the interrupt can be added to the bridge.

arch/arm64/boot/dts/freescale/imx8mp-beacon-kit.dts +2 -0
index 8de4dd268908..d854c94ec997 100644
@@ -405,6 +405,8 @@ adv_bridge: hdmi@3d {
 		compatible = "adi,adv7535";
 		reg = <0x3d>, <0x3c>, <0x3e>, <0x3f>;
 		reg-names = "main", "cec", "edid", "packet";
+		interrupt-parent = <&gpio4>;
+		interrupts = <27 IRQ_TYPE_EDGE_FALLING>;
 		adi,dsi-lanes = <4>;
 		#sound-dai-cells = <0>;
 
Signature · 1 line
2.43.0
#3 lore raw
In reply to Adam Ford

Hi Adam,

Thank you for the patch.

Quoted 13 lines · Adam Ford

The IRQ registration currently assumes that the GPIO is dedicated to it, but that may not necessarily be the case. If the board has another device sharing the IRQ, it won't be registered and the hot-plug detect fails. This is easily fixed by add the IRQF_SHARED flag.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
index b5518ff97165..21f08b2ae265 100644

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_probe(struct i2c_client *i2c) · line 1322

Quoted 6 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +2 -1
@@ -1318,7 +1318,8 @@ static int adv7511_probe(struct i2c_client *i2c)
 
 		ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
 						adv7511_irq_handler,
-						IRQF_ONESHOT, dev_name(dev),
+						IRQF_ONESHOT | IRQF_SHARED,
+						dev_name(dev),

This looks fine, but the IRQ handler doesn't.

static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd)

{
	unsigned int irq0, irq1;
	int ret;

	ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
	if (ret < 0)
		return ret;

	ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
	if (ret < 0)
		return ret;

	regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
	regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);

	if (process_hpd && irq0 & ADV7511_INT0_HPD && adv7511->bridge.encoder)
		schedule_work(&adv7511->hpd_work);

	if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) {
		adv7511->edid_read = true;

		if (adv7511->i2c_main->irq)
			wake_up_all(&adv7511->wq);
	}
#ifdef CONFIG_DRM_I2C_ADV7511_CEC
	adv7511_cec_irq_process(adv7511, irq1);

#endif

	return 0;
}

static irqreturn_t adv7511_irq_handler(int irq, void *devid)

{
	struct adv7511 *adv7511 = devid;
	int ret;

	ret = adv7511_irq_process(adv7511, true);
	return ret < 0 ? IRQ_NONE : IRQ_HANDLED;
}

The function will return IRQ_HANDLED as long as the registers can be read, even if they don't report any interrupt.

Quoted 3 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
 						adv7511);
 		if (ret)
 			goto err_unregister_audio;
Signature · 3 lines
Regards,

Laurent Pinchart
reviewer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] arm64: dts: imx8mp-beacon-kit: Enable HDMI bridge HPD

In reply to Adam Ford

Hi Adam,

Thank you for the patch.

Quoted 3 lines · Adam Ford

The DSI to HDMI bridge supports hot-plut-detect, but the driver didn't previously support a shared IRQ GPIO. With the driver updated, the interrupt can be added to the bridge.

You can reflow the commit message to 72 columns.

Quoted 1 line
Quoted 13 lines
arch/arm64/boot/dts/freescale/imx8mp-beacon-kit.dts +2 -0
index 8de4dd268908..d854c94ec997 100644
@@ -405,6 +405,8 @@ adv_bridge: hdmi@3d {
 		compatible = "adi,adv7535";
 		reg = <0x3d>, <0x3c>, <0x3e>, <0x3f>;
 		reg-names = "main", "cec", "edid", "packet";
+		interrupt-parent = <&gpio4>;
+		interrupts = <27 IRQ_TYPE_EDGE_FALLING>;
 		adi,dsi-lanes = <4>;
 		#sound-dai-cells = <0>;
 
Signature · 3 lines
Regards,

Laurent Pinchart
author
#4 lore raw
In reply to Laurent Pinchart
Quoted 20 lines · Laurent Pinchart

Hi Adam,

Thank you for the patch.

Quoted 14 lines · Adam Ford

The IRQ registration currently assumes that the GPIO is dedicated to it, but that may not necessarily be the case. If the board has another device sharing the IRQ, it won't be registered and the hot-plug detect fails. This is easily fixed by add the IRQF_SHARED flag.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
index b5518ff97165..21f08b2ae265 100644
@@ -1318,7 +1318,8 @@ static int adv7511_probe(struct i2c_client *i2c)
 
Quoted 7 lines

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_probe(struct i2c_client *i2c) · line 1322

Quoted 5 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +2 -1
              ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
                                              adv7511_irq_handler,
-                                             IRQF_ONESHOT, dev_name(dev),
+                                             IRQF_ONESHOT | IRQF_SHARED,
+                                             dev_name(dev),

This looks fine, but the IRQ handler doesn't.

Thanks for the review.

Quoted 13 lines

static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd)

{
        unsigned int irq0, irq1;
        int ret;

        ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
        if (ret < 0)
                return ret;

        ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
        if (ret < 0)
                return ret;

If I did a check here and returned if there was no IRQ to handle, would that be sufficient?

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
@@ -477,6 +477,11 @@ static int adv7511_irq_process(struct adv7511

*adv7511, bool process_hpd)

        if (ret < 0)
                return ret;

+ /* If there is no IRQ to handle, exit indicating no IRQ handled */
+ if (!(irq0 & (ADV7511_INT0_HPD | ADV7511_INT0_EDID_READY)) &&
+ !(irq1 & ADV7511_INT1_DDC_ERROR))
+ return -1;
+

        regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
        regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);

With this, I would expect adv7511_irq_handler to return IRQ_NONE. If you're OK with that approach, I can do that. If you want me to merge adv7511_irq_handler, and adv7511_irq_process, I can do that too to make the return codes a little more intuitive.

adam

Quoted 41 lines
        regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
        regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);

        if (process_hpd && irq0 & ADV7511_INT0_HPD && adv7511->bridge.encoder)
                schedule_work(&adv7511->hpd_work);

        if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) {
                adv7511->edid_read = true;

                if (adv7511->i2c_main->irq)
                        wake_up_all(&adv7511->wq);
        }
#ifdef CONFIG_DRM_I2C_ADV7511_CEC
        adv7511_cec_irq_process(adv7511, irq1);

#endif

        return 0;
}

static irqreturn_t adv7511_irq_handler(int irq, void *devid)

{
        struct adv7511 *adv7511 = devid;
        int ret;

        ret = adv7511_irq_process(adv7511, true);
        return ret < 0 ? IRQ_NONE : IRQ_HANDLED;
}

The function will return IRQ_HANDLED as long as the registers can be read, even if they don't report any interrupt.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_probe(struct i2c_client *i2c) · line 1325

Quoted 3 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
                                              adv7511);
              if (ret)
                      goto err_unregister_audio;

--
Regards,

Laurent Pinchart

#5 lore raw
Quoted 45 lines · Adam Ford
Quoted 15 lines · Laurent Pinchart
Quoted 14 lines · Adam Ford

The IRQ registration currently assumes that the GPIO is dedicated to it, but that may not necessarily be the case. If the board has another device sharing the IRQ, it won't be registered and the hot-plug detect fails. This is easily fixed by add the IRQF_SHARED flag.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
index b5518ff97165..21f08b2ae265 100644
@@ -1318,7 +1318,8 @@ static int adv7511_probe(struct i2c_client *i2c)
 
Quoted 7 lines

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_probe(struct i2c_client *i2c) · line 1322

Quoted 5 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +2 -1
              ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
                                              adv7511_irq_handler,
-                                             IRQF_ONESHOT, dev_name(dev),
+                                             IRQF_ONESHOT | IRQF_SHARED,
+                                             dev_name(dev),

This looks fine, but the IRQ handler doesn't.

Thanks for the review.

Quoted 12 lines

static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd)

{
        unsigned int irq0, irq1;
        int ret;

        ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
        if (ret < 0)
                return ret;

        ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
        if (ret < 0)
                return ret;

If I did a check here and returned if there was no IRQ to handle, would that be sufficient?

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_irq_process(struct adv7511 · line 483

Quoted 7 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +3 -0
@@ -477,6 +477,11 @@ static int adv7511_irq_process(struct adv7511
 *adv7511, bool process_hpd)
        if (ret < 0)
                return ret;
 
+       /* If there is no IRQ to handle, exit indicating no IRQ handled */
+       if (!(irq0 & (ADV7511_INT0_HPD | ADV7511_INT0_EDID_READY)) &&
+          !(irq1 & ADV7511_INT1_DDC_ERROR))

If these are the only interrupt sources that the driver enables, this is fine.

drivers/gpu/drm/bridge/adv7511/adv7511_drv.c static int adv7511_irq_process(struct adv7511 · line 484

Quoted 1 line
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +1 -0
+               return -1;

Maybe a defined error code instead ?

Quoted 45 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +1 -0
+
        regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
        regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);

With this, I would expect adv7511_irq_handler to return IRQ_NONE. If you're OK with that approach, I can do that. If you want me to merge adv7511_irq_handler, and adv7511_irq_process, I can do that too to make the return codes a little more intuitive.

Quoted 36 lines
        regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
        regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);

        if (process_hpd && irq0 & ADV7511_INT0_HPD && adv7511->bridge.encoder)
                schedule_work(&adv7511->hpd_work);

        if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) {
                adv7511->edid_read = true;

                if (adv7511->i2c_main->irq)
                        wake_up_all(&adv7511->wq);
        }
#ifdef CONFIG_DRM_I2C_ADV7511_CEC
        adv7511_cec_irq_process(adv7511, irq1);

#endif

        return 0;
}

static irqreturn_t adv7511_irq_handler(int irq, void *devid)

{
        struct adv7511 *adv7511 = devid;
        int ret;

        ret = adv7511_irq_process(adv7511, true);
        return ret < 0 ? IRQ_NONE : IRQ_HANDLED;
}

The function will return IRQ_HANDLED as long as the registers can be read, even if they don't report any interrupt.

Quoted 3 lines
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +0 -0
                                              adv7511);
              if (ret)
                      goto err_unregister_audio;
Signature · 3 lines
Regards,

Laurent Pinchart