[OpenWrt-Devel] [PATCH] Support for Edimax EW-7476RPC

Birger Koblitz mail at birger-koblitz.de
Sat May 25 03:30:29 EDT 2019


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.

AFAIK all the hardware works properly.

The model is also compatible with the newer EW-7478AC, at least the 
firmware can be cross-flashed after changing the magic bytes at the 
beginning of the image from RN79 to RN70. The newer device merely has 
external antennas.

As you can see from the patch, there is something really uncool about 
the devices. 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 and is activated by a DTS property of the gsw switch.


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..ddd2c26d93 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,9 @@ dir-860l-b1)
  edimax,br-6478ac-v2)
         set_wifi_led "$boardname:blue:wlan"
         ;;
+edimax,ew-7476rpc)
+        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..46b475830e
--- /dev/null
+++ b/target/linux/ramips/dts/EW-7476RPC.dts
@@ -0,0 +1,238 @@
+/*
+ * Device Tree file for the Edimax EW-7476RPC
+ * based on Edimax BR-6478AC V2
+ *
+ * Copyright (C) 2016 Rohan Murch <rohan.murch at gmail.com>
+ * Copyright (C) 2016 Hans Ulli Kroll <ulli.kroll at googlemail.com>
+ * Copyright (C) 2017 James McKenzie <openwrt at 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 30 GPIO_ACTIVE_LOW>;
+                       linux,default-trigger = "phy1tpt";
+               };
+               wlan5g {
+            label = "ew-7476rpc:blue:wlan5g";
+            gpios = <&gpio2 31 GPIO_ACTIVE_LOW>;
+            linux,default-trigger = "phy0tpt";
+        };
+       };
+
+/*
+       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 at 0 {
+               compatible = "jedec,spi-nor";
+               reg = <0 0>;
+               spi-max-frequency = <10000000>;
+
+               partitions {
+                       compatible = "fixed-partitions";
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+
+                       partition at 0 {
+                               label = "u-boot";
+                               reg = <0x0 0x30000>;
+                               read-only;
+                       };
+
+                       partition at 30000 {
+                               label = "u-boot-env";
+                               reg = <0x30000 0x10000>;
+                               read-only;
+                       };
+
+                       factory: partition at 40000 {
+                               label = "factory";
+                               reg = <0x40000 0x10000>;
+                               read-only;
+                       };
+
+                       partition at 50000 {
+                               label = "cimage";
+                               reg = <0x50000 0x20000>;
+                               read-only;
+                       };
+
+                       partition at 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 at 5 {
+               status = "okay";
+               mediatek,fixed-link = <1000 1 1 1>;
+               phy-mode = "rgmii";
+       };
+
+       mdio-bus {
+               status = "okay";
+
+               phy0: ethernet-phy at 0 {
+                       status ="disabled";
+                       reg = <0>;
+                       phy-mode = "rgmii";
+               };
+
+               phy1: ethernet-phy at 1 {
+                       status = "disabled";
+                       reg = <1>;
+                       phy-mode = "rgmii";
+               };
+
+               phy2: ethernet-phy at 2 {
+                       status = "disabled";
+                       reg = <2>;
+                       phy-mode = "rgmii";
+               };
+
+               phy3: ethernet-phy at 3 {
+                       status = "disabled";
+                       reg = <3>;
+                       phy-mode = "rgmii";
+               };
+
+               phy4: ethernet-phy at 4 {
+                       status = "disabled";
+                       reg = <4>;
+                       phy-mode = "rgmii";
+               };
+       };
+};
+
+
+&gsw {
+       mediatek,port5 = "gmac";
+       mediatek,rtl8211e-reset = "yes";
+};
+
+
+&wmac {
+       ralink,mtd-eeprom = <&factory 0>;
+};
+
+&pcie {
+       status = "okay";
+};
+
+&pcie0 {
+       wifi at 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..4e8ac48983 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,32 @@ 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;
+
+    pr_info("gsw: Resetting RTL8211e using gpio 39\n");
+    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 +125,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),
@@ -220,6 +247,7 @@ int mtk_gsw_init(struct fe_priv *priv)
         struct device_node *np = priv->switch_np;
         struct platform_device *pdev = of_find_device_by_node(np);
         struct mt7620_gsw *gsw;
+    const char *rtl8211e_reset = NULL;

         if (!pdev)
                 return -ENODEV;
@@ -231,7 +259,10 @@ int mtk_gsw_init(struct fe_priv *priv)
         priv->soc->swpriv = gsw;

         mt7620_hw_init(gsw, mt7620_mdio_mode(priv->dev->of_node));
-
+    of_property_read_string(np, "mediatek,rtl8211e-reset", 
&rtl8211e_reset);
+    if (rtl8211e_reset && !strcmp(rtl8211e_reset, "yes"))
+        reset_realtek_phy();
+
         if (gsw->irq) {
                 request_irq(gsw->irq, gsw_interrupt_mt7620, 0,
                             "gsw", priv);
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



_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list