Difference between spi_driver.id_table and spi_driver.driver.of_match_table
I am currently trying to understand how linux drivers work. As far as I know, the probe / init function of the driver is called when the kernel parses the corresponding .compatible line in the device tree. However, in the arizona-spi driver, there are several compatible lines that are referenced by different members:
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"
};
This is an excerpt from here .
What is the difference between arizona_spi_driver.id_table and arizona_spi_driver.driver.of_match_table?
source to share
There are several mechanisms for mapping drivers. The id_table is used to find a match from split device tree entries (without a vendor part), while from_match_table is used to find a match from full device tree entries (those that contain a vendor part).
If you check, arizona_of_match is defined like this:
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 is the vendor part for this case, while arizona_spi_ids does not contain the vendor part.
Hence, if you have something like this in your device tree:
compatible = "myvendor, wm5102"
Your device will match id_table , but not against of_match_table as the provider is different.
The kernel will perform the comparison with parametrom__po_pa__pa_pa_1 before the first test id_table (see. Spi_get_device_id in here ). Device mapping priority: from_match_table> acpi_driver> id_table.
source to share