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

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

/ {
	compatible = "teltonika,rut300", "teltonika,rut30x", "qca,qca9531";
	model = "TELTONIKA RUT300";

	aliases {
		label-mac-device = &eth1;
		led-boot = &led_wan;
		led-failsafe = &led_wan;
		led-running = &led_wan;
		led-upgrade = &led_wan;
		serial0 = &uart;
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pmx_leds_switch>, <&jtag_disable_pins>;

		led_wan: wan {
			function = LED_FUNCTION_WAN;
			color = <LED_COLOR_ID_YELLOW>;
			gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
		};

		lan1 {
			label = "yellow:lan1";
			gpios = <&gpio 4 GPIO_ACTIVE_HIGH>;
		};

		lan2 {
			label = "yellow:lan2";
			gpios = <&gpio 3 GPIO_ACTIVE_HIGH>;
		};

		lan3 {
			label = "yellow:lan3";
			gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
		};

		lan4 {
			label = "yellow:lan4";
			gpios = <&gpio 1 GPIO_ACTIVE_HIGH>;
		};
	};

	keys {
		compatible = "gpio-keys";

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

&spi {
	status = "okay";
	num-cs = <1>;

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

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

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

			config: partition@20000 {
				label = "config";
				reg = <0x020000 0x010000>;
				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@30000 {
				label = "art";
				reg = <0x030000 0x010000>;
				read-only;
			};

			partition@40000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x040000 0xf30000>;
			};

			partition@f70000 {
				label = "event-log";
				reg = <0xf70000 0x090000>;
			};
		};
	};
};

&usb0 {
	status = "okay";
};

&usb_phy {
	status = "okay";
};

&uart {
	status = "okay";
};

&eth0 {
	status = "okay";
	phy-handle = <&swphy0>;

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

&eth1 {
	phy-handle = <&swphy4>;
	nvmem-cells = <&macaddr_config_0 0>;
	nvmem-cell-names = "mac-address";

	gmac-config {
		device = <&gmac>;
		switch-phy-swap = <1>;
	};
};

&pinmux {
	pmx_leds_switch: leds_switch {
		// switch port LEDs on GPIO 0~4
		pinctrl-single,bits =	<0x0 0x00000000 0xffffffff>,
					<0x4 0x00000000 0x000000ff>;
	};
};
