From cf250183c796a2af336ae88909f96ffb6b5703bf Mon Sep 17 00:00:00 2001
From: Felix Kaechele <felix@fetzig.org>
Date: Mon, 15 Apr 2013 23:23:37 +0200
Subject: [PATCH 1/5] [ramips] add Poray M3 support

---
 target/linux/ramips/base-files/etc/diag.sh         |   3 +
 .../ramips/base-files/etc/uci-defaults/02_network  |   5 +
 .../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                     | 103 +++++++++++++++++++++
 target/linux/ramips/image/Makefile                 |   3 +
 target/linux/ramips/rt305x/profiles/poray.mk       |  19 ++++
 8 files changed, 142 insertions(+)
 create mode 100644 target/linux/ramips/dts/M3.dts
 create mode 100644 target/linux/ramips/rt305x/profiles/poray.mk

diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
index fe925c0..a78ba51 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/uci-defaults/02_network b/target/linux/ramips/base-files/etc/uci-defaults/02_network
index e28f2b5..3d58ee1 100755
--- a/target/linux/ramips/base-files/etc/uci-defaults/02_network
+++ b/target/linux/ramips/base-files/etc/uci-defaults/02_network
@@ -211,6 +211,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 52bf115..ca3eed7 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
@@ -69,6 +69,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 37b477a..064aed7 100755
--- a/target/linux/ramips/base-files/lib/ramips.sh
+++ b/target/linux/ramips/base-files/lib/ramips.sh
@@ -141,6 +141,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 ef15044..802f213 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..ed70e61
--- /dev/null
+++ b/target/linux/ramips/dts/M3.dts
@@ -0,0 +1,103 @@
+/dts-v1/;
+
+/include/ "rt5350.dtsi"
+
+/ {
+	compatible = "M3", "ralink,rt5350-soc";
+	model = "Poray M3";
+
+	palmbus@10000000 {
+		sysc@0 {
+			ralink,pinmux = "i2c", "spi", "uartlite", "mdio", "sdram", "rgmii";
+			ralink,gpiomux = "jtag";
+			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>;
+
+		partition@0 {
+			label = "u-boot";
+			reg = <0x0 0x30000>;
+			read-only;
+		};
+
+		partition@30000 {
+			label = "u-boot-env";
+			reg = <0x30000 0x10000>;
+			read-only;
+		};
+
+		factory: partition@40000 {
+			label = "factory";
+			reg = <0x40000 0x10000>;
+			read-only;
+		};
+
+		partition@50000 {
+			label = "firmware";
+			reg = <0x50000 0x3b0000>;
+		};
+			};
+		};
+	};
+
+	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";
+		ralink,mtd-eeprom = <&factory 0>;
+	};
+	
+	ehci@101c0000 {
+		status = "okay";
+	};
+
+	ohci@101c1000 {
+		status = "okay";
+	};
+};
diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
index 7a9c6ae..26227f3 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)
@@ -441,6 +443,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))
diff --git a/target/linux/ramips/rt305x/profiles/poray.mk b/target/linux/ramips/rt305x/profiles/poray.mk
new file mode 100644
index 0000000..9d787e3
--- /dev/null
+++ b/target/linux/ramips/rt305x/profiles/poray.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2013 Felix Kaechele <felix@fetzig.org>
+#                    Luis Soltero <lsoltero@globalmarinenet.com>
+#                    Michel Stempin <michel.stempin@wanadoo.fr>
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+define Profile/M3
+	NAME:=Poray M3
+	PACKAGES:=kmod-usb-core kmod-usb2 kmod-ledtrig-netdev kmod-ledtrig-timer
+endef
+
+define Profile/M3/Description
+	Package set for Poray M3 board
+endef
+
+$(eval $(call Profile,M3))
-- 
1.8.2.1

