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

#include <dt-bindings/input/input.h>
#include "tegra124.dtsi"

/ {
	model = "Xiaomi Mi Pad A0101";
	compatible = "xiaomi,mocha", "nvidia,tegra124";

	chosen {
		stdout-path = &uartd;
	};

	aliases {
		i2c0 = &pwr_i2c;
		i2c1 = &gen1_i2c;

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

		usb0 = &usb1;
	};

	memory {
		device_type = "memory";
		reg = <0x80000000 0x80000000>;
	};

	host1x@50000000 {
		dsia: dsi@54300000 {
			status = "okay";

			avdd-dsi-csi-supply = <&avdd_dsi_csi>;
			nvidia,ganged-mode = <&dsib>;

			panel@0 {
				compatible = "sharp,lq079l1sx01";
				reg = <0>;

				link2 = <&panel_secondary>;

				avdd-supply = <&avdd_lcd>;
				vddio-supply = <&vdd_lcd_io>;

				vsp-supply = <&vsp_5v5_lcd>;
				vsn-supply = <&vsn_5v5_lcd>;

				reset-gpios = <&gpio TEGRA_GPIO(H, 3) GPIO_ACTIVE_LOW>;

				backlight = <&lp8556>;
			};
		};

		dsib: dsi@54400000 {
			status = "okay";

			avdd-dsi-csi-supply = <&avdd_dsi_csi>;

			panel_secondary: panel@0 {
				compatible = "sharp,lq079l1sx01";
				reg = <0>;
			};
		};
	};

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

		state_default: pinmux {
			/* Keys pinmux */
			keys {
				nvidia,pins = "kb_col0_pq0",
						"kb_col6_pq6",
						"kb_col7_pq7";
				nvidia,function = "rsvd2";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			hall-front {
				nvidia,pins = "pi5";
				nvidia,function = "gmi";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			hall-back {
				nvidia,pins = "gpio_w3_aud_pw3";
				nvidia,function = "spi1";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			/* Leds pinmux */
			bl-en {
				nvidia,pins = "pbb4";
				nvidia,function = "vgp4";
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			keys-led {
				nvidia,pins = "ph1";
				nvidia,function = "pwm1";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};

			/* Panel pinmux */
			lcd-rst {
				nvidia,pins = "ph3";
				nvidia,function = "gmi";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			lcd-vsp {
				nvidia,pins = "pi4";
				nvidia,function = "gmi";
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			lcd-vsn {
				nvidia,pins = "kb_row10_ps2";
				nvidia,function = "kbc";
				nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			lcd-id {
				nvidia,pins = "kb_row6_pr6";
				nvidia,function = "displaya_alt";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			lcd-pwm {
				nvidia,pins = "ph2";
				nvidia,function = "pwm2";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};

			/* SDMMC3 pinmux */
			sdmmc3-clk {
				nvidia,pins = "sdmmc3_clk_pa6";
				nvidia,function = "sdmmc3";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			sdmmc3-cmd {
				nvidia,pins = "sdmmc3_cmd_pa7",
						"sdmmc3_dat0_pb7",
						"sdmmc3_dat1_pb6",
						"sdmmc3_dat2_pb5",
						"sdmmc3_dat3_pb4",
						"sdmmc3_clk_lb_out_pee4",
						"sdmmc3_clk_lb_in_pee5";
				nvidia,function = "sdmmc3";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			sdmmc3-cd {
				nvidia,pins = "sdmmc3_cd_n_pv2";
				nvidia,function = "sdmmc3";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			usd-pwr {
				nvidia,pins = "kb_row0_pr0";
				nvidia,function = "rsvd4";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};

			/* SDMMC4 pinmux */
			sdmmc4-clk {
				nvidia,pins = "sdmmc4_clk_pcc4";
				nvidia,function = "sdmmc4";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			sdmmc4-cmd {
				nvidia,pins = "sdmmc4_cmd_pt7",
						"sdmmc4_dat0_paa0",
						"sdmmc4_dat1_paa1",
						"sdmmc4_dat2_paa2",
						"sdmmc4_dat3_paa3",
						"sdmmc4_dat4_paa4",
						"sdmmc4_dat5_paa5",
						"sdmmc4_dat6_paa6",
						"sdmmc4_dat7_paa7";
				nvidia,function = "sdmmc4";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			/* I2C pinmux */
			gen1-i2c {
				nvidia,pins = "gen1_i2c_sda_pc5",
						"gen1_i2c_scl_pc4";
				nvidia,function = "i2c1";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,lock = <TEGRA_PIN_DISABLE>;
				nvidia,open-drain = <TEGRA_PIN_DISABLE>;
			};
			gen2-i2c {
				nvidia,pins = "gen2_i2c_scl_pt5",
						"gen2_i2c_sda_pt6";
				nvidia,function = "i2c2";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,lock = <TEGRA_PIN_DISABLE>;
				nvidia,open-drain = <TEGRA_PIN_DISABLE>;
			};
			cam-i2c {
				nvidia,pins = "cam_i2c_scl_pbb1",
						"cam_i2c_sda_pbb2";
				nvidia,function = "i2c3";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,lock = <TEGRA_PIN_DISABLE>;
				nvidia,open-drain = <TEGRA_PIN_DISABLE>;
			};
			ddc-i2c {
				nvidia,pins = "ddc_scl_pv4",
						"ddc_sda_pv5";
				nvidia,function = "i2c4";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			pwr-i2c {
				nvidia,pins = "pwr_i2c_scl_pz6",
						"pwr_i2c_sda_pz7";
				nvidia,function = "i2cpwr";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,open-drain = <TEGRA_PIN_DISABLE>;
			};

			dsi-b {
				nvidia,pins = "mipi_pad_ctrl_dsi_b";
				nvidia,function = "dsi_b";
			};

			/* GPIO power/drive control */
			drive-sdio1 {
				nvidia,pins = "drive_sdio1";
				nvidia,high-speed-mode = <TEGRA_PIN_ENABLE>;
				nvidia,schmitt = <TEGRA_PIN_DISABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <32>;
				nvidia,pull-up-strength = <42>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_FASTEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_FASTEST>;
			};

			drive-sdio3 {
				nvidia,pins = "drive_sdio3";
				nvidia,high-speed-mode = <TEGRA_PIN_ENABLE>;
				nvidia,schmitt = <TEGRA_PIN_DISABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <20>;
				nvidia,pull-up-strength = <36>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_FASTEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_FASTEST>;
			};

			drive-gma {
				nvidia,pins = "drive_gma";
				nvidia,high-speed-mode = <TEGRA_PIN_ENABLE>;
				nvidia,schmitt = <TEGRA_PIN_DISABLE>;
				nvidia,low-power-mode = <TEGRA_PIN_LP_DRIVE_DIV_1>;
				nvidia,pull-down-strength = <1>;
				nvidia,pull-up-strength = <2>;
				nvidia,slew-rate-rising = <TEGRA_PIN_SLEW_RATE_FASTEST>;
				nvidia,slew-rate-falling = <TEGRA_PIN_SLEW_RATE_FASTEST>;
			};
		};
	};

	uartd: serial@70006300 {
		status = "okay";
	};

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

		lp8556: backlight@2c {
			compatible = "ti,lp8556";
			reg = <0x2c>;

			dev-ctrl = /bits/ 8 <0x83>;
			init-brt = /bits/ 8 <0x1f>;

			power-supply = <&vdd_3v3_sys>;
			enable-supply = <&vddio_1v8_bl>;

			rom-98h {
				rom-addr = /bits/ 8 <0x98>;
				rom-val = /bits/ 8 <0x80>;
			};

			rom-9eh {
				rom-addr = /bits/ 8 <0x9e>;
				rom-val = /bits/ 8 <0x21>;
			};

			rom-a0h {
				rom-addr = /bits/ 8 <0xa0>;
				rom-val = /bits/ 8 <0xff>;
			};

			rom-a1h {
				rom-addr = /bits/ 8 <0xa1>;
				rom-val = /bits/ 8 <0x3f>;
			};

			rom-a2h {
				rom-addr = /bits/ 8 <0xa2>;
				rom-val = /bits/ 8 <0x20>;
			};

			rom-a3h {
				rom-addr = /bits/ 8 <0xa3>;
				rom-val = /bits/ 8 <0x00>;
			};

			rom-a4h {
				rom-addr = /bits/ 8 <0xa4>;
				rom-val = /bits/ 8 <0x72>;
			};

			rom-a5h {
				rom-addr = /bits/ 8 <0xa5>;
				rom-val = /bits/ 8 <0x24>;
			};

			rom-a6h {
				rom-addr = /bits/ 8 <0xa6>;
				rom-val = /bits/ 8 <0x80>;
			};

			rom-a7h {
				rom-addr = /bits/ 8 <0xa7>;
				rom-val = /bits/ 8 <0xf5>;
			};

			rom-a8h {
				rom-addr = /bits/ 8 <0xa8>;
				rom-val = /bits/ 8 <0x24>;
			};

			rom-a9h {
				rom-addr = /bits/ 8 <0xa9>;
				rom-val = /bits/ 8 <0xb2>;
			};

			rom-aah {
				rom-addr = /bits/ 8 <0xaa>;
				rom-val = /bits/ 8 <0x8f>;
			};

			rom-aeh {
				rom-addr = /bits/ 8 <0xae>;
				rom-val = /bits/ 8 <0x0f>;
			};
		};
	};

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

		/* Texas Instruments TPS65913 PMIC */
		pmic: tps65913@58 {
			compatible = "ti,tps65913";
			reg = <0x58>;

			interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
			#interrupt-cells = <2>;
			interrupt-controller;

			ti,system-power-controller;

			palmas_gpio: gpio {
				compatible = "ti,palmas-gpio";
				gpio-controller;
				#gpio-cells = <2>;
			};

			pinmux {
				compatible = "ti,tps65913-pinctrl";

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

				palmas_default: pinmux {
					pin_gpio4 {
						pins = "gpio4";
						function = "gpio";
					};
				};
			};

			pmic {
				compatible = "ti,tps65913-pmic";

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

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

					avdd_lcd: ldo2 {
						regulator-name = "avdd_lcd";
						regulator-min-microvolt = <1800000>;
						regulator-max-microvolt = <1800000>;
						regulator-boot-on;
					};

					avdd_dsi_csi: ldo5 {
						regulator-name = "avdd_dsi_csi";
						regulator-min-microvolt = <1200000>;
						regulator-max-microvolt = <1200000>;
						regulator-boot-on;
					};

					vddio_usd: ldo9 {
						regulator-name = "vddio_sdmmc";
						regulator-min-microvolt = <3300000>;
						regulator-max-microvolt = <3300000>;
						regulator-always-on;
						regulator-boot-on;
					};

					avdd_usb: ldousb {
						regulator-name = "vdd_usb";
						regulator-min-microvolt = <3300000>;
						regulator-max-microvolt = <3300000>;
						regulator-always-on;
						regulator-boot-on;
					};
				};
			};
		};
	};

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

		cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
		power-gpios = <&gpio TEGRA_GPIO(R, 0) GPIO_ACTIVE_HIGH>;

		vmmc-supply = <&vdd_hv_sdmmc>;
		vqmmc-supply = <&vddio_usd>;
	};

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

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

	usb1: usb@7d000000 {
		status = "okay";
		dr_mode = "otg";
	};

	clk32k_in: clock-32k {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <32768>;
		clock-output-names = "ref-oscillator";
	};

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

		switch-back-hall-sensor {
			label = "Hall sensor (back)";
			gpios = <&gpio TEGRA_GPIO(W, 3) GPIO_ACTIVE_LOW>;
			linux,code = <SW_LID>;
		};

		switch-front-hall-sensor {
			label = "Hall sensor (front)";
			gpios = <&gpio TEGRA_GPIO(I, 5) GPIO_ACTIVE_LOW>;
			linux,code = <SW_LID>;
		};
	};

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

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

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

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

	vdd_3v3_sys: regulator-bl-en {
		compatible = "regulator-fixed";
		regulator-name = "vdd_5v0_bl";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		enable-active-high;
	};

	vddio_1v8_bl: regulator-bl-io {
		compatible = "regulator-fixed";
		regulator-name = "vddio_1v8_bl";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		enable-active-high;
		gpio = <&gpio TEGRA_GPIO(BB, 4) GPIO_ACTIVE_HIGH>;
	};

	vdd_lcd_io: regulator-lcdvio {
		compatible = "regulator-fixed";
		regulator-name = "dvdd_lcd";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		enable-active-high;
		gpio = <&palmas_gpio 4 GPIO_ACTIVE_HIGH>;
	};

	vsp_5v5_lcd: regulator-vsp {
		compatible = "regulator-fixed";
		regulator-name = "avdd_lcd_vsp";
		regulator-min-microvolt = <5500000>;
		regulator-max-microvolt = <5500000>;
		enable-active-high;
		gpio = <&gpio TEGRA_GPIO(I, 4) GPIO_ACTIVE_HIGH>;
	};

	vsn_5v5_lcd: regulator-vsn {
		compatible = "regulator-fixed";
		regulator-name = "avdd_lcd_vsn";
		regulator-min-microvolt = <5500000>;
		regulator-max-microvolt = <5500000>;
		enable-active-high;
		gpio = <&gpio TEGRA_GPIO(S, 2) GPIO_ACTIVE_HIGH>;
	};
};
