// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2021, Linaro Limited
 */

/dts-v1/;

#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
#include <dt-bindings/gpio/gpio.h>
#include "sa8155p.dtsi"
#include "pmm8155au_1.dtsi"
#include "pmm8155au_2.dtsi"

/ {
	model = "Qualcomm Technologies, Inc. SA8155P ADP";
	compatible = "qcom,sa8155p-adp", "qcom,sa8155p";

	aliases {
		serial0 = &uart2;
		serial1 = &uart9;
	};

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

	vreg_3p3: vreg-3p3-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vreg_3p3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
	};

	/*
	 * S4A is always on and not controllable through RPMh.
	 * So model it as a fixed regulator.
	 */
	vreg_s4a_1p8: 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 = <&vreg_3p3>;
	};
};

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

		vdd-s1-supply = <&vreg_3p3>;
		vdd-s2-supply = <&vreg_3p3>;
		vdd-s3-supply = <&vreg_3p3>;
		vdd-s4-supply = <&vreg_3p3>;
		vdd-s5-supply = <&vreg_3p3>;
		vdd-s6-supply = <&vreg_3p3>;
		vdd-s7-supply = <&vreg_3p3>;
		vdd-s8-supply = <&vreg_3p3>;
		vdd-s9-supply = <&vreg_3p3>;
		vdd-s10-supply = <&vreg_3p3>;

		vdd-l1-l8-l11-supply = <&vreg_s6a_0p92>;
		vdd-l2-l10-supply = <&vreg_3p3>;
		vdd-l3-l4-l5-l18-supply = <&vreg_s6a_0p92>;
		vdd-l6-l9-supply = <&vreg_s6a_0p92>;
		vdd-l7-l12-l14-l15-supply = <&vreg_s5a_2p04>;
		vdd-l13-l16-l17-supply = <&vreg_3p3>;

		vreg_s5a_2p04: smps5 {
			regulator-name = "vreg_s5a_2p04";
			regulator-min-microvolt = <1904000>;
			regulator-max-microvolt = <2000000>;
		};

		vreg_s6a_0p92: smps6 {
			regulator-name = "vreg_s6a_0p92";
			regulator-min-microvolt = <920000>;
			regulator-max-microvolt = <1128000>;
		};

		vreg_l1a_0p752: ldo1 {
			regulator-name = "vreg_l1a_0p752";
			regulator-min-microvolt = <752000>;
			regulator-max-microvolt = <752000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdda_usb_hs_3p1:
		vreg_l2a_3p072: ldo2 {
			regulator-name = "vreg_l2a_3p072";
			regulator-min-microvolt = <3072000>;
			regulator-max-microvolt = <3072000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l3a_0p8: ldo3 {
			regulator-name = "vreg_l3a_0p8";
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vdd_usb_hs_core:
		vdda_usb_ss_dp_core_1:
		vreg_l5a_0p88: ldo5 {
			regulator-name = "vreg_l5a_0p88";
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <880000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-allow-set-load;
			regulator-allowed-modes = <RPMH_REGULATOR_MODE_LPM
						   RPMH_REGULATOR_MODE_HPM>;
		};

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

		vreg_l10a_2p96: ldo10 {
			regulator-name = "vreg_l10a_2p96";
			regulator-min-microvolt = <2504000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-allow-set-load;
			regulator-allowed-modes = <RPMH_REGULATOR_MODE_LPM
						   RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l11a_0p8: ldo11 {
			regulator-name = "vreg_l11a_0p8";
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

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

		vreg_l13a_2p7: ldo13 {
			regulator-name = "vreg_l13a_2p7";
			regulator-min-microvolt = <2704000>;
			regulator-max-microvolt = <2704000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l15a_1p7: ldo15 {
			regulator-name = "vreg_l15a_1p7";
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <1704000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

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

		vreg_l17a_2p96: ldo17 {
			regulator-name = "vreg_l17a_2p96";
			regulator-min-microvolt = <2504000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};

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

		vdd-s1-supply = <&vreg_3p3>;
		vdd-s2-supply = <&vreg_3p3>;
		vdd-s3-supply = <&vreg_3p3>;
		vdd-s4-supply = <&vreg_3p3>;
		vdd-s5-supply = <&vreg_3p3>;
		vdd-s6-supply = <&vreg_3p3>;
		vdd-s7-supply = <&vreg_3p3>;
		vdd-s8-supply = <&vreg_3p3>;
		vdd-s9-supply = <&vreg_3p3>;
		vdd-s10-supply = <&vreg_3p3>;

		vdd-l1-l8-l11-supply = <&vreg_s4c_1p352>;
		vdd-l2-l10-supply = <&vreg_3p3>;
		vdd-l3-l4-l5-l18-supply = <&vreg_s4c_1p352>;
		vdd-l6-l9-supply = <&vreg_s6c_1p128>;
		vdd-l7-l12-l14-l15-supply = <&vreg_s5c_2p04>;
		vdd-l13-l16-l17-supply = <&vreg_3p3>;

		vreg_s4c_1p352: smps4 {
			regulator-name = "vreg_s4c_1p352";
			regulator-min-microvolt = <1352000>;
			regulator-max-microvolt = <1352000>;
		};

		vreg_s5c_2p04: smps5 {
			regulator-name = "vreg_s5c_2p04";
			regulator-min-microvolt = <1904000>;
			regulator-max-microvolt = <2000000>;
		};

		vreg_s6c_1p128: smps6 {
			regulator-name = "vreg_s6c_1p128";
			regulator-min-microvolt = <1128000>;
			regulator-max-microvolt = <1128000>;
		};

		vreg_l1c_1p304: ldo1 {
			regulator-name = "vreg_l1c_1p304";
			regulator-min-microvolt = <1304000>;
			regulator-max-microvolt = <1304000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l2c_1p808: ldo2 {
			regulator-name = "vreg_l2c_1p808";
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l5c_1p2: ldo5 {
			regulator-name = "vreg_l5c_1p2";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-allow-set-load;
			regulator-allowed-modes = <RPMH_REGULATOR_MODE_LPM
						   RPMH_REGULATOR_MODE_HPM>;
		};

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

		vreg_l8c_1p2: ldo8 {
			regulator-name = "vreg_l8c_1p2";
			regulator-min-microvolt = <1200000>;
			regulator-max-microvolt = <1200000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
			regulator-allow-set-load;
			regulator-allowed-modes = <RPMH_REGULATOR_MODE_LPM
						   RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l10c_3p3: ldo10 {
			regulator-name = "vreg_l10c_3p3";
			regulator-min-microvolt = <3000000>;
			regulator-max-microvolt = <3312000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l11c_0p8: ldo11 {
			regulator-name = "vreg_l11c_0p8";
			regulator-min-microvolt = <800000>;
			regulator-max-microvolt = <800000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l12c_1p808: ldo12 {
			regulator-name = "vreg_l12c_1p808";
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l13c_2p96: ldo13 {
			regulator-name = "vreg_l13c_2p96";
			regulator-min-microvolt = <2504000>;
			regulator-max-microvolt = <2960000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l15c_1p9: ldo15 {
			regulator-name = "vreg_l15c_1p9";
			regulator-min-microvolt = <1704000>;
			regulator-max-microvolt = <2928000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l16c_3p008: ldo16 {
			regulator-name = "vreg_l16c_3p008";
			regulator-min-microvolt = <3008000>;
			regulator-max-microvolt = <3008000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};

		vreg_l18c_0p88: ldo18 {
			regulator-name = "vreg_l18c_0p88";
			regulator-min-microvolt = <880000>;
			regulator-max-microvolt = <880000>;
			regulator-initial-mode = <RPMH_REGULATOR_MODE_HPM>;
		};
	};
};

&ethernet {
	status = "okay";

	snps,reset-gpio = <&tlmm 79 GPIO_ACTIVE_LOW>;
	snps,reset-active-low;
	snps,reset-delays-us = <0 11000 70000>;

	snps,mtl-rx-config = <&mtl_rx_setup>;
	snps,mtl-tx-config = <&mtl_tx_setup>;

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

	phy-handle = <&rgmii_phy>;
	phy-mode = "rgmii";
	max-speed = <1000>;

	mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <1>;
		#size-cells = <0>;

		/* Micrel KSZ9031RNZ PHY */
		rgmii_phy: phy@7 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <0x7>;

			interrupts-extended = <&tlmm 124 IRQ_TYPE_EDGE_FALLING>;
			device_type = "ethernet-phy";
		};
	};

	mtl_rx_setup: rx-queues-config {
		snps,rx-queues-to-use = <1>;
		snps,rx-sched-sp;

		queue0 {
			snps,dcb-algorithm;
			snps,map-to-dma-channel = <0x0>;
			snps,route-up;
			snps,priority = <0x1>;
		};
	};

	mtl_tx_setup: tx-queues-config {
		snps,tx-queues-to-use = <1>;
		snps,tx-sched-wrr;

		queue0 {
			snps,weight = <0x10>;
			snps,dcb-algorithm;
			snps,priority = <0x0>;
		};
	};
};

&qupv3_id_1 {
	status = "okay";
};

&remoteproc_adsp {
	status = "okay";
	firmware-name = "qcom/sa8155p/adsp.mdt";
};

&remoteproc_cdsp {
	status = "okay";
	firmware-name = "qcom/sa8155p/cdsp.mdt";
};

&sdhc_2 {
	status = "okay";

	cd-gpios = <&tlmm 4 GPIO_ACTIVE_LOW>;
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&sdc2_on>;
	pinctrl-1 = <&sdc2_off>;
	vqmmc-supply = <&vreg_l13c_2p96>; /* IO line power */
	vmmc-supply = <&vreg_l17a_2p96>;  /* Card power line */
	bus-width = <4>;
	no-sdio;
	no-mmc;
};

&uart2 {
	status = "okay";
};

&uart9 {
	status = "okay";
};

&ufs_mem_hc {
	status = "okay";

	reset-gpios = <&tlmm 175 GPIO_ACTIVE_LOW>;

	vcc-supply = <&vreg_l10a_2p96>;
	vcc-max-microamp = <750000>;
	vccq-supply = <&vreg_l5c_1p2>;
	vccq-max-microamp = <700000>;
	vccq2-supply = <&vreg_s4a_1p8>;
	vccq2-max-microamp = <750000>;
};

&ufs_mem_phy {
	status = "okay";

	vdda-phy-supply = <&vreg_l8c_1p2>;
	vdda-pll-supply = <&vreg_l5a_0p88>;
};

&usb_1 {
	status = "okay";
};

&usb_1_dwc3 {
	dr_mode = "host";

	pinctrl-names = "default";
	pinctrl-0 = <&usb2phy_ac_en1_default>;
};

&usb_1_hsphy {
	status = "okay";
	vdda-pll-supply = <&vdd_usb_hs_core>;
	vdda33-supply = <&vdda_usb_hs_3p1>;
	vdda18-supply = <&vdda_usb_hs_1p8>;
};

&usb_1_qmpphy {
	status = "disabled";
};

&usb_2 {
	status = "okay";
};

&usb_2_dwc3 {
	dr_mode = "host";

	pinctrl-names = "default";
	pinctrl-0 = <&usb2phy_ac_en2_default>;
};

&usb_2_hsphy {
	status = "okay";
	vdda-pll-supply = <&vdd_usb_hs_core>;
	vdda33-supply = <&vdda_usb_hs_3p1>;
	vdda18-supply = <&vdda_usb_hs_1p8>;
};

&usb_2_qmpphy {
	status = "okay";
	vdda-phy-supply = <&vreg_l8c_1p2>;
	vdda-pll-supply = <&vdda_usb_ss_dp_core_1>;
};

&pcie0 {
	status = "okay";
};

&pcie0_phy {
	status = "okay";
	vdda-phy-supply = <&vreg_l18c_0p88>;
	vdda-pll-supply = <&vreg_l8c_1p2>;
};

&pcie1_phy {
	vdda-phy-supply = <&vreg_l18c_0p88>;
	vdda-pll-supply = <&vreg_l8c_1p2>;
};

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

	sdc2_on: sdc2-on-state {
		clk-pins {
			pins = "sdc2_clk";
			bias-disable;		/* No pull */
			drive-strength = <16>;	/* 16 MA */
		};

		cmd-pins {
			pins = "sdc2_cmd";
			bias-pull-up;		/* pull up */
			drive-strength = <16>;	/* 16 MA */
		};

		data-pins {
			pins = "sdc2_data";
			bias-pull-up;		/* pull up */
			drive-strength = <16>;	/* 16 MA */
		};

		sd-cd-pins {
			pins = "gpio96";
			function = "gpio";
			bias-pull-up;		/* pull up */
			drive-strength = <2>;	/* 2 MA */
		};
	};

	sdc2_off: sdc2-off-state {
		clk-pins {
			pins = "sdc2_clk";
			bias-disable;		/* No pull */
			drive-strength = <2>;	/* 2 MA */
		};

		cmd-pins {
			pins = "sdc2_cmd";
			bias-pull-up;		/* pull up */
			drive-strength = <2>;	/* 2 MA */
		};

		data-pins {
			pins = "sdc2_data";
			bias-pull-up;		/* pull up */
			drive-strength = <2>;	/* 2 MA */
		};

		sd-cd-pins {
			pins = "gpio96";
			function = "gpio";
			bias-pull-up;		/* pull up */
			drive-strength = <2>;	/* 2 MA */
		};
	};

	usb2phy_ac_en1_default: usb2phy-ac-en1-default-state {
		pins = "gpio113";
		function = "usb2phy_ac";
		bias-disable;
		drive-strength = <2>;
	};

	usb2phy_ac_en2_default: usb2phy-ac-en2-default-state {
		pins = "gpio123";
		function = "usb2phy_ac";
		bias-disable;
		drive-strength = <2>;
	};

	ethernet_defaults: ethernet-defaults-state {
		mdc-pins {
			pins = "gpio7";
			function = "rgmii";
			bias-pull-up;
		};

		mdio-pins {
			pins = "gpio59";
			function = "rgmii";
			bias-pull-up;
		};

		rgmii-rx-pins {
			pins = "gpio117", "gpio118", "gpio119", "gpio120", "gpio115", "gpio116";
			function = "rgmii";
			bias-disable;
			drive-strength = <2>;
		};

		rgmii-tx-pins {
			pins = "gpio122", "gpio4", "gpio5", "gpio6", "gpio114", "gpio121";
			function = "rgmii";
			bias-pull-up;
			drive-strength = <16>;
		};

		phy-intr-pins {
			pins = "gpio124";
			function = "emac_phy";
			bias-disable;
			drive-strength = <8>;
		};

		pps-pins {
			pins = "gpio81";
			function = "emac_pps";
			bias-disable;
			drive-strength = <8>;
		};

		phy-reset-pins {
			pins = "gpio79";
			function = "gpio";
			bias-pull-up;
			drive-strength = <16>;
		};
	};
};