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

#include "qca953x.dtsi"

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

/ {
	compatible = "joyit,jt-or750i", "qca,qca9531";
	model = "Joy-IT JT-OR750i";

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

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

	leds {
		compatible = "gpio-leds";

		pinctrl-names = "default";
		pinctrl-0 = <&jtag_disable_pins &pinmux_led_eth_pins>;

		led_status_green: status_green {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
			default-state = "on";
		};

		led_status_red: status_red {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_RED>;
			gpios = <&gpio 12 GPIO_ACTIVE_LOW>;
		};
	};
};

&pinmux {
	pinmux_led_eth_pins: pinmux_led_eth_pins {
		pinctrl-single,bits = \
			/* GPIO 4: LED_LINK_5 (WAN) */     \
			<0x04 0x0000002d 0x000000ff>,      \
			/* GPIO 14: LED_LINK_2 (LAN 3) */  \
			/* GPIO 15: LED_LINK_3 (LAN 2) */  \
			<0x0c 0x2b2a0000 0xffff0000>,      \
			/* GPIO 16: LED_LINK_4 (LAN 1) */  \
			<0x10 0x0000002c 0x000000ff>;
	};
};

&spi {
	status = "okay";

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

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

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

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

			partition@50000 {
				label = "firmware";
				reg = <0x50000 0xfa0000>;
				compatible = "denx,uimage";
			};

			art: partition@ff0000 {
				label = "art";
				reg = <0xff0000 0x10000>;
				read-only;

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

					macaddr_art_0: macaddr@0 {
						reg = <0x0 0x6>;
					};

					macaddr_art_6: macaddr@6 {
						reg = <0x6 0x6>;
					};

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

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

&eth0 {
	status = "okay";

	phy-handle = <&swphy4>;

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

&eth1 {
	nvmem-cells = <&macaddr_art_6>;
	nvmem-cell-names = "mac-address";
};

&pcie0 {
	status = "okay";

	wifi@0,0 {
		compatible = "qcom,ath10k";
		reg = <0x0000 0 0 0 0>;
		nvmem-cells = <&cal_art_5000>;
		nvmem-cell-names = "calibration";
	};
};

&wmac {
	status = "okay";

	nvmem-cells = <&cal_art_1000>;
	nvmem-cell-names = "calibration";
};