根据Device Tree生成Platformdevice
1.书写dts文件
要生成platformdevice,首先要定义一个dts文件,Device Tree机制根据这个dts文件生成platform device.
Documentation/devicetree/目录介绍了device tree的使用,dts的书写需要先阅读:
http://devicetree.org/Device_Tree_Usage
例如在arch/arm/boot/dts/目录下有exynos5420.dtsi文件
/ {
compatible ="samsung,exynos5420", "samsung,exynos5";
}
其他dts文件可以像头文件一样包含dtsi文件
dtc可以将dts编译成二进制文件dtb,加载kernel时,dtb的物理地址作为参数传递给kernel,kernel解析dtb并生成device tree对应的platform device。
2.添加machine_desc结构体,例如arch/arm/mach-exynos/exynos.c
staticchar const *const exynos_dt_compat[] __initconst = {
"samsung,exynos3",
"samsung,exynos3250",
"samsung,exynos4",
"samsung,exynos4210",
"samsung,exynos4212",
"samsung,exynos4412",
"samsung,exynos4415",
"samsung,exynos5",
"samsung,exynos5250",
"samsung,exynos5260",
"samsung,exynos5420",
"samsung,exynos5440",
NULL
};
….
DT_MACHINE_START(EXYNOS_DT,"SAMSUNG EXYNOS (Flattened Device Tree)")
/* Maintainer: Thomas Abraham<thomas.abraham@linaro.org> */
/* Maintainer: Kukjin Kim<kgene.kim@samsung.com> */
.l2c_aux_val = 0x3c400001,
.l2c_aux_mask = 0xc20fffff,
.smp = smp_ops(exynos_smp_ops),
.map_io = exynos_init_io,
.init_early = exynos_firmware_init,
.init_irq = exynos_init_irq,
.init_machine = exynos_dt_machine_init,
.init_late = exynos_init_late,
.dt_compat = exynos_