From 52b8c7a8928ccdc80436c76955f237960ea3bf1f Mon Sep 17 00:00:00 2001
From: Fredrik Olofsson <fredrik.olofsson@anyfinetworks.com>
Date: Tue, 10 Sep 2019 11:25:53 +0200
Subject: [PATCH] ipq40xx: Add support for D-Link DAP-2610

Specifications
==============
- SOC: IPQ4018
- RAM: DDR3 256MB
- Flash: SPI NOR 16MB
- WiFi:
    - 2.4GHz: IPQ4018, 2x2, front end SKY85303-11
    - 5GHz: IPQ4018, 2x2, front end SKY85717-21
- Ethernet: 1x 10/100/1000Mbps, POE 802.3af
- PHY: QCA8072
- UART: GND, blocked, 3.3V, RX, TX / 115200 8N1
- LED: 1x red / green
- Button: 1x reset / factory default
- U-Boot bootloader with tftp and "emergency web server" accessible
  using serial port.

Installation
============
Flash factory image from D-Link web UI. Constraints in the D-Link web UI
makes the factory image unnecessarily large. Flash again using
sysupgrade from inside OpenWrt to reclaim some flash space.

Return to stock D-Link firmware
===============================
Partition layout is preserved, and it is possible to return to the stock
firmware simply by downloading it from D-Link and writing it to the
firmware partition.

    # mtd -r write dap2610-firmware.bin firmware

Quirks
======
To be flashable from the D-Link http server, the firmware must be larger
then 6MB, and the size in the firmware header must match the actual file
size. Also, the boot loader verifies the checksum of the firmware before
each boot, thus the jffs2 must be after the checksum covered part. This
is solved in the factory image by having the rootfs at the very end of
the image (without pad-rootfs).

The sysupgrade image which does not have to be flashable from the D-Link
web UI may be smaller, and the checksum in the firmware header only
covers the kernel part of the image.

Signed-off-by: Fredrik Olofsson <fredrik.olofsson@anyfinetworks.com>
[added WRGG Variables to DEVICE_VARS, squashed spi pinconf/mux,
added emd1's gmac0 config,fix dtc warnings]
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
---
 package/firmware/ipq-wifi/Makefile            |   5 +-
 .../ipq-wifi/board-dlink_dap2610.qca4019      | Bin 0 -> 24316 bytes
 .../ipq40xx/base-files/etc/board.d/02_network |   5 +
 .../etc/hotplug.d/firmware/11-ath10k-caldata  |   8 +
 target/linux/ipq40xx/config-4.19              |   1 +
 .../arm/boot/dts/qcom-ipq4018-dap-2610.dts    | 241 ++++++++++++++++++
 target/linux/ipq40xx/image/Makefile           |  39 ++-
 .../901-arm-boot-add-dts-files.patch          |   3 +-
 8 files changed, 299 insertions(+), 3 deletions(-)
 create mode 100644 package/firmware/ipq-wifi/board-dlink_dap2610.qca4019
 create mode 100644 target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-dap-2610.dts

diff --git a/package/firmware/ipq-wifi/Makefile b/package/firmware/ipq-wifi/Makefile
index 161954fa1f..065cda160d 100644
--- a/package/firmware/ipq-wifi/Makefile
+++ b/package/firmware/ipq-wifi/Makefile
@@ -14,6 +14,8 @@ endef
 define Build/Compile
 endef
 
+# Use ath10k-bdencoder from https://github.com/qca/qca-swiss-army-knife.git
+# to generate the board-* files here.
 #
 # This is intended to be used on an interim basis until device-specific
 # board data for new devices is available through the upstream compilation
@@ -21,11 +23,11 @@ endef
 # Please send a mail with your device-specific board files upstream.
 # You can find instructions and examples on the linux-wireless wiki:
 # <https://wireless.wiki.kernel.org/en/users/drivers/ath10k/boardfiles>
-#
 
 ALLWIFIBOARDS:= \
 	aruba_ap-303 \
 	avm_fritzrepeater-1200 \
+	dlink_dap2610 \
 	ezviz_cs-w3-wd1200g-eup \
 	linksys_ea8300 \
 	qxwlan_e2600ac
@@ -93,6 +95,7 @@ endef
 
 $(eval $(call generate-ipq-wifi-package,aruba_ap-303,Aruba AP-303))
 $(eval $(call generate-ipq-wifi-package,avm_fritzrepeater-1200,AVM FRITZRepeater 1200))
+$(eval $(call generate-ipq-wifi-package,dlink_dap2610,D-Link DAP-2610))
 $(eval $(call generate-ipq-wifi-package,ezviz_cs-w3-wd1200g-eup,EZVIZ CS-W3-WD1200G EUP))
 $(eval $(call generate-ipq-wifi-package,linksys_ea8300,Linksys EA8300))
 $(eval $(call generate-ipq-wifi-package,qxwlan_e2600ac,Qxwlan E2600AC))
diff --git a/package/firmware/ipq-wifi/board-dlink_dap2610.qca4019 b/package/firmware/ipq-wifi/board-dlink_dap2610.qca4019
new file mode 100644
index 0000000000000000000000000000000000000000..08ed731a4cf020b1f79e12649a9cf89153ec0b50
GIT binary patch
literal 24316
zcmeHPTToL;8g7uAipojCEeVH^gj^Vi5Lk$S0s)x-5gFDCM8`!$B>^OYaxqRxxu}Q{
z8BvCd5wuWI@T{wpt23+2u8!+$Y0BN&s(JHe-{wK8tgS6y*4gfJI3bZlh={}G{GtE;
z`~LTLI_K6O`64qTCS#K(E;cVly)mOO3shBA0VtKLkp>_YhSGzzYj>8HMweFUV|JD6
zjWPPNwXtNXw0dVv8A`?_M%V4E(eK=MU~O5YeqTj&*-m4OGBGaJ1GX2yz67hK|MKtv
zOOCJ-wxE8a`k^WTV3}_KGys5F7!PAV_;Dt3c|7V0fcW_M|Ga(;QaL{0&A-p2(P0V4
zS*xk@1i<6TyS3V>k-#rd-Ys*TUS%r^fU`j#T9A*lJrSol_4uwEBT{`WBfWj}%pVBG
zKNDk67Kde@<9yr)Zj6g&W*^uvjRJo>z{o9GzI^3Mw;DL9EOe6hYh)SQhS9Pa7e^0X
z4&H2SHRyA6X)kZ~wltRM@^aQZywQ82wMPF%PU6EMXw~WqbAIy%%I&*yDR_0`=CRfa
z{RUn7%c0)mjpaIRPU^$!sG2S(M+F<4YORNPDO3Y#6nHgo^KfI4E;%O}Hf?U)rOSfV
zuJ*RVrg<va!<)Tl8;!a`RqS{JsiS{Wq#B`2QN^*CY2b*5^VC8>$@$FYSMKBfim!4F
zv0H=EhA-B(B$Y*O=H@-PvA;X}gsdi{q<d&v_nH%eTK3NS7xahoDnuKC((hlcKAuu8
zFXm~VTyOkl;|WD=*sgDf>bp0bimB)Cd3@1$ID5A+hn@Urpt?D?TCzDP>)KU)m!|cz
zdS3bcn{|DwkAxf9CG!g<##<TzZ{MZMSFFO=fx)4?uyFc}KM|vI?1a#*9AbDw1b~N!
zr>Ca}(o2?jdwctgi|=52Ly6|;(E=GqEEd7PNMS^TN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{B3G?k%?mlxzojkikif7i|H<{rv*}HdRiQhc_UH?eq>^9&9`+ro
z)MP4R!ouzi?(a-LDz9N}esn|Mk=7)t4B7FxueL;;7|9Ru|MQi~y&4TJ3}Bmk^N+<H
z2;912{r&5uXOoWzDgw7XuvBg@$ch$YUL%+5YSwFnvOsQY_r~K1bs@$6nma?kJFhw#
zUKO}wr0c-0oORJ6w$BYqU2Tq5sS4zc^wqRw9*(XGDt!8f+*8qwp?d<h-s(JL*q9|3
zvU~=*tM?Ubib>!JuXXEN)*X!6%g(zxSlyG-EUMw`xOT=^nw28r^Eo|Vm+fAk8?6lF
zo^IRvRf0jdjg@};M(u_C)3W-I-HUeNFcW7GSO5sj^cOgM?ZpWm{Vhg~szH~klto6u
zXHhZy^$me2B0?Ck#e2^D0tdsncXHsEti_GMbO|3HyWZkP9dYd$&iyR%_2(wje!{D{
zzWfIvm!9IjV<dkbaqE{g%bT(wM?PweFoO!=`=i#7;ZlHC9Lb?aJbK@zWiX)FTR?K|
z5zpRR{!fy7Px0?x%=P&%X8#Z;-V1W#i@FAXm<>++Y-8(+YftC@ntXdSHp9868MZKH
zIQMp7Q0Awg@6R)8y-RmL1-0Jg8001^RFjUN`vnZ=o&pgeN5g4vGo1U`zG}X||NjGr
C`f|_!

literal 0
HcmV?d00001

diff --git a/target/linux/ipq40xx/base-files/etc/board.d/02_network b/target/linux/ipq40xx/base-files/etc/board.d/02_network
index 59a2be0fe6..9cfc43f1f9 100755
--- a/target/linux/ipq40xx/base-files/etc/board.d/02_network
+++ b/target/linux/ipq40xx/base-files/etc/board.d/02_network
@@ -47,6 +47,7 @@ ipq40xx_setup_interfaces()
 		;;
 	aruba,ap-303|\
 	avm,fritzrepeater-1200|\
+	dlink,dap-2610 |\
 	engenius,eap1300|\
 	meraki,mr33|\
 	netgear,ex6100v2|\
@@ -103,6 +104,10 @@ ipq40xx_setup_macs()
 	cilab,meshpoint-one)
 		label_mac=$(mtd_get_mac_binary "ART" 0x1006)
 		;;
+	dlink,dap-2610)
+		lan_mac=$(mtd_get_mac_ascii bdcfg lanmac)
+		label_mac=$lan_mac
+		;;
 	engenius,ens620ext)
 		wan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
 		lan_mac=$(macaddr_add "$wan_mac" 1)
diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 34ea5a5411..22ac6eefc5 100644
--- a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -87,6 +87,10 @@ case "$FIRMWARE" in
 	unielec,u4019-32m)
 		caldata_extract "0:ART" 0x1000 0x2f20
 		;;
+	dlink,dap-2610)
+		caldata_extract "ART" 0x1000 0x2f20
+		ath10k_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac)
+		;;
 	engenius,ens620ext)
 		caldata_extract "ART" 0x1000 0x2f20
 		ath10k_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +2)
@@ -158,6 +162,10 @@ case "$FIRMWARE" in
 	unielec,u4019-32m)
 		caldata_extract "0:ART" 0x5000 0x2f20
 		;;
+	dlink,dap-2610)
+		caldata_extract "ART" 0x5000 0x2f20
+		ath10k_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
+		;;
 	engenius,ens620ext)
 		caldata_extract "ART" 0x5000 0x2f20
 		ath10k_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +3)
diff --git a/target/linux/ipq40xx/config-4.19 b/target/linux/ipq40xx/config-4.19
index e9c1bcd199..a28497aaec 100644
--- a/target/linux/ipq40xx/config-4.19
+++ b/target/linux/ipq40xx/config-4.19
@@ -305,6 +305,7 @@ CONFIG_MTD_SPI_NAND=y
 CONFIG_MTD_SPI_NOR=y
 CONFIG_MTD_SPLIT_FIRMWARE=y
 CONFIG_MTD_SPLIT_FIT_FW=y
+CONFIG_MTD_SPLIT_WRGG_FW=y
 CONFIG_MTD_UBI=y
 CONFIG_MTD_UBI_BEB_LIMIT=20
 CONFIG_MTD_UBI_BLOCK=y
diff --git a/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-dap-2610.dts b/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-dap-2610.dts
new file mode 100644
index 0000000000..0fd4318527
--- /dev/null
+++ b/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-dap-2610.dts
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+#include "qcom-ipq4019.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/soc/qcom,tcsr.h>
+
+/ {
+	model = "D-Link DAP 2610";
+	compatible = "dlink,dap-2610";
+
+	aliases {
+		led-boot = &led_red;
+		led-failsafe = &led_red;
+		led-running = &led_green;
+		led-upgrade = &led_red;
+	};
+
+	soc {
+		edma@c080000 {
+			qcom,num_gmac = <1>;
+			status = "ok";
+		};
+
+		tcsr@1949000 {
+			compatible = "qcom,tcsr";
+			reg = <0x1949000 0x100>;
+			qcom,wifi_glb_cfg = <TCSR_WIFI_GLB_CFG>;
+		};
+
+		ess_tcsr@1953000 {
+			compatible = "qcom,tcsr";
+			reg = <0x1953000 0x1000>;
+			qcom,ess-interface-select = <TCSR_ESS_PSGMII>;
+		};
+
+		tcsr@1957000 {
+			compatible = "qcom,tcsr";
+			reg = <0x1957000 0x100>;
+			qcom,wifi_noc_memtype_m0_m2 = <TCSR_WIFI_NOC_MEMTYPE_M0_M2>;
+		};
+
+		rng@22000 {
+			status = "ok";
+		};
+
+		crypto@8e3a000 {
+			status = "ok";
+		};
+
+		watchdog@b017000 {
+			status = "ok";
+		};
+
+		ess-switch@c000000 {
+			status = "ok";
+			switch_lan_bmp = <0x20>;
+			switch_wan_bmp = <0x00>;
+		};
+
+		ess-psgmii@98000 {
+			status = "ok";
+		};
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led_red: red {
+			label = "dap-2610:red:power";
+			gpios = <&tlmm 4 GPIO_ACTIVE_LOW>;
+		};
+
+		led_green: green {
+			label = "dap-2610:green:power";
+			gpios = <&tlmm 5 GPIO_ACTIVE_LOW>;
+		};
+	};
+
+	keys {
+		compatible = "gpio-keys";
+
+		reset {
+			label = "reset";
+			gpios = <&tlmm 63 GPIO_ACTIVE_LOW>;
+			linux,code = <KEY_RESTART>;
+		};
+	};
+};
+
+&blsp1_spi1 {
+	pinctrl-0 = <&spi_0_pins>;
+	pinctrl-names = "default";
+	status = "ok";
+	cs-gpios = <&tlmm 54 GPIO_ACTIVE_HIGH>;
+
+	flash@0 {
+		compatible = "jedec,spi-nor";
+		reg = <0>;
+		spi-max-frequency = <24000000>;
+
+		partitions {
+			#address-cells = <1>;
+			#size-cells = <1>;
+			compatible = "fixed-partitions";
+
+			partition@0 {
+				label = "SBL1";
+				reg = <0x0 0x40000>;
+				read-only;
+			};
+			partition@40000 {
+				label = "MIBIB";
+				reg = <0x40000 0x20000>;
+				read-only;
+			};
+			partition@60000 {
+				label = "QSEE";
+				reg = <0x60000 0x60000>;
+				read-only;
+			};
+			partition@c0000 {
+				label = "CDT";
+				reg = <0xc0000 0x10000>;
+				read-only;
+			};
+			partition@d0000 {
+				label = "DDRPARAMS";
+				reg = <0xd0000 0x10000>;
+				read-only;
+			};
+			partition@e0000 {
+				label = "APPSBLENV";
+				reg = <0xe0000 0x10000>;
+				read-only;
+			};
+			partition@f0000 {
+				label = "APPSBL";
+				reg = <0xf0000 0x80000>;
+				read-only;
+			};
+			partition@170000 {
+				label = "ART";
+				reg = <0x170000 0x10000>;
+				read-only;
+			};
+			partition@180000 {
+				compatible = "wrg";
+				label = "firmware";
+				reg = <0x180000 0xdc0000>;
+			};
+			partition@fb0000 {
+				label = "rgbd";
+				reg = <0xfb0000 0x10000>;
+				read-only;
+			};
+			partition@fc0000 {
+				label = "bdcfg";
+				reg = <0xfc0000 0x10000>;
+				read-only;
+			};
+			partition@fd0000 {
+				label = "langpack";
+				reg = <0xfd0000 0x20000>;
+				read-only;
+			};
+			partition@ff0000 {
+				label = "certificate";
+				reg = <0xff0000 0x10000>;
+				read-only;
+			};
+			partition@f40000 {
+				label = "captival";
+				reg = <0xf40000 0x70000>;
+				read-only;
+			};
+		};
+	};
+};
+
+&blsp_dma {
+	status = "ok";
+};
+
+&blsp1_uart1 {
+	pinctrl-0 = <&serial_pins>;
+	pinctrl-names = "default";
+	status = "ok";
+};
+
+&cryptobam {
+	status = "ok";
+};
+
+&gmac0 {
+	qcom,phy_mdio_addr = <4>;
+	qcom,poll_required = <1>;
+	qcom,forced_speed = <1000>;
+	qcom,forced_duplex = <1>;
+	vlan_tag = <1 0x20>;
+};
+
+&mdio {
+	status = "ok";
+};
+
+&tlmm {
+	serial_pins: serial_pinmux {
+		mux {
+			pins = "gpio60", "gpio61";
+			function = "blsp_uart0";
+			bias-disable;
+		};
+	};
+
+	spi_0_pins: spi_0_pinmux {
+		mux {
+			function = "blsp_spi0";
+			pins = "gpio55", "gpio56", "gpio57";
+			drive-strength = <12>;
+			bias-disable;
+		};
+		mux_cs {
+			function = "gpio";
+			pins = "gpio54";
+			drive-strength = <2>;
+			bias-disable;
+			output-high;
+		};
+	};
+};
+
+&wifi0 {
+	status = "ok";
+	qcom,ath10k-calibration-variant = "dlink,dap-2610";
+};
+
+&wifi1 {
+	status = "ok";
+	qcom,ath10k-calibration-variant = "dlink,dap-2610";
+};
diff --git a/target/linux/ipq40xx/image/Makefile b/target/linux/ipq40xx/image/Makefile
index 588a24c2fe..41a65280c3 100644
--- a/target/linux/ipq40xx/image/Makefile
+++ b/target/linux/ipq40xx/image/Makefile
@@ -1,7 +1,8 @@
 include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/image.mk
 
-DEVICE_VARS += RAS_BOARD RAS_ROOTFS_SIZE RAS_VERSION
+DEVICE_VARS += RAS_BOARD RAS_ROOTFS_SIZE RAS_VERSION \
+	       WRGG_DEVNAME WRGG_SIGNATURE
 
 define Device/Default
 	PROFILES := Default
@@ -61,6 +62,15 @@ define Build/SenaoFW
 	@cp $@.new $@
 endef
 
+define Build/wrgg-image
+	mkwrggimg -i $@ \
+	-o $@.new \
+	-d "$(WRGG_DEVNAME)" \
+	-s "$(WRGG_SIGNATURE)" \
+	-v "" -m "" -B ""
+	mv $@.new $@
+endef
+
 define Device/8dev_jalapeno-common
 	$(call Device/FitImage)
 	$(call Device/UbiFit)
@@ -227,6 +237,33 @@ define Device/compex_wpj428
 endef
 TARGET_DEVICES += compex_wpj428
 
+define Device/dlink_dap-2610
+	$(call Device/FitImageLzma)
+	DEVICE_VENDOR := D-Link
+	DEVICE_MODEL := DAP-2610
+	SOC := qcom-ipq4018
+	DEVICE_DTS_CONFIG := config@ap.dk01.1-c1
+	BLOCKSIZE := 64k
+	WRGG_DEVNAME := /dev/mtdblock/8
+	WRGG_SIGNATURE := wapac30_dkbs_dap2610
+	IMAGE_SIZE := 14080k
+	IMAGES := sysupgrade.bin factory.bin
+	# Bootloader expects a special 160 byte header which is added by
+	# wrgg-image.
+	# Factory image size must be larger than 6MB, and size in wrgg header must
+	# match actual factory image size to be flashable from D-Link http server.
+	# Bootloader verifies checksum of wrgg image before booting, thus jffs2
+	# cannot be part of the wrgg image. This is solved in the factory image by
+	# having the rootfs at the end of the image (without pad-rootfs). And in
+	# the sysupgrade image only the kernel is included in the wrgg checksum,
+	# but this is not flashable from the D-link http server.
+	# append-rootfs must start on an erase block boundary.
+	IMAGE/factory.bin    := append-kernel | pad-offset 6144k 160 | append-rootfs | wrgg-image | check-size $$$$(IMAGE_SIZE)
+	IMAGE/sysupgrade.bin := append-kernel | wrgg-image | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size $$$$(IMAGE_SIZE) | append-metadata
+	DEVICE_PACKAGES := ipq-wifi-dlink_dap2610
+endef
+TARGET_DEVICES += dlink_dap-2610
+
 define Device/engenius_eap1300
 	$(call Device/FitImage)
 	DEVICE_VENDOR := EnGenius
diff --git a/target/linux/ipq40xx/patches-4.19/901-arm-boot-add-dts-files.patch b/target/linux/ipq40xx/patches-4.19/901-arm-boot-add-dts-files.patch
index 099a2c7cdb..9c9a31e436 100644
--- a/target/linux/ipq40xx/patches-4.19/901-arm-boot-add-dts-files.patch
+++ b/target/linux/ipq40xx/patches-4.19/901-arm-boot-add-dts-files.patch
@@ -10,12 +10,13 @@ Signed-off-by: John Crispin <john@phrozen.org>
 
 --- a/arch/arm/boot/dts/Makefile
 +++ b/arch/arm/boot/dts/Makefile
-@@ -785,11 +785,40 @@ dtb-$(CONFIG_ARCH_QCOM) += \
+@@ -785,11 +785,41 @@ dtb-$(CONFIG_ARCH_QCOM) += \
  	qcom-apq8074-dragonboard.dtb \
  	qcom-apq8084-ifc6540.dtb \
  	qcom-apq8084-mtp.dtb \
 +	qcom-ipq4018-a42.dtb \
 +	qcom-ipq4018-ap120c-ac.dtb \
++	qcom-ipq4018-dap-2610.dtb \
 +	qcom-ipq4018-cs-w3-wd1200g-eup.dtb \
 +	qcom-ipq4018-ea6350v3.dtb \
 +	qcom-ipq4018-eap1300.dtb \
-- 
2.30.2