在此代码中,内核代码需要/ amba @ 0 / ps7-ethernet @ e000c000 / mdio中的兼容字符串。
它从不执行printk(KERN_ERR“ ... cp是=%s \ r \ n”,cp);
我的问题是设备树的正确方法应该是什么,以便
它可以找到mdio子级并找到兼容的字符串。而且,它不应破坏现有功能。
static int of_get_phy_id(struct device_node *device, u32 *phy_id)
{
struct property *prop;
const char *cp;
unsigned int upper, lower;
int i = 0;
printk(KERN_ERR "... get Ethernet PHY ID");
if(device->name != NULL)
{
printk(KERN_ERR "...type = %s",device->type);
printk(KERN_ERR "...type = %s",device->full_name);
printk(KERN_ERR "...property name = %s",device->properties->name);
}
// never enters here......
of_property_for_each_string(device, "compatible", prop, cp) {
printk(KERN_ERR "...the cp is = %s \r\n", cp);
printk(KERN_ERR "...the prop is = %s \r\n", prop->name);
if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) {
*phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF);
printk(KERN_ERR "...the phy id is = %d \r\n", *phy_id );
return 0;
}
}
printk(KERN_ERR "...ERROR... get Phy ID \r\n");
return -EINVAL;
}
...type = <NULL>
...type = /amba@0/ps7-ethernet@e000c000/mdio
...property name = #address-cells
...ERROR... get Phy ID
这是Yocto的zynq-7000.dtsi 我的DTS看起来像-
amba: amba {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
interrupt-parent = <&intc>;
ranges;
adc: adc@f8007100 {
compatible = "xlnx,zynq-xadc-1.00.a";
reg = <0xf8007100 0x20>;
interrupts = <0 7 4>;
interrupt-parent = <&intc>;
clocks = <&clkc 12>;
};
gem0: ethernet@e000b000 {
compatible = "cdns,zynq-gem", "cdns,gem";
reg = <0xe000b000 0x1000>;
status = "disabled";
interrupts = <0 22 4>;
clocks = <&clkc 30>, <&clkc 30>, <&clkc 13>;
clock-names = "pclk", "hclk", "tx_clk";
#address-cells = <1>;
#size-cells = <0>;
};
gem1: ethernet@e000c000 {
compatible = "cdns,zynq-gem", "cdns,gem";
reg = <0xe000c000 0x1000>;
status = "disabled";
interrupts = <0 45 4>;
clocks = <&clkc 31>, <&clkc 31>, <&clkc 14>;
clock-names = "pclk", "hclk", "tx_clk";
#address-cells = <1>;
#size-cells = <0>;
};
};