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

/dts-v1/;
#include "mt7981.dtsi"

/ {
	model = "Ubiquiti UniFi 6 Plus";
	compatible = "ubnt,unifi-6-plus", "mediatek,mt7981";

	aliases {
		serial0 = &uart0;
		led-boot = &led_white;
		led-failsafe = &led_white;
		led-running = &led_blue;
		led-upgrade = &led_blue;
		label-mac-device = &gmac1;
	};

	chosen {
		bootargs-override = "console=ttyS0,115200n8 rootwait root=/dev/mmcblk0p7";
		stdout-path = "serial0:115200n8";
	};

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

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


	leds {
		compatible = "gpio-leds";

		led_blue: dome-blue {
			label = "blue:dome";
			gpios = <&pio 9 GPIO_ACTIVE_HIGH>;
		};

		led_white: dome-white {
			label = "white:dome";
			gpios = <&pio 34 GPIO_ACTIVE_HIGH>;
		};
	};
};

&uart0 {
	status = "okay";
};

&watchdog {
	status = "okay";
};

&pio {
	spi2_flash_pins: spi2-pins {
		mux {
			function = "spi";
			groups = "spi2", "spi2_wp_hold";
		};

		conf-pu {
			pins = "SPI2_CS", "SPI2_HOLD", "SPI2_WP";
			drive-strength = <8>;
			bias-pull-up = <103>;
		};

		conf-pd {
			pins = "SPI2_CLK", "SPI2_MOSI", "SPI2_MISO";
			drive-strength = <8>;
			bias-pull-down = <103>;
		};
	};

	mmc0_pins_default: mmc0-pins-default {
		mux {
			function = "flash";
			groups = "emmc_45";
		};
	};

	mmc0_pins_uhs: mmc0-pins-uhs {
		mux {
			function = "flash";
			groups = "emmc_45";
		};
	};
};

&spi2 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi2_flash_pins>;
	status = "okay";

	flash@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "jedec,spi-nor";
		reg = <0>;

		spi-max-frequency = <52000000>;
		spi-tx-bus-width = <4>;
		spi-rx-bus-width = <4>;

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

			eeprom: partition@00000 {
				label = "EEPROM";
				reg = <0x00000 0x10000>;
				read-only;

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

					macaddr_eeprom_0: macaddr@0 {
						reg = <0x0 0x6>;
					};

					macaddr_eeprom_6: macaddr@6 {
						reg = <0x6 0x6>;
					};
				};
			};

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

&mmc0 {
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc0_pins_default>;
	pinctrl-1 = <&mmc0_pins_uhs>;
	bus-width = <8>;
	max-frequency = <52000000>;
	cap-mmc-highspeed;
	vmmc-supply = <&reg_3p3v>;
	non-removable;
	status = "okay";
};

&eth {
	pinctrl-names = "default";
	pinctrl-0 = <&mdio_pins>;
	status = "okay";

	gmac1: mac@1 {
		compatible = "mediatek,eth-mac";
		reg = <1>;
		phy-mode = "gmii";
		phy-handle = <&int_gbe_phy>;
		nvmem-cell-names = "mac-address";
		nvmem-cells = <&macaddr_eeprom_0>;
	};
};

&wifi {
	status = "okay";
};
