调用to_i2c_driver宏将其转换为 `struct i2c_driver 结构体指针。 代码检查driver的id_table字段是否为空。id_table是一个指向 I2C 驱动程序支持的设备 ID 表的指针。如果id_table不为空,则调用i2c_match_id函数,将driver->id_table和client作为参数进行匹配。如果匹配成功,即找到了匹配的设备 ID,函数返回的结果...
hello_drv_id_table表示以传统方式匹配设备和驱动程序。hello_i2c_of_match表示以设备树方式匹配。现在大多数都是以设备树方式匹配。 /*传统方式匹配*/ staticconststructi2c_device_idhello_drv_id_table[] ={ {"hello_i2c",0}, {}, }; /* 设备树匹配表 */ staticconststructof_device_idhello_i2c_of_ma...
id_table: 此驱动支持的I2C设备列表。 detect: 设备检测的回调函数。 address_list: 用于检测的I2C地址列表。 clients: 驱动内部使用的检测到的客户端列表。 struct i2c_driver { unsigned int class; /* Standard driver model interfaces */ int (*probe)(struct i2c_client *client, const struct i2c_device_...
hello_drv_id_table表示以传统方式匹配设备和驱动程序。hello_i2c_of_match表示以设备树方式匹配。现在大多数都是以设备树方式匹配。 /*传统方式匹配*/ static const struct i2c_device_id hello_drv_id_table[] = { {"hello_i2c",0}, {}, }; /* 设备树匹配表 */ static const struct of_device_id hel...
id_table:用于指定驱动程序支持的I2C设备ID列表,以便匹配对应的设备。 这些结构体共同构成了Linux内核中的I2C驱动框架,提供了对I2C总线、适配器和设备的抽象和管理功能。开发者可以基于这些结构体来编写自己的I2C驱动程序,并实现与I2C设备的通信和控制。所以我们的工作就是填充这些结构体然后调用对应的接口把我们填充好的...
.id_table = at24c02_ids, }; /* 2. 在入口函数注册platform_driver */ static int __init at24c02_init(void) { int err; printk("%s %s line %d\n", __FILE__, __FUNCTION__, __LINE__); return i2c_add_driver(&at24c02_drv);
.id_table = max1668_id, .detect = max1668_detect, .address_list = max1668_addr_list, }; module_i2c_driver(max1668_driver); 其中,detect函数 登录后复制/* Return 0 if detection is successful, -ENODEV otherwise */staticintmax1668_detect(structi2c_client *client,structi2c_board_info *info...
int(*probe)(struct i2c_client*,conststruct i2c_device_id*) 当I2C设备和驱动匹配成功以后 probe函数就会执行。 代码语言:javascript 复制 struct device_driver driver device_driver 驱动结构体,如果使用设备树的话,需要设置device_driver的of_match_table成员变量,也就是驱动的兼容(compatible)属性。
int (*probe)(struct i2c_client *, const struct i2c_device_id *); //probe函数 struct device_driver driver; //表明这是一个驱动 const struct i2c_device_id *id_table; //要匹配的从设备信息(名称) int (*detect)(struct i2c_client *, struct i2c_board_info *); //设备探测函数 ...
int (*probe)(struct i2c_client *client, const struct i2c_device_id *id); //匹配成功执行probe函数 int (*remove)(struct i2c_client *client);//分离时执行remove函数 struct device_driver driver; //父类 const struct i2c_device_id *id_table; //idtable匹配 ...