RK3288_Android7.1调试以太网ethernet

1、以太网(ethernet)的调试:
Rk默认已经添加了mac驱动。网卡分为两个层次:MAC+PHY
一般说来,MAC就是网络控制器,如果该驱动OK,就能直接看到ifconfig信息;
PHY是物理层,负责发送和传输的底层,如果PHY发生问题,ifconfig同样有信息,只有up时才会连接PHY,down时断开连接。
MAC和PHY通过MII接口传输以太网数据,通过MDIO接口访问PHY的配置寄存器。 PHY连不上第一可能是硬件问题,拿给做硬件的,首先检查一下供电是否正常(最关键),然后检查一下PHY所有信号是否都很正常(一般连接对了都没啥问题),
Adb通过 ifconfig -a命令可以查看是否注册了网卡设备eth0

rk3288:/ # ifconfig -a

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:1 
          RX bytes:0 TX bytes:0 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  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:1 
          RX bytes:0 TX bytes:0 

eth0      Link encap:Ethernet  HWaddr 46:50:6f:9d:8c:82
          inet addr:192.168.2.27  Bcast:192.168.2.255  Mask:255.255.255.0 
          inet6 addr: fe80::4450:6fff:fe9d:8c82/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:908 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:99 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:72432 TX bytes:12712 
          Interrupt:38 
rk3288:/ # 

我这里调试的是:Rk3288_Android7.1,kernel版本是4.4, 代码位置在drivers/net/ethernet/stmicro/stmmac/.
Dts配置:

--- a/arch/arm/boot/dts/rk3288-evb.dtsi 
+++ b/arch/arm/boot/dts/rk3288-evb.dtsi
		
	ext_gmac: external-gmac-clock {
		compatible = "fixed-clock";
		clock-frequency = <125000000>; //1000M网用125M
		clock-output-names = "ext_gmac";
		#clock-cells = <0>;
		};

    &gmac {
         //      phy-supply = <&vcc_phy>; //原理图phy的供电PHY_PMEB直接使用pmu的ldo脚,   所以这里注掉,不需要再配置
     phy-mode = "rgmii"; 
     clock_in_out = "input";
     snps,reset-gpio = <&gpio4 8 0>; //复位pin(参考原理图)
     snps,reset-active-low;
     snps,reset-delays-us = <0 10000 50000>;
     assigned-clocks = <&cru SCLK_MAC>;
     assigned-clock-parents = <&ext_gmac>;
     pinctrl-names = "default";
 	  pinctrl-0 = <&rgmii_pins>; 
     tx_delay = <0x30>;
     rx_delay = <0x10>;
     max-speed = <1000>; //这里配置最大的限速,1000就是可以达到1000M速度,100就是100M最大限速
     status = "okay";
	};

问题点总结:
1、万用表量供电脚PHY_PME只有0.4v的供电。
分析:
Phy的供电脚使用pmu(rk808)的VSWOUT2脚(对照原理图),注意dts添加对应pin的节点配置,这样rk808驱动才能添加对应的寄存器设置,使该pin输出3.3v供电:

--- a/arch/arm/boot/dts/rk3288-evb-android-rk808-hdmi.dts 
+++ b/arch/arm/boot/dts/rk3288-evb-android-rk808-hdmi.dts

 	  +                       vcc_lan: SWITCH_REG2 {
      +                                 regulator-always-on;
      +                                 regulator-boot-on;
      +                                 regulator-min-microvolt = <3300000>;
      +                                 regulator-max-microvolt = <3300000>;
  	  +                                 regulator-name = "vcc_lan";
   	  +                                 regulator-state-mem {
  	  +                                         regulator-off-in-suspend;
 	  +                                 };
      +                       };

2、报错rk_gmac-dwmac: probe of ff290000.ethernet failed with error -1。
分析:
dwmac-rk.c驱动的上电函数phy_power_on读取不到phy-supply的有效ldo,直接返回-1报错,就会无法正常识别到网卡设备eth0,需在驱动drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c中注掉phy_power_on的上下电操作,直接返回0即可。

	static int phy_power_on(struct rk_priv_data *bsp_priv, bool enable)
	{
	/*	struct regulator *ldo = bsp_priv->regulator;
	int ret;
	struct device *dev = &bsp_priv->pdev->dev;

	if (!ldo) {
		dev_err(dev, "no regulator found\n");
		return -1;
	}

	if (enable) {
		ret = regulator_enable(ldo);
		if (ret)
			dev_err(dev, "fail to enable phy-supply\n");
	} else {
		ret = regulator_disable(ldo);
		if (ret)
			dev_err(dev, "fail to disable phy-supply\n");
	}
	*/
	return 0;
	}

3、开机起来只识别到100M的速率,相关log打印:rk_gmac-dwmac ff290000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off)
分析:
dts配置:

max-speed = <1000>; //这里配置最大的限速

4、如果PHY的供电脚PHY_PMEB使用GPIO控制开关的话,dts部分还需要对照原理图加上以下的GPIO的配置。

vcc_phy: vcc-phy-regulator { 
		compatible = "regulator-fixed"; 
		enable-active-high; 
		gpio = <&gpio0 8 GPIO_ACTIVE_HIGH>; 
		pinctrl-names = "default"; 
		pinctrl-0 = <&eth_phy_pwr>; 
		regulator-name = "vcc_phy"; 
		regulator-min-microvolt = <3300000>; 
		regulator-max-microvolt = <3300000>; 
		regulator-always-on; 
		regulator-boot-on; 
	}; 
	& pinctrl {
		eth_phy { 
			eth_phy_pwr: eth-phy-pwr { 
			rockchip,pins = <0 8 RK_FUNC_GPIO &pcfg_pull_none>; 
		}; 
	};

你可能感兴趣的:(Android驱动开发,RK系列驱动开发)