GPIO IRQ Consumer Driver¶
A GPIO IRQ consumer driver uses a GPIO line as an interrupt source. Instead of polling a GPIO input periodically, the driver converts the GPIO descriptor into an IRQ and registers an interrupt handler.
Motivation¶
Without interrupts:
With interrupts:
Interrupt-driven designs reduce CPU usage and improve response latency.
GPIO IRQ Consumer Flow¶
Device Tree
↓
devm_gpiod_get()
↓
gpio_desc
↓
gpiod_to_irq()
↓
Linux IRQ number
↓
request_irq()
↓
ISR
GPIO and IRQ Relationship¶
A GPIO line is not the same as a Linux IRQ number.
Example:
The mapping is provided by the GPIO controller and IRQ subsystem.
GPIO Descriptor to IRQ¶
Drivers typically obtain a GPIO descriptor first:
Then convert it into an IRQ:
The returned IRQ number is used by the Linux IRQ subsystem.
IRQ Registration¶
After obtaining the IRQ number:
The driver provides:
- IRQ number
- Interrupt handler
- Trigger type
- Device context
When the interrupt occurs, the handler is executed.
IRQ Release¶
During driver removal:
The IRQ handler is unregistered and will no longer receive interrupts.
Probe Flow¶
Example:
button = devm_gpiod_get(dev, "button", GPIOD_IN);
irq = gpiod_to_irq(button);
ret = request_irq(
irq,
button_isr,
IRQF_TRIGGER_RISING,
"button",
dev);
Remove Flow¶
Example:
Common Trigger Types¶
| Trigger Type | Description |
|---|---|
| IRQF_TRIGGER_RISING | Interrupt on rising edge |
| IRQF_TRIGGER_FALLING | Interrupt on falling edge |
| IRQF_TRIGGER_HIGH | Interrupt while signal is high |
| IRQF_TRIGGER_LOW | Interrupt while signal is low |
Raspberry Pi Observation¶
The Raspberry Pi GPIO debug information and interrupt table show that GPIO numbers and IRQ numbers are different resources.
Example:
This demonstrates the role of gpiod_to_irq() in converting a GPIO resource into an interrupt resource.
Related Topics¶
- Linux GPIO Consumer Driver
- GPIO Controller Architecture
- GPIO Descriptor and gpiolib
- IRQ Subsystem
- Threaded IRQ