/*
 * Device Tree file for Zyxel NAS326
 *
 *  Copyright (C) 2017 bodhi <mibodhi@gmail.com>
 *                     Taras Ivaniukovich <rr-m@rr-m.org>
 *                     Henrik Andersson <henrik.4e@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-380.dtsi"

/ {
	model = "Zyxel NAS326";
	compatible = "zyxel,nas326", "marvell,armada380", "marvell,armada38x";

	chosen {
		bootargs = "console=ttyS0,115200";
	};

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

	soc {
		ranges = <MBUS_ID(0xf0, 0x01) 0 0xf1000000 0x100000
			  MBUS_ID(0x01, 0x1d) 0 0xfff00000 0x100000
			  MBUS_ID(0x09, 0x19) 0 0xf1100000 0x10000	/* CESA0: PHYS=0xf1100000
									   size 64K */
			  MBUS_ID(0x09, 0x15) 0 0xf1110000 0x10000>;	/* CESA1: PHYS=0xf1110000
									   size 64K */

		internal-regs {
			ethernet@70000 {
				status = "okay";
				phy-mode = "rgmii";
                mac-address = [ 1a 07 a8 2c 04 76 ];
				fixed-link {
					speed = <1000>;
					full-duplex;
				};
			};

			i2c0: i2c@11000 {
				status = "okay";
				clock-frequency = <100000>;
			};

			i2c1: i2c@11100 {
				status = "okay";
				clock-frequency = <100000>;
			};

			mdio {
			        status = "okay";
			};

			sata@a8000 {
				status = "okay";
			};


			sdhci@d8000 {
				broken-cd;
				wp-inverted;
				bus-width = <8>;
				status = "okay";
			};

			serial@12000 {
				status = "okay";
			};

			usb@58000 {
				  status = "okay";
			};
			
			usb3@f0000 {
				   status = "okay";
			};

			usb3@f8000 {
				   status = "okay";
			};

			flash@d0000 {
                                status = "okay";
                                num-cs = <1>;
                                marvell,nand-keep-config;
                                marvell,nand-enable-arbiter;
                                nand-on-flash-bbt;

				partition@00000000 {
					label = "U-Boot";
					reg = <0x00000000 0x00200000>;	/*   2 MB */
				};

				partition@00200000 {
					label = "U-Boot env";
					reg = <0x00200000 0x00200000>;	/*   2 MB */
				};

				partition@00400000 {
					label = "Config";
					reg = <0x00400000 0x00A00000>;	/*  10 MB */
				};

				partition@00600000 {
					label = "Kernel-1";
					reg = <0x00E00000 0x00F00000>;	/*  15 MB */
				};

				partition@01500000 {
					label = "RootFS-1";
					reg = <0x01D00000 0x06A00000>;	/* 106 MB */
				};

				partition@08300000 {
					label = "Kernel-2";
					reg = <0x08700000 0x00F00000>;	/*  15 MB */
				};

				partition@09200000 {
					label = "RootFS-2";
					reg = <0x09600000 0x06A00000>;	/* 106 MB */
				};
			};

			crypto@9D000 {
				status = "okay";
			};

			pinctrl@18000 {
				pinctrl-names = "default";

				pmx_power_button: pmx_power-button {
					marvell,pins = "mpp46";
					marvell,function = "gpio";
				};

				pmx_copy_button: pmx_copy-button {
					marvell,pins = "mpp39";
					marvell,function = "gpio";
				};
				
				pmx_reset_button: pmx_reset-button {
					marvell,pins = "mpp49";
					marvell,function = "gpio";
				};

				pmx_sata1_white_led: pmx_sata1_white_led {
					marvell,pins = "mpp50";
					marvell,function = "gpio";
				};

				pmx_sata1_red_led: pmx_sata1_red_led {
					marvell,pins = "mpp48";
					marvell,function = "gpio";
				};

				pmx_sata2_white_led: pmx_sata2_white_led {
					marvell,pins = "mpp53";
					marvell,function = "gpio";
				};
	
				pmx_sata2_red_led: pmx_sata2_red_led {
				        marvell,pins = "mpp54";
					marvell,function = "gpio";
				};
	
			        pmx_sys_white_led: pmx_sys_white_led {
					marvell,pins = "mpp52";
					marvell,function = "gpio";
				};

			        pmx_sys_red_led: pmx_sys_red_led {
					marvell,pins = "mpp55";
					marvell,function = "gpio";
				};

				pmx_usb_white_led: pmx_usb_white_led {
					marvell,pins = "mpp21";
					marvell,function = "gpio";
				};

				pmx_copy_white_led: pmx_copy_white_led {
					marvell,pins = "mpp26";
					marvell,function = "gpio";
				};
				
				pmx_copy_red_led: pmx_copy_red_led {
					marvell,pins = "mpp37";
					marvell,function = "gpio";
				};
				
				pmx_buzzer: pmx_buzzer {
					marvell,pins = "mpp19";
					marvell,function = "gpio";
				};
				
			};

		};

		pcie-controller {
			status = "okay";
			/*
			 * The two PCIe units are accessible through
			 * standard PCIe slots on the board.
			 */
			pcie@1,0 {
				/* Port 0, Lane 0 */
				status = "okay";
			};
			pcie@2,0 {
				/* Port 1, Lane 0 */
				status = "okay";
			};
		};
		
	};

	usb2_phy: usb2_phy {
		compatible = "usb-nop-xceiv";
		vcc-supply = <&usb2_power>;
	};

	gpio-keys {
		compatible = "gpio-keys";
		#address-cells = <1>;
		#size-cells = <0>;
		pinctrl-0 = <&pmx_power_button &pmx_copy_button &pmx_reset_button>;
		pinctrl-names = "default";

		button@1 {
			label = "Power Button";
			linux,code = <KEY_POWER>;
			gpios = <&gpio1 14 GPIO_ACTIVE_HIGH>;
		};

		button@2 {
			label = "Copy Button";
			linux,code = <KEY_COPY>;
			gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
		};

		button@3 {
			label = "Reset Button";
			linux,code = <KEY_RESTART>;
			gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>;
		};
	};

	gpio-leds {
		compatible = "gpio-leds";
		pinctrl-0 = <&pmx_sata1_white_led 
				&pmx_sata1_red_led 
				&pmx_sata2_white_led				
				&pmx_sata2_red_led
				&pmx_sys_white_led
				&pmx_sys_red_led
				&pmx_usb_white_led>;

		pinctrl-names = "default";

		white_sata1 {
			label = "nsa326:white:sata1";
			gpios = <&gpio1 18 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "ide-disk1";
		};

		red_sata1 {
			label = "nsa326:red:sata1";
			gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
		};

		white-sata2 {
			label = "nsa326:white:sata2";
			gpios = <&gpio1 21 GPIO_ACTIVE_HIGH>;
		};
		
		red-sata2 {                       
			label = "nsa326:red:sata2";
			gpios = <&gpio1 22 GPIO_ACTIVE_HIGH>;
		};

		white-usb {
			label = "nsa326:white:usb";
			gpios = <&gpio0 21 GPIO_ACTIVE_HIGH>;
                        linux,default-trigger = "usb-host";
		};

		white-sys {
			label = "nsa326:white:sys";
			gpios = <&gpio1 20 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "default-on";
		};

                red-sys {
                        label = "nsa326:red:sys";
                        gpios = <&gpio1 23 GPIO_ACTIVE_HIGH>;
                };

                white-copy {
                        label = "nsa326:white:copy";
                        gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>;
                };

                red-copy {
                        label = "nsa326:red:copy";
                        gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;
                };
	};

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

                usb2_power: regulator@1 {
                        compatible = "regulator-fixed";
                        reg = <1>;
                        regulator-name = "USB2 Power";
                        regulator-min-microvolt = <5000000>;
                        regulator-max-microvolt = <5000000>;
                        enable-active-high;
                        regulator-always-on;
                        regulator-boot-on;
                        gpio = <&gpio1 11 GPIO_ACTIVE_HIGH>;
                };

		reg_sata0: regulator@2 {
			compatible = "regulator-fixed";
			regulator-name = "pwr_en_sata0";
			regulator-min-microvolt = <12000000>;
			regulator-max-microvolt = <12000000>;
			enable-active-high;
			regulator-boot-on;
			gpio = <&gpio1 13 GPIO_ACTIVE_HIGH>;
		};

		reg_5v_sata0: v5-sata0 {
			compatible = "regulator-fixed";
			regulator-name = "v5.0-sata0";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			vin-supply = <&reg_sata0>;
		};

		reg_12v_sata0: v12-sata0 {
			compatible = "regulator-fixed";
			regulator-name = "v12.0-sata0";
			regulator-min-microvolt = <12000000>;
			regulator-max-microvolt = <12000000>;
			vin-supply = <&reg_sata0>;
		};

		reg_sata1: regulator@3 {
			regulator-name = "pwr_en_sata1";
			compatible = "regulator-fixed";
			regulator-min-microvolt = <12000000>;
			regulator-max-microvolt = <12000000>;
			enable-active-high;
			regulator-boot-on;
			gpio = <&gpio0 29 GPIO_ACTIVE_HIGH>;
		};

		reg_5v_sata1: v5-sata1 {
			compatible = "regulator-fixed";
			regulator-name = "v5.0-sata1";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			vin-supply = <&reg_sata1>;
		};

		reg_12v_sata1: v12-sata1 {
			compatible = "regulator-fixed";
			regulator-name = "v12.0-sata1";
			regulator-min-microvolt = <12000000>;
			regulator-max-microvolt = <12000000>;
			vin-supply = <&reg_sata1>;
		};

	};

	gpio-poweroff {
		compatible = "gpio-poweroff";
                pinctrl-0 = <&uart0_pins>;
                pinctrl-names = "default";
		gpios = <&gpio0 20  GPIO_ACTIVE_HIGH>;
	};
};