// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
 * Copyright (c) Toradex
 *
 * Common dtsi for Verdin iMX95 SoM on Zinnia carrier board
 *
 * https://www.toradex.com/computer-on-modules/verdin-arm-family/nxp-imx95
 * https://www.toradex.com/products/carrier-board/zinnia-carrier-board
 */

#include <dt-bindings/leds/common.h>
#include <dt-bindings/net/ti-dp83867.h>

/ {
	aliases {
		eeprom1 = &carrier_eeprom;
	};

	leds {
		compatible = "gpio-leds";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_zinnia_leds>;

		/* LED1 Red - SODIMM 48 - LED1_R */
		led-1 {
			color = <LED_COLOR_ID_RED>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <1>;
			gpios = <&gpio5 7 GPIO_ACTIVE_HIGH>;
		};

		/* LED1 Blue - SODIMM 46 - LED1_B */
		led-2 {
			color = <LED_COLOR_ID_BLUE>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <1>;
			gpios = <&gpio5 4 GPIO_ACTIVE_HIGH>;
		};

		/* LED3 Red - SODIMM 44 - LED3_R */
		led-3 {
			color = <LED_COLOR_ID_RED>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <3>;
			gpios = <&gpio5 5 GPIO_ACTIVE_HIGH>;
		};

		/* LED3 Green - SODIMM 54 - LED3_G */
		led-4 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <3>;
			gpios = <&gpio5 10 GPIO_ACTIVE_HIGH>;
		};

		/* LED3 Blue - SODIMM 36 - LED3_B */
		led-5 {
			color = <LED_COLOR_ID_BLUE>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <3>;
			gpios = <&gpio2 20 GPIO_ACTIVE_HIGH>;
		};

		/* LED4 Red - SODIMM 34 - LED4_R */
		led-6 {
			color = <LED_COLOR_ID_RED>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <4>;
			gpios = <&gpio2 21 GPIO_ACTIVE_HIGH>;
		};

		/* LED4 Green - SODIMM 32 - LED4_G */
		led-7 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <4>;
			gpios = <&gpio2 26 GPIO_ACTIVE_HIGH>;
		};

		/* LED4 Blue - SODIMM 30 - LED4_B */
		led-8 {
			color = <LED_COLOR_ID_BLUE>;
			default-state = "off";
			function = LED_FUNCTION_STATUS;
			function-enumerator = <4>;
			gpios = <&gpio2 16 GPIO_ACTIVE_HIGH>;
		};
	};

	/* Zinnia Power Supply Input Voltage */
	zinnia-1v8-voltage {
		compatible = "voltage-divider";
		full-ohms = <39000>; /* 12k + 27k */
		/* Verdin ADC_4 */
		io-channels = <&adc1 3>;
		output-ohms = <27000>;
	};

	zinnia-3v3-voltage {
		compatible = "voltage-divider";
		full-ohms = <54000>; /* 27k + 27k */
		/* Verdin ADC_3 */
		io-channels = <&adc1 2>;
		output-ohms = <27000>;
	};

	zinnia-5v-voltage {
		compatible = "voltage-divider";
		full-ohms = <39000>; /* 27k + 12k */
		/* Verdin ADC_2 */
		io-channels = <&adc1 1>;
		output-ohms = <12000>;
	};

	zinnia-input-voltage {
		compatible = "voltage-divider";
		full-ohms = <204700>; /* 200k + 4.7k */
		/* Verdin ADC_1 */
		io-channels = <&adc1 0>;
		output-ohms = <4700>;
	};
};

/* Verdin ADC_1, ADC_2, ADC_3 and ADC_4 */
&adc1 {
	status = "okay";
};

/* Verdin ETH_1 (On-module PHY) */
&enetc_port0 {
	status = "okay";
};

/* Verdin ETH_2_RGMII */
&enetc_port1 {
	phy-handle = <&ethphy2>;
	phy-mode = "rgmii-id";

	status = "okay";
};

/* Verdin CAN_1 */
&flexcan1 {
	status = "okay";
};

&gpio1 {
	gpio-line-names =
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"",
		"",
		"",
		"";
};

&gpio2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio1>, <&pinctrl_gpio2>, <&pinctrl_gpio3>;
	gpio-line-names =
		"DO1_EN", /* SODIMM 206 */ /* 0 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"DI1_EN", /* SODIMM 208 */
		"",
		"", /* 20 */
		"",
		"",
		"",
		"DI1_RB", /* SODIMM 210 */
		"",
		"",
		"",
		"",
		"",
		"", /* 30 */
		"";
};

&gpio3 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio6>;
	gpio-line-names =
		"", /* 0 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 20 */
		"",
		"",
		"",
		"",
		"",
		"",
		"DI2_EN", /* SODIMM 218 */
		"",
		"",
		"", /* 30 */
		"";
};

&gpio4 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio5>;
	gpio-line-names =
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 20 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"DI2_RB", /* SODIMM 216 */
		"";
};

&gpio5 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio4>, <&pinctrl_qspi1_io0_gpio>;
	gpio-line-names =
		"DI3_RB", /* SODIMM 56 */ /* 0 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"DO2_EN", /* SODIMM 212 */
		"",
		"",
		"",
		"",
		"";
};

/* Verdin I2C_1 */
&lpi2c4 {
	status = "okay";

	temperature-sensor@4f {
		compatible = "ti,tmp1075";
		reg = <0x4f>;
	};

	carrier_eeprom: eeprom@57 {
		compatible = "st,24c02", "atmel,24c02";
		reg = <0x57>;
		pagesize = <16>;
	};
};

/* Verdin SPI_1 */
&lpspi6 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_lpspi6>,
		    <&pinctrl_spi1_cs>,
		    <&pinctrl_uart8_cts_gpio>;
	cs-gpios = <&gpio2 14 GPIO_ACTIVE_LOW>,
		   <&som_gpio_expander 13 GPIO_ACTIVE_LOW>,
		   <&gpio4 29 GPIO_ACTIVE_LOW>;

	tpm@2 {
		compatible = "infineon,slb9670", "tcg,tpm_tis-spi";
		reg = <2>;
		spi-max-frequency = <18500000>;
	};
};

/* Verdin UART_3, used as the Linux console */
&lpuart1 {
	status = "okay";
};

/* Verdin UART_1 */
&lpuart7 {
	status = "okay";
};

/* Verdin UART_2, through RS485 transceiver */
&lpuart8 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_uart8>, <&pinctrl_uart8_rts>;
	rs485-rx-during-tx;
	linux,rs485-enabled-at-boot-time;

	status = "okay";
};

&netc_emdio {
	ethphy2: ethernet-phy@2 {
		reg = <2>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_eth2_rgmii_int>;
		interrupt-parent = <&gpio1>;
		interrupts = <12 IRQ_TYPE_LEVEL_LOW>;
		ti,rx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
		ti,tx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
	};
};

&som_gpio_expander {
	gpio-line-names =
		"DO3_EN", /* SODIMM 220 */
		"DI3_EN", /* SODIMM 222 */
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"",
		"", /* 10 */
		"",
		"",
		"",
		"",
		"";
};

/* Verdin USB_1 */
&usb2 {
	status = "okay";
};

/* Verdin USB_2 */
&usb3 {
	status = "okay";
};

&usb3_phy {
	status = "okay";
};

/* Verdin SD_1 */
&usdhc2 {
	status = "okay";
};

&scmi_iomuxc {
	pinctrl_uart8_cts_gpio: uart8ctsgrp {
		fsl,pins = <IMX95_PAD_GPIO_IO14__GPIO2_IO_BIT14	0x51e>; /* SODIMM 143 */
	};

	pinctrl_zinnia_leds: zinnialedsgrp {
		fsl,pins = <IMX95_PAD_GPIO_IO16__GPIO2_IO_BIT16		0x11e>, /* SODIMM 30 */
			   <IMX95_PAD_GPIO_IO26__GPIO2_IO_BIT26		0x11e>, /* SODIMM 32 */
			   <IMX95_PAD_GPIO_IO21__GPIO2_IO_BIT21		0x11e>, /* SODIMM 34 */
			   <IMX95_PAD_GPIO_IO20__GPIO2_IO_BIT20		0x11e>, /* SODIMM 36 */
			   <IMX95_PAD_XSPI1_DATA5__GPIO5_IO_BIT5	0x11e>, /* SODIMM 44 */
			   <IMX95_PAD_XSPI1_DATA4__GPIO5_IO_BIT4	0x11e>, /* SODIMM 46 */
			   <IMX95_PAD_XSPI1_DATA7__GPIO5_IO_BIT7	0x11e>, /* SODIMM 48 */
			   <IMX95_PAD_XSPI1_SS0_B__GPIO5_IO_BIT10	0x11e>; /* SODIMM 54 */
	};
};