// SPDX-License-Identifier: GPL-2.0
/dts-v1/;

#include <dt-bindings/input/input.h>

#include "tegra20.dtsi"

/ {
	model = "LG Optimus 2X (P990)";
	compatible = "lg,star", "nvidia,tegra20";

	chosen {
		stdout-path = &uartb;
	};

	aliases {
		i2c0 = &pwr_i2c;
		i2c5 = &dcdc_i2c;

		mmc0 = &sdmmc4;	/* eMMC */
		mmc1 = &sdmmc3; /* uSD slot */

		rtc0 = &pmic;
		rtc1 = "/rtc@7000e000";

		usb0 = &micro_usb;
	};

	memory {
		device_type = "memory";
		reg = <0x00000000 0x20000000>; /* 512 MB */
	};

	host1x@50000000 {
		dc@54200000 {
			rgb {
				status = "okay";

				port {
					dpi_output: endpoint {
						remote-endpoint = <&bridge_input>;
						bus-width = <24>;
					};
				};
			};
		};
	};

	bsev@6001b000 {
		status = "okay";
	};

	pinmux@70000014 {
		pinctrl-names = "default";
		pinctrl-0 = <&state_default>;

		state_default: pinmux {
			crt {
				nvidia,pins = "crtp";
				nvidia,function = "crt";
			};

			dap1 {
				nvidia,pins = "dap1";
				nvidia,function = "dap1";
			};

			dap2 {
				nvidia,pins = "dap2";
				nvidia,function = "dap2";
			};

			dap3 {
				nvidia,pins = "dap3";
				nvidia,function = "dap3";
			};

			dap4 {
				nvidia,pins = "dap4";
				nvidia,function = "dap4";
			};

			displaya {
				nvidia,pins = "lcsn", "ld0", "ld1", "ld10",
						"ld11", "ld12", "ld13", "ld14",
						"ld15", "ld16", "ld17", "ld2",
						"ld3", "ld4", "ld5", "ld6",
						"ld7", "ld8", "ld9", "ldc",
						"ldi", "lhp0", "lhp1", "lhp2",
						"lhs", "lm0", "lm1", "lpp",
						"lpw0", "lpw1", "lpw2", "lsc0",
						"lsc1", "lsck", "lsda", "lsdi",
						"lspi", "lvp0", "lvp1", "lvs";
				nvidia,function = "displaya";
			};

			gmi {
				nvidia,pins = "ata", "atc", "atd", "ate",
						"gmb", "irrx", "irtx";
				nvidia,function = "gmi";
			};

			hdmi {
				nvidia,pins = "hdint";
				nvidia,function = "hdmi";
			};

			i2c {
				nvidia,pins = "i2cp", "rm";
				nvidia,function = "i2c";
			};

			i2c2 {
				nvidia,pins = "pta";
				nvidia,function = "i2c2";
			};

			i2c3 {
				nvidia,pins = "dtf";
				nvidia,function = "i2c3";
			};

			kbc {
				nvidia,pins = "kbca", "kbcb", "kbcc", "kbce",
						"kbcf";
				nvidia,function = "kbc";
			};

			owr {
				nvidia,pins = "owc";
				nvidia,function = "owr";
			};

			plla-out {
				nvidia,pins = "cdev1";
				nvidia,function = "plla_out";
			};

			pllp-out4 {
				nvidia,pins = "cdev2";
				nvidia,function = "pllp_out4";
			};

			pwm {
				nvidia,pins = "gpu";
				nvidia,function = "pwm";
			};

			pwr-on {
				nvidia,pins = "pmc";
				nvidia,function = "pwr_on";
			};

			rtck {
				nvidia,pins = "gpu7";
				nvidia,function = "rtck";
			};

			sdio1 {
				nvidia,pins = "sdio1";
				nvidia,function = "sdio1";
			};

			sdio2 {
				nvidia,pins = "kbcd";
				nvidia,function = "sdio2";
			};

			sdio3 {
				nvidia,pins = "sdb", "sdc", "sdd", "slxa",
						"slxd", "slxk", "slxc";
				nvidia,function = "sdio3";
			};

			sdio4 {
				nvidia,pins = "atb", "gma", "gme";
				nvidia,function = "sdio4";
			};

			spi1 {
				nvidia,pins = "uda";
				nvidia,function = "spi1";
			};

			spi2 {
				nvidia,pins = "spia", "spib", "spic";
				nvidia,function = "spi2";
			};

			spi2-alt {
				nvidia,pins = "spid", "spie", "spig", "spih";
				nvidia,function = "spi2_alt";
			};

			uarta {
				nvidia,pins = "uaa", "uab";
				nvidia,function = "uarta";
			};

			uartc {
				nvidia,pins = "uca", "ucb";
				nvidia,function = "uartc";
			};

			uartd {
				nvidia,pins = "gmc";
				nvidia,function = "uartd";
			};

			vi {
				nvidia,pins = "dtc", "dtd";
				nvidia,function = "vi";
			};

			vi-sensor-clk {
				nvidia,pins = "csus";
				nvidia,function = "vi_sensor_clk";
			};

			conf-lsda {
				nvidia,pins = "lsda", "owc";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
			};

			conf-ata {
				nvidia,pins = "ata", "dtf", "gmb", "gmc",
						"i2cp", "irrx", "kbca", "kbcc",
						"kbcd", "kbce", "kbcf", "lcsn",
						"ldc", "pta", "rm", "sdc",
						"sdd", "spie", "spif", "spig",
						"spih", "uaa", "uad", "uca",
						"ucb", "pmce";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
			};

			conf-crtp {
				nvidia,pins = "crtp", "gpv", "hdint", "lhs",
						"lm0", "lpw0", "lpw1", "lpw2",
						"lsc1", "lsck", "lspi", "lvs",
						"slxa", "slxd", "spdi";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
			};

			conf-atb {
				nvidia,pins = "atb", "atc", "atd", "ate",
						"cdev1", "cdev2", "csus", "dap1",
						"dap2", "dap3", "dap4", "ddc",
						"dta", "dtb", "dte", "gma",
						"gmd", "gme", "gpu", "gpu7",
						"irtx", "kbcb", "lm1", "lsc0",
						"lsdi", "lvp0", "pmc", "sdb",
						"sdio1", "slxc", "spdo", "spia",
						"spib", "spic", "uab", "uac",
						"uda", "ck32", "ddrc", "pmca",
						"pmcb", "pmcc", "pmcd", "xm2c",
						"xm2d";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
			};

			conf-dtc {
				nvidia,pins = "dtc", "dtd";
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
			};

			conf-ld0 {
				nvidia,pins = "ld0", "ld1", "ld2", "ld3",
						"ld4", "ld5", "ld6", "ld7",
						"ld8", "ld9", "ld10", "ld11",
						"ld12", "ld13", "ld14", "ld15",
						"ld16", "ld17", "ldi", "lhp0",
						"lhp1", "lhp2", "lpp", "lvp1",
						"slxk", "spid";
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
			};

			drive-sdio1 {
				nvidia,pins = "drive_sdio1", "drive_vi1";
				nvidia,high-speed-mode = <TEGRA_PIN_DISABLE>;
				nvidia,schmitt = <TEGRA_PIN_ENABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <31>;
				nvidia,pull-up-strength = <31>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_SLOWEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_SLOWEST>;
			};

			drive-i2c {
				nvidia,pins = "drive_dbg", "drive_ddc", "drive_at1",
						"drive_vi2", "drive_ao1";
				nvidia,high-speed-mode = <TEGRA_PIN_DISABLE>;
				nvidia,schmitt = <TEGRA_PIN_ENABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <31>;
				nvidia,pull-up-strength = <31>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_FASTEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_FASTEST>;
			};

			drive-dap {
				nvidia,pins = "drive_dap2", "drive_dap3";
				nvidia,high-speed-mode = <TEGRA_PIN_DISABLE>;
				nvidia,schmitt = <TEGRA_PIN_ENABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <46>;
				nvidia,pull-up-strength = <46>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_SLOWEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_SLOWEST>;
			};
		};
	};

	uartb: serial@70006040 {
		clocks = <&tegra_car 7>;
		status = "okay";
	};

	pwr_i2c: i2c@7000d000 {
		status = "okay";
		clock-frequency = <400000>;

		pmic: max8907@3c {
			compatible = "maxim,max8907";
			reg = <0x3c>;
			interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;

			maxim,system-power-controller;

			regulators {
				vdd_1v8_vio: sd3 {
					regulator-name = "vcc_1v8_io";
					regulator-min-microvolt = <1800000>;
					regulator-max-microvolt = <1800000>;
					regulator-always-on;
					regulator-boot-on;
				};

				iovcc_1v8_lcd: ldo3 {
					regulator-name = "vcc_1v8_lcd";
					regulator-min-microvolt = <1800000>;
					regulator-max-microvolt = <1800000>;
					regulator-boot-on;
				};

				avdd_3v3_usb: ldo4 {
					regulator-name = "avdd_3v3_usb";
					regulator-min-microvolt = <3300000>;
					regulator-max-microvolt = <3300000>;
					regulator-always-on;
					regulator-boot-on;
				};

				vcore_emmc: ldo5 {
					regulator-name = "vcc_2v8_emmc";
					regulator-min-microvolt = <2800000>;
					regulator-max-microvolt = <2800000>;
					regulator-boot-on;
				};

				vdd_usd: ldo12 {
					regulator-name = "vcc_2v8_sdio";
					regulator-min-microvolt = <2800000>;
					regulator-max-microvolt = <2800000>;
					regulator-boot-on;
				};

				vcc_2v8_lcd: ldo14 {
					regulator-name = "vcc_2v8_lcd";
					regulator-min-microvolt = <2800000>;
					regulator-max-microvolt = <2800000>;
					regulator-boot-on;
				};
			};
		};
	};

	dcdc_i2c: i2c-5 {
		compatible = "i2c-gpio";

		sda-gpios = <&gpio TEGRA_GPIO(Q, 0) GPIO_ACTIVE_HIGH>;
		scl-gpios = <&gpio TEGRA_GPIO(Q, 1) GPIO_ACTIVE_HIGH>;

		i2c-gpio,delay-us = <5>;
		i2c-gpio,timeout-ms = <100>;

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

		aat2870: led-controller@60 {
			compatible = "skyworks,aat2870";
			reg = <0x60>;

			enable-gpios = <&gpio TEGRA_GPIO(R, 3) GPIO_ACTIVE_HIGH>;

			backlight {
				current-max-microamp = <27900000>;
			};
		};
	};

	micro_usb: usb@c5000000 {
		status = "okay";
		dr_mode = "otg";
	};

	usb-phy@c5000000 {
		status = "okay";
		vbus-supply = <&avdd_3v3_usb>;
	};

	sdmmc3: mmc@c8000400 {
		status = "okay";
		bus-width = <4>;

		cd-gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;

		vmmc-supply = <&vdd_usd>;
		vqmmc-supply = <&vdd_1v8_vio>;
	};

	sdmmc4: mmc@c8000600 {
		status = "okay";
		bus-width = <8>;
		non-removable;

		vmmc-supply = <&vcore_emmc>;
		vqmmc-supply = <&vdd_1v8_vio>;
	};

	/* 32KHz oscillator which is used by PMC */
	clk32k_in: clock-32k-in {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <32768>;
		clock-output-names = "ref-oscillator";
	};

	bridge: cpu-bridge {
		compatible = "nvidia,tegra-8bit-cpu";

		dc-gpios = <&gpio TEGRA_GPIO(N, 6) GPIO_ACTIVE_HIGH>;
		rw-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_HIGH>;
		cs-gpios = <&gpio TEGRA_GPIO(N, 4) GPIO_ACTIVE_HIGH>;

		data-gpios = <&gpio TEGRA_GPIO(E, 0) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 1) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 2) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 3) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 4) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 5) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 6) GPIO_ACTIVE_HIGH>,
			     <&gpio TEGRA_GPIO(E, 7) GPIO_ACTIVE_HIGH>;

		nvidia,init-sequence = <0x0000002c 0x0 0x0 0x00005000>;

		panel {
			/*
			 * There are 2 rev of P990. One has Hitachi TX10D07VM0BAA
			 * panel and other has LG LH400WV3-SD04 panel. We are using
			 * Hitachi here but it is dynamically adjusted for the
			 * correct compatible.
			 */
			compatible = "hit,tx10d07vm0baa";

			reset-gpios = <&gpio TEGRA_GPIO(V, 7) GPIO_ACTIVE_LOW>;

			avci-supply = <&vcc_2v8_lcd>;
			iovcc-supply = <&iovcc_1v8_lcd>;

			backlight = <&aat2870>;

			port {
				panel_input: endpoint {
					remote-endpoint = <&bridge_output>;
				};
			};
		};

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

			port@0 {
				reg = <0>;

				bridge_input: endpoint {
					remote-endpoint = <&dpi_output>;
				};
			};

			port@1 {
				reg = <1>;

				bridge_output: endpoint {
					remote-endpoint = <&panel_input>;
				};
			};
		};
	};

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

		key-power {
			label = "Power";
			gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>;
			linux,code = <KEY_ENTER>;
		};

		key-volume-up {
			label = "Volume Up";
			gpios = <&gpio TEGRA_GPIO(G, 1) GPIO_ACTIVE_LOW>;
			linux,code = <KEY_UP>;
		};

		key-volume-down {
			label = "Volume Down";
			gpios = <&gpio TEGRA_GPIO(G, 0) GPIO_ACTIVE_LOW>;
			linux,code = <KEY_DOWN>;
		};
	};

	vdd_3v3_vbat: regulator-vbat {
		compatible = "regulator-fixed";
		regulator-name = "vdd_vbat";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-always-on;
		regulator-boot-on;
	};
};
