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

#include "mt7620a.dtsi"

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

/ {
	compatible = "trendnet,tha103ac", "ralink,mt7620a-soc";
	model = "TRENDNET THA-103AC (EU)";

	aliases {
		label-mac-device = &ethernet;
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
	};

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

		button_reset {
			label = "reset";
			gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};

		/* wps button reassigned to rfkill */
		button_rfkill {
			label = "wifi on/off";
			gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RFKILL>;
		};

	};

	leds {
		compatible = "gpio-leds";

		led-0 {
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_WPS;
			gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
		};

		led_power: led-1 {
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_POWER;
			gpios = <&gpio0 14 GPIO_ACTIVE_LOW>;
			default-state = "on";
		};

		led-2 {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WLAN;
			gpios = <&gpio1 14 GPIO_ACTIVE_LOW>;
		};

		led-3 {
			color = <LED_COLOR_ID_BLUE>;
			/* LED_FUNCTION_RSSILOW isn't implemented yet */
			function = "rssilow";
			gpios = <&gpio2 16 GPIO_ACTIVE_LOW>;
		};

		led-4 {
			color = <LED_COLOR_ID_BLUE>;
			/* LED_FUNCTION_RSSIMEDLOW isn't implemented yet */
			function = "rssimedlow";
			gpios = <&gpio2 17 GPIO_ACTIVE_LOW>;
		};

		led-5 {
			color = <LED_COLOR_ID_BLUE>;
			/* LED_FUNCTION_RSSIMEDIUM isn't implemented yet */
			function = "rssimedium";
			gpios = <&gpio2 18 GPIO_ACTIVE_LOW>;
		};

		led-6 {
			color = <LED_COLOR_ID_BLUE>;
			/* LED_FUNCTION_RSSIHIGH isn't implemented yet */
			function = "rssihigh";
			gpios = <&gpio2 19 GPIO_ACTIVE_LOW>;
		};
	};
};

&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>;
				read-only;
			};

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

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

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

					eeprom_factory_8000: eeprom@8000 {
						reg = <0x8000 0x200>;
					};

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

					macaddr_factory_28: macaddr@28 {
						compatible = "mac-base";
						reg = <0x28 0x6>;
						#nvmem-cell-cells = <1>;
					};

					macaddr_factory_8004: macaddr@8004 {
						compatible = "mac-base";
						reg = <0x8004 0x6>;
						#nvmem-cell-cells = <1>;
					};
				};
			};

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

&state_default {
	gpio {
		groups = "i2c", "uartf", "ephy";
		function = "gpio";
	};
};

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

	mediatek,portmap = "wl";
};

&gpio1 {
	status = "okay";
};

&gpio2 {
	status = "okay";
};

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

&pcie {
	status = "okay";
};

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