Support for Edimax EW-7476RPC

I managed to get OpenWRT running on the Edimax EW-7476RPC, which is also sold for great value for money under the name Renkforce RF-WR-1200RF WLAN Repeater for great value for money. The model is also compatible with the newer EW-7478AC (at least the firmware can be cross-flashed after changing some magic bytes).

The patch looks like this:

diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds
index b55ca0413e..2063c099ed 100755
--- a/target/linux/ramips/base-files/etc/board.d/01_leds
+++ b/target/linux/ramips/base-files/etc/board.d/01_leds
@@ -146,6 +146,11 @@ dir-860l-b1)
 edimax,br-6478ac-v2)
        set_wifi_led "$boardname:blue:wlan"
        ;;
+edimax,ew-7476rpc)
+        ucidef_set_led_netdev "wlan5g" "WLAN 5G" "$boardname:blue:wlan5g" "wlan0"
+        ucidef_set_led_netdev "wlan2g" "WLAN 2G" "$boardname:blue:wlan2g" "wlan1"
+        ucidef_set_led_netdev "lan" "lan" "$boardname:green:internet" "eth0"
+        ;;
 ex2700|\
 wn3000rpv3)
        set_wifi_led "$boardname:green:router"
diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network
index 2e56678cf5..7b434896b5 100755
--- a/target/linux/ramips/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/base-files/etc/board.d/02_network
@@ -68,6 +68,7 @@ ramips_setup_interfaces()
        wnce2001|\
        zbt-cpe102|\
        zorlik,zl5900v2|\
+       edimax,ew-7476rpc|\
        zte-q7)
                ucidef_add_switch "switch0"
                ucidef_add_switch_attr "switch0" "enable" "false"
diff --git a/target/linux/ramips/dts/EW-7476RPC.dts b/target/linux/ramips/dts/EW-7476RPC.dts
new file mode 100644
index 0000000000..74f49ad7b1
--- /dev/null
+++ b/target/linux/ramips/dts/EW-7476RPC.dts
@@ -0,0 +1,235 @@
+/*
+ * Device Tree file for the Edimax EW-7476RPC
+ * based on Edimax BR-6478AC V2
+ *
+ * Copyright (C) 2016 Rohan Murch <rohan.murch@gmail.com>
+ * Copyright (C) 2016 Hans Ulli Kroll <ulli.kroll@googlemail.com>
+ * Copyright (C) 2017 James McKenzie <openwrt@madingley.org>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ 
+ The following definitions were found in the orignal GPL firmware source
+ HW_LED_WIRELESS_ABAND_="71"
+ HW_LED_WIRELESS_GBAND_="70"
+ HW_LED_WIRELES_="69"
+ HW_LED_POWER_="67"
+ HW_LED_WPS_="68"
+ HW_LED_LAN_="66"
+ HW_BUTTON_APSWITCH_BUT_1_="62"
+ HW_BUTTON_APSWITCH_BUT_2_="63"
+ HW_BUTTON_RESET_="60"
+
+ The device does not have a reset button (but there are solder pads for a button), WPS and reset are swapped.
+ 
+ */
+
+/dts-v1/;
+
+#include "mt7620a.dtsi"
+
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+
+/ {
+       compatible = "edimax,ew-7476rpc", "ralink,mt7620a-soc";
+       model = "Edimax EW7476RPC";
+
+       aliases {
+               led-boot = &led_power;
+               led-failsafe = &led_power;
+               led-running = &led_power;
+               led-upgrade = &led_power;
+       };
+
+       chosen {
+               bootargs = "console=ttyS0,57600";
+       };
+
+
+       keys {
+                compatible = "gpio-keys";
+
+                reset_wps {
+                        label = "reset_wps";
+                        gpios = <&gpio2 20 GPIO_ACTIVE_LOW>;
+                        linux,code = <KEY_RESTART>;
+                };
+       };
+
+       leds {
+               compatible = "gpio-leds";
+
+               led_power: power {
+                       label = "ew-7476rpc:green:power";
+                       gpios = <&gpio2 27 GPIO_ACTIVE_LOW>;
+               };
+               internet {
+                       label = "ew-7476rpc:green:internet";
+                       gpios = <&gpio2 26 GPIO_ACTIVE_LOW>;
+               };
+               wlan2g {
+                       label = "ew-7476rpc:blue:wlan2g";
+                       gpios = <&gpio2 31 GPIO_ACTIVE_LOW>;
+               };
+               wlan5g {
+                       label = "ew-7476rpc:blue:wlan5g";
+                       gpios = <&gpio2 30 GPIO_ACTIVE_LOW>;
+               };
+       };
+
+/*
+       gpio_export {
+               compatible = "gpio-export";
+               #size-cells = <0>;
+               usb-power {
+                       gpio-export,name="usb-power";
+                       gpio-export,output=<1>;
+                       gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
+               };
+       };
+       */
+};
+
+
+&gpio2 {
+       status = "okay";
+};
+
+&spi0 {
+       status = "okay";
+
+       flash@0 {
+               compatible = "jedec,spi-nor";
+               reg = <0 0>;
+               spi-max-frequency = <10000000>;
+
+               partitions {
+                       compatible = "fixed-partitions";
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+
+                       partition@0 {
+                               label = "u-boot";
+                               reg = <0x0 0x30000>;
+                               read-only;
+                       };
+
+                       partition@30000 {
+                               label = "u-boot-env";
+                               reg = <0x30000 0x10000>;
+                               read-only;
+                       };
+
+                       factory: partition@40000 {
+                               label = "factory";
+                               reg = <0x40000 0x10000>;
+                               read-only;
+                       };
+
+                       partition@50000 {
+                               label = "cimage";
+                               reg = <0x50000 0x20000>;
+                               read-only;
+                       };
+
+                       partition@70000 {
+                               compatible = "edimax,uimage";
+                               label = "firmware";
+                               reg = <0x00070000 0x00790000>;
+                       };
+               };
+       };
+};
+
+&pinctrl {
+       state_default: pinctrl0 {
+               gpio {
+            // might need pin 39: ;
+                       ralink,group = "i2c", "uartf", "nd_sd", "rgmii2", "spi refclk";
+                       ralink,function = "gpio";
+               };
+       };
+};
+
+
+&ethernet {
+
+    status = "okay";
+       mtd-mac-address = <&factory 0x4>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&rgmii1_pins &mdio_pins>;
+       mediatek,portmap = "l";
+    mediatek,mdio-mode = <1>;
+    
+       port@5 {
+               status = "okay";
+               mediatek,fixed-link = <1000 1 1 1>;
+               phy-mode = "rgmii";
+       };
+
+       mdio-bus {
+               status = "okay";
+
+               phy0: ethernet-phy@0 {
+                       status ="disabled";
+                       reg = <0>;
+                       phy-mode = "rgmii";
+               };
+
+               phy1: ethernet-phy@1 {
+                       status = "disabled";
+                       reg = <1>;
+                       phy-mode = "rgmii";
+               };
+
+               phy2: ethernet-phy@2 {
+                       status = "disabled";
+                       reg = <2>;
+                       phy-mode = "rgmii";
+               };
+
+               phy3: ethernet-phy@3 {
+                       status = "disabled";
+                       reg = <3>;
+                       phy-mode = "rgmii";
+               };
+
+               phy4: ethernet-phy@4 {
+                       status = "disabled";
+                       reg = <4>;
+                       phy-mode = "rgmii";
+               };
+       };
+};
+
+
+&gsw {
+       mediatek,port5 = "gmac";
+};
+
+
+&wmac {
+       ralink,mtd-eeprom = <&factory 0>;
+};
+
+&pcie {
+       status = "okay";
+};
+
+&pcie0 {
+       wifi@0,0 {
+               reg = <0x0000 0 0 0 0>;
+               mediatek,mtd-eeprom = <&factory 0x8000>;
+               mediatek,2ghz = <0>;
+       };
+};
+
+&ehci {
+       status = "okay";
+};
+
+&ohci {
+       status = "okay";
+};
diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7620.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7620.c
index 5fc5080aaf..0d617f5354 100644
--- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7620.c
+++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7620.c
@@ -84,6 +84,30 @@ static int mt7620_mdio_mode(struct device_node *eth_node)
        return ret;
 }
 
+void reset_realtek_phy(void){
+       #define RALINK_GPIO_DIR        0xB0000600+0x4C
+       #define RALINK_GPIO_DATA       0xB0000600+0x48
+       #define RALINK_RESETPHY_GPIO       (39-24)
+  u32 gpiodir;
+  u32 piodata;
+  u32 reset_pin= RALINK_RESETPHY_GPIO;
+  gpiodir =  le32_to_cpu(*(volatile u32 *)(RALINK_GPIO_DIR));
+  /*set gpio1 to output*/
+  gpiodir |= (1<<reset_pin);
+  *(volatile u32 *)(RALINK_GPIO_DIR) = cpu_to_le32(gpiodir);
+
+  piodata = le32_to_cpu(*(volatile u32 *)(RALINK_GPIO_DATA));
+  /*set to low(0)*/
+  piodata &= ~(1L << reset_pin);
+  *(volatile u32 *)(RALINK_GPIO_DATA) = cpu_to_le32(piodata);
+  /*delay 30ms*/
+  mdelay(30);
+  /*set to high(1)*/
+  piodata |= (1L << reset_pin);
+  *(volatile u32 *)(RALINK_GPIO_DATA) = cpu_to_le32(piodata);
+}
+
+
 static void mt7620_hw_init(struct mt7620_gsw *gsw, int mdio_mode)
 {
        u32 i;
@@ -99,6 +123,7 @@ static void mt7620_hw_init(struct mt7620_gsw *gsw, int mdio_mode)
        if (mdio_mode) {
                u32 val;
 
+        pr_info("gsw: mt7620_hw_init: mdio_mode set, disabling ephy\n");
                /* turn off ephy and set phy base addr to 12 */
                mtk_switch_w32(gsw, mtk_switch_r32(gsw, GSW_REG_GPC1) |
                        (0x1f << 24) | (0xc << 16),
@@ -207,6 +232,8 @@ static void mt7620_hw_init(struct mt7620_gsw *gsw, int mdio_mode)
                rt_sysc_w32(val, SYSC_REG_CFG1);
                pr_info("gsw: setting port4 to gmac mode\n");
        }
+
+       reset_realtek_phy();
 }
 
 static const struct of_device_id mediatek_gsw_match[] = {
diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 10d9fd7a3e..69e7988629 100644
--- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -1333,6 +1333,7 @@ static int fe_stop(struct net_device *dev)
        return 0;
 }
 
+
 static int __init fe_init(struct net_device *dev)
 {
        struct fe_priv *priv = netdev_priv(dev);
diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/soc_mt7620.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/soc_mt7620.c
index 7f728d142d..5116fbce5a 100644
--- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/soc_mt7620.c
+++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/soc_mt7620.c
@@ -183,7 +183,6 @@ static void mt7620_port_init(struct fe_priv *priv, struct device_node *np)
                dev_err(priv->dev, "port %d - invalid phy mode\n", id);
                return;
        }
-
        priv->phy->phy_node[id] = of_parse_phandle(np, "phy-handle", 0);
        if (!priv->phy->phy_node[id] && !priv->phy->phy_fixed[id])
                return;
@@ -231,6 +230,7 @@ static void mt7620_port_init(struct fe_priv *priv, struct device_node *np)
                        val |= PMCR_DUPLEX;
                mtk_switch_w32(gsw, val, GSW_REG_PORT_PMCR(id));
                dev_info(priv->dev, "using fixed link parameters\n");
+
                return;
        }
 
diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
index cf38aa2cb1..f302b321f3 100644
--- a/target/linux/ramips/image/mt7620.mk
+++ b/target/linux/ramips/image/mt7620.mk
@@ -617,6 +617,20 @@ define Device/edimax_br-6478ac-v2
 endef
 TARGET_DEVICES += edimax_br-6478ac-v2
 
+define Device/edimax_ew-7476rpc
+  DTS := EW-7476RPC
+  DEVICE_TITLE := Edimax EW-7476RPC
+  BLOCKSIZE := 64k
+  IMAGE_SIZE := 7616k
+  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
+        edimax-header -s CSYS -m RN79 -f 0x70000 -S 0x01100000 | pad-rootfs | \
+        append-metadata | check-size $$$$(IMAGE_SIZE)
+  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci kmod-phy-realtek
+endef
+TARGET_DEVICES += edimax_ew-7476rpc
+
+
+
 define Device/tplink_c2-v1
   $(Device/Archer)
   DTS := ArcherC2-v1

The boot log then looks like this

[    0.000000] Linux version 4.14.119 (birger@AMDDesktop) (gcc version 7.4.0 (OpenWrt GCC 7.4.0 r10026-395bef4bba)) #0 Fri May 17 19:41:43 2019
[    0.000000] Board has DDR2
[    0.000000] Analog PMU set to hw control
[    0.000000] Digital PMU set to hw control
[    0.000000] SoC Type: MediaTek MT7620A ver:2 eco:6
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019650 (MIPS 24KEc)
[    0.000000] MIPS: machine is Edimax EW7476RPC
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 04000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]
[    0.000000] On node 0 totalpages: 16384
[    0.000000] free_area_init_node: node 0, pgdat 8049beb0, node_mem_map 81000040
[    0.000000]   Normal zone: 128 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 16384 pages, LIFO batch:3
[    0.000000] random: get_random_bytes called from start_kernel+0x8c/0x474 with crng_init=0
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16256
[    0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 256 (order: -2, 1024 bytes)
[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Writing ErrCtl register=00048270
[    0.000000] Readback ErrCtl register=00048270
[    0.000000] Memory: 59712K/65536K available (3689K kernel code, 174K rwdata, 860K rodata, 196K init, 207K bss, 5824K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 256
[    0.000000] CPU Clock: 580MHz
[    0.000000] clocksource: systick: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 583261500 ns
[    0.000000] systick: enable autosleep mode
[    0.000000] systick: running - mult: 214748, shift: 32
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6590553264 ns
[    0.000010] sched_clock: 32 bits at 290MHz, resolution 3ns, wraps every 7405115902ns
[    0.015468] Calibrating delay loop... 385.84 BogoMIPS (lpj=1929216)
[    0.087712] pid_max: default: 32768 minimum: 301
[    0.097121] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.110141] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.130478] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.149958] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.162128] pinctrl core: initialized pinctrl subsystem
[    0.172975] NET: Registered protocol family 16
[    0.443304] PCI host bridge /pcie@10140000 ranges:
[    0.452703]  MEM 0x0000000020000000..0x000000002fffffff
[    0.463075]   IO 0x0000000010160000..0x000000001016ffff
[    0.490880] rt2880_gpio 10000600.gpio: registering 24 gpios
[    0.501914] rt2880_gpio 10000600.gpio: registering 24 irq handlers
[    0.514493] rt2880_gpio 10000660.gpio: registering 32 gpios
[    0.525481] rt2880_gpio 10000660.gpio: registering 32 irq handlers
[    0.538613] PCI host bridge to bus 0000:00
[    0.546613] pci_bus 0000:00: root bus resource [mem 0x20000000-0x2fffffff]
[    0.560321] pci_bus 0000:00: root bus resource [io  0xffffffff]
[    0.572055] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    0.585555] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    0.601349] pci 0000:00:00.0: [1814:0801] type 01 class 0x060400
[    0.601390] pci 0000:00:00.0: reg 0x10: [mem 0x00000000-0x7fffffff]
[    0.601407] pci 0000:00:00.0: reg 0x14: [mem 0x20200000-0x2020ffff]
[    0.601488] pci 0000:00:00.0: supports D1
[    0.601499] pci 0000:00:00.0: PME# supported from D0 D1 D3hot
[    0.601949] pci 0000:01:00.0: [14c3:7662] type 00 class 0x028000
[    0.602016] pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x000fffff 64bit]
[    0.602072] pci 0000:01:00.0: reg 0x30: [mem 0x00000000-0x0000ffff pref]
[    0.602189] pci 0000:01:00.0: PME# supported from D0 D3hot D3cold
[    0.602418] pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
[    0.602436] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 01
[    0.602482] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    0.615532] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    0.629344] pci 0000:00:00.0: BAR 8: assigned [mem 0x20000000-0x200fffff]
[    0.642847] pci 0000:00:00.0: BAR 9: assigned [mem 0x20100000-0x201fffff pref]
[    0.657212] pci 0000:00:00.0: BAR 1: assigned [mem 0x20200000-0x2020ffff]
[    0.670721] pci 0000:01:00.0: BAR 0: assigned [mem 0x20000000-0x200fffff 64bit]
[    0.685266] pci 0000:01:00.0: BAR 6: assigned [mem 0x20100000-0x2010ffff pref]
[    0.699614] pci 0000:00:00.0: PCI bridge to [bus 01]
[    0.709469] pci 0000:00:00.0:   bridge window [mem 0x20000000-0x200fffff]
[    0.722978] pci 0000:00:00.0:   bridge window [mem 0x20100000-0x201fffff pref]
[    0.741504] clocksource: Switched to clocksource systick
[    0.753210] NET: Registered protocol family 2
[    0.762613] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.776386] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.788979] TCP: Hash tables configured (established 1024 bind 1024)
[    0.801763] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.813276] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.825953] NET: Registered protocol family 1
[    0.834572] PCI: CLS 0 bytes, default 32
[    0.837290] rt-timer 10000100.timer: maximum frequency is 1220Hz
[    0.850047] Crashlog allocated RAM at address 0x3f00000
[    0.862160] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[    0.880779] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.892276] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.921710] io scheduler noop registered
[    0.929352] io scheduler deadline registered (default)
[    0.940451] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    0.954137] console [ttyS0] disabled
[    0.961130] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 20, base_baud = 2500000) is a Palmchip BK-3103
[    0.980899] console [ttyS0] enabled
[    0.994672] bootconsole [early0] disabled
[    1.011147] cacheinfo: Failed to find cpu0 device node
[    1.021411] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    1.038131] spi spi0.0: force spi mode3
[    1.046636] m25p80 spi0.0: mx25l6405d (8192 Kbytes)
[    1.056460] 5 fixed-partitions partitions found on MTD device spi0.0
[    1.069118] Creating 5 MTD partitions on "spi0.0":
[    1.078674] 0x000000000000-0x000000030000 : "u-boot"
[    1.089506] 0x000000030000-0x000000040000 : "u-boot-env"
[    1.101013] 0x000000040000-0x000000050000 : "factory"
[    1.112086] 0x000000050000-0x000000070000 : "cimage"
[    1.122917] 0x000000070000-0x000000800000 : "firmware"
[    1.137616] 2 edimax-fw partitions found on MTD device firmware
[    1.149482] Creating 2 MTD partitions on "firmware":
[    1.159383] 0x000000000000-0x000000182db2 : "kernel"
[    1.170210] 0x000000182db2-0x000000790000 : "rootfs"
[    1.180979] mtd: device 6 (rootfs) set to be root filesystem
[    1.193848] 1 squashfs-split partitions found on MTD device rootfs
[    1.206234] 0x00000044d000-0x000000790000 : "rootfs_data"
[    1.218783] libphy: Fixed MDIO Bus: probed
[    1.228486] Before reset
[    1.233579] ETH Status: GPIOMODE: 18341d, SYSCFG0: 122122
[    1.244331] ETH Status: SYSCFG1: 260c50f
[    1.252267] Init dev
[    1.256610] ETH Status: GPIOMODE: 18341d, SYSCFG0: 122122
[    1.267378] ETH Status: SYSCFG1: 260c50f
[    1.312391] AAAAAAA
[    1.316576] ETH Status: GPIOMODE: 18341d, SYSCFG0: 122122
[    1.327350] ETH Status: SYSCFG1: 260c50f
[    1.335318] libphy: mdio: probed
[    1.341803] mtk_soc_eth 10100000.ethernet: port 5 - phy mode 0
[    1.353444] mtk_soc_eth 10100000.ethernet: using fixed link parameters
[    1.366528] mtk_soc_eth 10100000.ethernet: loaded mt7620 driver
[    1.378322] Init finished
[    1.383535] ETH Status: GPIOMODE: 18341d, SYSCFG0: 122122
[    1.394285] ETH Status: SYSCFG1: 260c50f
[    1.402751] ETH Status: GPIOMODE: 18341d, SYSCFG0: 122122
[    1.413555] ETH Status: SYSCFG1: 260c50f
[    1.421369] mtk_soc_eth 10100000.ethernet eth0: mediatek frame engine at 0xb0100000, irq 5
[    1.438351] rt2880_wdt 10000120.watchdog: Initialized
[    1.449781] NET: Registered protocol family 10
[    1.462841] Segment Routing with IPv6
[    1.470253] NET: Registered protocol family 17
[    1.479225] 8021q: 802.1Q VLAN Support v1.8
[    1.500394] VFS: Mounted root (squashfs filesystem) readonly on device 31:6.
[    1.515580] Freeing unused kernel memory: 196K
[    1.524457] This architecture does not have kernel memory protection.
[    2.731469] random: fast init done
[    3.380385] init: Console is alive
[    3.387489] init: - watchdog -
[    5.430364] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    5.551159] usbcore: registered new interface driver usbfs
[    5.562270] usbcore: registered new interface driver hub
[    5.572991] usbcore: registered new device driver usb
[    5.589487] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    5.604279] ehci-platform: EHCI generic platform driver
[    5.625083] phy phy-usbphy.0: remote usb device wakeup disabled
[    5.636889] phy phy-usbphy.0: UTMI 16bit 30MHz
[    5.645764] ehci-platform 101c0000.ehci: EHCI Host Controller
[    5.657269] ehci-platform 101c0000.ehci: new USB bus registered, assigned bus number 1
[    5.673174] ehci-platform 101c0000.ehci: irq 26, io mem 0x101c0000
[    5.694481] ehci-platform 101c0000.ehci: USB 2.0 started, EHCI 1.00
[    5.707978] hub 1-0:1.0: USB hub found
[    5.715901] hub 1-0:1.0: 1 port detected
[    5.727138] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    5.741188] ohci-platform: OHCI generic platform driver
[    5.751975] ohci-platform 101c1000.ohci: Generic Platform OHCI controller
[    5.765573] ohci-platform 101c1000.ohci: new USB bus registered, assigned bus number 2
[    5.781447] ohci-platform 101c1000.ohci: irq 26, io mem 0x101c1000
[    5.819452] hub 2-0:1.0: USB hub found
[    5.827426] hub 2-0:1.0: 1 port detected
[    5.839923] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    5.858482] init: - preinit -
[    7.457746] mtk_soc_eth 10100000.ethernet eth0: port 5 link up (1000Mbps/Full duplex)
[    7.474130] 8021q: adding VLAN 0 to HW filter on device eth0
[    7.500521] random: procd: uninitialized urandom read (4 bytes read)
[    9.292167] jffs2: notice: (399) jffs2_build_xattr_subsystem: complete building xattr subsystem, 4 of xdatum (2 unchecked, 2 orphan) and 7 of xref (2 dead, 0 orphan) found.
[    9.325880] mount_root: switching to jffs2 overlay
[    9.371943] overlayfs: upper fs does not support tmpfile.
[    9.396159] urandom-seed: Seeding with /etc/urandom.seed
[    9.517075] mtk_soc_eth 10100000.ethernet eth0: port 5 link down
[    9.540150] procd: - early -
[    9.548561] procd: - watchdog -
[    9.998016] procd: - watchdog -
[   10.004582] procd: - ubus -
[   10.273375] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.289075] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.302347] random: ubusd: uninitialized urandom read (4 bytes read)
[   10.316057] procd: - init -
[   10.821844] kmodloader: loading kernel modules from /etc/modules.d/*
[   10.842463] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   10.863637] Loading modules backported from Linux version v4.19.32-0-g3a2156c839c7
[   10.878801] Backport generated by backports.git v4.19.32-1-0-g1c4f7569
[   10.895259] ip_tables: (C) 2000-2006 Netfilter Core Team
[   10.915457] nf_conntrack version 0.5.0 (1024 buckets, 4096 max)
[   10.996122] xt_time: kernel timezone is -0000
[   11.077996] mt76x2e 0000:01:00.0: card - bus=0x1, slot = 0x0 irq=4
[   11.090576] mt76x2e 0000:01:00.0: ASIC revision: 76120044
[   11.321439] mt76x2e 0000:01:00.0: ROM patch build: 20141115060606a
[   11.339584] mt76x2e 0000:01:00.0: Firmware Version: 0.0.00
[   11.350536] mt76x2e 0000:01:00.0: Build: 1
[   11.358689] mt76x2e 0000:01:00.0: Build Time: 201507311614____
[   11.378829] mt76x2e 0000:01:00.0: Firmware running!
[   11.391764] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[   11.414655] PPP generic driver version 2.4.2
[   11.432922] NET: Registered protocol family 24
[   11.551857] rt2800_wmac 10180000.wmac: loaded eeprom from mtd device "factory"
[   11.566330] ieee80211 phy1: rt2x00_set_rt: Info - RT chipset 6352, rev 0500 detected
[   11.581778] ieee80211 phy1: rt2x00_set_rf: Info - RF chipset 7620 detected
[   11.596195] ieee80211 phy1: Selected rate control algorithm 'minstrel_ht'
[   11.621336] kmodloader: done loading kernel modules from /etc/modules.d/*
[   12.921702] urandom_read: 5 callbacks suppressed
[   12.921712] random: jshn: uninitialized urandom read (4 bytes read)
[   23.339843] mtk_soc_eth 10100000.ethernet eth0: port 5 link up (1000Mbps/Full duplex)
[   23.355759] 8021q: adding VLAN 0 to HW filter on device eth0
[   23.448112] br-lan: port 1(eth0) entered blocking state
[   23.458618] br-lan: port 1(eth0) entered disabled state
[   23.469383] device eth0 entered promiscuous mode
[   23.541256] br-lan: port 1(eth0) entered blocking state
[   23.551737] br-lan: port 1(eth0) entered forwarding state
[   23.562713] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[   24.388903] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
[   27.731872] ieee80211 phy1: rt2800_rf_self_txdc_cal: Info - RF Tx self calibration start
[   27.748561] ieee80211 phy1: rt2800_rf_self_txdc_cal: Info - RF Tx self calibration end
[   29.613527] ieee80211 phy1: rt2800_loft_iq_calibration: Info - LOFT Calibration Done!
[   29.633144] ieee80211 phy1: rt2800_iq_search: Info - IQCalibration Start!
[   29.661066] ieee80211 phy1: rt2800_iq_search: Info - IQCalibration Done! CH = 0, (gain= 0, phase= 0)
[   29.680188] ieee80211 phy1: rt2800_iq_search: Info - IQCalibration Start!
[   29.708100] ieee80211 phy1: rt2800_iq_search: Info - IQCalibration Done! CH = 1, (gain= 1, phase=3e)
[   29.726331] ieee80211 phy1: rt2800_loft_iq_calibration: Info - TX IQ Calibration Done!
[   29.755623] ieee80211 phy1: rt2800_rxiq_calibration: Info - RXIQ G_imb=0, Ph_rx=-8
[   29.780972] ieee80211 phy1: rt2800_rxiq_calibration: Info - RXIQ G_imb=0, Ph_rx=1
[   29.805870] IPv6: ADDRCONF(NETDEV_UP): wlan1: link is not ready
[   29.935848] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[   29.949685] br-lan: port 2(wlan1) entered blocking state
[   29.960376] br-lan: port 2(wlan1) entered disabled state
[   29.971379] device wlan1 entered promiscuous mode
[   29.985915] br-lan: port 3(wlan0) entered blocking state
[   29.996596] br-lan: port 3(wlan0) entered disabled state
[   30.007541] device wlan0 entered promiscuous mode
[   30.310498] device wlan0 left promiscuous mode
[   30.319570] br-lan: port 3(wlan0) entered disabled state
[   30.593287] IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
[   30.606224] br-lan: port 2(wlan1) entered blocking state
[   30.616849] br-lan: port 2(wlan1) entered forwarding state
[   30.896121] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[   31.042898] br-lan: port 3(wlan0) entered blocking state
[   31.053580] br-lan: port 3(wlan0) entered disabled state
[   31.064601] device wlan0 entered promiscuous mode
[   52.649869] random: crng init done

As you can see from the patch there is something really uncool about the device. It uses an RTL8211E as phy for the one GBE link of the mt7620a. However, this realtek chip apparently has a bug, it needs to be reset after initialization of the switch on the mt7620a. This is done on all compatible devices by pulling GPIO 39 low at the right moment in time. The code has to be in the /target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/gsw_mt7620.c kernel driver. Is there a nicer way where to put the code, without polluting the driver?

There are two more issues I am not able to solve as this is my first OpenWRT port:
The leds are correctly in the device tree and I can assign them using the web interface, whereupon they at least can be switched on and off, however, I cannot get the inital configuration right.

The final issue is that the previous configuration gets lost when I flash the firmware via luci.

In case you want to try, the firmware can simply be uploaded to the repeater/access point via the orignal web-interface. If you have a 7478 model, you need to change the first bytes in the image from RN79 to RN70.

If it's being handled in related devices under OpenWrt using a patch from the OpenWrt source, I'd suggest sticking with that. Edit: Because if/when it gets fixed or improved by OpenWrt or upstream, your device will benefit from the change transparently.

There are two ways to get the initial configuration. For devices that support DTS-based trigger assignment, as I understand it, that is the preferred approach. From the device I'm presently working with

                led_wlan2g: wlan2g {
                        label = "gl-ar750s:green:wlan2g";
                        gpios = <&gpio 19 GPIO_ACTIVE_LOW>;
                        linux,default-trigger = "phy1tpt";
                };

Using base-files/etc/board.d/01_leds is the "older" method, as I understand it. A similar config line there might be

ucidef_set_led_netdev "wlan2g" "WLAN 2G" "gl-ar750s:green:wlan2g"
1 Like

Thanks a lot, Jeff. The wifi leds work now, I used the device tree method, you recommended.

As for patching, I guess I need to put a patch into openwrt/target/linux/ramips/patches-4.14, but probably with the right #ifdefs around, so I don't bread other devices, in particular those that might have GPIO 39 connected to self-destruct?

A single kernel is used for all devices on a given target/subtarget, so #ifdef isn't going to help there.

Without looking at the code or knowing your platform as well as the ones I work with regularly, picking off a DTS-based GPIO line might be a better plan.

OK, I see. It might be possible to detect the RTL8211e chip via the mdio bus, so a generic kernel for all mt7620a targets will still work, no ifdefs needed. I am skeptical about using DTS however, because this is really part of the initialization sequence of the chips at the right time, and I don't think this can be achieved with DTS, but I also have to admit I don't know much about the possibilities, there.

Another option might be to add a DTS property that is then queried in the driver code instead of an ifdef, something like mediatek,reset-rtl8211e. I'll have to look into that, this is probably the simplest way of doing it.

I think I will add a device page, now.

1 Like

I added a DTS property for the gsw switch and submitted the new patch to the development mailing list. I hope it is being picked up...

Device is now supported, see commit https://github.com/openwrt/openwrt/commit/88f7a29f99fb8209f6d7100d0cc0f7af6dba89cf

Once snapshot images are available, you might want to re-create the devicepage https://openwrt.org/toh/edimax/edimax_ew-7476rpc with the correct template (=supported).

Hi tmomas,

could you give me a hint as to how to recreate the page?

Thanks,
Kobi

Do you have u-boot for this device I'm trying to port it to D-link 1620. Thanks.

How did you find out that GPIO 39 need to be low I'm thinking I have different ping .

Figuring out whether the GPIO pin is active-low or high is merely trial and error, see
https://openwrt.org/docs/guide-developer/add.new.device
If you had the specs of the SoC and a multi-meter you could probably also measure whether there is a pull-up or pull-down resister at an input or output, but that would typically be much more work than simply trying it out.
BTW. I unfortunately don't have any U-Boot code for the device.

the router is exactly like yours but can't get this RTL8211E to work normally this are lest messages I have :

[    9.885105] kmodloader: done loading kernel modules from /etc/modules.d/*
[   15.220320] random: crng init done
[   41.141229] 8021q: adding VLAN 0 to HW filter on device eth0
[   41.176665] br-lan: port 1(eth0.1) entered blocking state
[   41.187502] br-lan: port 1(eth0.1) entered disabled state
[   41.198715] device eth0.1 entered promiscuous mode
[   41.208323] device eth0 entered promiscuous mode
[   41.288842] br-lan: port 1(eth0.1) entered blocking state
[   41.299658] br-lan: port 1(eth0.1) entered forwarding state
[   42.148932] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready

and how you see that's the line becomes active there are messages in log ?

And I have this error during GPIO test:
rt2880-pinmux pinctrl: pin 1 is not set to gpio mux

I am not sure I understand what you mean with the RTL8211E PHY not working properly. When you attache an ethernet cable to e.g. a switch, do you get a proper link at 1GBit, as shown e.g. with a green light on the switch-port? Or is this a problem with the port not routing packets to the Wireless PHY? In the first case you need to debug the GPIOs, maybe the PHY does not have power. In the latter case you need to look at the switch port configuration in /base-files/etc/board.d/02_network maybe you need to add/change an entry for your device.
If some GPIOs don't work when testing them on the command line, this is normally due to them having been configured to have a different functionality, like I2C, SPI or UART instead of GPIO. It is common for SoCs to allow configuration of different functionalities for the PINs, this reduces the number of PINs since most users do not need all functionalities in the same application.

It's showing not connected, but in openwrt I see br-lan eth0 and eth0.1.
for the GPIO any pin I test it gives:

[   59.074626] rt2880-pinmux pinctrl: pin 5 is not set to gpio mux
[   59.086495] rt2880-pinmux pinctrl: request() failed for pin 5
[   59.097971] rt2880-pinmux pinctrl: pin-5 (pio:5) status -22

and this is what I have in GPIO dir

root@OpenWrt:/sys/class/gpio# ls
export     gpiochip0  unexport

and when I install your firmware I see

root@OpenWrt:/sys/class/gpio# ls
export      gpiochip0   gpiochip24  gpiochip40  unexport

Maybe you have fulldump of Edimax flash that I can write and test. Thanks.

I don't have access at the moment to the device (vacation) but I also fail to see how a flash dump would help. Could you post your bootlog to see where there are differences to the 7476rpc boot process and whether e.g initialisation of the gpio driver fails?

I'm trying to configure the partitions I was thinking with edimax u-boot I can get rid of backup partitions.

It's ok no need of any backup I could figure out how to work with SPI.
regarding the ethernet can you please provide more details how did you find out what GPIO to use did you send "1" to it to enable after boot ? Because now on boot it shoes 1Gb connected but doesn't receive the IP.

now it doen't even show connection. tried enumerationg GPIOs sendin 0 and after 1 to all of them but ethernet didn't turn on