在Linux的設備樹中,可以使用platform device節點來描述platform_driver中的設備。以下是一個實現的步驟:
my_device {
compatible = "my_driver";
reg = <0x10000000 0x1000>;
interrupt-parent = <&intc>;
interrupts = <1 IRQ_TYPE_LEVEL_HIGH>;
};
static const struct of_device_id my_of_match[] = {
{ .compatible = "my_driver" },
{}
};
static struct platform_driver my_driver = {
.driver = {
.name = "my_driver",
.of_match_table = of_match_ptr(my_of_match),
},
.probe = my_probe,
.remove = my_remove,
};
module_platform_driver(my_driver);
static int my_probe(struct platform_device *pdev)
{
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "failed to get memory resource\n");
return -ENODEV;
}
// 初始化設備
// 注冊設備
return 0;
}
通過以上步驟,可以實現platform_driver中的設備樹支持,使得驅動程序能夠與設備樹中描述的設備匹配并正確初始化。