// SPDX-License-Identifier: GPL-2.0-only OR MIT

/dts-v1/;

#include "mt7981b.dtsi"

/ {
	aliases {
		label-mac-device = &wifi;
		led-boot = &led_status_blue;
		led-failsafe = &led_status_blue;
		led-running = &led_status_blue;
		led-upgrade = &led_status_blue;
		serial0 = &uart0;
	};

	chosen: chosen {
		stdout-path = "serial0:115200n8";
	};

	leds {
		compatible = "gpio-leds";

		led_status_blue: led-0 {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&pio 13 GPIO_ACTIVE_LOW>;
		};
	};

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

		button-0 {
			label = "reset";
			linux,code = <KEY_RESTART>;
			gpios = <&pio 11 GPIO_ACTIVE_LOW>;
		};

		button-1 {
			label = "mode";
			linux,code = <BTN_0>;
			linux,input-type = <EV_SW>;
			gpios = <&pio 25 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};
	};

	fan_5v: regulator-fan-5v {
		compatible = "regulator-fixed";
		regulator-name = "fan";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpios = <&pio 22 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		regulator-boot-on;
	};
};

&pwm {
	pinctrl-names = "default";
	pinctrl-0 = <&pwm_pins>;
	status = "okay";
};

&fan {
	pwms = <&pwm 0 40000 0>;
	fan-supply = <&fan_5v>;
	status = "okay";
};

&uart0 {
	status = "okay";
};

&watchdog {
	status = "okay";
};

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

	gmac0: mac@0 {
		compatible = "mediatek,eth-mac";
		reg = <0>;
		phy-mode = "sgmii";
		phy-handle = <&en8801sc>;
		nvmem-cells = <&macaddr_lan>;
		nvmem-cell-names = "mac-address";
		managed = "in-band-status";
	};

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

&mdio_bus {
	en8801sc: ethernet-phy@29 {
		compatible = "ethernet-phy-id03a2.9471";
		phy-mode = "sgmii";
		reg = <29>;
		reset-gpios = <&pio 39 GPIO_ACTIVE_LOW>;
		reset-assert-us = <10000>;
		reset-deassert-us = <20000>;
	};
};

&spi0 {
	pinctrl-names = "default";
	pinctrl-0 = <&spi0_flash_pins>;
	status = "okay";

	spi_nand: flash@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "spi-nand";
		reg = <0>;
		spi-max-frequency = <52000000>;
		spi-tx-bus-width = <4>;
		spi-rx-bus-width = <4>;

		spi-cal-enable;
		spi-cal-mode = "read-data";
		spi-cal-datalen = <7>;
		spi-cal-data = /bits/ 8 <0x53 0x50 0x49 0x4e 0x41 0x4e 0x44>;
		spi-cal-addrlen = <5>;
		spi-cal-addr = /bits/ 32 <0x0 0x0 0x0 0x0 0x0>;
	};
};

&pio {
	pwm_pins: pwm0-pins {
		mux {
			function = "pwm";
			groups = "pwm0_1";
		};
	};

	spi0_flash_pins: spi0-pins {
		mux {
			function = "spi";
			groups = "spi0", "spi0_wp_hold";
		};
	};
};

&usb_phy {
	status = "okay";
};

&xhci {
	status = "okay";
};

&wifi {
	status = "okay";
	nvmem-cells = <&eeprom_factory>;
	nvmem-cell-names = "eeprom";
};
