2、m/arch-pxa/pxa-regs.h>MODULE_LICENSE("GPL");#defineDEVICE_NAME"emdoor_kbd"#defineKEYVALUE_HAVE1#defineKEYVALUE_NO0#defineKPC_DIR1<<5#defineKPC_MAT1<<22staticintEmdoor_kbd_fasync(int,structfile*,int);typedefunsignedcharKBD_RET;structfasync_struct*fasync;//鍵盤結(jié)構(gòu)體定義ty
3、pedefstruct{KBD_RETkbd_buff;/*protectagainstoverrun*/unsignedintkbd_status;wait_queue_head_twq;spinlock_tlock;}KBD_DEV;實現(xiàn)鍵盤驅(qū)動讀操作函數(shù)staticssize_tEmdoor_kbd_read(structfile*filp,char*buffer,size_tcount,loff_t*ppos){KBD_DEV*kbd=filp->private_data;KBD_RETkbd_ret;while(
4、1){if(kbd->kbd_status==KEYVALUE_HAVE){kbd_ret=kbd->kbd_buff;copy_to_user(buffer,&kbd_ret,sizeof(KBD_RET));kbd->kbd_status=KEYVALUE_NO;returnsizeof(KBD_RET);}else{if(filp->f_flags&O_NONBLOCK)return-EAGAIN;interruptible_sleep_on(&(kbd->wq));if(signal_pending(current
5、))return-ERESTARTSYS;}}returnsizeof(KBD_RET);}1、實現(xiàn)鍵盤驅(qū)動中斷服務(wù)例程staticvoidEmdoor_isr_kbd(intirq,void*dev_id,structpt_regs*reg){printk(KERN_EMERG"Emdoor_isr_kbd,Interrupt");intkpc_value;KBD_DEV*kbd=(KBD_DEV*)dev_id;spin_lock_irq(&(kbd->lock));kpc_value=KPC;if(kpc_val
6、ue&KPC_MAT){kbd->kbd_buff=KPAS&0xFF;if(kbd->kbd_buff!=0xFF){switch(kbd->kbd_buff){case0x0:kbd->kbd_buff=5;break;case0x1:kbd->kbd_buff=6;break;case0x2:kbd->kbd_buff=7;break;case0x5:kbd->kbd_buff=8;break;case0x10:kbd->kbd_buff=9;break;case0x11:kbd->kbd_buff=10;break
7、;case0x12:kbd->kbd_buff=11;break;case0x15:kbd->kbd_buff=12;break;case0x20:kbd->kbd_buff=13;break;case0x21:kbd->kbd_buff=14;break;case0x22:kbd->kbd_buff=15;break;case0x25:kbd->kbd_buff=16;break;default:break;}kbd->kbd_status=KEYVALUE_HAVE;}}elseif(kpc_value&KPC_DIR
8、){kbd->kbd_buff=KPDK&0xFF;if(kbd->kbd_buff!=0x0){switch(kbd->kbd_buff){case0x40:kbd->kbd_buff=1;break;case0x2:kbd->kbd_buff=2;break;case0x4:kbd->kbd_buf