0

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?

6
  • The unit-address in the node-name, gpio-extender@77 should match the first address specified in the reg property of thar node, reg = <0x74>; Commented Aug 14, 2024 at 1:23
  • @sawdust thank you for your time. That must be a holdover from when I was working with the evaluation board. I've changed the node label to gpio-extender@74, but I have the same behavior. Again, this works totally fine when adding dtoverlay=tca9539 to /boot/firmware/config.txt, but the interrupts do not work if I call sudo dtoverlay tca9539 at runtime (with the overlay removed from config.txt). Commented Aug 14, 2024 at 3:51
  • Obviously you have something else at runtime that occupies pin 25 that is used for the interrupt. So when it’s in the config.txt, your expander does this, but something else stops working. Commented Aug 14, 2024 at 5:43
  • @0andriy is there any log i could check to confirm your theory or to get more information on why it would fail? dmesg shows nothing different. I've tried 25 and 27 already with the same behavior. gpioinfo shows both as unused. Commented Aug 14, 2024 at 13:06
  • Without any insinuation, I'd just wanted to gently suggest that there might be a more suitable site for this type of question: raspberrypi.stackexchange.com. Your question seems to be less about programming. Commented Aug 14, 2024 at 19:12

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

It is called a workaround, as it doesn’t really solve the problem.
Glad to hear that! But still, not a solution :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.