// SPDX-License-Identifier: GPL-2.0
/*
 * SDM845 MTP board device tree source
 *
 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
 */

/dts-v1/;

#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
#include "sdm845.dtsi"
#include "pm8998.dtsi"
#include "pmi8998.dtsi"

/ {
	model = "Qualcomm Technologies, Inc. SDM845 MTP";
	compatible = "qcom,sdm845-mtp", "qcom,sdm845";
	chassis-type = "handset";

	aliases {
		serial0 = &uart9;
	};

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

	vph_pwr: vph-pwr-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vph_pwr";
		regulator-min-microvolt = <3700000>;
		regulator-max-microvolt = <3700000>;
	};

	/*
	 * Apparently RPMh does not provide support for PM8998 S4 because it
	 * is always-on; model it as a fixed regulator.
	 */
	vreg_s4a_1p8: pm8998-smps4 {
		compatible = "regulator-fixed";
		regulator-name = "vreg_s4a_1p8";

		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		regulator-always-on;
		regulator-boot-on;

		vin-supply = <&vph_pwr>;
	};

	thermal-zones {
		xo_thermal: xo-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;

			thermal-sensors = <&pm8998_adc_tm 1>;

			trips {
				trip-point {
					temperature = <125000>;
					hysteresis = <10000>;
					type = "passive";
				};
			};
		};

		msm_thermal: msm-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;

			thermal-sensors = <&pm8998_adc_tm 2>;

			trips {
				trip-point {
					temperature = <125000>;
					hysteresis = <10000>;
					type = "passive";
				};
			};
		};

		pa_thermal: pa-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;

			thermal-sensors = <&pm8998_adc_tm 3>;

			trips {
				trip-point {
					temperature = <125000>;
					hysteresis = <10000>;
					type = "passive";
				};
			};
		};

		quiet_thermal: quiet-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;

			thermal-sensors = <&pm8998_adc_tm 4>;

			trips {
				trip-point {
					temperature = <125000>;
					hysteresis = <10000>;
					type = "passive";
				};
			};
		};
	};
};

&adsp_pas {
	status = "okay";
	firmware-name = "qcom/sdm845/adsp.mdt";
};

&apps_rsc {
	regulators-0 {
		compatible = "qcom,pm8998-rpmh-regulators";
		qcom,pmic-id = "a";

		vdd-s1-supply = <&vph_pwr>;
		vdd-s2-supply = <&vph_pwr>;
		vdd-s3-supply = <&vph_pwr>;
		vdd-s4-supply = <&vph_pwr>;
		vdd-s5-supply = <&vph_pwr>;
		vdd-s6-supply = <&vph_pwr>;
		vdd-s7-supply = <&vph_pwr>;
		vdd-s8-supply = <&vph_pwr>;
		vdd-s9-supply = <&vph_pwr>;
		vdd-s10-supply = <&vph_pwr>;
		vdd-s11-supply = <&vph_pwr>;
		vdd-s12-supply = <&vph_pwr>;
		vdd-s13-supply = <&vph_pwr>;
		vdd-l1-l27-supply = <&vreg_s7a_1p025>;
		vdd-l2-l8-l17-supply = <&vreg_s3a_1p35>;
		vdd-l3-l11-supply = <&vreg_s7a_1p025>;
		vdd-l4-l5-supply = <&vreg_s7a_1p025>;
		vdd-l6-supply = <&vph_pwr>;
		vdd-l7-l12-l14-l15-supply = <&vreg_s5a_2p04>;
		vdd-l9-supply = <&vreg_bob>;
		vdd-l10-l23-l25-supply = <&vreg_bob>;
		vdd-l13-l19-l21-supply = <&vreg_bob>;
		vdd-l16-l28-supply = <&vreg_bob>;
		vdd-l18-l22-supply = <&vreg_bob>;
		vdd-l20-l24-supply = <&vreg_bob>;
		vdd-l26-supply = <&vreg_s3a_1p35>;
		vin-lvs-1-2-supply = <&vreg_s4a_1p8>;

		vreg_s2a_1p125: smps2 {
			regulator-min-microvolt = <1100000>;
			regulator-max-microvolt = <1100000>;
		};

		vreg_s3a_1p35: smps3 {
			regulator-min-microvolt = <1352000>;
			regulator-max-microvolt = <1352000>;
		};

		vreg_s5a_2p04: smps5 {
			regulator-min-microvolt = <1904000>;
			regulator-max-microvolt = <2040000>;
		};

		vreg_s7a_1p025: smps7 {
			regulator-min-microvolt = <900000>;
			regulator-max-microvolt = <1028000>;
		};

		vdd_qusb_hs0:
		vdda_hp_pcie_core:
		vdda_mipi_csi0_0p9:
		vdda_mipi_csi1_0p9:
		vdda_mipi_csi2_0p9:
		vdda_mipi_dsi0_pll:
		vdda_mipi_dsi1_pll:
		vdda_qlink_lv:
		vdda_qlink_lv_ck:
		vdda_qrefs_0p875:
		vdda_pcie_core:
		vdda_pll_cc_ebi01:
		vdda_pll_cc_ebi23:
		vdda_sp_sensor:
		vdda_ufs1_core:
		vdda_ufs2_core:
		vdda_usb1_ss_core:
		vdda_usb2_ss_core:
		vreg_l1a_0p875: ldo1 {
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <880000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_10:
		vreg_l2a_1p2: ldo2 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-always-on;
		};

		vreg_l3a_1p0: ldo3 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdd_wcss_cx:
		vdd_wcss_mx:
		vdda_wcss_pll:
		vreg_l5a_0p8: ldo5 {
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_13:
		vreg_l6a_1p8: ldo6 {
			regulator-min-microvolt = <1856000>;
			regulator-max-microvolt = <1856000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l7a_1p8: ldo7 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l8a_1p2: ldo8 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1248000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l9a_1p8: ldo9 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l10a_1p8: ldo10 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l11a_1p0: ldo11 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1048000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdd_qfprom:
		vdd_qfprom_sp:
		vdda_apc1_cs_1p8:
		vdda_gfx_cs_1p8:
		vdda_qrefs_1p8:
		vdda_qusb_hs0_1p8:
		vddpx_11:
		vreg_l12a_1p8: ldo12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_2:
		vreg_l13a_2p95: ldo13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l14a_1p88: ldo14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l15a_1p8: ldo15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l16a_2p7: ldo16 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2704000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l17a_1p3: ldo17 {
			regulator-min-microvolt = <1304000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l18a_2p7: ldo18 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l19a_3p0: ldo19 {
			regulator-min-microvolt = <2856000>;
			regulator-max-microvolt = <3104000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l20a_2p95: ldo20 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l21a_2p95: ldo21 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l22a_2p85: ldo22 {
			regulator-min-microvolt = <2864000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l23a_3p3: ldo23 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdda_qusb_hs0_3p1:
		vreg_l24a_3p075: ldo24 {
			regulator-min-microvolt = <3088000>;
			regulator-max-microvolt = <3088000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l25a_3p3: ldo25 {
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdda_hp_pcie_1p2:
		vdda_hv_ebi0:
		vdda_hv_ebi1:
		vdda_hv_ebi2:
		vdda_hv_ebi3:
		vdda_mipi_csi_1p25:
		vdda_mipi_dsi0_1p2:
		vdda_mipi_dsi1_1p2:
		vdda_pcie_1p2:
		vdda_ufs1_1p2:
		vdda_ufs2_1p2:
		vdda_usb1_ss_1p2:
		vdda_usb2_ss_1p2:
		vreg_l26a_1p2: ldo26 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l28a_3p0: ldo28 {
			regulator-min-microvolt = <2856000>;
			regulator-max-microvolt = <3008000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_lvs1a_1p8: lvs1 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		vreg_lvs2a_1p8: lvs2 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
	};

	regulators-1 {
		compatible = "qcom,pmi8998-rpmh-regulators";
		qcom,pmic-id = "b";

		vdd-bob-supply = <&vph_pwr>;

		vreg_bob: bob {
			regulator-min-microvolt = <3312000>;
			regulator-max-microvolt = <3600000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_AUTO>;
			regulator-allow-bypass;
		};
	};

	regulators-2 {
		compatible = "qcom,pm8005-rpmh-regulators";
		qcom,pmic-id = "c";

		vdd-s1-supply = <&vph_pwr>;
		vdd-s2-supply = <&vph_pwr>;
		vdd-s3-supply = <&vph_pwr>;
		vdd-s4-supply = <&vph_pwr>;

		vreg_s3c_0p6: smps3 {
			regulator-min-microvolt = <600000>;
			regulator-max-microvolt = <600000>;
		};
	};
};

&cdsp_pas {
	status = "okay";
	firmware-name = "qcom/sdm845/cdsp.mdt";
};

&gcc {
	protected-clocks = <GCC_QSPI_CORE_CLK>,
			   <GCC_QSPI_CORE_CLK_SRC>,
			   <GCC_QSPI_CNOC_PERIPH_AHB_CLK>,
			   <GCC_LPASS_Q6_AXI_CLK>,
			   <GCC_LPASS_SWAY_CLK>;
};

&gmu {
	status = "okay";
};

&gpu {
	status = "okay";

	zap-shader {
		memory-region = <&gpu_mem>;
		firmware-name = "qcom/sdm845/a630_zap.mbn";
	};
};

&i2c10 {
	status = "okay";
	clock-frequency = <400000>;
};

&ipa {
	qcom,gsi-loader = "self";
	memory-region = <&ipa_fw_mem>;
	status = "okay";
};

&mdss {
	status = "okay";
};

&mdss_dsi0 {
	status = "okay";
	vdda-supply = <&vdda_mipi_dsi0_1p2>;

	qcom,dual-dsi-mode;
	qcom,master-dsi;

	ports {
		port@1 {
			endpoint {
				remote-endpoint = <&truly_in_0>;
				data-lanes = <0 1 2 3>;
			};
		};
	};

	panel@0 {
		compatible = "truly,nt35597-2K-display";
		reg = <0>;
		vdda-supply = <&vreg_l14a_1p88>;

		reset-gpios = <&tlmm 6 GPIO_ACTIVE_LOW>;
		mode-gpios = <&tlmm 52 GPIO_ACTIVE_HIGH>;

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

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

			port@1 {
				reg = <1>;
				truly_in_1: endpoint {
					remote-endpoint = <&mdss_dsi1_out>;
				};
			};
		};
	};
};

&mdss_dsi0_phy {
	status = "okay";
	vdds-supply = <&vdda_mipi_dsi0_pll>;
};

&mdss_dsi1 {
	status = "okay";
	vdda-supply = <&vdda_mipi_dsi1_1p2>;

	qcom,dual-dsi-mode;

	/* DSI1 is slave, so use DSI0 clocks */
	assigned-clock-parents = <&mdss_dsi0_phy 0>, <&mdss_dsi0_phy 1>;

	ports {
		port@1 {
			endpoint {
				remote-endpoint = <&truly_in_1>;
				data-lanes = <0 1 2 3>;
			};
		};
	};
};

&mdss_dsi1_phy {
	status = "okay";
	vdds-supply = <&vdda_mipi_dsi1_pll>;
};

&mss_pil {
	status = "okay";
	firmware-name = "qcom/sdm845/mba.mbn", "qcom/sdm845/modem.mbn";
};

&pm8998_adc {
	channel@4c {
		reg = <ADC5_XO_THERM_100K_PU>;
		label = "xo_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	channel@4d {
		reg = <ADC5_AMUX_THM1_100K_PU>;
		label = "msm_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	channel@4f {
		reg = <ADC5_AMUX_THM3_100K_PU>;
		label = "pa_therm1";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	channel@51 {
		reg = <ADC5_AMUX_THM5_100K_PU>;
		label = "quiet_therm";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	channel@83 {
		reg = <ADC5_VPH_PWR>;
		label = "vph_pwr";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};

	channel@85 {
		reg = <ADC5_VCOIN>;
		label = "vcoin";
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
	};
};

&pm8998_adc_tm {
	status = "okay";

	xo-thermistor@1 {
		reg = <1>;
		io-channels = <&pm8998_adc ADC5_XO_THERM_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	msm-thermistor@2 {
		reg = <2>;
		io-channels = <&pm8998_adc ADC5_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	pa-thermistor@3 {
		reg = <3>;
		io-channels = <&pm8998_adc ADC5_AMUX_THM3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	quiet-thermistor@4 {
		reg = <4>;
		io-channels = <&pm8998_adc ADC5_AMUX_THM5_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};
};

&qupv3_id_1 {
	status = "okay";
};

&sdhc_2 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&sdc2_clk &sdc2_cmd &sdc2_data &sd_card_det_n>;

	vmmc-supply = <&vreg_l21a_2p95>;
	vqmmc-supply = <&vddpx_2>;

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

&uart9 {
	status = "okay";
};

&ufs_mem_hc {
	status = "okay";

	reset-gpios = <&tlmm 150 GPIO_ACTIVE_LOW>;

	vcc-supply = <&vreg_l20a_2p95>;
	vcc-max-microamp = <600000>;
};

&ufs_mem_phy {
	status = "okay";

	vdda-phy-supply = <&vdda_ufs1_core>;
	vdda-pll-supply = <&vdda_ufs1_1p2>;
};

&usb_1 {
	status = "okay";
};

&usb_1_dwc3 {
	/* Until we have Type C hooked up we'll force this as peripheral. */
	dr_mode = "peripheral";
};

&usb_1_hsphy {
	status = "okay";

	vdd-supply = <&vdda_usb1_ss_core>;
	vdda-pll-supply = <&vdda_qusb_hs0_1p8>;
	vdda-phy-dpdm-supply = <&vdda_qusb_hs0_3p1>;

	qcom,imp-res-offset-value = <8>;
	qcom,hstx-trim-value = <QUSB2_V2_HSTX_TRIM_21_6_MA>;
	qcom,preemphasis-level = <QUSB2_V2_PREEMPHASIS_5_PERCENT>;
	qcom,preemphasis-width = <QUSB2_V2_PREEMPHASIS_WIDTH_HALF_BIT>;
};

&usb_1_qmpphy {
	status = "okay";

	vdda-phy-supply = <&vdda_usb1_ss_1p2>;
	vdda-pll-supply = <&vdda_usb1_ss_core>;
};

&usb_2 {
	status = "okay";
};

&usb_2_dwc3 {
	/*
	 * Though the USB block on SDM845 can support host, there's no vbus
	 * signal for this port on MTP.  Thus (unless you have a non-compliant
	 * hub that works without vbus) the only sensible thing is to force
	 * peripheral mode.
	 */
	dr_mode = "peripheral";
};

&usb_2_hsphy {
	status = "okay";

	vdd-supply = <&vdda_usb2_ss_core>;
	vdda-pll-supply = <&vdda_qusb_hs0_1p8>;
	vdda-phy-dpdm-supply = <&vdda_qusb_hs0_3p1>;

	qcom,imp-res-offset-value = <8>;
	qcom,hstx-trim-value = <QUSB2_V2_HSTX_TRIM_22_8_MA>;
};

&usb_2_qmpphy {
	status = "okay";

	vdda-phy-supply = <&vdda_usb2_ss_1p2>;
	vdda-pll-supply = <&vdda_usb2_ss_core>;
};

&venus {
	status = "okay";
};

&wifi {
	status = "okay";
	vdd-0.8-cx-mx-supply = <&vreg_l5a_0p8>;
	vdd-1.8-xo-supply = <&vreg_l7a_1p8>;
	vdd-1.3-rfa-supply = <&vreg_l17a_1p3>;
	vdd-3.3-ch0-supply = <&vreg_l25a_3p3>;
};

/* PINCTRL - additions to nodes defined in sdm845.dtsi */

&qup_i2c10_default {
	drive-strength = <2>;
	bias-disable;
};

&qup_uart9_rx {
	drive-strength = <2>;
	bias-pull-up;
};

&qup_uart9_tx {
	drive-strength = <2>;
	bias-disable;
};

&tlmm {
	gpio-reserved-ranges = <0 4>, <81 4>;

	sdc2_clk: sdc2-clk-state {
		pins = "sdc2_clk";
		bias-disable;

		/*
		 * It seems that mmc_test reports errors if drive
		 * strength is not 16 on clk, cmd, and data pins.
		 */
		drive-strength = <16>;
	};

	sdc2_cmd: sdc2-cmd-state {
		pins = "sdc2_cmd";
		bias-pull-up;
		drive-strength = <16>;
	};

	sdc2_data: sdc2-data-state {
		pins = "sdc2_data";
		bias-pull-up;
		drive-strength = <16>;
	};

	sd_card_det_n: sd-card-det-n-state {
		pins = "gpio126";
		function = "gpio";
		bias-pull-up;
	};
};