// SPDX-License-Identifier: GPL-2.0-or-later
#include "mt7621.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	compatible = "snr,snr-cpe-me1", "mediatek,mt7621-soc";
	model = "SNR-CPE-ME1";

	aliases {
		label-mac-device = &gmac1;

		led-boot = &led_usb;
		led-failsafe = &led_vpn;
		led-running = &led_green;
		led-upgrade = &led_sys;
	};

	leds {
		compatible = "gpio-leds";

		led_usb: led-0 { // USB Activity
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_USB;
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>; // [JTAG] JTDO
		};

		led_vpn: led-1 { // VPN Activity
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_INDICATOR;
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>; // [JTAG] JTCLK
		};

		led_sys: led-2 { // System config
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 3 GPIO_ACTIVE_LOW>; // [I2C] I2C_SD
			panic-indicator;
		};

		led_green: led-3 { // ? LED
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_HEARTBEAT;
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>; // [JTAG] JTMS
		};
	};

	keys {
		compatible = "gpio-keys";

		reset {
			label = "Reset Button";
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>; // [JTAG] JTDI
			linux,code = <KEY_RESTART>;
		};
	};

	reg_usb_vbus: regulator {
		compatible = "regulator-fixed";
		regulator-name = "usb_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	reg_3p3v: regulator-3p3v {
		compatible = "regulator-fixed";
		regulator-name = "fixed-3.3V";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-boot-on;
		regulator-always-on;
	};
};

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

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

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

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

&pcie {
	status = "okay";
};

&pcie0 { // MT7603EN
	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 { // MT7610EN
	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>;
	};
};

&spi0 {
	status = "okay";

	flash@0 { // GD25Q128CSIG
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <44000000>; // 44 MHz

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

					eeprom_factory_0: eeprom@0 {
						reg = <0x0 0x400>;
					};

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

					macaddr_factory_e000: macaddr@e000 {
						reg = <0xe000 0x6>;
					};

					macaddr_factory_e006: macaddr@e006 {
						reg = <0xe006 0x6>;
					};
				};
			};

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

			partition@30001 {
				label = "uboot-env";
				reg = <0x30000 0x1000>;
			};
		};
	};
};

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

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

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

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

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

&xhci {
	vbus-supply = <&reg_usb_vbus>;
	vusb33-supply = <&reg_3p3v>;
};
