// SPDX-License-Identifier: GPL-2.0
#include "tegra186.dtsi"

#include <dt-bindings/mfd/max77620.h>

/ {
	model = "NVIDIA Jetson TX2";
	compatible = "nvidia,p3310", "nvidia,tegra186";

	aliases {
		ethernet0 = "/ethernet@2490000";
		i2c0 = "/bpmp/i2c";
		i2c1 = "/i2c@3160000";
		i2c2 = "/i2c@c240000";
		i2c3 = "/i2c@3180000";
		i2c4 = "/i2c@3190000";
		i2c5 = "/i2c@31c0000";
		i2c6 = "/i2c@c250000";
		i2c7 = "/i2c@31e0000";
		mmc0 = "/mmc@3460000";
		mmc1 = "/mmc@3400000";
		serial0 = &uarta;
	};

	chosen {
		bootargs = "earlycon console=ttyS0,115200n8 fw_devlink=on";
		stdout-path = "serial0:115200n8";
	};

	memory@80000000 {
		device_type = "memory";
		reg = <0x0 0x80000000 0x2 0x00000000>;
	};

	ethernet@2490000 {
		status = "okay";

		phy-reset-gpios = <&gpio TEGRA186_MAIN_GPIO(M, 4)
					 GPIO_ACTIVE_LOW>;
		phy-handle = <&phy>;
		phy-mode = "rgmii";

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

			phy: ethernet-phy@0 {
				compatible = "ethernet-phy-ieee802.3-c22";
				reg = <0x0>;
				interrupt-parent = <&gpio>;
				interrupts = <TEGRA186_MAIN_GPIO(M, 5)
					      IRQ_TYPE_LEVEL_LOW>;

				#phy-cells = <0>;
			};
		};
	};

	memory-controller@2c00000 {
		status = "okay";
	};

	serial@3100000 {
		status = "okay";
	};

	i2c@3160000 {
		status = "okay";

		power-monitor@40 {
			compatible = "ti,ina3221";
			reg = <0x40>;
			#address-cells = <1>;
			#size-cells = <0>;

			input@0 {
				reg = <0x0>;
				label = "VDD_SYS_GPU";
				shunt-resistor-micro-ohms = <10000>;
			};

			input@1 {
				reg = <0x1>;
				label = "VDD_SYS_SOC";
				shunt-resistor-micro-ohms = <10000>;
			};

			input@2 {
				reg = <0x2>;
				label = "VDD_3V8_WIFI";
				shunt-resistor-micro-ohms = <10000>;
			};
		};

		power-monitor@41 {
			compatible = "ti,ina3221";
			reg = <0x41>;
			#address-cells = <1>;
			#size-cells = <0>;

			input@0 {
				reg = <0x0>;
				label = "VDD_IN";
				shunt-resistor-micro-ohms = <5000>;
			};

			input@1 {
				reg = <0x1>;
				label = "VDD_SYS_CPU";
				shunt-resistor-micro-ohms = <10000>;
			};

			input@2 {
				reg = <0x2>;
				label = "VDD_5V0_DDR";
				shunt-resistor-micro-ohms = <10000>;
			};
		};
	};

	i2c@3180000 {
		status = "okay";
	};

	ddc: i2c@3190000 {
		status = "okay";
	};

	i2c@31c0000 {
		status = "okay";
	};

	i2c@31e0000 {
		status = "okay";
	};

	/* SDMMC1 (SD/MMC) */
	mmc@3400000 {
		cd-gpios = <&gpio TEGRA186_MAIN_GPIO(P, 5) GPIO_ACTIVE_LOW>;
		wp-gpios = <&gpio TEGRA186_MAIN_GPIO(P, 4) GPIO_ACTIVE_HIGH>;

		vqmmc-supply = <&vddio_sdmmc1>;
	};

	/* SDMMC3 (SDIO) */
	mmc@3440000 {
		status = "okay";
		vqmmc-supply = <&vddio_sdmmc3>;
	};

	/* SDMMC4 (eMMC) */
	mmc@3460000 {
		status = "okay";
		bus-width = <8>;
		non-removable;

		vqmmc-supply = <&vdd_1v8_ap>;
		vmmc-supply = <&vdd_3v3_sys>;
	};

	hsp@3c00000 {
		status = "okay";
	};

	i2c@c240000 {
		status = "okay";
	};

	i2c@c250000 {
		status = "okay";

		/* module ID EEPROM */
		eeprom@50 {
			compatible = "atmel,24c02";
			reg = <0x50>;

			label = "module";
			vcc-supply = <&vdd_1v8>;
			address-width = <8>;
			pagesize = <8>;
			size = <256>;
			read-only;
		};
	};

	rtc@c2a0000 {
		status = "okay";
	};

	pmc@c360000 {
		nvidia,invert-interrupt;
	};

	bpmp {
		i2c {
			status = "okay";

			pmic: pmic@3c {
				compatible = "maxim,max77620";
				reg = <0x3c>;

				interrupt-parent = <&pmc>;
				interrupts = <24 IRQ_TYPE_LEVEL_LOW>;
				#interrupt-cells = <2>;
				interrupt-controller;

				#gpio-cells = <2>;
				gpio-controller;

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

				fps {
					fps0 {
						maxim,fps-event-source = <MAX77620_FPS_EVENT_SRC_EN0>;
						maxim,shutdown-fps-time-period-us = <640>;
					};

					fps1 {
						maxim,fps-event-source = <MAX77620_FPS_EVENT_SRC_EN1>;
						maxim,shutdown-fps-time-period-us = <640>;
					};

					fps2 {
						maxim,fps-event-source = <MAX77620_FPS_EVENT_SRC_EN0>;
						maxim,shutdown-fps-time-period-us = <640>;
					};
				};

				max77620_default: pinmux {
					gpio0 {
						pins = "gpio0";
						function = "gpio";
					};

					gpio1 {
						pins = "gpio1";
						function = "fps-out";
						maxim,active-fps-source = <MAX77620_FPS_SRC_0>;
					};

					gpio2 {
						pins = "gpio2";
						function = "fps-out";
						maxim,active-fps-source = <MAX77620_FPS_SRC_1>;
					};

					gpio3 {
						pins = "gpio3";
						function = "fps-out";
						maxim,active-fps-source = <MAX77620_FPS_SRC_1>;
					};

					gpio4 {
						pins = "gpio4";
						function = "32k-out1";
						drive-push-pull = <1>;
					};

					gpio5 {
						pins = "gpio5";
						function = "gpio";
						drive-push-pull = <0>;
					};

					gpio6 {
						pins = "gpio6";
						function = "gpio";
						drive-push-pull = <1>;
					};

					gpio7 {
						pins = "gpio7";
						function = "gpio";
						drive-push-pull = <0>;
					};
				};

				regulators {
					in-sd0-supply = <&vdd_5v0_sys>;
					in-sd1-supply = <&vdd_5v0_sys>;
					in-sd2-supply = <&vdd_5v0_sys>;
					in-sd3-supply = <&vdd_5v0_sys>;

					in-ldo0-1-supply = <&vdd_5v0_sys>;
					in-ldo2-supply = <&vdd_5v0_sys>;
					in-ldo3-5-supply = <&vdd_5v0_sys>;
					in-ldo4-6-supply = <&vdd_1v8>;
					in-ldo7-8-supply = <&avdd_dsi_csi>;

					sd0 {
						regulator-name = "VDD_DDR_1V1_PMIC";
						regulator-min-microvolt = <1100000>;
						regulator-max-microvolt = <1100000>;
						regulator-always-on;
						regulator-boot-on;
					};

					avdd_dsi_csi: sd1 {
						regulator-name = "AVDD_DSI_CSI_1V2";
						regulator-min-microvolt = <1200000>;
						regulator-max-microvolt = <1200000>;
					};

					vdd_1v8: sd2 {
						regulator-name = "VDD_1V8";
						regulator-min-microvolt = <1800000>;
						regulator-max-microvolt = <1800000>;
					};

					vdd_3v3_sys: sd3 {
						regulator-name = "VDD_3V3_SYS";
						regulator-min-microvolt = <3300000>;
						regulator-max-microvolt = <3300000>;
					};

					vdd_1v8_pll: ldo0 {
						regulator-name = "VDD_1V8_AP_PLL";
						regulator-min-microvolt = <1800000>;
						regulator-max-microvolt = <1800000>;
					};

					ldo2 {
						regulator-name = "VDDIO_3V3_AOHV";
						regulator-min-microvolt = <3300000>;
						regulator-max-microvolt = <3300000>;
						regulator-always-on;
						regulator-boot-on;
					};

					vddio_sdmmc1: ldo3 {
						regulator-name = "VDDIO_SDMMC1_AP";
						regulator-min-microvolt = <1800000>;
						regulator-max-microvolt = <3300000>;
					};

					ldo4 {
						regulator-name = "VDD_RTC";
						regulator-min-microvolt = <1000000>;
						regulator-max-microvolt = <1000000>;
					};

					vddio_sdmmc3: ldo5 {
						regulator-name = "VDDIO_SDMMC3_AP";
						regulator-min-microvolt = <2800000>;
						regulator-max-microvolt = <2800000>;
					};

					vdd_hdmi_1v05: ldo7 {
						regulator-name = "VDD_HDMI_1V05";
						regulator-min-microvolt = <1050000>;
						regulator-max-microvolt = <1050000>;
					};

					vdd_pex: ldo8 {
						regulator-name = "VDD_PEX_1V05";
						regulator-min-microvolt = <1050000>;
						regulator-max-microvolt = <1050000>;
					};
				};
			};
		};
	};

	cpus {
		cpu@0 {
			enable-method = "psci";
		};

		cpu@1 {
			enable-method = "psci";
		};

		cpu@2 {
			enable-method = "psci";
		};

		cpu@3 {
			enable-method = "psci";
		};

		cpu@4 {
			enable-method = "psci";
		};

		cpu@5 {
			enable-method = "psci";
		};
	};

	psci {
		compatible = "arm,psci-1.0";
		status = "okay";
		method = "smc";
	};

	gnd: regulator-gnd {
		compatible = "regulator-fixed";
		regulator-name = "GND";
		regulator-min-microvolt = <0>;
		regulator-max-microvolt = <0>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_5v0_sys: regulator-vdd-5v0-sys {
		compatible = "regulator-fixed";
		regulator-name = "VDD_5V0_SYS";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		regulator-always-on;
		regulator-boot-on;
	};

	vdd_1v8_ap: regulator-vdd-1v8-ap {
		compatible = "regulator-fixed";
		regulator-name = "VDD_1V8_AP";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;

		gpio = <&pmic 1 GPIO_ACTIVE_HIGH>;
		enable-active-high;

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