What irq number should I put for request_irq()?

711 views
Skip to first unread message

Noge

unread,
Oct 12, 2011, 2:14:50 AM10/12/11
to Beagle Board
Hi,

I did a "request_irq()", the return value is a non-zero value,
indicating request failure.

I suspect it is because I put the wrong irq number into the first
argument. The related portion of code:

//----------- code ---------------
ret = request_irq( 29, irq_handler, 0, "IRQ!",(void*)(irq_handler));

if (ret==0)
printk(KERN_ALERT "success request irq\n");
else
printk(KERN_ALERT "FAIL! request irq!\n");
//----------- code ends ---------------

I got the number 29 from the processor technical reference manual
which can be found here:
http://www.ti.com/litv/pdf/sprugn4n

Referring to Table 12-4 at page 2419, "Interrupt Mapping to the MPU
Subsystem", it says IRQ 29 is mapped to GPIO module 1; since the user
button stays in GPIO module 1, and that's how I got 29.

So my questions are:
1. What number should I put in the first argument? or which portion of
the technical reference should I refer to? I've been re-reading the
"Interrupt Controller" and "General-Purpose Interface" a few times,
but it doesn't seem to help...
2. Is there any examples out there for using interrupt on beagleboard-
xM?

I read the LDD3, and The Linux Kernel Module Programming Guide, I
understand the main flow of requesting interrupt, handling interrupt,
and scheduling the bottom halves, but they don't teach about how to
find the irq number...

Thanks for any help!

2bl...@gmail.com

unread,
Oct 12, 2011, 9:46:06 AM10/12/11
to beagl...@googlegroups.com

So my questions are:
1. What number should I put in the first argument? or which portion of
the technical reference should I refer to? I've been re-reading the
"Interrupt Controller" and "General-Purpose Interface" a few times,
but it doesn't seem to help...


For omap platform code use OMAP_GPIO_IRQ() from arch/arm/plat-omap/include/plat/gpio.h
For platform independent code, use gpio_to_irq() from drivers/gpio/gpiolib.c

You can look at the code for OMAP_GPIO_IRQ to learn the details of how it all correlates to the TRM.

2. Is there any examples out there for using interrupt on beagleboard-
xM?

Yeah, try looking at the board-*.c files under arch/arm/mach-omap2, something similar such as board-omap3evm.c might be a good place to start.
 

After you get the system booted up, do `cat /proc/interrupts` and you see your interrupt there. The number will be the value from OMAP_GPIO_IRQ/gpio_to_irq and your string should match exactly.

Also, make sure you configure the pin you're trying to use as a GPIO (aka MUXMODE_4).  I also typically also do a gpio_request() to prevent userspace from mucking with the gpio.  If you request the gpio, then you can view it via the gpio debugfs interface (make sure it's compiled in to your kernel). Then mount (mount -t debugfs debugfs /sys/kernel/debug) it anywhere and then `cat /sys/kernel/debug/gpio` and you should see the direction (should be input for IRQs...), the value, and the IRQ details of that particular gpio.  Also wrt debugfs, /sys/kernel/debug/omap_mux might be handy if you have OMAP_MUX_DEBUG compiled in to your kernel

- Kyle

Noge

unread,
Oct 16, 2011, 5:19:10 AM10/16/11
to Beagle Board
Thanks for your help Kyle!
=============================================================

=>For omap platform code use OMAP_GPIO_IRQ() from
=>arch/arm/plat-omap/include/plat/gpio.h
=>For platform independent code, use gpio_to_irq() from drivers/gpio/
gpiolib.c
=>
=>You can look at the code for OMAP_GPIO_IRQ to learn the details of
how it
=>all correlates to the TRM.

How do I use codes from directories other than the default include
path? I've tried using #include <linux/gpio.h> and #include <linux/asm/
gpio.h> but both failed to compile when I used gpio_to_irq() in my
code. Do I need to copy drivers/gpio/gpiolib.c into my own working
directory manually?

Anyway, my beagle board is xM version and the datasheet says it is
from DaVinci family instead of OMAP. Where should I find the
equivalent of arch/arm/plat-omap/include/plat/ for DaVinci? I can't
seem to find "plat-davinci".

========================================================

=>Yeah, try looking at the board-*.c files under arch/arm/mach-omap2,
=>something similar such as board-omap3evm.c might be a good place to
start.

=>After you get the system booted up, do `cat /proc/interrupts` and
you see
=>your interrupt there. The number will be the value from
=>OMAP_GPIO_IRQ/gpio_to_irq and your string should match exactly.

It seems that there are a lot of codes from the kernel source that I
can study as an example, however, I have a bit of doubts here. There
are so many pieces of code in the kernel source folder, how do I
determine which ones are actually compiled and used in my kernel where
I can do the matching like you mentioned. I mean, I'm sure not all the
codes in the kernel are used, right?

=======================================================
Thanks for the debugging suggestion, I'll give it a try after the
above works.

Any help is much appreciated!
Reply all
Reply to author
Forward
0 new messages