// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
 */

/ {
	aliases {
		serial0 = &uart13;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

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

		key-volume-up {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&pm7550_gpios 6 GPIO_ACTIVE_LOW>;
			debounce-interval = <10>;
			linux,can-disable;
			wakeup-source;
		};
	};

	pmic-glink {
		compatible = "qcom,eliza-pmic-glink",
			     "qcom,sm8550-pmic-glink",
			     "qcom,pmic-glink";
		#address-cells = <1>;
		#size-cells = <0>;
		orientation-gpios = <&tlmm 122 GPIO_ACTIVE_HIGH>;

		connector@0 {
			compatible = "usb-c-connector";
			reg = <0>;

			power-role = "dual";
			data-role = "dual";

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

				port@0 {
					reg = <0>;

					pmic_glink_hs_in: endpoint {
						remote-endpoint = <&usb_dwc3_hs>;
					};
				};

				port@1 {
					reg = <1>;

					pmic_glink_ss_in: endpoint {
						remote-endpoint = <&usb_dp_qmpphy_out>;
					};
				};
			};
		};
	};

	vreg_0p9: regulator-0v9 {
		compatible = "regulator-fixed";
		regulator-name = "VREG_0P9";

		regulator-min-microvolt = <900000>;
		regulator-max-microvolt = <900000>;
		regulator-always-on;
		regulator-boot-on;
	};

	vreg_1p8: regulator-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "VREG_1P8";

		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
		regulator-boot-on;
	};

	vreg_pcie_m_3p3: regulator-3p3 {
		compatible = "regulator-fixed";

		regulator-name = "vreg_3p3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;

		gpio = <&gpio_expander1 6 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	connector-0 {
		compatible = "pcie-m2-e-connector";
		vpcie3v3-supply = <&vreg_pcie_m_3p3>;
		w-disable1-gpios = <&tlmm 35 GPIO_ACTIVE_LOW>;
		w-disable2-gpios = <&pm8550vs_g_gpios 4 GPIO_ACTIVE_HIGH>;

		pinctrl-0 = <&m2_w_disable1>, <&m2_w_disable2>;
		pinctrl-names = "default";

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

			port@0 {
				reg = <0>;
				#address-cells = <1>;
				#size-cells = <0>;

				m2_e_pcie_ep: endpoint@0 {
					reg = <0>;
					remote-endpoint = <&pcieport0_ep>;
				};
			};

			port@3 {
				reg = <3>;
				#address-cells = <1>;
				#size-cells = <0>;

				m2_e_uart_ep: endpoint@0 {
					reg = <0>;
					remote-endpoint = <&uart5_ep>;
				};
			};
		};
	};
};

&i2c4 {
	pinctrl-0 = <&qup_i2c4_data_clk>;
	pinctrl-names = "default";

	clock-frequency = <400000>;

	status = "okay";

	gpio_expander1: gpio@3c {
		compatible = "ti,tca9538";
		#gpio-cells = <2>;
		gpio-controller;
		reg = <0x3c>;
	};
};

&pcie0 {
	status = "okay";
};

&pcie0_phy {
	vdda-phy-supply = <&vreg_l1k>;
	vdda-pll-supply = <&vreg_l3k>;

	status = "okay";
};

&pcie0_port0 {
	wake-gpios = <&tlmm 114 GPIO_ACTIVE_LOW>;
	reset-gpios = <&tlmm 78 GPIO_ACTIVE_LOW>;

	port {
		pcieport0_ep: endpoint {
			remote-endpoint = <&m2_e_pcie_ep>;
		};
	};
};

&pon_pwrkey {
	status = "okay";
};

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

&pm7550ba_eusb2_repeater {
	vdd18-supply = <&vreg_l7b>;
	vdd3-supply = <&vreg_l17b>;
};

&sdhc_2 {
	vmmc-supply = <&vreg_l13b>;
	vqmmc-supply = <&vreg_l23b>;

	cd-gpios = <&tlmm 58 GPIO_ACTIVE_LOW>;

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

	status = "okay";
};

&tlmm {
	sd_cd: sd-cd-state {
		pins = "gpio58";
		function = "gpio";
		bias-pull-up;
	};
};

&pcie1 {
	iommu-map = <0x0 &apps_smmu 0x1400 0x0 0x1>,
		    <0x100 &apps_smmu 0x1401 0x0 0x1>,
		    <0x208 &apps_smmu 0x1402 0x0 0x1>,
		    <0x210 &apps_smmu 0x1403 0x0 0x1>,
		    <0x218 &apps_smmu 0x1404 0x0 0x1>,
		    <0x300 &apps_smmu 0x1405 0x0 0x1>,
		    <0x400 &apps_smmu 0x1406 0x0 0x1>,
		    <0x500 &apps_smmu 0x1407 0x0 0x1>,
		    <0x501 &apps_smmu 0x1408 0x0 0x1>;

	status = "okay";
};

&pcie1_phy {
	vdda-phy-supply = <&vreg_l1k>;
	vdda-pll-supply = <&vreg_l3k>;

	status = "okay";
};

&pcie1_port0 {
	wake-gpios = <&tlmm 53 GPIO_ACTIVE_LOW>;
	/* Same GPIO is used for both PERST# and resx-gpio */

	tc9563: pcie@0,0 {
		compatible = "pci1179,0623";
		reg = <0x10000 0x0 0x0 0x0 0x0>;
		#address-cells = <3>;
		#size-cells = <2>;

		device_type = "pci";
		ranges;
		bus-range = <0x2 0xff>;

		vddc-supply = <&vreg_0p9>;
		vdd18-supply = <&vreg_1p8>;
		vdd09-supply = <&vreg_0p9>;
		vddio1-supply = <&vreg_1p8>;
		vddio2-supply = <&vreg_1p8>;
		vddio18-supply = <&vreg_1p8>;

		i2c-parent = <&i2c4 0x77>;

		resx-gpios = <&tlmm 54 GPIO_ACTIVE_LOW>;

		pcie@1,0 {
			reg = <0x20800 0x0 0x0 0x0 0x0>;
			#address-cells = <3>;
			#size-cells = <2>;

			device_type = "pci";
			ranges;
			bus-range = <0x3 0xff>;
		};

		pcie@2,0 {
			reg = <0x21000 0x0 0x0 0x0 0x0>;
			#address-cells = <3>;
			#size-cells = <2>;

			device_type = "pci";
			ranges;
			bus-range = <0x4 0xff>;
		};

		pcie@3,0 {
			reg = <0x21800 0x0 0x0 0x0 0x0>;
			#address-cells = <3>;
			#size-cells = <2>;
			device_type = "pci";
			ranges;
			bus-range = <0x5 0xff>;

			ethernet@0,0 {
				reg = <0x50000 0x0 0x0 0x0 0x0>;
			};

			ethernet@0,1 {
				reg = <0x50100 0x0 0x0 0x0 0x0>;
			};
		};
	};
};

&uart13 {
	compatible = "qcom,geni-debug-uart";

	status = "okay";
};

&usb {
	status = "okay";
};

&usb_dp_qmpphy {
	vdda-phy-supply = <&vreg_l3g>;
	vdda-pll-supply = <&vreg_l7k>;

	status = "okay";
};

&usb_dp_qmpphy_out {
	remote-endpoint = <&pmic_glink_ss_in>;
};

&usb_dwc3_hs {
	remote-endpoint = <&pmic_glink_hs_in>;
};

&usb_hsphy {
	vdd-supply = <&vreg_l7k>;
	vdda12-supply = <&vreg_l4b>;

	phys = <&pm7550ba_eusb2_repeater>;

	status = "okay";
};

&uart5 {
	status = "okay";

	port {
		uart5_ep: endpoint {
			remote-endpoint = <&m2_e_uart_ep>;
		};
	};
};

&pm8550vs_g_gpios {
	m2_w_disable2: m2-w-disable2-state {
		pins = "gpio4";
		function = "normal";
		input-disable;
		output-enable;
		bias-disable;
		power-source = <2>;
	};
};

&tlmm {
	m2_w_disable1: m2-w-disable1-state {
		pins = "gpio35";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
	};
};