// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
 * Copyright 2024 TechNexion Ltd.
 *
 * Author: Ray Chang <ray.chang@technexion.com>
 */

/dts-v1/;

#include <dt-bindings/phy/phy-imx8-pcie.h>
#include "imx8mp-edm-g.dtsi"

/ {
	compatible = "technexion,edm-g-imx8mp-wb", "technexion,edm-g-imx8mp", "fsl,imx8mp";
	model = "TechNexion EDM-G-IMX8MP SOM on WB-EDM-G";

	connector {
		compatible = "usb-c-connector";
		data-role = "dual";
		label = "USB-C";

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

			port@0 {
				reg = <0>;

				hs_ep: endpoint {
					remote-endpoint = <&usb3_hs_ep>;
				};
			};

			port@1 {
				reg = <1>;

				ss_ep: endpoint {
					remote-endpoint = <&hd3ss3220_in_ep>;
				};
			};
		};
	};

	hdmi-connector {
		compatible = "hdmi-connector";
		label = "HDMI OUT";
		type = "a";

		port {
			hdmi_in: endpoint {
				remote-endpoint = <&hdmi_tx_out>;
			};
		};
	};

	leds {
		compatible = "gpio-leds";

		led {
			default-state = "on";
			gpios = <&expander2 1 GPIO_ACTIVE_HIGH>;
			label = "gpio-led";
		};
	};

	pcie0_refclk: clock-pcie-ref {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <100000000>;
	};

	reg_pwr_3v3: regulator-pwr-3v3 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-max-microvolt = <3300000>;
		regulator-min-microvolt = <3300000>;
		regulator-name = "pwr-3v3";
	};

	reg_pwr_5v: regulator-pwr-5v {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-max-microvolt = <5000000>;
		regulator-min-microvolt = <5000000>;
		regulator-name = "pwr-5v";
	};

	sound-hdmi {
		compatible = "fsl,imx-audio-hdmi";
		audio-cpu = <&aud2htx>;
		hdmi-out;
		model = "audio-hdmi";
	};

	sound-wm8960 {
		compatible = "fsl,imx-audio-wm8960";
		audio-asrc = <&easrc>;
		audio-codec = <&wm8960>;
		audio-cpu = <&sai3>;
		audio-routing = "Headphone Jack", "HP_L",
			"Headphone Jack", "HP_R",
			"Ext Spk", "SPK_LP",
			"Ext Spk", "SPK_LN",
			"Ext Spk", "SPK_RP",
			"Ext Spk", "SPK_RN",
			"LINPUT1", "Mic Jack",
			"LINPUT1", "Mic Jack",
			"Mic Jack", "MICB";
		model = "wm8960-audio";
	};
};

&aud2htx {
	status = "okay";
};

&easrc {
	fsl,asrc-rate = <48000>;
	status = "okay";
};

&flexcan1 {
	status = "okay";
};

&gpio1 {
	gpio-line-names =
		"", "", "", "", "", "", "DSI_RST", "",
		"", "", "", "", "", "PCIE_CLKREQ_N", "", "",
		"", "", "", "", "", "", "", "",
		"", "", "", "", "", "", "", "";
	pinctrl-0 = <&pinctrl_gpio1>;
};

&gpio4 {
	gpio-line-names =
		"", "", "", "", "", "", "GPIO_P249", "GPIO_P251",
		"", "GPIO_P255", "", "", "", "", "", "",
		"DSI_BL_EN", "DSI_VDDEN", "", "", "", "", "", "",
		"", "", "", "", "", "", "", "";
	pinctrl-0 = <&pinctrl_gpio4>;
};

&hdmi_pvi {
	status = "okay";
};

&hdmi_tx {
	pinctrl-0 = <&pinctrl_hdmi>;
	pinctrl-names = "default";
	status = "okay";

	ports {
		port@1 {
			hdmi_tx_out: endpoint {
				remote-endpoint = <&hdmi_in>;
			};
		};
	};
};

&hdmi_tx_phy {
	status = "okay";
};

&i2c2 {
	status = "okay";

	wm8960: audio-codec@1a {
		compatible = "wlf,wm8960";
		reg = <0x1a>;
		clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIOMIX_SAI3_MCLK1>;
		clock-names = "mclk";
		#sound-dai-cells = <0>;
		AVDD-supply = <&reg_pwr_3v3>;
		DBVDD-supply = <&reg_pwr_3v3>;
		DCVDD-supply = <&reg_pwr_3v3>;
		SPKVDD1-supply = <&reg_pwr_5v>;
		SPKVDD2-supply = <&reg_pwr_5v>;
		wlf,gpio-cfg = <1 2>;
		wlf,hp-cfg = <2 2 3>;
		wlf,shared-lrclk;
	};

	expander1: gpio@21 {
		compatible = "nxp,pca9555";
		reg = <0x21>;
		#gpio-cells = <2>;
		gpio-controller;
		gpio-line-names = "EXPOSURE_TRIG_IN1", "FLASH_OUT1",
				  "INFO_TRIG_IN1", "CAM_SHUTTER1", "XVS1",
				  "PWR1_TIME0", "PWR1_TIME1", "PWR1_TIME2",
				  "EXPOSURE_TRIG_IN2", "FLASH_OUT2",
				  "INFO_TRIG_IN2", "CAM_SHUTTER2", "XVS2",
				  "PWR2_TIME0", "PWR2_TIME1", "PWR2_TIME2";
	};

	expander2: gpio@23 {
		compatible = "nxp,pca9555";
		reg = <0x23>;
		#interrupt-cells = <2>;
		interrupt-controller;
		interrupt-parent = <&gpio4>;
		interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
		#gpio-cells = <2>;
		gpio-controller;
		gpio-line-names = "M2_DISABLE_N", "LED_EN", "", "",
				  "", "", "", "USB_OTG_OC",
				  "EXT_GPIO8", "EXT_GPIO9", "", "",
				  "", "CSI1_PDB", "CSI2_PDB", "PD_FAULT";
		pinctrl-0 = <&pinctrl_expander2_irq>;
		pinctrl-names = "default";
	};

	usb_typec: usb-typec@67 {
		compatible = "ti,hd3ss3220";
		reg = <0x67>;
		interrupt-parent = <&gpio4>;
		interrupts = <8 IRQ_TYPE_LEVEL_LOW>;
		pinctrl-0 = <&pinctrl_hd3ss3220_irq>;
		pinctrl-names = "default";

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

			port@0 {
				reg = <0>;

				hd3ss3220_in_ep: endpoint {
					remote-endpoint = <&ss_ep>;
				};
			};

			port@1 {
				reg = <1>;

				hd3ss3220_out_ep: endpoint {
					remote-endpoint = <&usb3_role_switch>;
				};
			};
		};
	};
};

&i2c_0 {
	eeprom2: eeprom@51 {
		compatible = "atmel,24c02";
		reg = <0x51>;
		pagesize = <16>;
	};
};

&lcdif3 {
	status = "okay";
};

&pcie {
	status = "okay";
};

&pcie_phy {
	clocks = <&pcie0_refclk>;
	clock-names = "ref";
	fsl,clkreq-unsupported;
	fsl,refclk-pad-mode = <IMX8_PCIE_REFCLK_PAD_INPUT>;
	status = "okay";
};

&usb3_0 {
	status = "okay";
};

&usb3_1 {
	status = "okay";
};

&usb3_phy0 {
	status = "okay";
};

&usb3_phy1 {
	status = "okay";
};

&usb_dwc3_0 {
	/* dual role is implemented but not a full featured OTG */
	adp-disable;
	dr_mode = "otg";
	hnp-disable;
	role-switch-default-mode = "peripheral";
	srp-disable;
	usb-role-switch;

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

		port@0 {
			reg = <0>;

			usb3_hs_ep: endpoint {
				remote-endpoint = <&hs_ep>;
			};
		};

		port@1 {
			reg = <1>;

			usb3_role_switch: endpoint {
				remote-endpoint = <&hd3ss3220_out_ep>;
			};
		};
	};
};

&usb_dwc3_1 {
	dr_mode = "host";
};

&iomuxc {
	pinctrl_expander2_irq: expander2-irqgrp {
		fsl,pins = <
			MX8MP_IOMUXC_SAI1_TXC__GPIO4_IO11		0x140 /* GPIO_P247 */
		>;
	};

	pinctrl_gpio1: gpio1grp {
		fsl,pins = <
			MX8MP_IOMUXC_GPIO1_IO06__GPIO1_IO06		0x16 /* DSI_RST */
		>;
	};

	pinctrl_gpio4: gpio4grp {
		fsl,pins = <
			MX8MP_IOMUXC_SAI1_RXD4__GPIO4_IO06		0x16 /* GPIO_P249 */
			MX8MP_IOMUXC_SAI1_RXD5__GPIO4_IO07		0x16 /* GPIO_P251 */
			MX8MP_IOMUXC_SAI1_RXD7__GPIO4_IO09		0x16 /* GPIO_P255 */
			MX8MP_IOMUXC_SAI1_TXD4__GPIO4_IO16		0x16 /* DSI_BL_EN */
			MX8MP_IOMUXC_SAI1_TXD5__GPIO4_IO17		0x16 /* DSI_VDDEN */
		>;
	};

	pinctrl_hd3ss3220_irq: hd3ss3220-irqgrp {
		fsl,pins = <
			MX8MP_IOMUXC_SAI1_RXD6__GPIO4_IO08		0x41 /* GPIO_P253 */
		>;
	};

	pinctrl_hdmi: hdmigrp {
		fsl,pins = <
			MX8MP_IOMUXC_HDMI_DDC_SCL__HDMIMIX_HDMI_SCL	0x1c2
			MX8MP_IOMUXC_HDMI_DDC_SDA__HDMIMIX_HDMI_SDA	0x1c2
			MX8MP_IOMUXC_HDMI_CEC__HDMIMIX_HDMI_CEC		0x10
		>;
	};
};