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

#include "qcom-ipq8064-v2.0-smb208.dtsi"

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

/ {
	model = "Ruijie RG-MTFi-M520";
	compatible = "ruijie,rg-mtfi-m520", "qcom,ipq8064";

	memory@0 {
		reg = <0x42000000 0x7e000000>;
		device_type = "memory";
	};

	aliases {
		mdio-gpio0 = &mdio0;
		sdcc1 = &sdcc1;

		led-boot = &led_sys;
		led-failsafe = &led_sys;
		led-running = &led_sys;
		led-upgrade = &led_sys;
	};

	chosen {
		bootargs = "root=/dev/mmcblk0p3 rootfstype=squashfs,ext4 rootwait noinitrd";
	};

	leds {
		compatible = "gpio-leds";

		led_sys: sys {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio_ext 15 GPIO_ACTIVE_LOW>;
		};
	};

	keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&button_pins>;
		pinctrl-names = "default";

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

&qcom_pinmux {
	button_pins: button_pins {
		mux {
			pins = "gpio54";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};
	};

	mdio0_pins: mdio0-state {
		/delete-property/ pins;
		/delete-property/ function;
		/delete-property/ drive-strength;
		/delete-property/ bias-disable;

		clk {
			pins = "gpio1";
			input-disable;
		};
	};

	rgmii2_pins: rgmii2-state {
		/delete-property/ pins;
		/delete-property/ function;
		/delete-property/ drive-strength;
		/delete-property/ bias-disable;

		mux {
			pins = "gpio27", "gpio28", "gpio29",
			       "gpio30", "gpio31", "gpio32",
			       "gpio51", "gpio52", "gpio59",
			       "gpio60", "gpio61", "gpio62";
			function = "rgmii2";
			drive-strength = <8>;
			bias-disable;
		};

		tx {
			pins = "gpio27", "gpio28", "gpio29", "gpio30", "gpio31", "gpio32";
			input-disable;
		};
	};

	sdcc1_pins: sdcc1_pinmux {
		mux {
			pins =	"gpio38", "gpio39", "gpio40", "gpio41", "gpio42",
				"gpio43", "gpio44", "gpio45", "gpio46", "gpio47";
			function = "sdc1";
		};

		cmd {
			pins = "gpio45";
			drive-strength = <10>;
			bias-pull-up;
		};

		data {
			pins =	"gpio38", "gpio39", "gpio40", "gpio41",
				"gpio43", "gpio44", "gpio46", "gpio47";
			drive-strength = <10>;
			bias-pull-up;
		};

		clk {
			pins = "gpio42";
			drive-strength = <16>;
			bias-disable;
		};
	};

	spi_pins: spi-state {
		/delete-property/ pins;
		/delete-property/ function;
		/delete-property/ drive-strength;
		/delete-property/ bias-disable;

		mux {
			pins = "gpio18", "gpio19", "gpio21";
			function = "gsbi5";
			drive-strength = <10>;
			bias-none;
		};

		cs {
			pins = "gpio20";
			drive-strength = <12>;
		};
	};
};

&gsbi2 {
	qcom,mode = <GSBI_PROT_I2C_UART>;
	status = "okay";

	i2c@124a0000 {
		status = "okay";

		lm75@48 {
			compatible = "lm75";
			reg = <0x48>;
		};

		pcf8563: rtc@51 {
			compatible = "nxp,pcf8563";
			reg = <0x51>;
		};

		gpio_ext: tca9539@74 {
			compatible = "ti,tca9539";
			reg = <0x74>;

			gpio-controller;
			#gpio-cells = <2>;
		};
	};
};

&gsbi5 {
	qcom,mode = <GSBI_PROT_SPI>;
	status = "okay";

	spi4: spi@1a280000 {
		status = "okay";

		pinctrl-0 = <&spi_pins>;
		pinctrl-names = "default";

		cs-gpios = <&qcom_pinmux 20 GPIO_ACTIVE_LOW>;

		m25p80@0 {
			compatible = "s25fl256s1";
			#address-cells = <1>;
			#size-cells = <1>;
			spi-max-frequency = <50000000>;
			reg = <0>;

			SBL1@0 {
				label = "SBL1";
				reg = <0x0 0x10000>;
				read-only;
			};

			MIBIB@10000 {
				label = "MIBIB";
				reg = <0x10000 0x10000>;
				read-only;
			};

			SBL2@20000 {
				label = "SBL2";
				reg = <0x20000 0x20000>;
				read-only;
			};

			SBL3@40000 {
				label = "SBL3";
				reg = <0x40000 0x30000>;
				read-only;
			};

			DDRCONFIG@70000 {
				label = "DDRCONFIG";
				reg = <0x70000 0x10000>;
				read-only;
			};

			PRODUCTINFO@80000 {
				label = "PRODUCTINFO";
				reg = <0x80000 0x10000>;
				read-only;
			};

			TZ@90000 {
				label = "TZ";
				reg = <0x90000 0x30000>;
				read-only;
			};

			RPM@c0000 {
				label = "RPM";
				reg = <0xc0000 0x20000>;
				read-only;
			};

			APPSBL@e0000 {
				label = "APPSBL";
				reg = <0xe0000 0x80000>;
				read-only;
			};

			APPSBLENV@160000 {
				label = "APPSBLENV";
				reg = <0x160000 0x10000>;
				read-only;
			};

			BOOTCONFIG@170000 {
				label = "BOOTCONFIG";
				reg = <0x170000 0x10000>;
				read-only;
			};

			ART@180000 {
				label = "ART";
				reg = <0x180000 0x40000>;
				read-only;
			};
		};
	};
};

&sata_phy {
	status = "okay";
};

&sata {
	status = "okay";
};

&usb3_0 {
	status = "okay";
};

&usb3_1 {
	status = "okay";
};

&pcie0 {
	status = "okay";
	reset-gpio = <&qcom_pinmux 3 GPIO_ACTIVE_HIGH>;
	pinctrl-0 = <&pcie0_pins>;
	pinctrl-names = "default";
};

&pcie1 {
	status = "okay";
	reset-gpio = <&qcom_pinmux 48 GPIO_ACTIVE_HIGH>;
	pinctrl-0 = <&pcie1_pins>;
	pinctrl-names = "default";
	max-link-speed = <1>;
};

&mdio0 {
	status = "okay";

	pinctrl-0 = <&mdio0_pins>;
	pinctrl-names = "default";

	switch@10 {
		compatible = "qca,qca8337";
		#address-cells = <1>;
		#size-cells = <0>;
		reg = <0x10>;

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

			port@0 {
				reg = <0>;
				label = "cpu";
				ethernet = <&gmac1>;
				phy-mode = "rgmii";
				tx-internal-delay-ps = <1000>;
				rx-internal-delay-ps = <1000>;

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

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

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

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

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

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

			phy_port1: phy@0 {
				reg = <0>;
			};

			phy_port5: phy@4 {
				reg = <4>;
			};
		};
	};
};

&gmac1 {
	status = "okay";
	phy-mode = "rgmii";
	qcom,id = <1>;

	pinctrl-0 = <&rgmii2_pins>;
	pinctrl-names = "default";

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

&gmac2 {
	status = "okay";
	phy-mode = "sgmii";
	qcom,id = <2>;

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

&sdcc1 {
	status = "okay";
	pinctrl-0 = <&sdcc1_pins>;
	pinctrl-names = "default";
};

&adm_dma {
	status = "okay";
};

&CPU_SPC {
	status = "disabled";
};
