// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;

#include "kirkwood.dtsi"
#include "kirkwood-6281.dtsi"

/ {
	model = "ipTIME NAS1";
	compatible = "iptime,nas1", "marvell,kirkwood-88f6281", "marvell,kirkwood";

	aliases {
		serial0 = &uart0;
		led-boot = &led_ready;
		led-failsafe = &led_ready;
		led-running = &led_ready;
		led-upgrade = &led_ready;
	};

	chosen {
		/*
		 * "root" argument from the stock bootloader should be ignored
		 * as it'll prevent the kernel from finding the correct rootfs.
		 */
		bootargs-append = " console=ttyS0,115200 root=";
		stdout-path = "serial0:115200n8";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x00000000 0x10000000>;
	};

	gpio-leds {
		compatible = "gpio-leds";

		pinctrl-0 = <&pmx_led>;
		pinctrl-names = "default";

		hdd {
			label = "blue:hdd";
			gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "ata1";
		};

		usb {
			label = "blue:usb";
			gpios = <&gpio1 13 GPIO_ACTIVE_LOW>;
			trigger-sources = <&ehci_port1>;
			linux,default-trigger = "usbport";
		};

		led_ready: ready {
			label = "blue:ready";
			gpios = <&gpio1 14 GPIO_ACTIVE_LOW>;
		};
	};

	gpio-keys {
		compatible = "gpio-keys";

		pinctrl-0 = <&pmx_button>;
		pinctrl-names = "default";

		reset-copy {
			label = "Reset/Copy Button";
			linux,code = <KEY_RESTART>;
			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
		};

		power {
			label = "Power Button";
			linux,code = <KEY_POWER>;
			gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
		};
	};

	gpio-fan {
		compatible = "gpio-fan";

		pinctrl-0 = <&pmx_fan>;
		pinctrl-names = "default";
		gpios = <&gpio1  9 GPIO_ACTIVE_HIGH>,
		        <&gpio1 10 GPIO_ACTIVE_HIGH>;
		/* We don't know the exact rpm, just use dummy values here. */
		gpio-fan,speed-map = <0 0>, <1 1>, <2 2>;
		#cooling-cells = <2>;
	};

	gpio-poweroff {
		compatible = "gpio-poweroff";
		gpios = <&pca9536 0 GPIO_ACTIVE_LOW>;
	};

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

		pinctrl-0 = <&pmx_usb_vbus>;
		pinctrl-names = "default";

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

&pinctrl {
	pmx_led: pmx-led {
		marvell,pins = "mpp35", "mpp45", "mpp46";
		marvell,function = "gpio";
	};

	pmx_fan: pmx-fan {
		marvell,pins = "mpp41", "mpp42";
		marvell,function = "gpio";
	};

	pmx_usb_vbus: pmx-usb-vbus {
		marvell,pins = "mpp43";
		marvell,function = "gpio";
	};

	pmx_button: pmx-button {
		marvell,pins = "mpp44", "mpp48";
		marvell,function = "gpio";
	};
};

&spi0 {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <20000000>;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x40000>;
				read-only;
			};

			partition@40000 {
				compatible = "openwrt,uimage", "denx,uimage";
				openwrt,offset = <0x400>;
				label = "firmware";
				reg = <0x40000 0xf80000>;
			};

			partition@fc0000 {
				label = "config";
				reg = <0xfc0000 0x40000>;
				read-only;
			};
		};
	};
};

&rtc {
	status = "disabled";
};

&i2c0 {
	status = "okay";

	pca9536: gpio@41 {
		compatible = "nxp,pca9536";
		reg = <0x41>;
		gpio-controller;
		#gpio-cells = <2>;
	};
};

&uart0 {
	status = "okay";
};

&usb0 {
	status = "okay";

	#address-cells = <1>;
	#size-cells = <0>;

	ehci_port1: port@1 {
		reg = <1>;
		#trigger-source-cells = <0>;
	};
};

&mdio {
	status = "okay";

	ethphyb: ethernet-phy@b {
		reg = <0x0b>;
	};
};

&eth1 {
	status = "okay";
};

&eth1port {
	phy-handle = <&ethphyb>;
	phy-connection-type = "rgmii-id";
};

&sata {
	status = "okay";

	#address-cells = <1>;
	#size-cells = <0>;
	nr-ports = <1>;

	sata-port@0 {
		reg = <0>;
		#thermal-sensor-cells = <0>;
	};
};
