Other Parts Discussed in Thread: AM3358, TPS65217
Greetings!
I'm using BeagleBone Black (Sitara AM3358) with a LED connected to pin GPIO2_1 and a button with a 3k3 pull-up on GPIO0_7. I want the LED to reflect the state of the push button. I've written a simple device driver.
However I get no interrupt. I can see the correct value of the GPIO with:
cat /sys/kernel/debug/gpio
so it's not a hardware problem. If I do this:
cat /proc/interrupts
I see that my device driver gets no interrupt:
CPU0
7: 1 INTC tps65217
12: 5293 INTC edma
14: 0 INTC edma_error
18: 3436 INTC musb-hdrc.0.auto
....
135: 0 GPIO gpio_test <--- THIS IS FROM MY MODULE
Once I managed to get it working but I did not do anything special ... it just started by itself, randomly. Any help is appreciated!
#include <linux/module.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
static unsigned int irq_num;
void gpio_handler(void)
{
if(gpio_get_value(7)){
gpio_direction_output(65, 1);
}else{
gpio_direction_output(65, 0);
}
}
static int __init thirddrv_init(void)
{
printk("*******thirddrv init *******\n");
gpio_request(7, "thirdingpio");
gpio_direction_input(7);
irq_num = gpio_to_irq(7);
request_irq(irq_num, (irq_handler_t)gpio_handler, 0, "gpio_test", NULL);
gpio_request(65, "thirdoutgpio");
gpio_direction_output(65, 1);
return 0;
}
static void __exit thirddrv_exit(void)
{
printk("*******thirddrv exit*******\n");
gpio_direction_output(65, 0);
gpio_free(65);
free_irq(irq_num, NULL);
gpio_free(7);
}
module_init(thirddrv_init);
module_exit(thirddrv_exit);
MODULE_AUTHOR("L.B.");
MODULE_DESCRIPTION("BeagleBone Black toggle a 0.5 mA LED on GPIO2_1 when GPIO0_7 is pressed. Device driver.");
MODULE_LICENSE("GPL");