compatible = “aaa,bbb”
当一个驱动支持多个设备的时候,在每个设备的dts中,都会配置各自的compatible,当与driver中的compatible匹配后,会取各自的data。在 __of_match_node中有match++。
Example1
static const struct of_device_id plat_drv_match[] = {
{
.compatible = "aaa,bbb", .data = &bbb_hw_data},
{
.compatible = "aaa,ccc", .data = &ccc_hw_data},
{
}
};
data = of_device_get_match_data(dev);
在bbb.dts中,匹配到第1条,data就用第1条
在ccc.dts中,匹配到第2条,data就用第2条
Example2
static const struct of_device_id maxim4c_of_match[] = {
{
.compatible = "maxim4c,max96712",
.data = (const void *)MAX96712_CHIP_ID
}, {
.compatible = "maxim4c,max96722",
.data = (const void *)MAX96722_CHIP_ID
},
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, maxim4c_of_match);
static struct i2c_driver maxim4c_i2c_driver = {
.driver = {
.name = MAXIM4C_NAME,
.pm = &maxim4c_pm_ops,
.of_match_table = of_match_ptr(maxim4c_of_match),