Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4531

Advanced users • On Raspberry PI 4, how to use GPIO IRQ in LKM? IRQ not firing

$
0
0
On Raspberry PI 4, how to use GPIO IRQ in LKM? IRQ not firing

I have a Raspberry PI 4 connected to a breadboard. On the breadboard is connected a push button and a physical resistance as pull-up like the picture attached (using 5 V as source and GPIO pin 27)

With this simple Linux Kernel Module, it seems like I am never called back when I press the button: the IRQ is never fired.

Code:

$ cat dummy_gpio_irq.c #include <linux/module.h>#include <linux/init.h>#include <linux/gpio.h>#include <linux/interrupt.h> /* IRQ */MODULE_LICENSE("GPL");MODULE_AUTHOR("Dark VADOR");MODULE_DESCRIPTION("A dummy IRQ driver");static unsigned int irq_number;static irqreturn_t gpio_irq_handler(int irq, void *dev_id) {printk("dummy_gpio_irq: interrupt was triggered and ISR was called.\n");return IRQ_HANDLED;}static int __init drv_init(void) {/* Init GPIO */if(gpio_request(27, "rpi-gpio-27")) {printk("dummy_gpio_irq: can't allocate GPIO 27\n");return -1;}/* Set GPIO direction */if(gpio_direction_input(27)) {printk("dummy_gpio_irq: can't set GPIO 27 to input\n");gpio_free(27);return -1;}/* Set IRQ */irq_number = gpio_to_irq(27);if(request_irq(irq_number, gpio_irq_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "dummy_gpio_irq", NULL) != 0) {printk("dummy_gpio_irq: can't request interrupt %d.\n", irq_number);gpio_free(27);return -1;}printk("dummy_gpio_irq: GPIO button is mapped to IRQ %d.\n", irq_number);printk("dummy_gpio_irq: module is initialized into the kernel.\n");return 0;}static void __exit drv_exit(void) {printk("dummy_gpio_irq: module is removed from the kernel.\n");}module_init(drv_init);module_exit(drv_exit);
At run time I get

Code:

$ sudo insmod dummy_gpio_irq.ko$ sudo dmesg | tail[   54.864848] dummy_gpio_irq: loading out-of-tree module taints kernel.[   54.865967] dummy_gpio_irq: GPIO button is mapped to IRQ 56.[   54.865987] dummy_gpio_irq: module is initialized into the kernel.$ cat /proc/interrupts | grep dummy_gpio_irq 56:          0          0          0          0  pinctrl-bcm2835  27 Edge      dummy_gpio_irq# Push the button several times on the Raspberry Pi 4$ sudo dmesg | tail[   54.864848] dummy_gpio_irq: loading out-of-tree module taints kernel.[   54.865967] dummy_gpio_irq: GPIO button is mapped to IRQ 56.[   54.865987] dummy_gpio_irq: module is initialized into the kernel.
The IRQ is never called when I press/release the button.

As Raspberry Pi 4 comes with a new GIC-400 interrupt controller I tired with:

Code:

$ cat /boot/config.txt | grep gicenable_gic=0
and

Code:

$ cat /boot/config.txt | grep gicenable_gic=1
Same behavior in both cases: IRQ are not fired.

Does somebody knows why and how to fix this?
Screenshot from 2024-06-13 21-59-58.png

Statistics: Posted by fghoussen — Thu Jun 13, 2024 8:10 pm — Replies 0 — Views 26



Viewing all articles
Browse latest Browse all 4531

Trending Articles