How to Know the Interrupt/Gpio Number for a Specific Pin in Linux

how to know the Interrupt/GPIO number for a specific pin in linux

The Embedded Linux you are using should have a GPIO driver that has #define statements for the GPIO pins. You can then get the IRQ number of the specific GPIO using something like:

irq_num = gpio_to_irq(S3C64XX_GPP(8));

The Linux GPIO lib support for that particular chip is available in the following file:

linux/arch/arm/mach-s3c6400/include/mach/gpio.h

There you will find all the #define statements for the various GPIO.

See the section on GPIO Conventions in their documentation:

http://www.kernel.org/doc/Documentation/gpio/gpio.txt

How to know which pin triggered the interrupt with i.MX6?

From NXP TechSupport answer: "Interrupt source can be obtained reading GPIOx_ISR register described in sect.28.5.7 GPIO interrupt status register (GPIOx_ISR)"

Here is the corresponding register description from this document.

Sample Image

How to handle GPIO interrupt-like handling in Linux userspace

From kernel gpio/sysfs.txt:

"value" ... reads as either 0 (low) or 1 (high). If the GPIO
is configured as an output, this value may be written;
any nonzero value is treated as high.

If the pin can be configured as interrupt-generating interrupt
and if it has been configured to generate interrupts (see the
description of "edge"), you can poll(2) on that file and
poll(2) will return whenever the interrupt was triggered. If
you use poll(2), set the events POLLPRI and POLLERR. If you
use select(2), set the file descriptor in exceptfds. After
poll(2) returns, either lseek(2) to the beginning of the sysfs
file and read the new value or close the file and re-open it
to read the value.

"edge" ... reads as either "none", "rising", "falling", or
"both". Write these strings to select the signal edge(s)
that will make poll(2) on the "value" file return.

This file exists only if the pin can be configured as an
interrupt generating input pin.

The preferred way is usually to configure the interrupt with /sys/class/gpio/gpioN/edge and poll(2) for POLLPRI | POLLERR (important it's not POLLIN!) on /sys/class/gpio/gpioN/value. If your process is some "real-time" process that needs to handle the events in real time, consider decreasing it's niceness.

You can even find some example code on github that uses poll, ex. this repo.

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