主题 : 关于IIC EEPROM的问题 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 6147
精华: 0
发帖: 91
金钱: 640 两
威望: 241 点
综合积分: 182 分
注册时间: 2009-05-21
最后登录: 2011-06-23
楼主  发表于: 2010-06-09 18:02

 关于IIC EEPROM的问题

大家好:
    请教个问题,我的网卡驱动中需要读取eeprom的值,绑定MAC地址,现已注册成功了i2c设备,在上层中通过dev/下的i2c
    字符设备节点,是可以正常实现读写的,但是由于网卡驱动是在内核态中,哪么我应该怎么样去访问eeprom了,今天试着
    直接调用i2c_dev.c static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
    unsigned long arg)函数,但是有一个i2c_client结构体变量,这个结构体变量该如何来赋值,应该是把这个eeprom看成一个
    i2c client,注册为一个adapter,后来我就直接用at24.c中的代码copy到网卡驱动中,想直接在网卡驱动中声明一个adapter,
    实现其读写,但是在read时,出现s3c2440-i2c s3c2440-i2c: cannot get bus (error -110),想请教下,这种内核态中一个驱动
    调用另一个驱动该如何来调用呀,可能是我还没有搞清楚内核态驱动的架构?谢谢
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-06-10 14:21
i2c-dev.c里定义的接口是给User Space的应用程序通过/dev/i2c/下面的字符设备读写i2c slave设备用的。
给内核中的其它模块调用的接口i2c_transfer()声明定义在include/linux/i2c.h中:

复制代码
  1. extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
  2.                         int num);
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 6147
精华: 0
发帖: 91
金钱: 640 两
威望: 241 点
综合积分: 182 分
注册时间: 2009-05-21
最后登录: 2011-06-23
2楼  发表于: 2010-06-11 10:34
已经OK,采用的轮询方式,经过多次调试,发现在读eeprom值时,没有加上spin_lock_irq禁止中断,加上以后,正常读取数据,

kasim谢谢,你上面所说的这个我了解,i2c_dev.c是给i2c slave使用的,我现在的盲点就在于
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
                        int num);
这个函数中 i2c_adapter的i2c适配器,是不是可以这样理解,一个client attach到adapter上,如果你想要在网卡在读eeprom,哪么你必须找到eeprom所在的adapter,应该就是i2c-s3c2410.c中的adapter,使用的都是一个算法,但是如何在网卡驱动中获取这个adapter呢?这才是我困惑的?请教下
级别: 侠客
UID: 6147
精华: 0
发帖: 91
金钱: 640 两
威望: 241 点
综合积分: 182 分
注册时间: 2009-05-21
最后登录: 2011-06-23
3楼  发表于: 2010-06-11 10:42
是使用i2c_get_adapter(int id),但是这个id不知道是如何来识别的
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
4楼  发表于: 2010-06-11 10:48
这个函数中 i2c_adapter的i2c适配器,是不是可以这样理解,一个client attach到adapter上,如果你想要在网卡在读eeprom,哪么你必须找到eeprom所在的adapter,应该就是i2c- s3c2410.c中的adapter,使用的都是一个算法,

是的,i2c_transfer()的作用在于向一个连接在指定的i2c adapter(即s3c2440的I2C Controller)上特定的I2C Slave设备(在i2c_msg结构中指定slave的地址)发送消息。

但是如何在网卡驱动中获取这个adapter呢?这才是我困惑的?请教下

如果你把linux/i2c.h看完的话,应该会看到这样一个接口:
复制代码
  1. extern struct i2c_adapter *i2c_get_adapter(int id);

注意这个接口应该在arch/arm/mach-s3c2440/mach-mini2440.c这样的硬件平台相关代码里调用,因为只有mini2440才知道连接EEPROM的i2c adapter的id。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
5楼  发表于: 2010-06-11 10:49
引用第3楼mikej于2010-06-11 10:42发表的  :
是使用i2c_get_adapter(int id),但是这个id不知道是如何来识别的

id就是向系统注册的i2c adapter的序号,0,1,2...
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 6147
精华: 0
发帖: 91
金钱: 640 两
威望: 241 点
综合积分: 182 分
注册时间: 2009-05-21
最后登录: 2011-06-23
6楼  发表于: 2010-06-11 11:42
这个0 1 2 应该就是i2c0 i2c1 i2c2三个cpu中的编号吧,非常感谢kasim的帮助,谢谢