From ca27b3d370353ff57719718a1964c6b4f10b11a4 Mon Sep 17 00:00:00 2001
From: Makoto Takeuchi <mak0@lxsys.co.uk>
Date: Wed, 24 May 2017 16:37:24 +0100
Subject: [PATCH] kirkwood: add support for Cisco ON100

The Cisco ON100 device is a Kirkwood based router:

    SoC: Marvell 88F6282 1600Mhz
    SDRAM memory: 512MB DDR3 1333Mhz
    Gigabit ethernet: 2x Marvell 88E1310 (over RGMII)
    Flash memory: 512MB
    2 bi-colour status LEDs (green/red)
    1 Reset button
    1 USB 2.0 port (on back)
    1 SDIO slot (on back)

This commit adds a target profile of "Cisco Systems ON100" under the target
system "Marvell Kirkwood".

Flashing can be performed over tftp, once "dhcp" has been issued:
 tftpboot ${loadaddr} lede-kirkwood-on100-squashfs-factory.bin
 nand erase 0x0c0000 ${filesize}
 nand write ${loadaddr} 0x0c0000 ${filesize}

Once flashed, set environment variables to boot:
 setenv bootcmd nand read \${loadaddr} 0x0c0000 0x540000\; setenv bootargs
  \; bootm
 saveenv

Signed-off-by: Makoto Takeuchi <mak0@lxsys.co.uk>
---
 .../base-files/etc/board.d/02_network         |   3 +
 target/linux/kirkwood/base-files/etc/diag.sh  |   3 +
 .../linux/kirkwood/base-files/lib/kirkwood.sh |   4 +
 target/linux/kirkwood/image/Makefile          |  13 +-
 .../kirkwood/patches-4.4/195-on100.patch      | 173 ++++++++++++++++++
 5 files changed, 195 insertions(+), 1 deletion(-)
 create mode 100644 target/linux/kirkwood/patches-4.4/195-on100.patch

diff --git a/target/linux/kirkwood/base-files/etc/board.d/02_network b/target/linux/kirkwood/base-files/etc/board.d/02_network
index 35d735f9db..19f0292b29 100755
--- a/target/linux/kirkwood/base-files/etc/board.d/02_network
+++ b/target/linux/kirkwood/base-files/etc/board.d/02_network
@@ -35,6 +35,9 @@ case "$board" in
 	ucidef_set_interface_lan "eth0" "dhcp"
 	ucidef_set_interface_macaddr "lan" $( mtd_get_mac_ascii uboot_env ethaddr )
 	;;
+"on100")
+	ucidef_set_interface_lan "eth0 eth1"
+	;;
 *)
 	ucidef_set_interface_lan "eth0"
 	;;
diff --git a/target/linux/kirkwood/base-files/etc/diag.sh b/target/linux/kirkwood/base-files/etc/diag.sh
index 1c4632d613..64650850d6 100755
--- a/target/linux/kirkwood/base-files/etc/diag.sh
+++ b/target/linux/kirkwood/base-files/etc/diag.sh
@@ -23,6 +23,9 @@ get_status_led() {
 	nsa310b)
 		status_led="nsa310:green:sys"
 		;;
+	on100)
+		status_led="on100:green:health"
+		;;
 	esac
 }
 
diff --git a/target/linux/kirkwood/base-files/lib/kirkwood.sh b/target/linux/kirkwood/base-files/lib/kirkwood.sh
index 2c7d7baf4b..dbf3456172 100755
--- a/target/linux/kirkwood/base-files/lib/kirkwood.sh
+++ b/target/linux/kirkwood/base-files/lib/kirkwood.sh
@@ -33,6 +33,10 @@ kirkwood_board_detect() {
 		name="ib62x0"
 		;;
 
+	"Cisco Systems ON100")
+		name="on100"
+		;;
+
 	"Cloud Engines Pogoplug E02")
 		name="pogo_e02"
 		;;
diff --git a/target/linux/kirkwood/image/Makefile b/target/linux/kirkwood/image/Makefile
index 141505e002..fc21aa4657 100644
--- a/target/linux/kirkwood/image/Makefile
+++ b/target/linux/kirkwood/image/Makefile
@@ -11,7 +11,7 @@ include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/image.mk
 
 KERNEL_LOADADDR:=0x8000
-TARGET_DEVICES = linksys-audi linksys-viper dockstar goflexnet goflexhome iconnect pogo_e02 ib62x0 nsa310b nsa325
+TARGET_DEVICES = linksys-audi linksys-viper dockstar goflexnet goflexhome iconnect pogo_e02 ib62x0 nsa310b nsa325 on100
 
 UBI_OPTS := -m 2048 -p 128KiB -s 512
 UBIFS_OPTS := -m 2048 -e 126KiB -c 4096
@@ -94,6 +94,17 @@ $(Device/dockstar)
   DEVICE_PACKAGES := kmod-gpio-button-hotplug kmod-rtc-pcf8563 kmod-usb3
 endef
 
+define Device/on100
+  DEVICE_TITLE := Cisco Systems ON100
+  DEVICE_DTS := kirkwood-on100
+#  DEVICE_PACKAGES := kmod-mvsdio kmod-usb-storage kmod-i2c-core kmod-i2c-mv64xxx kmod-ata-core kmod-btmrvl kmod-btmrvl-sdio kmod-libertas kmod-libertas-sdio
+  DEVICE_PACKAGES := kmod-i2c-mv64xxx
+  KERNEL_SIZE := 5376k
+  IMAGES += factory.bin
+  IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi
+  UBINIZE_OPTS := -E 5
+endef
+
 define Device/pogo_e02
 $(Device/dockstar)
   DEVICE_TITLE := Cloud Engines Pogoplug E02
diff --git a/target/linux/kirkwood/patches-4.4/195-on100.patch b/target/linux/kirkwood/patches-4.4/195-on100.patch
new file mode 100644
index 0000000000..8c66f2d173
--- /dev/null
+++ b/target/linux/kirkwood/patches-4.4/195-on100.patch
@@ -0,0 +1,173 @@
+--- /dev/null
++++ b/arch/arm/boot/dts/kirkwood-on100.dts
+@@ -0,0 +1,160 @@
++/dts-v1/;
++
++#include "kirkwood.dtsi"
++#include "kirkwood-6282.dtsi"
++
++/ {
++	model = "Cisco Systems ON100";
++	compatible = "cisco,on100", "marvell,kirkwood-88f6282", "marvell,kirkwood";
++
++	memory {
++		device_type = "memory";
++		reg = <0x00000000 0x20000000>;
++	};
++
++	aliases {
++		serial0 = &uart0;
++	};
++
++	chosen {
++		bootargs = "console=ttyS0,115200n8 earlyprintk";
++		stdout-path = "serial0:115200n8";
++	};
++
++ 	gpio_keys {
++		compatible = "gpio-keys";
++		#address-cells = <1>;
++		#size-cells = <0>;
++		pinctrl-0 = <&pmx_btn_reset>;
++		pinctrl-names = "default";
++
++		button@1 {
++			label = "Reset Button";
++			linux,code = <KEY_RESTART>;
++			gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
++		};
++	};
++
++	gpio-leds {
++		compatible = "gpio-leds";
++		pinctrl-0 = < &pmx_led_health_r &pmx_led_health_g >;
++		pinctrl-names = "default";
++
++		health-g {
++			label = "on100:green:health";
++			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
++		};
++
++		health-r {
++			label = "on100:red:health";
++			gpios = <&gpio1 13 GPIO_ACTIVE_LOW>;
++		};
++
++		health2-g {
++			label = "on100:green:health2";
++			gpios = <&gpio1 14 GPIO_ACTIVE_LOW>;
++		};
++
++		health2-r {
++			label = "on100:red:health2";
++			gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
++		};
++	};
++};
++
++&eth0 {
++	status = "okay";
++
++	ethernet0-port@0 {
++		phy-handle = <&ethphy0>;
++		phy-connection-type = "rgmii-id";
++	};
++};
++
++&eth1 {
++	status = "okay";
++
++	ethernet1-port@0 {
++		phy-handle = <&ethphy1>;
++		phy-connection-type = "rgmii-id";
++	};
++};
++
++&mdio {
++	status = "okay";
++
++	ethphy0: ethernet-phy@0 {
++		/* Marvell 88E1121R */
++		compatible = "ethernet-phy-id0141.0cb0",
++			     "ethernet-phy-ieee802.3-c22";
++		reg = <0>;
++	};
++
++	ethphy1: ethernet-phy@1 {
++		/* Marvell 88E1121R */
++		compatible = "ethernet-phy-id0141.0cb0",
++			     "ethernet-phy-ieee802.3-c22";
++		reg = <1>;
++	};
++};
++
++&nand {
++	status = "okay";
++
++	partition@0 {
++		label = "u-boot";
++		reg = <0x00000000 0x000a0000>;
++		read-only;
++	};
++
++	partition@a0000 {
++		label = "u-boot environment";
++		reg = <0x000a0000 0x00020000>;
++		read-only;
++	};
++
++	partition@c0000 {
++		label = "kernel";
++		reg = <0x000c0000 0x00540000>;
++	};
++
++	partition@600000 {
++		label = "ubi";
++		reg = <0x00600000 0x1fa00000>;
++	};
++};
++
++&pinctrl {
++	pmx_led_health_r: pmx-led-health-r {
++		marvell,pins = "mpp45";
++		marvell,function = "gpio";
++	};
++
++	pmx_led_health_g: pmx-led-health-g {
++		marvell,pins = "mpp44";
++		marvell,function = "gpio";
++	};
++
++	pmx_led_health2_r: pmx-led-health2-r {
++		marvell,pins = "mpp47";
++		marvell,function = "gpio";
++	};
++
++	pmx_led_health2_g: pmx-led-health2-g {
++		marvell,pins = "mpp46";
++		marvell,function = "gpio";
++	};
++
++	pmx_btn_reset: pmx-led-reset {
++		marvell,pins = "mpp31";
++		marvell,function = "gpio";
++	};
++};
++
++&sdio {
++	status = "okay";
++};
++
++&uart0 {
++	status = "okay";
++};
+--- a/arch/arm/boot/dts/Makefile
++++ b/arch/arm/boot/dts/Makefile
+@@ -206,6 +206,7 @@ dtb-$(CONFIG_MACH_KIRKWOOD) += \
+ 	kirkwood-nsa310b.dtb \
+ 	kirkwood-nsa310s.dtb \
+ 	kirkwood-nsa325.dtb \
++	kirkwood-on100.dtb \
+ 	kirkwood-openblocks_a6.dtb \
+ 	kirkwood-openblocks_a7.dtb \
+ 	kirkwood-openrd-base.dtb \
-- 
2.30.2