// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2020, Yassine Oudjana <y.oudjana@protonmail.com>
 */

#include "pm8994.dtsi"
#include "pmi8994.dtsi"
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>

/ {
	divclk1_cdc: divclk1 {
		compatible = "gpio-gate-clock";
		clocks = <&rpmcc RPM_SMD_DIV_CLK1>;
		#clock-cells = <0>;
		enable-gpios = <&pm8994_gpios 15 GPIO_ACTIVE_HIGH>;

		pinctrl-names = "default";
		pinctrl-0 = <&divclk1_default>;
	};

	divclk4: divclk4 {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <32768>;
		clock-output-names = "divclk4";

		pinctrl-names = "default";
		pinctrl-0 = <&divclk4_pin_a>;
	};

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

		key-vol-up {
			label = "Volume Up";
			gpios = <&pm8994_gpios 2 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_VOLUMEUP>;
			wakeup-source;
			debounce-interval = <15>;
		};

		key-dome {
			label = "Home";
			gpios = <&tlmm 34 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_HOME>;
			wakeup-source;
			debounce-interval = <15>;
		};
	};

	irled {
		compatible = "pwm-ir-tx";
		pwms = <&pm8994_lpg 1 1000000>;

		pinctrl-names = "default";
		pinctrl-0 = <&irled_default>;
	};

	reserved-memory {
		memory@88800000 {
			reg = <0x0 0x88800000 0x0 0x1400000>;
			no-map;
		};

		/* This platform has all PIL regions offset by 0x1400000 */
		/delete-node/ mpss@88800000;
		mpss_mem: mpss@89c00000 {
			reg = <0x0 0x89c00000 0x0 0x6200000>;
			no-map;
		};

		/delete-node/ adsp@8ea00000;
		adsp_mem: adsp@8fe00000 {
			reg = <0x0 0x8fe00000 0x0 0x1b00000>;
			no-map;
		};

		/delete-node/ slpi@90500000;
		slpi_mem: slpi@91900000 {
			reg = <0x0 0x91900000 0x0 0xa00000>;
			no-map;
		};

		/delete-node/ gpu@90f00000;
		gpu_mem: gpu@92300000 {
			compatible = "shared-dma-pool";
			reg = <0x0 0x92300000 0x0 0x2000>;
			no-map;
		};

		/delete-node/ venus@91000000;
		venus_mem: venus@92400000 {
			reg = <0x0 0x92400000 0x0 0x500000>;
			no-map;
		};

		ramoops@92900000 {
			compatible = "ramoops";
			reg = <0x0 0x92900000 0x0 0x100000>;
			no-map;

			record-size = <0x8000>;
			console-size = <0x80000>;
			ftrace-size = <0x20000>;
			pmsg-size = <0x40000>;
		};

		/delete-node/ rmtfs;
		rmtfs@f6c00000 {
			compatible = "qcom,rmtfs-mem";
			reg = <0 0xf6c00000 0 0x200000>;
			no-map;

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

		/delete-node/ mba@91500000;
		mba_mem: mba@f6f00000 {
			reg = <0x0 0xf6f00000 0x0 0x100000>;
			no-map;
		};
	};

	vph_pwr: vph-pwr-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vph_pwr";
		regulator-min-microvolt = <3800000>;
		regulator-max-microvolt = <3800000>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_3v2_tp: vdd-3v2-tp {
		compatible = "regulator-fixed";
		regulator-name = "vdd_3v2_tp";
		regulator-min-microvolt = <3200000>;
		regulator-max-microvolt = <3200000>;
		startup-delay-us = <4000>;
		vin-supply = <&vph_pwr>;

		gpio = <&tlmm 73 0>;
		enable-active-high;
	};

	vdd_3v3: rome-vreg {
		compatible = "regulator-fixed";
		regulator-name = "vdd_3v3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		startup-delay-us = <4000>;
		vin-supply = <&vph_pwr_bbyp>;

		gpio = <&pm8994_gpios 9 0>;
		enable-active-high;
		pinctrl-names = "default";
		pinctrl-0 = <&rome_enable_default>;

		/* Required by QCA6174a - vddpe-3v3 */
		regulator-always-on;
	};

	/* WL_EN pin defined as a fixed regulator */
	wlan_en: wlan-en-1-8v {
		compatible = "regulator-fixed";
		regulator-name = "wlan-en-regulator";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		gpio = <&pm8994_gpios 8 0>;
		/* WLAN card specific delay */
		startup-delay-us = <70000>;
		enable-active-high;
		pinctrl-names = "default";
		pinctrl-0 = <&wlan_en_default>;
	};
};

&adsp_pil {
	status = "okay";
};

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

	nfc: nfc@28 {
		compatible = "nxp,nxp-nci-i2c";

		reg = <0x28>;

		interrupt-parent = <&tlmm>;
		interrupts = <9 IRQ_TYPE_LEVEL_HIGH>;

		enable-gpios = <&tlmm 12 GPIO_ACTIVE_HIGH>;
		firmware-gpios = <&tlmm 21 GPIO_ACTIVE_HIGH>;

		pinctrl-names = "default";
		pinctrl-0 = <&nfc_default>;
	};
};

&blsp2_i2c3 {
	status = "okay";

	typec: typec@47 {
		compatible = "ti,tusb320l";
		reg = <0x47>;
		interrupt-parent = <&tlmm>;
		interrupts = <63 IRQ_TYPE_EDGE_RISING>;
	};
};

&blsp2_i2c6 {
	status = "okay";
	/* MSM_TS */
};

&blsp1_uart2 {
	status = "okay";
	label = "QCA_UART";

	bluetooth: bluetooth {
		compatible = "qcom,qca6174-bt";

		enable-gpios = <&pm8994_gpios 19 GPIO_ACTIVE_HIGH>;
		clocks = <&divclk4>;
	};
};

&gpu {
	status = "okay";
};

&mdss {
	status = "okay";
};

&mdss_dsi0 {
	status = "okay";

	vdd-supply = <&vreg_l2a_1p25>;
	vddio-supply = <&vreg_l14a_1p8>;

	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&mdss_dsi_default &mdss_te_default>;
	pinctrl-1 = <&mdss_dsi_sleep &mdss_te_sleep>;
};

&mdss_dsi0_out {
	status = "okay";

	data-lanes = <0 1 2 3>;
};

&mdss_dsi0_phy {
	status = "okay";

	vcca-supply = <&vreg_l28a_0p925>;
};

&mmcc {
	vdd-gfx-supply = <&vdd_gfx>;
};

&mss_pil {
	status = "okay";

	pll-supply = <&vreg_l12a_1p8>;
};

&pcie0 {
	status = "okay";

	/* Supplied by vdd_3v3, but choose wlan_en to drive enable pin high */
	vddpe-3v3-supply = <&wlan_en>;
	vdda-supply = <&vreg_l28a_0p925>;

	perst-gpios = <&tlmm 35 GPIO_ACTIVE_LOW>;
	wake-gpios = <&tlmm 37 GPIO_ACTIVE_HIGH>;
};

&pcie_phy {
	status = "okay";

	vdda-phy-supply = <&vreg_l28a_0p925>;
	vdda-pll-supply = <&vreg_l12a_1p8>;
};

&pm8994_resin {
	status = "okay";

	linux,code = <KEY_VOLUMEDOWN>;
};

&pm8994_lpg {
	status = "okay";

	qcom,power-source = <1>;
};

&pmi8994_lpg {
	status = "okay";

	qcom,power-source = <1>;

	multi-led {
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_STATUS;

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

		led@1 {
			reg = <1>;
			color = <LED_COLOR_ID_BLUE>;
		};

		led@2 {
			reg = <2>;
			color = <LED_COLOR_ID_GREEN>;
		};

		led@3 {
			reg = <3>;
			color = <LED_COLOR_ID_RED>;
		};
	};
};

&slim_msm {
	status = "okay";

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

		tasha_ifd: tas-ifd@0,0 {
			compatible = "slim217,1a0";
			reg = <0 0>;
		};

		wcd9335: codec@1,0 {
			compatible = "slim217,1a0";
			reg = <1 0>;

			clock-names = "mclk", "slimbus";
			clocks = <&divclk1_cdc>,
				 <&rpmcc RPM_SMD_BB_CLK1>;
			interrupt-parent = <&tlmm>;
			interrupts = <54 IRQ_TYPE_LEVEL_HIGH>,
				     <53 IRQ_TYPE_LEVEL_HIGH>;
			interrupt-names = "intr1", "intr2";
			interrupt-controller;
			#interrupt-cells = <1>;

			pinctrl-0 = <&cdc_reset_active &wcd_intr_default>;
			pinctrl-names = "default";

			reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>;
			slim-ifc-dev = <&tasha_ifd>;

			#sound-dai-cells = <1>;

			vdd-buck-supply = <&vreg_s4a_1p8>;
			vdd-buck-sido-supply = <&vreg_s4a_1p8>;
			vdd-rx-supply = <&vreg_s4a_1p8>;
			vdd-tx-supply = <&vreg_s4a_1p8>;
			vdd-vbat-supply = <&vph_pwr>;
			vdd-micbias-supply = <&vph_pwr_bbyp>;
			vdd-io-supply = <&vreg_s4a_1p8>;
		};
	};
};

&slpi_pil {
	status = "okay";

	px-supply = <&vreg_lvs2a_1p8>;
};

&usb3 {
	status = "okay";
	extcon = <&typec>;

	qcom,select-utmi-as-pipe-clk;
};

&usb3_dwc3 {
	extcon = <&typec>;

	/* usb3-phy is not used on this device */
	phys = <&hsusb_phy1>;
	phy-names = "usb2-phy";

	maximum-speed = "high-speed";
	snps,is-utmi-l1-suspend;
	snps,usb2-gadget-lpm-disable;
	snps,hird-threshold = /bits/ 8 <0>;
};

&hsusb_phy1 {
	status = "okay";
	extcon = <&typec>;

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

&ufshc {
	status = "okay";

	vcc-supply = <&vreg_l20a_2p95>;
	vccq-supply = <&vreg_l25a_1p2>;
	vccq2-supply = <&vreg_s4a_1p8>;

	vcc-max-microamp = <600000>;
	vccq-max-microamp = <450000>;
	vccq2-max-microamp = <450000>;
};

&ufsphy {
	status = "okay";

	vdda-phy-supply = <&vreg_l28a_0p925>;
	vdda-pll-supply = <&vreg_l12a_1p8>;
	vddp-ref-clk-supply = <&vreg_l25a_1p2>;
};

&venus {
	status = "okay";
};

&rpm_requests {
	regulators-0 {
		compatible = "qcom,rpm-pm8994-regulators";

		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_l1-supply = <&vreg_s1b_1p025>;
		vdd_l2_l26_l28-supply = <&vreg_s3a_1p3>;
		vdd_l3_l11-supply = <&vreg_s3a_1p3>;
		vdd_l4_l27_l31-supply = <&vreg_s3a_1p3>;
		vdd_l5_l7-supply = <&vreg_s5a_2p15>;
		vdd_l6_l12_l32-supply = <&vreg_s5a_2p15>;
		vdd_l8_l16_l30-supply = <&vph_pwr>;
		vdd_l9_l10_l18_l22-supply = <&vph_pwr_bbyp>;
		vdd_l13_l19_l23_l24-supply = <&vph_pwr_bbyp>;
		vdd_l14_l15-supply = <&vreg_s5a_2p15>;
		vdd_l17_l29-supply = <&vph_pwr_bbyp>;
		vdd_l20_l21-supply = <&vph_pwr_bbyp>;
		vdd_l25-supply = <&vreg_s3a_1p3>;
		vdd_lvs1_2-supply = <&vreg_s4a_1p8>;

		vreg_s3a_1p3: s3 {
			regulator-name = "vreg_s3a_1p3";
			regulator-min-microvolt = <1300000>;
			regulator-max-microvolt = <1300000>;

			/* Required by QCA6174a - vdd-core */
			regulator-always-on;
		};
		vreg_s4a_1p8: s4 {
			regulator-name = "vreg_s4a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;

			/* Required by QCA6174a - vddio */
			regulator-always-on;
		};
		vreg_s5a_2p15: s5 {
			regulator-name = "vreg_s5a_2p15";
			regulator-min-microvolt = <2150000>;
			regulator-max-microvolt = <2150000>;
		};
		vreg_s7a_0p8: s7 {
			regulator-name = "vreg_s7a_0p8";
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
		};
		vreg_l1a_1p0: l1 {
			regulator-name = "vreg_l1a_1p0";
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};
		vreg_l2a_1p25: l2 {
			regulator-name = "vreg_l2a_1p25";
			regulator-min-microvolt = <1250000>;
			regulator-max-microvolt = <1250000>;
		};
		vreg_l4a_1p225: l4 {
			regulator-name = "vreg_l4a_1p225";
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
		};
		vreg_l6a_1p8: l6 {
			regulator-name = "vreg_l6a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l8a_1p8: l8 {
			regulator-name = "vreg_l8a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l9a_1p8: l9 {
			regulator-name = "vreg_l9a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l10a_1p8: l10 {
			regulator-name = "vreg_l10a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l12a_1p8: l12 {
			regulator-name = "vreg_l12a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
		};
		vreg_l13a_2p95: l13 {
			regulator-name = "vreg_l13a_2p95";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};
		vreg_l14a_1p8: l14 {
			regulator-name = "vreg_l14a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l15a_1p8: l15 {
			regulator-name = "vreg_l15a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		vreg_l16a_2p7: l16 {
			regulator-name = "vreg_l16a_2p7";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};
		vreg_l19a_3p3: l19 {
			regulator-name = "vreg_l19a_3p3";
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3000000>;
		};
		vreg_l20a_2p95: l20 {
			regulator-name = "vreg_l20a_2p95";
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-allow-set-load;
		};
		vreg_l21a_2p95: l21 {
			regulator-name = "vreg_l21a_2p95";
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3300000>;
			regulator-always-on;
		};
		vreg_l23a_2p8: l23 {
			regulator-name = "vreg_l23a_2p8";
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};
		vreg_l24a_3p075: l24 {
			regulator-name = "vreg_l24a_3p075";
			regulator-min-microvolt = <3075000>;
			regulator-max-microvolt = <3075000>;
		};
		vreg_l25a_1p2: l25 {
			regulator-name = "vreg_l25a_1p2";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-allow-set-load;
		};
		vreg_l27a_1p2: l27 {
			regulator-name = "vreg_l27a_1p2";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};
		vreg_l28a_0p925: l28 {
			regulator-name = "vreg_l28a_0p925";
			regulator-min-microvolt = <925000>;
			regulator-max-microvolt = <925000>;
			regulator-allow-set-load;
		};
		vreg_l30a_1p8: l30 {
			regulator-name = "vreg_l30a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;

			/* Required by QCA6174a - vddio-xtal */
			regulator-always-on;
		};
		vreg_l32a_1p8: l32 {
			regulator-name = "vreg_l32a_1p8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};
		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,rpm-pmi8994-regulators";

		vdd_s1-supply = <&vph_pwr>;
		vdd_s2-supply = <&vph_pwr>;
		vdd_s3-supply = <&vph_pwr>;
		vdd_bst_byp-supply = <&vph_pwr>;

		vreg_s1b_1p025: s1 {
			regulator-name = "vreg_s1b_1p025";
			regulator-min-microvolt = <1025000>;
			regulator-max-microvolt = <1025000>;
		};

		vph_pwr_bbyp: boost-bypass {
			regulator-name = "vph_pwr_bbyp";
			regulator-min-microvolt = <3150000>;
			regulator-max-microvolt = <3600000>;
		};
	};
};

&pm8994_spmi_regulators {
	qcom,saw-reg = <&saw3>;
	s8 {
		qcom,saw-slave;
	};
	s9 {
		qcom,saw-slave;
	};
	s10 {
		qcom,saw-slave;
	};
	vreg_apc_0p8: s11 {
		qcom,saw-leader;
		regulator-name = "vreg_apc_0p8";
		regulator-min-microvolt = <470000>;
		regulator-max-microvolt = <1140000>;
		regulator-max-step-microvolt = <150000>;
		regulator-always-on;
	};
};

&pmi8994_spmi_regulators {
	vdd_gfx: s2 {
		regulator-name = "vdd_gfx";
		regulator-min-microvolt = <400000>;
		regulator-max-microvolt = <1015000>;
		regulator-enable-ramp-delay = <500>;
	};
};

&pm8994_gpios {
	irled_default: irled-default-state {
		pins = "gpio5";
		function = PMIC_GPIO_FUNC_FUNC1;
		output-low;
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_HIGH>;
		power-source = <PM8994_GPIO_S4>;
		bias-disable;
	};

	wlan_en_default: wlan-en-state {
		pins = "gpio8";
		function = PMIC_GPIO_FUNC_NORMAL;
		output-low;
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_LOW>;
		power-source = <PM8994_GPIO_S4>;
		bias-disable;
	};

	rome_enable_default: rome-enable-state {
		pins = "gpio9";
		function = PMIC_GPIO_FUNC_NORMAL;
		output-high;
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_LOW>;
		power-source = <PM8994_GPIO_VPH>;
	};

	divclk1_default: divclk1-state {
		pins = "gpio15";
		function = PMIC_GPIO_FUNC_FUNC1;
		bias-disable;
		power-source = <PM8994_GPIO_S4>;
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_LOW>;
	};

	divclk4_pin_a: divclk4-state {
		pins = "gpio18";
		function = PMIC_GPIO_FUNC_FUNC2;
		bias-disable;
		power-source = <PM8994_GPIO_S4>;
	};
};

&tlmm {
	mdss_dsi_default: mdss-dsi-default-state {
		pins = "gpio8";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	mdss_dsi_sleep: mdss-dsi-sleep-state {
		pins = "gpio8";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	mdss_te_default: mdss-te-default-state {
		pins = "gpio10";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};

	mdss_te_sleep: mdss-te-sleep-state {
		pins = "gpio10";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};

	nfc_default: nfc-default-state {
		pins = "gpio12", "gpio21";
		function = "gpio";
		drive-strength = <16>;
		bias-pull-up;
	};
};