1

I am looking for how to use a gpio as an interrupt using device tree dts file.

previously I did that by using the following code in my dts file

                interrupts = <3 30>;
                #interrupt-cells = <2>;
                interrupt-parent = <&intc>;

where intc is

                intc: interrupt-controller {
                compatible = "brcm,bcm2708-armctrl-ic";
                reg = <0x7e00b200 0x200>;
                interrupt-controller;
                #interrupt-cells = <2>;
                };

But now in 3.18.5 everything changed in the kernel of the rpi, now we need to use the gpio to do the same that we did earlier.

But I stucked in middle of it.

The gpio code is

        gpio: gpio {
        compatible = "brcm,bcm2835-gpio";
        reg = <0x7e200000 0xb4>;
        interrupts = <2 17>, <2 18>;

        gpio-controller;
        #gpio-cells = <2>;

        interrupt-controller;
        #interrupt-cells = <2>;
        };

I need to use this gpio node as my interrupt controller.

How can I do that? How to specify which gpio is to be used as the interrupt? Any suggestions are welcome

1

Are you trying to get interrupts for output gpio ?

Maybe this will help: https://github.com/raspberrypi/linux/issues/808

It seems the gpios with kernel 3.18.5 are a bit unstable, maybe waiting for patches to come is a good idea.

Otherwise, with default DTS the gpio pins are attached to the gpio controller and should benefit from the interrupt controller.

Extracted from 3.18.y pi kernel dts : https://github.com/raspberrypi/linux/blob/rpi-3.18.y/arch/arm/boot/dts/bcm2835-rpi-b.dts

&gpio {
   pinctrl-names = "default";
   pinctrl-0 = <&gpioout &alt0 &alt2 &alt3>;
   gpioout: gpioout {
      brcm,pins = <6>;
      brcm,function = <1>; /* GPIO out */
   };
   alt0: alt0 {
      brcm,pins = <0 1 2 3 4 5 7 8 9 10 11 14 15 40 45>;
      brcm,function = <4>; /* alt0 */
   };
   alt3: alt3 {
      brcm,pins = <48 49 50 51 52 53>;
      brcm,function = <7>; /* alt3 */
   };
   /* I2S interface */
   alt2: alt2 {
      brcm,pins = <28 29 30 31>;
      brcm,function = <6>; /* alt2 */
   };
};

What are you trying to achieve with gpio interrupts ?

Based on your needs you may not need gpio interruptions directly.

It also depends on how are you planning to handle interrupts:

  • sysfs gpio export (/sys/class/gpio/)
  • kernel module
  • Other ?

After struggling with gpios and dts on the beagle bone black I recommend not to change the dts unless necessary as it may change often (kernel compatibility updates...) and require good knowledge of the board.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.