mattmunee
mattmunee

Reputation: 29

GPIO Expander Interrupt Not Working With Dynamic Device Tree Overlay

I have a GPIO expander (TI TCA9539) on board connected to a Raspberry Pi. I've written a device tree overlay as follows:

// Raspberry Pi device tree overlay for TCA9539 GPIO Expander

/dts-v1/;
/plugin/;

/{
        compatible = "brcm,bcm2835";

        fragment@0 {
                target = <&i2cbus>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";

                        exp1: gpio-extender@74 {
                                #address-cells = <1>;
                                compatible = "ti,tca9539";
                                reg = <0x74>;
                                interrupt-parent = <&gpio>; /* Use Pi GPIO as interrupt parent */
                                interrupts = <25 2>;        /* Use GPIO25 as interrupt pin, 2=IRQ_TYPE_EDGE_FALLING */
                                interrupt-names = "gpio-expander";
                                gpio-controller;
                                #gpio-cells = <2>;
                                interrupt-controller;
                                #interrupt-cells = <2>;
                        };
                };
        };

        frag100: fragment@100 {
                target = <&i2c_arm>;
                i2cbus: __overlay__ {
                        status = "okay";
                };
        };
};

When I add this overlay to /boot/firmware/config.txt, everything works as expected, and I can monitor edges using gpiomon. I also see that in /proc/interrupts I have the following line:

 40:          0          0          0          0  pinctrl-bcm2835  25 Edge      1-0074

However, if I remove the overlay from /boot/firmware/config.txt and instead try to load the overlay dynamically using sudo dtoverlay tca9539, the interrupts no longer work. I still see all 16 new GPIO lines appear under "gpiochip2" in gpioinfo, but when I run gpiomon, I receive the following error:

gpiomon: error waiting for events: No such device

I also see that the line is missing from /proc/interrupts.

Is there anyway to retain the interrupt functionality when using a dynamic overlay?

Upvotes: 0

Views: 169

Answers (1)

mattmunee
mattmunee

Reputation: 29

I've managed to solve my issue another way. The reason I was trying to use the dynamic overlay in the first place is because the GPIO expander is on a separate circuit board that may or may not have power when the Pi boots. If the board did not have power during boot, then the device tree driver would fail to load. I now know that I can force a "re-probe" of the driver by executing the following command after the GPIO expander has power.

echo 1-0074 | sudo tee /sys/bus/i2c/drivers/pca953x/bind

This way I can keep the overlay in config.txt, and just execute the command above if the Pi boots when the GPIO expander doesn't have power.

Upvotes: 0

Related Questions