// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd.
 */

/dts-v1/;

#include "rk3399-excavator-sapphire.dtsi"
#include "rk3399-linux.dtsi"
#include <dt-bindings/input/input.h>

/ {
	model = "Rockchip RK3399 Excavator Board (Linux Opensource)";
	compatible = "rockchip,rk3399-excavator-linux", "rockchip,rk3399";

	fiq_debugger: fiq-debugger {
		compatible = "rockchip,fiq-debugger";
		rockchip,serial-id = <2>;
		rockchip,signal-irq = <182>;
		rockchip,wake-irq = <0>;
		rockchip,irq-mode-enable = <1>;  /* If enable uart uses irq instead of fiq */
		rockchip,baudrate = <1500000>;  /* Only 115200 and 1500000 */
		pinctrl-names = "default";
		pinctrl-0 = <&uart2c_xfer>;
	};

	edp_panel: edp-panel {
		compatible = "lg,lp079qx1-sp0v", "panel-simple";
		backlight = <&backlight>;
		power-supply = <&vcc3v3_s0>;
		enable-gpios = <&gpio4 30 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&lcd_panel_reset>;

		ports {
			panel_in_edp: endpoint {
				remote-endpoint = <&edp_out_panel>;
			};
		};
	};

	hdmi_sound: hdmi-sound {
		status = "okay";
	};

	gpio-keys {
		compatible = "gpio-keys";
		#address-cells = <1>;
		#size-cells = <0>;
		autorepeat;

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

		button@0 {
			gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
			label = "GPIO Key Power";
			linux,input-type = <1>;
			gpio-key,wakeup = <1>;
			debounce-interval = <100>;
		};
	};

	vccadc_ref: vccadc-ref {
		compatible = "regulator-fixed";
		regulator-name = "vcc1v8_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
	};

	ext_cam_clk: external-camera-clock {
		compatible = "fixed-clock";
		clock-frequency = <27000000>;
		clock-output-names = "CLK_CAMERA_27MHZ";
		#clock-cells = <0>;
	};

	adc-keys {
		compatible = "adc-keys";
		io-channels = <&saradc 1>;
		io-channel-names = "buttons";
		poll-interval = <100>;
		keyup-threshold-microvolt = <1800000>;

		button-up {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			press-threshold-microvolt = <100000>;
		};

		button-down {
			label = "Volume Down";
			linux,code = <KEY_VOLUMEDOWN>;
			press-threshold-microvolt = <300000>;
		};

		back {
			label = "Back";
			linux,code = <KEY_BACK>;
			press-threshold-microvolt = <985000>;
		};

		menu {
			label = "Menu";
			linux,code = <KEY_MENU>;
			press-threshold-microvolt = <1314000>;
		};
	};
};

&rkisp1_0 {
	status = "okay";

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

		isp0_mipi_in: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&dphy_rx0_out>;
		};
	};
};

&mipi_dphy_rx0 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi_in_ucam0: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&ucam_out0>;
				data-lanes = <1 2>;
			};
		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			dphy_rx0_out: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&isp0_mipi_in>;
			};
		};
	};
};

&isp0_mmu {
	status = "okay";
};

&rkisp1_1 {
	status = "okay";

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

		isp1_mipi_in: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&dphy_tx1rx1_out>;
		};
	};
};

&mipi_dphy_tx1rx1 {
	status = "okay";

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

		port@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;

			mipi_in_ucam1: endpoint@1 {
				reg = <1>;
				/* Unlinked camera */
				//remote-endpoint = <&ucam_out1>;
				data-lanes = <1 2>;
			};
		};

		port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			dphy_tx1rx1_out: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&isp1_mipi_in>;
			};
		};
	};
};

&isp1_mmu {
	status = "okay";
};

&saradc {
	vref-supply = <&vccadc_ref>;
};

&backlight {
	status = "okay";
	enable-gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>;
};

&cdn_dp {
	status = "disabled";
};

&display_subsystem {
	status = "okay";
};

&dsi_in_vopl {
	status = "okay";
};

&dsi_in_vopb {
	status = "disabled";
};

&dsi {
	status = "okay";

	panel@0 {
		compatible ="simple-panel-dsi";
		reg = <0>;

		dsi,flags = <(MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST)>;
		dsi,format = <MIPI_DSI_FMT_RGB888>;
		dsi,lanes = <4>;

		display-timings {
			native-mode = <&timing0_720p_30hz>;

			timing0_720p_30hz: timing0-720p-30hz {
				clock-frequency = <96000000>;
				hactive = <1280>;
				vactive = <720>;
				hback-porch = <200>;
				hfront-porch = <1000>;
				vback-porch = <100>;
				vfront-porch = <200>;
				hsync-len = <200>;
				vsync-len = <200>;
				hsync-active = <0>;
				vsync-active = <0>;
				de-active = <0>;
				pixelclk-active = <0>;
			};

			timing1_1080p_30hz: timing0-1080p-30hz {
				clock-frequency = <76000000>;
				hactive = <1920>;
				vactive = <1080>;
				hback-porch = <100>;
				hfront-porch = <200>;
				vback-porch = <10>;
				vfront-porch = <10>;
				hsync-len = <20>;
				vsync-len = <20>;
				hsync-active = <0>;
				vsync-active = <0>;
				de-active = <0>;
				pixelclk-active = <0>;
			};

			timing2_1080p_87hz: timing1-1080p-87hz {
				clock-frequency = <220000000>;
				hactive = <1920>;
				vactive = <1080>;
				hback-porch = <200>;
				hfront-porch = <120>;
				vback-porch = <20>;
				vfront-porch = <2>;
				hsync-len = <20>;
				vsync-len = <10>;
				hsync-active = <0>;
				vsync-active = <0>;
				de-active = <0>;
				pixelclk-active = <0>;
			};
		};

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

			port@0 {
				reg = <0>;
				panel_in_dsi: endpoint {
					remote-endpoint = <&dsi_out_panel>;
				};
			};
		};
	};

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

		port@1 {
			reg = <1>;
			dsi_out_panel: endpoint {
				remote-endpoint = <&panel_in_dsi>;
			};
		};
	};
};

&edp_in_vopl {
	status = "disabled";
};

&edp_in_vopb {
	status = "okay";
};

&route_edp {
	status = "okay";
};

&edp {
	force-hpd;
	status = "okay";

	ports {
		edp_out: port@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			edp_out_panel: endpoint@0 {
				reg = <0>;
				remote-endpoint = <&panel_in_edp>;
			};
		};
	};
};

&hdmi {
	/* remove the hdmi_cec, reused by edp_hpd */
	pinctrl-0 = <&hdmi_i2c_xfer>;
	#address-cells = <1>;
	#size-cells = <0>;
	#sound-dai-cells = <0>;
	status = "okay";
};

&i2c1 {
	status = "okay";

	gsl3673: gsl3673@40 {
		compatible = "GSL,GSL3673";
		reg = <0x40>;
		screen_max_x = <1536>;
		screen_max_y = <2048>;
		irq_gpio_number = <&gpio1 20 IRQ_TYPE_LEVEL_LOW>;
		rst_gpio_number = <&gpio4 22 GPIO_ACTIVE_HIGH>;
	};

	tc358749x: tc358749x@f {
		compatible = "toshiba,tc358749";
		reg = <0xf>;
		clocks = <&ext_cam_clk>;
		clock-names = "refclk";
		reset-gpios = <&gpio2 7 GPIO_ACTIVE_LOW>;
		interrupt-parent = <&gpio2>;
		interrupts = <12 IRQ_TYPE_LEVEL_LOW>;
		pinctrl-names = "default";
		pinctrl-0 = <&hdmiin_gpios>;
		status = "disabled";
		port {
			hdmiin_out0: endpoint {
				/* Unlinked mipi dphy rx0 */
				//remote-endpoint = <&mipi_in_ucam0>;
				data-lanes = <1 2 3 4>;
				clock-noncontinuous;
				link-frequencies =
					/bits/ 64 <297000000>;
			};
		};
	};

	vm149c: vm149c@0c {
		compatible = "silicon touch,vm149c";
		status = "okay";
		reg = <0x0c>;
		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
	};

	ov13850: ov13850@10 {
		compatible = "ovti,ov13850";
		status = "okay";
		reg = <0x10>;
		clocks = <&cru SCLK_CIF_OUT>;
		clock-names = "xvclk";

		/* conflict with csi-ctl-gpios */
		reset-gpios = <&gpio2 10 GPIO_ACTIVE_HIGH>;
		pwdn-gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "rockchip,camera_default";
		pinctrl-0 = <&cif_clkout>;
		lens-focus = <&vm149c>;

		port {
			ucam_out0: endpoint {
				remote-endpoint = <&mipi_in_ucam0>;
				data-lanes = <1 2>;
			};
		};
	};
};

&i2c4 {
	status = "okay";
};

&pcie_phy {
	status = "okay";
};

&pcie0 {
	status = "okay";
};

&pinctrl {
	buttons {
		pwrbtn: pwrbtn {
			rockchip,pins = <0 RK_PA5 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	lcd-panel {
		lcd_panel_reset: lcd-panel-reset {
			rockchip,pins = <4 RK_PD6 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	hdmiin {
		hdmiin_gpios: hdmiin-gpios {
			rockchip,pins =
				<2 RK_PA5 RK_FUNC_GPIO &pcfg_output_high>,
				<2 RK_PA6 RK_FUNC_GPIO &pcfg_output_high>,
				<2 RK_PA7 RK_FUNC_GPIO &pcfg_pull_none>,
				<2 RK_PB0 RK_FUNC_GPIO &pcfg_output_high>,
				<2 RK_PB1 RK_FUNC_GPIO &pcfg_output_high>,
				<2 RK_PB2 RK_FUNC_GPIO &pcfg_output_low>,
				<2 RK_PB4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};

&vopb {
	status = "okay";
};

&vopb_mmu {
	status = "okay";
};

&vopl {
	status = "okay";
};

&vopl_mmu {
	status = "okay";
};
