// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2021, Martin Botka <martin.botka@somainline.org>
 */

/dts-v1/;

#include "sm6125.dtsi"
#include "pm6125.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/gpio-keys.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>

/ {
	/* required for bootloader to select correct board */
	qcom,msm-id = <394 0x10000>; /* sm6125 v1 */
	qcom,board-id = <34 0>;

	model = "Sony Xperia 10 II";
	compatible = "sony,pdx201", "qcom,sm6125";
	chassis-type = "handset";

	aliases {
		mmc0 = &sdhc_1; /* SDC1 eMMC slot */
		mmc1 = &sdhc_2; /* SDC2 SD card slot */
	};

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

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

	extcon_usb: extcon-usb {
		compatible = "linux,extcon-usb-gpio";
		id-gpios = <&tlmm 102 GPIO_ACTIVE_HIGH>;
	};

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

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

		key-volume-down {
			label = "Volume Down";
			gpios = <&tlmm 47 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_VOLUMEDOWN>;
			debounce-interval = <15>;
			linux,can-disable;
			wakeup-source;
		};
	};

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		debug_mem: memory@ffb00000 {
			reg = <0x0 0xffb00000 0x0 0xc0000>;
			no-map;
		};

		last_log_mem: memory@ffbc0000 {
			reg = <0x0 0xffbc0000 0x0 0x80000>;
			no-map;
		};

		pstore_mem: ramoops@ffc00000 {
			compatible = "ramoops";
			reg = <0x0 0xffc40000 0x0 0xc0000>;
			record-size = <0x1000>;
			console-size = <0x40000>;
			pmsg-size = <0x20000>;
		};

		cmdline_mem: memory@ffd00000 {
			reg = <0x0 0xffd40000 0x0 0x1000>;
			no-map;
		};
	};

	thermal-zones {
		rf-pa0-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;
			thermal-sensors = <&pm6125_adc_tm 0>;

			trips {
				active-config0 {
					temperature = <125000>;
					hysteresis = <1000>;
					type = "critical";
				};
			};
		};

		quiet-thermal {
			polling-delay-passive = <0>;
			polling-delay = <5000>;
			thermal-sensors = <&pm6125_adc_tm 1>;

			trips {
				active-config0 {
					temperature = <125000>;
					hysteresis = <1000>;
					type = "critical";
				};
			};
		};

		xo-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;
			thermal-sensors = <&pm6125_adc_tm 2>;

			trips {
				active-config0 {
					temperature = <125000>;
					hysteresis = <1000>;
					type = "critical";
				};
			};
		};

		rf-pa1-thermal {
			polling-delay-passive = <0>;
			polling-delay = <0>;
			thermal-sensors = <&pm6125_adc_tm 3>;

			trips {
				active-config0 {
					temperature = <125000>;
					hysteresis = <1000>;
					type = "critical";
				};
			};
		};
	};
};

&gpi_dma0 {
	status = "okay";
};

&hsusb_phy1 {
	vdd-supply = <&pm6125_l7>;
	vdda-pll-supply = <&pm6125_l10>;
	vdda-phy-dpdm-supply = <&pm6125_l15>;
	status = "okay";
};

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

	/* NXP PN553 NFC @ 28 */
};

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

	/* Samsung touchscreen @ 48 */
};

&i2c3 {
	clock-frequency = <1000000>;
	status = "okay";

	/* Cirrus Logic CS35L41 boosted audio amplifier @ 40 */
};

&mdss {
	status = "okay";
};

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

	panel@0 {
		compatible = "samsung,sofef01-m-ams597ut01";
		reg = <0>;

		reset-gpios = <&tlmm 90 GPIO_ACTIVE_LOW>;

		vddio-supply = <&pm6125_l12>;

		pinctrl-0 = <&mdss_dsi_active &mdss_te_active_sleep>;
		pinctrl-1 = <&mdss_dsi_sleep &mdss_te_active_sleep>;
		pinctrl-names = "default", "sleep";

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

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

&mdss_dsi0_phy {
	status = "okay";
};

&pm6125_adc {
	pinctrl-names = "default";
	pinctrl-0 = <&camera_flash_therm &emmc_ufs_therm &rf_pa1_therm>;

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

	channel@4e {
		reg = <ADC5_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "quiet_therm";
	};

	channel@52 {
		reg = <ADC5_GPIO1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "camera_flash_therm";
	};

	channel@54 {
		reg = <ADC5_GPIO3_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "emmc_ufs_therm";
	};

	channel@55 {
		reg = <ADC5_GPIO4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time = <200>;
		qcom,pre-scaling = <1 1>;
		label = "rf_pa1_therm";
	};
};

&pm6125_adc_tm {
	status = "okay";

	rf-pa0-therm@0 {
		reg = <0>;
		io-channels = <&pm6125_adc ADC5_AMUX_THM1_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	quiet-therm@1 {
		reg = <1>;
		io-channels = <&pm6125_adc ADC5_AMUX_THM2_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	xo-therm@2 {
		reg = <2>;
		io-channels = <&pm6125_adc ADC5_XO_THERM_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};

	rf-pa1-therm@3 {
		reg = <3>;
		io-channels = <&pm6125_adc ADC5_GPIO4_100K_PU>;
		qcom,ratiometric;
		qcom,hw-settle-time-us = <200>;
	};
};

&pm6125_gpios {
	camera_flash_therm: camera-flash-therm-state {
		pins = "gpio3";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

	emmc_ufs_therm: emmc-ufs-therm-state {
		pins = "gpio6";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};

	rf_pa1_therm: rf-pa1-therm-state {
		pins = "gpio7";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-high-impedance;
	};
};

&pon_pwrkey {
	status = "okay";
};

&pon_resin {
	status = "okay";
	linux,code = <KEY_VOLUMEUP>;
};

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

		vdd_l2_l3_l4-supply = <&pm6125_l7>;
		vdd_l5_l15_l19_l20_l21_l22-supply = <&pm6125_l10>;

		/*
		 * S3/S4 is VDD_CX
		 * S5 is VDD_MX/WCSS_MX
		 */

		pm6125_s6: s6 {
			regulator-min-microvolt = <936000>;
			regulator-max-microvolt = <1422000>;
		};

		pm6125_l1: l1 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1256000>;
		};

		pm6125_l2: l2 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1056000>;
		};

		pm6125_l3: l3 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1064000>;
		};

		pm6125_l4: l4 {
			regulator-min-microvolt = <872000>;
			regulator-max-microvolt = <976000>;
		};

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

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

		pm6125_l7: l7 {
			regulator-min-microvolt = <872000>;
			regulator-max-microvolt = <976000>;
		};

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

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

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

		pm6125_l11: l11 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
		};

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

		pm6125_l13: l13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1832000>;
		};

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

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

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

		pm6125_l17: l17 {
			regulator-min-microvolt = <1248000>;
			regulator-max-microvolt = <1304000>;
		};

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

		pm6125_l19: l19 {
			regulator-min-microvolt = <1648000>;
			regulator-max-microvolt = <2952000>;
		};

		pm6125_l20: l20 {
			regulator-min-microvolt = <1648000>;
			regulator-max-microvolt = <2952000>;
		};

		pm6125_l21: l21 {
			regulator-min-microvolt = <2600000>;
			regulator-max-microvolt = <2856000>;
		};

		pm6125_l22: l22 {
			regulator-min-microvolt = <2944000>;
			regulator-max-microvolt = <2950000>;
			regulator-allow-set-load;
		};

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

		pm6125_l24: l24 {
			regulator-min-microvolt = <2944000>;
			regulator-max-microvolt = <2950000>;
			regulator-allow-set-load;
		};
	};
};

&qupv3_id_0 {
	status = "okay";
};

&sdc2_off_state {
	sd-cd-pins {
		pins = "gpio98";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
	};
};

&sdc2_on_state {
	sd-cd-pins {
		pins = "gpio98";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
	};
};

&sdhc_1 {
	vmmc-supply = <&pm6125_l24>;
	vqmmc-supply = <&pm6125_l11>;
	status = "okay";
};

&sdhc_2 {
	cd-gpios = <&tlmm 98 GPIO_ACTIVE_HIGH>;
	vmmc-supply = <&pm6125_l22>;
	vqmmc-supply = <&pm6125_l5>;
	no-sdio;
	no-mmc;
	status = "okay";
};

&tlmm {
	gpio-reserved-ranges = <22 2>, <28 6>;

	vol_down_n: vol-down-n-state {
		pins = "gpio47";
		function = "gpio";
		drive-strength = <2>;
		bias-disable;
	};

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

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

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

};

&usb3 {
	status = "okay";
};

&usb3_dwc3 {
	extcon = <&extcon_usb>;
};
