系统版本:Ubuntu18.04-64
编译器版本:gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)
uboot版本:2018.07 -linux4sam_6.0
板子型号:at91sama5d3x-xplained
MCU型号:sama5d36
原理设计,电源是通过MCU控制的,RST也是通过MCU控制的;外部晶振50M;这样做的好处是,MCU复位之后,PHY芯片一定会被复位,防止PHY由于EMC问题死机,软件复位不了,可以通过电源让芯片强制下电,从而恢复工作;
一、PHY在内核配置中需要使能对应的芯片厂商驱动Micrel公司PHY;
make menuconfig
Device Drivers --->
[*] Network device support --->
[*] Ethernet driver support --->
-*- MDIO bus device drivers ---- //MDIO控制器读取PHY寄存器
-*- PHY Device support and infrastructure --->
<*> Micrel PHYs //Micrel公司的ksz9031和ksz8081
二、修改设备树文件,硬件配置语言,所有的硬件相关信息都需要从设备树中获取。这是新内核的特性。
//arch/arm/boot/dts/at91-sama5d3_xplaint.dts
macb1: ethernet@f802c000 {
phy-mode = "rmii";
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ethernet-phy@1 {
reg = <0x1>;
};
};
三、把编译出的zImage烧录进板子,查看打印信息
内核打印信息
macb f0028000.ethernet: Jack macb_probe phy_interface=2.
macb f0028000.ethernet: macb_mii_init name=f0028000.ethernet,id=ffffffff
libphy: MACB_mii_bus: probed
Generic PHY f0028000.ethernet-ffffffff:07: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f0028000.ethernet-ffffffff:07, irq=POLL)
macb f0028000.ethernet eth0: Cadence GEM rev 0x00020119 at 0xf0028000 irq 46 (ee:ab:c1:d2:e6:c6)
macb f802c000.ethernet: invalid hw address, using random
macb f802c000.ethernet: Jack macb_probe phy_interface=7.
macb f802c000.ethernet: macb_mii_init name=f802c000.ethernet,id=ffffffff
libphy: MACB_mii_bus: probed
Generic PHY f802c000.ethernet-ffffffff:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=f802c000.ethernet-ffffffff:01, irq=POLL)
macb f802c000.ethernet eth1: Cadence MACB rev 0x0001010c at 0xf802c000 irq 47 (06:50:95:f8:63:dc)
全是id=ffffffff,怀疑是MDIO有问题
四、文件系统启动后,通过sys系统查看网卡驱动,使用cat命令查看对应的值,发现PHY的ID依然是全FF;
root@sama5d3-xplained:/sys/bus/mdio_bus/drivers/Generic PHY# ls
bind f0028000.ethernet-ffffffff:07 f802c000.ethernet-ffffffff:01 uevent unbind
root@sama5d3-xplained:/sys/bus/mdio_bus/drivers# cat Generic\ PHY/f802c000.ethernet-ffffffff\:01/phy_id
0x00000000 //没有读取到硬件ID
root@sama5d3-xplained:/sys/bus/mdio_bus/drivers# cat Generic\ PHY/f802c000.ethernet-ffffffff\:01/phy_interface
rmii
root@sama5d3-xplained:/sys/bus/mdio_bus/drivers#
五、设备树配置正确,为什么读取不到ID呢,这时候想起会不会是RST脚的电平是可控的,会不会默认是低,导致PHY不工作呢,电源是不是还没有;
使用万用表测量,发现RST脚还没有高电平。
修改为:电源和RST默认高电平
macb1: ethernet@f802c000 {
phy-mode = "rmii";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-0 = <