From a7331b5933f421312f72029db0b49561c379f439 Mon Sep 17 00:00:00 2001
From: David Bauer <mail@david-bauer.net>
Date: Thu, 5 Aug 2021 02:07:30 +0200
Subject: [PATCH] ath79-generic: add support for Joy-IT JT-OR750i (#2284)

---
 ...h79-add-support-for-Joy-IT-JT-OR750i.patch | 220 ++++++++++++++++++
 ...-enable-missing-pinmux-for-JT-OR750i.patch |  24 ++
 ...-fix-JT-OR750i-switch-LED-assignment.patch |  26 +++
 targets/ath79-generic                         |   9 +
 4 files changed, 279 insertions(+)
 create mode 100644 patches/openwrt/0023-ath79-add-support-for-Joy-IT-JT-OR750i.patch
 create mode 100644 patches/openwrt/0024-ath79-enable-missing-pinmux-for-JT-OR750i.patch
 create mode 100644 patches/openwrt/0025-ath79-fix-JT-OR750i-switch-LED-assignment.patch

diff --git a/patches/openwrt/0023-ath79-add-support-for-Joy-IT-JT-OR750i.patch b/patches/openwrt/0023-ath79-add-support-for-Joy-IT-JT-OR750i.patch
new file mode 100644
index 000000000..50c0cd0f6
--- /dev/null
+++ b/patches/openwrt/0023-ath79-add-support-for-Joy-IT-JT-OR750i.patch
@@ -0,0 +1,220 @@
+From: Vincent Wiemann <vincent.wiemann@ironai.com>
+Date: Sun, 20 Jun 2021 16:56:21 +0200
+Subject: ath79: add support for Joy-IT JT-OR750i
+
+Specifications:
+ * QCA9531, 16 MiB flash (Winbond W25Q128JVSQ), 128 MiB RAM
+ * 802.11n 2T2R (external antennas)
+ * QCA9887, 802.11ac 1T1R (connected with diplexer to one of the antennas)
+ * 3x 10/100 LAN, 1x 10/100 WAN
+ * UART header with pinout printed on PCB
+
+Installation:
+ * The device comes with a bootloader installed only
+ * The bootloader offers DHCP and is reachable at http://10.123.123.1
+ * Accept the agreement and flash sysupgrade.bin
+ * Use Firefox if flashing does not work
+
+TFTP recovery with static IP:
+ * Rename sysupgrade.bin to jt-or750i_firmware.bin
+ * Offer it via TFTP server at 192.168.0.66
+ * Keep the reset button pressed for 4 seconds after connecting power
+
+TFTP recovery with dynamic IP:
+ * Rename sysupgrade.bin to jt-or750i_firmware.bin
+ * Offer it via TFTP server with a DHCP server running at the same address
+ * Keep the reset button pressed for 6 seconds after connecting power
+
+Co-authored-by: Sebastian Schaper <openwrt@sebastianschaper.net>
+Signed-off-by: Vincent Wiemann <vincent.wiemann@ironai.com>
+(cherry picked from commit 55b4b3655263984b92e4b9fc515a5e6b8003c655)
+
+diff --git a/target/linux/ath79/base-files/etc/board.d/01_leds b/target/linux/ath79/base-files/etc/board.d/01_leds
+index dd0f91affa3cd9a731343a816bc666e0bbd44e99..ba8dcd430304a284296861b9e0694be42c68fe44 100755
+--- a/target/linux/ath79/base-files/etc/board.d/01_leds
++++ b/target/linux/ath79/base-files/etc/board.d/01_leds
+@@ -84,6 +84,9 @@ glinet,gl-ar300m-lite)
+ glinet,gl-x750)
+ 	ucidef_set_led_netdev "wan" "WAN" "$boardname:green:wan" "eth1"
+ 	;;
++joyit,jt-or750i)
++	ucidef_set_led_default "ath10k" "ath10k-disable" "ath10k-phy0" "0"
++	;;
+ netgear,wnr612-v2|\
+ on,n150r)
+ 	ucidef_set_led_netdev "wan" "WAN" "netgear:green:wan" "eth0"
+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 57429fbc1c851b6d8a8a03096d7043f78a489549..fba5d68eafff37bcedeb734a4d524cfb338d00fa 100755
+--- a/target/linux/ath79/base-files/etc/board.d/02_network
++++ b/target/linux/ath79/base-files/etc/board.d/02_network
+@@ -171,6 +171,11 @@ ath79_setup_interfaces()
+ 		ucidef_add_switch "switch0" \
+ 			"0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
+ 	;;
++	joyit,jt-or750i)
++		ucidef_set_interface_wan "eth1"
++		ucidef_add_switch "switch0" \
++			"0@eth0" "2:lan:3" "3:lan:2" "4:lan:1"
++		;;
+ 	librerouter,librerouter-v1)
+ 		ucidef_add_switch "switch0" \
+ 			"0@eth0" "5:wan" "6@eth1" "4:lan"
+diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+index c917f38211d0b246f064dba4b7feefecf61f5856..39205de2ec2ecd4d67a560dccfad36aab7a0aa0b 100644
+--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
++++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+@@ -100,7 +100,8 @@ case "$FIRMWARE" in
+ 		ath10kcal_extract "art" 20480 2116
+ 		ath10kcal_patch_mac $(mtd_get_mac_ascii devdata "wlan5mac")
+ 		;;
+-	elecom,wrc-1750ghbk2-i)
++	elecom,wrc-1750ghbk2-i|\
++	joyit,jt-or750i)
+ 		ath10kcal_extract "art" 20480 2116
+ 		;;
+ 	engenius,ecb1750)
+diff --git a/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+new file mode 100644
+index 0000000000000000000000000000000000000000..8a4d4c682380b26aa2437b26391273ddc7bf2d75
+--- /dev/null
++++ b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+@@ -0,0 +1,120 @@
++// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
++/dts-v1/;
++
++#include "qca953x.dtsi"
++
++#include <dt-bindings/gpio/gpio.h>
++#include <dt-bindings/input/input.h>
++
++/ {
++	compatible = "joyit,jt-or750i", "qca,qca9531";
++	model = "Joy-IT JT-OR750i";
++
++	aliases {
++		led-boot = &led_status_green;
++		led-failsafe = &led_status_red;
++		led-running = &led_status_green;
++		led-upgrade = &led_status_red;
++		label-mac-device = &eth0;
++	};
++
++	keys {
++		compatible = "gpio-keys";
++
++		reset {
++			label = "reset";
++			linux,code = <KEY_RESTART>;
++			gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
++		};
++	};
++
++	leds {
++		compatible = "gpio-leds";
++
++		led_status_green: status_green {
++			label = "green:status";
++			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
++			default-state = "on";
++		};
++
++		led_status_red: status_red {
++			label = "red:status";
++			gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
++		};
++	};
++};
++
++&pinmux {
++	pinmux_led_eth_pins: pinmux_led_eth_pins {
++		pinctrl-single,bits = \
++			/* GPIO 4: LED_LINK_5 (WAN) */     \
++			<0x04 0x0000002d 0x000000ff>,      \
++			/* GPIO 14: LED_LINK_2 (LAN 3) */  \
++			/* GPIO 15: LED_LINK_3 (LAN 2) */  \
++			<0x0c 0x2b2c0000 0xffff0000>,      \
++			/* GPIO 16: LED_LINK_4 (LAN 1) */  \
++			<0x10 0x0000002a 0x000000ff>;
++	};
++};
++
++&spi {
++	status = "okay";
++
++	flash@0 {
++		compatible = "jedec,spi-nor";
++		reg = <0>;
++		spi-max-frequency = <50000000>;
++
++		partitions {
++			compatible = "fixed-partitions";
++			#address-cells = <1>;
++			#size-cells = <1>;
++
++			partition@0 {
++				label = "u-boot";
++				reg = <0x0 0x40000>;
++				read-only;
++			};
++
++			partition@40000 {
++				label = "u-boot-env";
++				reg = <0x40000 0x10000>;
++				read-only;
++			};
++
++			partition@50000 {
++				label = "firmware";
++				reg = <0x50000 0xfa0000>;
++				compatible = "denx,uimage";
++			};
++
++			art: partition@ff0000 {
++				label = "art";
++				reg = <0xff0000 0x10000>;
++				read-only;
++			};
++		};
++	};
++};
++
++&eth0 {
++	status = "okay";
++
++	phy-handle = <&swphy4>;
++
++	mtd-mac-address = <&art 0x0>;
++};
++
++&eth1 {
++	mtd-mac-address = <&art 0x6>;
++};
++
++&pcie0 {
++	status = "okay";
++};
++
++&wmac {
++	status = "okay";
++
++	mtd-cal-data = <&art 0x1000>;
++};
+diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk
+index 7159f9c6d2dabf0a80b4a107790471da32af97bc..080be91fe1351b45a68057de71e5cd1464773f11 100644
+--- a/target/linux/ath79/image/generic.mk
++++ b/target/linux/ath79/image/generic.mk
+@@ -484,6 +484,14 @@ define Device/jjplus_ja76pf2
+ endef
+ TARGET_DEVICES += jjplus_ja76pf2
+ 
++define Device/joyit_jt-or750i
++  ATH_SOC := qca9531
++  DEVICE_TITLE := Joy-IT JT-OR750i
++  DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca9887-ct
++  IMAGE_SIZE := 16000k
++endef
++TARGET_DEVICES += joyit_jt-or750i
++
+ define Device/librerouter_librerouter-v1
+   ATH_SOC := qca9558
+   DEVICE_TITLE := LibreRouter v1
diff --git a/patches/openwrt/0024-ath79-enable-missing-pinmux-for-JT-OR750i.patch b/patches/openwrt/0024-ath79-enable-missing-pinmux-for-JT-OR750i.patch
new file mode 100644
index 000000000..c27f43431
--- /dev/null
+++ b/patches/openwrt/0024-ath79-enable-missing-pinmux-for-JT-OR750i.patch
@@ -0,0 +1,24 @@
+From: David Bauer <mail@david-bauer.net>
+Date: Wed, 28 Jul 2021 13:52:22 +0200
+Subject: ath79: enable missing pinmux for JT-OR750i
+
+Without explicit configuration of these pins the ethernet as well as
+status LED of the device do not work correctly.
+
+Signed-off-by: David Bauer <mail@david-bauer.net>
+(cherry picked from commit 4feb9a4211d4c8e118e6b8f01fa0bbd4eab5d35c)
+
+diff --git a/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+index 8a4d4c682380b26aa2437b26391273ddc7bf2d75..d87daddd771325a8788b59edf2159c3be7bedf07 100644
+--- a/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
++++ b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+@@ -31,6 +31,9 @@
+ 	leds {
+ 		compatible = "gpio-leds";
+ 
++		pinctrl-names = "default";
++		pinctrl-0 = <&jtag_disable_pins &pinmux_led_eth_pins>;
++
+ 		led_status_green: status_green {
+ 			label = "green:status";
+ 			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
diff --git a/patches/openwrt/0025-ath79-fix-JT-OR750i-switch-LED-assignment.patch b/patches/openwrt/0025-ath79-fix-JT-OR750i-switch-LED-assignment.patch
new file mode 100644
index 000000000..f437f4958
--- /dev/null
+++ b/patches/openwrt/0025-ath79-fix-JT-OR750i-switch-LED-assignment.patch
@@ -0,0 +1,26 @@
+From: David Bauer <mail@david-bauer.net>
+Date: Wed, 28 Jul 2021 14:17:13 +0200
+Subject: ath79: fix JT-OR750i switch LED assignment
+
+The LEDs for LAN1 and LAN3 were swapped. Link on port 1 would illuminate
+the LED on port 3 and vice versa.
+
+Signed-off-by: David Bauer <mail@david-bauer.net>
+(cherry picked from commit f0a885ed8636b9762d12f2eb2755f63297ff0cb5)
+
+diff --git a/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+index d87daddd771325a8788b59edf2159c3be7bedf07..60fa922878355ebdaf7d2983fe926efdf8b97207 100644
+--- a/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
++++ b/target/linux/ath79/dts/qca9531_joyit_jt-or750i.dts
+@@ -54,9 +54,9 @@
+ 			<0x04 0x0000002d 0x000000ff>,      \
+ 			/* GPIO 14: LED_LINK_2 (LAN 3) */  \
+ 			/* GPIO 15: LED_LINK_3 (LAN 2) */  \
+-			<0x0c 0x2b2c0000 0xffff0000>,      \
++			<0x0c 0x2b2a0000 0xffff0000>,      \
+ 			/* GPIO 16: LED_LINK_4 (LAN 1) */  \
+-			<0x10 0x0000002a 0x000000ff>;
++			<0x10 0x0000002c 0x000000ff>;
+ 	};
+ };
+ 
diff --git a/targets/ath79-generic b/targets/ath79-generic
index 5537a7ea3..5cf3e20ed 100644
--- a/targets/ath79-generic
+++ b/targets/ath79-generic
@@ -65,6 +65,15 @@ device('gl.inet-gl-ar750s-nor', 'glinet_gl-ar750s', {
 	packages = ATH10K_PACKAGES_QCA9887,
 })
 
+
+-- JOY-IT
+
+device('joy-it-jt-or750i', 'joyit_jt-or750i', {
+	packages = ATH10K_PACKAGES_QCA9887,
+	factory = false,
+})
+
+
 -- OCEDO
 
 device('ocedo-raccoon', 'ocedo_raccoon', {
-- 
GitLab