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

#include "mt7628an.dtsi"

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

/ {
	compatible = "wavlink,wl-wn570ha2", "mediatek,mt7628an-soc";
	model = "Wavlink WL-WN570HA2";

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

	keys {
		compatible = "gpio-keys";

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

	leds {
		compatible = "gpio-leds";

		led_power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 37 GPIO_ACTIVE_LOW>;
		};

		lan {
			function = LED_FUNCTION_LAN;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 43 GPIO_ACTIVE_LOW>;
		};

		wifi-high {
			label = "blue:wifi-high";
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
		};

		wifi-med {
			label = "blue:wifi-med";
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
		};

		wifi-low {
			label = "blue:wifi-low";
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
		};

		wifi {
			function = LED_FUNCTION_WLAN;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 44 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "phy0tpt";
		};
	};
};

&state_default {
	gpio {
		groups = "i2c", "wled_an", "p0led_an", "wdt", "refclk";
		function = "gpio";
	};
};

&pcie {
	status = "okay";
};

&spi0 {
	status = "okay";

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

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

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

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
			};

			partition@40000 {
				label = "factory";
				reg = <0x40000 0x10000>;

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

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

					eeprom_factory_8000: eeprom@8000 {
						/* MT7613 has unique eeprom size '0x4da8' */
						reg = <0x8000 0x4da8>;
					};

					macaddr_factory_4: macaddr@4 {
						reg = <0x4 0x6>;
					};

					macaddr_factory_28: macaddr@28 {
						reg = <0x28 0x6>;
					};

					macaddr_factory_4004: macaddr@4004 {
						reg = <0x4004 0x6>;
					};
				};
			};

			partition@50000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x50000 0xf20000>;
			};

			partition@f70000 {
				label = "vendor";
				reg = <0xf70000 0x80000>;
				read-only;
			};

			partition@ff0000 {
				label = "hw";
				reg = <0xff0000 0x10000>;
				read-only;
			};
		};
	};
};

&pcie0 {
	wifi@0,0 {
		compatible = "mediatek,mt76";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_8000>, <&macaddr_factory_4004>;
		nvmem-cell-names = "eeprom", "mac-address";
		ieee80211-freq-limit = <5000000 6000000>;
	};
};

&wmac {
	status = "okay";

	nvmem-cells = <&eeprom_factory_0>, <&macaddr_factory_4>;
	nvmem-cell-names = "eeprom", "mac-address";
};

&ethernet {
	nvmem-cells = <&macaddr_factory_28>;
	nvmem-cell-names = "mac-address";
};

&esw {
	mediatek,portmap = <0x2f>;
};
