From 6fdaf16dd0623db1a324d33fdf0bc1654365ee62 Mon Sep 17 00:00:00 2001
From: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Date: Tue, 18 Feb 2020 00:08:18 +0100
Subject: [PATCH] ath79: add support for Ubiquiti Picostation M (XM)

This adds support for the Ubiquiti Picostation M (XM), which has the
same board/LEDs as the Bullet M XM, but different case and antennas.

Specifications:
- AR7241 SoC @ 400 MHz
- 32 MB RAM
- 8 MB SPI flash
- 1x 10/100 Mbps Ethernet, 24 Vdc PoE-in
- External antenna: 5 dBi (USA), 2 dBi (EU)
- POWER/LAN green LEDs
- 4x RSSI LEDs (red, orange, green, green)
- UART (115200 8N1) on PCB

Flashing via WebUI:
  Upload the factory image via the stock firmware web UI.

  Attention: airOS firmware versions >= 5.6 have a new bootloader with
  an incompatible partition table!

  Please downgrade to <= 5.5 _before_ flashing OpenWrt!
  Refer to the device's Wiki page for further information.

Flashing via TFTP:
  Same procedure as other NanoStation M boards.

- Use a pointy tool (e.g., pen cap, paper clip) and keep the reset
  button on the device or on the PoE supply pressed
- Power on the device via PoE (keep reset button pressed)
- Keep pressing until LEDs flash alternatively LED1+LED3 =>
  LED2+LED4 => LED1+LED3, etc.
- Release reset button
- The device starts a TFTP server at 192.168.1.20
- Set a static IP on the computer (e.g., 192.168.1.21/24)
- Upload via tftp the factory image:
  $ tftp 192.168.1.20
  tftp> bin
  tftp> trace
  tftp> put openwrt-ath79-generic-xxxxx-ubnt_picostation-m-squashfs-factory.bin

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 .../linux/ath79/dts/ar7241_ubnt_picostation-m.dts   | 13 +++++++++++++
 .../ath79/generic/base-files/etc/board.d/01_leds    |  1 +
 .../ath79/generic/base-files/etc/board.d/02_network |  1 +
 .../etc/hotplug.d/firmware/10-ath9k-eeprom          |  1 +
 target/linux/ath79/image/generic-ubnt.mk            |  8 ++++++++
 5 files changed, 24 insertions(+)
 create mode 100644 target/linux/ath79/dts/ar7241_ubnt_picostation-m.dts

diff --git a/target/linux/ath79/dts/ar7241_ubnt_picostation-m.dts b/target/linux/ath79/dts/ar7241_ubnt_picostation-m.dts
new file mode 100644
index 00000000000..e2376a1b925
--- /dev/null
+++ b/target/linux/ath79/dts/ar7241_ubnt_picostation-m.dts
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/dts-v1/;
+
+#include "ar7241_ubnt_xm_outdoor.dtsi"
+
+/ {
+	compatible = "ubnt,picostation-m", "ubnt,xm", "qca,ar7241";
+	model = "Ubiquiti Picostation M";
+};
+
+&eth1 {
+	compatible = "syscon", "simple-mfd";
+};
diff --git a/target/linux/ath79/generic/base-files/etc/board.d/01_leds b/target/linux/ath79/generic/base-files/etc/board.d/01_leds
index 3567df662b9..6668e15a74d 100755
--- a/target/linux/ath79/generic/base-files/etc/board.d/01_leds
+++ b/target/linux/ath79/generic/base-files/etc/board.d/01_leds
@@ -248,6 +248,7 @@ ubnt,nanostation-loco-m|\
 ubnt,nanostation-loco-m-xw|\
 ubnt,nanostation-m|\
 ubnt,nanostation-m-xw|\
+ubnt,picostation-m|\
 ubnt,rocket-m)
 	ucidef_set_rssimon "wlan0" "200000" "1"
 	ucidef_set_led_rssi "rssilow" "RSSILOW" "ubnt:red:link1" "wlan0" "1" "100"
diff --git a/target/linux/ath79/generic/base-files/etc/board.d/02_network b/target/linux/ath79/generic/base-files/etc/board.d/02_network
index 993632562f8..4891affe177 100755
--- a/target/linux/ath79/generic/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network
@@ -49,6 +49,7 @@ ath79_setup_interfaces()
 	ubnt,nanostation-ac-loco|\
 	ubnt,nanostation-loco-m|\
 	ubnt,nanostation-loco-m-xw|\
+	ubnt,picostation-m|\
 	ubnt,rocket-m|\
 	ubnt,unifiac-lite|\
 	ubnt,unifiac-lr|\
diff --git a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index ea42478c610..96f9d5c0d2a 100644
--- a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -92,6 +92,7 @@ case "$FIRMWARE" in
 	ubnt,bullet-m|\
 	ubnt,nanostation-loco-m|\
 	ubnt,nanostation-m|\
+	ubnt,picostation-m|\
 	ubnt,rocket-m)
 		caldata_extract "art" 0x1000 0x1000
 		;;
diff --git a/target/linux/ath79/image/generic-ubnt.mk b/target/linux/ath79/image/generic-ubnt.mk
index c0b61212380..a4aff09feca 100644
--- a/target/linux/ath79/image/generic-ubnt.mk
+++ b/target/linux/ath79/image/generic-ubnt.mk
@@ -211,6 +211,14 @@ define Device/ubnt_nanostation-m-xw
 endef
 TARGET_DEVICES += ubnt_nanostation-m-xw
 
+define Device/ubnt_picostation-m
+  $(Device/ubnt-xm)
+  DEVICE_MODEL := Picostation M
+  DEVICE_PACKAGES += rssileds
+  SUPPORTED_DEVICES += bullet-m
+endef
+TARGET_DEVICES += ubnt_picostation-m
+
 define Device/ubnt_rocket-m
   $(Device/ubnt-xm)
   DEVICE_MODEL := Rocket-M
-- 
GitLab