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

#include "qcom-ipq6018.dtsi"
#include "qcom-ipq6018-rpm-regulator.dtsi"
#include "qcom-ipq6018-cpr-regulator.dtsi"
#include "qcom-ipq6018-cp-cpu.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>

/ {
	model = "YunCore AX840";
	compatible = "yuncore,ax840", "qcom,ipq6018-cp03", "qcom,ipq6018";

	#address-cells = <0x2>;
	#size-cells = <0x2>;
	interrupt-parent = <&intc>;

	aliases {
		/* Aliases as required by u-boot to patch MAC addresses */
		ethernet0 = "/soc/dp2";
		ethernet1 = "/soc/dp1";

		serial0 = &blsp1_uart3;
		serial1 = &blsp1_uart2;

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

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

	reserved-memory {
		tzapp:tzapp@49B00000 {	/* TZAPPS */
			no-map;
			reg = <0x0 0x49B00000 0x0 0x00600000>;
		};
	};
};

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

	spi_0_pins: spi_0_pins {
		mux {
			pins = "gpio38", "gpio39", "gpio40", "gpio41";
			function = "blsp0_spi";
			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 {
		rst_button {
			pins = "gpio19";
			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 = "gpio75";
			function = "gpio";
			bias-pull-up;
		};
	};

	leds_pins: leds_pins {
		led_blue {
			pins = "gpio35";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-down;
		};

		led_green {
			pins = "gpio37";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-down;
		};

		led_red {
			pins = "gpio32";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-down;
		};
	};
};

&soc {
	mdio: mdio@90000 {
		status = "ok";

		pinctrl-0 = <&mdio_pins>;
		pinctrl-names = "default";
		phy-reset-gpio = <&tlmm 75 0>;

		ethernet-phy@0 {
			reg = <0x03>;
		};

		ethernet-phy@1 {
			reg = <0x04>;
		};
	};

	ess-switch@3a000000 {
		switch_cpu_bmp =   <0x01>; /* cpu port bitmap */
		switch_lan_bmp =   <0x10>; /* lan port bitmap */
		switch_wan_bmp =   <0x20>; /* wan port bitmap */
		switch_inner_bmp = <0x80>; /*inner port bitmap*/
		switch_mac_mode =  <0x00>; /* 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@3 {
				port_id = <0x04>;
				phy_address = <0x03>;
			};

			port@4 {
				port_id = <0x05>;
				phy_address = <0x04>;
			};
		};
	};

	dp1 {
		device_type = "network";
		compatible = "qcom,nss-dp";
		qcom,id = <0x05>;
		reg = <0x3a001800 0x200>;
		qcom,mactype = <0x00>;
		local-mac-address = [00 00 00 00 00 00];
		qcom,link-poll = <0x01>;
		qcom,phy-mdio-addr = <0x04>;
		phy-mode = "sgmii";
	};

	dp2 {
		device_type = "network";
		compatible = "qcom,nss-dp";
		qcom,id = <0x04>;
		reg = <0x3a001600 0x200>;
		qcom,mactype = <0x00>;
		local-mac-address = [00 00 00 00 00 00];
		qcom,link-poll = <0x01>;
		qcom,phy-mdio-addr = <0x03>;
		phy-mode = "sgmii";
	};

	gpio_keys {
		compatible = "gpio-keys";

		pinctrl-0 = <&button_pins>;
		pinctrl-names = "default";

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

	leds {
		compatible = "gpio-leds";

		pinctrl-0 = <&leds_pins>;
		pinctrl-names = "default";

		led_system: system {
			label = "ax860:green:system";
			gpio = <&tlmm 37 GPIO_ACTIVE_HIGH>;
		};

		wlan2g {
			label = "ax860:blue:wlan2g";
			gpio = <&tlmm 35 GPIO_ACTIVE_HIGH>;
		};

		wlan5g {
			label = "ax860:red:wlan5g";
			gpio = <&tlmm 32 GPIO_ACTIVE_HIGH>;
		};
	};
};

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

&spi_0 {
	pinctrl-0 = <&spi_0_pins>;
	pinctrl-names = "default";
	cs-select = <0>;
	status = "ok";

	m25p80@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		reg = <0>;
		compatible = "n25q128a11";
		linux,modalias = "m25p80", "n25q128a11";
		spi-max-frequency = <50000000>;
		use-default-sizes;
	};
};

&qpic_bam {
	status = "ok";
};

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

&nss_crypto {
	status = "ok";
};

&cpu0_opp_table {
	compatible = "operating-points-v2";
	opp-shared;

	opp03 {
		opp-hz = /bits/ 64 <1200000000>;
		opp-microvolt = <3>;
		clock-latency-ns = <200000>;
	};

	/delete-node/ opp04;
	/delete-node/ opp05;
	/delete-node/ opp06;
};

&qseecom {
	mem-start = <0x49B00000>;
	mem-size = <0x600000>;
	status = "ok";
};
