当前位置: 技术问答>linux和unix
请问下linux的i2c驱动问题
来源: 互联网 发布时间:2016-10-05
本文导语: 这段时间在看linux的i2c实现,在看《i2c源代码情景分析(beta2)》时发现 struct i2c_algorithm { char name[32]; /* textual description */ unsigned int id; int (*master_xfer)(struct i2c...
这段时间在看linux的i2c实现,在看《i2c源代码情景分析(beta2)》时发现
struct i2c_algorithm {
char name[32]; /* textual description */
unsigned int id;
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data);
int(*slave_send)(struct i2c_adapter *,char*,int);
int (*slave_recv)(struct i2c_adapter *,char*,int);
int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
u32 (*functionality) (struct i2c_adapter *);
};
而我在linux-2.6.31的源代码中发现i2c_algorithm定义如下
struct i2c_algorithm {
/* If an adapter algorithm can't do I2C-level access, set master_xfer
to NULL. If an adapter algorithm can do SMBus access, set
smbus_xfer. If set to NULL, the SMBus protocol is simulated
using common I2C messages */
/* master_xfer should return the number of messages successfully
processed, or a negative value on error */
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
int num);
int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data *data);
/* To determine what the adapter supports */
u32 (*functionality) (struct i2c_adapter *);
};
在源码的Documentation中提到目前i2c只支持master模式(从上面的结构体也印证了这一点,只有master_xfer)。
从《i2c源代码情景分析(beta2)》来看,是有slave模式的,
我的问题是2.6.31是比较新的内核了,《i2c源代码情景分析(beta2)》是几年前的东西了,为什么较新的i2c驱动功能反而少了呢????
struct i2c_algorithm {
char name[32]; /* textual description */
unsigned int id;
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data);
int(*slave_send)(struct i2c_adapter *,char*,int);
int (*slave_recv)(struct i2c_adapter *,char*,int);
int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
u32 (*functionality) (struct i2c_adapter *);
};
而我在linux-2.6.31的源代码中发现i2c_algorithm定义如下
struct i2c_algorithm {
/* If an adapter algorithm can't do I2C-level access, set master_xfer
to NULL. If an adapter algorithm can do SMBus access, set
smbus_xfer. If set to NULL, the SMBus protocol is simulated
using common I2C messages */
/* master_xfer should return the number of messages successfully
processed, or a negative value on error */
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
int num);
int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data *data);
/* To determine what the adapter supports */
u32 (*functionality) (struct i2c_adapter *);
};
在源码的Documentation中提到目前i2c只支持master模式(从上面的结构体也印证了这一点,只有master_xfer)。
从《i2c源代码情景分析(beta2)》来看,是有slave模式的,
我的问题是2.6.31是比较新的内核了,《i2c源代码情景分析(beta2)》是几年前的东西了,为什么较新的i2c驱动功能反而少了呢????
|
你再仔细看看源码;其实都是简单的调用了i2c_transfer()函数而已,并无区别。
|
你看的代码是不同平台的吧。某些平台 如DaVinci 确实只有master模式。
|
应该是用不上了吧,可以想象只有master端可以跑linux,一般slave端就是一颗小芯片而已。