[WIP] add basic support cpe210v2 cpe210v2
authorAlexander Couzens <lynxis@fe80.eu>
Wed, 11 Oct 2017 18:19:59 +0000 (20:19 +0200)
committerAlexander Couzens <lynxis@fe80.eu>
Sat, 14 Oct 2017 05:00:49 +0000 (07:00 +0200)
TODO:
- Find a (good) way to overwrite 25/40 clock detection (by cmdline and/or dts)
- The reset button is doing a lot false positives.

Working:
- serial (tx, rx should work after soldering)
- network
- firmware flashing via tftp + webui
- wifi
- leds

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Signed-off-by: Arne Zachlod <arne@nerdkeller.org>
target/linux/ar71xx/base-files/etc/board.d/01_leds
target/linux/ar71xx/base-files/etc/board.d/02_network
target/linux/ar71xx/base-files/lib/ar71xx.sh
target/linux/ar71xx/base-files/lib/upgrade/platform.sh
target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c
target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
target/linux/ar71xx/image/tp-link.mk
target/linux/ar71xx/patches-4.4/999-qca953x-clock-25mhz.patch [new file with mode: 0644]
tools/firmware-utils/src/tplink-safeloader.c

index 51d21ca917bb44e553466b8f4d0b39e8c92cb4be..e15f7435577ea3954ac15c77079ffb9410615118 100755 (executable)
@@ -208,6 +208,15 @@ wbs510)
        ucidef_set_led_rssi "rssimediumhigh" "RSSIMEDIUMHIGH" "tp-link:green:link3" "wlan0" "51" "100" "-50" "13"
        ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "tp-link:green:link4" "wlan0" "76" "100" "-75" "13"
        ;;
+cpe210v2|\
+cpe510v2)
+       ucidef_set_led_netdev "lan" "LAN" "tp-link:green:lan0" "eth0"
+       ucidef_set_rssimon "wlan0" "200000" "1"
+       ucidef_set_led_rssi "rssilow" "RSSILOW" "tp-link:green:link1" "wlan0" "1" "100" "0" "13"
+       ucidef_set_led_rssi "rssimediumlow" "RSSIMEDIUMLOW" "tp-link:green:link2" "wlan0" "26" "100" "-25" "13"
+       ucidef_set_led_rssi "rssimediumhigh" "RSSIMEDIUMHIGH" "tp-link:green:link3" "wlan0" "51" "100" "-50" "13"
+       ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "tp-link:green:link4" "wlan0" "76" "100" "-75" "13"
+       ;;
 cr3000)
        ucidef_set_led_netdev "wan" "WAN" "pcs:blue:wan" "eth1"
        ucidef_set_led_switch "lan1" "LAN1" "pcs:blue:lan1" "switch0" "0x04"
index 39e819fd3dcb4bf942db9c65ad52685e5ddd678b..db2f561b9da942577d5c13081e2bfd4d3e12dddc 100755 (executable)
@@ -70,6 +70,8 @@ ar71xx_setup_interfaces()
        cap4200ag|\
        cf-e380ac-v1|\
        cf-e380ac-v2|\
+       cpe210v2|\
+       cpe510v2|\
        eap120|\
        eap300v2|\
        eap7660d|\
index 0b3645f5cfa3936a443d527b29a77bcaaed0e5e5..59f0a6eb9f7d6c874548ec813deec9b2bea074f6 100755 (executable)
@@ -526,6 +526,18 @@ ar71xx_board_detect() {
                name="cpe210"
                tplink_pharos_board_detect
                ;;
+       *"CPE210 v2")
+               name="cpe210v2"
+               tplink_pharos_board_detect
+               ;;
+       *"CPE510 v2")
+               name="cpe510v2"
+               tplink_pharos_board_detect
+               ;;
+       *"CPE510/520 v2")
+               name="cpe510v2"
+               tplink_pharos_board_detect
+               ;;
        *"CPE505N")
                name="cpe505n"
                ;;
index adb920c393526b5382430c77763bfcb93e7d595a..36ee082e5e67dd32a8412713811cce673e477e18 100755 (executable)
@@ -549,6 +549,12 @@ platform_check_image() {
                tplink_pharos_check_image "$1" "7f454c46" && return 0
                return 1
                ;;
+       cpe210v2|\
+       cpe510v2)
+               # magic = mktplinkfw v1 header
+               tplink_pharos_check_image "$1" "01000000" && return 0
+               return 1
+               ;;
        a40|\
        a60|\
        mr1750v2|\
index 916c32ec49f026534b7dc5a0b9bd3b42cb41885c..5bd74ef53d875779618284034afcf1f1614ad8f8 100644 (file)
 #define CPE510_GPIO_EXTERNAL_LNA1      19
 
 #define CPE510_GPIO_BTN_RESET  4
+#define CPE510V2_GPIO_BTN_RESET        17
 
 #define CPE510_KEYS_POLL_INTERVAL      20 /* msecs */
 #define CPE510_KEYS_DEBOUNCE_INTERVAL  (3 * CPE510_KEYS_POLL_INTERVAL)
+#define CPE510V2_KEYS_DEBOUNCE_INTERVAL        (5 * CPE510_KEYS_POLL_INTERVAL)
 
 
 static struct gpio_led cpe510_leds_gpio[] __initdata = {
@@ -70,6 +72,31 @@ static struct gpio_led cpe510_leds_gpio[] __initdata = {
        },
 };
 
+static struct gpio_led cpe510v2_leds_gpio[] __initdata = {
+       {
+               .name           = "tp-link:green:lan0",
+               .gpio           = CPE510_GPIO_LED_LAN0,
+               .active_low     = 1,
+       }, {
+               .name           = "tp-link:green:link1",
+               .gpio           = CPE510_GPIO_LED_L1,
+               .active_low     = 1,
+       }, {
+               .name           = "tp-link:green:link2",
+               .gpio           = CPE510_GPIO_LED_L2,
+               .active_low     = 1,
+       }, {
+               .name           = "tp-link:green:link3",
+               .gpio           = CPE510_GPIO_LED_L3,
+               .active_low     = 1,
+       }, {
+               .name           = "tp-link:green:link4",
+               .gpio           = CPE510_GPIO_LED_L4,
+               .active_low     = 1,
+       },
+};
+
+
 static struct gpio_led wbs510_leds_gpio[] __initdata = {
        {
                .name           = "tp-link:green:lan0",
@@ -109,6 +136,17 @@ static struct gpio_keys_button cpe510_gpio_keys[] __initdata = {
        }
 };
 
+static struct gpio_keys_button cpe510v2_gpio_keys[] __initdata = {
+       {
+               .desc           = "Reset button",
+               .type           = EV_KEY,
+               .code           = KEY_RESTART,
+               .debounce_interval = CPE510V2_KEYS_DEBOUNCE_INTERVAL,
+               .gpio           = CPE510V2_GPIO_BTN_RESET,
+               .active_low     = 1,
+       }
+};
+
 static void __init cpe_setup(u8 *mac)
 {
        /* Disable JTAG, enabling GPIOs 0-3 */
@@ -132,6 +170,59 @@ static void __init cpe_setup(u8 *mac)
 }
 
 
+static void __init cpe510v2_setup(void)
+{
+       void __iomem *reg;
+
+       u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
+       u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
+
+       ath79_gpio_direction_select(8, 0);
+       ath79_gpio_direction_select(9, 0);
+
+       ath79_gpio_direction_select(10, 1); /* SOUT */
+       ath79_gpio_direction_select(5, 1);
+       ath79_gpio_direction_select(6, 1);
+       ath79_gpio_direction_select(7, 1);
+
+       ath79_gpio_output_select(10, 0x16); /* SOUT */
+       ath79_gpio_output_select(5, 0x09); /* CS0 */
+       ath79_gpio_output_select(6, 0x08); /* CLK */
+       ath79_gpio_output_select(7, 0x0c); /* MOSI */
+
+       ath79_gpio_function_setup(AR934X_GPIO_FUNC_JTAG_DISABLE | AR934X_GPIO_FUNC_CLK_OBS3_EN,
+                                 AR934X_GPIO_FUNC_CLK_OBS4_EN);
+
+       reg = (void *)KSEG1ADDR(AR71XX_GPIO_BASE + QCA953X_GPIO_REG_IN_ENABLE0);
+       /* set in register */
+        __raw_writel(0x908, reg); /* pin 8 + pin 9 = SIN + MISO */
+        /* flush write */
+        __raw_readl(reg);
+
+       ath79_register_leds_gpio(-1, ARRAY_SIZE(cpe510v2_leds_gpio),
+                                cpe510v2_leds_gpio);
+       ath79_register_gpio_keys_polled(1, CPE510_KEYS_POLL_INTERVAL,
+                                       ARRAY_SIZE(cpe510v2_gpio_keys),
+                                       cpe510v2_gpio_keys);
+
+       ath79_register_m25p80(NULL);
+
+       /* ethernet */
+       ath79_register_mdio(0, 0);
+       ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0);
+
+       ath79_switch_data.phy4_mii_en = 1;
+       ath79_eth0_data.duplex = DUPLEX_FULL;
+       ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
+       ath79_eth0_data.phy_mask = BIT(4);
+       ath79_eth0_data.speed = SPEED_100;
+
+       ath79_register_eth(0);
+
+       /* wmac */
+       ath79_register_wmac(ee, mac);
+}
+
 static void __init cpe510_setup(void)
 {
        u8 *mac = (u8 *) KSEG1ADDR(0x1f830008);
@@ -164,6 +255,12 @@ MIPS_MACHINE(ATH79_MACH_CPE210, "CPE210", "TP-LINK CPE210/220",
 MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE510/520",
             cpe510_setup);
 
+MIPS_MACHINE(ATH79_MACH_CPE210V2, "CPE210V2", "TP-LINK CPE210 v2",
+            cpe510v2_setup);
+
+MIPS_MACHINE(ATH79_MACH_CPE510V2, "CPE510V2", "TP-LINK CPE510 v2",
+            cpe510v2_setup);
+
 MIPS_MACHINE(ATH79_MACH_WBS210, "WBS210", "TP-LINK WBS210",
             wbs_setup);
 
index 756d406e119cd77a8cf202031038e0410e8f10a6..98cc27837bcb491a8b06aa027a7f076a7dff1ea0 100644 (file)
@@ -66,8 +66,10 @@ enum ath79_mach_type {
        ATH79_MACH_CF_E520N,                    /* COMFAST CF-E520N */
        ATH79_MACH_CF_E530N,                    /* COMFAST CF-E530N */
        ATH79_MACH_CPE210,                      /* TP-LINK CPE210 */
+       ATH79_MACH_CPE210V2,                    /* TP-LINK CPE210 v2 */
        ATH79_MACH_CPE505N,                     /* P&W CPE505N */
        ATH79_MACH_CPE510,                      /* TP-LINK CPE510 */
+       ATH79_MACH_CPE510V2,                    /* TP-LINK CPE510 v2 */
        ATH79_MACH_CPE830,                      /* YunCore CPE830 */
        ATH79_MACH_CPE870,                      /* YunCore CPE870 */
        ATH79_MACH_CR3000,                      /* PowerCloud CR3000 */
index 5d2518b6cad6891c93bd3ad3967c0a816282b402..d5d7be02fd1f7c6b5deffb606c745883373fe2da 100644 (file)
@@ -221,7 +221,23 @@ define Device/cpe210-220-v1
   $(Device/cpe510-520-v1)
   DEVICE_TITLE := TP-LINK CPE210/220 v1
   BOARDNAME := CPE210
-  TPLINK_BOARD_ID := CPE210
+  TPLINK_BOARD_ID := CPE210V2
+endef
+
+define Device/cpe210-220-v2
+  DEVICE_TITLE := TP-LINK CPE210/220 v2
+  DEVICE_PACKAGES := rssileds
+  MTDPARTS := spi0.0:128k(u-boot)ro,64k(pation-table)ro,64k(product-info)ro,1536k(kernel),6144k(rootfs),192k(config)ro,64k(ART)ro,7680k@0x40000(firmware)
+  IMAGE_SIZE := 7680k
+  BOARDNAME := CPE210V2
+  TPLINK_BOARD_ID := CPE210V2
+  KERNEL := kernel-bin | patch-cmdline | lzma | tplink-v1-header
+  IMAGES := sysupgrade.bin factory.bin
+  IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade
+  IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
+  TPLINK_HWID := 0x0
+  TPLINK_HWREV := 0
+  TPLINK_HEADER_VERSION := 1
 endef
 
 define Device/wbs210-v1
@@ -237,7 +253,7 @@ define Device/wbs510-v1
   BOARDNAME := WBS510
   TPLINK_BOARD_ID := WBS510
 endef
-TARGET_DEVICES += cpe210-220-v1 cpe510-520-v1 wbs210-v1 wbs510-v1
+TARGET_DEVICES += cpe210-220-v1 cpe510-520-v1 cpe210-220-v2 wbs210-v1 wbs510-v1
 
 define Device/eap120-v1
   DEVICE_TITLE := TP-LINK EAP120 v1
diff --git a/target/linux/ar71xx/patches-4.4/999-qca953x-clock-25mhz.patch b/target/linux/ar71xx/patches-4.4/999-qca953x-clock-25mhz.patch
new file mode 100644 (file)
index 0000000..240fbf1
--- /dev/null
@@ -0,0 +1,28 @@
+--- a/arch/mips/ath79/clock.c
++++ b/arch/mips/ath79/clock.c
+@@ -365,10 +365,7 @@ static void __init qca953x_clocks_init(v
+       u32 bootstrap;
+       bootstrap = ath79_reset_rr(QCA953X_RESET_REG_BOOTSTRAP);
+-      if (bootstrap & QCA953X_BOOTSTRAP_REF_CLK_40)
+-              ref_rate = 40 * 1000 * 1000;
+-      else
+-              ref_rate = 25 * 1000 * 1000;
++      ref_rate = 25 * 1000 * 1000;
+       pll = ath79_pll_rr(QCA953X_PLL_CPU_CONFIG_REG);
+       out_div = (pll >> QCA953X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
+--- a/arch/mips/ath79/dev-wmac.c
++++ b/arch/mips/ath79/dev-wmac.c
+@@ -162,10 +162,7 @@ static void qca953x_wmac_setup(void)
+       ath79_wmac_resources[1].end = ATH79_IP2_IRQ(1);
+       t = ath79_reset_rr(QCA953X_RESET_REG_BOOTSTRAP);
+-      if (t & QCA953X_BOOTSTRAP_REF_CLK_40)
+-              ath79_wmac_data.is_clk_25mhz = false;
+-      else
+-              ath79_wmac_data.is_clk_25mhz = true;
++      ath79_wmac_data.is_clk_25mhz = true;
+       ath79_wmac_data.get_mac_revision = ar93xx_get_soc_revision;
+ }
index dceba75da56d8c39eb654c68b1ec2277ed2c872e..a1f43ef2e5e2c8f96584af1280e6d913fbcd72b8 100644 (file)
@@ -154,6 +154,43 @@ static struct device_info boards[] = {
                .last_sysupgrade_partition = "file-system",
        },
 
+       /** Firmware layout for the CPE210/220 v2 */
+       {
+               .id     = "CPE210V2",
+               .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n",
+               .support_list =
+                       "SupportList:\r\n"
+                       "CPE210(TP-LINK|EU|N300-2):2.0\r\n"
+                       "CPE210(TP-LINK|UN|N300-2):2.0\r\n"
+                       "CPE210(TP-LINK|UN|N300-2|00000000):2.0\r\n"
+                       "CPE210(TP-LINK|US|N300-2|55530000):2.0\r\n"
+                       "CPE210(TP-LINK|EU|N300-2|45550000):2.0\r\n",
+               .support_trail = '\xff',
+               .soft_ver = NULL,
+
+               .partitions = {
+                       {"fs-uboot", 0x00000, 0x20000},
+                       {"partition-table", 0x20000, 0x02000},
+                       {"default-mac", 0x30000, 0x00020},
+                       {"product-info", 0x31100, 0x00100},
+                       {"device-info", 0x31400, 0x00400},
+                       {"signature", 0x32000, 0x00400},
+                       {"device-id", 0x33000, 0x00100},
+                       {"os-image", 0x40000, 0x170000},
+                       {"soft-version", 0x1b0000, 0x00100},
+                       {"support-list", 0x1b1000, 0x01000},
+                       {"file-system", 0x1c0000, 0x600000},
+                       {"user-config", 0x7c0000, 0x10000},
+                       {"default-config", 0x7d0000, 0x10000},
+                       {"log", 0x7e0000, 0x10000},
+                       {"radio", 0x7f0000, 0x10000},
+                       {NULL, 0, 0}
+               },
+
+               .first_sysupgrade_partition = "os-image",
+               .last_sysupgrade_partition = "file-system",
+       },
+
        /** Firmware layout for the CPE510/520 */
        {
                .id     = "CPE510",