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

/dts-v1/;

#include "ipq6018.dtsi"
#include "ipq6018-common.dtsi"
#include "ipq6018-ess.dtsi"
#include "ipq6018-nss.dtsi"

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

/ {
	model = "JDCloud RE-CS-02";
	compatible = "jdcloud,re-cs-02", "qcom,ipq6018";

	aliases {
		serial0 = &blsp1_uart3;
		serial1 = &blsp1_uart6;

		led-boot = &led_status_blue;
		led-failsafe = &led_status_red;
		led-running = &led_status_green;
		led-upgrade = &led_status_red;

		ethernet0 = &dp1;
		ethernet1 = &dp2;
		ethernet2 = &dp3;
		ethernet3 = &dp4;
		ethernet4 = &dp5;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	keys {
		compatible = "gpio-keys";

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

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

		screen {
			label = "screen";
			linux,code = <BTN_1>;
			gpios = <&tlmm 71 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		compatible = "gpio-leds";

		led_status_red: status-red {
			label = "red:status";
			gpios = <&tlmm 57 GPIO_ACTIVE_HIGH>;
		};

		led_status_green: status-green {
			label = "green:status";
			gpios = <&tlmm 58 GPIO_ACTIVE_HIGH>;
		};

		led_status_blue: status-blue {
			label = "blue:status";
			gpios = <&tlmm 79 GPIO_ACTIVE_HIGH>;
		};
	};
};

&tlmm {
	gpio-reserved-ranges = <20 1>;

	btuart_pins: btuart-pins {
		mux {
			pins = "gpio48", "gpio49";
			function = "blsp5_uart";
			drive-strength = <8>;
			bias-pull-up;
		};
	};

	tmp1628_pins: tmp1628-pins {
		mux {
			pins = "gpio69", "gpio70", "gpio73", "gpio74";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-down;
		};
	};

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

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

	usb_pwr_pins: usb-pwr-pins {
		mux {
			pins = "gpio22";
			function = "gpio";
			bias-pull-down;
			output-high;
		};
	};
};

&blsp1_uart6 {
	status = "okay";

	pinctrl-0 = <&btuart_pins>;
	pinctrl-names = "default";
};

&sdhc {
	status = "okay";

	/delete-property/ mmc-hs400-1_8v;
	mmc-ddr-1_8v;
	mmc-hs200-1_8v;
};

&pcie0 {
	status = "okay";
	perst-gpios = <&tlmm 53 GPIO_ACTIVE_LOW>;

	bridge@0,0 {
		reg = <0x00000000 0 0 0 0>;
		#address-cells = <3>;
		#size-cells = <2>;
		ranges;

		wifi@1,0 {
			status = "okay";

			compatible = "pci17cb,1104";
			qcom,ath11k-fw-memory-mode = <1>;
			qcom,ath11k-calibration-variant = "JDC-RE-CS-02";
			reg = <0x00010000 0 0 0 0>;
		};
	};
};

&mdio {
	status = "okay";

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

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

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

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

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

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

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

&switch {
	status = "okay";

	switch_lan_bmp = <(ESS_PORT1 | ESS_PORT2 | ESS_PORT3 | ESS_PORT4)>;
	switch_wan_bmp = <ESS_PORT5>;
	switch_mac_mode = <MAC_MODE_PSGMII>;
	switch_mac_mode1 = <MAC_MODE_SGMII_PLUS>;

	qcom,port_phyinfo {
		port@1 {
			port_id = <1>;
			phy_address = <24>;
		};

		port@2 {
			port_id = <2>;
			phy_address = <25>;
		};

		port@3 {
			port_id = <3>;
			phy_address = <26>;
		};

		port@4 {
			port_id = <4>;
			phy_address = <27>;
		};

		port@5 {
			port_id = <5>;
			phy_address = <12>;
			port_mac_sel = "QGMAC_PORT";
		};
	};
};

&wifi {
	status = "okay";
	qcom,ath11k-fw-memory-mode = <1>;
	qcom,ath11k-calibration-variant = "JDC-RE-CS-02";
};

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

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

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

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

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

&usb3 {
	status = "okay";
	pinctrl-0 = <&usb_pwr_pins>;
	pinctrl-names = "default";
};

&edma {
	status = "okay";
};
