of_iomap()函数是从设备树获得地址并映射。但我始终获取失败,折腾了两天,终于找到原因,记录下坑位;
网上说
#address-cells = <1>;
#size-cells = <1>;
是指定其子节点的地址属性,只要子节点用reg =<>,即可。
但是,这样做并不见得奏效。后来参照了别人的设备树才发现:
最重要的是: rangs; 对,是他,少了就不行。
原设备树:
leds {
#address-cells = <1>;
#size-cells = <1>;
compatible = "pwm-leds";
led1 {
reg = <0x40000320 0x04>;
label = "power-led";/*HW control*/
owner = "hd";
};
led2 {
reg = <0x40000324 0x04>;
label = "sys-led";
owner = "ps";
};
led3 {
reg = <0x40000328 0x04>;
label = "link-led";
owner = "pl";
};
led4 {
reg = <0x4000032C 0x04>;
label = "act-led";
owner = "ps";
};
led5 {
reg = <0x40000330 0x04>;
label = "sync-led";
owner = "pl";
};
led6 {
reg = <0x40000334 0x04>;
label = "alarm-led";
owner = "ps";
};
};
#address-cells = <1>; #size-cells = <1>;
现在正确的设备树:
leds {
#address-cells = <1>;
#size-cells = <1>;
compatible = "pwm-leds";
ranges;
led1 {
reg = <0x40000320 0x04>;
label = "power-led";/*HW control*/
owner = "hd";
};
led2 {
reg = <0x40000324 0x04>;
label = "sys-led";
owner = "ps";
};
led3 {
reg = <0x40000328 0x04>;
label = "link-led";
owner = "pl";
};
led4 {
reg = <0x4000032C 0x04>;
label = "act-led";
owner = "ps";
};
led5 {
reg = <0x40000330 0x04>;
label = "sync-led";
owner = "pl";
};
led6 {
reg = <0x40000334 0x04>;
label = "alarm-led";
owner = "ps";
};
};