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

#include "mt7621_mikrotik.dtsi"

/ {
	compatible = "mikrotik,ltap-2hnd", "mediatek,mt7621-soc";
	model = "MikroTik RouterBOARD LtAP-2HnD";

	aliases {
		led-boot = &led_usr;
		led-failsafe = &led_usr;
		led-running = &led_usr;
		led-upgrade = &led_usr;
		label-mac-device = &ethernet;
	};

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

		rssi0 {
			label = "green:rssi0";
			gpios = <&ath9k 0 GPIO_ACTIVE_LOW>;
		};
		rssi1 {
			label = "green:rssi1";
			gpios = <&ath9k 1 GPIO_ACTIVE_LOW>;
		};
		rssi2 {
			label = "green:rssi2";
			gpios = <&ath9k 2 GPIO_ACTIVE_LOW>;
		};
		rssi3 {
			label = "green:rssi3";
			gpios = <&ath9k 3 GPIO_ACTIVE_LOW>;
		};
		rssi4 {
			label = "green:rssi4";
			gpios = <&ath9k 4 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		compatible = "gpio-leds";

		pwr {
			label = "blue:pwr";
			gpios = <&gpio 23 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};

		led_usr: usr {
			label = "green:usr";
			gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
		};

		gps {
			label = "green:gps";
			gpios = <&gpio 28 GPIO_ACTIVE_LOW>;
		};
	};

	/* TODO: find GPIOs for the WLAN antenna switches */
	gpio-export {
		compatible = "gpio-export";

		usb-select {
			gpio-export,name = "usb-select";
			gpio-export,output = <1>;
			gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
		};
		gps-reset {
			gpio-export,name = "gps-reset";
			gpio-export,output = <1>;
			gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
		};
		sim-select {
			gpio-export,name = "sim-select";
			gpio-export,output = <1>;
			gpios = <&gpio 25 GPIO_ACTIVE_HIGH>;
		};
		gps-ant-select {
			/* internal antenna = 0 */
			gpio-export,name = "gps-ant-select";
			gpio-export,output = <0>;
			gpios = <&gpio 27 GPIO_ACTIVE_HIGH>;
		};
		lte-reset {
			gpio-export,name = "lte-reset";
			gpio-export,output = <1>;
			gpios = <&gpio 29 GPIO_ACTIVE_HIGH>;
		};
	};

	pps {
		compatible = "pps-gpio";
		gpios = <&gpio 14 GPIO_ACTIVE_HIGH>;
	};

	pcie1_vcc_reg {
		compatible = "regulator-fixed";
		regulator-name = "pcie1_vcc";

		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpios = <&gpio 10 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		regulator-boot-on;
	};

	pcie2_vcc_reg {
		compatible = "regulator-fixed";
		regulator-name = "pcie2_vcc";

		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpios = <&gpio 11 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		regulator-boot-on;
	};
};

&partitions {
	partition@40000 {
		compatible = "mikrotik,minor";
		label = "firmware";
		reg = <0x040000 0xfc0000>;
	};
};

&ethernet {
	pinctrl-0 = <&mdio_pins>, <&rgmii1_pins>;

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

&switch0 {
	ports {
		port@0 {
			status = "okay";
			label = "lan";
		};
	};
};

&pcie0 {
	status = "okay";

	ath9k: wifi@0,0 {
		compatible = "pci168c,0030";
		reg = <0x0000 0 0 0 0>;
		qca,no-eeprom;
		nvmem-cells = <&macaddr_hard 1>;
		nvmem-cell-names = "mac-address";
		gpio-controller;
		#gpio-cells = <2>;
	};
};

&state_default {
	gpio {
		groups = "uart2", "wdt", "rgmii2";
		function = "gpio";
	};
};

&i2c {
	status = "okay";
};

&pcie {
	status = "okay";
};

&uartlite3 {
	status = "okay";
};
