I.MX6Q(TQIMX6Q/TQE9)學習筆記——新版BSP之網卡驅動移植,tqimx6qtqe9
由於對網卡這塊不是很熟悉,誤以為網卡驅動也可以簡單的配置下DTS就可以正常工作了,實際移植中遇到了些問題。閑話少說,下面開始tqimx6q的網卡驅動移植。
DTS編寫
首先在我們的DTS中添加網卡配置,參考sabrelite的DTS,我們可以如下編寫:
&fec { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_enet_1>; phy-mode = "rgmii"; status = "okay";};
開始以為添加以上內容後編譯並燒寫DTB就可以正常工作了,實則不然,還需要添加PHY相關的配置代碼。
PHY配置
開啟arch/arm/mach-imx/mach-imx6q.c,在宏PHY_ID_AR8031附近做如下修改:
static int ar8035_phy_fixup(struct phy_device *dev){ u16 val; /* Ar803x phy SmartEEE feature cause link status generates glitch, * which cause ethernet link down/up issue, so disable SmartEEE */ phy_write(dev, 0xd, 0x3); phy_write(dev, 0xe, 0x805d); phy_write(dev, 0xd, 0x4003); val = phy_read(dev, 0xe); phy_write(dev, 0xe, val & ~(1 << 8)); /* * Enable 125MHz clock from CLK_25M on the AR8031. This * is fed in to the IMX6 on the ENET_REF_CLK (V22) pad. * Also, introduce a tx clock delay. * * This is the same as is the AR8031 fixup. */ ar8031_phy_fixup(dev); /*check phy power*/ val = phy_read(dev, 0x0); if (val & BMCR_PDOWN) phy_write(dev, 0x0, val & ~BMCR_PDOWN); return 0;}#define PHY_ID_AR8035 0x004dd072static void __init imx6q_enet_phy_init(void){ if (IS_BUILTIN(CONFIG_PHYLIB)) { phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK, ksz9021rn_phy_fixup); phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK, ksz9031rn_phy_fixup); phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff, ar8031_phy_fixup); phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffff, ar8035_phy_fixup); }}
即添加AR8035的ID,並初始化AR8035的寄存器,具體的含義我還沒有來得及分析,以上修改參考了:
http://lxr.free-electrons.com/source/arch/arm/mach-imx/mach-imx6q.c
完成以上修改之後重新編譯uImage和dtb,然後燒寫開發板即可。
測試方法
尋求網卡的測試方法目標應該很明確,就是能ping通外網即可,下面是我在tqimx6q上的測試步驟。
Step1. 查看網卡資訊
執行命令:
ifconfig -a
效果如下:
@tqimx6q #ifconfig -aeth0 Link encap:Ethernet HWaddr AA:EF:AE:8A:EA:05 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)lo Link encap:Local Loopback LOOPBACK MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)sit0 Link encap:IPv6-in-IPv4 NOARP MTU:1480 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Step2. 使能網卡eth0,執行命令:
ifconfig eth0 up
效果如下:
@tqimx6q #ifconfig eth0 upfec 2188000.ethernet eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=2188000.ethernet:00, irq=-1)IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready@tqimx6q #libphy: 2188000.ethernet:00 - Link is Up - 100/FullIPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Step3. 動態擷取IP,執行指令:
udhcpc
效果如下:
@tqimx6q #udhcpcudhcpc (v1.22.1) startedSending discover...Sending select for 192.168.0.106...Lease of 192.168.0.106 obtained, lease time 86400
Step4. 將動態擷取的IP設定給網卡eth0,執行指令:
ifconfig eth0 192.168.0.106
之後可以通過命令查看網卡配置資訊:
ifconfig eth0
效果如下:
@tqimx6q #ifconfig eth0 192.168.0.106@tqimx6q #ifconfig eth0eth0 Link encap:Ethernet HWaddr AA:EF:AE:8A:EA:05 inet addr:192.168.0.106 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::a8ef:aeff:fe8a:ea05/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:253 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24238 (23.6 KiB) TX bytes:1152 (1.1 KiB)
Step5. 設定網關,執行指令:
route add default gw 192.168.0.1
Step6. 通過ping指令測試網路狀態,執行指令:
ping 8.8.8.8
效果如下:
@tqimx6q #ping 8.8.8.8PING 8.8.8.8 (8.8.8.8): 56 data bytes64 bytes from 8.8.8.8: seq=0 ttl=43 time=77.409 ms64 bytes from 8.8.8.8: seq=1 ttl=43 time=83.292 ms64 bytes from 8.8.8.8: seq=2 ttl=43 time=88.236 ms64 bytes from 8.8.8.8: seq=3 ttl=43 time=80.713 ms64 bytes from 8.8.8.8: seq=4 ttl=43 time=74.452 ms64 bytes from 8.8.8.8: seq=5 ttl=43 time=78.627 ms
可見,tqimx6q已經可以ping通Google的DNS伺服器了。至此,網卡的移植工作就完成了,PHY相關的配置還沒有仔細研究就來分享了,請見諒。文章編寫匆忙,如有問題請幫忙指出,有疑問可以留言討論。
本文作者:girlkoo
本文連結:http://blog.csdn.net/girlkoo/article/details/45678357