From 7d710a2b0487755c09d0caf6a1ab910ac5732dc6 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Wed, 11 Oct 2017 20:19:59 +0200 Subject: [PATCH] [WIP] add basic support cpe210v2 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 Signed-off-by: Arne Zachlod --- .../ar71xx/base-files/etc/board.d/01_leds | 9 ++ .../ar71xx/base-files/etc/board.d/02_network | 2 + target/linux/ar71xx/base-files/lib/ar71xx.sh | 12 +++ .../ar71xx/base-files/lib/upgrade/platform.sh | 6 ++ .../files/arch/mips/ath79/mach-cpe510.c | 97 +++++++++++++++++++ .../ar71xx/files/arch/mips/ath79/machtypes.h | 2 + target/linux/ar71xx/image/tp-link.mk | 20 +++- .../patches-4.4/999-qca953x-clock-25mhz.patch | 28 ++++++ tools/firmware-utils/src/tplink-safeloader.c | 37 +++++++ 9 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 target/linux/ar71xx/patches-4.4/999-qca953x-clock-25mhz.patch diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds index 51d21ca917..e15f743557 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/01_leds +++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds @@ -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" diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network index 39e819fd3d..db2f561b9d 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -70,6 +70,8 @@ ar71xx_setup_interfaces() cap4200ag|\ cf-e380ac-v1|\ cf-e380ac-v2|\ + cpe210v2|\ + cpe510v2|\ eap120|\ eap300v2|\ eap7660d|\ diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh index 0b3645f5cf..59f0a6eb9f 100755 --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh @@ -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" ;; diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh index adb920c393..36ee082e5e 100755 --- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh @@ -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|\ diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c index 916c32ec49..5bd74ef53d 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c @@ -37,9 +37,11 @@ #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); diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h index 756d406e11..98cc27837b 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h @@ -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 */ diff --git a/target/linux/ar71xx/image/tp-link.mk b/target/linux/ar71xx/image/tp-link.mk index 5d2518b6ca..d5d7be02fd 100644 --- a/target/linux/ar71xx/image/tp-link.mk +++ b/target/linux/ar71xx/image/tp-link.mk @@ -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 index 0000000000..240fbf150e --- /dev/null +++ b/target/linux/ar71xx/patches-4.4/999-qca953x-clock-25mhz.patch @@ -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; + } diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c index dceba75da5..a1f43ef2e5 100644 --- a/tools/firmware-utils/src/tplink-safeloader.c +++ b/tools/firmware-utils/src/tplink-safeloader.c @@ -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", -- 2.30.2