// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2021 BayLibre, SAS.
 * Author: Fabien Parent <fparent@baylibre.com>
 */

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include "mt8183.dtsi"
#include "mt6358.dtsi"

/ {
	model = "Pumpkin MT8183";
	compatible = "mediatek,mt8183-pumpkin", "mediatek,mt8183";

	aliases {
		serial0 = &uart0;
	};

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

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

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		scp_mem_reserved: scp-mem@50000000 {
			compatible = "shared-dma-pool";
			reg = <0 0x50000000 0 0x2900000>;
			no-map;
		};
	};

	leds {
		compatible = "gpio-leds";

		led-red {
			label = "red";
			gpios = <&pio 155 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};

		led-green {
			label = "green";
			gpios = <&pio 156 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};
	};

	thermistor {
		compatible = "murata,ncp03wf104";
		pullup-uv = <1800000>;
		pullup-ohm = <390000>;
		pulldown-ohm = <0>;
		io-channels = <&auxadc 0>;
	};

	connector {
		compatible = "hdmi-connector";
		label = "hdmi";
		type = "d";

		port {
			hdmi_connector_in: endpoint {
				remote-endpoint = <&hdmi_connector_out>;
			};
		};
	};
};

&auxadc {
	status = "okay";
};

&gpu {
	mali-supply = <&mt6358_vgpu_reg>;
};

&i2c0 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_0>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_1>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c2 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_2>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c3 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_3>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c4 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_4>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c5 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c_pins_5>;
	status = "okay";
	clock-frequency = <100000>;
};

&i2c6 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c6_pins>;
	status = "okay";
	clock-frequency = <100000>;
	#address-cells = <1>;
	#size-cells = <0>;

	it66121hdmitx: hdmitx@4c {
		compatible = "ite,it66121";
		reg = <0x4c>;
		pinctrl-names = "default";
		pinctrl-0 = <&ite_pins>;
		reset-gpios = <&pio 160 GPIO_ACTIVE_LOW>;
		interrupt-parent = <&pio>;
		interrupts = <4 IRQ_TYPE_LEVEL_LOW>;
		vcn33-supply = <&mt6358_vcn33_reg>;
		vcn18-supply = <&mt6358_vcn18_reg>;
		vrf12-supply = <&mt6358_vrf12_reg>;

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

			port@0 {
				reg = <0>;

				it66121_in: endpoint {
					bus-width = <12>;
					remote-endpoint = <&dpi_out>;
				};
			};

			port@1 {
				reg = <1>;

				hdmi_connector_out: endpoint {
					remote-endpoint = <&hdmi_connector_in>;
				};
			};
		};
	};
};

&keyboard {
	pinctrl-names = "default";
	pinctrl-0 = <&keyboard_pins>;
	status = "okay";
	linux,keymap = <MATRIX_KEY(0x00, 0x00, KEY_VOLUMEDOWN)
			MATRIX_KEY(0x01, 0x00, KEY_VOLUMEUP)>;
	keypad,num-rows = <2>;
	keypad,num-columns = <1>;
	debounce-delay-ms = <32>;
	mediatek,keys-per-group = <2>;
};

&mmc0 {
	status = "okay";
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc0_pins_default>;
	pinctrl-1 = <&mmc0_pins_uhs>;
	bus-width = <8>;
	max-frequency = <200000000>;
	cap-mmc-highspeed;
	mmc-hs200-1_8v;
	mmc-hs400-1_8v;
	cap-mmc-hw-reset;
	no-sdio;
	no-sd;
	hs400-ds-delay = <0x12814>;
	vmmc-supply = <&mt6358_vemc_reg>;
	vqmmc-supply = <&mt6358_vio18_reg>;
	assigned-clocks = <&topckgen CLK_TOP_MUX_MSDC50_0>;
	assigned-clock-parents = <&topckgen CLK_TOP_MSDCPLL_CK>;
	non-removable;
};

&mmc1 {
	status = "okay";
	pinctrl-names = "default", "state_uhs";
	pinctrl-0 = <&mmc1_pins_default>;
	pinctrl-1 = <&mmc1_pins_uhs>;
	bus-width = <4>;
	max-frequency = <200000000>;
	cap-sd-highspeed;
	sd-uhs-sdr50;
	sd-uhs-sdr104;
	cap-sdio-irq;
	no-mmc;
	no-sd;
	vmmc-supply = <&mt6358_vmch_reg>;
	vqmmc-supply = <&mt6358_vmc_reg>;
	keep-power-in-suspend;
	wakeup-source;
	non-removable;
};

&mt6358_vgpu_reg {
	regulator-min-microvolt = <625000>;
	regulator-max-microvolt = <900000>;

	regulator-coupled-with = <&mt6358_vsram_gpu_reg>;
	regulator-coupled-max-spread = <100000>;
};

&mt6358_vsram_gpu_reg {
	regulator-min-microvolt = <850000>;
	regulator-max-microvolt = <1000000>;

	regulator-coupled-with = <&mt6358_vgpu_reg>;
	regulator-coupled-max-spread = <100000>;
};

&pio {
	i2c_pins_0: i2c0-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO82__FUNC_SDA0>,
				 <PINMUX_GPIO83__FUNC_SCL0>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c_pins_1: i2c1-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO81__FUNC_SDA1>,
				 <PINMUX_GPIO84__FUNC_SCL1>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c_pins_2: i2c2-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO103__FUNC_SCL2>,
				 <PINMUX_GPIO104__FUNC_SDA2>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c_pins_3: i2c3-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO50__FUNC_SCL3>,
				 <PINMUX_GPIO51__FUNC_SDA3>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c_pins_4: i2c4-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO105__FUNC_SCL4>,
				 <PINMUX_GPIO106__FUNC_SDA4>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c_pins_5: i2c5-pins {
		pins_i2c {
			pinmux = <PINMUX_GPIO48__FUNC_SCL5>,
				 <PINMUX_GPIO49__FUNC_SDA5>;
			mediatek,pull-up-adv = <3>;
		};
	};

	i2c6_pins: i2c6-pins {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO113__FUNC_SCL6>,
				 <PINMUX_GPIO114__FUNC_SDA6>;
			mediatek,pull-up-adv = <3>;
		};
	};

	keyboard_pins: keyboard-pins {
		pins_keyboard {
			pinmux = <PINMUX_GPIO91__FUNC_KPROW1>,
				 <PINMUX_GPIO92__FUNC_KPROW0>,
				 <PINMUX_GPIO93__FUNC_KPCOL0>;
		};
	};

	mmc0_pins_default: mmc0-pins-default {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO123__FUNC_MSDC0_DAT0>,
				 <PINMUX_GPIO128__FUNC_MSDC0_DAT1>,
				 <PINMUX_GPIO125__FUNC_MSDC0_DAT2>,
				 <PINMUX_GPIO132__FUNC_MSDC0_DAT3>,
				 <PINMUX_GPIO126__FUNC_MSDC0_DAT4>,
				 <PINMUX_GPIO129__FUNC_MSDC0_DAT5>,
				 <PINMUX_GPIO127__FUNC_MSDC0_DAT6>,
				 <PINMUX_GPIO130__FUNC_MSDC0_DAT7>,
				 <PINMUX_GPIO122__FUNC_MSDC0_CMD>;
			input-enable;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-up-adv = <01>;
		};

		pins_clk {
			pinmux = <PINMUX_GPIO124__FUNC_MSDC0_CLK>;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-down-adv = <2>;
		};

		pins_rst {
			pinmux = <PINMUX_GPIO133__FUNC_MSDC0_RSTB>;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-down-adv = <01>;
		};
	};

	mmc0_pins_uhs: mmc0-pins-uhs {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO123__FUNC_MSDC0_DAT0>,
				 <PINMUX_GPIO128__FUNC_MSDC0_DAT1>,
				 <PINMUX_GPIO125__FUNC_MSDC0_DAT2>,
				 <PINMUX_GPIO132__FUNC_MSDC0_DAT3>,
				 <PINMUX_GPIO126__FUNC_MSDC0_DAT4>,
				 <PINMUX_GPIO129__FUNC_MSDC0_DAT5>,
				 <PINMUX_GPIO127__FUNC_MSDC0_DAT6>,
				 <PINMUX_GPIO130__FUNC_MSDC0_DAT7>,
				 <PINMUX_GPIO122__FUNC_MSDC0_CMD>;
			input-enable;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-up-adv = <01>;
		};

		pins_clk {
			pinmux = <PINMUX_GPIO124__FUNC_MSDC0_CLK>;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-down-adv = <2>;
		};

		pins_ds {
			pinmux = <PINMUX_GPIO131__FUNC_MSDC0_DSL>;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-down-adv = <2>;
		};

		pins_rst {
			pinmux = <PINMUX_GPIO133__FUNC_MSDC0_RSTB>;
			drive-strength = <MTK_DRIVE_14mA>;
			mediatek,pull-up-adv = <01>;
		};
	};

	mmc1_pins_default: mmc1-pins-default {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO31__FUNC_MSDC1_CMD>,
				 <PINMUX_GPIO32__FUNC_MSDC1_DAT0>,
				 <PINMUX_GPIO34__FUNC_MSDC1_DAT1>,
				 <PINMUX_GPIO33__FUNC_MSDC1_DAT2>,
				 <PINMUX_GPIO30__FUNC_MSDC1_DAT3>;
			input-enable;
			mediatek,pull-up-adv = <2>;
		};

		pins_clk {
			pinmux = <PINMUX_GPIO29__FUNC_MSDC1_CLK>;
			input-enable;
			mediatek,pull-down-adv = <2>;
		};

		pins_pmu {
			pinmux = <PINMUX_GPIO178__FUNC_GPIO178>;
			output-high;
		};
	};

	mmc1_pins_uhs: mmc1-pins-uhs {
		pins_cmd_dat {
			pinmux = <PINMUX_GPIO31__FUNC_MSDC1_CMD>,
				 <PINMUX_GPIO32__FUNC_MSDC1_DAT0>,
				 <PINMUX_GPIO34__FUNC_MSDC1_DAT1>,
				 <PINMUX_GPIO33__FUNC_MSDC1_DAT2>,
				 <PINMUX_GPIO30__FUNC_MSDC1_DAT3>;
			drive-strength = <6>;
			input-enable;
			mediatek,pull-up-adv = <2>;
		};

		pins_clk {
			pinmux = <PINMUX_GPIO29__FUNC_MSDC1_CLK>;
			drive-strength = <8>;
			mediatek,pull-down-adv = <2>;
			input-enable;
		};
	};

	ite_pins: ite-pins {
		pins-irq {
			pinmux = <PINMUX_GPIO4__FUNC_GPIO4>;
			input-enable;
			bias-pull-up;
		};

		pins-rst {
			pinmux = <PINMUX_GPIO160__FUNC_GPIO160>;
			output-high;
		};
	};

	dpi_func_pins: dpi-func-pins {
		pins-dpi {
			pinmux = <PINMUX_GPIO12__FUNC_I2S5_BCK>,
				 <PINMUX_GPIO46__FUNC_I2S5_LRCK>,
				 <PINMUX_GPIO47__FUNC_I2S5_DO>,
				 <PINMUX_GPIO13__FUNC_DBPI_D0>,
				 <PINMUX_GPIO14__FUNC_DBPI_D1>,
				 <PINMUX_GPIO15__FUNC_DBPI_D2>,
				 <PINMUX_GPIO16__FUNC_DBPI_D3>,
				 <PINMUX_GPIO17__FUNC_DBPI_D4>,
				 <PINMUX_GPIO18__FUNC_DBPI_D5>,
				 <PINMUX_GPIO19__FUNC_DBPI_D6>,
				 <PINMUX_GPIO20__FUNC_DBPI_D7>,
				 <PINMUX_GPIO21__FUNC_DBPI_D8>,
				 <PINMUX_GPIO22__FUNC_DBPI_D9>,
				 <PINMUX_GPIO23__FUNC_DBPI_D10>,
				 <PINMUX_GPIO24__FUNC_DBPI_D11>,
				 <PINMUX_GPIO25__FUNC_DBPI_HSYNC>,
				 <PINMUX_GPIO26__FUNC_DBPI_VSYNC>,
				 <PINMUX_GPIO27__FUNC_DBPI_DE>,
				 <PINMUX_GPIO28__FUNC_DBPI_CK>;
		};
	};

	dpi_idle_pins: dpi-idle-pins {
		pins-idle {
			pinmux = <PINMUX_GPIO12__FUNC_GPIO12>,
				 <PINMUX_GPIO46__FUNC_GPIO46>,
				 <PINMUX_GPIO47__FUNC_GPIO47>,
				 <PINMUX_GPIO13__FUNC_GPIO13>,
				 <PINMUX_GPIO14__FUNC_GPIO14>,
				 <PINMUX_GPIO15__FUNC_GPIO15>,
				 <PINMUX_GPIO16__FUNC_GPIO16>,
				 <PINMUX_GPIO17__FUNC_GPIO17>,
				 <PINMUX_GPIO18__FUNC_GPIO18>,
				 <PINMUX_GPIO19__FUNC_GPIO19>,
				 <PINMUX_GPIO20__FUNC_GPIO20>,
				 <PINMUX_GPIO21__FUNC_GPIO21>,
				 <PINMUX_GPIO22__FUNC_GPIO22>,
				 <PINMUX_GPIO23__FUNC_GPIO23>,
				 <PINMUX_GPIO24__FUNC_GPIO24>,
				 <PINMUX_GPIO25__FUNC_GPIO25>,
				 <PINMUX_GPIO26__FUNC_GPIO26>,
				 <PINMUX_GPIO27__FUNC_GPIO27>,
				 <PINMUX_GPIO28__FUNC_GPIO28>;
		};
	};
};

&pmic {
	interrupts-extended = <&pio 182 IRQ_TYPE_LEVEL_HIGH>;
};

&mfg {
	domain-supply = <&mt6358_vgpu_reg>;
};

&cci {
	proc-supply = <&mt6358_vproc12_reg>;
};

&cpu0 {
	proc-supply = <&mt6358_vproc12_reg>;
};

&cpu1 {
	proc-supply = <&mt6358_vproc12_reg>;
};

&cpu2 {
	proc-supply = <&mt6358_vproc12_reg>;
};

&cpu3 {
	proc-supply = <&mt6358_vproc12_reg>;
};

&cpu4 {
	proc-supply = <&mt6358_vproc11_reg>;
};

&cpu5 {
	proc-supply = <&mt6358_vproc11_reg>;
};

&cpu6 {
	proc-supply = <&mt6358_vproc11_reg>;
};

&cpu7 {
	proc-supply = <&mt6358_vproc11_reg>;
};

&uart0 {
	status = "okay";
};

&scp {
	status = "okay";
};

&dpi0 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&dpi_func_pins>;
	pinctrl-1 = <&dpi_idle_pins>;
	status = "okay";
};

&dpi_out {
	remote-endpoint = <&it66121_in>;
};