平台:RK3588 Android12
问题:以太网调试
RK3588 芯片拥有 2 个 GMAC 控制器,都是支持千兆网的,GMAC0 的 RGMII/RMII 接口复用在 VCCIO3 电源域。
驱动:
RK3588平台默认支持的是RTL8211f,但是这里用的是MAE0621A,所以得加上驱动
1.kernel-5.10/arch/arm64/configs/rockchip_defconfig
+CONFIG_MAXIO_PHY=y
2.kernel-5.10/drivers/net/phy/Kconfig
B.kernel/drivers/net/phy/Kconfig
+config MAXIO_PHY
+ tristate "Maxio PHYs"
+ help
+ Supports the Maxio MAExxxx PHY.
3.kernel-5.10/drivers/net/phy/Makefile
+obj-$(CONFIG_MAXIO_PHY) += maxio.o
5.在kernel-5.10/drivers/net/phy/下增加maxio.c文件
6.kernel-5.10/drivers/net/phy/phy_device.c
Android11以前是在函数static int get_phy_id里面加上
if (is_c45)
return get_phy_c45_ids(bus, addr, phy_id, c45_ids);
++ #ifdef CONFIG_MAXIO_PHY
++ mdiobus_write(bus,addr,MII_PHYSID2,0);
++ #endif
但是Android12里面static int get_phy_id做了一些修改,把802.3-c22这种情况下的操作封装成了函数get_phy_c22_id,大致都是一样的,直接在get_phy_c22_id加上就好了。
int phy_reg;
++ #ifdef CONFIG_MAXIO_PHY
++ /*
++ *An MDIO connects to multiple PHYs requiring write before read.
++ *This operation does not affect one MDIO connected to a single PHY
++ *MII_PHYSID2 is a read-only register and writine to it has no effect
++ */
++ mdiobus_write(bus,addr,MII_PHYSID2,0);
++ #endif
dts配置:
++ &gmac0 {
++ /* Use rgmii-rxid mode to disable rx delay inside Soc */
++ phy-mode = "rgmii-rxid"; //PHY 接口
++ clock_in_out = "output"; //时钟方向,由 GMAC 提供
++
++ snps,reset-gpio = <&gpio1 RK_PA4 GPIO_ACTIVE_LOW>; //复位IO及有效电平
++ snps,reset-active-low;
++ /* Reset time is 20ms, 100ms for rtl8211f */
++ snps,reset-delays-us = <0 20000 100000>;
++
++ pinctrl-names = "default";
++ pinctrl-0 = <&gmac0_miim
++ &gmac0_tx_bus2
++ &gmac0_rx_bus2
++ &gmac0_rgmii_clk
++ &gmac0_rgmii_bus
++ >;
++
++ tx_delay = <0x44>; //TX 线上的延时值
++ /* rx_delay = <0x4f>; //RX 线上的延时值*/
++
++ phy-handle = <&rgmii_phy0>;
++ status = "okay";
++ };
++
++ &gmac1 {
++ /* Use rmii-rxid mode to disable rx delay inside Soc */
++ phy-mode = "rgmii-rxid";
++ clock_in_out = "output";
++
++ snps,reset-gpio = <&gpio3 RK_PB7 GPIO_ACTIVE_LOW>;
++ snps,reset-active-low;
++ /* Reset time is 20ms, 100ms for rtl8211f */
++ snps,reset-delays-us = <0 20000 100000>;
++
++ pinctrl-names = "default";
++ pinctrl-0 = <&gmac1_miim
++ &gmac1_tx_bus2
++ &gmac1_rx_bus2
++ &gmac1_rgmii_clk
++ &gmac1_rgmii_bus
++ >;
++
++ tx_delay = <0x43>;
++ //rx_delay = <0x3f>;
++
++ phy-handle = <&rgmii_phy1>;
++ status = "okay";
++ };
++
++ &mdio0 {
++ rgmii_phy0: phy@1 {
++ compatible = "ethernet-phy-ieee802.3-c22";
++ reg = <0x0>;
++ };
++ };
++
++ &mdio1 {
++ rgmii_phy1: phy@1 {
++ compatible = "ethernet-phy-ieee802.3-c22";
++ reg = <0x0>;
++ };
++ };
具体引脚配置需要根据原理图配置,在这里踩了两个坑,一个是clock_in_out,另一个是phy的地址reg。
clock_in_out的话需要看一下时钟是用的谁的,这里用的是phy的,所以给了output;
地址reg一开始给了0x1,发现不行,找不到phy
[ 11.126825] [ T390] rk_gmac-dwmac fe1c0000.ethernet eth0: no phy at addr -1
[ 11.126866] [ T390] rk_gmac-dwmac fe1c0000.ethernet eth0: stmmac_open: Cannot attach to PHY (error: -19)
[ 11.129913] [ T390] rk_gmac-dwmac fe1b0000.ethernet eth1: no phy at addr -1
[ 11.129949] [ T390] rk_gmac-dwmac fe1b0000.ethernet eth1: stmmac_open: Cannot attach to PHY (error: -19)
将地址改成0x0后两个phy都找到了
[ 17.499451] [ T392] rk_gmac-dwmac fe1c0000.ethernet eth0: PHY [stmmac-1:00] driver [MAE0621A Gigabit Ethernet] (irq=POLL)
[ 17.504206] [ T392] dwmac4: Master AXI performs any burst length
[ 17.504262] [ T392] rk_gmac-dwmac fe1c0000.ethernet eth0: No Safety Features support found
[ 17.504295] [ T392] rk_gmac-dwmac fe1c0000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[ 17.504892] [ T392] rk_gmac-dwmac fe1c0000.ethernet eth0: registered PTP clock
[ 17.505923] [ T392] rk_gmac-dwmac fe1c0000.ethernet eth0: configuring for phy/rgmii-rxid link mode
[ 17.557124] [ T392] MAXIO_PHY_VER: v1.7.2
[ 21.739504] [ T392] rk_gmac-dwmac fe1b0000.ethernet eth1: PHY [stmmac-0:00] driver [MAE0621A Gigabit Ethernet] (irq=POLL)
[ 21.741682] [ T392] dwmac4: Master AXI performs any burst length
[ 21.741716] [ T392] rk_gmac-dwmac fe1b0000.ethernet eth1: No Safety Features support found
[ 21.741735] [ T392] rk_gmac-dwmac fe1b0000.ethernet eth1: IEEE 1588-2008 Advanced Timestamp supported
[ 21.742368] [ T392] rk_gmac-dwmac fe1b0000.ethernet eth1: registered PTP clock
[ 21.743035] [ T392] rk_gmac-dwmac fe1b0000.ethernet eth1: configuring for phy/rgmii-rxid link mode
eth1节点正常,可以上网。
eth1 Link encap:Ethernet HWaddr 06:54:6b:28:84:ad Driver rk_gmac-dwmac
inet addr:192.168.0.189 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::7ce6:75e3:a044:b11/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9126 TX bytes:5518
Interrupt:92
console:/ # ping www.baidu.com
PING www.a.shifen.com (183.2.172.42) 56(84) bytes of data.
64 bytes from 183.2.172.42: icmp_seq=1 ttl=53 time=9.51 ms
64 bytes from 183.2.172.42: icmp_seq=2 ttl=53 time=9.30 ms
64 bytes from 183.2.172.42: icmp_seq=3 ttl=53 time=9.54 ms
最后还有一个bug没解决,用gmac0时发现有线网图标会有一个感叹号,ip什么都有,看起来有点像网络阻塞,插上网线的时候相关的打印信息要比gmac1慢好多,暂时还没有解决。
参考文章:RK3588 调试 phy-CSDN博客