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

#include "rk3588.dtsi"
#include "rk3588-nvr.dtsi"
#include "rk3588-rk806-single.dtsi"

/ {
	i2s0_sound: i2s0-sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,format = "i2s";
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,name = "rockchip,es8311";
		simple-audio-card,dai-link@0 {
			format = "i2s";
			cpu {
				sound-dai = <&i2s0_8ch>;
			};
			codec {
				sound-dai = <&es8311>;
			};
		};
	};

	leds: leds {
		compatible = "gpio-leds";
		hdd_led: hdd-led {
			gpios = <&gpio3 RK_PC1 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};
		net_led: net-led {
			gpios = <&gpio3 RK_PC0 GPIO_ACTIVE_HIGH>;
			default-state = "off";
		};
		work_led: work-led {
			gpios = <&gpio3 RK_PB7 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
		};
	};

	pcie30_avdd0v75: pcie30-avdd0v75 {
		compatible = "regulator-fixed";
		regulator-name = "pcie30_avdd0v75";
		regulator-boot-on;
		regulator-always-on;
		regulator-min-microvolt = <750000>;
		regulator-max-microvolt = <750000>;
		vin-supply = <&vdd_0v75_s0>;
	};

	pcie30_avdd1v8: pcie30-avdd1v8 {
		compatible = "regulator-fixed";
		regulator-name = "pcie30_avdd1v8";
		regulator-boot-on;
		regulator-always-on;
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		vin-supply = <&avcc_1v8_s0>;
	};

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

	vcc3v3_pcie30: vcc3v3-pcie30 {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_pcie30";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		enable-active-high;
		gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_HIGH>;
		startup-delay-us = <7500>;
		vin-supply = <&vcc12v_dcin>;
	};

	vcc5v0_sys: 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>;
	};

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

	vcc5v0_otg: vcc5v0-otg-regulator {
		compatible = "regulator-fixed";
		regulator-name = "vcc5v0_otg";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		enable-active-high;
		gpio = <&gpio4 RK_PA7 GPIO_ACTIVE_HIGH>;
		vin-supply = <&vcc5v0_sys>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_otg_en>;
	};

	vcc_1v1_nldo_s3: vcc-1v1-nldo-s3 {
		compatible = "regulator-fixed";
		regulator-name = "vcc_1v1_nldo_s3";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <1100000>;
		regulator-max-microvolt = <1100000>;
		vin-supply = <&vcc5v0_sys>;
	};
};

&combphy0_ps {
	pinctrl-names = "default";
	pinctrl-0 = <&sata0_pm_reset>;
	status = "okay";
};

&combphy1_ps {
	pinctrl-names = "default";
	pinctrl-0 = <&sata1_pm_reset>;
	status = "okay";
};

&combphy2_psu {
	status = "okay";
};

&dp0 {
	pinctrl-0 = <&dp0m2_pins>;
	pinctrl-names = "default";
	status = "okay";
};

&dp0_in_vp0 {
	status = "okay";
};

&dp0_in_vp1 {
	status = "okay";
};

&dp0_in_vp2 {
	status = "okay";
};

&dp1 {
	pinctrl-0 = <&dp1m2_pins &dp1_hdmi_ctl>;
	pinctrl-names = "default";
	status = "okay";
};

&dp1_in_vp0 {
	status = "okay";
};

&dp1_in_vp1 {
	status = "okay";
};

&dp1_in_vp2 {
	status = "okay";
};

&dp1_sound {
	status = "okay";
};

&gmac0 {
	/* Use rgmii-rxid mode to disable rx delay inside Soc */
	phy-mode = "rgmii-rxid";
	clock_in_out = "output";

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

	pinctrl-names = "default";
	pinctrl-0 = <&gmac0_miim
		     &gmac0_tx_bus2
		     &gmac0_rx_bus2
		     &gmac0_rgmii_clk
		     &gmac0_rgmii_bus>;

	tx_delay = <0x44>;
	/* rx_delay = <0x4f>; */

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

&gmac1 {
	/* Use rgmii-rxid mode to disable rx delay inside Soc */
	phy-mode = "rgmii-rxid";
	clock_in_out = "output";

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

	pinctrl-names = "default";
	pinctrl-0 = <&gmac1_miim
		     &gmac1_tx_bus2
		     &gmac1_rx_bus2
		     &gmac1_rgmii_clk
		     &gmac1_rgmii_bus>;

	tx_delay = <0x42>;
	/* rx_delay = <0x4f>; */

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

&hdmi0 {
	enable-gpios = <&gpio4 RK_PB1 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

&hdmi0_in_vp0 {
	status = "okay";
};

&hdmi0_in_vp1 {
	status = "okay";
};

&hdmi0_in_vp2 {
	status = "okay";
};

&hdmi0_sound {
	status = "okay";
};

&hdmi1 {
	enable-gpios = <&gpio4 RK_PB2 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

&hdmi1_in_vp0 {
	status = "okay";
};

&hdmi1_in_vp1 {
	status = "okay";
};

&hdmi1_in_vp2 {
	status = "okay";
};

&hdmi1_sound {
	status = "okay";
};

&hdptxphy_hdmi0 {
	status = "okay";
};

&hdptxphy_hdmi1 {
	status = "okay";
};

&i2c0 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2c0m2_xfer>;

	vdd_cpu_big0_s0: vdd_cpu_big0_mem_s0: rk8602@42 {
		compatible = "rockchip,rk8602";
		reg = <0x42>;
		vin-supply = <&vcc5v0_sys>;
		regulator-compatible = "rk860x-reg";
		regulator-name = "vdd_cpu_big0_s0";
		regulator-min-microvolt = <550000>;
		regulator-max-microvolt = <1050000>;
		regulator-ramp-delay = <2300>;
		rockchip,suspend-voltage-selector = <1>;
		regulator-boot-on;
		regulator-always-on;
		regulator-state-mem {
			regulator-off-in-suspend;
		};
	};

	vdd_cpu_big1_s0: vdd_cpu_big1_mem_s0: rk8603@43 {
		compatible = "rockchip,rk8603";
		reg = <0x43>;
		vin-supply = <&vcc5v0_sys>;
		regulator-compatible = "rk860x-reg";
		regulator-name = "vdd_cpu_big1_s0";
		regulator-min-microvolt = <550000>;
		regulator-max-microvolt = <1050000>;
		regulator-ramp-delay = <2300>;
		rockchip,suspend-voltage-selector = <1>;
		regulator-boot-on;
		regulator-always-on;
		regulator-state-mem {
			regulator-off-in-suspend;
		};
	};
};

&i2c2 {
	status = "okay";

	vdd_npu_s0: vdd_npu_mem_s0: rk8602@42 {
		compatible = "rockchip,rk8602";
		reg = <0x42>;
		vin-supply = <&vcc5v0_sys>;
		regulator-compatible = "rk860x-reg";
		regulator-name = "vdd_npu_s0";
		regulator-min-microvolt = <550000>;
		regulator-max-microvolt = <950000>;
		regulator-ramp-delay = <2300>;
		rockchip,suspend-voltage-selector = <1>;
		regulator-boot-on;
		regulator-always-on;
		regulator-state-mem {
			regulator-off-in-suspend;
		};
	};
};

&i2c3 {
	status = "okay";
	es8311: es8311@18 {
		status = "okay";
		compatible = "everest,es8311";
		reg = <0x18>;
		#sound-dai-cells = <0>;
		adc-pga-gain = <6>;     /* 18dB */
		adc-volume = <0xbf>;    /* 0dB */
		dac-volume = <0xbf>;    /* 0dB */
		aec-mode = "adc left, adc right";
		clocks = <&mclkout_i2s0>;
		clock-names = "mclk";
		assigned-clocks = <&mclkout_i2s0>;
		assigned-clock-rates = <12288000>;
		pinctrl-names = "default";
		pinctrl-0 = <&i2s0_mclk>;
	};
};

&i2c4 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&i2c4m3_xfer>;
};

&i2c5 {
	status = "okay";
};

&i2c6 {
	status = "okay";
	hym8563: hym8563@51 {
		compatible = "haoyu,hym8563";
		reg = <0x51>;

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

		interrupt-parent = <&gpio0>;
		interrupts = <RK_PB2 IRQ_TYPE_LEVEL_LOW>;
		wakeup-source;
	};
};

&i2s0_8ch {
	status = "okay";
	pinctrl-0 = <&i2s0_lrck
		     &i2s0_sclk
		     &i2s0_sdi0
		     &i2s0_sdo0>;
};

&i2s5_8ch {
	status = "okay";
};

&i2s6_8ch {
	status = "okay";
};

&mdio0 {
	rgmii_phy0: phy@1 {
		compatible = "ethernet-phy-ieee802.3-c22";
		reg = <0x1>;
	};
};

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

&pcie30phy {
	status = "okay";
};

&pcie3x4 {
	reset-gpios = <&gpio4 RK_PB6 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_pcie30>;
	pinctrl-names = "default";
	pinctrl-0 = <&pcie30x4_clkreqn_m1>;
	status = "okay";
};

&pwm3 {
	compatible = "rockchip,remotectl-pwm";
	pinctrl-names = "default";
	pinctrl-0 = <&pwm3m0_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>;
	};
};

&rk806single {
	pinctrl-names = "default", "pmic-power-off";
	pinctrl-0 = <&pmic_pins>, <&rk806_dvs1_null>, <&rk806_dvs2_null>, <&rk806_dvs3_null>;
	pinctrl-1 = <&rk806_dvs1_slp>, <&rk806_dvs2_null>, <&rk806_dvs3_null>;

	regulators {
		avcc_1v8_s0: PLDO_REG1 {
			regulator-always-on;
			regulator-boot-on;
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-name = "avcc_1v8_s0";
			regulator-state-mem {
				regulator-on-in-suspend;
				regulator-suspend-microvolt = <1800000>;
			};
		};
	};
};

&rockchip_suspend {
	status = "okay";
	rockchip,sleep-debug-en = <1>;
	rockchip,virtual-poweroff = <1>;
	rockchip,sleep-mode-config = <
		(0
		| RKPM_SLP_ARMOFF_DDRPD
		)
	>;
	rockchip,wakeup-config = <
		(0
		| RKPM_CPU0_WKUP_EN
		| RKPM_GPIO_WKUP_EN
		)
	>;
};

&route_dp0 {
	status = "okay";
	force-output;
	connect = <&vp2_out_dp0>;

	force_timing {
		clock-frequency = <65000000>;
		hactive = <1024>;
		vactive = <768>;
		hfront-porch = <24>;
		hsync-len = <136>;
		hback-porch = <160>;
		vfront-porch = <3>;
		vsync-len = <6>;
		vback-porch = <29>;
		hsync-active = <0>;
		vsync-active = <0>;
		de-active = <0>;
		pixelclk-active = <0>;
	};

};

&route_dp1 {
	status = "okay";
	force-output;
	connect = <&vp2_out_dp1>;

	force_timing {
		clock-frequency = <65000000>;
		hactive = <1024>;
		vactive = <768>;
		hfront-porch = <24>;
		hsync-len = <136>;
		hback-porch = <160>;
		vfront-porch = <3>;
		vsync-len = <6>;
		vback-porch = <29>;
		hsync-active = <0>;
		vsync-active = <0>;
		de-active = <0>;
		pixelclk-active = <0>;
	};

};

&route_hdmi0 {
	status = "okay";
	force-output;
	connect = <&vp2_out_hdmi0>;

	force_timing {
		clock-frequency = <65000000>;
		hactive = <1024>;
		vactive = <768>;
		hfront-porch = <24>;
		hsync-len = <136>;
		hback-porch = <160>;
		vfront-porch = <3>;
		vsync-len = <6>;
		vback-porch = <29>;
		hsync-active = <0>;
		vsync-active = <0>;
		de-active = <0>;
		pixelclk-active = <0>;
	};

};

&route_hdmi1 {
	status = "okay";
	force-output;
	connect = <&vp2_out_hdmi1>;

	force_timing {
		clock-frequency = <65000000>;
		hactive = <1024>;
		vactive = <768>;
		hfront-porch = <24>;
		hsync-len = <136>;
		hback-porch = <160>;
		vfront-porch = <3>;
		vsync-len = <6>;
		vback-porch = <29>;
		hsync-active = <0>;
		vsync-active = <0>;
		de-active = <0>;
		pixelclk-active = <0>;
	};

};

&sata0 {
	status = "okay";
};

&sata1 {
	status = "okay";
};

&sdhci {
	bus-width = <8>;
	no-sdio;
	no-sd;
	non-removable;
	max-frequency = <200000000>;
	mmc-hs400-1_8v;
	mmc-hs400-enhanced-strobe;
	status = "okay";
};

&spdif_tx5 {
	status = "okay";
};

&pinctrl {
	dp {
		dp1_hdmi_ctl: dp-hdmi-ctl {
			rockchip,pins = <0 RK_PD5 RK_FUNC_GPIO &pcfg_pull_up>,
					<3 RK_PB2 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

	pcie30x4 {
		pcie30x4_clkreqn_m1: pcie30x4-clkreqn-m1 {
			rockchip,pins = <4 RK_PB4 RK_FUNC_GPIO &pcfg_pull_down>;
		};
	};


	rtc {
		rtc_int: rtc-int {
			rockchip,pins = <0 RK_PB2 RK_FUNC_GPIO &pcfg_pull_up>;
		};
	};

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

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

	sata {
		sata0_pm_reset: sata0-pm-reset {
			rockchip,pins = <4 RK_PA0 RK_FUNC_GPIO &pcfg_output_high>;
		};
		sata1_pm_reset: sata1-pm-reset {
			rockchip,pins = <4 RK_PA1 RK_FUNC_GPIO &pcfg_output_high>;
		};
	};
};

&u2phy0 {
	status = "okay";
};

&u2phy1 {
	status = "okay";
};

&u2phy2 {
	status = "okay";
};

&u2phy3 {
	status = "okay";
};

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

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

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

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

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

&usbdp_phy0 {
	rockchip,dp-lane-mux = < 2 3 >;
	status = "okay";
};

&usbdp_phy0_dp {
	status = "okay";
};

&usbdp_phy0_u3 {
	status = "okay";
};

&usbdp_phy1 {
	rockchip,dp-lane-mux = < 0 1 2 3 >;
	status = "okay";
};

&usbdp_phy1_dp {
	status = "okay";
};

&usbdp_phy1_u3 {
	maximum-speed = "high-speed";
	status = "okay";
};

&usbdrd3_0 {
	status = "okay";
};

&usbdrd3_1 {
	status = "okay";
};

&usbdrd_dwc3_0 {
	dr_mode = "peripheral";
	status = "okay";
};

&usbdrd_dwc3_1 {
	dr_mode = "host";
	maximum-speed = "high-speed";
	status = "okay";
};

&usbhost3_0 {
	status = "okay";
};

&usbhost_dwc3_0 {
	dr_mode = "host";
	status = "okay";
};

&vdd_log_s0 {
	regulator-state-mem {
		regulator-on-in-suspend;
		regulator-suspend-microvolt = <750000>;
	};
};

&vdd_vdenc_s0 {
	regulator-init-microvolt = <750000>;
};

