// 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>

/ {
	compatible = "zte,e8820s", "mediatek,mt7621-soc";
	model = "ZTE E8820S";

	aliases {
		led-boot = &power_led;
		led-failsafe = &system_led;
		led-running = &system_led;
		led-upgrade = &system_led;
		label-mac-device = &gmac0;
	};

	chosen {
		bootargs = "console=ttyS0,115200";
	};

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

		power_led: led-power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_WHITE>;
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
		};

		system_led: led-system {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_WHITE>;
			gpios = <&gpio 3 GPIO_ACTIVE_LOW>;
		};
	};

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

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

		button-wifi {
			label = "wifi";
			gpios = <&gpio 10 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RFKILL>;
		};

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

&ethphy4 {
	/delete-property/ interrupts;
};

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

&gmac1 {
	status = "okay";
	label = "wan";
	phy-handle = <&ethphy4>;

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

&nand {
	status = "okay";

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

		partition@0 {
			label = "Bootloader";
			reg = <0x0 0x220000>;
			read-only;
		};

		partition@80000 {
			compatible = "nvmem-cells";
			label = "config";
			reg = <0x220000 0x140000>;
			read-only;

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

				macaddr_config_12: macaddr@12 {
					compatible = "mac-base";
					reg = <0x12 0x6>;
					#nvmem-cell-cells = <1>;
				};
			};
		};

		partition@360000 {
			compatible = "nvmem-cells";
			label = "factory";
			reg = <0x360000 0x140000>;
			read-only;

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

				eeprom_factory_f000: eeprom@f000 {
					reg = <0xf000 0x400>;
				};

				eeprom_factory_f800: eeprom@f800 {
					reg = <0xf800 0x200>;
				};
			};
		};

		partition@4a0000 {
			label = "kernel";
			reg = <0x4a0000 0x400000>;
		};

		partition@8a0000 {
			label = "ubi";
			reg = <0x8a0000 0x76e0000>;
		};
	};
};

&pcie {
	reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>,
		      <&gpio 4 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&pcie0 {
	wifi@0,0 {
		compatible = "pci14c3,7603";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_f000>, <&macaddr_config_12 0>;
		nvmem-cell-names = "eeprom", "mac-address";
		ieee80211-freq-limit = <2400000 2500000>;

		led {
			led-active-low;
		};
	};
};

&pcie1 {
	wifi@0,0 {
		compatible = "pci14c3,7662";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_f800>, <&macaddr_config_12 1>;
		nvmem-cell-names = "eeprom", "mac-address";
		ieee80211-freq-limit = <5000000 6000000>;

		led {
			led-active-low;
			led-sources = <2>;
		};
	};
};

&switch0 {
	ports {
		port@0 {
			status = "okay";
			label = "lan1";
		};

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

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

		port@3 {
			status = "okay";
			label = "lan4";
		};
	};
};

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