What I am trying to achieve is: If ONOFF button is pressed shorter than 5 secs, I will handle interrupt and put the system in sleep mode. For now, I am trying to see a kernel message that says I triggered the interrupt successfully when the button is pressed. I am proceeding from another vendor's basic kernel module example for handling gpio interrupts. I have edited it a little bit:
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/gpio.h>
static int irq_number = -1;
irqreturn_t gpio_isr(int this_irq, void *dev_id)
{
printk("Interrupt happened at gpio:%d\n", irq_number);
return IRQ_HANDLED;
}
static void __exit gpio_interrupt_exit (void)
{
free_irq(irq_number,0);
return;
}
static int __init gpio_interrupt_init (void)
{
int r;
if (irq_number < 0) {
printk("Please specify a valid gpio_number\n");
return -1;
}
r = request_irq(irq_number, gpio_isr, 0, 0, 0);
if (r) {
printk("failure requesting irq %i\n", irq_number);
return r;
}
return 0;
}
MODULE_LICENSE("GPL");
module_param(irq_number, int, 0);
module_init(gpio_interrupt_init);
module_exit(gpio_interrupt_exit);From what I've read from the Reference Manual, ONOFF pin has IRQ 36, so I enter 36 as my irq_number parameter. After installing module, Linux hangs. I guess I am choosing wrong number that points to a busy pin, so that causes the hang.
Is it possible to handle ONOFF pin's interrupt? If so, how can I do it? Thanks in advance.