/*
 * Device Tree file for WD MyCloud Mirror
 * Based on DB-88F6710-BP-DDR3
 *
 *  Copyright (C) 2012 Marvell
 *
 * Lior Amsalem <alior@marvell.com>
 * Gregory CLEMENT <gregory.clement@free-electrons.com>
 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
 * Allester Fox <fox.axon@gmail.com>
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

/dts-v1/;
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include "armada-370.dtsi"

/ {
	model = "WD MyCloud Mirror";
	compatible = "marvell,a370-db", "marvell,armada370", "marvell,armada-370-xp";

	chosen {
		stdout-path = "serial0:115200n8";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x00000000 0x20000000>; /* 512 MiB */
	};

	soc {
		ranges = <MBUS_ID(0xf0, 0x01) 0 0xf1000000 0x100000
			MBUS_ID(0x01, 0xe0) 0 0xfff00000 0x100000
			MBUS_ID(0x09, 0x01) 0 0xf1100000 0x10000>;

		internal-regs {
			sata@a0000 {
				nr-ports = <2>;
				status = "okay";
			};

			usb@50000 {
				status = "okay";
			};

			nand@d0000 {
				status = "okay";
				compatible = "marvell,armada370-nand";
				num-cs = <1>;
				marvell,nand-enable-arbiter;
				nand-on-flash-bbt;
				nand-ecc-strength = <4>;
				nand-ecc-step-size = <512>;
				
				partitions {
					compatible = "fixed-partitions";
					#address-cells = <1>;
					#size-cells = <1>;

					partition@0 {
						label = "u-Boot";
						reg = <0x00000000 0x00500000>;	// Warning: New style: <start size> not old <start end> !
						read-only;
					};
					partition@500000 {
						label = "uImage";
						reg = <0x00500000 0x00500000>;
					};
					partition@a00000 {
						label = "ramdisk";
						reg = <0x00A00000 0x00500000>;
					};
					partition@f00000 {
						label = "image.cfs";
						reg = <0x00f00000 0x0c900000>;
					};
					partition@dd00000 {
						label = "rescue firmware";
						reg = <0x0dd00000 0x00f00000>;
					};
					partition@ec00000 {
						label = "config";
						reg = <0x0ec00000 0x01400000>;
					};
					partition@d800000 {
						label = "reserve";
						reg = <0x0d800000 0x00500000>;
					};
				};
			};
		};
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&reset_button_pin>;
		pinctrl-names = "default";

		reset-button {
			label = "Reset Button";
			linux,code = <KEY_RESTART>;
			gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;
		};
	};

	gpio-leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&led_pins>;

		hdd1-blue {
			label = "hdd1-blue";
			gpios = <&gpio1 25 GPIO_ACTIVE_HIGH>;	// gpio57
			//linux,default-trigger = "none";
			default-state = "keep";
		};
		hdd2-blue {
			label = "hdd2-blue";
			gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;	// gpio55
			//linux,default-trigger = "none";
			default-state = "keep";
		};
		hdd1-red {
			label = "hdd1-red";
			gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;	// gpio53
			// linux,default-trigger = "none";
			default-state = "keep";
		};
		hdd2-red {
			label = "hdd2-red";
			gpios = <&gpio1 20 GPIO_ACTIVE_HIGH>;	// gpio52
			// linux,default-trigger = "none";
			default-state = "keep";
		};
	};

	gpio-fan {
		status = "okay";
		compatible = "gpio-fan";
		pinctrl-names = "default";
		pinctrl-0 = <&fan_pins>;

		gpios = <&gpio0 8 GPIO_ACTIVE_HIGH
				&gpio0 16 GPIO_ACTIVE_HIGH
				&gpio1 0 GPIO_ACTIVE_HIGH	// mpp32: 32-32=0
				&gpio0 6 GPIO_ACTIVE_HIGH>;
		alarm-gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>;
		gpio-fan,speed-map = < 0 0
			 1500 1
			 1700 2
			 1800 3
			 2100 4>;
	};

	regulators {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <0>;

		usb_power: regulator@1 {
			compatible = "regulator-fixed";
			reg = <1>;
			pinctrl-0 = <&xhci_pwr_pin>;
			pinctrl-names = "default";
			regulator-name = "USB3.0 Port Power";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			enable-active-high;
			regulator-boot-on;
			regulator-always-on;
			gpio = <&gpio0 13 GPIO_ACTIVE_HIGH>;
		};

		sata_1_power: regulator@2 {
			compatible = "regulator-fixed";
			reg = <2>;
			pinctrl-0 = <&sata_1_pwr_pin>;
			pinctrl-names = "default";
			regulator-name = "SATA-1 Power";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			startup-delay-us = <2000000>;
			enable-active-high;
			regulator-always-on;
			regulator-boot-on;
			gpio = <&gpio1 22 GPIO_ACTIVE_HIGH>;
		};

		sata_2_power: regulator@3 {
			compatible = "regulator-fixed";
			reg = <3>;
			pinctrl-0 = <&sata_2_pwr_pin>;
			pinctrl-names = "default";
			regulator-name = "SATA-2 Power";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			startup-delay-us = <4000000>;
			enable-active-high;
			regulator-always-on;
			regulator-boot-on;
			gpio = <&gpio1 24 GPIO_ACTIVE_HIGH>;
		};
	};
};

&pciec {
	status = "okay";

	pcie@1,0 {
		/* Port 0, Lane 0 */
		status = "okay";
	};

	pcie@2,0 {
		/* Port 1, Lane 0 */
		status = "okay";
	};
};

&pinctrl {
	led_pins: led-pins {
		// HDD2-Red, HDD1-Red, HDD1-Blue, HDD2-Blue
		marvell,pins = "mpp52", "mpp53", "mpp57", "mpp55";
		marvell,function = "gpio";
	};

	fan_pins: fan-pins {
		marvell,pins = "mpp6", "mpp8", "mpp16", "mpp32";
		marvell,function = "gpio";
	};

	xhci_pwr_pin: xhci-pwr-pin {
		marvell,pins = "mpp13";
		marvell,function = "gpio";
	};

	sata_1_pwr_pin: sata-1-pwr-pin {
		marvell,pins = "mpp54";
		marvell,function = "gpio";
	};

	sata_2_pwr_pin: sata-2-pwr-pin {
		marvell,pins = "mpp56";
		marvell,function = "gpio";
	};

	uart1_pins: uart1-pins {
		marvell,pins = "mpp60", "mpp61";
		marvell,function = "uart1";
	};

	reset_button_pin: reset-button-pin {
		marvell,pins = "mpp64";
		marvell,function = "gpio";
	};
};

/* Serial console */
&uart0 {
	status = "okay";
};

/* Connected to Weltrend MCU */
&uart1 {
	pinctrl-0 = <&uart1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&mdio {
	phy0: ethernet-phy@0 { /* Marvell 88E1318 */
		reg = <0>;
		/*
		marvell,reg-init = <0x0 0x16 0x0 0x0002>,
				<0x0 0x19 0x0 0x0077>,
				<0x0 0x18 0x0 0x5747>;
		*/
	};
};

&eth1 {
	phy = <&phy0>;
	phy-mode = "rgmii-id";
	status = "okay";
};

&i2c0 {
	compatible = "marvell,mv64xxx-i2c";
	clock-frequency = <100000>;
	status = "okay";
};
