How to apply for GPIO interrupt in kernel


New Member

Messages: 1

Hi everybody,
Recently I transplanted an i2c device to FreeBSD on Raspberry 3b+, and needed to use a GPIO interrupt function. When using the gpio_alloc_intr_resource () function, it always returned NULL. I don’t know what went wrong.
And attach DTS configuration :
touchscreen@5d {
     compatible = "goodix,gt9886";
     reg = <0x5d>;
     interrupt-parent = <&gpio>;
     interrupts = <6 IRQ_TYPE_EDGE_FALLING>;
     goodix,irq-gpio = <&gpio 6 GPIO_ACTIVE_HIGH>;

Alexander Mishin


Reaction score: 7
Messages: 24

Sorry, for I late.

It depends on a dev You are passing to the function. I did it somehow like this:
struct yourdriver_softc *sc = device_get_softc(dev);
uint32_t pincaps;
int err;

if ((err = gpio_pin_getcaps(sc->pin, &pincaps)) != 0) {
    device_printf(dev, "Cannot query capabilities of gpio pin\n");
    return (err);
if ((pincaps & GPIO_INTR_EDGE_BOTH) == 0) {
    device_printf(dev, "Pin cannot be configured for both signal edges interrupt\n");
    return (ENOTSUP);
if ((sc->intr_res = gpio_alloc_intr_resource(sc->pin->dev, &sc->intr_rid, RF_ACTIVE,
    sc->pin, GPIO_INTR_EDGE_BOTH)) == NULL) {
        device_printf(dev, "Cannot allocate an IRQ for the GPIO\n");
        return (ENOTSUP);
err = bus_setup_intr(sc->pin->dev, sc->intr_res, INTR_TYPE_MISC | INTR_MPSAFE,
    NULL, rcrecv_ihandler, sc, &sc->intr_cookie);

Note, first argument is not a dev, not a xxxbus (i.e. as a parent of the device), but a pin->dev. Works fine in both cases, for device on either simplebus or gpiobus.
To be precise, it works also with first argument is a dev on a simplebus.

Works fine for me on H3 and H2+ under FreeBSD13-stable.