MT7628与MT7688除了WIFI之外,其他几乎一样,没有区别;至少在网口方面是一样的;本文将介绍Openwrt中多网口与其复用为GPIO的方式
只有单网口以及5网口的两种,没有中间方案;这一点需要留意;
关于寄存器配置,可以在两个地方进行:
drivers/rt2880_eth.c, 宏定义CONFIG_ETH_ONE_PORT_ONLY部分即是;
void rt305x_esw_init(void)
{
....
#elif defined (MT7628_ASIC_BOARD)
/*TODO: Init MT7628 ASIC PHY HERE*/
i = RALINK_REG(RT2880_AGPIOCFG_REG);
#if defined (CONFIG_ETH_ONE_PORT_ONLY)
i |= MT7628_EPHY_EN;
i = i & ~(MT7628_P0_EPHY_AIO_EN);
#else
i = i & ~(MT7628_EPHY_EN);
#endif
RALINK_REG(RT2880_AGPIOCFG_REG) = i;
printf("RESET MT7628 PHY!!!!!!");
// reset phy
i = RALINK_REG(RT2880_RSTCTRL_REG);
i = i | RSTCTRL_EPHY_RST;
RALINK_REG(RT2880_RSTCTRL_REG) = i;
i = i & ~(RSTCTRL_EPHY_RST);
RALINK_REG(RT2880_RSTCTRL_REG) = i;
i = RALINK_REG(RALINK_SYSCTL_BASE + 0x64);
#if defined (CONFIG_ETH_ONE_PORT_ONLY)
i &= 0xf003f003;
i |= 0x05540554;
RALINK_REG(RALINK_SYSCTL_BASE + 0x64) = i; // set P0 EPHY LED mode
#else
i &= 0xf003f003;
RALINK_REG(RALINK_SYSCTL_BASE + 0x64) = i;
#endif
udelay(5000);
mt7628_ephy_init();
...
}
CONFIG_ETH_ONE_PORT_ONLY 在menuconfig中配置,最终记录在autoconf.h中;
menuconfig的配置除了ONE_PORT_ONLY 之外还有WLLL,LLLW等配置,自行根据板子所用到的网口进行选择;
x x [ ] ETH One Port Only
x x [*] Partition LAN/WAN
x x (LLLL/W) LAN/WAN Board Layout
x x ---
x x Load an Alternate Configuration File
x x Save Configuration to an Alternate File
ethernet@10100000 {
mtd-mac-address = <&factory 0x4>;
ralink,port-map = "llllw";
};
"ralink,port-map"将被
drivres/net/ethernet/ralink/esw_rt3052.c 解析
#define RT305X_ESW_PMAP_LLLLLL 0x3f
#define RT305X_ESW_PMAP_LLLLWL 0x2f
#define RT305X_ESW_PMAP_WLLLLL 0x3e
static int esw_probe(struct platform_device *pdev)
{
...
port_map = of_get_property(np, "ralink,portmap", NULL);
if (port_map)
esw->port_map = be32_to_cpu(*port_map);
...
esw_hw_init(esw);
}
static void esw_hw_init(struct rt305x_esw *esw)
{
int i;
u8 port_disable = 0;
u8 port_map = RT305X_ESW_PMAP_LLLLLL;
...
if (esw->port_map)
port_map = esw->port_map;
else
port_map = RT305X_ESW_PMAP_LLLLLL;
/*
* Unused HW feature, but still nice to be consistent here...
* This is also exported to userspace ('lan' attribute) so it's
* conveniently usable to decide which ports go into the wan vlan by
* default.
*/
esw_rmw(esw, RT305X_ESW_REG_SGC2,
RT305X_ESW_SGC2_LAN_PMAP_M << RT305X_ESW_SGC2_LAN_PMAP_S,
port_map << RT305X_ESW_SGC2_LAN_PMAP_S);
}
因此无论uboot和dts中如何配置,PORT0 一定是作为网口并且是使能可用的;
Uboot中针对网口寄存器进行了设定之后,Kernel中 解析dts配置,然后驱动初始化,并没有设定全部,最终加载后,还是只有一个网口;
即如果使用的是单网口配置的uboot,openwrt系统起来后,还需在对寄存器进行一次设定;
在此,我们可以参考mtk-openwrt-sdk中的reg工具进行,在openwrt系统加载完后,在应用空间进行寄存器修改
start() {
reg w 10000064 0x0
reg w 1000003c 0xe001ff
}
ramips_setup_rt3x5x_vlans()
{
if [ ! -x /sbin/swconfig ]; then
# legacy default
ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
return
fi
local wanports=""
local lanports=""
for port in 5 4 3 2 1 0; do
if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
continue
fi
if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
wanports="$port $wanports"
else
lanports="$port $lanports"
fi
done
ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
ucidef_add_switch "rt305x" "1" "1"
ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
}
...
zbt-wg2626)|\
your-borad-name)
ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
ucidef_add_switch "switch0" "1" "1"
ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
ucidef_add_switch_vlan "switch0" "2" "4 6t"
;;
需要注意的是 02_network仅仅只是将配置写入配置文件,然后有系统加载执行,前提是reg 先设定好相关寄存器,否则只改变02_network是无效的;