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

/dts-v1/;

#include "mt7981.dtsi"

/ {
	model = "NRadio C8-668GL";
	compatible = "nradio,c8-668gl", "mediatek,mt7981";

	aliases {
		ethernet0 = &gmac0;
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
		serial0 = &uart0;
	};

	chosen {
		stdout-path = "serial0:115200n1";
		/* If official system version < 1.9.2.n6.c3, use root=PARTLABEL=rootfs */
		bootargs = "console=ttyS0,115200n1 root=PARTLABEL=rootfs_2nd rootwait";
	};

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

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

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

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

		cpepower {
			gpio-export,name = "cpe-pwr";
			gpio-export,output = <0>;
			gpios = <&pio 31 GPIO_ACTIVE_LOW>;
		};

		cpesel0 {
			gpio-export,name = "cpe-sel0";
			gpio-export,output = <1>;
			gpios = <&pio 30 GPIO_ACTIVE_HIGH>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led_power: power {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_POWER;
			gpios = <&pio 10 GPIO_ACTIVE_LOW>;
		};

		led-cellular-5g {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <0>;
			gpios = <&pio 11 GPIO_ACTIVE_LOW>;
		};

		led-cellular-4g {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <1>;
			gpios = <&pio 12 GPIO_ACTIVE_LOW>;
		};

		led-wifi {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_WLAN;
			gpios = <&pio 13 GPIO_ACTIVE_LOW>;
		};
	};
};

&uart0 {
	status = "okay";
};

&watchdog {
	status = "okay";
};

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

	card@0 {
		compatible = "mmc-card";
		reg = <0>;

		block {
			compatible = "block-device";
			partitions {
				block-partition-env {
					partname = "u-boot-env";

					nvmem-layout {
						compatible = "u-boot,env";
					};
				};

				block-partition-factory {
					partname = "factory";

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

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

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

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

&eth {
	status = "okay";

	gmac0: mac@0 {
		compatible = "mediatek,eth-mac";
		reg = <0>;
		phy-mode = "2500base-x";

		fixed-link {
			speed = <2500>;
			full-duplex;
			pause;
		};
	};

	gmac1: mac@1 {
		compatible = "mediatek,eth-mac";
		reg = <1>;
		phy-mode = "2500base-x";
		phy-handle = <&phy21>;
	};

	mdio: mdio-bus {
		#address-cells = <1>;
		#size-cells = <0>;

		phy5: ethernet-phy@5 {
			compatible = "ethernet-phy-ieee802.3-c45";
			reg = <5>;
			reset-gpios = <&pio 7 GPIO_ACTIVE_LOW>;
			reset-assert-us = <600>;
			reset-deassert-us = <20000>;
		};

		phy21: ethernet-phy@21 {
			compatible = "ethernet-phy-ieee802.3-c45";
			reg = <21>;
			reset-gpios = <&pio 8 GPIO_ACTIVE_LOW>;
			reset-assert-us = <600>;
			reset-deassert-us = <20000>;
		};

		switch@1f {
			compatible = "mediatek,mt7531";
			reg = <31>;
			reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;
			interrupt-controller;
			#interrupt-cells = <1>;
			interrupt-parent = <&pio>;
			interrupts = <38 IRQ_TYPE_LEVEL_HIGH>;

			ports {
				#address-cells = <1>;
				#size-cells = <0>;

				port@1 {
					reg = <1>;
					label = "lan1";
				};

				port@2 {
					reg = <2>;
					label = "lan2";
				};

				port@3 {
					reg = <3>;
					label = "lan3";
				};

				port@5 {
					reg = <5>;
					label = "lan4";
					phy-mode = "2500base-x";
					phy-handle = <&phy5>;
				};

				port@6 {
					reg = <6>;
					label = "cpu";
					ethernet = <&gmac0>;
					phy-mode = "2500base-x";

					fixed-link {
						speed = <2500>;
						full-duplex;
						pause;
					};
				};
			};
		};
	};
};

&usb_phy {
	status = "okay";
};

&xhci {
	status = "okay";
};

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