// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2025, Danila Tikhonov <danila@jiaxyga.com>
 */
/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 "sm8475.dtsi"
#include "pm8350.dtsi"
#include "pm8350b.dtsi"
#include "pm8350c.dtsi"
#include "pm8450.dtsi"
#include "pmk8350.dtsi"
#include "pmr735a.dtsi"

/delete-node/ &video_mem;
/delete-node/ &adsp_mem;
/delete-node/ &rmtfs_mem;

/ {
	model = "Nothing Phone (2)";
	compatible = "nothing,pong", "qcom,sm8475";
	chassis-type = "handset";

	aliases {
		hsuart0 = &uart20;
		serial0 = &uart7;
	};

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

		bootargs = "PMOS_NOSPLASH console=tty0 clk_ignore_unused pd_ignore_unused";

		framebuffer: framebuffer@b8000000 {
			compatible = "simple-framebuffer";
			reg = <0x0 0xb8000000 0x0 0x2b00000>;
			width = <1080>;
			height = <2412>;
			stride = <(1080 * 4)>;
			format = "a8r8g8b8";

			clocks = <&gcc GCC_DISP_HF_AXI_CLK>;
		};
	};

	/* goodix,fingerprint */

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

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

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

	reserved-memory {
		adsp_mem: memory@85700000 {
			reg = <0x0 0x85700000 0x0 0x2800000>;
			no-map;
		};

		ramoops@85200000 {
			compatible = "ramoops";
			reg = <0x0 0x85200000 0x0 0x400000>;

			record-size = <0x200000>;
			pmsg-size = <0x200000>;
			console-size = <0x200000>;
			no-map;
		};

		video_mem: memory@9fd00000 {
			reg = <0x0 0x9fd00000 0x0 0x700000>;
			no-map;
		};

		splash_region@b8000000 {
			reg = <0x0 0xb8000000 0x0 0x2b00000>;
			no-map;
		};

		/*
		 * bootloader_log_region: reg = <0x0 0xa7605000 0x0 0x8000>;
		 * splash_region: reg = <0x0 0xb8000000 0x0 0x2b00000>;
		 */

		rmtfs_mem: memory@fc700000 {
			compatible = "qcom,rmtfs-mem";
			reg = <0x0 0xf3300000 0x0 0x280000>;
			no-map;

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

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

&apps_rsc {
	regulators-0 {
		compatible = "qcom,pm8350-rpmh-regulators";
		qcom,pmic-id = "b";

		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-l4-supply = <&pm8350_s11>;
		vdd-l2-l7-supply = <&vreg_bob>;
		vdd-l3-l5-supply = <&pm8350_s11>;
		vdd-l6-l9-l10-supply = <&pm8350_s12>;

		/*
		 * ARC regulators:
		 * s5 - gfx.lvl
		 * l8 - lcx.lvl
		 */

		pm8350_s10: smps10 {
			regulator-name = "pm8350_s10";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8350_s11: smps11 {
			regulator-name = "pm8350_s11";
			regulator-min-microvolt = <382000>;
			regulator-max-microvolt = <1170000>;
		};

		pm8350_s12: smps12 {
			regulator-name = "pm8350_s12";
			regulator-min-microvolt = <1224000>;
			regulator-max-microvolt = <2040000>;
		};

		pm8350_l1: ldo1 {
			regulator-name = "pm8350_l1";
			regulator-min-microvolt = <830000>;
			regulator-max-microvolt = <920000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l2: ldo2 {
			regulator-name = "pm8350_l2";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l3: ldo3 {
			regulator-name = "pm8350_l3";
			regulator-min-microvolt = <870000>;
			regulator-max-microvolt = <970000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l5: ldo5 {
			regulator-name = "pm8350_l5";
			regulator-min-microvolt = <720000>;
			regulator-max-microvolt = <958000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l6: ldo6 {
			regulator-name = "pm8350_l6";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1216000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l7: ldo7 {
			regulator-name = "pm8350_l7";
			regulator-min-microvolt = <2400000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350_l9: ldo9 {
			regulator-name = "pm8350_l9";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};

	regulators-1 {
		compatible = "qcom,pm8350c-rpmh-regulators";
		qcom,pmic-id = "c";

		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-l1-l12-supply = <&pm8350c_s1>;
		vdd-l2-l8-supply = <&pm8350c_s1>;
		vdd-l3-l4-l5-l7-l13-supply = <&vreg_bob>;
		vdd-l6-l9-l11-supply = <&vreg_bob>;
		vdd-l10-supply = <&pm8350_s12>;

		vdd-bob-supply = <&vph_pwr>;

		/*
		 * ARC regulators:
		 * s2 - mxc.lvl
		 * s4 - mss.lvl
		 * s6 - cx.lvl
		 */

		pm8350c_s1: smps1 {
			regulator-name = "pm8350c_s1";
			regulator-min-microvolt = <1900000>;
			regulator-max-microvolt = <2024000>;
		};

		pm8350c_s10: smps10 {
			regulator-name = "pm8350c_s10";
			regulator-min-microvolt = <1052000>;
			regulator-max-microvolt = <1170000>;
		};

		vreg_bob: bob {
			regulator-name = "vreg_bob";
			regulator-min-microvolt = <3008000>;
			regulator-max-microvolt = <3960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_AUTO>;
		};

		pm8350c_l2: ldo2 {
			regulator-name = "pm8350c_l2";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1980000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l3: ldo3 {
			regulator-name = "pm8350c_l3";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l4: ldo4 {
			regulator-name = "pm8350c_l4";
			regulator-min-microvolt = <1620000>;
			regulator-max-microvolt = <3300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l5: ldo5 {
			regulator-name = "pm8350c_l5";
			regulator-min-microvolt = <1620000>;
			regulator-max-microvolt = <3300000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l6: ldo6 {
			regulator-name = "pm8350c_l6";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l7: ldo7 {
			regulator-name = "pm8350c_l7";
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l8: ldo8 {
			regulator-name = "pm8350c_l8";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l9: ldo9 {
			regulator-name = "pm8350c_l9";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l10: ldo10 {
			regulator-name = "pm8350c_l10";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l12: ldo12 {
			regulator-name = "pm8350c_l12";
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1980000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8350c_l13: ldo13 {
			regulator-name = "pm8350c_l13";
			regulator-min-microvolt = <2700000>;
			regulator-max-microvolt = <3544000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};

	regulators-2 {
		compatible = "qcom,pm8450-rpmh-regulators";
		qcom,pmic-id = "h";

		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-l2-supply = <&vreg_bob>;
		vdd-l3-supply = <&vreg_bob>;
		vdd-l4-supply = <&vreg_bob>;

		/*
		 * ARC regulators:
		 * S2 - ebi.lvl
		 * S4 - mmcx.lvl
		 * S6 - mx.lvl
		 * L1 - lmx.lvl
		 */

		pm8450_s3: smps3 {
			regulator-name = "pm8450_s3";
			regulator-min-microvolt = <470000>;
			regulator-max-microvolt = <570000>;
		};

		pm8450_l2: ldo2 {
			regulator-name = "pm8450_l2";
			regulator-min-microvolt = <820000>;
			regulator-max-microvolt = <958000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		pm8450_l3: ldo3 {
			regulator-name = "pm8450_l3";
			regulator-min-microvolt = <866000>;
			regulator-max-microvolt = <958000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};

	regulators-3 {
		compatible = "qcom,pmr735a-rpmh-regulators";
		qcom,pmic-id = "e";

		vdd-s1-supply = <&vph_pwr>;
		vdd-s2-supply = <&vph_pwr>;
		vdd-s3-supply = <&vph_pwr>;

		vdd-l1-l2-supply = <&pmr735a_s2>;
		vdd-l3-supply = <&pmr735a_s1>;
		vdd-l4-supply = <&pm8350c_s1>;
		vdd-l5-l6-supply = <&pm8350c_s1>;
		vdd-l7-bob-supply = <&vreg_bob>;

		pmr735a_s1: smps1 {
			regulator-name = "pmr735a_s1";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1296000>;
		};

		pmr735a_s2: smps2 {
			regulator-name = "pmr735a_s2";
			regulator-min-microvolt = <500000>;
			regulator-max-microvolt = <1040000>;
		};

		pmr735a_s3: smps3 {
			regulator-name = "pmr735a_s3";
			regulator-min-microvolt = <300000>;
			regulator-max-microvolt = <2352000>;
		};

		pmr735a_l1: ldo1 {
			regulator-name = "pmr735a_l1";
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <880000>;
		};

		pmr735a_l2: ldo2 {
			regulator-name = "pmr735a_l2";
			regulator-min-microvolt = <480000>;
			regulator-max-microvolt = <1200000>;
		};

		pmr735a_l3: ldo3 {
			regulator-name = "pmr735a_l3";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pmr735a_l4: ldo4 {
			regulator-name = "pmr735a_l4";
			regulator-min-microvolt = <1776000>;
			regulator-max-microvolt = <1776000>;
		};

		pmr735a_l5: ldo5 {
			regulator-name = "pmr735a_l5";
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <920000>;
		};

		pmr735a_l6: ldo6 {
			regulator-name = "pmr735a_l6";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pmr735a_l7: ldo7 {
			regulator-name = "pmr735a_l7";
			regulator-min-microvolt = <2800000>;
			regulator-max-microvolt = <2800000>;
		};
	};
};

&dispcc {
	status = "okay";
};

&gpi_dma0 {
	status = "okay";
};

&gpi_dma1 {
	status = "okay";
};

&gpi_dma2 {
	status = "okay";
};

&gpu {
	status = "okay";

	zap-shader {
		firmware-name = "qcom/a730_zap.mbn";
	};
};

&i2c5 {
	clock-frequency = <100000>;
	status = "okay";

	/* nq@64 rtc6226 */

	fsa4480: typec-mux@42 {
		compatible = "fcs,fsa4480";
		reg = <0x42>;

		mode-switch;
		orientation-switch;

		port {
			fsa4480_ept: endpoint {
				//remote-endpoint = <&typec_controller>;
			};
		};
	};

	/* redriver@1c onnn,redriver */
	/* aw20036_led@3a awinic,aw20036_led */

	nxp_eusb2_repeater: repeater@4f {
		compatible = "nxp,eusb2-repeater";
		reg = <0x4f>;

		vdd18-supply = <&pm8350_s10>;
		vdd3-supply = <&pm8350_l2>;

		reset-gpio = <&pm8350c_gpios 7 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&eusb2_reset_default>;

		qcom,param-override-seq = <64 6 34 7 100 8>;
		/*
		 * Rx squelch detection threshold to 110mV (default is 125mV);
		 * Tx Deemphasis to 2dB, Tx Deemphasis bit duration to 0.8UI
		 * (default is 0 for both);
		 * Output Voltage Swing to 550mV (default is 450mV);
		 */
		#phy-cells = <0>;
	};
};

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

	/* nq@28 qcom,sn-nci */
};

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

	/* tfa98xx@34 */
	/* tfa98xx@35 */
};

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

	/* haptic_hv@5a awinic,aw8692x */
};

&mdss {
	status = "okay";
};

&mdss_dsi0 {
	vdda-supply = <&pm8350_l6>;

	status = "okay";

	panel@0 {
		compatible = "mdss,nt37705-visionox-amoled-120hz";
		reg = <0>;

		reset-gpios = <&tlmm 0 GPIO_ACTIVE_LOW>;
		te-gpios = <&tlmm 86 GPIO_ACTIVE_HIGH>;

		vdd-supply = <&pm8350c_l13>;
		vddio-supply = <&pm8350c_l12>;

		pinctrl-0 = <&disp_reset_n_active>, <&mdp_vsync_active>;
		pinctrl-1 = <&disp_reset_n_suspend>, <&mdp_vsync_suspend>;
		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 {
	vdds-supply = <&pm8350_l5>;
	status = "okay";
};

&pon_pwrkey {
	status = "okay";
};

&pon_resin {
	linux,code = <KEY_VOLUMEDOWN>;

	status = "okay";
};

&pm8350_gpios {
	volume_up_n: volume-up-n-state {
		pins = "gpio6";
		function = PMIC_GPIO_FUNC_NORMAL;
		bias-pull-up;
		input-enable;
		power-source = <1>;
	};
};

&pm8350c_flash {
	status = "okay";

	led-0 {
		function = LED_FUNCTION_FLASH;
		color = <LED_COLOR_ID_YELLOW>;
		led-sources = <1>, <4>;
		led-max-microamp = <500000>;
		flash-max-microamp = <1500000>;
		flash-max-timeout-us = <1280000>;
	};
};

&pm8350c_gpios {
	eusb2_reset_default: eusb2-reset-default-state {
		pins = "gpio7";
		function = PMIC_GPIO_FUNC_NORMAL;
		input-enable;
		output-enable;
		bias-disable;
		power-source = <1>;	/* 1.8V */
		qcom,drive-strength = <PMIC_GPIO_STRENGTH_MED>;
	};
};

&pmk8350_rtc {
	status = "okay";
};

&qupv3_id_0 {
	status = "okay";
};

&qupv3_id_1 {
	status = "okay";
};

&qupv3_id_2 {
	status = "okay";
};

&remoteproc_adsp {
	firmware-name = "qcom/sm8475/pong/adsp.mbn";
	status = "okay";
};

&remoteproc_cdsp {
	firmware-name = "qcom/sm8475/pong/cdsp.mbn";
	status = "okay";
};

&remoteproc_mpss {
	firmware-name = "qcom/sm8475/pong/modem.mbn";
	status = "okay";
};

&remoteproc_slpi {
	firmware-name = "qcom/sm8475/pong/slpi.mbn";
	status = "okay";
};

&qup_spi4_data_clk {
	drive-strength = <6>;
	bias-disable;
};

&spi4 {
	status = "okay";

	touchscreen@0 {
		compatible = "goodix,gt9916";
		reg = <0>;

		interrupt-parent = <&tlmm>;
		interrupts = <21 IRQ_TYPE_LEVEL_LOW>;

		reset-gpios = <&tlmm 20 GPIO_ACTIVE_LOW>;

		avdd-supply = <&pm8350c_l3>;
		vddio-supply = <&pm8350c_l12>;

		spi-max-frequency = <20000000>;

		touchscreen-size-x = <1080>;
		touchscreen-size-y = <2412>;

		pinctrl-names = "default";
		pinctrl-0 = <&ts_irq>, <&ts_reset>;
	};
};

&tlmm {
	/* Reserved I/Os for FP */
	gpio-reserved-ranges = <28 4>;

	disp_reset_n_active: disp0-reset-n-active-state {
		pins = "gpio0";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	disp_reset_n_suspend: disp0-reset-n-suspend-state {
		pins = "gpio0";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	ts_irq: ts-irq-state {
		pins = "gpio21";
		function = "gpio";
		drive-strength = <8>;
		bias-pull-up;
	};

	ts_reset: ts-reset-state {
		pins = "gpio20";
		function = "gpio";
		drive-strength = <8>;
		bias-pull-up;
	};

	glyph_irq: glyph-irq-state {
		pins = "gpio60";
		function = "gpio";
		drive-strength = <8>;
		bias-pull-up;
	};

	glyph_reset: glyph-reset-state {
		pins = "gpio44";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	mdp_vsync_active: mdp-vsync-active-state {
		pins = "gpio86", "gpio87";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};

	mdp_vsync_suspend: mdp-vsync-suspend-state {
		pins = "gpio86", "gpio87";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};
};

&uart7 {
	status = "okay";
};

&uart20 {
	status = "okay";

	/* Bluetooth */
};

&ufs_mem_hc {
	reset-gpios = <&tlmm 210 GPIO_ACTIVE_LOW>;

	vcc-supply = <&pm8350_l7>;
	vcc-max-microamp = <1100000>;
	vccq-supply = <&pm8350_l9>;
	vccq-max-microamp = <1200000>;

	status = "okay";
};

&ufs_mem_phy {
	vdda-phy-supply = <&pm8350_l5>;
	vdda-pll-supply = <&pm8350c_l10>;

	status = "okay";
};

&usb_1 {
	/* USB 2.0 only */
	qcom,select-utmi-as-pipe-clk;
	status = "okay";
};

&usb_1_dwc3 {
	dr_mode = "peripheral";
	maximum-speed = "high-speed";
	/* Remove USB3 phy */
	phys = <&usb_1_hsphy>;
	phy-names = "usb2-phy";
};

&usb_1_hsphy {
	vdd-supply = <&pm8350_l5>;
	vdda12-supply = <&pm8350c_l10>;

	phys = <&nxp_eusb2_repeater>;

	status = "okay";
};
