// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (c) 2026 Adam Skladowski <a39skl@gmail.com>
 */

/dts-v1/;

#include "sm6115.dtsi"
#include "pm6125.dtsi"
#include "pmi632.dtsi"
#include <dt-bindings/leds/common.h>

/delete-node/ &pil_adsp_mem;
/delete-node/ &pil_gpu_mem;
/delete-node/ &pil_ipa_fw_mem;
/delete-node/ &pil_ipa_gsi_mem;

/ {
	model = "Xiaomi Redmi 9T";
	compatible = "xiaomi,lemon", "qcom,sm6115";
	chassis-type = "handset";

	aliases {
		mmc0 = &sdhc_2;
	};

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

		framebuffer0: framebuffer@5c000000 {
			compatible = "simple-framebuffer";
			reg = <0 0x5c000000 0 (2340 * 1080 * 4)>;
			width = <1080>;
			height = <2340>;
			stride = <(1080 * 4)>;
			format = "a8r8g8b8";
			clocks = <&gcc GCC_DISP_HF_AXI_CLK>;
		};
	};

	backlight_dsi: backlight-dsi {
		compatible = "led-backlight";
		leds = <&led_backlight>;
		brightness-levels = <255>;
		default-brightness-level = <190>;
		/* Backlight controllers can differ between panel variants */
		status = "disabled";
	};

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

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

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

	reserved-memory {
		pil_adsp_mem: memory@53400000 {
			reg = <0x0 0x53400000 0x0 0x2600000>;
			no-map;
		};

		pil_ipa_fw_mem: memory@55a00000 {
			reg = <0x0 0x55a00000 0x0 0x10000>;
			no-map;
		};

		pil_ipa_gsi_mem: memory@55a10000 {
			reg = <0x0 0x55a10000 0x0 0x5000>;
			no-map;
		};

		pil_gpu_mem: memory@fa400000 {
			reg = <0x0 0xfa400000 0x0 0x2000>;
			no-map;
		};

		ramoops: ramoops@64000000 {
			compatible = "ramoops";
			no-map;
			reg = <0x0 0x64000000 0x0 0x400000>;
			record-size = <0x100000>;
			console-size = <0x100000>;
			pmsg-size = <0x200000>;
			ecc-size = <16>;
		};
	};

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

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

&dispcc {
	/* Prevent simplefb from dying until we wire panel driver */
	status = "disabled";
};

&gpi_dma0 {
	status = "okay";
};

&gpu {
	status = "okay";
};

&i2c1 {
	status = "okay";

	lm36923_bl: led-controller@36 {
		compatible = "ti,lm36923";
		reg = <0x36>;

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

		enable-gpios = <&tlmm 99 GPIO_ACTIVE_HIGH>;
		ti,ovp-microvolt = <29000000>;
		/* Backlight controllers can differ between panel variants */
		status = "disabled";

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

		led_backlight: led@0 {
			reg = <0>;
			function = LED_FUNCTION_BACKLIGHT;
			color = <LED_COLOR_ID_WHITE>;
			label = ":backlight";
			linux,default-trigger = "backlight";
			led-max-microamp = <25000>;
		};
	};
};

&mdss_dsi0 {
	vdda-supply = <&pm6125_l18>;
};

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

&pil_cdsp_mem {
	reg = <0x0 0x51a00000 0x0 0xa00000>;
};

&pm6125_gpios {
	vol_up_n: vol-up-n-state {
		pins = "gpio5";
		function = "normal";
		power-source = <0>;
		bias-pull-up;
		input-enable;
	};
};

&pmi632_typec {
	status = "okay";

	connector {
		compatible = "usb-c-connector";

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

		typec-power-opmode = "default";
		pd-disable;

		vbus-supply = <&pmi632_vbus>;

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

			port@0 {
				reg = <0>;
				pmi632_hs_in: endpoint {
					remote-endpoint = <&usb_dwc3_hs>;
				};
			};

			port@1 {
				reg = <1>;
				pmi632_ss_in: endpoint {
					remote-endpoint = <&usb_qmpphy_out>;
				};
			};
		};
	};
};

&pmi632_vbus {
	regulator-min-microamp = <500000>;
	regulator-max-microamp = <1000000>;

	status = "okay";
};

&pon_pwrkey {
	status = "okay";
};

&pon_resin {
	linux,code = <KEY_VOLUMEDOWN>;

	status = "okay";
};

&qupv3_id_0 {
	status = "okay";
};

&remoteproc_adsp {
	status = "okay";
};

&remoteproc_cdsp {
	status = "okay";
};

&remoteproc_mpss {
	status = "okay";
};

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

		pm6125_s6: s6 {
			regulator-min-microvolt = <304000>;
			regulator-max-microvolt = <1456000>;
		};

		pm6125_s7: s7 {
			regulator-min-microvolt = <1280000>;
			regulator-max-microvolt = <2080000>;
		};

		pm6125_s8: s8 {
			regulator-min-microvolt = <1064000>;
			regulator-max-microvolt = <1304000>;
		};

		pm6125_l1: l1 {
			regulator-min-microvolt = <952000>;
			regulator-max-microvolt = <1152000>;
		};

		pm6125_l4: l4 {
			regulator-min-microvolt = <488000>;
			regulator-max-microvolt = <1000000>;
		};

		pm6125_l5: l5 {
			regulator-min-microvolt = <1648000>;
			regulator-max-microvolt = <2960000>;
			regulator-allow-set-load;

			regulator-always-on;
		};

		pm6125_l6: l6 {
			regulator-min-microvolt = <576000>;
			regulator-max-microvolt = <656000>;
		};

		pm6125_l7: l7 {
			/* sdhci2 vdd-io-bias supply */
			regulator-min-microvolt = <1256000>;
			regulator-max-microvolt = <1256000>;

			regulator-always-on;
		};

		pm6125_l8: l8 {
			regulator-min-microvolt = <400000>;
			regulator-max-microvolt = <728000>;
		};

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

		pm6125_l10: l10 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <1904000>;
		};

		pm6125_l11: l11 {
			regulator-min-microvolt = <1768000>;
			regulator-max-microvolt = <1952000>;
		};

		pm6125_l12: l12 {
			regulator-min-microvolt = <1624000>;
			regulator-max-microvolt = <1984000>;
		};

		pm6125_l13: l13 {
			regulator-min-microvolt = <1504000>;
			regulator-max-microvolt = <1952000>;
		};

		pm6125_l14: l14 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <1904000>;
		};

		pm6125_l15: l15 {
			regulator-min-microvolt = <2920000>;
			regulator-max-microvolt = <3232000>;
		};

		pm6125_l16: l16 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <1904000>;
		};

		pm6125_l17: l17 {
			regulator-min-microvolt = <1152000>;
			regulator-max-microvolt = <1384000>;
		};

		pm6125_l18: l18 {
			regulator-min-microvolt = <1232000>;
			regulator-max-microvolt = <1232000>;
		};

		pm6125_l19: l19 {
			regulator-min-microvolt = <1624000>;
			regulator-max-microvolt = <3304000>;
		};

		pm6125_l20: l20 {
			regulator-min-microvolt = <1624000>;
			regulator-max-microvolt = <3304000>;
		};

		pm6125_l21: l21 {
			regulator-min-microvolt = <2400000>;
			regulator-max-microvolt = <3600000>;
		};

		pm6125_l22: l22 {
			regulator-min-microvolt = <2952000>;
			regulator-max-microvolt = <2960000>;
			regulator-allow-set-load;

			regulator-always-on;
		};

		pm6125_l23: l23 {
			regulator-min-microvolt = <3200000>;
			regulator-max-microvolt = <3400000>;
		};

		pm6125_l24: l24 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <3600000>;
		};
	};
};

&sdhc_2 {
	cd-gpios = <&tlmm 88 GPIO_ACTIVE_HIGH>;

	pinctrl-0 = <&sdc2_state_on>, <&sdc2_cd_on>;
	pinctrl-1 = <&sdc2_state_off>, <&sdc2_cd_off>;
	pinctrl-names = "default", "sleep";

	vmmc-supply = <&pm6125_l22>;
	vqmmc-supply = <&pm6125_l5>;
	/* No binding for vdd-io-bias on L7*/
	no-sdio;
	no-mmc;

	status = "okay";
};

&sleep_clk {
	clock-frequency = <32764>;
};

&spi2 {
	status = "okay";
};

&tlmm {
	gpio-reserved-ranges = <14 4>; /* Fingerprint SPI */

	lm3692x_bl_active: lm3692x-active-state {
		pins = "gpio99";
		function = "gpio";
		drive-strength = <0x02>;
		bias-pull-up;
	};

	mdss_dsi_active: mdss-dsi-active-state {
		pins = "gpio85";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	sdc2_cd_on: sdc2-cd-on-state {
		pins = "gpio88";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
	};

	sdc2_cd_off: sdc2-cd-off-state {
		pins = "gpio88";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
	};

	te_active: te-active-state {
		pins = "gpio81";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};
};

&ufs_mem_hc {
	vcc-max-microamp = <600000>;
	vcc-supply = <&pm6125_l24>;
	vccq2-max-microamp = <600000>;
	vccq2-supply = <&pm6125_l11>;
	vdd-hba-supply = <&pm6125_l18>;

	status = "okay";
};

&ufs_mem_phy {
	vdda-phy-supply = <&pm6125_l4>;
	vdda-pll-supply = <&pm6125_l12>;

	status = "okay";
};

&usb {
	status = "okay";
};

&usb_dwc3 {
	maximum-speed = "high-speed";
};

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

&usb_hsphy {
	vdd-supply = <&pm6125_l4>;
	vdda-pll-supply = <&pm6125_l12>;
	vdda-phy-dpdm-supply = <&pm6125_l15>;

	status = "okay";
};

&usb_qmpphy {
	vdda-phy-supply = <&pm6125_l4>;
	vdda-pll-supply = <&pm6125_l12>;

	status = "okay";
};

&usb_qmpphy_out {
	remote-endpoint = <&pmi632_ss_in>;
};

&xo_board {
	clock-frequency = <19200000>;
};