// SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
/*
 * Copyright (C) 2025 PHYTEC Messtechnik GmbH
 */

/dts-v1/;

#include <dt-bindings/leds/leds-pca9532.h>
#include <dt-bindings/phy/phy-imx8-pcie.h>
#include <dt-bindings/pwm/pwm.h>
#include "imx8mp-phycore-fpsc.dtsi"

/ {
	compatible = "phytec,imx8mp-libra-rdk-fpsc",
		     "phytec,imx8mp-phycore-fpsc", "fsl,imx8mp";
	model = "PHYTEC i.MX8MP Libra RDK FPSC";

	backlight_lvds0: backlight-lvds0 {
		compatible = "pwm-backlight";
		pinctrl-0 = <&pinctrl_lvds0>;
		pinctrl-names = "default";
		power-supply = <&reg_vdd_12v0>;
		status = "disabled";
	};

	chosen {
		stdout-path = &uart4;
	};

	panel_lvds0: panel-lvds0 {
		/* compatible panel in overlay */
		backlight = <&backlight_lvds0>;
		power-supply = <&reg_vdd_3v3>;
		status = "disabled";

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

	reg_can1_stby: regulator-can1-stby {
		compatible = "regulator-fixed";
		regulator-max-microvolt = <1800000>;
		regulator-min-microvolt = <1800000>;
		regulator-name = "can1-stby";
		gpio = <&gpio_expander 10 GPIO_ACTIVE_LOW>;
	};

	reg_can2_stby: regulator-can2-stby {
		compatible = "regulator-fixed";
		regulator-max-microvolt = <1800000>;
		regulator-min-microvolt = <1800000>;
		regulator-name = "can2-stby";
		gpio = <&gpio_expander 9 GPIO_ACTIVE_LOW>;
	};

	reg_vdd_12v0: regulator-vdd-12v0 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-max-microvolt = <12000000>;
		regulator-min-microvolt = <12000000>;
		regulator-name = "VDD_12V0";
	};

	reg_vdd_1v8: regulator-vdd-1v8 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-max-microvolt = <1800000>;
		regulator-min-microvolt = <1800000>;
		regulator-name = "VDD_1V8";
	};

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

	reg_vdd_5v0: regulator-vdd-5v0 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-boot-on;
		regulator-max-microvolt = <5000000>;
		regulator-min-microvolt = <5000000>;
		regulator-name = "VDD_5V0";
	};
};

&eqos {
	phy-handle = <&ethphy1>;
	status = "okay";

	mdio {
		compatible = "snps,dwmac-mdio";
		#address-cells = <1>;
		#size-cells = <0>;

		ethphy1: ethernet-phy@1 {
			compatible = "ethernet-phy-ieee802.3-c22";
			reg = <0x1>;
			enet-phy-lane-no-swap;
			ti,clk-output-sel = <DP83867_CLK_O_SEL_OFF>;
			ti,fifo-depth = <DP83867_PHYCR_FIFO_DEPTH_4_B_NIB>;
			ti,rx-internal-delay = <DP83867_RGMIIDCTL_1_50_NS>;
			ti,tx-internal-delay = <DP83867_RGMIIDCTL_1_50_NS>;
		};
	};
};

/* CAN FD */
&flexcan1 {
	xceiver-supply = <&reg_can1_stby>;
	status = "okay";
};

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

&flexspi {
	status = "okay";

	spi_nor: flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <80000000>;
		spi-rx-bus-width = <4>;
		spi-tx-bus-width = <1>;
		vcc-supply = <&reg_vdd_1v8>;
	};
};

&gpio5 {
	gpio-line-names = "", "", "", "", "I2C5_SDA",
			  "GPIO1", "", "", "", "SPI1_CS",
			  "", "", "", "SPI2_CS", "I2C1_SCL",
			  "I2C1_SDA", "I2C2_SCL", "I2C2_SDA", "I2C3_SCL", "I2C3_SDA",
			  "", "GPIO2", "", "LVDS1_BL_EN", "SPI3_CS",
			  "", "GPIO3";
};

&i2c2 {
	clock-frequency = <400000>;
	status = "okay";

	eeprom@51 {
		compatible = "atmel,24c02";
		reg = <0x51>;
		pagesize = <16>;
		vcc-supply = <&reg_vdd_1v8>;
	};
};

&i2c3 {
	clock-frequency = <400000>;
	status = "okay";

	leds@62 {
		compatible = "nxp,pca9533";
		reg = <0x62>;

		led-1 {
			type = <PCA9532_TYPE_LED>;
		};

		led-2 {
			type = <PCA9532_TYPE_LED>;
		};

		led-3 {
			type = <PCA9532_TYPE_LED>;
		};
	};
};

&i2c5 {
	#address-cells = <1>;
	#size-cells = <0>;
	clock-frequency = <400000>;
	status = "okay";

	gpio_expander: gpio@20 {
		compatible = "ti,tca6416";
		reg = <0x20>;
		interrupt-parent = <&gpio4>;
		interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
		#gpio-cells = <2>;
		gpio-controller;
		gpio-line-names = "CSI1_CTRL1", "CSI1_CTRL2", "CSI1_CTRL3",
				  "CSI1_CTRL4", "CSI2_CTRL1", "CSI2_CTRL2",
				  "CSI2_CTRL3", "CSI2_CTRL4", "CLK_EN_AV",
				  "nCAN2_EN", "nCAN1_EN", "PCIE1_nWAKE",
				  "PCIE2_nWAKE", "PCIE2_nALERT_3V3",
				  "UART1_BT_RS_SEL", "UART1_RS232_485_SEL";
		vcc-supply = <&reg_vdd_1v8>;

		uart1_bt_rs_sel: bt-rs-hog {
			gpios = <14 GPIO_ACTIVE_HIGH>;
			gpio-hog;
			line-name = "UART1_BT_RS_SEL";
			output-low;	/* default RS232/RS485 */
		};

		uart1_rs232_485_sel: rs232-485-hog {
			gpios = <15 GPIO_ACTIVE_HIGH>;
			gpio-hog;
			line-name = "UART1_RS232_485_SEL";
			output-high;	/* default RS232 */
		};
	};
};

&iomuxc {
	pinctrl_lvds0: lvds0grp {
		fsl,pins = <
			MX8MP_IOMUXC_UART1_TXD__GPIO5_IO23	0x12
		>;
	};
	pinctrl_rtc: rtcgrp {
		fsl,pins = <
			MX8MP_IOMUXC_UART2_TXD__GPIO5_IO25	0x1c0
		>;
	};
};

&lvds_bridge {
	ports {
		port@1 {
			ldb_lvds_ch0: endpoint {
				remote-endpoint = <&panel0_in>;
			};
		};
	};
};

/* Mini PCIe */
&pcie {
	reset-gpio = <&gpio1 8 GPIO_ACTIVE_LOW>;
	vpcie-supply = <&reg_vdd_3v3>;
	status = "okay";
};

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

&reg_vdd_io {
	regulator-max-microvolt = <1800000>;
	regulator-min-microvolt = <1800000>;
};

&rv3028 {
	interrupt-parent = <&gpio5>;
	interrupts = <25 IRQ_TYPE_LEVEL_LOW>;
	aux-voltage-chargeable = <1>;
	pinctrl-0 = <&pinctrl_rtc>;
	pinctrl-names = "default";
	trickle-resistor-ohms = <3000>;
	wakeup-source;
};

&snvs_pwrkey {
	status = "okay";
};

/* debug console */
&uart4 {
	status = "okay";
};

/* SD-Card */
&usdhc2 {
	assigned-clocks = <&clk IMX8MP_CLK_USDHC2>;
	assigned-clock-rates = <200000000>;
	bus-width = <4>;
	disable-wp;
	status = "okay";
};