Detecting Interrupt on Gpio in Kernel Module

How to provide interrupt generating GPIOs from a kernel module

In order to test GPIO library inside the kernel the gpio-sim module has been created which emulates what regular GPIO chip can do, including interrupt generation.

The code responsible for that is located in the gpio_sim_apply_pull(). Don't look at the function name, because it just applies the full state of the artificial line.

Note, that in the older kernels the gpio-mockup driver is present for the similar purposes.

How to detecting interrupt on a GPIO line in Embedded Linux?

Make the GPIO pin explicitly to detect falling edge.

At the gpio module level it is necessary to enable FALLING_DETECT of gpio.

GPIO IRQ on ARM based Embedded Linux

I assume you are triggering your interrupts with an external system (maybe a microcontroller or something that can toggle the GPIOS). Since I do not see a real ack of the interrupt, I assume the external system does not wait for the interrupt to be handled to maybe trigger a new one.

printk is a very slow function and that's why you can miss some interrupts: a new one can be triggered while you are still handling the previous one.

So I would advise not to use printk in the handler. If you want to achieve something like this, it would be better to use a tasklet or a workqueue as the bottom half of the interrupt handler.

I can only recommend the reading of the Chapter 10 of Linux Device Drivers.

Oh and by the way, your IRQ handler should not return 0 but IRQ_HANDLED.



Related Topics



Leave a reply



Submit