ARM Linux 3.x的设备树(Device Tree)
时间:11-09
来源:互联网
点击:
- match[]__initconst={
- 490"arm,vexpress",
- 491"xen,xenvm",
- 492NULL,
- 493};
- 495DT_MACHINE_START(VEXPRESS_DT,"ARM-VersatileExpress")
- 496.dt_compat=v2m_dt_match,
- 497.smp=smp_ops(vexpress_smp_ops),
- 498.map_io=v2m_dt_map_io,
- 499.init_early=v2m_dt_init_early,
- 500.init_irq=v2m_dt_init_irq,
- 501.timer=&v2m_dt_timer,
- 502.init_machine=v2m_dt_init,
- 503.handle_irq=gic_handle_irq,
- 504.restart=vexpress_restart,
- 505MACHINE_END
譬如arch/arm/mach-exynos/mach-exynos5-dt.c的EXYNOS5_DT machine同时兼容"samsung,exynos5250"和"samsung,exynos5440":
[cpp]view plaincopy
- 158staticcharconst*exynos5_dt_compat[]__initdata={
- 159"samsung,exynos5250",
- 160"samsung,exynos5440",
- 161NULL
- 162};
- 163
- 177DT_MACHINE_START(EXYNOS5_DT,"SAMSUNGEXYNOS5(FlattenedDeviceTree)")
- 178/*Maintainer:KukjinKim
*/ - 179.init_irq=exynos5_init_irq,
- 180.smp=smp_ops(exynos_smp_ops),
- 181.map_io=exynos5_dt_map_io,
- 182.handle_irq=gic_handle_irq,
- 183.init_machine=exynos5_dt_machine_init,
- 184.init_late=exynos_init_late,
- 185.timer=&exynos4_timer,
- 186.dt_compat=exynos5_dt_compat,
- 187.restart=exynos5_restart,
- 188.reserve=exynos5_reserve,
- 189MACHINE_END
它的.init_machine成员函数就针对不同的machine进行了不同的分支处理:
[cpp]view plaincopy
- 126staticvoid__initexynos5_dt_machine_init(void)
- 127{
- 128…
- 149
- 150if(of_machine_is_compatible("samsung,exynos5250"))
- 151of_platform_populate(NULL,of_default_bus_match_table,
- 152exynos5250_auxdata_lookup,NULL);
- 153elseif(of_machine_is_compatible("samsung,exynos5440"))
- 154of_platform_populate(NULL,of_default_bus_match_table,
- 155exynos5440_auxdata_lookup,NULL);
- 156}
使用Device Tree后,驱动需要与.dts中描述的设备结点进行匹配,从而引发驱动的probe()函数执行。对于platform_driver而言,需要添加一个OF匹配表,如前文的.dts文件的"acme,a1234-i2c-bus"兼容I2C控制器结点的OF匹配表可以是:
[cpp]view plaincopy
- 436staticconststructof_device_ida1234_i2c_of_match[]={
- 437{.compatible="acme,a1234-i2c-bus",},
- 438{},
- 439};
- 440MODULE_DEVICE_TABLE(of,a1234_i2c_of_match);
- 441
- 442staticstructplatform_driveri2c_a1234_driver={
- 443.driver={
- 444.name="a1234-i2c-bus",
- 445.owner=THIS_MODULE,
- 449.of_match_table=a1234_i2c_of_match,
- 450},
- 451.probe=i2c_a1234_probe,
- 452.remove=i2c_a1234_remove,
- 453};
- 454module_platform_driver(i2c_a1234_driver);
对于I2C和SPI从设备而言,同样也可以透过of_match_table添加匹配的.dts中的相关结点的compatible属性,如sound/soc/codecs/wm8753.c中的:
[cpp]view plaincopy
- 1533staticconststructof_device_idwm8753_of_match[]={
- 1534{.compatible="wlf,wm8753",},
- 1535{}
- 1536};
- 1537MODULE_DEVICE_TABLE(of,wm8753_of_match);
- 1587staticstructspi_driverwm8753_spi_driver={
- 1588.driver={
- 1589.name="wm8753",
- 1590.owner=THIS_MODULE,
- 1591.of_match_table=wm8753_of_match,
- 1592},
- 1593.probe=wm8753_spi_probe,
- 1594.remove=wm8753_spi_remove,
- 1595};
- 1640staticstructi2c_driverwm8753_i2c_driver={
- 1641.driver={
- 1642.name="wm8753",
- 1643.owner=THIS_MODULE,
- 1644.of_match_table=wm8753_of_match,
- 1645},
- 1646.probe=wm8753_i2c_probe,
- 1647.remove=wm8753_i2c_remove,
- 1648.id_table=wm8753_i2c_id,
- 1649};
[cpp]view plaincopy
- 90staticintspi_match_device(structdevice*
ARMLinux设备 相关文章:
- ARM嵌入式Linux设备树简介及应用示例(11-21)
- ARM嵌入式LINUX设备驱动设计入门学习(11-19)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)