// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2016-2022, AngeloGioacchino Del Regno
 *                          <angelogioacchino.delregno@somainline.org>
 * Copyright (c) 2022, Konrad Dybcio <konrad.dybcio@somainline.org>
 * Copyright (c) 2022, Marijn Suijten <marijn.suijten@somainline.org>
 */

#include "msm8956.dtsi"

#include "pm8004.dtsi"
#include "pm8950.dtsi"
#include "pmi8950.dtsi"

/ {
	qcom,msm-id = <266 0x10001>; /* MSM8956 v1.1 */
	qcom,board-id = <8 0>;

	aliases {
		mmc0 = &sdhc_1; /* SDC1 eMMC slot */
		mmc1 = &sdhc_2; /* SDC2 SD card slot */
		mmc2 = &sdhc_3; /* SDC3 SDIO card slot */
		serial0 = &blsp2_uart2;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	reserved-memory {
		cont-splash@83000000 {
			reg = <0x0 0x83000000 0x0 0x2800000>;
		};

		ramoops@57f00000 {
			compatible = "ramoops";
			reg = <0 0x57f00000 0 0x100000>;
			record-size = <0x20000>;
			console-size = <0x40000>;
			ftrace-size = <0x20000>;
			pmsg-size = <0x20000>;
			ecc-size = <16>;
		};
	};

	usbphy_1p2: regulator-usbphy-1p2 {
		compatible = "regulator-fixed";
		regulator-name = "usbphy-1p2";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1200000>;
		regulator-max-microvolt = <1200000>;
		vin-supply = <&vph_pwr>;
	};

	vph_pwr: regulator-vph-pwr {
		compatible = "regulator-fixed";
		regulator-name = "vph-pwr";
		regulator-always-on;
		regulator-boot-on;
	};
};

&blsp1_i2c4 {
	status = "okay";

	/* Synaptics RMI4 @ 2c */
};

&blsp2_uart2 {
	status = "okay";
};

&gcc {
	vdd_gfx-supply = <&pm8004_s5>;
};

&otg {
	status = "okay";
};

&pm8004_spmi_regulators {
	vdd_s2-supply = <&vph_pwr>;
	vdd_s5-supply = <&vph_pwr>;

	/* Cluster 1 supply */
	pm8004_s2: s2 {
		/* regulator-min-microvolt = <500000>; */
		/* Set .95V to prevent unstabilities until CPR for this SoC is done */
		regulator-min-microvolt = <950000>;
		regulator-max-microvolt = <1165000>;
		regulator-name = "vdd_apc1";
		/* Set always on until the CPU PLL is done */
		regulator-always-on;
		regulator-boot-on;
	};

	pm8004_s5: s5 {
		regulator-min-microvolt = <950000>;
		regulator-max-microvolt = <1165000>;
		regulator-enable-ramp-delay = <500>;
		regulator-name = "vdd_gfx";
		/* Hack this on until the gpu driver is ready for it */
		regulator-always-on;
	};
};

&pm8950_spmi_regulators {
	vdd_s5-supply = <&vph_pwr>;

	/* Cluster 0 supply */
	pm8950_spmi_s5: s5 {
		/* Set .95V to prevent unstabilities until CPR for this SoC is done */
		/* regulator-min-microvolt = <790000>; */
		regulator-min-microvolt = <950000>;
		regulator-max-microvolt = <1165000>;
		regulator-name = "vdd_apc0";
		/* Set always on until the CPU PLL is done */
		regulator-always-on;
		regulator-boot-on;
	};
};

&rpm_requests {
	pm8950_regulators: regulators {
		compatible = "qcom,rpm-pm8950-regulators";

		vdd_s1-supply = <&vph_pwr>;
		vdd_s2-supply = <&vph_pwr>;
		vdd_s3-supply = <&vph_pwr>;
		vdd_s4-supply = <&vph_pwr>;
		vdd_s6-supply = <&vph_pwr>;
		vdd_l1_l19-supply = <&pm8950_s3>;
		vdd_l2_l23-supply = <&pm8950_s3>;
		vdd_l3-supply = <&pm8950_s3>;
		vdd_l5_l6_l7_l16-supply = <&pm8950_s4>;
		vdd_l8_l11_l12_l17_l22-supply = <&vph_pwr>;

		pm8950_s1: s1 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1162500>;
		};

		pm8950_s3: s3 {
			regulator-min-microvolt = <1325000>;
			regulator-max-microvolt = <1325000>;
			regulator-always-on;
		};

		pm8950_s4: s4 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-always-on;
		};

		pm8950_l1: l1 {
			regulator-min-microvolt = <900000>;
			regulator-max-microvolt = <1100000>;
		};

		pm8950_l2: l2 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8950_l3: l3 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1200000>;
		};

		pm8950_l5: l5 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-system-load = <290000>;
			regulator-allow-set-load;
		};

		pm8950_l6: l6 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8950_l7: l7 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
		};

		pm8950_l8: l8 {
			regulator-min-microvolt = <2900000>;
			regulator-max-microvolt = <2900000>;
			regulator-system-load = <130000>;
			regulator-allow-set-load;
		};

		pm8950_l9: l9 {
			regulator-min-microvolt = <2000000>;
			regulator-max-microvolt = <2400000>;
		};

		pm8950_l10: l10 {
			regulator-min-microvolt = <2500000>;
			regulator-max-microvolt = <2900000>;
		};

		pm8950_l11: l11 {
			regulator-min-microvolt = <2950000>;
			regulator-max-microvolt = <2950000>;
			regulator-system-load = <60000>;
			regulator-allow-set-load;
		};

		pm8950_l12: l12 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2950000>;
			regulator-system-load = <100000>;
			regulator-allow-set-load;
		};

		pm8950_l13: l13 {
			regulator-min-microvolt = <3075000>;
			regulator-max-microvolt = <3075000>;
		};

		pm8950_l14: l14 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <3300000>;
		};

		pm8950_l15: l15 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <3300000>;
		};

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

		pm8950_l17: l17 {
			regulator-min-microvolt = <2500000>;
			regulator-max-microvolt = <2900000>;
		};

		pm8950_l22: l22 {
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3000000>;
		};

		pm8950_l23: l23 {
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
		};
	};
};

&sdhc_1 {
	/* Toshiba THGBMHG8C4LBAU7 (032G34) */
	bus-width = <8>;
	non-removable;
	vmmc-supply = <&pm8950_l8>;
	vqmmc-supply = <&pm8950_l5>;
	status = "okay";
};

&sdhc_2 {
	bus-width = <4>;
	cd-gpios = <&tlmm 100 GPIO_ACTIVE_HIGH>;
	vmmc-supply = <&pm8950_l11>;
	vqmmc-supply = <&pm8950_l12>;
	status = "okay";
};

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

&usb_hs_phy {
	vdd-supply = <&usbphy_1p2>;
	vdda1p8-supply = <&pm8950_l7>;
	vdda3p3-supply = <&pm8950_l13>;
	status = "okay";
};

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