Handling of IRQ in MPC8xx GPIO

Scott Wood scottwood at freescale.com
Wed Jun 5 07:59:46 EST 2013


On Thu, Feb 21, 2013 at 06:32:36AM -0000, LEROY Christophe wrote:
> This patch allows the use IRQ to notify the change of GPIO status on the MPC8xx
> CPM IO ports. This then allows to associate IRQs to GPIOs in the Device Tree. Ex:
> 	CPM1_PIO_C: gpio-controller at 960 {
> 		#gpio-cells = <2>;
> 		compatible = "fsl,cpm1-pario-bank-c";
> 		reg = <0x960 0x10>;
> 		interrupts = <255 255 255 255 1 2 6 9 10 11 14 15 23 24 26 31>;
> 		interrupt-parent = <&CPM_PIC>;
> 		gpio-controller;
> 	};
> 
> Signed-off-by: Christophe Leroy <christophe.leroy at c-s.fr>
[snip]
> @@ -581,6 +588,30 @@
>  	spin_unlock_irqrestore(&cpm1_gc->lock, flags);
>  }
>  
> +static int __cpm1_gpio16_to_irq(struct of_mm_gpio_chip *mm_gc,
> +		unsigned int gpio)
> +{
> +	struct cpm1_gpio16_chip *cpm1_gc = to_cpm1_gpio16_chip(mm_gc);
> +
> +	return cpm1_gc->irq[gpio] ? cpm1_gc->irq[gpio] : -ENXIO;
> +}

If it's an internal function, why not just pass in cpm1_gc?

Or just open-code it, as it's a one-liner and you don't use it anywhere
else.

Or fix the gpio layer to use 0 to mean "no irq" rather than -ENXIO... :-)

> diff -ur linux-3.7.9/kernel/irq/irqdomain.c linux/kernel/irq/irqdomain.c
> --- linux-3.7.9/kernel/irq/irqdomain.c	2013-02-17 19:53:32.000000000 +0100
> +++ linux/kernel/irq/irqdomain.c	2012-12-13 19:52:38.000000000 +0100
> @@ -763,7 +763,8 @@
>  	BUG_ON(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR);
>  
>  	/* Check revmap bounds; complain if exceeded */
> -	if (WARN_ON(hwirq >= domain->revmap_data.linear.size))
> +	/* 255 is a trick to allow UNDEF value in DTS */
> +	if (hwirq == 255 || WARN_ON(hwirq >= domain->revmap_data.linear.size))
>  		return 0;

NACK.  Besides the hackishness of it, 255 is valid for some interrupt
controllers.

If you need for a way to leave holes in an "interrupts" property, propose
something non-hacky on devicetree-discuss at lists.ozlabs.org.

Or, do what some other devices do, and have a different property that
indicates which pins are connected, and only include those in the
"interrupts" property.  See
Documentation/devicetree/bindings/powerpc/fsl/mpic-msgr.txt and
mpic-msgr-receive-mask as an example.

-Scott



More information about the Linuxppc-dev mailing list