|
小弟我最近在做系统移植,需要完成一个kernel2.6下的i2c键盘驱动程序,i2c控制器应该就是使用的s3c2410芯片里的,还用到一个mega8芯片,我猜应该是作为i2c设备接到总线上,并由这个mega8控制i2c总线上的键盘和ic卡读卡器。由于以前没有写过Linux驱动,基本上算是边学边干。现在手头上有一个基于kernel2.4的,可是好像2.4和2.6区别很大,有些地方不太明白,特来向诸位请教,先谢过了!
这个驱动用到的i2c_client结构体里有一个叫做slvRecvNotify的成员函数,感觉好像是使用设备产生中断后,由这个函数来判断是哪一个设备引发中断,可kernel2.6中已经不再使用了,这个函数是如何被调用的呢?kernel2.6中又是如何取代这个操作的呢?
貌似不能上传附件,附上部分代码,如下,还望诸位前辈能不吝赐教~~~小弟感激不尽!
- static struct i2c_client mega8_client = {
- flags: 0,
- addr: MEGA8_I2CADDRESS,
- adapter: NULL,
- driver: &i2c_mega8_driver,
- name: "I2C Mega8",
- id: 1,
- slvRecvNotify: i2c_mega8_slvRcv, //???
- };
复制代码
- static int i2c_mega8_slvRcv( char *buf, int len, int begin)
- {
- static int index = 0;
- static I2C_MEGA8_BUFFER frame;
- char *p = frame.m_buffer;
- if(begin==1) //the first byte of a i2c frame
- index=0;
- DPRINTK ("mega8 slv Rcv:%d\n",*buf);
- memcpy(p + index, buf, len);
- index += len;
- DPRINTK ("index:%d\n",index);
- if (index >= BUFFER_TYPE_LEN){
- switch (GetI2C_Devtype(frame.m_cmd)){
- case DTYPE_SECURITY:
- break;
- #ifdef CONFIG_I2C_MEGA8_MATRIX_KEYBOARD
- case DTYPE_MKEYB:
- if (index >= sizeof (frame.m_kbd)){
- DPRINTK ("Request kbd:%d\n", RequestArray[DTYPE_MKEYB]);
- if (RequestArray[DTYPE_MKEYB]){
- mega8_kbd_raw((I2C_kbd * )&frame);
- }
- index = 0;
- }
- break;
- #endif
- #if 0//#ifdef CONFIG_I2C_MEGA8_IC_CARD
- case DTYPE_ICCARD:
- if((frame.m_cmd==CMD_ICC_FAILED && index >= ICCARD_COUNT_FAILED_OFFSET) ||
- (index>ICCARD_COUNT_OFFSET && index >= frame.m_iccard.iccard_cnt+ICCARD_COUNT_OFFSET && frame.m_cmd==CMD_ICC_READ)||
- (index>=ICCARD_COUNT_OFFSET && frame.m_cmd==CMD_ICC_WRITE) ||
- (index >= ICCARD_COUNT_PWD_OFFSET && frame.m_cmd == CMD_ICC_VERIFY) ||
- (index >= ICCARD_COUNT_TYPESEL_OFFSET && frame.m_cmd == CMD_ICC_TYPESEL)){
- DPRINTK ("Request ic-card:%d\n", RequestArray[DTYPE_ICCARD]);
- if (RequestArray[DTYPE_ICCARD]){
- mega8_iccard_raw((I2C_ICCard * )&frame);
- }
- index = 0;
- }
- break;
- #endif
- #if 0 //#ifdef CONFIG_I2C_MEGA8_PS2_0
- case DTYPE_PS2_0:
- if(index >= sizeof(frame.m_ps2)){
- DPRINTK ("Request ps2-0:%d\n", RequestArray[DTYPE_PS2_0]);
- if (RequestArray[DTYPE_PS2_0]){
- mega8_ps2_raw0(frame.m_ps2.ps2data);
- }
- index = 0;
- }
- break;
- #endif
- #if 0 //#ifdef CONFIG_I2C_MEGA8_PS2_1
- case DTYPE_PS2_1:
- if(index >= sizeof(frame.m_ps2)){
- DPRINTK ("Request ps2-1:%d\n", RequestArray[DTYPE_PS2_1]);
- if (RequestArray[DTYPE_PS2_1]){
- mega8_ps2_raw1(frame.m_ps2.ps2data);
- }
- index = 0;
- }
- break;
- #endif
- case DTYPE_ALL:
- break;
-
- }
- }
- return 0;
- }
复制代码
|
|