簡單按鍵中斷驅動,在mini6410開發板上運行良好。
僅供技術交流,請勿商用
- #include <linux/fs.h>
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/irq.h>
- #include <asm/irq.h>
- #include <asm/io.h>
- #include <linux/interrupt.h>
- #include <linux/miscdevice.h>
- #include <linux/cdev.h>
- #include <asm/uaccess.h>
- #include <mach/hardware.h>
- #include <linux/platform_device.h>
- #include <mach/regs-gpio.h>
- #include <mach/gpio-bank-n.h>
- #include <plat/gpio-cfg.h>
-
- #define DEVICE_NAME "button_irq"
-
- static int button_irq_open(struct inode *inode,struct file *filp)
- {
- return 0;
- }
- static int button_irq_release(struct inode *inode,struct file *filp)
- {
- return 0;
- }
- static irqreturn_t button_irq_inter(int nr,void *devid)
- {
- static int count=0;
- count ++;
- printk("%d\n",count);
- return IRQ_RETVAL(IRQ_HANDLED);
- }
- static int button_irq_init()
- {
- unsigned int ret;
- ret = request_irq(IRQ_EINT(0),button_irq_inter,IRQ_TYPE_EDGE_BOTH,"KEY0",NULL);
- return 0;
- }
- static struct file_operations dev_fops =
- {
- .owner = THIS_MODULE,
- .open = button_irq_open,
- .release = button_irq_release,
-
- };
- static struct miscdevice misc =
- {
- .minor = MISC_DYNAMIC_MINOR,
- .name = DEVICE_NAME,
- .fops = &dev_fops,
- };
- static int __init dev_init()
- {
- int ret;
- ret = misc_register(&misc);
- printk("button_irq errno\n");
- button_irq_init();
- return 0;
- }
- static void __exit dev_exit()
- {
- misc_deregister(&misc);
- free_irq(IRQ_EINT(0),NULL);
- }
-
- module_init(dev_init);
- module_exit(dev_exit);
-
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("MUGE0913");