天嵌 ARM开发社区

 找回密码
 注册
查看: 3879|回复: 0

I.MX6Q学习笔记——新版BSP之网卡驱动移植

[复制链接]
freewing 发表于 2015-5-22 10:03:21 | 显示全部楼层 |阅读模式
  本文由博主girlkoo编写,关于E9与TQIMX6Q开发平台网卡驱动移植的文章。
  由于对网卡这块不是很熟悉,误以为网卡驱动也可以简单的配置下DTS就可以正常工作了,实际移植中遇到了些问题。闲话少说,下面开始tqimx6q的网卡驱动移植。

  DTS编写

  首先在我们的DTS中添加网卡配置,参考sabrelite的DTS,我们可以如下编写:

  1. &fec {  
  2.     pinctrl-names = "default";  
  3.     pinctrl-0 = <&pinctrl_enet_1>;  
  4.     phy-mode = "rgmii";  
  5.     status = "okay";  
  6. };  
复制代码


  开始以为添加以上内容后编译并烧写DTB就可以正常工作了,实则不然,还需要添加PHY相关的配置代码。

  PHY配置

  打开arch/arm/mach-imx/mach-imx6q.c,在宏PHY_ID_AR8031附近做如下修改:

  1. static int ar8035_phy_fixup(struct phy_device *dev)  
  2. {  
  3.     u16 val;  
  4.       
  5.       
  6.     /* Ar803x phy SmartEEE feature cause link status generates glitch,
  7.     * which cause ethernet link down/up issue, so disable SmartEEE
  8.     */  
  9.     phy_write(dev, 0xd, 0x3);  
  10.     phy_write(dev, 0xe, 0x805d);  
  11.     phy_write(dev, 0xd, 0x4003);  
  12.       
  13.       
  14.     val = phy_read(dev, 0xe);  
  15.     phy_write(dev, 0xe, val & ~(1 << 8));  
  16.       
  17.       
  18.     /*
  19.     * Enable 125MHz clock from CLK_25M on the AR8031.  This
  20.     * is fed in to the IMX6 on the ENET_REF_CLK (V22) pad.
  21.     * Also, introduce a tx clock delay.
  22.     *
  23.     * This is the same as is the AR8031 fixup.
  24.     */  
  25.     ar8031_phy_fixup(dev);  
  26.       
  27.       
  28.     /*check phy power*/  
  29.     val = phy_read(dev, 0x0);  
  30.     if (val & BMCR_PDOWN)  
  31.         phy_write(dev, 0x0, val & ~BMCR_PDOWN);  
  32.       
  33.       
  34.     return 0;  
  35. }  
  36.   
  37. #define PHY_ID_AR8035 0x004dd072  
  38.   
  39. static void __init imx6q_enet_phy_init(void)  
  40. {  
  41.     if (IS_BUILTIN(CONFIG_PHYLIB)) {  
  42.         phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,  
  43.                 ksz9021rn_phy_fixup);  
  44.         phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,  
  45.                 ksz9031rn_phy_fixup);  
  46.         phy_register_fixup_for_uid(PHY_ID_AR8031, 0xffffffff,  
  47.                 ar8031_phy_fixup);  
  48.         phy_register_fixup_for_uid(PHY_ID_AR8035, 0xffffffff,  
  49.                 ar8035_phy_fixup);  
  50.     }  
  51. }  
复制代码

  即添加AR8035的ID,并初始化AR8035的寄存器,具体的含义我还没有来得及分析,以上修改参考了:
  http://lxr.free-electrons.com/so ... ch-imx/mach-imx6q.c
  完成以上修改之后重新编译uImage和dtb,然后烧写开发板即可。

  测试方法
  寻求网卡的测试方法目标应该很明确,就是能ping通外网即可,下面是我在tqimx6q上的测试步骤。
  Step1. 查看网卡信息

  执行命令:
  1. ifconfig -a  
复制代码


  效果如下:

  1. @tqimx6q #ifconfig -a  
  2. eth0      Link encap:Ethernet  HWaddr AA:EF:AE:8A:EA:05   
  3.           BROADCAST MULTICAST  MTU:1500  Metric:1  
  4.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  5.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  6.           collisions:0 txqueuelen:1000   
  7.           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
  8.   
  9. lo        Link encap:Local Loopback   
  10.           LOOPBACK  MTU:65536  Metric:1  
  11.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  12.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  13.           collisions:0 txqueuelen:0   
  14.           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
  15.   
  16. sit0      Link encap:IPv6-in-IPv4   
  17.           NOARP  MTU:1480  Metric:1  
  18.           RX packets:0 errors:0 dropped:0 overruns:0 frame:0  
  19.           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0  
  20.           collisions:0 txqueuelen:0   
  21.           RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)  
复制代码


  Step2. 使能网卡eth0,执行命令:
  1. ifconfig eth0 up  
复制代码


  效果如下:

  1. @tqimx6q #ifconfig eth0 up  
  2. fec 2188000.ethernet eth0: Freescale FEC PHY driver [Generic PHY] (mii_bus:phy_addr=2188000.ethernet:00, irq=-1)  
  3. IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready  
  4. @tqimx6q #libphy: 2188000.ethernet:00 - Link is Up - 100/Full  
  5. IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready  
复制代码


  Step3. 动态获取IP,执行指令:
  1. udhcpc  
复制代码


  效果如下:
  1. @tqimx6q #udhcpc  
  2. udhcpc (v1.22.1) started  
  3. Sending discover...  
  4. Sending select for 192.168.0.106...  
  5. Lease of 192.168.0.106 obtained, lease time 86400  
复制代码



  Step4. 将动态获取的IP设置给网卡eth0,执行指令:
  1. ifconfig eth0 192.168.0.106  
复制代码


  之后可以通过命令查看网卡配置信息:
  1. ifconfig eth0  
复制代码


  效果如下:

  1. @tqimx6q #ifconfig eth0 192.168.0.106  
  2. @tqimx6q #ifconfig eth0  
  3. eth0      Link encap:Ethernet  HWaddr AA:EF:AE:8A:EA:05   
  4.           inet addr:192.168.0.106  Bcast:192.168.0.255  Mask:255.255.255.0  
  5.           inet6 addr: fe80::a8ef:aeff:fe8a:ea05/64 Scope:Link  
  6.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
  7.           RX packets:253 errors:0 dropped:0 overruns:0 frame:0  
  8.           TX packets:8 errors:0 dropped:0 overruns:0 carrier:0  
  9.           collisions:0 txqueuelen:1000   
  10.           RX bytes:24238 (23.6 KiB)  TX bytes:1152 (1.1 KiB)  
复制代码



  Step5. 设置网关,执行指令:

  1. route add default gw 192.168.0.1  
复制代码



  Step6. 通过ping指令测试网络状态,执行指令:
  1. ping 8.8.8.8  
复制代码



  效果如下:

  1. @tqimx6q #ping 8.8.8.8  
  2. PING 8.8.8.8 (8.8.8.8): 56 data bytes  
  3. 64 bytes from 8.8.8.8: seq=0 ttl=43 time=77.409 ms  
  4. 64 bytes from 8.8.8.8: seq=1 ttl=43 time=83.292 ms  
  5. 64 bytes from 8.8.8.8: seq=2 ttl=43 time=88.236 ms  
  6. 64 bytes from 8.8.8.8: seq=3 ttl=43 time=80.713 ms  
  7. 64 bytes from 8.8.8.8: seq=4 ttl=43 time=74.452 ms  
  8. 64 bytes from 8.8.8.8: seq=5 ttl=43 time=78.627 ms  
复制代码



  可见,tqimx6q已经可以ping通谷歌的DNS服务器了。至此,网卡的移植工作就完成了,PHY相关的配置还没有仔细研究就来分享了,请见谅。文章编写匆忙,如有问题请帮忙指出,有疑问可以留言讨论。





您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-3-29 05:16 , Processed in 1.046875 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表