我有一个类似的案例,终于找到了解释:设备树 i2c 设备绑定中似乎有一个未记录的扭曲。
让我们看看 i2c_device_match() (i2c-core-base.c):
/* Attempt an OF style match */
if (i2c_of_match_device(drv->of_match_table, client))
return 1;
在 i2c_of_match_device() (i2c-core-of.c) 中实际发生了什么?:
*i2c_of_match_device(const struct of_device_id *matches,
struct i2c_client *client){
const struct of_device_id *match;
if (!(client && matches))
return NULL;
match = of_match_device(matches, &client->dev);
if (match)
return match;
return i2c_of_match_device_sysfs(matches, client); }
嗯,我们首先尝试使用兼容字段的 Open Firmware 样式匹配,但如果失败,我们仍然调用 i2c_of_match_device_sysfs()。它有什么作用?
i2c_of_match_device_sysfs(const struct of_device_id *matches,
struct i2c_client *client) {
const char *name;
for (; matches->compatible[0]; matches++) {
/*
* Adding devices through the i2c sysfs interface provides us
* a string to match which may be compatible with the device
* tree compatible strings, however with no actual of_node the
* of_match_device() will not match
*/
if (sysfs_streq(client->name, matches->compatible))
return matches;
name = strchr(matches->compatible, ',');
if (!name)
name = matches->compatible;
else
name++;
if (sysfs_streq(client->name, name))
return matches;
}
return NULL; }
答对了!正如您在代码中看到的, i2c_of_match_device_sysfs() 将设备树中的兼容字符串与驱动程序i2c_device_id的名称字段进行比较。另外,如果compatible字段中有逗号,则会对逗号后面的部分进行匹配。
所以在你的情况下,设备树数据
compatible = "adv7ex"
与“adv7ex”匹配
static struct i2c_device_id adv7ex_id[] = {
{ "adv7ex", ADV7EX },
{ } };
MODULE_DEVICE_TABLE(i2c, adv7ex_id);
即使您的兼容是“acme-inc,adv7ex”,就像设备树的推荐符号一样,它仍然会匹配。