// SPDX-License-Identifier: GPL-2.0

/dts-v1/;

#include <dt-bindings/leds/common.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>
#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
#include <dt-bindings/sound/qcom,q6afe.h>
#include <dt-bindings/sound/qcom,q6asm.h>
#include "sdm845.dtsi"
#include "sdm845-wcd9340.dtsi"
#include "pm8998.dtsi"
#include "pmi8998.dtsi"

/*
 * Delete following upstream (sdm845.dtsi) reserved
 * memory mappings which are different in this device.
 */
/delete-node/ &tz_mem;
/delete-node/ &adsp_mem;
/delete-node/ &wlan_msa_mem;
/delete-node/ &mpss_region;
/delete-node/ &venus_mem;
/delete-node/ &cdsp_mem;
/delete-node/ &mba_region;
/delete-node/ &slpi_mem;
/delete-node/ &spss_mem;
/delete-node/ &rmtfs_mem;

/ {
	chassis-type = "handset";

	/* required for bootloader to select correct board */
	qcom,board-id = <69 0>;
	qcom,msm-id = <321 0x20001>;

	aliases {
		serial1 = &uart6;
	};

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

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

		key-vol-up {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&pm8998_gpios 6 GPIO_ACTIVE_LOW>;
		};
	};

	/* Reserved memory changes from downstream */
	reserved-memory {
		tz_mem: memory@86200000 {
			reg = <0 0x86200000 0 0x4900000>;
			no-map;
		};

		adsp_mem: memory@8c500000 {
			reg = <0 0x8c500000 0 0x1e00000>;
			no-map;
		};

		wlan_msa_mem: memory@8e300000 {
			reg = <0 0x8e300000 0 0x100000>;
			no-map;
		};

		mpss_region: memory@8e400000 {
			reg = <0 0x8e400000 0 0x7800000>;
			no-map;
		};

		venus_mem: memory@95c00000 {
			reg = <0 0x95c00000 0 0x500000>;
			no-map;
		};

		cdsp_mem: memory@96100000 {
			reg = <0 0x96100000 0 0x800000>;
			no-map;
		};

		mba_region: memory@96900000 {
			reg = <0 0x96900000 0 0x200000>;
			no-map;
		};

		slpi_mem: memory@96b00000 {
			reg = <0 0x96b00000 0 0x1400000>;
			no-map;
		};

		spss_mem: memory@97f00000 {
			reg = <0 0x97f00000 0 0x100000>;
			no-map;
		};

		/* Cont splash region set up by the bootloader */
		cont_splash_mem: framebuffer@9d400000 {
			reg = <0 0x9d400000 0 0x2400000>;
			no-map;
		};

		rmtfs_mem: memory@f6301000 {
			compatible = "qcom,rmtfs-mem";
			reg = <0 0xf6301000 0 0x200000>;
			no-map;

			qcom,client-id = <1>;
			qcom,vmid = <15>;
		};
	};

	battery: battery {
		compatible = "simple-battery";

		charge-full-design-microamp-hours = <4000000>;
		voltage-min-design-microvolt = <3400000>;
		voltage-max-design-microvolt = <4400000>;
	};

	vreg_s4a_1p8: vreg-s4a-1p8 {
		compatible = "regulator-fixed";
		regulator-name = "vreg_s4a_1p8";

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

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

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

		vreg_l1a_0p875: ldo1 {
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <880000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l5a_0p8: ldo5 {
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			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_l12a_1p8: ldo12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

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

		vreg_l14a_1p8: ldo14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-boot-on;
			regulator-always-on;
		};

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

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

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

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

		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>;
		};

		vreg_l26a_1p2: ldo26 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-boot-on;
		};
	};
};

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

&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/beryllium/a630_zap.mbn";
	};
};

&ibb {
	regulator-min-microvolt = <4600000>;
	regulator-max-microvolt = <6000000>;
	regulator-over-current-protection;
	regulator-pull-down;
	regulator-soft-start;
	qcom,discharge-resistor-kohms = <300>;
};

&lab {
	regulator-min-microvolt = <4600000>;
	regulator-max-microvolt = <6000000>;
	regulator-over-current-protection;
	regulator-pull-down;
	regulator-soft-start;
};

&mdss {
	status = "okay";
};

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

	display_panel: panel@0 {
		reg = <0>;
		vddio-supply = <&vreg_l14a_1p8>;
		vddpos-supply = <&lab>;
		vddneg-supply = <&ibb>;

		backlight = <&pmi8998_wled>;
		reset-gpios = <&tlmm 6 GPIO_ACTIVE_LOW>;

		status = "disabled";

		port {
			panel_in_0: endpoint {
				remote-endpoint = <&mdss_dsi0_out>;
			};
		};
	};
};

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

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

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

&ipa {
	qcom,gsi-loader = "self";
	memory-region = <&ipa_fw_mem>;
	firmware-name = "qcom/sdm845/beryllium/ipa_fws.mbn";
	status = "okay";
};

&pm8998_gpios {
	vol_up_pin_a: vol-up-active-state {
		pins = "gpio6";
		function = "normal";
		input-enable;
		bias-pull-up;
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_NO>;
	};
};

&pmi8998_lpg {
	status = "okay";

	led@5 {
		reg = <5>;
		color = <LED_COLOR_ID_WHITE>;
		function = LED_FUNCTION_STATUS;
	};
};

&pmi8998_wled {
	status = "okay";
	qcom,current-boost-limit = <970>;
	qcom,ovp-millivolt = <29600>;
	qcom,current-limit-microamp = <20000>;
	qcom,num-strings = <2>;
	qcom,switching-freq = <600>;
	qcom,external-pfet;
	qcom,cabc;
};

&pmi8998_charger {
	monitored-battery = <&battery>;

	status = "okay";
};

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

/* QUAT I2S Uses 1 I2S SD Line for audio on TAS2559/60 amplifiers */
&q6afedai {
	dai@22 {
		reg = <QUATERNARY_MI2S_RX>;
		qcom,sd-lines = <0>;
	};
};

&q6asmdai {
	dai@0 {
		reg = <0>;
	};

	dai@1 {
		reg = <1>;
	};

	dai@2 {
		reg = <2>;
	};
};

&qupv3_id_0 {
	status = "okay";
};

&sdhc_2 {
	status = "okay";

	pinctrl-names = "default";
	pinctrl-0 = <&sdc2_default_state &sdc2_card_det_n>;

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

	bus-width = <4>;
	cd-gpios = <&tlmm 126 GPIO_ACTIVE_HIGH>;
};

&sound {
	compatible = "qcom,db845c-sndcard", "qcom,sdm845-sndcard";
	pinctrl-0 = <&quat_mi2s_active
			&quat_mi2s_sd0_active>;
	pinctrl-names = "default";
	model = "Xiaomi Poco F1";
	audio-routing =
		"RX_BIAS", "MCLK",
		"AMIC1", "MIC BIAS1",
		"AMIC2", "MIC BIAS2",
		"AMIC3", "MIC BIAS3";

	mm1-dai-link {
		link-name = "MultiMedia1";
		cpu {
			sound-dai = <&q6asmdai  MSM_FRONTEND_DAI_MULTIMEDIA1>;
		};
	};

	mm2-dai-link {
		link-name = "MultiMedia2";
		cpu {
			sound-dai = <&q6asmdai  MSM_FRONTEND_DAI_MULTIMEDIA2>;
		};
	};

	mm3-dai-link {
		link-name = "MultiMedia3";
		cpu {
			sound-dai = <&q6asmdai  MSM_FRONTEND_DAI_MULTIMEDIA3>;
		};
	};

	slim-dai-link {
		link-name = "SLIM Playback";
		cpu {
			sound-dai = <&q6afedai SLIMBUS_0_RX>;
		};

		platform {
			sound-dai = <&q6routing>;
		};

		codec {
			sound-dai = <&wcd9340 0>;
		};
	};

	slimcap-dai-link {
		link-name = "SLIM Capture";
		cpu {
			sound-dai = <&q6afedai SLIMBUS_0_TX>;
		};

		platform {
			sound-dai = <&q6routing>;
		};

		codec {
			sound-dai = <&wcd9340 1>;
		};
	};
};

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

	sdc2_default_state: sdc2-default-state {
		clk-pins {
			pins = "sdc2_clk";
			bias-disable;
			drive-strength = <16>;
		};

		cmd-pins {
			pins = "sdc2_cmd";
			bias-pull-up;
			drive-strength = <10>;
		};

		data-pins {
			pins = "sdc2_data";
			bias-pull-up;
			drive-strength = <10>;
		};
	};

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

&uart6 {
	status = "okay";

	pinctrl-0 = <&qup_uart6_4pin>;

	bluetooth {
		compatible = "qcom,wcn3990-bt";

		vddio-supply = <&vreg_s4a_1p8>;
		vddxo-supply = <&vreg_l7a_1p8>;
		vddrf-supply = <&vreg_l17a_1p3>;
		vddch0-supply = <&vreg_l25a_3p3>;
		max-speed = <3200000>;
	};
};

&ufs_mem_hc {
	status = "okay";

	reset-gpios = <&tlmm 150 GPIO_ACTIVE_LOW>;

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

&ufs_mem_phy {
	status = "okay";

	vdda-phy-supply = <&vreg_l1a_0p875>;
	vdda-pll-supply = <&vreg_l26a_1p2>;
};

&usb_1 {
	status = "okay";
};

&usb_1_dwc3 {
	dr_mode = "peripheral";
};

&usb_1_hsphy {
	status = "okay";

	vdd-supply = <&vreg_l1a_0p875>;
	vdda-pll-supply = <&vreg_l12a_1p8>;
	vdda-phy-dpdm-supply = <&vreg_l24a_3p075>;

	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 = <&vreg_l26a_1p2>;
	vdda-pll-supply = <&vreg_l1a_0p875>;
};

&venus {
	status = "okay";
	firmware-name = "qcom/sdm845/beryllium/venus.mbn";
};

&wcd9340 {
	reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
	vdd-buck-supply = <&vreg_s4a_1p8>;
	vdd-buck-sido-supply = <&vreg_s4a_1p8>;
	vdd-tx-supply = <&vreg_s4a_1p8>;
	vdd-rx-supply = <&vreg_s4a_1p8>;
	vdd-io-supply = <&vreg_s4a_1p8>;
	qcom,micbias1-microvolt = <2700000>;
	qcom,micbias2-microvolt = <1800000>;
	qcom,micbias3-microvolt = <2700000>;
	qcom,micbias4-microvolt = <2700000>;
};

&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>;
	vdd-3.3-ch1-supply = <&vreg_l23a_3p3>;
};