// SPDX-License-Identifier: (GPL-2.0+ OR MIT)

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/soc/rockchip,vop2.h>
#include "rk3588-armsom-lm7.dtsi"

/ {
	model = "ArmSoM W3";
	compatible = "armsom,w3", "armsom,lm7", "rockchip,rk3588";

	aliases {
		mmc1 = &sdmmc;
		mmc2 = &sdio;
	};

	analog-sound {
		compatible = "audio-graph-card";
		label = "rk3588-es8316";

		widgets = "Microphone", "Mic Jack",
			  "Headphone", "Headphones";

		routing = "MIC2", "Mic Jack",
			  "Headphones", "HPOL",
			  "Headphones", "HPOR";

		dais = <&i2s0_8ch_p0>;
		hp-det-gpio = <&gpio1 RK_PD5 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&hp_detect>;
	};

	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 {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&led_rgb_b>;

		led-rgb-b {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio0 RK_PB7 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "heartbeat";
		};

		led-rgb-r {
			function = LED_FUNCTION_STATUS;
			color = <LED_COLOR_ID_RED>;
			gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "none";
		};
	};

	fan: pwm-fan {
		compatible = "pwm-fan";
		cooling-levels = <0 120 150 180 210 240 255>;
		fan-supply = <&vcc5v0_sys>;
		pwms = <&pwm1 0 50000 0>;
		#cooling-cells = <2>;
	};

	rfkill {
		compatible = "rfkill-gpio";
		label = "rfkill-pcie-wlan";
		radio-type = "wlan";
		shutdown-gpios = <&gpio4 RK_PA2 GPIO_ACTIVE_HIGH>;
	};

	rfkill-bt {
		compatible = "rfkill-gpio";
		label = "rfkill-m2-bt";
		radio-type = "bluetooth";
		shutdown-gpios = <&gpio3 RK_PD5 GPIO_ACTIVE_HIGH>;
	};

	vcc3v3_pcie2x1l0: regulator-vcc3v3-pcie2x1l0 {
		compatible = "regulator-fixed";
		enable-active-high;
		gpios = <&gpio1 RK_PD2 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&pcie2_0_vcc3v3_en>;
		regulator-name = "vcc3v3_pcie2x1l0";
		regulator-always-on;
		regulator-boot-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		startup-delay-us = <50000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc3v3_pcie2x1l2: regulator-vcc3v3-pcie2x1l2 {
		compatible = "regulator-fixed";
		regulator-name = "vcc3v3_pcie2x1l2";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		startup-delay-us = <5000>;
		vin-supply = <&vcc_3v3_s3>;
	};

	vcc3v3_pcie30: regulator-vcc3v3-pcie30 {
		compatible = "regulator-fixed";
		enable-active-high;
		gpios = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>;
		pinctrl-names = "default";
		pinctrl-0 = <&pcie3_vcc3v3_en>;
		regulator-name = "vcc3v3_pcie30";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		startup-delay-us = <5000>;
		vin-supply = <&vcc5v0_sys>;
	};

	vcc5v0_host: regulator-vcc5v0-host {
		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>;
		pinctrl-names = "default";
		pinctrl-0 = <&vcc5v0_host_en>;
		vin-supply = <&vcc5v0_sys>;
	};
};

&combphy0_ps {
	status = "okay";
};

&combphy1_ps {
	status = "okay";
};

&combphy2_psu {
	status = "okay";
};

&hdmi0 {
	frl-enable-gpios = <&gpio4 RK_PB1 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_in {
	hdmi0_in_vp0: endpoint {
		remote-endpoint = <&vp0_out_hdmi0>;
	};
};

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

&hdmi0_sound {
	status = "okay";
};

&hdmi1 {
	frl-enable-gpios = <&gpio4 RK_PA1 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";
};

&i2c6 {
	status = "okay";

	hym8563: rtc@51 {
		compatible = "haoyu,hym8563";
		reg = <0x51>;
		#clock-cells = <0>;
		clock-output-names = "hym8563";
		pinctrl-names = "default";
		pinctrl-0 = <&hym8563_int>;
		interrupt-parent = <&gpio0>;
		interrupts = <RK_PB0 IRQ_TYPE_LEVEL_LOW>;
		wakeup-source;
	};
};

&i2c7 {
	status = "okay";

	es8316: audio-codec@11 {
		compatible = "everest,es8316";
		reg = <0x11>;
		clocks = <&cru I2S0_8CH_MCLKOUT>;
		clock-names = "mclk";
		assigned-clocks = <&cru I2S0_8CH_MCLKOUT>;
		assigned-clock-rates = <12288000>;
		#sound-dai-cells = <0>;

		port {
			es8316_p0_0: endpoint {
				remote-endpoint = <&i2s0_8ch_p0_0>;
			};
		};
	};
};

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

	i2s0_8ch_p0: port {
		i2s0_8ch_p0_0: endpoint {
			dai-format = "i2s";
			mclk-fs = <256>;
			remote-endpoint = <&es8316_p0_0>;
		};
	};
};

&i2s5_8ch {
	status = "okay";
};

&i2s6_8ch {
	status = "okay";
};

&package_thermal {
	polling-delay = <1000>;

	trips {
		package_fan0: package-fan0 {
			temperature = <55000>;
			hysteresis = <2000>;
			type = "active";
		};

		package_fan1: package-fan1 {
			temperature = <65000>;
			hysteresis = <2000>;
			type = "active";
		};
	};

	cooling-maps {
		map0 {
			trip = <&package_fan0>;
			cooling-device = <&fan THERMAL_NO_LIMIT 1>;
		};

		map1 {
			trip = <&package_fan1>;
			cooling-device = <&fan 2 THERMAL_NO_LIMIT>;
		};
	};
};

&pcie2x1l0 {
	pinctrl-names = "default";
	pinctrl-0 = <&pcie2_0_rst>;
	reset-gpios = <&gpio4 RK_PA5 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_pcie2x1l0>;
	status = "okay";
};

&pcie2x1l2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pcie2_2_rst>;
	reset-gpios = <&gpio3 RK_PB0 GPIO_ACTIVE_HIGH>;
	vpcie3v3-supply = <&vcc3v3_pcie2x1l2>;
	status = "okay";
};

&pcie30phy {
	status = "okay";
};

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

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

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

	hym8563 {
		hym8563_int: hym8563-int {
			rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	leds {
		led_rgb_b: led-rgb-b {
			rockchip,pins = <0 RK_PB7 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	sound {
		hp_detect: hp-detect {
			rockchip,pins = <1 RK_PD5 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	pcie2 {
		pcie2_0_rst: pcie2-0-rst {
			rockchip,pins = <4 RK_PA5 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		pcie2_0_vcc3v3_en: pcie2-0-vcc-en {
			rockchip,pins = <1 RK_PD2 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		pcie2_2_rst: pcie2-2-rst {
			rockchip,pins = <3 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

	pcie3 {
		pcie3_rst: pcie3-rst {
			rockchip,pins = <4 RK_PB6 RK_FUNC_GPIO &pcfg_pull_none>;
		};

		pcie3_vcc3v3_en: pcie3-vcc3v3-en {
			rockchip,pins = <1 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
		};
	};

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

&pwm1 {
	status = "okay";
};

&sdmmc {
	bus-width = <4>;
	cap-sd-highspeed;
	cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
	disable-wp;
	max-frequency = <200000000>;
	no-sdio;
	no-mmc;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc_3v3_s3>;
	vqmmc-supply = <&vccio_sd_s0>;
	status = "okay";
};

&sdio {
	bus-width = <4>;
	cap-sdio-irq;
	disable-wp;
	keep-power-in-suspend;
	max-frequency = <200000000>;
	no-sd;
	no-mmc;
	non-removable;
	pinctrl-names = "default";
	pinctrl-0 = <&sdiom0_pins>;
	sd-uhs-sdr12;
	sd-uhs-sdr25;
	sd-uhs-sdr50;
	sd-uhs-sdr104;
	vmmc-supply = <&vcc3v3_pcie2x1l0>;
	vqmmc-supply = <&vcc_1v8_s3>;
	wakeup-source;
	status = "okay";
};

&uart2 {
	pinctrl-0 = <&uart2m0_xfer>;
	pinctrl-names = "default";
	status = "okay";
};

&uart6 {
	pinctrl-names = "default";
	pinctrl-0 = <&uart6m1_xfer &uart6m1_ctsn &uart6m1_rtsn>;
	status = "okay";
};

&u2phy1 {
	status = "okay";
};

&u2phy1_otg {
	status = "okay";
};

&u2phy2 {
	status = "okay";
};

&u2phy2_host {
	/* connected to USB hub, which is powered by vcc5v0_sys */
	phy-supply = <&vcc5v0_sys>;
	status = "okay";
};

&u2phy3 {
	status = "okay";
};

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

&usbdp_phy1 {
	status = "okay";
};

&usb_host0_ehci {
	status = "okay";
};

&usb_host0_ohci {
	status = "okay";
};

&usb_host1_ehci {
	status = "okay";
};

&usb_host1_ohci {
	status = "okay";
};

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

&usb_host2_xhci {
	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>;
	};
};