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

#include "qcom-ipq8064-smb208.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	model = "Fortinet FAP-421E";
	compatible = "fortinet,fap-421e", "qcom,ipq8064";

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

	reserved-memory {
		rsvd@41200000 {
			no-map;
			reg = <0x41200000 0x300000>;
		};
		wifi_dump@44000000 {
			no-map;
			reg = <0x44000000 0x600000>;
		};
	};

	aliases {
		led-boot = &led_power_yellow;
		led-failsafe = &led_power_yellow;
		led-running = &led_power_yellow;
		led-upgrade = &led_power_yellow;
		label-mac-device = &gmac0;
	};

	chosen {
		bootargs-override = "console=ttyMSM0,9600n8";
	};

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

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

	leds {
		compatible = "gpio-leds";
		pinctrl-0 = <&led_pins>;
		pinctrl-names = "default";

		eth1-amber {
			label = "amber:eth1";
			gpios = <&qcom_pinmux 27 GPIO_ACTIVE_LOW>;
		};

		eth1-yellow {
			label = "yellow:eth1";
			gpios = <&qcom_pinmux 26 GPIO_ACTIVE_LOW>;
		};

		eth2-amber {
			label = "amber:eth2";
			gpios = <&qcom_pinmux 29 GPIO_ACTIVE_LOW>;
		};

		eth2-yellow {
			label = "yellow:eth2";
			gpios = <&qcom_pinmux 28 GPIO_ACTIVE_LOW>;
		};

		power-amber {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_AMBER>;
			gpios = <&qcom_pinmux 53 GPIO_ACTIVE_LOW>;
		};

		led_power_yellow: power-yellow {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_YELLOW>;
			gpios = <&qcom_pinmux 58 GPIO_ACTIVE_LOW>;
		};

		2g-yellow {
			label = "yellow:2g";
			gpios = <&qcom_pinmux 30 GPIO_ACTIVE_LOW>;
		};

		5g-yellow {
			label = "yellow:5g";
			gpios = <&qcom_pinmux 64 GPIO_ACTIVE_LOW>;
		};
	};
};

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

	led_pins: led_pins {
		mux {
			bias-pull-down;
			drive-strength = <2>;
			function = "gpio";
			output-low;
			pins = "gpio23";
		};
	};

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

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

		mux-2 {
			bias-disable;
			drive-strength = <16>;
			function = "rgmii2";
			pins = "gpio66";
		};
	};

	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";
			bias-pull-down;
		};

		data {
			pins = "gpio18", "gpio19";
			drive-strength = <10>;
		};

		cs {
			pins = "gpio20";
			drive-strength = <10>;
			bias-pull-up;
		};

		clk {
			pins = "gpio21";
			drive-strength = <12>;
		};
	};

	uart0_pins: uart0_pins {
		mux {
			bias-disable;
			drive-strength = <12>;
			function = "gsbi7";
			pins = "gpio6", "gpio7";
		};
	};

	usb_pwr_en_pins: usb_pwr_en_pins {
		mux {
			pins = "gpio22";
			function = "gpio";
			drive-strength = <12>;
			bias-pull-down;
			output-low;
		};
	};
};

&gsbi7 {
	qcom,mode = <GSBI_PROT_I2C_UART>;

	status = "okay";
};

&gsbi7_serial{
	pinctrl-0 = <&uart0_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&gsbi5 {
	qcom,mode = <GSBI_PROT_SPI>;

	status = "okay";

	spi@1a280000 {
		status = "okay";

		pinctrl-0 = <&spi_pins>;
		pinctrl-names = "default";
		cs-gpios = <&qcom_pinmux 20 GPIO_ACTIVE_LOW>;

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

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

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

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

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

			partition@100000 {
				label = "DDRCONFIG";
				reg = <0x100000 0x10000>;
				read-only;
			};

			partition@110000 {
				label = "SSD";
				reg = <0x110000 0x10000>;
				read-only;
			};

			partition@120000 {
				label = "TZ";
				reg = <0x120000 0x80000>;
				read-only;
			};

			partition@1a0000 {
				label = "RPM";
				reg = <0x1a0000 0x80000>;
				read-only;
			};

			partition@220000 {
				label = "APPSBL";
				reg = <0x220000 0x80000>;
				read-only;

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

					macaddr_appsbl_7ff80: mac-address@7ff80 {
						compatible = "mac-base";
						reg = <0x7ff80 0xc>;
						#nvmem-cell-cells = <1>;
					};
				};
			};

			partition@2a0000 {
				label = "APPSBLENV";
				reg = <0x2a0000 0x40000>;
			};

			partition@2e0000 {
				label = "ART";
				reg = <0x2e0000 0x40000>;
				read-only;
			};

			partition@320000 {
				label = "kernel";
				reg = <0x320000 0x600000>;
			};

			partition@920000 {
				label = "ubi";
				reg = <0x920000 0x1400000>;
			};

			partition@1d20000 {
				label = "reserved";
				reg = <0x1d20000 0x260000>;
				read-only;
			};

			partition@1f80000 {
				label = "config";
				reg = <0x1f80000 0x80000>;
				read-only;
			};
		};
	};
};

&hs_phy_1 {
	status = "okay";
};

&ss_phy_1 {
	status = "okay";
};

&usb3_1 {
	status = "okay";

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

&pcie0 {
	status = "okay";
};

&pcie_bridge0 {
	wifi@0,0 {
		compatible = "qcom,ath10k";
		reg = <0x00010000 0 0 0 0>;
		nvmem-cells = <&macaddr_appsbl_7ff80 8>;
		nvmem-cell-names = "mac-address";
	};
};

&pcie1 {
	status = "okay";

	max-link-speed = <1>;
};

&pcie_bridge1 {
	wifi@0,0 {
		compatible = "qcom,ath10k";
		reg = <0x00010000 0 0 0 0>;
		nvmem-cells = <&macaddr_appsbl_7ff80 16>;
		nvmem-cell-names = "mac-address";
	};
};

&adm_dma {
	status = "okay";
};

&mdio0 {
	status = "okay";

	#address-cells = <0x1>;
	#size-cells = <0x0>;
	gpios = <&qcom_pinmux 1 GPIO_ACTIVE_HIGH>,
			<&qcom_pinmux 0 GPIO_ACTIVE_HIGH>;
	pinctrl-0 = <&mdio0_pins>;
	pinctrl-names = "default";

	phy1: ethernet-phy@1 {
		reg = <1>;
	};

	phy2: ethernet-phy@2 {
		reg = <2>;
	};
};

&gmac0 {
	status = "okay";

	phy-mode = "rgmii";
	qcom,id = <0>;
	pinctrl-0 = <&rgmii2_pins>;
	pinctrl-names = "default";
	nvmem-cells = <&macaddr_appsbl_7ff80 0>;
	nvmem-cell-names = "mac-address";

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

&gmac2 {
	status = "okay";

	phy-mode = "sgmii";
	qcom,id = <2>;
	nvmem-cells = <&macaddr_appsbl_7ff80 1>;
	nvmem-cell-names = "mac-address";

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