// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (c) 2022 Linaro Limited
 */

/dts-v1/;

#include "sm6115.dtsi"
#include "pm6125.dtsi"

/ {
	model = "Lenovo Tab P11";
	compatible = "lenovo,j606f", "qcom,sm6115p", "qcom,sm6115";
	chassis-type = "tablet";

	/* required for bootloader to select correct board */
	qcom,msm-id = <445 0x10000>, <420 0x10000>;
	qcom,board-id = <34 3>;

	aliases {
		mmc0 = &sdhc_2;
	};

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

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

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

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

		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 {
		ramoops@ffc00000 {
			compatible = "ramoops";
			reg = <0x0 0xffc00000 0x0 0x100000>;
			record-size = <0x1000>;
			console-size = <0x40000>;
			ftrace-size = <0x20000>;
			ecc-size = <16>;
		};
	};
};

&gpu {
	status = "okay";

	zap-shader {
		firmware-name = "qcom/sm6115/LENOVO/J606F/a610_zap.mbn";
	};
};

&mdss {
	status = "okay";
};

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

	panel: panel@0 {
		compatible = "lenovo,j606f-boe-nt36523w", "novatek,nt36523w";
		reg = <0>;

		reset-gpios = <&tlmm 82 GPIO_ACTIVE_LOW>;
		vddio-supply = <&pm6125_l9>;

		pinctrl-names = "default";
		pinctrl-0 = <&te_active &mdss_dsi_active>;

		rotation = <180>; /* Yep, it's mounted upside down! */

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

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

&mdss_dsi0_phy {
	status = "okay";
};

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

&pon_pwrkey {
	status = "okay";
};

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

&remoteproc_adsp {
	firmware-name = "qcom/sm6115/LENOVO/J606F/adsp.mbn";
	status = "okay";
};

&remoteproc_cdsp {
	firmware-name = "qcom/sm6115/LENOVO/J606F/cdsp.mbn";
	status = "okay";
};

&remoteproc_mpss {
	firmware-name = "qcom/sm6115/LENOVO/J606F/modem.mbn";
	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>;
			/* 3.056V capped to 2.96V for SDHCI */
			regulator-max-microvolt = <2960000>;
			regulator-allow-set-load;
			/* Broken hw, this one can't be turned off or SDHCI will break! */
			regulator-always-on;
		};

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

		pm6125_l7: l7 {
			/* 1.2V-1.304V fixed at 1.256V for SDHCI bias */
			regulator-min-microvolt = <1256000>;
			regulator-max-microvolt = <1256000>;
			/*
			 * TODO: SDHCI seems to also work with this one turned off, however
			 * there exists a possibility that it may not work with some very
			 * specific SDCard types, perhaps validating this against a wide
			 * range of models could rule that out, saving some power would
			 * certainly be nice..
			 */
			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 = <1704000>;
			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 {
			/* 1.104V-1.312V fixed @ 1.232V for DSIPHY */
			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>;
			/* 3.304V capped to 2.96V for SDHCI */
			regulator-max-microvolt = <2960000>;
			regulator-allow-set-load;
			/* Broken hw, this one can't be turned off or SDHCI will break! */
			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-names = "default", "sleep";
	pinctrl-0 = <&sdc2_state_on &sdc2_gate_pin>;
	pinctrl-1 = <&sdc2_state_off>;
	vmmc-supply = <&pm6125_l22>;
	vqmmc-supply = <&pm6125_l5>;
	no-sdio;
	no-mmc;
	status = "okay";
};

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

&tlmm {
	gpio-reserved-ranges = <14 4>;

	/*
	 * This is a wholly undocumented pin (other than a single vague "pwr-gpios" reference)
	 * that needs to be toggled for the SD Card slot to work properly..
	 */
	sdc2_gate_pin: sdc2-gate-state {
		pins = "gpio45";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-up;
		output-high;
	};

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

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

&ufs_mem_hc {
	vcc-supply = <&pm6125_l24>;
	vcc-max-microamp = <600000>;
	vccq2-supply = <&pm6125_l11>;
	vccq2-max-microamp = <600000>;
	status = "okay";
};

&ufs_mem_phy {
	vdda-phy-supply = <&pm6125_l4>;
	vdda-pll-supply = <&pm6125_l12>;
	vddp-ref-clk-supply = <&pm6125_l18>;
	status = "okay";
};

&usb {
	status = "okay";
};

&usb_dwc3 {
	maximum-speed = "high-speed";
	dr_mode = "peripheral";

	phys = <&usb_hsphy>;
	phy-names = "usb2-phy";
};

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

&wifi {
	vdd-0.8-cx-mx-supply = <&pm6125_l8>;
	vdd-1.8-xo-supply = <&pm6125_l16>;
	vdd-1.3-rfa-supply = <&pm6125_l17>;
	vdd-3.3-ch0-supply = <&pm6125_l23>;
	qcom,ath10k-calibration-variant = "Lenovo_P11";
	status = "okay";
};

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