// SPDX-License-Identifier: GPL-2.0
#include "qcom-apq8064-v2.0.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/qcom,pmic-gpio.h>

/ {
	model = "CompuLab CM-QS600";
	compatible = "qcom,apq8064-cm-qs600", "qcom,apq8064";

	aliases {
		serial0 = &gsbi7_serial;
	};

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

	sdcc4_pwrseq: pwrseq-sdcc4 {
		pinctrl-names = "default";
		pinctrl-0 = <&wlan_default_gpios>;
		compatible = "mmc-pwrseq-simple";
		reset-gpios = <&pm8921_gpio 43 GPIO_ACTIVE_LOW>;
	};

	/* on board fixed 3.3v supply */
	v3p3_fixed: regulator-v3p3 {
		compatible = "regulator-fixed";
		regulator-name = "PCIE V3P3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
	};
};

&gsbi1 {
	qcom,mode = <GSBI_PROT_I2C>;
	status = "okay";
};

&gsbi1_i2c {
	clock-frequency = <200000>;
	status = "okay";

	eeprom@50 {
		compatible = "atmel,24c02";
		reg = <0x50>;
		pagesize = <32>;
	};
};

&gsbi7 {
	qcom,mode = <GSBI_PROT_I2C_UART>;
	status = "okay";
};

&gsbi7_serial {
	pinctrl-names = "default";
	pinctrl-0 = <&gsbi7_uart_2pins>;
	status = "okay";
};

&pcie {
	vdda-supply = <&pm8921_s3>;
	vdda_phy-supply = <&pm8921_lvs6>;
	vdda_refclk-supply = <&v3p3_fixed>;
	pinctrl-0 = <&pcie_pins>;
	pinctrl-names = "default";
	perst-gpios = <&tlmm_pinmux 27 GPIO_ACTIVE_LOW>;
	status = "okay";
};

&pm8921_gpio {
	wlan_default_gpios: wlan-gpios-state {
		pinconf {
			pins = "gpio43";
			function = "normal";
			bias-disable;
			power-source = <PM8921_GPIO_S4>;
		};
	};
};

&rpm {
	regulators {
		vin_lvs1_3_6-supply = <&pm8921_s4>;
		vin_lvs2-supply = <&pm8921_s1>;
		vin_lvs4_5_7-supply = <&pm8921_s4>;

		vdd_l1_l2_l12_l18-supply = <&pm8921_s4>;
		vdd_l24-supply = <&pm8921_s1>;
		vdd_l25-supply = <&pm8921_s1>;
		vdd_l26-supply = <&pm8921_s7>;
		vdd_l27-supply = <&pm8921_s7>;
		vdd_l28-supply = <&pm8921_s7>;


		/* Buck SMPS */
		s1 {
			regulator-always-on;
			regulator-min-microvolt = <1225000>;
			regulator-max-microvolt = <1225000>;
			qcom,switch-mode-frequency = <3200000>;
			bias-pull-down;
		};

		s3 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1400000>;
			qcom,switch-mode-frequency = <4800000>;
		};

		s4 {
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			qcom,switch-mode-frequency = <3200000>;
		};

		s7 {
			regulator-min-microvolt = <1300000>;
			regulator-max-microvolt = <1300000>;
			qcom,switch-mode-frequency = <3200000>;
		};

		l3 {
			regulator-min-microvolt = <3050000>;
			regulator-max-microvolt = <3300000>;
			bias-pull-down;
		};

		l4 {
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1800000>;
			bias-pull-down;
		};

		l5 {
			regulator-min-microvolt = <2750000>;
			regulator-max-microvolt = <3000000>;
			bias-pull-down;
		};

		l23 {
			regulator-min-microvolt = <1700000>;
			regulator-max-microvolt = <1900000>;
			bias-pull-down;
		};

		lvs6 {
			bias-pull-down;
		};

	};
};

/* eMMC */
&sdcc1 {
	vmmc-supply = <&pm8921_l5>;
	vqmmc-supply = <&pm8921_s4>;
	status = "okay";
};

/* External micro SD card */
&sdcc3 {
	vmmc-supply = <&v3p3_fixed>;
	pinctrl-names = "default";
	pinctrl-0 = <&card_detect>;
	cd-gpios = <&tlmm_pinmux 26 GPIO_ACTIVE_LOW>;
	status = "okay";
};

/* WLAN */
&sdcc4 {
	status = "okay";
	vmmc-supply = <&v3p3_fixed>;
	vqmmc-supply = <&v3p3_fixed>;
	mmc-pwrseq = <&sdcc4_pwrseq>;
};

&tlmm_pinmux {
	card_detect: card_detect {
		mux {
			pins = "gpio26";
			function = "gpio";
			bias-disable;
		};
	};

	pcie_pins: pcie_pinmux {
		mux {
			pins = "gpio27";
			function = "gpio";
		};
		conf {
			pins = "gpio27";
			drive-strength = <12>;
			bias-disable;
		};
	};
};

&usb_hs1_phy {
	v3p3-supply = <&pm8921_l3>;
	v1p8-supply = <&pm8921_l4>;
};

&usb_hs3_phy {
	v3p3-supply = <&pm8921_l3>;
	v1p8-supply = <&pm8921_l23>;
};

&usb_hs4_phy {
	v3p3-supply = <&pm8921_l3>;
	v1p8-supply = <&pm8921_l23>;
};

/* OTG */
&usb1 {
	dr_mode = "otg";
	status = "okay";
};

&usb3 {
	dr_mode = "host";
	status = "okay";
};

&usb4 {
	dr_mode = "host";
	status = "okay";
};