How to write GPIO interrupt handler in Linux device driver?

I am writing GPIO Device Driver for linux 3.14 on Beagleboard XM (RevB). I have done with simple ON/OFF LED blinking. But stuck at interrupt handler implementation. BB XM has GPIO_7 pin connected to user button. Following is code sample I have implemented. But it is not working. I am able to insert module using insmod. Interrupt is also registered in /proc/interrupts. But handler is not getting invoked.

Am I on right track?

`
#include <linux/gpio.h>
#include <linux/interrupt.h>

#define GPIO 7

int var;

static irqreturn_t irq_handler(int irq, void *dev_id)
{
var++;
printk(“In the Interrupt handler, Count: %d\n”, var);
return IRQ_HANDLED;
}

static int __init hello_init(void)
{
int errno, irq_line;
if((errno = gpio_direction_input(GPIO)) !=0)
{
printk(KERN_INFO “Can’t set GPIO direction, error %i\n”, errno);
gpio_free(GPIO);
return -EINVAL;
}
irq_line = gpio_to_irq(GPIO);
printk (“IRQ Line is %d \n”,irq_line);

errno = request_irq( irq_line, (irq_handler_t)irq_handler, IRQF_TRIGGER_FALLING, “Interrupt123”, NULL );
if(errno<0)
{
printk(KERN_INFO “Problem requesting IRQ, error %i\n”, errno);
}
return 0;
}

static void __exit hello_exit(void)
{
int irq_line;
printk (“Unloading my module.\n”);
irq_line = gpio_to_irq(GPIO);
free_irq(irq_line,NULL);
printk(“Hello Example Exit\n”);
return;
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR(“TheInventor”);
MODULE_DESCRIPTION(“Interrupt Module”);
MODULE_LICENSE(“GPL”);
`

Hi,
Could you help me know where to store the linux/gpio.h file in beagleboard xM?

It is working thank you

What does dmesg look like?

I would have made the variable var look like this

“static int var;”

Also, I would have added a proc to display the current value of var.

Finally, I would have added something this to hello_init():

printk(“Entered hello_init().\n”);

None of these things are strictly necessary, but that’s how I do it. . .

Regards,

Dave Chapman

I have used this driver on dragon 410c platform.

Not on Beagleboard.