// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2020, Konrad Dybcio
 */

/dts-v1/;

#include "msm8992.dtsi"
#include "pm8994.dtsi"
#include "pmi8994.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/gpio-keys.h>

/delete-node/ &adsp_mem;
/delete-node/ &audio_mem;
/delete-node/ &mpss_mem;
/delete-node/ &peripheral_region;
/delete-node/ &rmtfs_mem;

/ {
	model = "Xiaomi Mi 4C";
	compatible = "xiaomi,libra", "qcom,msm8992";
	chassis-type = "handset";

	/* required for bootloader to select correct board */
	qcom,msm-id = <251 0>, <252 0>;
	qcom,pmic-id = <65545 65546 0 0>;
	qcom,board-id = <12 0>;

	/* This enables graphical output via bootloader-enabled display */
	chosen {
		bootargs = "earlycon=tty0 console=tty0 maxcpus=1";

		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		framebuffer0: framebuffer@3400000 {
			compatible = "simple-framebuffer";
			reg = <0 0x3400000 0 (1080 * 1920 * 3)>;
			width = <1080>;
			height = <1920>;
			stride = <(1080 * 3)>;
			format = "r8g8b8";
			/*
			 * That's a lot of clocks, but it's necessary due
			 * to unused clk cleanup & no panel driver yet..
			 */
			clocks = <&mmcc MDSS_AHB_CLK>,
				 <&mmcc MDSS_AXI_CLK>,
				 <&mmcc MDSS_VSYNC_CLK>,
				 <&mmcc MDSS_MDP_CLK>,
				 <&mmcc MDSS_BYTE0_CLK>,
				 <&mmcc MDSS_PCLK0_CLK>,
				 <&mmcc MDSS_ESC0_CLK>;
			power-domains = <&mmcc MDSS_GDSC>;
		};
	};

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

		button {
			label = "Volume Up";
			gpios = <&pm8994_gpios 3 GPIO_ACTIVE_LOW>;
			linux,input-type = <1>;
			linux,code = <KEY_VOLUMEUP>;
			wakeup-source;
			debounce-interval = <15>;
		};
	};

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		memory_hole: hole@6400000 {
			reg = <0 0x06400000 0 0x600000>;
			no-map;
		};

		memory_hole2: hole2@6c00000 {
			reg = <0 0x06c00000 0 0x2400000>;
			no-map;
		};

		mpss_mem: mpss@9000000 {
			reg = <0 0x09000000 0 0x5a00000>;
			no-map;
		};

		tzapp: tzapp@ea00000 {
			reg = <0 0x0ea00000 0 0x1900000>;
			no-map;
		};

		mdm_rfsa_mem: mdm-rfsa@ca0b0000 {
			reg = <0 0xca0b0000 0 0x10000>;
			no-map;
		};

		rmtfs_mem: rmtfs@ca100000 {
			compatible = "qcom,rmtfs-mem";
			reg = <0 0xca100000 0 0x180000>;
			no-map;

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

		audio_mem: audio@cb400000 {
			reg = <0 0xcb000000 0 0x400000>;
			no-mem;
		};

		qseecom_mem: qseecom@cb400000 {
			reg = <0 0xcb400000 0 0x1c00000>;
			no-mem;
		};

		adsp_rfsa_mem: adsp-rfsa@cd000000 {
			reg = <0 0xcd000000 0 0x10000>;
			no-map;
		};

		sensor_rfsa_mem: sensor-rfsa@cd010000 {
			reg = <0 0xcd010000 0 0x10000>;
			no-map;
		};

		ramoops@dfc00000 {
			compatible = "ramoops";
			reg = <0 0xdfc00000 0 0x40000>;
			console-size = <0x10000>;
			record-size = <0x10000>;
			ftrace-size = <0x10000>;
			pmsg-size = <0x20000>;
		};
	};
};

&blsp1_i2c2 {
	status = "okay";

	/* Atmel or Synaptics touchscreen */
};

&blsp1_i2c5 {
	status = "okay";

	/* ST lsm6db0 gyro/accelerometer */
};

&blsp1_i2c6 {
	status = "okay";

	/*
	 * NXP NCI NFC,
	 * TI USB320 Type-C controller,
	 * Pericom 30216a USB (de)mux switch
	 */
};

&blsp2_i2c1 {
	status = "okay";

	/* cm36686 proximity and ambient light sensor */
};

&blsp2_i2c5 {
	status = "okay";

	/* Silabs si4705 FM transmitter */
};

&blsp2_uart2 {
	status = "okay";
};

&pm8994_spmi_regulators {
	VDD_APC0: s8 {
		regulator-min-microvolt = <680000>;
		regulator-max-microvolt = <1180000>;
		regulator-always-on;
		regulator-boot-on;
	};

	/* APC1 is 3-phase, but quoting downstream, s11 is "the gang leader" */
	VDD_APC1: s11 {
		regulator-min-microvolt = <700000>;
		regulator-max-microvolt = <1225000>;
		regulator-always-on;
		regulator-boot-on;
	};
};

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

		vdd_l1-supply = <&pm8994_s7>;
		vdd_l2_26_28-supply = <&pm8994_s3>;
		vdd_l3_11-supply = <&pm8994_s3>;
		vdd_l4_27_31-supply = <&pm8994_s3>;
		vdd_l5_7-supply = <&pm8994_s3>;
		vdd_l6_12_32-supply = <&pm8994_s5>;
		vdd_l8_16_30-supply = <&vph_pwr>;
		vdd_l9_10_18_22-supply = <&vph_pwr>;
		vdd_l13_19_23_24-supply = <&vph_pwr>;
		vdd_l14_15-supply = <&pm8994_s5>;
		vdd_l17_29-supply = <&vph_pwr>;
		vdd_l20_21-supply = <&vph_pwr>;
		vdd_l25-supply = <&pm8994_s5>;
		vdd_lvs1_2-supply = <&pm8994_s4>;

		/* S1, S2, S6 and S12 are managed by RPMPD */

		pm8994_s3: s3 {
			regulator-min-microvolt = <1300000>;
			regulator-max-microvolt = <1300000>;
		};

		pm8994_s4: s4 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
			regulator-always-on;
			regulator-system-load = <325000>;
		};

		pm8994_s5: s5 {
			regulator-min-microvolt = <2150000>;
			regulator-max-microvolt = <2150000>;
		};

		pm8994_s7: s7 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		/* S8, S9, S10 and S11 - SPMI-managed VDD_APC */

		pm8994_l1: l1 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l2: l2 {
			regulator-min-microvolt = <1250000>;
			regulator-max-microvolt = <1250000>;
		};

		pm8994_l3: l3 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8994_l4: l4 {
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
		};

		/* L5 is inaccessible from RPM */

		pm8994_l6: l6 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		/* L7 is inaccessible from RPM */

		pm8994_l8: l8 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l9: l9 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l10: l10 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l11: l11 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8994_l12: l12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l13: l13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
		};

		pm8994_l14: l14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l15: l15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l16: l16 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};

		pm8994_l17: l17 {
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <2700000>;
		};

		pm8994_l18: l18 {
			regulator-min-microvolt = <2850000>;
			regulator-max-microvolt = <2850000>;
			regulator-always-on;
		};

		pm8994_l19: l19 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l20: l20 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-always-on;
			regulator-boot-on;
			regulator-allow-set-load;
			regulator-system-load = <570000>;
		};

		pm8994_l21: l21 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-always-on;
		};

		pm8994_l22: l22 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3000000>;
		};

		pm8994_l23: l23 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l24: l24 {
			regulator-min-microvolt = <3075000>;
			regulator-max-microvolt = <3150000>;
		};

		pm8994_l25: l25 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l26: l26 {
			regulator-min-microvolt = <987500>;
			regulator-max-microvolt = <987500>;

		};

		pm8994_l27: l27 {
			regulator-min-microvolt = <1050000>;
			regulator-max-microvolt = <1050000>;
		};

		pm8994_l28: l28 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
		};

		pm8994_l29: l29 {
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};

		pm8994_l30: l30 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_l31: l31 {
			regulator-min-microvolt = <1262500>;
			regulator-max-microvolt = <1262500>;
		};

		pm8994_l32: l32 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8994_lvs1: lvs1 {};
		pm8994_lvs2: lvs2 {};
	};

	pmi8994_regulators: regulators-1 {
		compatible = "qcom,rpm-pmi8994-regulators";
		vdd_s1-supply = <&vph_pwr>;
		vdd_bst_byp-supply = <&vph_pwr>;

		pmi8994_s1: s1 {
			regulator-min-microvolt = <1025000>;
			regulator-max-microvolt = <1025000>;
		};

		/* S2 & S3 - VDD_GFX */

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

&sdhc1 {
	status = "okay";

	mmc-hs400-1_8v;
	vmmc-supply = <&pm8994_l20>;
	vqmmc-supply = <&pm8994_s4>;
};