// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)

/dts-v1/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include "armada-372x.dtsi"

/ {
	model = "GL.iNet GL-MV1000";
	compatible = "glinet,gl-mv1000", "marvell,armada3720";

	aliases {
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
	};

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

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

	vcc_sd_reg1: regulator {
		compatible = "regulator-gpio";
		regulator-name = "vcc_sd1";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <3300000>;
		regulator-boot-on;

		gpios-states = <0>;
		states = <1800000 0x1
			3300000 0x0>;
		enable-active-high;
	};

	keys {
		compatible = "gpio-keys";

		reset {
			label = "reset";
			linux,code = <KEY_RESTART>;
			gpios = <&gpionb 14 GPIO_ACTIVE_LOW>;
		};

		switch {
			label = "switch";
			linux,code = <BTN_0>;
			gpios = <&gpiosb 22 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		compatible = "gpio-leds";

		vpn {
			label = "green:vpn";
			gpios = <&gpionb 11 GPIO_ACTIVE_LOW>;
		};

		wan {
			function = LED_FUNCTION_WAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpionb 12 GPIO_ACTIVE_LOW>;
		};

		led_power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpionb 13 GPIO_ACTIVE_LOW>;
			default-state = "on";
		};
	};
};

&spi0 {
	status = "okay";

	flash@0 {
		reg = <0>;
		compatible = "jedec,spi-nor";
		spi-max-frequency = <104000000>;
		m25p,fast-read;
		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

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

			partition@f0000 {
				label = "u-boot-env";
				reg = <0xf0000 0x8000>;
				read-only;
			};

			factory: partition@f8000 {
				label = "factory";
				reg = <0xf8000 0x8000>;
				read-only;

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

					macaddr_factory_0: macaddr@0 {
						reg = <0x0 0x6>;
					};

					macaddr_factory_6: macaddr@6 {
						reg = <0x6 0x6>;
					};
				};
			};

			partition@100000 {
				label = "gl-firmware-dtb";
				reg = <0x100000 0x10000>;
				read-only;
			};

			partition@110000 {
				label = "gl-firmware";
				reg = <0x110000 0xef0000>;
				read-only;
			};

			partition@ef0000 {
				label = "gl-firmware-jffs2";
				reg = <0xef0000 0x110000>;
				read-only;
			};
		};
	};
};

&sdhci1 {
	wp-inverted;
	bus-width = <4>;
	cd-gpios = <&gpionb 17 GPIO_ACTIVE_LOW>;
	marvell,pad-type = "sd";
	no-1-8-v;
	vqmmc-supply = <&vcc_sd_reg1>;
	status = "okay";
};

&sdhci0 {
	bus-width = <8>;
	mmc-ddr-1_8v;
	mmc-hs400-1_8v;
	non-removable;
	no-sd;
	no-sdio;
	marvell,pad-type = "fixed-1-8v";
	status = "okay";
};

&usb3 {
	status = "okay";
};

&usb2 {
	status = "okay";
};

&uart0 {
	status = "okay";
};

&mdio {
	switch0: switch0@1 {
		compatible = "marvell,mv88e6085";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <1>;

		dsa,member = <0 0>;

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

			port@0 {
				reg = <0>;
				ethernet = <&eth0>;
			};

			port@1 {
				reg = <1>;
				label = "wan";
				phy-handle = <&switch0phy0>;
			};

			port@2 {
				reg = <2>;
				label = "lan0";
				phy-handle = <&switch0phy1>;

				nvmem-cells = <&macaddr_factory_6>;
				nvmem-cell-names = "mac-address";
			};

			port@3 {
				reg = <3>;
				label = "lan1";
				phy-handle = <&switch0phy2>;

				nvmem-cells = <&macaddr_factory_6>;
				nvmem-cell-names = "mac-address";
			};
		};

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

			switch0phy0: switch0phy0@11 {
				reg = <0x11>;
			};
			switch0phy1: switch0phy1@12 {
				reg = <0x12>;
			};
			switch0phy2: switch0phy2@13 {
				reg = <0x13>;
			};
		};
	};
};

&eth0 {
	nvmem-cells = <&macaddr_factory_0>;
	nvmem-cell-names = "mac-address";
	phy-mode = "rgmii-id";
	status = "okay";

	fixed-link {
		speed = <1000>;
		full-duplex;
	};
};
