From e3875350f3e4185020b64e0588bba521cd1d6e64 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Mon, 18 Jul 2016 19:39:57 +0200 Subject: [PATCH] ar71xx: add support for D-Link DAP-2695 rev. A1 Signed-off-by: Stijn Tintel Acked-by: John Crispin --- package/boot/uboot-envtools/files/ar71xx | 1 + .../ar71xx/base-files/etc/board.d/01_leds | 5 + .../ar71xx/base-files/etc/board.d/02_network | 3 + .../etc/hotplug.d/firmware/11-ath10k-caldata | 4 + .../etc/uci-defaults/09_fix-checksum | 9 + target/linux/ar71xx/base-files/lib/ar71xx.sh | 3 + .../ar71xx/base-files/lib/upgrade/platform.sh | 13 ++ target/linux/ar71xx/config-4.4 | 1 + .../files/arch/mips/ath79/Kconfig.openwrt | 9 + .../ar71xx/files/arch/mips/ath79/Makefile | 1 + .../files/arch/mips/ath79/mach-dap-2695-a1.c | 191 ++++++++++++++++++ .../ar71xx/files/arch/mips/ath79/machtypes.h | 1 + target/linux/ar71xx/image/generic.mk | 29 +++ 13 files changed, 270 insertions(+) create mode 100644 target/linux/ar71xx/files/arch/mips/ath79/mach-dap-2695-a1.c diff --git a/package/boot/uboot-envtools/files/ar71xx b/package/boot/uboot-envtools/files/ar71xx index a075020fdb..45f1f4561f 100644 --- a/package/boot/uboot-envtools/files/ar71xx +++ b/package/boot/uboot-envtools/files/ar71xx @@ -54,6 +54,7 @@ om2p-lc) dr531) ubootenv_add_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000" ;; +dap-2695-a1 | \ wzr-hp-ag300h) ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000" ;; 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 9734189fd5..a32ca9101e 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/01_leds +++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds @@ -174,6 +174,11 @@ rb-2011uias-2hnd) ucidef_set_led_switch "eth9" "ETH9" "rb:green:eth9" "switch1" "0x04" ucidef_set_led_switch "eth10" "ETH10" "rb:green:eth10" "switch1" "0x02" ;; +dap-2695-a1) + ucidef_set_led_default "power" "POWER" "d-link:green:power" "1" + ucidef_set_led_default "diag" "DIAG" "d-link:red:power" "0" + ucidef_set_led_wlan "wlan2g" "WLAN 2.4 GHz" "d-link:green:wlan2g" "phy1tpt" + ;; dhp-1565-a1) ucidef_set_led_switch "wan" "WAN" "d-link:green:planet" "switch0" "0x20" ;; 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 35a7407ef7..1cb6b4c292 100755 --- a/target/linux/ar71xx/base-files/etc/board.d/02_network +++ b/target/linux/ar71xx/base-files/etc/board.d/02_network @@ -230,6 +230,9 @@ ar71xx_setup_interfaces() ucidef_add_switch "switch0" \ "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" ;; + dap-2695-a1) + ucidef_add_switch "switch0" "0@eth0" "2:lan" "3:wan" "6@eth1" + ;; db120|\ rb-2011l|\ rb-2011uas|\ diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 322998d2cf..5a48b06a36 100644 --- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -47,6 +47,10 @@ board=$(ar71xx_board_name) case "$FIRMWARE" in "ath10k/cal-pci-0000:00:00.0.bin") case $board in + dap-2695-a1) + ath10kcal_extract "radiocfg" 20480 2116 + ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a) + ;; dlan-pro-1200-ac) ath10kcal_extract "art" 20480 2116 ;; diff --git a/target/linux/ar71xx/base-files/etc/uci-defaults/09_fix-checksum b/target/linux/ar71xx/base-files/etc/uci-defaults/09_fix-checksum index 1bfd5253eb..057afe0193 100644 --- a/target/linux/ar71xx/base-files/etc/uci-defaults/09_fix-checksum +++ b/target/linux/ar71xx/base-files/etc/uci-defaults/09_fix-checksum @@ -11,9 +11,18 @@ fixtrx() { mtd -o 32 fixtrx firmware } +fixwrgg() { + local kernel_size=$(sed -n 's/mtd[0-9]*: \([0-9a-f]*\).*"kernel".*/\1/p' /proc/mtd) + + [ "$kernel_size" ] && mtd -c 0x$kernel_size fixwrgg firmware +} + case "$board" in mynet-rext |\ wrt160nl) fixtrx ;; +dap-2695-a1) + fixwrgg + ;; esac diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh index fb375a5e15..f51d7db9c1 100755 --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh @@ -511,6 +511,9 @@ ar71xx_board_detect() { *CR5000) name="cr5000" ;; + *"DAP-2695 rev. A1") + name="dap-2695-a1" + ;; *"DB120 reference board") name="db120" ;; diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh index 46f014306f..9c0f3f3bc5 100755 --- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh @@ -105,6 +105,10 @@ seama_get_type_magic() { get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' } +wrgg_get_image_magic() { + get_image "$@" | dd bs=4 count=1 skip=8 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + cybertan_get_image_magic() { get_image "$@" | dd bs=8 count=1 skip=0 2>/dev/null | hexdump -v -n 8 -e '1/1 "%02x"' } @@ -531,6 +535,15 @@ platform_check_image() { return 0 ;; + dap-2695-a1) + local magic=$(wrgg_get_image_magic "$1") + [ "$magic" != "21030820" ] && { + echo "Invalid image, bad type: $magic" + return 1 + } + + return 0; + ;; esac echo "Sysupgrade is not yet supported on $board." diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4 index 0e731e8e0d..4e3f5a4beb 100644 --- a/target/linux/ar71xx/config-4.4 +++ b/target/linux/ar71xx/config-4.4 @@ -64,6 +64,7 @@ CONFIG_ATH79_MACH_CF_E316N_V2=y CONFIG_ATH79_MACH_CPE510=y CONFIG_ATH79_MACH_CR3000=y CONFIG_ATH79_MACH_CR5000=y +CONFIG_ATH79_MACH_DAP_2695_A1=y CONFIG_ATH79_MACH_DB120=y CONFIG_ATH79_MACH_DGL_5500_A1=y CONFIG_ATH79_MACH_DHP_1565_A1=y diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt index a81620f474..86df292dd8 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt +++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt @@ -1698,3 +1698,12 @@ config ATH79_MACH_QIHOO_C301 select ATH79_DEV_WMAC select ATH79_DEV_USB select ATH79_NVRAM + +config ATH79_MACH_DAP_2695_A1 + bool "D-Link DAP-2695 rev. A1 support" + select SOC_QCA955X + select ATH79_DEV_ETH + select ATH79_DEV_GPIO_BUTTONS + select ATH79_DEV_LEDS_GPIO + select ATH79_DEV_M25P80 + select ATH79_DEV_WMAC diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Makefile b/target/linux/ar71xx/files/arch/mips/ath79/Makefile index 671c30bb3c..4b927bcc3b 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile +++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_ATH79_MACH_CF_E316N_V2) += mach-cf-e316n-v2.o obj-$(CONFIG_ATH79_MACH_CPE510) += mach-cpe510.o obj-$(CONFIG_ATH79_MACH_CR3000) += mach-cr3000.o obj-$(CONFIG_ATH79_MACH_CR5000) += mach-cr5000.o +obj-$(CONFIG_ATH79_MACH_DAP_2695_A1) += mach-dap-2695-a1.o obj-$(CONFIG_ATH79_MACH_DB120) += mach-db120.o obj-$(CONFIG_ATH79_MACH_DGL_5500_A1) += mach-dgl-5500-a1.o obj-$(CONFIG_ATH79_MACH_DHP_1565_A1) += mach-dhp-1565-a1.o diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-dap-2695-a1.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-dap-2695-a1.c new file mode 100644 index 0000000000..f0ed911c81 --- /dev/null +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-dap-2695-a1.c @@ -0,0 +1,191 @@ +/* + * D-Link DAP-2695 rev. A1 support + * + * Copyright (c) 2012 Qualcomm Atheros + * Copyright (c) 2012-2013 Gabor Juhos + * Copyright (c) 2016 Stijn Tintel + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include +#include +#include + +#include + +#include "common.h" +#include "pci.h" +#include "dev-ap9x-pci.h" +#include "dev-gpio-buttons.h" +#include "dev-eth.h" +#include "dev-leds-gpio.h" +#include "dev-m25p80.h" +#include "dev-spi.h" +#include "dev-wmac.h" +#include "machtypes.h" +#include "nvram.h" + +#define DAP2695_GPIO_LED_GREEN_POWER 23 +#define DAP2695_GPIO_LED_RED_POWER 14 +#define DAP2695_GPIO_LED_WLAN_2G 13 + +#define DAP2695_GPIO_BTN_RESET 17 + +#define DAP2695_KEYS_POLL_INTERVAL 20 /* msecs */ +#define DAP2695_KEYS_DEBOUNCE_INTERVAL (3 * DAP2695_KEYS_POLL_INTERVAL) + +#define DAP2695_NVRAM_ADDR 0x1f040000 +#define DAP2695_NVRAM_SIZE 0x10000 + +#define DAP2695_MAC0_OFFSET 1 +#define DAP2695_MAC1_OFFSET 2 +#define DAP2695_WMAC_CALDATA_OFFSET 0x1000 + +static struct gpio_led dap2695_leds_gpio[] __initdata = { + { + .name = "d-link:green:power", + .gpio = DAP2695_GPIO_LED_GREEN_POWER, + .active_low = 1, + }, + { + .name = "d-link:red:power", + .gpio = DAP2695_GPIO_LED_RED_POWER, + .active_low = 1, + }, + { + .name = "d-link:green:wlan2g", + .gpio = DAP2695_GPIO_LED_WLAN_2G, + .active_low = 1, + }, +}; + +static struct gpio_keys_button dap2695_gpio_keys[] __initdata = { + { + .desc = "Soft reset", + .type = EV_KEY, + .code = KEY_RESTART, + .debounce_interval = DAP2695_KEYS_DEBOUNCE_INTERVAL, + .gpio = DAP2695_GPIO_BTN_RESET, + .active_low = 1, + }, +}; + +static struct ar8327_pad_cfg dap2695_ar8327_pad0_cfg = { + .mode = AR8327_PAD_MAC_RGMII, + .txclk_delay_en = true, + .rxclk_delay_en = true, + .txclk_delay_sel = AR8327_CLK_DELAY_SEL1, + .rxclk_delay_sel = AR8327_CLK_DELAY_SEL2, + .mac06_exchange_dis = true, +}; + +static struct ar8327_pad_cfg dap2695_ar8327_pad6_cfg = { + .mode = AR8327_PAD_MAC_SGMII, + .sgmii_delay_en = true, +}; + +static struct ar8327_platform_data dap2695_ar8327_data = { + .pad0_cfg = &dap2695_ar8327_pad0_cfg, + .pad6_cfg = &dap2695_ar8327_pad6_cfg, + .port0_cfg = { + .force_link = 1, + .speed = AR8327_PORT_SPEED_1000, + .duplex = 1, + .txpause = 1, + .rxpause = 1, + }, + .port6_cfg = { + .force_link = 1, + .speed = AR8327_PORT_SPEED_1000, + .duplex = 1, + .txpause = 1, + .rxpause = 1, + }, +}; + +static struct mdio_board_info dap2695_mdio0_info[] = { + { + .bus_id = "ag71xx-mdio.0", + .phy_addr = 0, + .platform_data = &dap2695_ar8327_data, + }, +}; + +static struct flash_platform_data dap2695_flash_data = { + .type = "mx25l12805d", +}; + +static void dap2695_get_mac(const char *name, char *mac) +{ + u8 *nvram = (u8 *) KSEG1ADDR(DAP2695_NVRAM_ADDR); + int err; + + err = ath79_nvram_parse_mac_addr(nvram, DAP2695_NVRAM_SIZE, + name, mac); + if (err) + pr_err("no MAC address found for %s\n", name); +} + +static void __init dap2695_setup(void) +{ + u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); + u8 mac0[ETH_ALEN], mac1[ETH_ALEN], wmac0[ETH_ALEN]; + + dap2695_get_mac("lanmac=", mac0); + dap2695_get_mac("wanmac=", mac1); + dap2695_get_mac("wlanmac=", wmac0); + + ath79_register_m25p80(&dap2695_flash_data); + + ath79_register_leds_gpio(-1, ARRAY_SIZE(dap2695_leds_gpio), + dap2695_leds_gpio); + ath79_register_gpio_keys_polled(-1, DAP2695_KEYS_POLL_INTERVAL, + ARRAY_SIZE(dap2695_gpio_keys), + dap2695_gpio_keys); + + ath79_register_wmac(art + DAP2695_WMAC_CALDATA_OFFSET, wmac0); + + ath79_setup_qca955x_eth_cfg(QCA955X_ETH_CFG_RGMII_EN); + + ath79_register_mdio(0, 0x0); + + mdiobus_register_board_info(dap2695_mdio0_info, + ARRAY_SIZE(dap2695_mdio0_info)); + + /* GMAC0 is connected to the RGMII interface */ + ath79_init_mac(ath79_eth0_data.mac_addr, mac0, DAP2695_MAC0_OFFSET); + ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII; + ath79_eth0_data.phy_mask = BIT(0); + ath79_eth0_data.mii_bus_dev = &ath79_mdio0_device.dev; + ath79_eth0_pll_data.pll_1000 = 0x56000000; + + ath79_register_eth(0); + + /* GMAC1 is connected to the SGMII interface */ + ath79_init_mac(ath79_eth1_data.mac_addr, mac1, DAP2695_MAC1_OFFSET); + ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_SGMII; + ath79_eth1_data.speed = SPEED_1000; + ath79_eth1_data.duplex = DUPLEX_FULL; + ath79_eth1_pll_data.pll_1000 = 0x03000101; + + ath79_register_eth(1); + + ath79_register_pci(); +} + +MIPS_MACHINE(ATH79_MACH_DAP_2695_A1, "DAP-2695-A1", + "D-Link DAP-2695 rev. A1", + dap2695_setup); diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h index 1a67f26190..1243409159 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h +++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h @@ -56,6 +56,7 @@ enum ath79_mach_type { ATH79_MACH_CPE510, /* TP-LINK CPE510 */ ATH79_MACH_CR3000, /* PowerCloud CR3000 */ ATH79_MACH_CR5000, /* PowerCloud CR5000 */ + ATH79_MACH_DAP_2695_A1, /* D-Link DAP-2695 rev. A1 */ ATH79_MACH_DB120, /* Atheros DB120 reference board */ ATH79_MACH_DGL_5500_A1, /* D-link DGL-5500 rev. A1 */ ATH79_MACH_DHP_1565_A1, /* D-Link DHP-1565 rev. A1 */ diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk index 070bfbb1d6..ae0c7fcae1 100644 --- a/target/linux/ar71xx/image/generic.mk +++ b/target/linux/ar71xx/image/generic.mk @@ -597,3 +597,32 @@ $(Device/seama) endef TARGET_DEVICES += dir-869-a1 mynet-n600 mynet-n750 qihoo-c301 + +define Build/mkwrggimg + $(STAGING_DIR_HOST)/bin/mkwrggimg -b \ + -i $@ -o $@.imghdr -d /dev/mtdblock/1 \ + -m $(BOARDNAME) -s $(DAP_SIGNATURE) \ + -v LEDE -B $(REVISION) + mv $@.imghdr $@ +endef + +define Build/wrgg-pad-rootfs + $(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 64 >>$@ +endef + +define Device/dap-2695-a1 + DEVICE_TITLE := D-Link DAP-2695 rev. A1 + DEVICE_PACKAGES := ath10k-firmware-qca988x kmod-ath10k uboot-envtools + BOARDNAME = DAP-2695-A1 + IMAGES := factory.img sysupgrade.bin + IMAGE_SIZE = 15360k + IMAGE/factory.img = append-kernel | pad-offset 65536 160 | append-rootfs | wrgg-pad-rootfs | mkwrggimg | check-size $$$$(IMAGE_SIZE) + IMAGE/sysupgrade.bin = append-kernel | pad-offset 65536 160 | mkwrggimg | append-rootfs | wrgg-pad-rootfs | check-size $$$$(IMAGE_SIZE) + KERNEL := kernel-bin | patch-cmdline | relocate-kernel | lzma + KERNEL_INITRAMFS := $$(KERNEL) | mkwrggimg + MTDPARTS = spi0.0:256k(bootloader)ro,64k(bdcfg)ro,64k(rgdb)ro,64k(langpack)ro,15360k(firmware),448k(captival)ro,64k(certificate)ro,64k(radiocfg)ro + DAP_SIGNATURE := wapac02_dkbs_dap2695 + DEVICE_VARS += DAP_SIGNATURE +endef + +TARGET_DEVICES += dap-2695-a1 -- 2.30.2