/*
 * Copyright (c) 2019, 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-ipq6018.dtsi"
#include <dt-bindings/input/input.h>

/ {
	#address-cells = <0x2>;
	#size-cells = <0x2>;
	interrupt-parent = <&intc>;
	qcom,msm-id = <0x1A5 0x0>;

	aliases {
		ethernet0 = "/soc/dp1";
		ethernet1 = "/soc/dp2";
		ethernet2 = "/soc/dp3";

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

	chosen {
		bootargs = "console=ttyMSM0,115200,n8 rw init=/init";
		bootargs-append = " swiotlb=1 coherent_pool=2M";
	};
};

&tlmm {
	uart_pins: uart_pins {
		mux {
			pins = "gpio44", "gpio45";
			function = "blsp2_uart";
			drive-strength = <8>;
			bias-pull-down;
		};
	};

	qpic_pins: qpic_pins {
		data_0 {
			pins = "gpio15";
			function = "qpic_pad0";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_1 {
			pins = "gpio12";
			function = "qpic_pad1";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_2 {
			pins = "gpio13";
			function = "qpic_pad2";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_3 {
			pins = "gpio14";
			function = "qpic_pad3";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_4 {
			pins = "gpio5";
			function = "qpic_pad4";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_5 {
			pins = "gpio6";
			function = "qpic_pad5";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_6 {
			pins = "gpio7";
			function = "qpic_pad6";
			drive-strength = <8>;
			bias-pull-down;
		};
		data_7 {
			pins = "gpio8";
			function = "qpic_pad7";
			drive-strength = <8>;
			bias-pull-down;
		};
		qpic_pad {
			pins = "gpio1", "gpio3", "gpio4",
			       "gpio10", "gpio11", "gpio17";
			function = "qpic_pad";
			drive-strength = <8>;
			bias-pull-down;
		};
	};

	button_pins: button_pins {
		switch_button {
			pins = "gpio9";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-up;
		};
		reset_button {
			pins = "gpio18";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-up;
		};
	};

	mdio_pins: mdio_pinmux {
		mux_0 {
			pins = "gpio64";
			function = "mdc";
			drive-strength = <8>;
			bias-pull-up;
		};
		mux_1 {
			pins = "gpio65";
			function = "mdio";
			drive-strength = <8>;
			bias-pull-up;
		};
		mux_2 {
			pins = "gpio74";
			function = "gpio";
			bias-pull-up;
		};
	};

	leds_pins: leds_pins {
		white {
			pins = "gpio35";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-down;
		};
		blue {
			pins = "gpio37";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-down;
		};
	};

	usb_pins: usb_pins {
		usb_pwr {
			pins = "gpio0";
			function = "gpio";
			bias-pull-up;
			output-high;
		};
	};
};

&soc {
	mdio0: mdio@90000 {
		pinctrl-0 = <&mdio_pins>;
		pinctrl-names = "default";
		phy-reset-gpio = <&tlmm 74 GPIO_ACTIVE_HIGH>;
		status = "ok";
		phy0: ethernet-phy@0 {
			reg = <0>;
		};
		phy1: ethernet-phy@1 {
			reg = <1>;
		};
		phy2: ethernet-phy@2 {
			reg = <2>;
		};
	};

	ess0: ess-switch@3a000000 {
		switch_cpu_bmp = <0x1>;  /* cpu port bitmap */
		switch_lan_bmp = <0x0c>; /* lan port bitmap */
		switch_wan_bmp = <0x02>; /* wan port bitmap */
		switch_inner_bmp = <0xc0>; /*inner port bitmap*/
		switch_mac_mode = <0x0>; /* mac mode for uniphy instance0*/
		switch_mac_mode1 = <0xff>; /* mac mode for uniphy instance1*/
		switch_mac_mode2 = <0xff>; /* mac mode for uniphy instance2*/
		qcom,port_phyinfo {
			port@0 {
				port_id = <1>;
				phy_address = <0>;
			};
			port@1 {
				port_id = <2>;
				phy_address = <1>;
			};
			port@2 {
				port_id = <3>;
				phy_address = <2>;
			};
		};
	};

	dp1 {
		device_type = "network";
		compatible = "qcom,nss-dp";
		qcom,id = <1>;
		reg = <0x3a001000 0x200>;
		qcom,mactype = <0>;
		local-mac-address = [000000000000];
		qcom,link-poll = <1>;
		qcom,phy-mdio-addr = <0>;
		phy-mode = "sgmii";
	};

	dp2 {
		device_type = "network";
		compatible = "qcom,nss-dp";
		qcom,id = <2>;
		reg = <0x3a001200 0x200>;
		qcom,mactype = <0>;
		local-mac-address = [000000000000];
		qcom,link-poll = <1>;
		qcom,phy-mdio-addr = <1>;
		phy-mode = "sgmii";
	};

	dp3 {
		device_type = "network";
		compatible = "qcom,nss-dp";
		qcom,id = <3>;
		reg = <0x3a001400 0x200>;
		qcom,mactype = <0>;
		local-mac-address = [000000000000];
		qcom,link-poll = <1>;
		qcom,phy-mdio-addr = <2>;
		phy-mode = "sgmii";
	};

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

		led_run: led@35 {
			label = "white:sys";
			gpios = <&tlmm 35 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};

		led@37 {
			label = "blue:wan";
			gpios = <&tlmm 37 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};
	};

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

		switch {
			label = "switch";
			linux,code = <KEY_WPS_BUTTON>;
			gpios = <&tlmm 9 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			debounce-interval = <60>;
		};
		reset {
			label = "reset";
			linux,code = <KEY_RESTART>;
			gpios = <&tlmm 18 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			debounce-interval = <60>;
		};
	};
};

&blsp1_uart3 {
	pinctrl-0 = <&uart_pins>;
	pinctrl-names = "default";
	status = "ok";
};

&qpic_bam {
	status = "ok";
};

&nand {
	pinctrl-0 = <&qpic_pins>;
	pinctrl-names = "default";
	status = "ok";
};

&ssphy_0 {
	status = "ok";
};

&qusb_phy_0 {
	status = "ok";
};

&usb3 {
	pinctrl-0 = <&usb_pins>;
	pinctrl-names = "default";
	status = "ok";
};

&nss_crypto {
	status = "ok";
};

&q6_region {
	reg = <0x0 0x4ab00000 0x0 0x05500000>;
};

&CPU0 {
	operating-points = <
		/* kHz   uV (fixed) */
		864000   1100000
		1056000  1100000
		1200000  1100000
	>;
	clock-latency = <200000>;
};

&CPU1 {
	operating-points = <
		/* kHz   uV (fixed) */
		864000   1100000
		1056000  1100000
		1200000  1100000
	>;
	clock-latency = <200000>;
};

&CPU2 {
	operating-points = <
		/* kHz   uV (fixed) */
		864000   1100000
		1056000  1100000
		1200000  1100000
	>;
	clock-latency = <200000>;
};

&CPU3 {
	operating-points = <
		/* kHz   uV (fixed) */
		864000   1100000
		1056000  1100000
		1200000  1100000
	>;
	clock-latency = <200000>;
};
