From 146eb4925c7f32650f38cb52139696a827051700 Mon Sep 17 00:00:00 2001
From: Robert Marko <robert@meshpoint.me>
Date: Mon, 25 Nov 2019 15:25:00 +0100
Subject: [PATCH] ipq40xx: add support for Crisis Innovation Lab MeshPoint.One
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

MeshPoint.One is Wi-Fi hotspot and smart IoT gateway (based upon
Jalapeno module from 8Devices).

MeshPoint.One (https://meshpointone.com) is a unique Wi-Fi hotspot and
smart city gateway that can be installed and powered from street
lighting (even solar power in the future).  MeshPoint provides up to 27
hours of interrupted Wi-Fi and IoT services from internal battery even
when external power is not available.  MeshPoint.One can be used for
disaster relief efforts in order to provide instant Wi-Fi coverage that
can be easily expanded by just adding more devices that create wide area
mesh network.  MeshPoint.One devices have standard Luci UI for
management.

Features:
- 1x 1Gpbs WAN
- 1x 1Gbps LAN
- POE input (eth0)
- POE output (eth1)
- Sensor for temperature, humidity and pressure (Bosch BME280)
- current, voltage and power measurement via TI INA230
- Hardware real time clock
- optional power via Li-Ion battery
- micro USB port with USB to serial chip for easy OpenWrt terminal
  access
- I2C header for connecting additional sensors

Installation:
-------------
Simply flash the sysupgrade image from stock firmware.

Or use the built in Web recovery into bootloader:
Hold Reset button for 5 to 20 seconds or use UART and httpd command.
Web UI will appear on 192.168.2.100 by default.
For web recovery use the factory.ubi image.

Signed-off-by: Damir Samardzic <damir.samardzic@sartura.hr>
Signed-off-by: Damir Franusic <damir.franusic@sartura.hr>
Signed-off-by: Valent Turkovic <valent@meshpoint.me>
Signed-off-by: Robert Marko <robert@meshpoint.me>
[commit description long line wrap, usb->USB]
Signed-off-by: Petr Å tetiar <ynezz@true.cz>
---
 .../ipq40xx/base-files/etc/board.d/02_network |  5 ++
 .../base-files/etc/board.d/03_gpio_switches   |  3 +
 .../etc/hotplug.d/firmware/11-ath10k-caldata  |  2 +
 .../base-files/lib/upgrade/platform.sh        |  1 +
 .../boot/dts/qcom-ipq4018-meshpoint-one.dts   | 81 +++++++++++++++++++
 target/linux/ipq40xx/image/Makefile           | 19 ++++-
 .../901-arm-boot-add-dts-files.patch          |  3 +-
 7 files changed, 110 insertions(+), 4 deletions(-)
 create mode 100644 target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-meshpoint-one.dts

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 dafd83234ee9..122c1a103d90 100755
--- a/target/linux/ipq40xx/base-files/etc/board.d/02_network
+++ b/target/linux/ipq40xx/base-files/etc/board.d/02_network
@@ -18,6 +18,7 @@ ipq40xx_setup_interfaces()
 		ucidef_set_interfaces_lan_wan "eth0" "eth1"
 		;;
 	asus,map-ac2200|\
+	cilab,meshpoint-one|\
 	openmesh,a42|\
 	openmesh,a62)
 		ucidef_set_interfaces_lan_wan "eth1" "eth0"
@@ -84,6 +85,9 @@ ipq40xx_setup_macs()
 		wan_mac=$(mtd_get_mac_binary_ubi Factory 0x5006)
 		lan_mac=$(mtd_get_mac_binary_ubi Factory 0x1006)
 		;;
+	cilab,meshpoint-one)
+		label_mac=$(mtd_get_mac_binary "ART" 0x1006)
+		;;
 	engenius,ens620ext)
 		wan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
 		lan_mac=$(macaddr_add "$wan_mac" 1)
@@ -96,6 +100,7 @@ ipq40xx_setup_macs()
 
 	[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
 	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
+	[ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
 }
 
 board_config_update
diff --git a/target/linux/ipq40xx/base-files/etc/board.d/03_gpio_switches b/target/linux/ipq40xx/base-files/etc/board.d/03_gpio_switches
index 4e306a94a5c0..e46a297ea7aa 100755
--- a/target/linux/ipq40xx/base-files/etc/board.d/03_gpio_switches
+++ b/target/linux/ipq40xx/base-files/etc/board.d/03_gpio_switches
@@ -7,6 +7,9 @@ board_config_update
 board=$(board_name)
 
 case "$board" in
+cilab,meshpoint-one)
+	ucidef_add_gpio_switch "poe_passtrough" "POE passtrough enable" "413" "1"
+	;;
 compex,wpj428)
 	ucidef_add_gpio_switch "sim_card_select" "SIM card select" "3" "0"
 	;;
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 d4e4cc49ec8b..3d465194154a 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
@@ -45,6 +45,7 @@ case "$FIRMWARE" in
 	case "$board" in
 	8dev,jalapeno |\
 	alfa-network,ap120c-ac |\
+	cilab,meshpoint-one |\
 	glinet,gl-b1300 |\
 	linksys,ea6350v3 |\
 	qcom,ap-dk01.1-c1)
@@ -109,6 +110,7 @@ case "$FIRMWARE" in
 	case "$board" in
 	8dev,jalapeno |\
 	alfa-network,ap120c-ac |\
+	cilab,meshpoint-one |\
 	glinet,gl-b1300 |\
 	linksys,ea6350v3 |\
 	qcom,ap-dk01.1-c1)
diff --git a/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh b/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
index 96f865c67e32..41f8fcfccbfb 100644
--- a/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
@@ -50,6 +50,7 @@ platform_do_upgrade() {
 	avm,fritzbox-7530 |\
 	avm,fritzrepeater-1200 |\
 	avm,fritzrepeater-3000 |\
+	cilab,meshpoint-one |\
 	qxwlan,e2600ac-c2)
 		nand_do_upgrade "$1"
 		;;
diff --git a/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-meshpoint-one.dts b/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-meshpoint-one.dts
new file mode 100644
index 000000000000..2e21b553254d
--- /dev/null
+++ b/target/linux/ipq40xx/files-4.19/arch/arm/boot/dts/qcom-ipq4018-meshpoint-one.dts
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/* Copyright (c) 2019, CRISIS INNOVATION LAB d.o.o.
+ * Author: Robert Marko <robert@meshpoint.me>
+ */
+
+#include "qcom-ipq4018-jalapeno.dtsi"
+
+/ {
+	model = "Crisis Innovation Lab MeshPoint.One";
+	compatible = "cilab,meshpoint-one";
+
+	aliases {
+		led-boot = &led_status;
+		led-failsafe = &led_status;
+		led-running = &led_status;
+		led-upgrade = &led_status;
+	};
+
+	soc {
+		i2c-gpio {
+			status = "okay";
+
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			compatible = "i2c-gpio";
+			gpios = <&tlmm 0 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) /* sda */
+					 &tlmm 4 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) /* scl */
+					>;
+
+			bme280@76 {
+				status = "okay";
+
+				compatible = "bosch,bme280";
+				reg = <0x76>;
+			};
+
+			pcf2129@51 {
+				status = "okay";
+
+				compatible = "nxp,pcf2129";
+				reg = <0x51>;
+			};
+
+			ina230@40 {
+				status = "okay";
+
+				compatible = "ti,ina230";
+				reg = <0x40>;
+				shunt-resistor = <2000>;
+			};
+
+			ina230@44 {
+				status = "okay";
+
+				compatible = "ti,ina230";
+				reg = <0x44>;
+				shunt-resistor = <2000>;
+			};
+		};
+	};
+
+	keys {
+		compatible = "gpio-keys";
+
+		reset {
+			label = "reset";
+			gpios = <&tlmm 5 GPIO_ACTIVE_LOW>;
+			linux,code = <KEY_RESTART >;
+		};
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		led_status: status {
+			label = "meshpoint-one:blue:status";
+			gpios = <&tlmm 63 GPIO_ACTIVE_HIGH>;
+		};
+	};
+};
diff --git a/target/linux/ipq40xx/image/Makefile b/target/linux/ipq40xx/image/Makefile
index a9c5e625af48..ac344474756e 100644
--- a/target/linux/ipq40xx/image/Makefile
+++ b/target/linux/ipq40xx/image/Makefile
@@ -60,14 +60,18 @@ define Build/SenaoFW
 	@cp $@.new $@
 endef
 
-define Device/8dev_jalapeno
+define Device/8dev_jalapeno-common
 	$(call Device/FitImage)
 	$(call Device/UbiFit)
+	BLOCKSIZE := 128k
+	PAGESIZE := 2048
+endef
+
+define Device/8dev_jalapeno
+	$(call Device/8dev_jalapeno-common)
 	DEVICE_VENDOR := 8devices
 	DEVICE_MODEL := Jalapeno
 	DEVICE_DTS := qcom-ipq4018-jalapeno
-	BLOCKSIZE := 128k
-	PAGESIZE := 2048
 endef
 TARGET_DEVICES += 8dev_jalapeno
 
@@ -164,6 +168,15 @@ define Device/avm_fritzrepeater-3000
 endef
 TARGET_DEVICES += avm_fritzrepeater-3000
 
+define Device/cilab_meshpoint-one
+	$(call Device/8dev_jalapeno-common)
+	DEVICE_DTS := qcom-ipq4018-meshpoint-one
+	DEVICE_VENDOR := Crisis Innovation Lab
+	DEVICE_MODEL := MeshPoint.One
+	DEVICE_PACKAGES := kmod-i2c-gpio kmod-iio-bmp280-i2c kmod-hwmon-ina2xx kmod-rtc-pcf2127
+endef
+TARGET_DEVICES += cilab_meshpoint-one
+
 define Device/compex_wpj419
 	$(call Device/FitImage)
 	$(call Device/UbiFit)
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 4649b337e33b..93214e60e99d 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,7 +10,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
 
 --- a/arch/arm/boot/dts/Makefile
 +++ b/arch/arm/boot/dts/Makefile
-@@ -785,11 +785,36 @@ dtb-$(CONFIG_ARCH_QCOM) += \
+@@ -785,11 +785,37 @@ dtb-$(CONFIG_ARCH_QCOM) += \
  	qcom-apq8074-dragonboard.dtb \
  	qcom-apq8084-ifc6540.dtb \
  	qcom-apq8084-mtp.dtb \
@@ -23,6 +23,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
 +	qcom-ipq4018-ex6150v2.dtb \
 +	qcom-ipq4018-fritz4040.dtb \
 +	qcom-ipq4018-jalapeno.dtb \
++	qcom-ipq4018-meshpoint-one.dtb \
 +	qcom-ipq4018-nbg6617.dtb \
 +	qcom-ipq4018-rt-ac58u.dtb \
 +	qcom-ipq4018-wre6606.dtb \
-- 
2.30.2