// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2022, Alexander Martinz <amartinz@shiftphones.com>
 * Copyright (c) 2022, Caleb Connolly <caleb@connolly.tech>
 * Copyright (c) 2022, Dylan Van Assche <me@dylanvanassche.be>
 */

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
#include "sdm845.dtsi"
#include "pm8998.dtsi"
#include "pmi8998.dtsi"

/ {
	model = "SHIFT SHIFT6mq";
	compatible = "shift,axolotl", "qcom,sdm845";
	qcom,msm-id = <321 0x20001>;
	qcom,board-id = <11 0>;

	aliases {
		display0 = &framebuffer0;
		serial0 = &uart9;
		serial1 = &uart6;
	};

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

		stdout-path = "serial0";

		/* Use framebuffer setup by the bootloader. */
		framebuffer0: framebuffer@9d400000 {
			compatible = "simple-framebuffer";
			reg = <0x0 0x9d400000 0x0 (1080 * 2160 * 4)>;
			width = <1080>;
			height = <2160>;
			stride = <(1080 * 4)>;
			format = "a8r8g8b8";
		};
	};

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

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

		key-vol-up {
			label = "volume_up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&pm8998_gpios 6 GPIO_ACTIVE_LOW>;
			debounce-interval = <15>;
		};
	};

	reserved-memory {
		framebuffer@9d400000 {
			reg = <0x0 0x9d400000 0x0 (1080 * 2160 * 4)>;
			no-map;
		};

		ramoops: ramoops@b0000000 {
			compatible = "ramoops";
			reg = <0 0xb0000000 0 0x00400000>;
			record-size = <0x40000>;
			console-size = <0x40000>;
			ftrace-size = <0x40000>;
			pmsg-size = <0x200000>;
			ecc-size = <0x0>;
		};
	};

	battery: battery {
		compatible = "simple-battery";

		charge-full-design-microamp-hours = <3850000>;
		voltage-min-design-microvolt = <3600000>;
		voltage-max-design-microvolt = <4400000>;
	};

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

	vreg_s4a_1p8: pm8998-smps4 {
		compatible = "regulator-fixed";
		regulator-name = "vreg_s4a_1p8";

		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

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

		vin-supply = <&vph_pwr>;
	};
};

&adsp_pas {
	status = "okay";
	firmware-name = "qcom/sdm845/axolotl/adsp.mbn";
};

&apps_rsc {
	regulators-0 {
		compatible = "qcom,pm8998-rpmh-regulators";
		qcom,pmic-id = "a";

		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-s13-supply = <&vph_pwr>;
		vdd-l1-l27-supply = <&vreg_s7a_1p025>;
		vdd-l2-l8-l17-supply = <&vreg_s3a_1p35>;
		vdd-l3-l11-supply = <&vreg_s7a_1p025>;
		vdd-l4-l5-supply = <&vreg_s7a_1p025>;
		vdd-l6-supply = <&vph_pwr>;
		vdd-l7-l12-l14-l15-supply = <&vreg_s5a_2p04>;
		vdd-l9-supply = <&vreg_bob>;
		vdd-l10-l23-l25-supply = <&vreg_bob>;
		vdd-l13-l19-l21-supply = <&vreg_bob>;
		vdd-l16-l28-supply = <&vreg_bob>;
		vdd-l18-l22-supply = <&vreg_bob>;
		vdd-l20-l24-supply = <&vreg_bob>;
		vdd-l26-supply = <&vreg_s3a_1p35>;
		vin-lvs-1-2-supply = <&vreg_s4a_1p8>;

		vreg_s2a_1p125: smps2 {
			regulator-min-microvolt = <1100000>;
			regulator-max-microvolt = <1100000>;
		};

		vreg_s3a_1p35: smps3 {
			regulator-min-microvolt = <1352000>;
			regulator-max-microvolt = <1352000>;
		};

		vreg_s5a_2p04: smps5 {
			regulator-min-microvolt = <1904000>;
			regulator-max-microvolt = <2040000>;
		};

		vreg_s7a_1p025: smps7 {
			regulator-min-microvolt = <900000>;
			regulator-max-microvolt = <1028000>;
		};

		vdd_qusb_hs0:
		vdda_hp_pcie_core:
		vdda_mipi_csi0_0p9:
		vdda_mipi_csi1_0p9:
		vdda_mipi_csi2_0p9:
		vdda_mipi_dsi0_pll:
		vdda_mipi_dsi1_pll:
		vdda_qlink_lv:
		vdda_qlink_lv_ck:
		vdda_qrefs_0p875:
		vdda_pcie_core:
		vdda_pll_cc_ebi01:
		vdda_pll_cc_ebi23:
		vdda_sp_sensor:
		vdda_ufs1_core:
		vdda_ufs2_core:
		vdda_usb1_ss_core:
		vdda_usb2_ss_core:
		vreg_l1a_0p875: ldo1 {
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <880000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_10:
		vreg_l2a_1p2: ldo2 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-always-on;
		};

		vreg_l3a_1p0: ldo3 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdd_wcss_cx:
		vdd_wcss_mx:
		vdda_wcss_pll:
		vreg_l5a_0p8: ldo5 {
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_13:
		vreg_l6a_1p8: ldo6 {
			regulator-min-microvolt = <1856000>;
			regulator-max-microvolt = <1856000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l7a_1p8: ldo7 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l8a_1p2: ldo8 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1248000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l9a_1p8: ldo9 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l10a_1p8: ldo10 {
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l11a_1p0: ldo11 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1048000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdd_qfprom:
		vdd_qfprom_sp:
		vdda_apc1_cs_1p8:
		vdda_gfx_cs_1p8:
		vdda_qrefs_1p8:
		vdda_qusb_hs0_1p8:
		vddpx_11:
		vreg_l12a_1p8: ldo12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vddpx_2:
		vreg_l13a_2p95: ldo13 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l14a_1p88: ldo14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l15a_1p8: ldo15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l16a_2p7: ldo16 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2704000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l17a_1p3: ldo17 {
			regulator-min-microvolt = <1304000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l18a_2p7: ldo18 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l19a_3p0: ldo19 {
			regulator-min-microvolt = <2856000>;
			regulator-max-microvolt = <3104000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l20a_2p95: ldo20 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l21a_2p95: ldo21 {
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l22a_2p85: ldo22 {
			regulator-min-microvolt = <2864000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l23a_3p3: ldo23 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdda_qusb_hs0_3p1:
		vreg_l24a_3p075: ldo24 {
			regulator-min-microvolt = <3088000>;
			regulator-max-microvolt = <3088000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l25a_3p3: ldo25 {
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdda_hp_pcie_1p2:
		vdda_hv_ebi0:
		vdda_hv_ebi1:
		vdda_hv_ebi2:
		vdda_hv_ebi3:
		vdda_mipi_csi_1p25:
		vdda_mipi_dsi0_1p2:
		vdda_mipi_dsi1_1p2:
		vdda_pcie_1p2:
		vdda_ufs1_1p2:
		vdda_ufs2_1p2:
		vdda_usb1_ss_1p2:
		vdda_usb2_ss_1p2:
		vreg_l26a_1p2: ldo26 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l28a_3p0: ldo28 {
			regulator-min-microvolt = <2856000>;
			regulator-max-microvolt = <3008000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		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,pmi8998-rpmh-regulators";
		qcom,pmic-id = "b";

		vdd-bob-supply = <&vph_pwr>;

		vreg_bob: bob {
			regulator-min-microvolt = <3312000>;
			regulator-max-microvolt = <3600000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_AUTO>;
			regulator-allow-bypass;
		};
	};

	regulators-2 {
		compatible = "qcom,pm8005-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>;

		vreg_s3c_0p6: smps3 {
			regulator-min-microvolt = <600000>;
			regulator-max-microvolt = <600000>;
		};
	};
};

&cdsp_pas {
	status = "okay";
	firmware-name = "qcom/sdm845/axolotl/cdsp.mbn";
};

&gcc {
	protected-clocks = <GCC_QSPI_CORE_CLK>,
			   <GCC_QSPI_CORE_CLK_SRC>,
			   <GCC_QSPI_CNOC_PERIPH_AHB_CLK>,
			   <GCC_LPASS_Q6_AXI_CLK>,
			   <GCC_LPASS_SWAY_CLK>;
};

&gmu {
	status = "okay";
};

&gpu {
	status = "okay";

	zap-shader {
		memory-region = <&gpu_mem>;
		firmware-name = "qcom/sdm845/axolotl/a630_zap.mbn";
	};
};

&i2c5 {
	status = "okay";

	touchscreen@38 {
		compatible = "focaltech,fts8719";
		reg = <0x38>;
		wakeup-source;
		interrupt-parent = <&tlmm>;
		interrupts = <125 IRQ_TYPE_EDGE_FALLING>;
		vdd-supply = <&vreg_l28a_3p0>;
		vcc-i2c-supply = <&vreg_l14a_1p88>;

		pinctrl-names = "default", "suspend";
		pinctrl-0 = <&ts_int_active &ts_reset_active>;
		pinctrl-1 = <&ts_int_suspend &ts_reset_suspend>;

		reset-gpio = <&tlmm 99 GPIO_ACTIVE_HIGH>;
		irq-gpio = <&tlmm 125 GPIO_TRANSITORY>;
		touchscreen-size-x = <1080>;
		touchscreen-size-y = <2160>;
		focaltech,max-touch-number = <5>;
	};
};

&i2c10 {
	/* SMB1355@0x0C */
};

&ipa {
	qcom,gsi-loader = "self";
	memory-region = <&ipa_fw_mem>;
	firmware-name = "qcom/sdm845/axolotl/ipa_fws.mbn";
	status = "okay";
};

&mdss {
	status = "okay";
};

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

	panel@0 {
		compatible = "visionox,rm69299-shift";
		status = "okay";
		reg = <0>;
		vdda-supply = <&vreg_l14a_1p88>;
		vdd3p3-supply = <&vreg_l28a_3p0>;

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

		reset-gpios = <&tlmm 6 GPIO_ACTIVE_HIGH>;

		pinctrl-names = "default", "sleep";
		pinctrl-0 = <&sde_dsi_active &sde_te_active>;
		pinctrl-1 = <&sde_dsi_suspend &sde_te_suspend>;

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

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

&mdss_dsi0_phy {
	status = "okay";
	vdds-supply = <&vdda_mipi_dsi0_pll>;
};

&mss_pil {
	status = "okay";
	firmware-name = "qcom/sdm845/axolotl/mba.mbn", "qcom/sdm845/axolotl/modem.mbn";
};

&pm8998_gpios {
	volume_up_gpio: pm8998-gpio6-state {
		pinconf {
			pins = "gpio6";
			function = "normal";
			input-enable;
			bias-pull-up;
			qcom,drive-strength = <0>;
		};
	};
};

&pmi8998_charger {
	monitored-battery = <&battery>;

	status = "okay";
};

&pm8998_resin {
	linux,code = <KEY_VOLUMEDOWN>;
	status = "okay";
};

&pmi8998_lpg {
	status = "okay";

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

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

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

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

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

&pmi8998_flash {
	status = "okay";

	led-0 {
		function = LED_FUNCTION_FLASH;
		color = <LED_COLOR_ID_WHITE>;
		led-sources = <1>;
		led-max-microamp = <100000>;
		flash-max-microamp = <1100000>;
		flash-max-timeout-us = <1280000>;
	};

	led-1 {
		function = LED_FUNCTION_FLASH;
		color = <LED_COLOR_ID_YELLOW>;
		led-sources = <2>;
		led-max-microamp = <100000>;
		flash-max-microamp = <1100000>;
		flash-max-timeout-us = <1280000>;
	};
};

&qup_uart9_rx {
	drive-strength = <2>;
	bias-pull-up;
};

&qup_uart9_tx {
	drive-strength = <2>;
	bias-disable;
};

&qupv3_id_0 {
	status = "okay";
};

&qupv3_id_1 {
	status = "okay";
};

&slpi_pas {
	firmware-name = "qcom/sdm845/axolotl/slpi.mbn";
	status = "okay";
};

&tlmm {
	gpio-reserved-ranges = <0 4>, <81 4>;

	sde_dsi_active: sde-dsi-active-state {
		pins = "gpio6", "gpio11";
		function = "gpio";
		drive-strength = <8>;
		bias-disable;
	};

	sde_dsi_suspend: sde-dsi-suspend-state {
		pins = "gpio6", "gpio11";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

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

	sde_te_suspend: sde-te-suspend-state {
		pins = "gpio10";
		function = "mdp_vsync";
		drive-strength = <2>;
		bias-pull-down;
	};

	ts_int_active: ts-int-active-state {
		pins = "gpio125";
		function = "gpio";
		drive-strength = <8>;
		bias-pull-up;
	};

	ts_int_suspend: ts-int-suspend-state {
		pins = "gpio125";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

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

	ts_reset_suspend: ts-reset-suspend-state {
		pins = "gpio99";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};
};

&uart6 {
	status = "okay";

	pinctrl-0 = <&qup_uart6_4pin>;

	bluetooth {
		compatible = "qcom,wcn3990-bt";

		/*
		 * This path is relative to the qca/
		 * subdir under lib/firmware.
		 */
		firmware-name = "axolotl/crnv21.bin";

		vddio-supply = <&vreg_s4a_1p8>;
		vddxo-supply = <&vreg_l7a_1p8>;
		vddrf-supply = <&vreg_l17a_1p3>;
		vddch0-supply = <&vreg_l25a_3p3>;
		max-speed = <3200000>;
	};
};

&uart9 {
	status = "okay";
};

&ufs_mem_hc {
	status = "okay";

	reset-gpios = <&tlmm 150 GPIO_ACTIVE_LOW>;

	vcc-supply = <&vreg_l20a_2p95>;
	vcc-max-microamp = <600000>;
};

&ufs_mem_phy {
	status = "okay";

	vdda-phy-supply = <&vdda_ufs1_core>;
	vdda-pll-supply = <&vdda_ufs1_1p2>;
};

&usb_1 {
	status = "okay";
};

&usb_1_dwc3 {
	dr_mode = "peripheral";
};

&usb_1_hsphy {
	status = "okay";

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

&usb_1_qmpphy {
	status = "okay";

	vdda-phy-supply = <&vreg_l26a_1p2>;
	vdda-pll-supply = <&vreg_l1a_0p875>;
};

&venus {
	status = "okay";
	firmware-name = "qcom/sdm845/axolotl/venus.mbn";
};

&wifi {
	status = "okay";

	vdd-0.8-cx-mx-supply = <&vreg_l5a_0p8>;
	vdd-1.3-rfa-supply = <&vreg_l17a_1p3>;
	vdd-1.8-xo-supply = <&vreg_l7a_1p8>;
	vdd-3.3-ch0-supply = <&vreg_l25a_3p3>;
	vdd-3.3-ch1-supply = <&vreg_l23a_3p3>;

	qcom,snoc-host-cap-8bit-quirk;
};
