// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 */

/dts-v1/;

#include "msm8916-pm8916.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/pinctrl/qcom,pmic-mpp.h>
#include <dt-bindings/sound/apq8016-lpass.h>

/ {
	model = "Qualcomm Technologies, Inc. APQ 8016 SBC";
	compatible = "qcom,apq8016-sbc", "qcom,apq8016";

	aliases {
		mmc0 = &sdhc_1; /* eMMC */
		mmc1 = &sdhc_2; /* SD card */
		serial0 = &blsp_uart2;
		serial1 = &blsp_uart1;
		usid0 = &pm8916_0;
		i2c0 = &blsp_i2c2;
		i2c1 = &blsp_i2c6;
		i2c3 = &blsp_i2c4;
		spi0 = &blsp_spi5;
		spi1 = &blsp_spi3;
	};

	chosen {
		stdout-path = "serial0";
	};

	reserved-memory {
		ramoops@bff00000 {
			compatible = "ramoops";
			reg = <0x0 0xbff00000 0x0 0x100000>;

			record-size = <0x20000>;
			console-size = <0x20000>;
			ftrace-size = <0x20000>;
		};
	};

	usb2513 {
		compatible = "smsc,usb3503";
		reset-gpios = <&pm8916_gpios 3 GPIO_ACTIVE_LOW>;
		initial-mode = <1>;
	};

	usb_id: usb-id {
		compatible = "linux,extcon-usb-gpio";
		id-gpios = <&tlmm 121 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_id_default>;
	};

	hdmi-out {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi_con: endpoint {
				remote-endpoint = <&adv7533_out>;
			};
		};
	};

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

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

		button {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&tlmm 107 GPIO_ACTIVE_LOW>;
		};
	};

	leds {
		pinctrl-names = "default";
		pinctrl-0 = <&tlmm_leds>,
			    <&pm8916_gpios_leds>,
			    <&pm8916_mpps_leds>;

		compatible = "gpio-leds";

		led-1 {
			label = "apq8016-sbc:green:user1";
			function = LED_FUNCTION_HEARTBEAT;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&tlmm 21 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
			default-state = "off";
		};

		led-2 {
			label = "apq8016-sbc:green:user2";
			function = LED_FUNCTION_DISK_ACTIVITY;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&tlmm 120 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "mmc0";
			default-state = "off";
		};

		led-3 {
			label = "apq8016-sbc:green:user3";
			function = LED_FUNCTION_DISK_ACTIVITY;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&pm8916_gpios 1 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "mmc1";
			default-state = "off";
		};

		led-4 {
			label = "apq8016-sbc:green:user4";
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&pm8916_gpios 2 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "none";
			panic-indicator;
			default-state = "off";
		};

		led-5 {
			label = "apq8016-sbc:yellow:wlan";
			function = LED_FUNCTION_WLAN;
			color = <LED_COLOR_ID_YELLOW>;
			gpios = <&pm8916_mpps 2 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "phy0tx";
			default-state = "off";
		};

		led-6 {
			label = "apq8016-sbc:blue:bt";
			function = LED_FUNCTION_BLUETOOTH;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&pm8916_mpps 3 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "bluetooth-power";
			default-state = "off";
		};
	};
};

&blsp_i2c2 {
	/* On Low speed expansion: LS-I2C0 */
	status = "okay";
};

&blsp_i2c4 {
	/* On High speed expansion: HS-I2C2 */
	status = "okay";

	adv_bridge: bridge@39 {
		status = "okay";

		compatible = "adi,adv7533";
		reg = <0x39>;

		interrupt-parent = <&tlmm>;
		interrupts = <31 IRQ_TYPE_EDGE_FALLING>;

		adi,dsi-lanes = <4>;
		clocks = <&rpmcc RPM_SMD_BB_CLK2>;
		clock-names = "cec";

		pd-gpios = <&tlmm 32 GPIO_ACTIVE_HIGH>;

		avdd-supply = <&pm8916_l6>;
		a2vdd-supply = <&pm8916_l6>;
		dvdd-supply = <&pm8916_l6>;
		pvdd-supply = <&pm8916_l6>;
		v1p2-supply = <&pm8916_l6>;
		v3p3-supply = <&pm8916_l17>;

		pinctrl-names = "default","sleep";
		pinctrl-0 = <&adv7533_int_active &adv7533_switch_active>;
		pinctrl-1 = <&adv7533_int_suspend &adv7533_switch_suspend>;
		#sound-dai-cells = <1>;

		ports {
			#address-cells = <1>;
			#size-cells = <0>;

			port@0 {
				reg = <0>;
				adv7533_in: endpoint {
					remote-endpoint = <&mdss_dsi0_out>;
				};
			};

			port@1 {
				reg = <1>;
				adv7533_out: endpoint {
					remote-endpoint = <&hdmi_con>;
				};
			};
		};
	};
};

&blsp_i2c6 {
	/* On Low speed expansion: LS-I2C1 */
	status = "okay";
};

&blsp_spi3 {
	/* On High speed expansion: HS-SPI1 */
	status = "okay";
};

&blsp_spi5 {
	/* On Low speed expansion: LS-SPI0 */
	status = "okay";
};

&blsp_uart1 {
	status = "okay";
	label = "LS-UART0";
};

&blsp_uart2 {
	status = "okay";
	label = "LS-UART1";
};

&camss {
	status = "okay";
};

&gpu {
	status = "okay";
};

&lpass {
	status = "okay";
};

&lpass_codec {
	status = "okay";
};

&mba_mem {
	status = "okay";
};

&mdss {
	status = "okay";
};

&mdss_dsi0_out {
	data-lanes = <0 1 2 3>;
	remote-endpoint = <&adv7533_in>;
};

&mpss {
	status = "okay";

	firmware-name = "qcom/apq8016/mba.mbn", "qcom/apq8016/modem.mbn";
};

&mpss_mem {
	status = "okay";
	reg = <0x0 0x86800000 0x0 0x2b00000>;
};

&pm8916_codec {
	status = "okay";
	qcom,mbhc-vthreshold-low = <75 150 237 450 500>;
	qcom,mbhc-vthreshold-high = <75 150 237 450 500>;
};

&pm8916_resin {
	status = "okay";
	linux,code = <KEY_VOLUMEDOWN>;
};

&pm8916_rpm_regulators {
	/*
	 * The 96Boards specification expects a 1.8V power rail on the low-speed
	 * expansion connector that is able to provide at least 0.18W / 100 mA.
	 * L15/L16 are connected in parallel to provide 55 mA each. A minimum load
	 * must be specified to ensure the regulators are not put in LPM where they
	 * would only provide 5 mA.
	 */
	pm8916_l15: l15 {
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-system-load = <50000>;
		regulator-allow-set-load;
		regulator-always-on;
	};
	pm8916_l16: l16 {
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-system-load = <50000>;
		regulator-allow-set-load;
		regulator-always-on;
	};

	pm8916_l17: l17 {
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
	};
};

&sdhc_1 {
	status = "okay";
};

&sdhc_2 {
	status = "okay";

	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sdc2_default &sdc2_cd_default>;
	pinctrl-1 = <&sdc2_sleep &sdc2_cd_default>;

	cd-gpios = <&tlmm 38 GPIO_ACTIVE_LOW>;
};

&sound {
	status = "okay";

	pinctrl-0 = <&cdc_pdm_default &sec_mi2s_default>;
	pinctrl-1 = <&cdc_pdm_sleep &sec_mi2s_sleep>;
	pinctrl-names = "default", "sleep";
	model = "DB410c";
	audio-routing =
		"AMIC2", "MIC BIAS Internal2",
		"AMIC3", "MIC BIAS External1";

	quaternary-dai-link {
		link-name = "ADV7533";
		cpu {
			sound-dai = <&lpass MI2S_QUATERNARY>;
		};
		codec {
			sound-dai = <&adv_bridge 0>;
		};
	};

	primary-dai-link {
		link-name = "WCD";
		cpu {
			sound-dai = <&lpass MI2S_PRIMARY>;
		};
		codec {
			sound-dai = <&lpass_codec 0>, <&pm8916_codec 0>;
		};
	};

	tertiary-dai-link {
		link-name = "WCD-Capture";
		cpu {
			sound-dai = <&lpass MI2S_TERTIARY>;
		};
		codec {
			sound-dai = <&lpass_codec 1>, <&pm8916_codec 1>;
		};
	};
};

&usb {
	status = "okay";
	extcon = <&usb_id>, <&usb_id>;

	pinctrl-names = "default", "device";
	pinctrl-0 = <&usb_sw_sel_pm &usb_hub_reset_pm>;
	pinctrl-1 = <&usb_sw_sel_pm_device &usb_hub_reset_pm_device>;
};

&usb_hs_phy {
	extcon = <&usb_id>;
};

&venus {
	status = "okay";
};

&venus_mem {
	status = "okay";
};

&wcnss {
	status = "okay";
	firmware-name = "qcom/apq8016/wcnss.mbn";
};

&wcnss_ctrl {
	firmware-name = "qcom/apq8016/WCNSS_qcom_wlan_nv_sbc.bin";
};

&wcnss_iris {
	compatible = "qcom,wcn3620";
};

&wcnss_mem {
	status = "okay";
};

/* Enable CoreSight */
&cti0 { status = "okay"; };
&cti1 { status = "okay"; };
&cti12 { status = "okay"; };
&cti13 { status = "okay"; };
&cti14 { status = "okay"; };
&cti15 { status = "okay"; };
&debug0 { status = "okay"; };
&debug1 { status = "okay"; };
&debug2 { status = "okay"; };
&debug3 { status = "okay"; };
&etf { status = "okay"; };
&etm0 { status = "okay"; };
&etm1 { status = "okay"; };
&etm2 { status = "okay"; };
&etm3 { status = "okay"; };
&etr { status = "okay"; };
&funnel0 { status = "okay"; };
&funnel1 { status = "okay"; };
&replicator { status = "okay"; };
&stm { status = "okay"; };
&tpiu { status = "okay"; };

/*
 * 2mA drive strength is not enough when connecting multiple
 * I2C devices with different pull up resistors.
 */
&blsp_i2c2_default {
	drive-strength = <16>;
};

&blsp_i2c4_default {
	drive-strength = <16>;
};

&blsp_i2c6_default {
	drive-strength = <16>;
};

/*
 * GPIO name legend: proper name = the GPIO line is used as GPIO
 *         NC = not connected (pin out but not routed from the chip to
 *              anything the board)
 *         "[PER]" = pin is muxed for [peripheral] (not GPIO)
 *         LSEC = Low Speed External Connector
 *         HSEC = High Speed External Connector
 *
 * Line names are taken from the schematic "DragonBoard410c"
 * dated monday, august 31, 2015. Page 5 in particular.
 *
 * For the lines routed to the external connectors the
 * lines are named after the 96Boards CE Specification 1.0,
 * Appendix "Expansion Connector Signal Description".
 *
 * When the 96Board naming of a line and the schematic name of
 * the same line are in conflict, the 96Board specification
 * takes precedence, which means that the external UART on the
 * LSEC is named UART0 while the schematic and SoC names this
 * UART3. This is only for the informational lines i.e. "[FOO]",
 * the GPIO named lines "GPIO-A" thru "GPIO-L" are the only
 * ones actually used for GPIO.
 */

&tlmm {
	gpio-line-names =
		"[UART0_TX]", /* GPIO_0, LSEC pin 5 */
		"[UART0_RX]", /* GPIO_1, LSEC pin 7 */
		"[UART0_CTS_N]", /* GPIO_2, LSEC pin 3 */
		"[UART0_RTS_N]", /* GPIO_3, LSEC pin 9 */
		"[UART1_TX]", /* GPIO_4, LSEC pin 11 */
		"[UART1_RX]", /* GPIO_5, LSEC pin 13 */
		"[I2C0_SDA]", /* GPIO_8, LSEC pin 17 */
		"[I2C0_SCL]", /* GPIO_7, LSEC pin 15 */
		"[SPI1_DOUT]", /* SPI1_MOSI, HSEC pin 1 */
		"[SPI1_DIN]", /* SPI1_MISO, HSEC pin 11 */
		"[SPI1_CS]", /* SPI1_CS_N, HSEC pin 7 */
		"[SPI1_SCLK]", /* SPI1_CLK, HSEC pin 9 */
		"GPIO-B", /* LS_EXP_GPIO_B, LSEC pin 24 */
		"GPIO-C", /* LS_EXP_GPIO_C, LSEC pin 25 */
		"[I2C3_SDA]", /* HSEC pin 38 */
		"[I2C3_SCL]", /* HSEC pin 36 */
		"[SPI0_MOSI]", /* LSEC pin 14 */
		"[SPI0_MISO]", /* LSEC pin 10 */
		"[SPI0_CS_N]", /* LSEC pin 12 */
		"[SPI0_CLK]", /* LSEC pin 8 */
		"HDMI_HPD_N", /* GPIO 20 */
		"USR_LED_1_CTRL",
		"[I2C1_SDA]", /* GPIO_22, LSEC pin 21 */
		"[I2C1_SCL]", /* GPIO_23, LSEC pin 19 */
		"GPIO-G", /* LS_EXP_GPIO_G, LSEC pin 29 */
		"GPIO-H", /* LS_EXP_GPIO_H, LSEC pin 30 */
		"[CSI0_MCLK]", /* HSEC pin 15 */
		"[CSI1_MCLK]", /* HSEC pin 17 */
		"GPIO-K", /* LS_EXP_GPIO_K, LSEC pin 33 */
		"[I2C2_SDA]", /* HSEC pin 34 */
		"[I2C2_SCL]", /* HSEC pin 32 */
		"DSI2HDMI_INT_N",
		"DSI_SW_SEL_APQ",
		"GPIO-L", /* LS_EXP_GPIO_L, LSEC pin 34 */
		"GPIO-J", /* LS_EXP_GPIO_J, LSEC pin 32 */
		"GPIO-I", /* LS_EXP_GPIO_I, LSEC pin 31 */
		"GPIO-A", /* LS_EXP_GPIO_A, LSEC pin 23 */
		"FORCED_USB_BOOT",
		"SD_CARD_DET_N",
		"[WCSS_BT_SSBI]",
		"[WCSS_WLAN_DATA_2]", /* GPIO 40 */
		"[WCSS_WLAN_DATA_1]",
		"[WCSS_WLAN_DATA_0]",
		"[WCSS_WLAN_SET]",
		"[WCSS_WLAN_CLK]",
		"[WCSS_FM_SSBI]",
		"[WCSS_FM_SDI]",
		"[WCSS_BT_DAT_CTL]",
		"[WCSS_BT_DAT_STB]",
		"NC",
		"NC", /* GPIO 50 */
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC", /* GPIO 60 */
		"NC",
		"NC",
		"[CDC_PDM0_CLK]",
		"[CDC_PDM0_SYNC]",
		"[CDC_PDM0_TX0]",
		"[CDC_PDM0_RX0]",
		"[CDC_PDM0_RX1]",
		"[CDC_PDM0_RX2]",
		"GPIO-D", /* LS_EXP_GPIO_D, LSEC pin 26 */
		"NC", /* GPIO 70 */
		"NC",
		"NC",
		"NC",
		"NC", /* GPIO 74 */
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"BOOT_CONFIG_0", /* GPIO 80 */
		"BOOT_CONFIG_1",
		"BOOT_CONFIG_2",
		"BOOT_CONFIG_3",
		"NC",
		"NC",
		"BOOT_CONFIG_5",
		"NC",
		"NC",
		"NC",
		"NC", /* GPIO 90 */
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC",
		"NC", /* GPIO 100 */
		"NC",
		"NC",
		"NC",
		"SSBI_GPS",
		"NC",
		"NC",
		"KEY_VOLP_N",
		"NC",
		"NC",
		"[LS_EXP_MI2S_WS]", /* GPIO 110 */
		"NC",
		"NC",
		"[LS_EXP_MI2S_SCK]",
		"[LS_EXP_MI2S_DATA0]",
		"GPIO-E", /* LS_EXP_GPIO_E, LSEC pin 27 */
		"NC",
		"[DSI2HDMI_MI2S_WS]",
		"[DSI2HDMI_MI2S_SCK]",
		"[DSI2HDMI_MI2S_DATA0]",
		"USR_LED_2_CTRL", /* GPIO 120 */
		"SB_HS_ID";

	sdc2_cd_default: sdc2-cd-default-state {
		pins = "gpio38";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
	};

	tlmm_leds: tlmm-leds-state {
		pins = "gpio21", "gpio120";
		function = "gpio";

		output-low;
	};

	usb_id_default: usb-id-default-state {
		pins = "gpio121";
		function = "gpio";

		drive-strength = <8>;
		bias-pull-up;
	};

	adv7533_int_active: adv533-int-active-state {
		pins = "gpio31";
		function = "gpio";

		drive-strength = <16>;
		bias-disable;
	};

	adv7533_int_suspend: adv7533-int-suspend-state {
		pins = "gpio31";
		function = "gpio";

		drive-strength = <2>;
		bias-disable;
	};

	adv7533_switch_active: adv7533-switch-active-state {
		pins = "gpio32";
		function = "gpio";

		drive-strength = <16>;
		bias-disable;
	};

	adv7533_switch_suspend: adv7533-switch-suspend-state {
		pins = "gpio32";
		function = "gpio";

		drive-strength = <2>;
		bias-disable;
	};

	msm_key_volp_n_default: msm-key-volp-n-default-state {
		pins = "gpio107";
		function = "gpio";

		drive-strength = <8>;
		bias-pull-up;
	};
};

&pm8916_gpios {
	gpio-line-names =
		"USR_LED_3_CTRL",
		"USR_LED_4_CTRL",
		"USB_HUB_RESET_N_PM",
		"USB_SW_SEL_PM";

	usb_hub_reset_pm: usb-hub-reset-pm-state {
		pins = "gpio3";
		function = PMIC_GPIO_FUNC_NORMAL;

		input-disable;
		output-high;
	};

	usb_hub_reset_pm_device: usb-hub-reset-pm-device-state {
		pins = "gpio3";
		function = PMIC_GPIO_FUNC_NORMAL;

		output-low;
	};

	usb_sw_sel_pm: usb-sw-sel-pm-state {
		pins = "gpio4";
		function = PMIC_GPIO_FUNC_NORMAL;

		power-source = <PM8916_GPIO_VPH>;
		input-disable;
		output-high;
	};

	usb_sw_sel_pm_device: usb-sw-sel-pm-device-state {
		pins = "gpio4";
		function = PMIC_GPIO_FUNC_NORMAL;

		power-source = <PM8916_GPIO_VPH>;
		input-disable;
		output-low;
	};

	pm8916_gpios_leds: pm8916-gpios-leds-state {
		pins = "gpio1", "gpio2";
		function = PMIC_GPIO_FUNC_NORMAL;

		output-low;
	};
};

&pm8916_mpps {
	gpio-line-names =
		"VDD_PX_BIAS",
		"WLAN_LED_CTRL",
		"BT_LED_CTRL",
		"GPIO-F"; /* LS_EXP_GPIO_F, LSEC pin 28 */

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

	ls_exp_gpio_f: pm8916-mpp4-state {
		pins = "mpp4";
		function = "digital";

		output-low;
		power-source = <PM8916_MPP_L5>;	/* 1.8V */
	};

	pm8916_mpps_leds: pm8916-mpps-state {
		pins = "mpp2", "mpp3";
		function = "digital";

		output-low;
	};
};
