// 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 = "asus,rp-ac56", "mediatek,mt7621-soc";
	model = "Asus RP-AC56";

	aliases {
		led-boot = &led_power_orange;
		led-failsafe = &led_power_orange;
		led-running = &led_power_white;
		led-upgrade = &led_power_blue;
		label-mac-device = &gmac0;
	};

	leds {
		compatible = "gpio-leds";

		wlan2g_red {
			label = "red:wlan2g";
			gpios = <&gpio 16 GPIO_ACTIVE_HIGH>;
		};

		wlan2g_blue {
			label = "blue:wlan2g";
			gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
		};

		wlan2g_green {
			label = "green:wlan2g";
			gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "phy0tpt";
		};

		wlan5g_red {
			label = "red:wlan5g";
			gpios = <&gpio 45 GPIO_ACTIVE_HIGH>;
		};

		wlan5g_blue {
			label = "blue:wlan5g";
			gpios = <&gpio 43 GPIO_ACTIVE_HIGH>;
		};

		wlan5g_green {
			label = "green:wlan5g";
			gpios = <&gpio 44 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "phy1tpt";
		};

		led_power_white: power_white {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_WHITE>;
			gpios = <&gpio 48 GPIO_ACTIVE_HIGH>;
		};

		led_power_orange: power_orange {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_ORANGE>;
			gpios = <&gpio 47 GPIO_ACTIVE_HIGH>;
		};

		led_power_blue: power_blue {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio 46 GPIO_ACTIVE_HIGH>;
		};
	};

	keys {
		compatible = "gpio-keys";

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

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

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,name = "Audio-I2S";
		simple-audio-card,format = "i2s";
		simple-audio-card,bitclock-master = <&dailink0_master>;
		simple-audio-card,frame-master = <&dailink0_master>;
		simple-audio-card,routing =
			"Headphone Jack", "HP_L",
			"Headphone Jack", "HP_R";
		simple-audio-card,mclk-fs = <256>;

		simple-audio-card,cpu {
			sound-dai = <&i2s>;
		};

		dailink0_master: simple-audio-card,codec {
			sound-dai = <&codec>;
		};
	};
};

&gpio {
	status = "okay";
};

&spi0 {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <50000000>;
		m25p,fast-read;

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

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

			partition@30000 {
				label = "nvram";
				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 0x400>;
					};

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

					macaddr_factory_4: macaddr@4 {
						reg = <0x4 0x6>;
					};
				};
			};

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

			partition@ff0000 {
				label = "radio";
				reg = <0xff0000 0x10000>;
				read-only;
			};
		};
	};
};

&state_default {
	gpio {
		groups = "uart2";
		function = "gpio";
	};
};

&pinctrl {
	i2s_pins: i2s {
		i2s {
			groups = "uart3";
			function = "i2s";
		};
	};
};

&pcie {
	status = "okay";
};

&pcie0 {
	wifi@0,0 {
		compatible = "mediatek,mt76";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_0>;
		nvmem-cell-names = "eeprom";
		ieee80211-freq-limit = <2400000 2500000>;
	};
};

&pcie1 {
	wifi@0,0 {
		compatible = "mediatek,mt76";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&eeprom_factory_8000>;
		nvmem-cell-names = "eeprom";
		ieee80211-freq-limit = <5000000 6000000>;
	};
};

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

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

&xhci {
	status = "disabled";
};

&i2c {
	status = "okay";

	codec: wm8960@18 {
		#sound-dai-cells = <0>;
		compatible = "wlf,wm8960";
		reg = <0x18>;
		wlf,shared-lrclk;
	};
};

&gdma {
	status = "okay";
};

&i2s {
	#sound-dai-cells = <0>;
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2s_pins>;
};