From 6e2faecb4e535ba12f03761fb0367ce9ce7676a6 Mon Sep 17 00:00:00 2001
From: Sven Eckelmann <sven@narfation.org>
Date: Mon, 23 Nov 2020 21:19:27 +0100
Subject: [PATCH] ath79: add support for Plasma Cloud PA300E

---
 docs/user/supported_devices.rst               |   1 +
 .../luasrc/usr/lib/lua/gluon/platform.lua     |   1 +
 ...-Add-support-for-Plasma-Cloud-PA300E.patch | 123 ++++++++++++++++++
 targets/ath79-generic                         |   2 +
 4 files changed, 127 insertions(+)
 create mode 100644 patches/openwrt/0020-ath79-Add-support-for-Plasma-Cloud-PA300E.patch

diff --git a/docs/user/supported_devices.rst b/docs/user/supported_devices.rst
index 0f406d0bd..f7375c286 100644
--- a/docs/user/supported_devices.rst
+++ b/docs/user/supported_devices.rst
@@ -206,6 +206,7 @@ ath79-generic
 * Plasma Cloud
 
   - PA300
+  - PA300E
 
 * TP-Link
 
diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
index b583222ff..fb5699038 100644
--- a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
+++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua
@@ -54,6 +54,7 @@ function M.is_outdoor_device()
 	elseif M.match('ath79', 'generic', {
 		'devolo,dvl1750x',
 		'plasmacloud,pa300',
+		'plasmacloud,pa300e',
 		'tplink,cpe220-v3',
 	}) then
 		return true
diff --git a/patches/openwrt/0020-ath79-Add-support-for-Plasma-Cloud-PA300E.patch b/patches/openwrt/0020-ath79-Add-support-for-Plasma-Cloud-PA300E.patch
new file mode 100644
index 000000000..d2a4f8d87
--- /dev/null
+++ b/patches/openwrt/0020-ath79-Add-support-for-Plasma-Cloud-PA300E.patch
@@ -0,0 +1,123 @@
+From: Sven Eckelmann <sven@narfation.org>
+Date: Mon, 23 Nov 2020 13:41:34 +0100
+Subject: ath79: Add support for Plasma Cloud PA300E
+
+Device specifications:
+
+* Qualcomm/Atheros QCA9533 v2
+* 650/600/217 MHz (CPU/DDR/AHB)
+* 64 MB of RAM
+* 16 MB of SPI NOR flash (mx25l12805d)
+  - 2x 7 MB available; but one of the 7 MB regions is the recovery image
+* 2x 10/100 Mbps Ethernet
+* 2T2R 2.4 GHz Wi-Fi
+* multi-color LED (controlled via red/green/blue GPIOs)
+* 1x GPIO-button (reset)
+* external h/w watchdog (enabled by default)
+* TTL pins are on board (arrow points to VCC, then follows: GND, TX, RX)
+* 2x fast ethernet
+  - eth0
+    + Label: Ethernet 1
+    + 24V passive POE (mode B)
+    + used as WAN interface
+  - eth1
+    + Label: Ethernet 2
+    + 802.3af POE
+    + builtin switch port 2
+    + used as LAN interface
+* 12-24V 1A DC
+* external antennas
+
+Flashing instructions:
+
+The tool ap51-flash (https://github.com/ap51-flash/ap51-flash) should be
+used to transfer the factory image to the u-boot when the device boots up.
+
+Signed-off-by: Sven Eckelmann <sven@narfation.org>
+Origin: backport, https://github.com/openwrt/openwrt/commit/ba6a387b9700bc1d486f2a73fbd4b88cfb5758f1
+
+diff --git a/package/boot/uboot-envtools/files/ath79 b/package/boot/uboot-envtools/files/ath79
+index 8808e81682f70583c4b2a888f8ddca9448277919..a5df255009919d62d580faa9baf2ef4fe45d36ec 100644
+--- a/package/boot/uboot-envtools/files/ath79
++++ b/package/boot/uboot-envtools/files/ath79
+@@ -39,7 +39,8 @@ netgear,wndr3700|\
+ netgear,wndr3700-v2)
+ 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
+ 	;;
+-plasmacloud,pa300)
++plasmacloud,pa300|\
++plasmacloud,pa300e)
+ 	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
+ 	;;
+ esac
+diff --git a/target/linux/ath79/base-files/etc/board.d/02_network b/target/linux/ath79/base-files/etc/board.d/02_network
+index 846e2807ede8ec828a2f519f9b33c0d1dfdd5129..57429fbc1c851b6d8a8a03096d7043f78a489549 100755
+--- a/target/linux/ath79/base-files/etc/board.d/02_network
++++ b/target/linux/ath79/base-files/etc/board.d/02_network
+@@ -116,6 +116,7 @@ ath79_setup_interfaces()
+ 	comfast,cf-e110n-v2|\
+ 	comfast,cf-e120a-v3|\
+ 	plasmacloud,pa300|\
++	plasmacloud,pa300e|\
+ 	tplink,cpe220-v3|\
+ 	ubnt,nanostation-m|\
+ 	ubnt,routerstation)
+diff --git a/target/linux/ath79/base-files/lib/upgrade/dualboot_datachk.sh b/target/linux/ath79/base-files/lib/upgrade/dualboot_datachk.sh
+index 68733ccf154582e29b6416ad8daa7eb7a81bcc7e..002f5f9668978292615b19c3ba14b17afac709e2 100644
+--- a/target/linux/ath79/base-files/lib/upgrade/dualboot_datachk.sh
++++ b/target/linux/ath79/base-files/lib/upgrade/dualboot_datachk.sh
+@@ -45,7 +45,8 @@ platform_do_upgrade_dualboot_datachk() {
+ 	# boot anymore to Linux until it was reflashed with ap51-flash.
+ 	local next_boot_part="1"
+ 	case "$(board_name)" in
+-	plasmacloud,pa300)
++	plasmacloud,pa300|\
++	plasmacloud,pa300e)
+ 		primary_kernel_mtd=3
+ 		;;
+ 	*)
+diff --git a/target/linux/ath79/base-files/lib/upgrade/platform.sh b/target/linux/ath79/base-files/lib/upgrade/platform.sh
+index c4f869932a02ef353e694b50496c3b2ed5d59f12..f1bbc24036d4f371c941f9736bc736be4903dec7 100644
+--- a/target/linux/ath79/base-files/lib/upgrade/platform.sh
++++ b/target/linux/ath79/base-files/lib/upgrade/platform.sh
+@@ -46,7 +46,8 @@ platform_do_upgrade() {
+ 	jjplus,ja76pf2)
+ 		redboot_fis_do_upgrade "$1" linux
+ 		;;
+-	plasmacloud,pa300)
++	plasmacloud,pa300|\
++	plasmacloud,pa300e)
+ 		PART_NAME="inactive"
+ 		platform_do_upgrade_dualboot_datachk "$1"
+ 		;;
+diff --git a/target/linux/ath79/dts/qca9533_plasmacloud_pa300e.dts b/target/linux/ath79/dts/qca9533_plasmacloud_pa300e.dts
+new file mode 100644
+index 0000000000000000000000000000000000000000..1527a796bb63b7c33b60caaeb97438936daf727e
+--- /dev/null
++++ b/target/linux/ath79/dts/qca9533_plasmacloud_pa300e.dts
+@@ -0,0 +1,8 @@
++// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
++
++#include "qca9533_plasmacloud_pa300.dtsi"
++
++/ {
++	compatible = "plasmacloud,pa300e", "qca,qca9533";
++	model = "Plasma Cloud PA300E";
++};
+diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk
+index 3c1db9b3204d6784580f87ea9adb7a2ba98d285b..7159f9c6d2dabf0a80b4a107790471da32af97bc 100644
+--- a/target/linux/ath79/image/generic.mk
++++ b/target/linux/ath79/image/generic.mk
+@@ -663,6 +663,12 @@ define Device/plasmacloud_pa300
+ endef
+ TARGET_DEVICES += plasmacloud_pa300
+ 
++define Device/plasmacloud_pa300e
++  $(Device/plasmacloud_pa300-common)
++  DEVICE_TITLE := Plasma Cloud PA300E
++endef
++TARGET_DEVICES += plasmacloud_pa300e
++
+ define Device/netgear_wndr3800
+   $(Device/netgear_wndr3x00)
+   DEVICE_TITLE := NETGEAR WNDR3800
diff --git a/targets/ath79-generic b/targets/ath79-generic
index 19ce8bacd..38388ec6f 100644
--- a/targets/ath79-generic
+++ b/targets/ath79-generic
@@ -75,6 +75,8 @@ device('ocedo-raccoon', 'ocedo_raccoon', {
 
 device('plasma-cloud-pa300', 'plasmacloud_pa300')
 
+device('plasma-cloud-pa300e', 'plasmacloud_pa300e')
+
 -- TP-Link
 
 device('tp-link-archer-c2-v3', 'tplink_archer-c2-v3', {
-- 
GitLab