/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2019, Robert Marko <robimarko@gmail.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "qcom-ipq4019.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/soc/qcom,tcsr.h>

/ {
	model = "Mikrotik Wireless Wire Dish LHGG-60ad";
	compatible = "mikrotik,lhgg-60ad";

	memory {
		device_type = "memory";
		reg = <0x80000000 0x10000000>;
	};

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

	aliases {
		led-boot = &user;
		led-failsafe = &user;
		led-running = &user;
		led-upgrade = &user;
	};

	soc {
		rng@22000 {
			status = "okay";
		};

		mdio@90000 {
			status = "okay";
		};

		counter@4a1000 {
			compatible = "qcom,qca-gcnt";
			reg = <0x4a1000 0x4>;
		};

		tcsr@1949000 {
			compatible = "qcom,tcsr";
			reg = <0x1949000 0x100>;
			qcom,wifi_glb_cfg = <TCSR_WIFI_GLB_CFG>;
		};

		ess_tcsr@1953000 {
			compatible = "qcom,tcsr";
			reg = <0x1953000 0x1000>;
			qcom,ess-interface-select = <TCSR_ESS_PSGMII_RGMII5>;
		};

		tcsr@1957000 {
			compatible = "qcom,tcsr";
			reg = <0x1957000 0x100>;
			qcom,wifi_noc_memtype_m0_m2 = <TCSR_WIFI_NOC_MEMTYPE_M0_M2>;
		};

		crypto@8e3a000 {
			status = "okay";
		};

		watchdog@b017000 {
			status = "okay";
		};
	};

	keys {
		compatible = "gpio-keys";

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

	leds {
		compatible = "gpio-leds";

		power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
			default-state = "keep";
			panic-indicator;
		};

		user: user {
			label = "yellow:user";
			gpios = <&tlmm 3 GPIO_ACTIVE_HIGH>;
		};

		wlan {
			function = LED_FUNCTION_WLAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&tlmm 58 GPIO_ACTIVE_HIGH>;
		};

		align-left {
			label = "green:align-left";
			gpios = <&tlmm 1 GPIO_ACTIVE_HIGH>;
		};

		align-right {
			label = "green:align-right";
			gpios = <&tlmm 2 GPIO_ACTIVE_HIGH>;
		};

		wlan-rx {
			label = "green:align-down";
			gpios = <&tlmm 4 GPIO_ACTIVE_HIGH>;
		};

		wlan-tx {
			label = "green:align-up";
			gpios = <&tlmm 5 GPIO_ACTIVE_HIGH>;
		};
	};
};

&tlmm {
	serial_pins: serial_pinmux {
		mux {
			pins = "gpio60", "gpio61";
			function = "blsp_uart0";
			bias-disable;
		};
	};

	spi_0_pins: spi-0-pinmux {
		pinmux {
			function = "blsp_spi0";
			pins = "gpio13", "gpio14", "gpio15";
			bias-disable;
		};

		pinmux_cs {
			function = "gpio";
			pins = "gpio12";
			bias-disable;
			output-high;
		};
	};
};

&blsp_dma {
	status = "okay";
};

&blsp1_spi1 {
	pinctrl-0 = <&spi_0_pins>;
	pinctrl-names = "default";
	cs-gpios = <&tlmm 12 GPIO_ACTIVE_HIGH>;
	status = "okay";

	m25p80@0 {
		reg = <0>;
		compatible = "jedec,spi-nor";
		spi-max-frequency = <24000000>;

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

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

			partition@80000 {
				compatible = "mikrotik,routerboot-partitions";
				#address-cells = <1>;
				#size-cells = <1>;
				label = "RouterBoot";
				reg = <0x80000 0x80000>;

				hard_config {
					read-only;
					size = <0x2000>;
				};

				dtb_config {
					read-only;
				};

				soft_config {
				};
			};

			partition@100000 {
				compatible = "mikrotik,minor";
				label = "firmware";
				reg = <0x100000 0xf00000>;
			};
		};
	};
};

&blsp1_uart1 {
	pinctrl-0 = <&serial_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&cryptobam {
	status = "okay";
};

&pcie0 {
	status = "okay";
	perst-gpio = <&tlmm 42 GPIO_ACTIVE_HIGH>;

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

		/* wil6210 802.11ad card */
		wifi: wifi@1,0 {
			status = "okay";
			/* wil6210 driver has no compatible */
			reg = <0x00010000 0 0 0 0>;
		};
	};
};

&ethphy1 {
	status = "disabled";
};

&ethphy2 {
	status = "disabled";
};

&ethphy3 {
	status = "disabled";
};

&ethphy4 {
	status = "disabled";
};

&psgmiiphy {
	status = "disabled";
};

&gmac {
	status = "okay";
};

&switch {
	status = "okay";

	/delete-property/ psgmii-ethphy;
};

&swport5 {
	status = "okay";

	label = "lan";
	phy-handle = <&ethphy0>;
	phy-mode = "rgmii-id";
};
