在嵌入式系统(我工作的地方)领域,操作系统内核通过读取设备树知道要调用哪个设备驱动程序。阅读here,了解我在说什么。
但是,更准确地说,设备树(即描述操作系统将运行的硬件的文件)是在引导时读取的。因此,操作系统读取它,将实例化正确的驱动程序。在设备树的 compatible 字段中,有确切的 key-word 必须与驱动程序的关键字匹配。
例如,假设您有一个带有以下节点的设备树:
ps7_axi_interconnect_0: axi@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "xlnx,ps7-axi-interconnect-1.00.a", "simple-bus";
ranges ;
gic: interrupt-controller@f8f01000 {
#interrupt-cells = < 3 >;
compatible = "arm,cortex-a9-gic";
interrupt-controller ;
reg = < 0xf8f01000 0x1000 >,< 0xf8f00100 0x100 >;
} ;
pl310: pl310-controller@f8f02000 {
arm,data-latency = < 3 2 2 >;
arm,tag-latency = < 2 2 2 >;
cache-level = < 2 >;
cache-unified ;
compatible = "arm,pl310-cache";
interrupts = < 0 34 4 >;
reg = < 0xf8f02000 0x1000 >;
} ;
[ ... more items ... ]
xillybus_0: xillybus@50000000 {
compatible = "xlnx,xillybus-1.00.a";
reg = < 0x50000000 0x1000 >;
interrupts = < 0 59 1 >;
interrupt-parent = <&gic>;
xlnx,max-burst-len = <0x10>;
xlnx,native-data-width = <0x20>;
xlnx,slv-awidth = <0x20>;
xlnx,slv-dwidth = <0x20>;
xlnx,use-wstrb = <0x1>;
} ;
};
请注意字段compatible。
现在,将使用此节点的驱动程序必须具有以下内容:
static struct of_device_id xillybus_of_match[] __devinitdata = {
{ .compatible = "xlnx,xillybus-1.00.a", },
{}
};
MODULE_DEVICE_TABLE(of, xillybus_of_match);
/********something else*******/
static struct platform_driver xillybus_platform_driver = {
.probe = xilly_drv_probe,
.remove = xilly_drv_remove,
.driver = {
.name = "xillybus",
.owner = THIS_MODULE,
.of_match_table = xillybus_of_match,
},
};
要更好地了解发生了什么,请参阅this 简单教程。我希望这会有所帮助。
关于 LED 示例
在这个git repository folder 中,您可以找到一个设备驱动模块,通过读取设备树的compatible 字段,可以设法打开它。在同一个文件夹中,有源 C 文件来测试驱动程序打开和关闭它。你可以通过C代码了解open和close被调用时会发生什么等等。