// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2016, 2018 The Linux Foundation. All rights reserved.
 * Copyright (c) 2016 Google, Inc
 */

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

/ {
	model = "Google WiFi (Gale)";
	compatible = "google,wifi", "google,gale-v2", "qcom,ipq4019";

	aliases {
		// TODO: Verify if the ethernet0 alias is needed
		ethernet0 = &gmac;
		label-mac-device = &gmac0;
		led-boot = &led0_blue;
		led-failsafe = &led0_red;
		led-running = &led0_blue;
		led-upgrade = &led0_red;
	};

	chosen {
		/*
		 * rootwait: in case we're booting from slow/async USB storage.
		 */
		bootargs-append = " rootwait";
		stdout-path = &blsp1_uart1;
	};

	memory {
		device_type = "memory";
		reg = <0x80000000 0x20000000>; /* 512MB */
	};

	soc {
		edma@c080000 {
			/*
			 * Factory bootloader (depthcharge) will fail to boot
			 * if this exact path (soc/edma@c080000/gmac0) doesn't
			 * exist.
			 */
			gmac0: gmac0 {
			};

			/*
			 * Factory bootloader (depthcharge) will fail to boot
			 * if this exact path (soc/edma@c080000/gmac1) doesn't
			 * exist.
			 */
			gmac1 {
			};
		};
	};

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

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

&scm {
	qcom,sdi-enabled;
};

&tlmm {
	gpio-line-names = "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  "",
			  /* AP_FLASH_WP_L is crossystem ABI. */
			  "AP_FLASH_WP_L" /* 53 */,
			  "",
			  "",
			  "",
			  /* RECOVERY_SW_L is crossystem ABI. */
			  "RECOVERY_SW_L" /* 57 */;

	fw_pinmux: fw_pinmux {
		wp {
			pins = "gpio53";
			output-low;
		};
		recovery {
			pins = "gpio57";
			function = "gpio";
			bias-none;
		};
		developer {
			pins = "gpio41";
			bias-none;
		};
	};

	reset802_15_4 {
		pins = "gpio60";
	};

	led_reset {
		pins = "gpio22";
		output-high;
	};

	sys_reset {
		pins = "gpio19";
		output-high;
	};

	rx_active {
		pins = "gpio43";
		bias-pull,down;
	};

	spi_0_pins: spi_0_pinmux {
		pinmux {
			function = "blsp_spi0";
			pins = "gpio13", "gpio14","gpio15";
		};
		pinmux_cs {
			function = "gpio";
			pins = "gpio12";
		};
		pinconf {
			pins = "gpio13", "gpio14","gpio15";
			drive-strength = <12>;
			bias-disable;
		};
		pinconf_cs {
			pins = "gpio12";
			drive-strength = <2>;
			bias-disable;
			output-high;
		};
	};

	spi_1_pins: spi_1_pinmux {
		pinmux {
			function = "blsp_spi1";
			pins = "gpio44", "gpio46","gpio47";
		};
		pinmux_cs {
			function = "gpio";
			pins = "gpio45";
		};
		pinconf {
			pins = "gpio44", "gpio46","gpio47";
			drive-strength = <12>;
			bias-disable;
		};
		pinconf_cs {
			pins = "gpio45";
			drive-strength = <2>;
			bias-disable;
			output-high;
		};
	};

	serial_0_pins: serial0_pinmux {
		mux {
			pins = "gpio16", "gpio17";
			function = "blsp_uart0";
			bias-disable;
		};
	};

	serial_1_pins: serial1_pinmux {
		mux {
			pins = "gpio8", "gpio9", "gpio10", "gpio11";
			function = "blsp_uart1";
			bias-disable;
		};
	};

	i2c_0_pins: i2c_0_pinmux {
		mux {
			pins = "gpio20", "gpio21";
			function = "blsp_i2c0";
			drive-open-drain;
		};
	};

	i2c_1_pins: i2c_1_pinmux {
		mux {
			pins = "gpio34", "gpio35";
			function = "blsp_i2c1";
			drive-open-drain;
		};
	};

	sd_0_pins: sd_0_pinmux {
		sd0 {
			pins = "gpio23", "gpio24", "gpio25", "gpio26", "gpio29", "gpio30", "gpio31", "gpio32";
			function = "sdio";
			drive-strength = <10>;
			bias-pull-up;
			pull-up-res = <0>;
		};
		sdclk {
			pins = "gpio27";
			function = "sdio";
			drive-strength = <2>;
			bias-pull-up;
			pull-up-res = <0>;
		};
		sdcmd {
			pins = "gpio28";
			function = "sdio";
			drive-strength = <10>;
			bias-pull-up;
			pull-up-res = <0>;
		};
	};

	mdio_pins: mdio_pinmux {
		mux_1 {
			pins = "gpio6";
			function = "mdio";
			bias-disable;
		};
		mux_2 {
			pins = "gpio7";
			function = "mdc";
			bias-disable;
		};
		mux_3 {
			pins = "gpio40";
			function = "gpio";
			bias-disable;
			output-high;
		};
	};

	wifi1_1_pins: wifi2_pinmux {
		mux {
			pins = "gpio58";
			output-low;
		};
	};
};

&blsp_dma {
	status = "okay";
};

&blsp1_i2c3 {
	pinctrl-0 = <&i2c_0_pins>;
	pinctrl-names = "default";
	status = "okay";

	tpm@20 {
		compatible = "infineon,slb9645tt";
		reg = <0x20>;
		powered-while-suspended;
	};
};

&blsp1_i2c4 {
	pinctrl-0 = <&i2c_1_pins>;
	pinctrl-names = "default";
	status = "okay";

	led-controller@32 {
		#address-cells = <1>;
		#size-cells = <0>;
		compatible = "national,lp5523";
		reg = <0x32>;
		clock-mode = /bits/ 8 <1>;

#if 1
		led0_red: led@0 {
			reg = <0>;
			chan-name = "LED0_Red";
			led-cur = /bits/ 8 <0x64>;
			max-cur = /bits/ 8 <0x78>;
			color = <LED_COLOR_ID_RED>;
			function = LED_FUNCTION_FAULT;
		};

		led@1 {
			reg = <1>;
			chan-name = "LED0_Green";
			led-cur = /bits/ 8 <0x64>;
			max-cur = /bits/ 8 <0x78>;
			color = <LED_COLOR_ID_GREEN>;
		};

		led0_blue: led@2 {
			reg = <2>;
			chan-name = "LED0_Blue";
			led-cur = /bits/ 8 <0x64>;
			max-cur = /bits/ 8 <0x78>;
			color = <LED_COLOR_ID_BLUE>;
			function = LED_FUNCTION_POWER;
		};
#else
		/*
		 * openwrt isn't ready to handle multi-intensity leds yet
		 * # echo 255 255 255 > /sys/class/leds/tricolor/multi_intensity
		 * # echo 255 > /sys/class/leds/tricolor/brightness
		 */
		multi-led@2 {
			function = LED_FUNCTION_POWER;
			reg = <2>;
			color = <LED_COLOR_ID_RGB>;
			#address-cells = <1>;
			#size-cells = <0>;

			led@0 {
				reg = <0>;
				chan-name = "tricolor";
				led-cur = /bits/ 8 <0x64>;
				max-cur = /bits/ 8 <0x78>;
				color = <LED_COLOR_ID_RED>;
			};

			led@1 {
				reg = <1>;
				chan-name = "tricolor";
				led-cur = /bits/ 8 <0x64>;
				max-cur = /bits/ 8 <0x78>;
				color = <LED_COLOR_ID_GREEN>;
			};

			led@2 {
				reg = <2>;
				chan-name = "tricolor";
				led-cur = /bits/ 8 <0x64>;
				max-cur = /bits/ 8 <0x78>;
				color = <LED_COLOR_ID_BLUE>;
			};
		};
#endif
	};
};

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

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

&blsp1_spi2 {
	pinctrl-0 = <&spi_1_pins>;
	pinctrl-names = "default";
	status = "okay";
	cs-gpios = <&tlmm 45 GPIO_ACTIVE_HIGH>;

	/*
	 * This "spidev" was included in the manufacturer device tree. I
	 * suspect it's the (unused; and removed from later HW spins) Zigbee
	 * radio -- SiliconLabs EM3581 Zigbee? There's no driver or binding for
	 * this at the moment.
	 */
	spidev@0 {
		compatible = "spidev";
		reg = <0>;
		spi-max-frequency = <24000000>;
	};
};

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

&blsp1_uart2 {
	pinctrl-0 = <&serial_1_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&gmac {
	status = "okay";
};

&mdio {
	status = "okay";
	pinctrl-0 = <&mdio_pins>;
	pinctrl-names = "default";
};

&prng {
	status = "okay";
};

&sdhci {
	status = "okay";
	pinctrl-0 = <&sd_0_pins>;
	pinctrl-names = "default";
	clock-frequency = <192000000>;
	vqmmc-supply = <&vqmmc>;
	non-removable;
};

&switch {
	status = "okay";
};

&swport4 {
	status = "okay";

	label = "lan";
};

&swport5 {
	status = "okay";
};

&usb2 {
	status = "okay";
};

&usb2_hs_phy {
	status = "okay";
};

&usb3 {
	status = "okay";
};

&usb3_ss_phy {
	status = "okay";
};

&usb3_hs_phy {
	status = "okay";
};

&vqmmc {
	status = "okay";
};

&watchdog {
	status = "okay";
};

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

&wifi1 {
	status = "okay";
	pinctrl-0 = <&wifi1_1_pins>;
	pinctrl-names = "default";
	qcom,ath10k-calibration-variant = "GO_GALE";
};
