linux-spi_driver.id_table和spi_driver.driver.of_match_table之间的区别
作者:互联网
我目前正在尝试了解linux驱动程序的工作方式.据我所知,当内核解析设备树中相应的.compatible字符串时,将调用驱动程序的probe / init函数.但是,在arizona-spi驱动程序中,看起来好像有多个在不同成员中引用的兼容字符串:
static const struct spi_device_id arizona_spi_ids[] = {
{ "wm5102", WM5102 },
{ "wm5110", WM5110 },
{ },
};
MODULE_DEVICE_TABLE(spi, arizona_spi_ids);
static struct spi_driver arizona_spi_driver = {
.driver = {
.name = "arizona",
.owner = THIS_MODULE,
.pm = &arizona_pm_ops,
// Contains e.g. "wlf,wm5102"
.of_match_table = of_match_ptr(arizona_of_match),
},
.probe = arizona_spi_probe,
.remove = arizona_spi_remove,
.id_table = arizona_spi_ids, // Contains "wm5102" and "wm5110"
};
这是here的摘录.
那么arizona_spi_driver.id_table和arizona_spi_driver.driver.of_match_table有什么区别?
解决方法:
有几种驱动程序匹配的机制. id_table用于从剥离的设备树条目(无供应商部分)中查找匹配项,而of_match_table用于从完整设备树项(具有供应商部分中的条目)查找匹配项.
如果检查,则将arizona_of_match定义为:
const struct of_device_id arizona_of_match[] = {
{ .compatible = "wlf,wm5102", .data = (void *)WM5102 },
{ .compatible = "wlf,wm5110", .data = (void *)WM5110 },
{ .compatible = "wlf,wm8280", .data = (void *)WM8280 },
{ .compatible = "wlf,wm8997", .data = (void *)WM8997 },
{},
};
wlf是这种情况下的供应商部分,而arizona_spi_ids不包含供应商部分.
因此,如果您的设备树中包含以下内容:
compatible = “myvendor,wm5102”
您的设备将与id_table匹配,但不会与of_match_table匹配,因为供应商不同.
内核将在检查id_table之前首先与of_match_table进行匹配(请参见here中的spi_get_device_id).设备匹配优先级为:of_match_table> acpi_driver> id_table.
标签:device-tree,linux-kernel,linux-device-driver,linux 来源: https://codeday.me/bug/20191029/1956778.html