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

/dts-v1/;

#include <dt-bindings/leds/common.h>
#include <dt-bindings/soc/rockchip,vop2.h>
#include "rk3588-coolpi-cm5.dtsi"

/ {
	model = "RK3588 CoolPi CM5 EVB";
	compatible = "coolpi,pi-cm5-evb", "coolpi,pi-cm5", "rockchip,rk3588";

	backlight: backlight {
		compatible = "pwm-backlight";
		enable-gpios = <&gpio4 RK_PA3 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&bl_en>;
		power-supply = <&vcc12v_dcin>;
		pwms = <&pwm2 0 25000 0>;
	};

	hdmi0-con {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi0_con_in: endpoint {
				remote-endpoint = <&hdmi0_out_con>;
			};
		};
	};

	hdmi1-con {
		compatible = "hdmi-connector";
		type = "a";

		port {
			hdmi1_con_in: endpoint {
				remote-endpoint = <&hdmi1_out_con>;
			};
		};
	};

	leds: leds {
		compatible = "gpio-leds";

		green_led: led-0 {
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio3 RK_PB7 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
		};
	};

	vcc12v_dcin: regulator-vcc12v-dcin {
		compatible = "regulator-fixed";
		regulator-name = "vcc12v_dcin";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
	};

	vcc5v0_sys: regulator-vcc5v0-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		vin-supply = <&vcc12v_dcin>;
	};

	vcc3v3_sys: regulator-vcc3v3-sys {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		vin-supply = <&vcc12v_dcin>;
	};

	vcc3v3_lcd: regulator-vcc3v3-lcd {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_lcd";
		enable-active-high;
		gpio = <&gpio1 RK_PC4 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&lcdpwr_en>;
		vin-supply = <&vcc3v3_sys>;
	};

	vcc5v0_usb_host1: vcc5v0_usb_host2: regulator-vcc5v0-usb-host {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_host";
		regulator-boot-on;
		regulator-always-on;
		enable-active-high;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_host_pwren>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc5v0_usb30_otg: regulator-vcc5v0-usb30-otg {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_otg";
		regulator-boot-on;
		regulator-always-on;
		enable-active-high;
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpios = <&gpio0 RK_PA0 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&usb_otg_pwren>;
		vin-supply = <&vcc5v0_sys>;
	};
};

&hdmi0 {
	frl-enable-gpios = <&gpio4 RK_PB0 GPIO_ACTIVE_LOW>;
	pinctrl-0 = <&hdmim0_tx0_cec &hdmim0_tx0_hpd
		     &hdmim0_tx0_scl &hdmim0_tx0_sda &hdmi0_tx_on_h>;
	pinctrl-names = "default";
	status = "okay";
};

&hdmi0_sound {
	status = "okay";
};

&hdmi0_in {
	hdmi0_in_vp0: endpoint {
		remote-endpoint = <&vp0_out_hdmi0>;
	};
};

&hdmi0_out {
	hdmi0_out_con: endpoint {
		remote-endpoint = <&hdmi0_con_in>;
	};
};

&hdmi1 {
	frl-enable-gpios = <&gpio4 RK_PB2 GPIO_ACTIVE_LOW>;
	pinctrl-0 = <&hdmim2_tx1_cec &hdmim0_tx1_hpd &hdmim1_tx1_scl &hdmim1_tx1_sda
		     &hdmi1_tx_on_h>;
	pinctrl-names = "default";
	status = "okay";
};

&hdmi1_in {
	hdmi1_in_vp1: endpoint {
		remote-endpoint = <&vp1_out_hdmi1>;
	};
};

&hdmi1_out {
	hdmi1_out_con: endpoint {
		remote-endpoint = <&hdmi1_con_in>;
	};
};

&hdmi1_sound {
	status = "okay";
};

&hdptxphy0 {
	status = "okay";
};

&hdptxphy1 {
	status = "okay";
};

&i2s5_8ch {
	status = "okay";
};

&i2s6_8ch {
	status = "okay";
};

/* M.2 E-Key */
&pcie2x1l1 {
	reset-gpios = <&gpio4 RK_PA2 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_sys>;
	pinctrl-names = "default";
	pinctrl-0 = <&pcie_clkreq &pcie_wake &pcie_rst &wifi_pwron &bt_pwron>;
	status = "okay";
};

&pcie30phy {
	data-lanes = <1 1 2 2>;
	status = "okay";
};

/* Standard pcie */
&pcie3x2 {
	reset-gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_sys>;
	status = "okay";
};

/* M.2 M-Key ssd */
&pcie3x4 {
	num-lanes = <2>;
	reset-gpios = <&gpio4 RK_PB6 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_sys>;
	status = "okay";
};

&pinctrl {
	hdmi {
		hdmi0_tx_on_h: hdmi0-tx-on-h {
			rockchip,pins = <4 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		hdmi1_tx_on_h: hdmi1-tx-on-h {
			rockchip,pins = <4 RK_PB2 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	lcd {
		lcdpwr_en: lcdpwr-en {
			rockchip,pins = <1 RK_PC4 RK_FUNC_GPIO &pcfg_pull_down>;
		};

		bl_en: bl-en {
			rockchip,pins = <4 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	usb {
		usb_host_pwren: usb-host-pwren {
			rockchip,pins = <1 RK_PD5 RK_FUNC_GPIO &pcfg_pull_up>;
		};

		usb_otg_pwren: usb-otg-pwren {
			rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	wifi {
		bt_pwron: bt-pwron {
			rockchip,pins = <3 RK_PA6 RK_FUNC_GPIO &pcfg_pull_up>;
		};

		pcie_clkreq: pcie-clkreq {
			rockchip,pins = <4 RK_PA0 RK_FUNC_GPIO &pcfg_pull_up>;
		};

		pcie_rst: pcie-rst {
			rockchip,pins = <4 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>;
		};

		wifi_pwron: wifi-pwron {
			rockchip,pins = <3 RK_PB1 RK_FUNC_GPIO &pcfg_pull_up>;
		};

		pcie_wake: pcie-wake {
			rockchip,pins = <4 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};
};

&pwm2 {
	status = "okay";
};

&sata1 {
	status = "okay";
};

&u2phy2 {
	status = "okay";
};

&u2phy3 {
	status = "okay";
};

&u2phy2_host {
	phy-supply = <&vcc5v0_usb_host1>;
	status = "okay";
};

&u2phy3_host {
	phy-supply = <&vcc5v0_usb_host2>;
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&vop {
	status = "okay";
};

&vop_mmu {
	status = "okay";
};

&vp0 {
	vp0_out_hdmi0: endpoint@ROCKCHIP_VOP2_EP_HDMI0 {
		reg = <ROCKCHIP_VOP2_EP_HDMI0>;
		remote-endpoint = <&hdmi0_in_vp0>;
	};
};

&vp1 {
	vp1_out_hdmi1: endpoint@ROCKCHIP_VOP2_EP_HDMI1 {
		reg = <ROCKCHIP_VOP2_EP_HDMI1>;
		remote-endpoint = <&hdmi1_in_vp1>;
	};
};