I2C 的 4 个结构体

1,

struct i2c_driver {
 int id;
 unsigned int class;

 /* Notifies the driver that a new bus has appeared. This routine
  * can be used by the driver to test if the bus meets its conditions
  * & seek for the presence of the chip(s) it supports. If found, it
  * registers the client(s) that are on the bus to the i2c admin. via
  * i2c_attach_client.  (LEGACY I2C DRIVERS ONLY)
  */
 int (*attach_adapter)(struct i2c_adapter *);/*依附i2c_adapter函数指针 */

 int (*detach_adapter)(struct i2c_adapter *);/*脱离i2c_adapter函数指针*/

 /* tells the driver that a client is about to be deleted & gives it
  * the chance to remove its private data. Also, if the client struct
  * has been dynamically allocated by the driver in the function above,
  * it must be freed here.  (LEGACY I2C DRIVERS ONLY)
  */
 int (*detach_client)(struct i2c_client *); /*i2c client脱离函数指针*/

 /* Standard driver model interfaces, for "new style" i2c drivers.
  * With the driver model, device enumeration is NEVER done by drivers;
  * it's done by infrastructure.  (NEW STYLE DRIVERS ONLY)
  */
 int (*probe)(struct i2c_client *, const struct i2c_device_id *);
 int (*remove)(struct i2c_client *);

 /* driver model interfaces that don't relate to enumeration  */
 void (*shutdown)(struct i2c_client *);
 int (*suspend)(struct i2c_client *, pm_message_t mesg);
 int (*resume)(struct i2c_client *);

 /* a ioctl like command that can be used to perform specific functions
  * with the device.
  */
 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);//类似ioctl*/

 struct device_driver driver;/*设备驱动结构体*/

 const struct i2c_device_id *id_table;

 /* Device detection callback for automatic device creation */
 int (*detect)(struct i2c_client *, int kind, struct i2c_board_info *);
 const struct i2c_client_address_data *address_data;
 struct list_head clients;
};



#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)

/**
 

2.

 * struct i2c_client - represent an I2C slave device
 * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;
 * I2C_CLIENT_PEC indicates it uses SMBus Packet Error Checking
 * @addr: Address used on the I2C bus connected to the parent adapter.
 * @name: Indicates the type of the device, usually a chip name that's
 * generic enough to hide second-sourcing and compatible revisions.
 * @adapter: manages the bus segment hosting this I2C device
 * @driver: device's driver, hence pointer to access routines
 * @dev: Driver model device node for the slave.
 * @irq: indicates the IRQ generated by this device (if any)
 * @list: list of active/busy clients (DEPRECATED)
 * @detected: member of an i2c_driver.clients list
 * @released: used to synchronize client releases & detaches and references
 *
 * An i2c_client identifies a single device (i.e. chip) connected to an
 * i2c bus. The behaviour exposed to Linux is defined by the driver
 * managing the device.
 */
struct i2c_client {
 unsigned short flags;  /* div., see below  *//标志
 unsigned short addr;  /* chip address - NOTE: 7bit *///低7位为芯片地址
     /* addresses are stored in the */
     /* _LOWER_ 7 bits  */
 char name[I2C_NAME_SIZE];//设备名称
 struct i2c_adapter *adapter; /* the adapter we sit on */依附的i2c_adapter
 struct i2c_driver *driver; /* and our access routines */依附的i2c_driver
 struct device dev;  /* the device structure  */
 int irq;   /* irq issued by device  */分配给设备中断号
 struct list_head list;  /* DEPRECATED */
 struct list_head detected;
 struct completion released;//用于同步
};
 

3.



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); /*i2c传输函数指针*/

 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,/*smbus传输函数指针*/

      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 *);/*返回适配器支持功能*/
};
 
 

4.




struct i2c_adapter {
 struct module *owner; //所属模块
 unsigned int id; //algorithm 类型 ,定义于i2c_id.h,I2C_ALGO_*****
 unsigned int class;    /* classes to allow probing for */
 const struct i2c_algorithm *algo; /* the algorithm to access the bus */总线通信方法结构体指针
 void *algo_data; //algorithm 私有数据
 /* --- administration stuff. */
 int (*client_register)(struct i2c_client *);  //client 注册时调用
 int (*client_unregister)(struct i2c_client *);//client 注销时调用
 /* data fields that are valid for all devices */
 u8 level;    /* nesting level for lockdep */
 struct mutex bus_lock;/*控制并发访问自旋锁*/
 struct mutex clist_lock;
 int timeout;
 int retries; //重试次数
 struct device dev;  /* the adapter device */ //适配器设备
 int nr;
 struct list_head clients; /* DEPRECATED * /* client链表头*/
/
 char name[48]; //适配器名称
 struct completion dev_released;  //用于同步
}
 
 struct i2c_msg {
2 __u16 addr; /* 设备地址*/
3 __u16 flags; /* 标志 */ 
4 __u16 len; /* 消息长度*/
5 __u8 *buf; /* 消息数据*/
6 };

你可能感兴趣的:(linux内核,c语言)