这个结构体就是包含了挂载在总线下的从设备信息
,包括:寄存器物理地址、适配器、driver、设备信息、设备名字等信息,且使用的指针,方便调用,所以在驱动中大量使用它作为形参传入函数,进入函数再根据需求进行数据访问,方便管理。
struct i2c_client {
unsigned int flags; /* 设备标志 */
unsigned int addr; /* slave地址,7-bit or 10-bit */
struct i2c_adapter *adapter; /* 适配器 */
struct i2c_driver *driver; /* 该设备驱动 */
int usage_count; /* 访问设备总数 */
struct device dev; /* 设备信息 */
struct list_head list; /* 挂载总线下的设备链表 */
char name[I2C_NAME_SIZE]; /* 设备名称 */
struct completion released;
};
Linux下的i2c驱动的编写有两种类型:Legacy model和Standard driver model
第一种风格的驱动需要自己创建i2c_client,并且需要驱动作者知道i2c设备的地址。第二种风格的驱动不需要自己创建i2c_client,但是需要填写支持的设备列表或者支持设备的地址列表
如果选用第二种方法,需要根据实际情况完善下面的device_id信息
static const struct i2c_device_id xxxx[] = {
{ "xxx,xxxxx", 0 },
{ }
};
有设备树的compatible的值需要和设备树上的保持一致
static const struct of_device_id xxxxxx[] = {
{ .compatible = "xxx,xxxxxxx", },
{ }
};
设备和驱动匹配成功后i2c_client获得数据
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
i2c_driver中的.probe函数就会被执行,i2c_client被传入probe函数。
这个函数是由驱动开发者进行编写,但是这个时候传入的i2c_client信息并不完整,在probe中还会进行填充。
=============================== end ========================================
学习总结得出,如有错误,还望不吝赐教
参考文章:https://blog.csdn.net/u013427264/article/details/42774981
https://blog.csdn.net/antchen88/article/details/80411050
https://zhuanlan.zhihu.com/p/663352981