1、查找结点:
a、通过节点名字查找:
np = of_find_node_by_name(NULL, “ethernet”);
b、通过节点属性查找:
np = of_find_compatible_node(NULL, NULL, “davicom,dm9000”);
c、通过路径名查找:
np = of_find_compatible_node(”/key”);
2、设备树如下:
srom-cs1@5000000 {
compatible = “simple-bus”;
#address-cells = <1>;
#size-cells = <1>;
reg = <0x5000000 0x1000000>;
ranges;
ethernet@5000000 {
compatible = “davicom,dm9000”;
reg = <0x5000000 0x2 0x5000004 0x2>;
interrupt-parent = <&gpx0>;
interrupts = <6 4>;
davicom,no-eeprom;
mac-address = [00 0a 2d a6 55 a2];
};
};
a、提取地址属性:注意是地址属性reg中的第0和第1个元素;
struct resource con;
struct resource dat;
ret = of_address_to_resource(np, 0, &con);
ret = of_address_to_resource(np, 1, &dat);
b、得到软中断号(映射过的)// interrupts = <6 4>;
irq = of_irq_get(np, 0);
c、找到属性值(私有属性),放到属性结构体中,再从属性结构体中提取name(名字),length(长度),value(属性值)
prop = of_find_property(np, “davicom,no-eeprom”, NULL);