Getting MCP23008 interrupts functioning via DTB

Post Reply
jass
Posts: 2
Joined: Mon Sep 11, 2023 2:03 am
languages_spoken: english
ODROIDs: C2/C4/SmartPower
Has thanked: 1 time
Been thanked: 0
Contact:

Getting MCP23008 interrupts functioning via DTB

Post by jass »

Hello,

I'm improving the integration of a custom C4 Hat with the tobetter kernel 5.16. The hat consists of a number of devices which are all confirmed working via userspace drivers and kernel integration (IE CAN bus transceiver/driver as network interface, RTC module/PPS setting disciplined clock via crony and GPIO expanders recognized as gpiochips). I also use this hat on separate projects using microcontroller so have 100% confidence in the hardware. I am cross compiling DTBs w/full source tree.

I have two mcp23008s on i2c0. For simplicity, I am only working with one for now. Wiring is as follows
INT - PIN16/GPIOX_0
RST - PIN18/GPIOX_1
I2c0-SDA - PIN3
I2c0-SCL - PIN5

To following is stripped down dts

Code: Select all

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>


/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        // i2c2 aliased with i2c0.
        target = <&i2c2>;

        __overlay__ {
            status = "okay";

            #address-cells = <1>;
            #size-cells = <0>;

            mcp23008: mcp23008@21 {
                status = "okay";
                compatible = "microchip,mcp23008";
                reg = <0x21>;
                #gpio-cells = <2>;
                gpio-controller;

                interrupt-parent = <&gpio_intc>; // MUST be gpio_intc
                interrupts = <GPIOX_0 IRQ_TYPE_LEVEL_LOW>;
                // irq-gpios works with gpio_intc OR gpio..hmm or not at all...
                // perhaps details from interrupt-parent and interrupts is sufficient
                irq-gpios = <&gpio_intc GPIOX_0 GPIO_ACTIVE_LOW>; 
                interrupt-controller;
                #interrupt-cells=<2>;
                reset-gpios = <&gpio GPIOX_1 GPIO_ACTIVE_LOW>;
            };
        };
    };  
};
I've been toying with the following dtb overlay for a while now, permuting through options and have seen the following:

What works:
mcp23008 chip registered as gpiochip
kernel registers an interrupt for the mcp23008 on the expected gpiochip0 line on the 40 pin header (65)
GPIO pins can be toggled/read as expected using libgpiod
monitoring i2c bus traffic, when interrupt is detected, ISR services the gpiochip by inquring for the pin states/CAPVEC to determine interrupt source,.

What doesn't
GPIOX_0 state has no correlation to interrupt firing (ie by monitoring /proc/interrupts).
In the above dts configuration, interrupt should fire when low. With a scope on PIN16 confirming that the level is HIGH, /proc/interrupts is firing continuously.
If I modify DTS by adding/changing interrupts line to

Code: Select all

microchip,irq-active-high
interrupts = <GPIOX_0 IRQ_TYPE_LEVEL_LOW>;
1. PIN16 state changes to LOW (as expected with MPC23008 configuration updated)
2. Interrupts do not fire continuously
3. Manually connecting 3.3V to PIN16 does not cause the interrupt to fire according to /proc/interrupts or by monitoring i2c traffic for the isr's activity

If I migrate the pin on the 40 pin header to something unused/disconnected from the Hat, I see the same behavior (ruling out interaction between the pin on the odroid and the hat circuitry).

My conclusion is that my DTS/DTBO is not correctly configuring the interrupt, or linking the interrupt controller to the gpio.

I appreciate any help
Thanks,
-J

User avatar
joerg
Posts: 1957
Joined: Tue Apr 01, 2014 2:14 am
languages_spoken: german, english, español
ODROIDs: C1, C1+, C2, N1, N2, C4
Location: Germany
Has thanked: 200 times
Been thanked: 431 times
Contact:

Re: Getting MCP23008 interrupts functioning via DTB

Post by joerg »

Take look at this one of my threads: viewtopic.php?p=354373#p354373
There I have explained how to get the right number of interrupt line for a gpio. In your case it would be 77, if I am not wrong. ;)
These users thanked the author joerg for the post:
jass (Tue Sep 12, 2023 12:14 am)

jass
Posts: 2
Joined: Mon Sep 11, 2023 2:03 am
languages_spoken: english
ODROIDs: C2/C4/SmartPower
Has thanked: 1 time
Been thanked: 0
Contact:

Re: Getting MCP23008 interrupts functioning via DTB

Post by jass »

Thank you, solved the issue immediately.

I've set up a gpiokey that is not nicely driving interrupts on the system. Works perfectly until system shutdown (shutdown -h/-r now), which just stops responding (ethernet connection, serial console, no activity). Heartbeat led continues and my gpiokey continues to generate interrupts (can observe via i2c bus as cascading interrupt is serviced).

On hard reboot, tail /var/log/syslog, it seems that adding in the gpio-key driver triggers activity from irqbalance, which seems to be guessing the class of my IRQs every 10s.

Code: Select all

Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ panfrost-job(37) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ panfrost-mmu(38) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ panfrost-gpu(39) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ ff400000.usb(40) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ xhci-hcd:usb1(41) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ cd(42) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ 0-0020(44) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ 0-0021(45) guessed as class 0
Sep 14 01:18:47 server /usr/sbin/irqbalance: IRQ t1(46) guessed as class 0
If I shut down the irqbalance systemd process (which takes ~60s), system can be shut down as normal. Curious what is driving this unusual behavior

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest