Skip to content

gpiod_to_irq()

Purpose

Converts a GPIO descriptor into a Linux IRQ number.

#include <linux/gpio/consumer.h>

Prototype

int gpiod_to_irq(const struct gpio_desc *desc);

Parameters

  • desc: GPIO descriptor returned by a descriptor-based GPIO lookup API.

Return Value

  • Success: IRQ number.
  • Failure: negative errno.

Minimal Example

irq = gpiod_to_irq(priv->button);
if (irq < 0)
    return irq;

ret = devm_request_threaded_irq(dev, irq, NULL, button_irq_thread,
                                IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
                                "my-button", priv);

Common Pitfalls

  • Not every GPIO line can necessarily be used as an IRQ on every platform.
  • Use Device Tree interrupt properties directly when the hardware interrupt is not modeled as a GPIO.
  • Check the return value before passing it to IRQ request APIs.