i2c struct i2c_adapter /i2c_client /i2c_driver /i2c_add_driver() /i2c_register_driver()

 1  struct i2c_adapter {
 2     struct module *owner;
 3     unsigned int id;
 4     unsigned int class// 适配器支持的类型,如传感器,eeprom等        
 5     const struct i2c_algorithm *algo;        //该适配器的通信函数    
 6     void *algo_data;
 7     /* data fields that are valid for all devices    */
 8     struct rt_mutex bus_lock;
 9     int timeout;                             //超时时间限定
10     int retries;                             //通信重复次数限定
11     /* 
12      * 内嵌的标准device,其中dev->type标识该设备
13      * 是个adapter,其值为i2c_adapter_type
14 */
15     struct device dev;        
17     int nr;                                  //适配器编号也是bus编号,第几条i2c总线
18     char name[48];                           //名字
19     struct completion dev_released;
20     struct mutex userspace_clients_lock;
21     struct list_head userspace_clients;
22 };
 
 
 
 
 1  struct i2c_client {
2 unsigned short flags; //设备的标志,如唤醒标志等等 3
4 /* chip address - NOTE: 7bit */
5 /* addresses are stored in the */
6 /* _LOWER_ 7 bits */
7 unsigned short addr; //设备的地址 8 char name[I2C_NAME_SIZE]; //设备的名字 9 struct i2c_adapter *adapter; //设备所属的适配器 10 struct i2c_driver *driver; //设备的driver
12 /* 13 * 内嵌的标准device模型,其中dev->type标识该设备 14 * 是个client,其值为i2c_client_type 15 */
16 struct device dev; /* the device structure */
17 int irq; //中断号 18 struct list_head detected; //挂接点,挂接在adapter 19 };

 1   struct i2c_driver {
 2     unsigned int class;                                   //支持的类型,与adapter的class相对
10     /* Standard driver model interfaces */
11     int (*probe)(struct i2c_client *, const struct i2c_device_id *);
12     int (*remove)(struct i2c_client *);
15     int (*suspend)(struct i2c_client *, pm_message_t mesg);
16     int (*resume)(struct i2c_client *);
31     struct device_driver driver; 
33     const struct i2c_device_id *id_table;                            //支持的client信息表
36     int (*detect)(struct i2c_client *, struct i2c_board_info *);     //探测函数
37     const unsigned short *address_list;                              //driver支持的client地址
38     struct list_head clients;                                        //挂接其探测到的支持的设备
39 };

三、i2c_add_driver分析

    驱动端的统一接口为i2c_add_driver:

static inline int i2c_add_driver(struct i2c_driver *driver) { /* *注册i2c driver,可能是adapter的,也可能是client的 */ return i2c_register_driver(THIS_MODULE, driver); } int i2c_register_driver(struct module *owner, struct i2c_driver *driver) {
 
}
    
    
    
    
     /*
      * 如果i2c_driver->id_table存在,也就是支持的设备信息表
      * 存在,那么利用这个表进行匹配
      */
 
 
 
 
 
 




你可能感兴趣的:(c,list,struct,Module,Class,structure)