/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
 *
 * 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/soc/qcom,tcsr.h>

/ {
	model = "ASUS RT-ACRH17";
	compatible = "asus,rt-acrh17", "qcom,ipq4019";

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

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

	chosen {
		bootargs-append = " ubi.mtd=UBI_DEV";
	};

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

		ess-psgmii@98000 {
			status = "okay";
		};

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

		tcsr@194b000 {
			compatible = "qcom,tcsr";
			reg = <0x194b000 0x100>;
			qcom,usb-hsphy-mode-select = <TCSR_USB_HSPHY_HOST_MODE>;
		};

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

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

		usb2@60f8800 {
			status = "okay";
		};

		usb3@8af8800 {
			status = "okay";
		};

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

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

		ess-switch@c000000 {
			status = "okay";
		};

		edma@c080000 {
			status = "okay";
		};
	};

	gpio-keys {
		compatible = "gpio-keys";

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

		wps {
			label = "wps";
			gpios = <&tlmm 11 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_WPS_BUTTON>;
		};
	};

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

		power: status {
			label = "rt-acrh17:blue:status";
			gpios = <&tlmm 40 GPIO_ACTIVE_LOW>;
		};

		lan1 {
			label = "rt-acrh17:blue:lan1";
			gpios = <&tlmm 45 GPIO_ACTIVE_LOW>;
		};

		lan2 {
			label = "rt-acrh17:blue:lan2";
			gpios = <&tlmm 43 GPIO_ACTIVE_LOW>;
		};

		lan3 {
			label = "rt-acrh17:blue:lan3";
			gpios = <&tlmm 42 GPIO_ACTIVE_LOW>;
		};

		lan4 {
			label = "rt-acrh17:blue:lan4";
			gpios = <&tlmm 49 GPIO_ACTIVE_LOW>;
		};

		wan_blue {
			label = "rt-acrh17:blue:wan";
			gpios = <&tlmm 61 GPIO_ACTIVE_HIGH>;
		};

		wan_red {
			label = "rt-acrh17:red:wan";
			gpios = <&tlmm 68 GPIO_ACTIVE_HIGH>;
		};

		wlan2g {
			label = "rt-acrh17:blue:wlan2g";
			gpios = <&tlmm 52 GPIO_ACTIVE_LOW>;
		};

		wlan5g {
			label = "rt-acrh17:blue:wlan5g";
			gpios = <&tlmm 54 GPIO_ACTIVE_LOW>;
		};
	};
};

&cryptobam {
	status = "okay";
};

&blsp_dma {
	status = "okay";
};

&qpic_bam {
	status = "okay";
};

&nand {
	pinctrl-0 = <&nand_pins>;
	pinctrl-names = "default";
	status = "okay";

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

			partition@0 {
				label = "Bootloader";
				reg = <0x000000000000 0x000000400000>;
				read-only;
			};
			partition@1 {
				label = "UBI_DEV";
				reg = <0x000000400000 0x000007C00000>;
			};
		};
	};
};

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

	nand_pins: nand_pins {
		pullups {
			pins = "gpio53", "gpio58",
				 "gpio59";
			function = "qpic";
			bias-pull-up;
		};

		pulldowns {
			pins = "gpio55", "gpio56",
				 "gpio57", "gpio60",
				 "gpio62", "gpio63", "gpio64",
				 "gpio65", "gpio66", "gpio67",
				 "gpio69";
			function = "qpic";
			bias-pull-down;
		};
	};
};

&pcie0 {
	status = "okay";
	perst-gpio = <&tlmm 38 GPIO_ACTIVE_LOW>;
	wake-gpio = <&tlmm 50 GPIO_ACTIVE_LOW>;
	/* overwrite interrupts */
	interrupts = <GIC_SPI 141 IRQ_TYPE_NONE>;

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

		wifi2: wifi@1,0 {
			compatible = "qcom,ath10k";
			status = "okay";
			reg = <0x00010000 0 0 0 0>;
		};
	};
};

&wifi0 {
	status = "okay";
	qcom,ath10k-calibration-variant = "RT-ACRH17";
};

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

&usb3_ss_phy {
	status = "okay";
};

&usb3_hs_phy {
	status = "okay";
};

&usb2_hs_phy {
	status = "okay";
};
