转自:https://blog.csdn.net/tiantao2012/article/details/72779331
一般驱动要同时兼容dt和acpi的话,需要在定义platform_driver的时候同时指定of_match_table和acpi_match_table
static struct platform_driver hns_nic_dev_driver = { .driver = { .name = "hns-nic", .of_match_table = hns_enet_of_match, .acpi_match_table = ACPI_PTR(hns_enet_acpi_match), }, .probe = hns_nic_dev_probe, .remove = hns_nic_dev_remove, };
但是这段code,其实按照下面的写法会更好
static struct platform_driver hns_nic_dev_driver = { .driver = { .name = "hns-nic", .of_match_table = of_match_ptr(hns_enet_of_match), .acpi_match_table = ACPI_PTR(hns_enet_acpi_match), }, .probe = hns_nic_dev_probe, .remove = hns_nic_dev_remove, };
即和ACPI_PTR对应的是of_match_ptr
#ifdef CONFIG_OF #define of_match_ptr(_ptr) (_ptr) #else #define of_match_ptr(_ptr) (null) #endif
同样ACPI_PTR的定义如下:
#ifdef CONFIG_ACPI #define ACPI_PTR(_ptr) (_ptr) #else #define of_match_ptr(_ptr) (null) #endif
但是现实情况是CONFIG_ACPI和CONFIG_OF 会同时定义,因为ACPI启动下需要通过dt来得到systab.