i2c驱动看下来感觉就像一张找不到头的网,繁复错杂,千丝万缕,很难理清。这还只是一个简单的子系统,还有复杂的USB总线,更别提内核的复杂了,哎,路漫漫其修远兮...anyway,加油!
函数指针和链表在驱动中随处可见,这些也是C语言的精华所在,看着都觉费力,什么时候才能设计出这种高水平的代码来...
1 结构体内容
1.1 struct i2c_adapter
i2c适配器的描述结构体。
/*
* i2c_adapter is the structure used to identify a physical i2c bus along
* with the access algorithms necessary to access it.
*/
struct i2c_adapter {
struct module *owner; /*该结构体所属模块*/
unsigned int id __deprecated;
unsigned int class; /* classes to allow probing for */
const struct i2c_algorithm *algo; /* the algorithm to access the bus */
void *algo_data;
/* data fields that are valid for all devices */
struct rt_mutex bus_lock; /*控制并发访问的自旋锁*/
int timeout; /* in jiffies */
int retries; /*重试次数*/
struct device dev; /* the adapter device */
int nr;
char name[48]; /*适配器的名称*/
struct completion dev_released; /*完成量,用于同步*/
struct mutex userspace_clients_lock;
struct list_head userspace_clients; /*client链表头*/
};
1.2 struct i2c_algorithm
i2c适配器的通信接口结构体
/*
* The following structs are for those who like to implement new bus drivers:
* i2c_algorithm is the interface to a class of hardware solutions which can
* be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
* to name two of the most common.
*/
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_xfe