如果你的driver 要兼容dtb和acpi 两种启动方式,基本可以分成两步
第一步:在定义platform_driver match table的时候同时定义acpi和dtb的。例如:
static const struct acpi_device_id mbigen_acpi_match[] = {
{ "HISI0152", 0 },
{}
};
static struct platform_driver mbigen_platform_driver = {
.driver = {
.name = "Hisilicon MBIGEN-V2",
.of_match_table = mbigen_of_match,
.acpi_match_table = ACPI_PTR(mbigen_acpi_match),
},
.probe = mbigen_device_probe,
};
可以同一个table 分别赋值给of_match_table,用于dtb 启动是匹配,acpi_match_table 用于acpi 启动时匹配,注意acpi_match_table 赋值是需要对match table加上ACPI_PTR。
第二步:如果driver需要从dtb或者acpi表中 parse数据的话,需要两种情况都考虑。例如一般的模板如下:
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
err = mbigen_of_create_domain(pdev, mgn_chip);
else if (ACPI_COMPANION(&pdev->dev))
err = mbigen_acpi_create_domain(pdev, mgn_chip);
else
err = -EINVAL;
如果是dtb的话,肯定是定义CONFIG_OF 并且pdev->dev.of_node 不为NULL,否则ACPI的话ACPI_COMPANION(&pdev->dev 肯定不为NULL,注意要对pdev->dev 加上ACPI_COMPANION。
第一步:在定义platform_driver match table的时候同时定义acpi和dtb的。例如:
static const struct acpi_device_id mbigen_acpi_match[] = {
{ "HISI0152", 0 },
{}
};
static struct platform_driver mbigen_platform_driver = {
.driver = {
.name = "Hisilicon MBIGEN-V2",
.of_match_table = mbigen_of_match,
.acpi_match_table = ACPI_PTR(mbigen_acpi_match),
},
.probe = mbigen_device_probe,
};
可以同一个table 分别赋值给of_match_table,用于dtb 启动是匹配,acpi_match_table 用于acpi 启动时匹配,注意acpi_match_table 赋值是需要对match table加上ACPI_PTR。
第二步:如果driver需要从dtb或者acpi表中 parse数据的话,需要两种情况都考虑。例如一般的模板如下:
if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
err = mbigen_of_create_domain(pdev, mgn_chip);
else if (ACPI_COMPANION(&pdev->dev))
err = mbigen_acpi_create_domain(pdev, mgn_chip);
else
err = -EINVAL;
如果是dtb的话,肯定是定义CONFIG_OF 并且pdev->dev.of_node 不为NULL,否则ACPI的话ACPI_COMPANION(&pdev->dev 肯定不为NULL,注意要对pdev->dev 加上ACPI_COMPANION。