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

/dts-v1/;

#include "rk3566-box.dtsi"

/ {
	model = "Rockchip RK3566 BOX DEMO V10 Board";
	compatible = "rockchip,rk3568-box-demo-v10", "rockchip,rk3566";

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

		ir-led {
			gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};

		work-led {
			gpios = <&gpio0 RK_PC3 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "timer";
		};
	};

	vcc2v5_sys: vcc2v5-ddr {
		compatible = "regulator-fixed";
		regulator-name = "vcc2v5-sys";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <2500000>;
		regulator-max-microvolt = <2500000>;
		vin-supply = <&vcc3v3_sys>;
	};

	sdio_pwrseq: sdio-pwrseq {
		compatible = "mmc-pwrseq-simple";
		clocks = <&pmucru CLK_RTC_32K>;
		clock-names = "ext_clock";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_enable_h &wifi_32k>;
		reset-gpios = <&gpio2 RK_PB1 GPIO_ACTIVE_LOW>;
	};

	vcc3v3_sd: vcc3v3-sd-regulator {
		compatible = "regulator-gpio";
		regulator-name = "vcc3v3_sd";
		regulator-min-microvolt = <100000>;
		regulator-max-microvolt = <3300000>;
		gpios = <&gpio0 RK_PA5 GPIO_ACTIVE_HIGH>;
		gpios-states = <0x1>;
		states = <100000 0x1
			  3300000 0x0>;
	};

	vccio_sd: vccio-sd-regulator {
		compatible = "regulator-gpio";
		regulator-name = "vccio_sd";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <3300000>;
		gpios = <&gpio0 RK_PB6 GPIO_ACTIVE_HIGH>;
		gpios-states = <0x1>;
		states = <1800000 0x0
			  3300000 0x1>;
	};

	vcc5v0_host: vcc5v0-host-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_host_en>;
		regulator-name = "vcc5v0_host";
		regulator-always-on;
	};

	vcc5v0_otg: vcc5v0-otg-regulator {
		compatible = "regulator-fixed";
		enable-active-high;
		gpio = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_otg_en>;
		regulator-name = "vcc5v0_otg";
	};

	vcc_camera: vcc-camera-regulator {
		compatible = "regulator-fixed";
		gpio = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&camera_pwr>;
		regulator-name = "vcc_camera";
		enable-active-high;
		regulator-always-on;
		regulator-boot-on;
	};

	wireless_wlan: wireless-wlan {
		compatible = "wlan-platdata";
		rockchip,grf = <&grf>;
		wifi_chip_type = "ap6398s";
		pinctrl-names = "default";
		pinctrl-0 = <&wifi_host_wake_irq>;
		WIFI,host_wake_irq = <&gpio2 RK_PB2 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};

	wireless_bluetooth: wireless-bluetooth {
		compatible = "bluetooth-platdata";
		clocks = <&pmucru CLK_RTC_32K>;
		clock-names = "ext_clock";
		//wifi-bt-power-toggle;
		uart_rts_gpios = <&gpio2 RK_PB5 GPIO_ACTIVE_LOW>;
		pinctrl-names = "default", "rts_gpio";
		pinctrl-0 = <&uart1m0_rtsn>;
		pinctrl-1 = <&uart1_gpios>;
		BT,reset_gpio    = <&gpio2 RK_PB7 GPIO_ACTIVE_HIGH>;
		BT,wake_gpio     = <&gpio2 RK_PC1 GPIO_ACTIVE_HIGH>;
		BT,wake_host_irq = <&gpio2 RK_PC0 GPIO_ACTIVE_HIGH>;
		status = "okay";
	};
};

&combphy1_usq {
	assigned-clocks = <&pmucru CLK_PCIEPHY1_REF>;
	assigned-clock-rates = <100000000>;
	status = "okay";
};

&combphy2_psq {
	status = "okay";
};

&csi2_dphy_hw {
	status = "okay";
};

&csi2_dphy0 {
	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 = <&gc4c33_out>;
				data-lanes = <1 2>;
			};

			mipi_in_ucam1: endpoint@2 {
				reg = <2>;
				remote-endpoint = <&gc8034_out>;
				data-lanes = <1 2 3 4>;
			};
		};

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

			csidphy_out: endpoint@1 {
				reg = <1>;
				remote-endpoint = <&isp0_in>;
			};
		};
	};
};

&gmac1 {
	phy-mode = "rgmii";
	clock_in_out = "input";

	snps,reset-gpio = <&gpio4 RK_PC2 GPIO_ACTIVE_LOW>;
	snps,reset-active-low;
	/* Reset time is 20ms, 100ms for rtl8211f */
	snps,reset-delays-us = <0 20000 100000>;

	assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;
	assigned-clock-parents =  <&cru SCLK_GMAC1_RGMII_SPEED>, <&gmac1_clkin>;

	pinctrl-names = "default";
	pinctrl-0 = <&gmac1m1_miim
		     &gmac1m1_tx_bus2
		     &gmac1m1_rx_bus2
		     &gmac1m1_rgmii_clk
		     &gmac1m1_rgmii_bus
		     &gmac1m1_clkinout>;

	tx_delay = <0x4f>;
	rx_delay = <0x2d>;

	phy-handle = <&rgmii_phy1>;
	status = "okay";
};

&i2c2{
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2c2m1_xfer>;

	gc8034: gc8034@37 {
		status = "okay";
		compatible = "galaxycore,gc8034";
		reg = <0x37>;
		clocks = <&cru CLK_CIF_OUT>;
		clock-names = "xvclk";
		power-domains = <&power RK3568_PD_VI>;
		pinctrl-names = "default";
		pinctrl-0 = <&cif_clk>;
		/*pwren-gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;*/
		reset-gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_LOW>;
		pwdn-gpios = <&gpio4 RK_PB2 GPIO_ACTIVE_LOW>;
		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "RK-CMK-8M-2-v1";
		rockchip,camera-module-lens-name = "CK8401";
		port {
			gc8034_out: endpoint {
				remote-endpoint = <&mipi_in_ucam1>;
				data-lanes = <1 2 3 4>;
			};
		};
	};

	gc4c33: gc4c33@29 {
		status = "okay";
		compatible = "galaxycore,gc4c33";
		reg = <0x29>;
		clocks = <&cru CLK_CIF_OUT>;
		clock-names = "xvclk";
		power-domains = <&power RK3568_PD_VI>;
		pinctrl-names = "default";
		pinctrl-0 = <&cif_clk>;
		/*pwren-gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;*/
		reset-gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_HIGH>;
		pwdn-gpios = <&gpio4 RK_PB2 GPIO_ACTIVE_HIGH>;
		rockchip,camera-module-index = <0>;
		rockchip,camera-module-facing = "back";
		rockchip,camera-module-name = "PCORW0009A";
		rockchip,camera-module-lens-name = "40IRC-4M";
		port {
			gc4c33_out: endpoint {
				remote-endpoint = <&mipi_in_ucam0>;
				data-lanes = <1 2>;
			};
		};
	};
};

&mdio1 {
	rgmii_phy1: phy@0 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <0x0>;
	};
};

&pwm15 {
	compatible = "rockchip,remotectl-pwm";
	pinctrl-names = "default";
	pinctrl-0 = <&pwm15m1_pins>;
	remote_pwm_id = <3>;
	handle_cpu_id = <1>;
	remote_support_psci = <0>;
	status = "okay";

	ir_key1 {
		rockchip,usercode = <0x4040>;
		rockchip,key_table =
			<0xf2	KEY_REPLY>,
			<0xba	KEY_BACK>,
			<0xf4	KEY_UP>,
			<0xf1	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xee	KEY_RIGHT>,
			<0xbd	KEY_HOME>,
			<0xea	KEY_VOLUMEUP>,
			<0xe3	KEY_VOLUMEDOWN>,
			<0xe2	KEY_SEARCH>,
			<0xb2	KEY_POWER>,
			<0xbc	KEY_MUTE>,
			<0xec	KEY_MENU>,
			<0xbf	0x190>,
			<0xe0	0x191>,
			<0xe1	0x192>,
			<0xe9	183>,
			<0xe6	248>,
			<0xe8	185>,
			<0xe7	186>,
			<0xf0	388>,
			<0xbe	0x175>;
	};

	ir_key2 {
		rockchip,usercode = <0xff00>;
		rockchip,key_table =
			<0xf9	KEY_HOME>,
			<0xbf	KEY_BACK>,
			<0xfb	KEY_MENU>,
			<0xaa	KEY_REPLY>,
			<0xb9	KEY_UP>,
			<0xe9	KEY_DOWN>,
			<0xb8	KEY_LEFT>,
			<0xea	KEY_RIGHT>,
			<0xeb	KEY_VOLUMEDOWN>,
			<0xef	KEY_VOLUMEUP>,
			<0xf7	KEY_MUTE>,
			<0xe7	KEY_POWER>,
			<0xfc	KEY_POWER>,
			<0xa9	KEY_VOLUMEDOWN>,
			<0xa8	KEY_PLAYPAUSE>,
			<0xe0	KEY_VOLUMEDOWN>,
			<0xa5	KEY_VOLUMEDOWN>,
			<0xab	183>,
			<0xb7	388>,
			<0xe8	388>,
			<0xf8	184>,
			<0xaf	185>,
			<0xed	KEY_VOLUMEDOWN>,
			<0xee	186>,
			<0xb3	KEY_VOLUMEDOWN>,
			<0xf1	KEY_VOLUMEDOWN>,
			<0xf2	KEY_VOLUMEDOWN>,
			<0xf3	KEY_SEARCH>,
			<0xb4	KEY_VOLUMEDOWN>,
			<0xa4	KEY_SETUP>,
			<0xbe	KEY_SEARCH>;
	};

	ir_key3 {
		rockchip,usercode = <0x1dcc>;
		rockchip,key_table =
			<0xee	KEY_REPLY>,
			<0xf0	KEY_BACK>,
			<0xf8	KEY_UP>,
			<0xbb	KEY_DOWN>,
			<0xef	KEY_LEFT>,
			<0xed	KEY_RIGHT>,
			<0xfc	KEY_HOME>,
			<0xf1	KEY_VOLUMEUP>,
			<0xfd	KEY_VOLUMEDOWN>,
			<0xb7	KEY_SEARCH>,
			<0xff	KEY_POWER>,
			<0xf3	KEY_MUTE>,
			<0xbf	KEY_MENU>,
			<0xf9	0x191>,
			<0xf5	0x192>,
			<0xb3	388>,
			<0xbe	KEY_1>,
			<0xba	KEY_2>,
			<0xb2	KEY_3>,
			<0xbd	KEY_4>,
			<0xf9	KEY_5>,
			<0xb1	KEY_6>,
			<0xfc	KEY_7>,
			<0xf8	KEY_8>,
			<0xb0	KEY_9>,
			<0xb6	KEY_0>,
			<0xb5	KEY_BACKSPACE>;
	};
};

/* Need to be modified according to the actual hardware */
&pmu_io_domains {
	status = "okay";
	pmuio2-supply = <&vcc_3v3>;
	vccio1-supply = <&vcc_3v3>;
	vccio3-supply = <&vcc_3v3>;
	vccio4-supply = <&vcc_3v3>;
	vccio5-supply = <&vcc_3v3>;
	vccio6-supply = <&vcc_3v3>;
	vccio7-supply = <&vcc_3v3>;
};

&rkisp {
	status = "okay";
};

&rkisp_mmu {
	status = "okay";
};

&rkisp_vir0 {
	status = "okay";

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

		isp0_in: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&csidphy_out>;
		};
	};
};

&sata2 {
	status = "okay";
};

&sdmmc0 {
	max-frequency = <50000000>;
	no-sdio;
	no-mmc;
	bus-width = <4>;
	cap-mmc-highspeed;
	cap-sd-highspeed;
	disable-wp;
	//sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_sd>;
	vqmmc-supply = <&vccio_sd>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd &sdmmc0_det>;
	status = "okay";
};

&sdmmc1 {
	max-frequency = <150000000>;
	no-sd;
	no-mmc;
	bus-width = <4>;
	disable-wp;
	cap-sd-highspeed;
	cap-sdio-irq;
	keep-power-in-suspend;
	non-removable;
	mmc-pwrseq = <&sdio_pwrseq>;
	pinctrl-names = "default";
	pinctrl-0 = <&sdmmc1_bus4 &sdmmc1_cmd &sdmmc1_clk>;
	sd-uhs-sdr104;
	status = "okay";
};

&uart1 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&uart1m0_xfer &uart1m0_ctsn>;
};

&u2phy0_host {
	phy-supply = <&vcc5v0_host>;
	status = "okay";
};

&u2phy0_otg {
	vbus-supply = <&vcc5v0_otg>;
	status = "okay";
};

&u2phy1_host {
	phy-supply = <&vcc5v0_host>;
	status = "okay";
};

&u2phy1_otg {
	phy-supply = <&vcc5v0_host>;
	status = "okay";
};

&usb2phy1 {
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&pinctrl {
	cam {
		camera_pwr: camera-pwr {
			rockchip,pins =
				/* camera power en */
				<0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	sdio-pwrseq {
		wifi_enable_h: wifi-enable-h {
			rockchip,pins = <2 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		wifi_32k: wifi-32k {
			rockchip,pins = <2 RK_PC6 1 &pcfg_pull_none>;
		};
	};

	usb {
		vcc5v0_host_en: vcc5v0-host-en {
			rockchip,pins = <0 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		vcc5v0_otg_en: vcc5v0-otg-en {
			rockchip,pins = <0 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
		};

	};

	wireless-wlan {
		wifi_host_wake_irq: wifi-host-wake-irq {
			rockchip,pins = <2 RK_PB2 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};

	wireless-bluetooth {
		uart1_gpios: uart1-gpios {
			rockchip,pins = <2 RK_PB5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};
};
