dirvt char / platform / module / drm

platform 驱动与设备树:compatible 如何匹配到 probe

2026-07-02 · platform

很多片上外设没有 PCI ID,内核用 platform 总线挂它们。设备描述常来自设备树,匹配键是 compatible

谁声明设备

uart0: serial@10000000 {
    compatible = "vendor,foo-uart";
    reg = <0x10000000 0x1000>;
    interrupts = <...>;
};

启动解析 DT 后会生成 platform_device,并填好寄存器、中断等资源。

谁声明驱动

static const struct of_device_id foo_of_match[] = {
    { .compatible = "vendor,foo-uart" },
    { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, foo_of_match);

static struct platform_driver foo_driver = {
    .probe  = foo_probe,
    .remove = foo_remove,
    .driver = {
        .name = "foo-uart",
        .of_match_table = foo_of_match,
    },
};

platform 总线比较 of_match_table 与设备的 compatible,命中后调 probe()

排查

常见坑:compatible 拼写不一致、模块没加载、reg/IRQ 资源拿错。

← index