從 Device Tree 到 platform_device
在 Linux 3.10.49 中,核心透過 DT_MACHINE_START 與 MACHINE_END 描述板級資訊。其中 .dt_compat 負責匹配 dts 根節點的 compatible,.init_machine 則是解析 dts 的入口。
註冊流程
- init_machine 回呼進入 of_platform_populate。
- of_default_bus_match_table 會匹配 simple-bus 或 arm,amba-bus。
- of_platform_bus_create 會遞迴拜訪子節點,缺少 compatible 的節點不會被註冊。
- of_platform_device_create_pdata 會檢查 status,並透過 of_device_alloc 建立 platform_device。
- of_device_alloc 會處理 reg、interrupts、of_node 與 device 名稱,最後由 of_device_add 完成註冊。
因此,需要指定寄存器位址的板載設備,通常會放在 compatible 為 simple-bus 的節點下,才能被正確建立。