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

/ {
	model = "D-Link DAP-1720 A1";
	compatible = "dlink,dap-1720-a1", "qca,qca9563";

	aliases {
		led-boot = &led_status_green;
		led-failsafe = &led_status_red;
		led-running = &led_status_green;
		led-upgrade = &led_status_red;

		label-mac-device = &eth0;
	};

	keys {
		compatible = "gpio-keys";

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

		button-wps {
			label = "wps";
			gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WPS_BUTTON>;
			debounce-interval = <60>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led_status_red: led-status-red {
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
			panic-indicator;
		};

		led_status_green: led-status-green {
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 6 GPIO_ACTIVE_LOW>;
			default-state = "on";
		};

		led-rssi-middle {
			color = <LED_COLOR_ID_GREEN>;
			function = "signal"; //LED_FUNCTION_SIGNAL;
			function-enumerator = <2>;
			gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
		};

		led-rssi-top {
			color = <LED_COLOR_ID_GREEN>;
			function = "signal"; //LED_FUNCTION_SIGNAL;
			function-enumerator = <3>;
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
		};

		led-rssi-bottom-green {
			color = <LED_COLOR_ID_GREEN>;
			function = "signal"; //LED_FUNCTION_SIGNAL;
			function-enumerator = <1>;
			gpios = <&gpio 19 GPIO_ACTIVE_LOW>;
		};

		led-rssi-bottom-red {
			color = <LED_COLOR_ID_RED>;
			function = "signal"; //LED_FUNCTION_SIGNAL;
			function-enumerator = <1>;
			gpios = <&gpio 20 GPIO_ACTIVE_LOW>;
		};
	};
};

&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"; // vendor calls it `bootloader`
				reg = <0x000000 0x40000>;
				read-only;
			};

			partition@40000 {
				compatible = "u-boot,env";
				label = "u-boot-env"; // vendor calls it `bdcfg`
				reg = <0x040000 0x10000>;
				read-only;
			};

			partition@50000 {
				label = "devdata";
				reg = <0x050000 0x10000>;
				read-only;

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

					macaddr_ath10k: macaddr@94 {
						compatible = "mac-base";
						reg = <0x94 0x11>;
						#nvmem-cell-cells = <1>;
					};

					macaddr_ath9k: macaddr@b0 {
						compatible = "mac-base";
						reg = <0xb0 0x11>;
						#nvmem-cell-cells = <1>;
					};

					macaddr_lan: macaddr@c9 {
						compatible = "mac-base";
						reg = <0xc9 0x11>;
						#nvmem-cell-cells = <1>;
					};
				};
			};

			partition@60000 {
				label = "devconf";
				reg = <0x060000 0x10000>;
				read-only;
			};

			partition@70000 {
				compatible = "seama";
				label = "firmware";
				reg = <0x070000 0xf80000>;
			};

			partition@ff0000 {
				label = "art"; // vendor calls it `radiocfg`
				reg = <0xff0000 0x010000>;
				read-only;

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

					cal_ath9k: cal@1000 {
						reg = <0x1000 0x440>;
					};

					cal_ath10k: cal@5000 {
						reg = <0x5000 0x844>;
					};
				};
			};
		};
	};
};

&mdio0 {
	status = "okay";

	phy0: ethernet-phy@0 {
		reg = <0>;
		reset-gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
	};
};

&eth0 {
	status = "okay";

	phy-handle = <&phy0>;
	phy-mode = "sgmii";

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

&pcie {
	status = "okay";

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

		nvmem-cells = <&cal_ath10k>, <&macaddr_ath10k 0>;
		nvmem-cell-names = "calibration", "mac-address";
	};
};

&wmac {
	status = "okay";

	nvmem-cells = <&cal_ath9k>, <&macaddr_ath9k 0>;
	nvmem-cell-names = "calibration", "mac-address";
};
