// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
 * Copyright 2025-2026 TQ-Systems GmbH <linux@ew.tq-group.com>,
 * D-82229 Seefeld, Germany.
 * Author: Paul Gerber
 */

/dts-v1/;

#include <dt-bindings/leds/common.h>
#include "imx8mp-tqma8mpqs.dtsi"

/ {
	model = "TQ-Systems i.MX8MPlus TQMa8MPxS on MB-SMARC-2";
	compatible = "tq,imx8mp-tqma8mpqs-mb-smarc-2", "tq,imx8mp-tqma8mpqs", "fsl,imx8mp";
	chassis-type = "embedded";

	chosen {
		stdout-path = &uart3;
	};

	aliases {
		ethernet0 = &eqos;
		ethernet1 = &fec;
		mmc0 = &usdhc3;
		mmc1 = &usdhc2;
		rtc0 = &pcf85063;
		rtc1 = &snvs_rtc;
		spi0 = &flexspi;
		spi1 = &ecspi1;
		spi2 = &ecspi2;
		spi3 = &ecspi3;
	};

	backlight_lvds0: backlight-lvds0 {
		compatible = "pwm-backlight";
		pwms = <&pwm3 0 100000 0>;
		brightness-levels = <0 4 8 16 32 64 128 255>;
		default-brightness-level = <7>;
		enable-gpios = <&expander0 0 GPIO_ACTIVE_HIGH>;
		power-supply = <&reg_12v0>;
		status = "disabled";
	};

	backlight_lvds1: backlight-lvds1 {
		compatible = "pwm-backlight";
		pwms = <&pwm2 0 100000 0>;
		brightness-levels = <0 4 8 16 32 64 128 255>;
		default-brightness-level = <7>;
		enable-gpios = <&expander0 2 GPIO_ACTIVE_HIGH>;
		power-supply = <&reg_12v0>;
		status = "disabled";
	};

	hdmi-connector {
		compatible = "hdmi-connector";
		label = "X6";
		type = "a";

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

	panel_lvds0: panel-lvds0 {
		/*
		 * Display is not fixed, so compatible has to be added from
		 * DT overlay
		 */
		backlight = <&backlight_lvds0>;
		power-supply = <&reg_lvds0>;
		status = "disabled";

		port {
			panel_in_lvds0: endpoint {
				remote-endpoint = <&ldb_lvds_ch0>;
			};
		};
	};

	panel_lvds1: panel-lvds1 {
		/*
		 * Display is not fixed, so compatible has to be added from
		 * DT overlay
		 */
		backlight = <&backlight_lvds1>;
		power-supply = <&reg_lvds1>;
		status = "disabled";

		port {
			panel_in_lvds1: endpoint {
				remote-endpoint = <&ldb_lvds_ch1>;
			};
		};
	};

	reg_1v8: regulator-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "1V8";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
		regulator-always-on;
	};

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

	reg_12v0: regulator-12v0 {
		compatible = "regulator-fixed";
		regulator-name = "12V0";
		regulator-min-microvolt = <12000000>;
		regulator-max-microvolt = <12000000>;
		regulator-always-on;
	};

	reg_lvds0: regulator-lvds0 {
		compatible = "regulator-fixed";
		regulator-name = "LCD0_VDD_EN";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpio = <&expander0 1 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	reg_lvds1: regulator-lvds1 {
		compatible = "regulator-fixed";
		regulator-name = "LCD1_VDD_EN";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpio = <&expander0 3 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	reserved-memory {
		#address-cells = <2>;
		#size-cells = <2>;
		ranges;

		/* global autoconfigured region for contiguous allocations */
		linux,cma {
			compatible = "shared-dma-pool";
			reusable;
			size = <0 0x38000000>;
			alloc-ranges = <0 0x40000000 0 0x78000000>;
			linux,cma-default;
		};
	};

	sound {
		compatible = "fsl,imx-audio-tlv320aic32x4";
		model = "tqm-tlv320aic32";
		audio-asrc = <&easrc>;
		audio-cpu = <&sai5>;
		audio-codec = <&tlv320aic3x04>;
		audio-routing =
			"IN3_L", "Mic Jack",
			"Mic Jack", "Mic Bias",
			"IN1_L", "Line In Jack",
			"IN1_R", "Line In Jack",
			"Line Out Jack", "LOL",
			"Line Out Jack", "LOR";
	};

	usb-connector {
		compatible = "gpio-usb-b-connector", "usb-b-connector";
		type = "micro";
		label = "X4";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_usbcon0>;
		id-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;

		port {
			usb_dr_connector: endpoint {
				remote-endpoint = <&usb3_dwc>;
			};
		};
	};
};

&easrc {
	status = "okay";
};

&ecspi1 {
	status = "okay";
};

&eqos {
	status = "okay";
};

&ethphy0 {
	leds {
		#address-cells = <1>;
		#size-cells = <0>;

		led@1 {
			reg = <1>;
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_LAN;
			function-enumerator = <0>;
			default-state = "keep";
		};

		led@2 {
			reg = <2>;
			color = <LED_COLOR_ID_AMBER>;
			function = LED_FUNCTION_LAN;
			function-enumerator = <0>;
			default-state = "keep";
		};
	};
};

&ethphy3 {
	leds {
		#address-cells = <1>;
		#size-cells = <0>;

		led@1 {
			reg = <1>;
			color = <LED_COLOR_ID_GREEN>;
			function = LED_FUNCTION_LAN;
			function-enumerator = <0>;
			default-state = "keep";
		};

		led@2 {
			reg = <2>;
			color = <LED_COLOR_ID_AMBER>;
			function = LED_FUNCTION_LAN;
			function-enumerator = <0>;
			default-state = "keep";
		};
	};
};

&fec {
	status = "okay";
};

&flexcan1 {
	xceiver-supply = <&reg_3v3>;
	status = "okay";
};

&flexcan2 {
	xceiver-supply = <&reg_3v3>;
	status = "okay";
};

&hdmi_pvi {
	status = "okay";
};

&hdmi_tx {
	status = "okay";

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

&hdmi_tx_phy {
	status = "okay";
};

&i2c1 {
	tlv320aic3x04: audio-codec@18 {
		compatible = "ti,tlv320aic32x4";
		reg = <0x18>;
		clock-names = "mclk";
		clocks = <&audio_blk_ctrl IMX8MP_CLK_AUDIOMIX_SAI5_MCLK1>;
		iov-supply = <&reg_1v8>;
		ldoin-supply = <&reg_3v3>;
		assigned-clocks = <&clk IMX8MP_CLK_SAI5>;
		assigned-clock-parents = <&clk IMX8MP_AUDIO_PLL1_OUT>;
		assigned-clock-rates = <12288000>;
	};

	eeprom2: eeprom@57 {
		compatible = "atmel,24c32";
		reg = <0x57>;
		pagesize = <32>;
		vcc-supply = <&reg_3v3>;
	};
};

&ldb_lvds_ch0 {
	remote-endpoint = <&panel_in_lvds0>;
};

&ldb_lvds_ch1 {
	remote-endpoint = <&panel_in_lvds1>;
};

&lcdif1 {
	status = "okay";
};

&lcdif3 {
	status = "okay";
};

&pcie_phy {
	fsl,clkreq-unsupported;
	status = "okay";
};

&pcie {
	status = "okay";
};

&reg_usdhc2_vmmc {
	startup-delay-us = <100>;
	off-on-delay-us = <200000>;
	status = "okay";
};

&reg_usdhc2_vqmmc {
	status = "okay";
};

&sai3 {
	status = "okay";
};

&sai5 {
	status = "okay";
};

&snvs_pwrkey {
	status = "okay";
};

&uart1 {
	status = "okay";
};

&uart2 {
	status = "okay";
};

&uart4 {
	status = "okay";
};

&usb3_0 {
	status = "okay";
};

&usb_dwc3_0 {
	status = "okay";

	port {
		usb3_dwc: endpoint {
			remote-endpoint = <&usb_dr_connector>;
		};
	};
};

&usdhc2 {
	cd-gpios = <&gpio2 12 GPIO_ACTIVE_LOW>;
	wp-gpios = <&gpio2 20 GPIO_ACTIVE_HIGH>;
	vmmc-supply = <&reg_usdhc2_vmmc>;
	no-mmc;
	no-sdio;
	status = "okay";
};