BigW Consortium Gitlab

Commit 6d86e143 by Forest Godfrey

Add basic interrupt registration.

parent acc0c891
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#define IRQ_GPIO_PIN 22
#define GPIO_IRQ_NAME "ai2c_keyboard_irq"
static int irq_num = -1;
static int count = 0;
static irqreturn_t
ai2c_intr_lower(int irq, void *data) {
if (count++ < 10) {
printk("ai2c_intr_lower: entered\n");
}
return IRQ_HANDLED;
}
int
ai2c_init(void) {
int i;
int ret;
int flags = 0;
void *drv_info = NULL;
printk(KERN_INFO "Arduino I2C Keyboard Starting\n");
for (i = 20; i < 35; i++) {
int g;
ret = gpio_request(IRQ_GPIO_PIN, GPIO_IRQ_NAME);
if (ret < 0) {
printk(KERN_ERR "ai2c: IRQ pin reservation failed: error %d\n", ret);
return ret;
}
gpio_direction_input(IRQ_GPIO_PIN);
irq_num = gpio_to_irq(IRQ_GPIO_PIN);
g = gpio_to_irq(i);
printk(KERN_INFO "ai2c: gpio[%d]: irq = %d\n", i, g);
printk(KERN_INFO "ai2c: Reserved pin [%d]: irq = %d\n", IRQ_GPIO_PIN, irq_num);
ret = request_irq(irq_num, ai2c_intr_lower, flags, "ai2c_keyboard", drv_info);
if (ret < 0) {
printk(KERN_ERR "ai2c: request_irq failed: error %d\n", ret);
return ret;
}
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
irq_set_irq_type(irq_num, IRQ_TYPE_EDGE_FALLING);
return 0;
}
void
ai2c_shutdown(void) {
printk(KERN_INFO "Arduino I2C Keyboard Shutting Down\n");
if (irq_num > 0) {
free_irq(irq_num, ai2c_intr_lower);
}
}
module_init(ai2c_init);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment