/dts-v1/;

#include "ipq5018.dtsi"
#include "ipq5018-ess.dtsi"
#include "ipq5018-mx-base.dtsi"

/ {
	model = "Linksys MR5500";
	compatible = "linksys,mr5500", "qcom,ipq5018";

	chosen {
		bootargs-append = " root=/dev/ubiblock0_0 coherent_pool=2M";
		stdout-path = "serial0:115200n8";
	};

	gpio-leds {
		compatible = "gpio-leds";

		usb {
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_USB;
			gpios = <&tlmm 19 GPIO_ACTIVE_HIGH>;
			trigger-sources = <&usb_port1>;
			linux,default-trigger = "usbport";
		};
	};

	regulator_fixed_5p0: regulator-s0500 {
		compatible = "regulator-fixed";
		regulator-min-microvolt = <500000>;
		regulator-max-microvolt = <500000>;
		regulator-name = "fixed_5p0";
		gpios = <&tlmm 17 GPIO_ACTIVE_LOW>;
	};
};

/*
 * ===============================================================
 *     _______________________         _______________________
 *    |        IPQ5018        |       |        QCA8337        |
 *    | +------+   +--------+ |       | +--------+   +------+ |
 *    | | MAC0 |---| GE Phy | |       | |  Phy0  |---| MAC1 | |
 *    | +------+   +--------+ |       | +--------+   +------+ |
 *    | +------+   +--------+ |       | +--------+   +------+ |
 *    | | MAC1 |---| Uniphy |-+-SGMII-+-| SerDes |---| MAC6 | |
 *    | +------+   +--------+ |       | +--------+   +------+ |
 *    |_______________________|       |_______________________|
 *
 * ===============================================================
 */

&uniphy0 {
	status = "okay";

	assigned-clocks = <&uniphy0 UNIPHY_CLK_REF>;
	assigned-clock-rates = <UNIPHY_REFCLK_25MHZ>;
};

// MAC1 ---SGMII---> QCA8337 SerDes
&gmac1 {
	status = "okay";

	phy-mode = "sgmii";

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

	fixed-link {
		speed = <1000>;
		full-duplex;
	};
};

&mdio0 {
	status = "okay";
};

&mdio1 {
	status = "okay";

	pinctrl-0 = <&mdio1_pins>;
	pinctrl-names = "default";
	reset-gpios = <&tlmm 39 GPIO_ACTIVE_LOW>;

	switch1: ethernet-switch@17 {
		compatible = "qca,qca8337";
		reg = <17>;
		#address-cells = <1>;
		#size-cells = <0>;

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

			port@1 {
				reg = <1>;
				label = "lan1";
				phy-handle = <&qca8337_0>;
				phy-mode = "internal";

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

					led@0 {
						reg = <0>;
						color = <LED_COLOR_ID_GREEN>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};

					led@1 {
						reg = <1>;
						color = <LED_COLOR_ID_AMBER>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};
				};
			};

			port@2 {
				reg = <2>;
				label = "lan2";
				phy-handle = <&qca8337_1>;
				phy-mode = "internal";

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

					led@0 {
						reg = <0>;
						color = <LED_COLOR_ID_GREEN>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};

					led@1 {
						reg = <1>;
						color = <LED_COLOR_ID_AMBER>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};
				};
			};

			port@3 {
				reg = <3>;
				label = "lan3";
				phy-handle = <&qca8337_2>;
				phy-mode = "internal";

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

					led@0 {
						reg = <0>;
						color = <LED_COLOR_ID_GREEN>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};

					led@1 {
						reg = <1>;
						color = <LED_COLOR_ID_AMBER>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};
				};
			};

			port@4 {
				reg = <4>;
				label = "lan4";
				phy-handle = <&qca8337_3>;
				phy-mode = "internal";

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

					led@0 {
						reg = <0>;
						color = <LED_COLOR_ID_GREEN>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};

					led@1 {
						reg = <1>;
						color = <LED_COLOR_ID_AMBER>;
						function = LED_FUNCTION_LAN;
						default-state = "keep";
					};
				};
			};

			port@5 {
				reg = <5>;
				label = "wan";
				phy-handle = <&qca8337_4>;
				phy-mode = "internal";

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

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

					led@1 {
						reg = <1>;
						color = <LED_COLOR_ID_AMBER>;
						function = LED_FUNCTION_WAN;
						default-state = "keep";
					};
				};
			};

			port@6 {
				reg = <6>;
				label = "cpu";
				phy-mode = "sgmii";
				ethernet = <&gmac1>;
				qca,sgmii-enable-pll;

				fixed-link {
					speed = <1000>;
					full-duplex;
				};
			};
		};

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

			// QCA8337 Phy0 -> LAN1
			qca8337_0: ethernet-phy@0 {
				reg = <0>;
			};

			// QCA8337 Phy1 -> LAN2
			qca8337_1: ethernet-phy@1 {
				reg = <1>;
			};

			// QCA8337 Phy2 -> LAN3
			qca8337_2: ethernet-phy@2 {
				reg = <2>;
			};

			// QCA8337 Phy3 -> LAN4
			qca8337_3: ethernet-phy@3 {
				reg = <3>;
			};

			// QCA8337 Phy4 -> WAN
			qca8337_4: ethernet-phy@4 {
				reg = <4>;
			};
		};
	};
};

&usbphy0 {
	status = "okay";

	vdd-supply = <&regulator_fixed_5p0>;
};

&usb {
	status = "okay";

	vbus-supply = <&regulator_fixed_5p0>;
};

&usb_dwc {
	#address-cells = <1>;
	#size-cells = <0>;
	dr_mode = "host";

	usb_port1: port@1 {
		reg = <1>;
		#trigger-source-cells = <0>;
	};
};

&pcie0_phy {
	status = "okay";
};

&pcie0 {
	status = "okay";

	perst-gpios = <&tlmm 15 GPIO_ACTIVE_LOW>;

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

			/* QCN9074: ath11k lacks DT compatible for PCI cards */
			compatible = "pci17cb,1104";
			reg = <0x00010000 0 0 0 0>;

			qcom,ath11k-calibration-variant = "Linksys-MR5500";
		};
	};
};

&q6v5_wcss {
	firmware-name = "ath11k/IPQ5018/hw1.0/q6_fw.mdt",
			"ath11k/IPQ5018/hw1.0/m3_fw.mdt";
};

&wifi {
	status = "okay";

	qcom,rproc = <&q6v5_wcss>;
	qcom,ath11k-calibration-variant = "Linksys-MR5500";
	qcom,ath11k-fw-memory-mode = <1>;
};
