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

/ {
	aliases {
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
	};

	/* NAND flash is devided by half for failover.
	Bootloader dynamically pass which partition to boot,
	we can't change CONFIG_MIPS_CMDLINE_FROM_DTB, so
	cmdline have to be hardcoded to second partition */

	chosen {
		bootargs = "console=ttyS0,115200n8 ubi.mtd=rutos-b";
	};

	keys {
		compatible = "gpio-keys";

		reset {
			label = "reset";
			linux,code = <KEY_RESTART>;
			gpios = <&gpio 10 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led_power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
		};
	};
};

&spi0 {
	status = "okay";

	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;

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

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

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

			partition@90000 {
				label = "config";
				reg = <0x90000 0x10000>;
				read-only;

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

					macaddr_config_0: macaddr@0 {
						compatible = "mac-base";
						reg = <0x0 0x6>;
						#nvmem-cell-cells = <1>;
					};
				};
			};

			partition@a0000 {
				label = "bootconfig-a";
				reg = <0xa0000 0x10000>;
			};

			partition@b0000 {
				label = "bootconfig-b";
				reg = <0xb0000 0x10000>;
			};

			partition@c0000 {
				label = "factory";
				reg = <0xc0000 0x10000>;
				read-only;

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

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

			partition@d0000 {
				label = "event-log";
				reg = <0xd0000 0x90000>;
			};

			partition@400000 {
				label = "recovery";
				reg = <0x200000 0xe00000>;
			};
		};
	};

	flash@1 {
		compatible = "spi-nand";
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <1>;
		spi-max-frequency = <24000000>;

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

			partition@0 {
				label = "rutos-a";
				reg = <0x00000000 0x08000000>;
			};

			partition@8000000 {
				label = "rutos-b";
				reg = <0x08000000 0x08000000>;
			};
		};
	};
};

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

&gmac1 {
	status = "okay";
	label = "wan";
	phy-handle = <&ethphy4>;
	nvmem-cells = <&macaddr_config_0 1>;
	nvmem-cell-names = "mac-address";
};

&state_default {
	gpio {
		groups = "wdt", "jtag", "sdhci", "uart2", "uart3";
		function = "gpio";
	};
};

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