#include <linux/fs.h> #include <linux/module.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/cdev.h> #include <linux/ioport.h> #include <linux/pci.h> #include <asm/uaccess.h> #include <asm/io.h> #include <asm/irq.h> #include <linux/interrupt.h> #include <asm/mach/irq.h> static int major = 0; static struct class *cls; /* gpecon 0x56000040 */ /* gpfcon 0x56000050 */ /* gpgcon 0x56000060 */ static volatile unsigned long *gpecon; static volatile unsigned long *gpedat; static volatile unsigned long *gpfcon; static volatile unsigned long *gpfdat; static volatile unsigned long *gpgcon; static volatile unsigned long *gpgdat; static irqreturn_t buttons_irq(int irq, void *dev_id) { //char *str = (char *)dev_id; printk("irq = %d, dev_id = %d\n", irq, (int)dev_id); return IRQ_HANDLED; } static irqreturn_t buttons_irq2(int irq, void *dev_id) { //char *str = (char *)dev_id; printk("buttons_irq2 **************\n"); return IRQ_HANDLED; } int buttons_open(struct inode *inode, struct file *file) { return 0; } ssize_t buttons_read(struct file *inode, char __user *buf, size_t size, loff_t *offset) { return 0; } static const struct file_operations buttons_fops = { .owner = THIS_MODULE, .read = buttons_read, .open = buttons_open /* 設定引腳,申請資源 */ }; char *id = "K1"; int buttons_init(void) { major = register_chrdev(0, "buttons", &buttons_fops); /* sysfs */ cls = class_create(THIS_MODULE, "buttons_class"); class_device_create(cls, NULL, MKDEV(major, 0), NULL, "buttons"); gpecon = ioremap(0x56000040, 4096); gpedat = gpecon + 1; gpfcon = gpecon + 4; gpfdat = gpfcon + 1; gpgcon = gpecon + 8; gpgdat = gpgcon + 1; /* 註冊中斷 共用中斷號*/ request_irq(IRQ_EINT0, buttons_irq, IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "K10_irq", 'a'); request_irq(IRQ_EINT0, buttons_irq2, IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "K10_irq_other", 'b'); /* 設定GPIO為中斷引腳 * 設定觸發方式 * 使能中斷 */ /* 設定KSCAN0(GPE11)為輸出引腳,輸出0 */ *gpecon &= ~(0x3 << 22); *gpecon |= (1 << 22); *gpedat &= ~(1<<11); return 0; } void buttons_exit(void) { unregister_chrdev(major, "buttons"); class_device_destroy(cls, MKDEV(major, 0)); class_destroy(cls); iounmap(gpecon); free_irq(IRQ_EINT0, 'a'); free_irq(IRQ_EINT0, 'b'); } module_init(buttons_init); module_exit(buttons_exit); MODULE_LICENSE("GPL"); |