??????????????????в????У?????????????????????????????????????????????I/O????????????????????????豸?????????????????????????????????????????豸???????????????????????ж????????????????????????????У???????????????????????????????軔???????????ж???????????????????????????????????
????1.?????????????????
????2 ?????????е??й??????
????2.1 ?????豸????????????
#define MAX KEY BUF 16 // ??????????С
typedef unsigned char KEY RET;
//?豸???壺
typedef struct
{
unsigned int keyStatus[KEY NUM]; //4?? ???? ????
KEY RET buf[MAX KEY BUF]; // ????????
unsigned int head?? tail; // ???????????β
wait queue head t wq; //???????
struct cdev cdev;      //cdev ????
} KEY DEV;
static struct timer list key timer[KEY NUM];//4?? ??????????
????2.2 ??????????????????????
static struct key info
{
int irq no;      //?ж??
unsigned int gpio port; //GPIO???
int key no;     //???
} key info tab [4] =
{
/* ????????CPU ???*/
{  IRQ EINT10?? GPIO G2?? 1
}
??
{
IRQ EINT13?? GPIO G5?? 2
}
??
{
IRQ EINT14?? GPIO G6?? 3
}
??
{
IRQ EINT15?? GPIO G7?? 4
}
??
};
????2.3 ?????豸???????????????
????static struct file operations s3c2410 key fops =
????{
????owner: THIS MODULE??
????open: s3c2410 key open??  //????豸
????release: s3c2410 key release??  //????豸
????read: s3c2410 key read??  //??? ??????
????};
????3 ?????豸?????????ж??????
????3.1 ???????
static int    init s3c2410 key init (void)
{
...//?????豸??????cdev
request irqs(); //????ж????
keydev .head = keydev .tail = 0; //?????????
for (i = 0; i < KEY NUM; i++)
keydev.keyStatus[i] = KEYSTATUS UP;
init waitqueue head (&(keydev .wq)); //???????
//?????????????????????????
for (i = 0; i < KEY NUM; i++)
setup timer (&key timer[i]?? key timer handler?? i);
//?? ?????????????????????????????
}
????3.2 ж?????
????static void     exit s3c2410 key exit (void)
????{
????free irqs(); //????ж?
????...//????豸??????cdev
????}