[LEDE-DEV] [PATCH 5/5] ar71xx: add support for D-Link DAP-2695 rev. A1

Stijn Tintel stijn at linux-ipv6.be
Sun Sep 11 09:12:35 PDT 2016


Signed-off-by: Stijn Tintel <stijn at linux-ipv6.be>
---
 package/boot/uboot-envtools/files/ar71xx           |   1 +
 target/linux/ar71xx/base-files/etc/board.d/01_leds |   5 +
 .../linux/ar71xx/base-files/etc/board.d/02_network |   5 +
 .../etc/hotplug.d/firmware/11-ath10k-caldata       |   4 +
 .../base-files/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 +
 .../ar71xx/files/arch/mips/ath79/Kconfig.openwrt   |   9 +
 target/linux/ar71xx/files/arch/mips/ath79/Makefile |   1 +
 .../files/arch/mips/ath79/mach-dap-2695-a1.c       | 191 +++++++++++++++++++++
 .../linux/ar71xx/files/arch/mips/ath79/machtypes.h |   1 +
 target/linux/ar71xx/image/generic.mk               |  38 ++++
 13 files changed, 281 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 a075020..45f1f45 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 cf05859..96352a2 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
@@ -197,6 +197,11 @@ rb-2011uias-2hnd)
 	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 b637113..65292b0 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/02_network
+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
@@ -538,6 +538,11 @@ wndr3700)
 	ucidef_add_switch_port_attr "switch0" 5 led 2
 	;;
 
+dap-2695-a1)
+	ucidef_set_interfaces_lan_wan "eth0" "eth1"
+	ucidef_add_switch "switch0" "0 at eth0" "2:lan" "3:wan" "6 at eth1"
+	;;
+
 *)
 	ucidef_set_interfaces_lan_wan "eth0" "eth1"
 	;;
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 0e93feb..31f54e3 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 1bfd525..057afe0 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 e57701a..82c1872 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -469,6 +469,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 716fa52..e94dd13 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"'
 }
@@ -526,6 +530,15 @@ platform_check_image() {
                 }
                 return 0
                 ;;
+	dap-2695-a1)
+		local magic=$(wrgg_get_image_magic "$1")
+		[ "$magic" != "21030820" ] && {
+			echo "Invalid image, bad type: $typemagic"
+			return 1
+		}
+
+		return 0;
+		;;
 
 	esac
 
diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4
index 0b160f3..3be7cb3 100644
--- a/target/linux/ar71xx/config-4.4
+++ b/target/linux/ar71xx/config-4.4
@@ -63,6 +63,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 a6f19da..03caf76 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
@@ -1631,3 +1631,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 3222a76..4427fe0 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Makefile
+++ b/target/linux/ar71xx/files/arch/mips/ath79/Makefile
@@ -67,6 +67,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_DLAN_HOTSPOT)	+= mach-dlan-hotspot.o
 obj-$(CONFIG_ATH79_MACH_DLAN_PRO_500_WP)	+= mach-dlan-pro-500-wp.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 0000000..f0ed911
--- /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 <juhosg at openwrt.org>
+ * Copyright (c) 2016 Stijn Tintel <stijn at linux-ipv6.be>
+ *
+ * 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 <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/platform_device.h>
+#include <linux/ar8216_platform.h>
+
+#include <asm/mach-ath79/ar71xx_regs.h>
+
+#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 a3b8c87..4e6506d 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
@@ -55,6 +55,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_PB44,		/* Atheros PB44 reference board */
 	ATH79_MACH_DGL_5500_A1,		/* D-link DGL-5500 rev. A1 */
diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk
index bd92a84..b762d3c 100644
--- a/target/linux/ar71xx/image/generic.mk
+++ b/target/linux/ar71xx/image/generic.mk
@@ -552,3 +552,41 @@ $(Device/seama)
 endef
 
 TARGET_DEVICES += 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/relocate-kernel
+	rm -rf $(KDIR)/relocate
+	$(CP) ../../generic/image/relocate $(KDIR)
+	$(MAKE) -C $(KDIR)/relocate KERNEL_ADDR=$(KERNEL_LOADADDR) CROSS_COMPILE=$(TARGET_CROSS)
+	( \
+		dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
+		perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
+		cat $@ \
+	) > $@.new
+	#( dd if=/dev/zero bs=385024 count=1 && cat $@ ) > $@.new
+	mv $@.new $@
+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 | seama-pad-rootfs | mkwrggimg | check-size $$$$(IMAGE_SIZE)
+  IMAGE/sysupgrade.bin = append-kernel | pad-offset 65536 160 | mkwrggimg | append-rootfs | seama-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.7.3




More information about the Lede-dev mailing list