From a4e37cd5277a885c5d9bfd578088395510ceb4de Mon Sep 17 00:00:00 2001
From: Felix Kaechele <felix@fetzig.org>
Date: Wed, 3 Apr 2013 22:39:37 +0200
Subject: [PATCH] Add support for Poray M3

---
 target/linux/ramips/base-files/etc/diag.sh         |  3 +
 .../etc/hotplug.d/firmware/10-rt2x00-eeprom        |  1 +
 .../ramips/base-files/etc/uci-defaults/02_network  |  9 +++
 .../ramips/base-files/lib/preinit/06_set_iface_mac |  5 ++
 target/linux/ramips/base-files/lib/ramips.sh       |  3 +
 .../ramips/base-files/lib/upgrade/platform.sh      |  1 +
 target/linux/ramips/dts/M3.dts                     | 88 ++++++++++++++++++++++
 target/linux/ramips/image/Makefile                 |  3 +
 8 files changed, 113 insertions(+)
 create mode 100644 target/linux/ramips/dts/M3.dts

diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
index 866003c..c699695 100755
--- a/target/linux/ramips/base-files/etc/diag.sh
+++ b/target/linux/ramips/base-files/etc/diag.sh
@@ -49,6 +49,9 @@ get_status_led() {
 	hw550-3g)
 		status_led="hw550-3g:green:status"
 		;;
+	m3)
+		status_led="m3:blue:status"
+		;;
 	mofi3500-3gn)
 		status_led="mofi3500-3gn:green:status"
 		;;
diff --git a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
index b6490b5..8dd8121 100644
--- a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
+++ b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
@@ -72,6 +72,7 @@ case "$FIRMWARE" in
 	rt-n13u | \
 	freestation5 | \
 	hw550-3g | \
+	m3 | \
 	mofi3500-3gn | \
 	pwh2004 | \
 	nbg-419n | \
diff --git a/target/linux/ramips/base-files/etc/uci-defaults/02_network b/target/linux/ramips/base-files/etc/uci-defaults/02_network
index 98aefbd..4b6978b 100755
--- a/target/linux/ramips/base-files/etc/uci-defaults/02_network
+++ b/target/linux/ramips/base-files/etc/uci-defaults/02_network
@@ -131,6 +131,10 @@ ramips_setup_interfaces()
 	wli-tx4-ag300n)
 		ucidef_set_interface_lan "eth0"
 		;;
+	m3)
+		swconfig dev rt305x set reset 1
+		ucidef_set_interface_lan "eth0"
+		;;
 
 	*)
 		RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
@@ -210,6 +214,11 @@ ramips_setup_macs()
 		wan_mac=$(macaddr_add "$lan_mac" 1)
 		;;
 
+	m3)
+		lan_mac=$(mtd_get_mac_binary factory 4)
+		lan_mac=$(macaddr_add "$lan_mac" -1)
+		;;
+
 	nbg-419n | \
 	wcr-150gn)
                 lan_mac=$(mtd_get_mac_binary factory 4)
diff --git a/target/linux/ramips/base-files/lib/preinit/06_set_iface_mac b/target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
index 7824e2b..3c4951e 100644
--- a/target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
+++ b/target/linux/ramips/base-files/lib/preinit/06_set_iface_mac
@@ -68,6 +68,11 @@ preinit_set_mac_address() {
 		mac=$(mtd_get_mac_binary factory 40)
 		ifconfig eth0 hw ether $mac 2>/dev/null
 		;;
+	m3)
+		mac=$(mtd_get_mac_binary factory 4)
+		mac=$(macaddr_add "$mac" -1)
+		ifconfig eth0 hw ether $mac 2>/dev/null
+		;;
 	wl341v3)
 		mac=$(mtd_get_mac_binary board-nvram 65440)
 		ifconfig eth0 hw ether $mac 2>/dev/null
diff --git a/target/linux/ramips/base-files/lib/ramips.sh b/target/linux/ramips/base-files/lib/ramips.sh
index c89dd46..ba409e9 100755
--- a/target/linux/ramips/base-files/lib/ramips.sh
+++ b/target/linux/ramips/base-files/lib/ramips.sh
@@ -138,6 +138,9 @@ ramips_board_detect() {
 	*"Planex MZK-W300NH2"*)
 		name="mzk-w300nh2"
 		;;
+	*"Poray M3")
+		name="m3"
+		;;
 	*"PWH2004")
 		name="pwh2004"
 		;;
diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
index 34d2c54..4833c5f 100755
--- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
@@ -38,6 +38,7 @@ platform_check_image() {
 	rt-n13u | \
 	freestation5 | \
 	hw550-3g | \
+	m3 | \
 	mofi3500-3gn | \
 	mzk-w300nh2 | \
 	nbg-419n | \
diff --git a/target/linux/ramips/dts/M3.dts b/target/linux/ramips/dts/M3.dts
new file mode 100644
index 0000000..2cb6a5c
--- /dev/null
+++ b/target/linux/ramips/dts/M3.dts
@@ -0,0 +1,88 @@
+/dts-v1/;
+
+/include/ "rt5350.dtsi"
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "M3", "ralink,rt5350-soc";
+	model = "Poray M3";
+
+	memorydetect {
+		ralink,memory = <0x0 0x200000 0x4000000>;
+	};
+
+	chosen {
+		bootargs = "console=ttyS0,57600 mtdparts=spi0.0:192k(u-boot)ro,64k(u-boot-env)ro,64k(factory)ro,3872k@0x50000(firmware)";
+	};
+
+	palmbus@10000000 {
+		sysc@0 {
+			ralink,pinmmux = "i2c", "spi", "uartlite", "jtag", "mdio", "sdram", "rgmii";
+			ralink,uartmux = "gpio";
+			ralink,wdtmux = <1>;
+		};
+
+		gpio0: gpio@600 {
+			status = "okay";
+		};
+
+		spi@b00 {
+			status = "okay";
+			m25p80@0 {
+				#address-cells = <1>;
+				#size-cells = <1>;
+				compatible = "w25q32";
+				reg = <0 0>;
+				linux,modalias = "m25p80", "w25q32";
+				spi-max-frequency = <10000000>;
+			};
+		};
+	};
+
+	ethernet@10100000 {
+		status = "okay";
+	};
+
+	esw@10110000 {
+		status = "okay";
+		ralink,portmap = <0x2f>;
+	};
+
+	gpio-leds {
+		compatible = "gpio-leds";
+		status {
+			label = "m3:blue:status";
+			gpios = <&gpio0 9 1>;
+		};
+	};
+
+	gpio-keys-polled {
+		compatible = "gpio-keys-polled";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		poll-interval = <20>;
+		reset {
+			label = "reset";
+			gpios = <&gpio0 10 1>;
+			linux,code = <0x198>;
+		};
+		mode {
+			label = "mode";
+			gpios = <&gpio0 17 1>;
+			linux,code = <0x100>;
+		};
+	};
+
+	wmac@10180000 {
+		status = "okay";
+	};
+
+	ehci@101c0000 {
+		status = "okay";
+	};
+	
+	ohci@101c1000 {
+		status = "okay";
+	};
+};
diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
index 0002eb4..c44a150 100644
--- a/target/linux/ramips/image/Makefile
+++ b/target/linux/ramips/image/Makefile
@@ -317,6 +317,8 @@ Image/Build/Profile/RT-N13U=$(call BuildFirmware/Default8M/$(1),$(1),rt-n13u,RT-
 
 Image/Build/Profile/FREESTATION5=$(call BuildFirmware/Default8M/$(1),$(1),freestation5,FREESTATION5)
 
+Image/Build/Profile/M3=$(call BuildFirmware/Default4M/$(1),$(1),m3,M3)
+
 Image/Build/Profile/MOFI3500-3GN=$(call BuildFirmware/Default8M/$(1),$(1),mofi3500-3gn,MOFI3500-3GN)
 
 Image/Build/Profile/NBG-419N=$(call BuildFirmware/Default4M/$(1),$(1),nbg-419n,NBG-419N)
@@ -429,6 +431,7 @@ define Image/Build/Profile/Default
 	$(call Image/Build/Profile/FONERA20N,$(1))
 	$(call Image/Build/Profile/FREESTATION5,$(1))
 	$(call Image/Build/Profile/HW550-3G,$(1))
+	$(call Image/Build/Profile/M3,$(1))
 	$(call Image/Build/Profile/MOFI3500-3GN,$(1))
 	$(call Image/Build/Profile/MZKW300NH2,$(1))
 	$(call Image/Build/Profile/NBG-419N,$(1))
-- 
1.8.1.4

