// 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 = "dual-q,h721", "mediatek,mt7621-soc";
	model = "Dual-Q H721";

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

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

	gpio-export {
		compatible = "gpio-export";
		#size-cells = <0>;

		usb-30-power {
			gpio-export,name = "usb-30-power";
			gpio-export,output = <0>;
			gpios = <&gpio 22 GPIO_ACTIVE_LOW>;
		};

		usb-20-power {
			gpio-export,name = "usb-20-power";
			gpio-export,output = <0>;
			gpios = <&gpio 23 GPIO_ACTIVE_LOW>;
		};
	};

	keys {
		compatible = "gpio-keys";

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

	leds {
		compatible = "gpio-leds";

		usb1 {
			label = "green:usb1";
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
		};

		sig1 {
			label = "green:sig1";
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
		};

		usb2 {
			label = "green:usb2";
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
		};

		sig2 {
			label = "green:sig2";
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
		};

		tf {
			label = "green:tf";
			gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
		};

		wifi1 {
			label = "green:wifi1";
			gpios = <&gpio 24 GPIO_ACTIVE_LOW>;
		};

		wifi2 {
			label = "green:wifi2";
			gpios = <&gpio 25 GPIO_ACTIVE_LOW>;
		};

		led_status: status {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio 27 GPIO_ACTIVE_LOW>;
		};
	};
};

&spi0 {
	status = "okay";

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

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

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

			partition@30000 {
				label = "config";
				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>;

					macaddr_factory_e000: macaddr@e000 {
						compatible = "mac-base";
						reg = <0xe000 0x6>;
						#nvmem-cell-cells = <1>;
					};
				};
			};

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

&sdhci {
	status = "okay";
};

&pcie {
	status = "okay";
};

&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";
		};

		port@4 {
			status = "okay";
			label = "wan";

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

&ethernet {
	pinctrl-0 = <&mdio_pins>, <&rgmii1_pins>;
};

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

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