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

#include "qca956x.dtsi"

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

/ {
	compatible = "tplink,tl-wdr6500-v2", "qca,qca9561";
	model = "TP-Link TL-WDR6500 v2";

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

	keys {
		compatible = "gpio-keys";

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

	leds {
		compatible = "gpio-leds";

		lan4 {
			label = "green:lan4";
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
		};

		lan3 {
			label = "green:lan3";
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
		};

		lan2 {
			label = "green:lan2";
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
		};

		lan1 {
			label = "green:lan1";
			gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
		};

		wan {
			function = LED_FUNCTION_WAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
		};

		led_system: system {
			label = "white:system";
			gpios = <&gpio 21 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};
	};
};

&spi {
	status = "okay";

	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 0x010000>;
				read-only;

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

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

			partition@10000 {
				compatible = "tplink,firmware";
				label = "firmware";
				reg = <0x010000 0x7e0000>;
			};

			partition@7f0000 {
				label = "art";
				reg = <0x7f0000 0x010000>;
				read-only;

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

					calibration_ath9k: calibration@1000 {
						reg = <0x1000 0x440>;
					};

					calibration_ath10k: calibration@5000 {
						reg = <0x5000 0x844>;
					};
				};
			};
		};
	};
};

&uart {
	status = "okay";
};

&pcie {
	status = "okay";

	wifi@0,0 {
		compatible = "qcom,ath10k";
		reg = <0 0 0 0 0>;

		nvmem-cells = <&macaddr_uboot_fc00 (-2)>, <&calibration_ath10k>;
		nvmem-cell-names = "mac-address", "calibration";
	};
};

&mdio0 {
	status = "okay";
};

&eth0 {
	status = "okay";

	phy-handle = <&swphy4>;

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

&eth1 {
	status = "okay";

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

&wmac {
	status = "okay";

	nvmem-cells = <&macaddr_uboot_fc00 (-1)>, <&calibration_ath9k>;
	nvmem-cell-names = "mac-address", "calibration";
};

&usb0 {
	status = "okay";
};

&usb_phy0 {
	status = "okay";
};
