// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
/*
 * Copyright (c) 2024 TQ-Systems GmbH <linux@ew.tq-group.com>,
 * D-82229 Seefeld, Germany.
 * Author: Alexander Stein
 */

/dts-v1/;

#include <dt-bindings/phy/phy-imx8-pcie.h>
#include "imx95-tqma9596sa.dtsi"

/ {
	model = "TQ-Systems i.MX95 TQMa95xxSA on MB-SMARC-2";
	compatible = "tq,imx95-tqma9596sa-mb-smarc-2", "tq,imx95-tqma9596sa", "fsl,imx95";

	aliases {
		gpio0 = &gpio1;
		gpio1 = &gpio2;
		gpio2 = &gpio3;
		gpio3 = &gpio4;
		i2c0 = &lpi2c1;
		i2c1 = &lpi2c2;
		i2c2 = &lpi2c3;
		i2c3 = &lpi2c4;
		i2c4 = &lpi2c5;
		i2c5 = &lpi2c6;
		i2c6 = &lpi2c7;
		i2c7 = &lpi2c8;
		mmc0 = &usdhc1;
		mmc1 = &usdhc2;
		rtc0 = &pcf85063;
		rtc1 = &scmi_bbm;
		serial0 = &lpuart1;
		serial1 = &lpuart2;
		serial2 = &lpuart3;
		serial3 = &lpuart4;
		serial4 = &lpuart5;
		serial5 = &lpuart6;
		serial6 = &lpuart7;
		serial7 = &lpuart8;
		spi0 = &flexspi1;
		spi1 = &lpspi3;
	};

	chosen {
		stdout-path = &lpuart7;
	};

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

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

	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 {
				/* TODO: LVDS0 out */
			};
		};
	};

	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 {
				/* TODO: LVDS1 out */
			};
		};
	};

	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 = <&expander2 2 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 = <&expander2 4 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	sound {
		compatible = "fsl,imx-audio-tlv320aic32x4";
		model = "tqm-tlv320aic32";
		audio-codec = <&tlv320aic3x04>;
		audio-cpu = <&sai3>;
		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";
	};
};

&enetc_port0 {
	status = "okay";
};

&enetc_port1 {
	status = "okay";
};

&expander2 {
	pcie1-clk-en-hog {
		gpio-hog;
		gpios = <14 GPIO_ACTIVE_HIGH>;
		output-high;
		line-name = "PCIE1_CLK_EN";
	};

	pcie2-clk-en-hog {
		gpio-hog;
		gpios = <15 GPIO_ACTIVE_HIGH>;
		output-high;
		line-name = "PCIE2_CLK_EN";
	};
};

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

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

&lpi2c1 {
	tlv320aic3x04: audio-codec@18 {
		compatible = "ti,tlv320aic32x4";
		reg = <0x18>;
		clocks = <&scmi_clk IMX95_CLK_SAI3>;
		clock-names = "mclk";
		iov-supply = <&reg_1v8>;
		ldoin-supply = <&reg_3v3>;
	};

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

&lpspi3 {
	status = "okay";
};

/* SER0 */
&lpuart1 {
	status = "reserved";
};

/* SER3 */
&lpuart5 {
	status = "okay";
};

/* SER1 */
&lpuart7 {
	status = "okay";
};

/* SER2 */
&lpuart8 {
	status = "okay";
};

/* X44 mPCIe */
&pcie0 {
	status = "okay";
};

/* X22 PCIe x1 socket */
&pcie1 {
	status = "okay";
};

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

&sai3 {
	status = "okay";
};

/* X4 */
&usb2 {
	srp-disable;
	hnp-disable;
	adp-disable;
	/* DR not yet supported */
	dr_mode = "peripheral";
	disable-over-current;
	status = "okay";
};

/* X16 */
&usdhc2 {
	no-mmc;
	no-sdio;
	status = "okay";
};