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

#include "mt7621.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	aliases {
		led-boot = &led_power_green;
		led-failsafe = &led_power_red;
		led-running = &led_power_green;
		led-upgrade = &led_power_green;
	};

	chosen {
		bootargs-override = "console=ttyS0,115200n8";
	};

	leds {
		compatible = "gpio-leds";

		led-0 {
			gpios = <&gpio 5 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WLAN_5GHZ;
		};

		led-1 {
			gpios = <&gpio 6 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_WLAN_5GHZ;
			linux,default-trigger = "phy1tpt";
		};

		led_power_green: led-2 {
			gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_POWER;
		};

		led-3 {
			gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_POWER;
		};

		led-4 {
			gpios = <&gpio 9 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_WLAN_5GHZ;
		};

		led-5 {
			gpios = <&gpio 10 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WLAN_2GHZ;
		};

		led-6 {
			gpios = <&gpio 11 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_WLAN_2GHZ;
		};

		led-7 {
			gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_WLAN_2GHZ;
			linux,default-trigger = "phy0tpt";
		};

		led_power_red: led-8 {
			gpios = <&gpio 16 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_POWER;
		};
	};

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

		button-reset {
			label = "reset";
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};

		button-wps {
			label = "wps";
			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WPS_BUTTON>;
		};
	};
};

&gmac0 {
	nvmem-cells = <&macaddr_factory_3fff4>;
	nvmem-cell-names = "mac-address";
};

&nand {
	status = "okay";
	pinctrl-0 = <&nand_pins>;
	pinctrl-names = "default";

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

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

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

		partition@100000 {
			label = "factory";
			reg = <0x100000 0x80000>;
			read-only;

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

				eeprom_factory_0: eeprom@0 {
					reg = <0x0 0xe00>;
				};

				precal_factory_e10: precal@e10 {
					reg = <0xe10 0x19c10>;
				};

				macaddr_factory_4: mac-address@4 {
					compatible = "mac-base";
					reg = <0x4 0x6>;
					#nvmem-cell-cells = <1>;
				};

				macaddr_factory_3fff4: mac-address@3fff4 {
					reg = <0x3fff4 0x6>;
				};

				macaddr_factory_3fffa: mac-address@3fffa {
					reg = <0x3fffa 0x6>;
				};
			};
		};

		/* stock: "firmware" */
		partition@180000 {
			reg = <0x180000 0xf00000>;
			label = "kernel";
		};

		partition@1080000 {
			label = "user_data";
			reg = <0x1080000 0x500000>;
			read-only;
		};

		partition@1580000 {
			label = "tm_pattern";
			reg = <0x1580000 0x500000>;
			read-only;
		};

		partition@1a80000 {
			label = "tm_key";
			reg = <0x1a80000 0x100000>;
			read-only;
		};

		/* stock: (unused) */
		partition@1b80000 {
			label = "ubi";
			reg = <0x1b80000 0x6480000>;
		};
	};
};

&pcie {
	status = "okay";
};

&pcie1 {
	wifi: wifi@0,0 {
		compatible = "mediatek,mt76";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_0>, <&precal_factory_e10>;
		nvmem-cell-names = "eeprom", "precal";
		mediatek,disable-radar-background;
		#address-cells = <1>;
		#size-cells = <0>;
	};
};

&switch0 {
	ports {
		port@1 {
			status = "okay";
			label = "lan2";
		};

		port@2 {
			status = "okay";
			label = "lan1";
		};
	};
};

&state_default {
	gpio {
		groups = "i2c", "uart3", "uart2", "jtag", "wdt";
		function = "gpio";
	};
};

&uartlite {
	pinctrl-0 = <&uart1_pins>;
	pinctrl-names = "default";
};

&xhci {
	status = "disabled";
};
