在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中的设备树支持,使得驱动程序能够与设备树中描述的设备匹配并正确初始化。