// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/* Copyright (c) 2023, Chukun Pan <amadeus@jmu.edu.cn> */

/dts-v1/;

#include "ipq8074.dtsi"
#include "ipq8074-hk-cpu.dtsi"
#include "ipq8074-ess.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	model = "Arcadyan AW1000";
	compatible = "arcadyan,aw1000", "qcom,ipq8074";

	aliases {
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
		serial0 = &blsp1_uart5;
		/*
		 * Aliases as required by u-boot
		 * to patch MAC addresses
		 */
		ethernet0 = &dp1;
		ethernet1 = &dp2;
		ethernet2 = &dp3;
		ethernet3 = &dp4;
		ethernet4 = &dp6_syn;
		label-mac-device = &dp1;
	};

	chosen {
		stdout-path = "serial0:115200n8";
		bootargs-append = " root=/dev/ubiblock0_1";
	};

	gpio-export {
		compatible = "gpio-export";

		lte-pwrkey {
			gpio-export,name = "lte_pwrkey";
			gpio-export,output = <1>;
			gpios = <&tlmm 54 GPIO_ACTIVE_HIGH>;
		};

		lte-power {
			gpio-export,name = "lte_power";
			gpio-export,output = <1>;
			gpios = <&tlmm 30 GPIO_ACTIVE_HIGH>;
		};

		lte-reset {
			gpio-export,name = "lte_reset";
			gpio-export,output = <1>;
			gpios = <&tlmm 63 GPIO_ACTIVE_HIGH>;
		};
	};

	keys {
		compatible = "gpio-keys";

		wlan {
			label = "wlan";
			linux,code = <KEY_WLAN>;
			gpios = <&tlmm 2 GPIO_ACTIVE_LOW>;
		};

		wps {
			label = "wps";
			linux,code = <KEY_WPS_BUTTON>;
			gpios = <&tlmm 62 GPIO_ACTIVE_LOW>;
		};

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

	led-spi {
		compatible = "spi-gpio";
		#address-cells = <1>;
		#size-cells = <0>;

		sck-gpios = <&tlmm 18 GPIO_ACTIVE_HIGH>;
		mosi-gpios = <&tlmm 19 GPIO_ACTIVE_HIGH>;

		led_gpio: led-gpio@0 {
			compatible = "fairchild,74hc595";
			reg = <0>;
			gpio-controller;
			#gpio-cells = <2>;
			registers-number = <2>;
			spi-max-frequency = <1000000>;
			enable-gpios = <&tlmm 20 GPIO_ACTIVE_HIGH>;
		};
	};

	leds {
		compatible = "gpio-leds";

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

		wifi {
			label = "green:wifi";
			gpios = <&led_gpio 1 GPIO_ACTIVE_HIGH>;
		};

		internet {
			label = "green:internet";
			gpios = <&led_gpio 2 GPIO_ACTIVE_HIGH>;
		};

		5g-red {
			label = "red:5g";
			gpios = <&led_gpio 3 GPIO_ACTIVE_LOW>;
		};

		5g-green {
			label = "green:5g";
			gpios = <&led_gpio 4 GPIO_ACTIVE_LOW>;
		};

		5g-blue {
			label = "blue:5g";
			gpios = <&led_gpio 5 GPIO_ACTIVE_LOW>;
		};

		signal-red {
			label = "red:signal";
			gpios = <&led_gpio 6 GPIO_ACTIVE_LOW>;
		};

		signal-green {
			label = "green:signal";
			gpios = <&led_gpio 8 GPIO_ACTIVE_LOW>;
		};

		signal-blue {
			label = "blue:signal";
			gpios = <&led_gpio 9 GPIO_ACTIVE_LOW>;
		};

		phone {
			label = "green:phone";
			gpios = <&led_gpio 11 GPIO_ACTIVE_HIGH>;
		};
	};

	usb_vbus: regulator-usb-vbus {
		compatible = "regulator-fixed";
		regulator-name = "usb_vbus";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&tlmm 9 GPIO_ACTIVE_LOW>;
		regulator-boot-on;
	};
};

&tlmm {
	mdio_pins: mdio-pins {
		mdc {
			pins = "gpio68";
			function = "mdc";
			drive-strength = <8>;
			bias-pull-up;
		};

		mdio {
			pins = "gpio69";
			function = "mdio";
			drive-strength = <8>;
			bias-pull-up;
		};
	};
};

&blsp1_uart5 {
	status = "okay";
};

&cryptobam {
	status = "okay";
};

&crypto {
	status = "okay";
};

&prng {
	status = "okay";
};

&qpic_bam {
	status = "okay";
};

&qpic_nand {
	status = "okay";

	nand@0 {
		reg = <0>;
		nand-ecc-strength = <8>;
		nand-ecc-step-size = <512>;
		nand-bus-width = <8>;

		partitions {
			compatible = "qcom,smem-part";
		};
	};
};

&qusb_phy_0 {
	status = "okay";
};

&qusb_phy_1 {
	status = "okay";

	vdd-supply = <&usb_vbus>;
};

&ssphy_0 {
	status = "okay";
};

&ssphy_1 {
	status = "okay";
};

&usb_0 {
	status = "okay";
};

&usb_1 {
	status = "okay";
};

&mdio {
	status = "okay";

	pinctrl-0 = <&mdio_pins>;
	pinctrl-names = "default";
	reset-gpios = <&tlmm 37 GPIO_ACTIVE_LOW>;

	ethernet-phy-package@0 {
		compatible = "qcom,qca8075-package";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0>;

		qcom,package-mode = "qsgmii";

		qca8075_0: ethernet-phy@0 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <0>;
		};

		qca8075_1: ethernet-phy@1 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <1>;
		};

		qca8075_2: ethernet-phy@2 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <2>;
		};

		qca8075_3: ethernet-phy@3 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <3>;
		};
	};

	qca8081: ethernet-phy@28 {
		compatible = "ethernet-phy-id004d.d101";
		reg = <28>;
		reset-deassert-us = <10000>;
		reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>;

		leds {
			#address-cells = <1>;
			#size-cells = <0>;

			led@2 {
				reg = <2>;
				active-low;
				color = <LED_COLOR_ID_GREEN>;
				function = LED_FUNCTION_WAN;
				default-state = "keep";
			};
		};
	};
};

&switch {
	status = "okay";

	switch_lan_bmp = <(ESS_PORT1 | ESS_PORT2 | ESS_PORT3 | ESS_PORT4)>; /* lan port bitmap */
	switch_wan_bmp = <ESS_PORT6>; /* wan port bitmap */
	switch_mac_mode = <MAC_MODE_QSGMII>; /* mac mode for uniphy instance0*/
	switch_mac_mode2 = <MAC_MODE_SGMII_PLUS>; /* mac mode for uniphy instance2*/

	qcom,port_phyinfo {
		port@1 {
			port_id = <1>;
			phy_address = <0>;
		};
		port@2 {
			port_id = <2>;
			phy_address = <1>;
		};
		port@3 {
			port_id = <3>;
			phy_address = <2>;
		};
		port@4 {
			port_id = <4>;
			phy_address = <3>;
		};
		port@6 {
			port_id = <6>;
			phy_address = <28>;
			port_mac_sel = "QGMAC_PORT";
		};
	};
};

&edma {
	status = "okay";
};

&dp1 {
	status = "okay";
	phy-mode = "qsgmii";
	phy-handle = <&qca8075_0>;
	label = "lan1";
};

&dp2 {
	status = "okay";
	phy-mode = "qsgmii";
	phy-handle = <&qca8075_1>;
	label = "lan2";
};

&dp3 {
	status = "okay";
	phy-mode = "qsgmii";
	phy-handle = <&qca8075_2>;
	label = "lan3";
};

&dp4 {
	status = "okay";
	phy-mode = "qsgmii";
	phy-handle = <&qca8075_3>;
	label = "lan4";
};

&dp6_syn {
	status = "okay";
	phy-handle = <&qca8081>;
	label = "wan";
};

&wifi {
	status = "okay";

	qcom,ath11k-calibration-variant = "Arcadyan-AW1000";
};
