// SPDX-License-Identifier: GPL-2.0-only OR MIT
/*
 * Copyright (c) Toradex
 *
 * Toradex OSM iMX93/iMX91 SoM on OSM Development carrier board
 *
 * https://www.toradex.com/computer-on-modules/osm-arm-family/nxp-imx93
 * https://www.toradex.com/computer-on-modules/osm-arm-family/nxp-imx91
 * https://www.toradex.com/products/carrier-board/osm-development-board
 */

#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/net/ti-dp83867.h>
#include <dt-bindings/usb/pd.h>

/ {
	aliases {
		eeprom1 = &carrier_eeprom;
	};

	reg_carrier_1p8v: regulator-carrier-1p8v {
		compatible = "regulator-fixed";
		regulator-max-microvolt = <1800000>;
		regulator-min-microvolt = <1800000>;
		regulator-name = "On-carrier V1.8_SW";
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,bitclock-master = <&codec_dai>;
		simple-audio-card,format = "i2s";
		simple-audio-card,frame-master = <&codec_dai>;
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,name = "verdin-wm8904";
		simple-audio-card,routing =
			"Headphone Jack", "HPOUTL",
			"Headphone Jack", "HPOUTR",
			"IN2L", "Line In Jack",
			"IN2R", "Line In Jack",
			"Microphone Jack", "MICBIAS",
			"IN1L", "Microphone Jack";
		simple-audio-card,widgets =
			"Microphone", "Microphone Jack",
			"Headphone", "Headphone Jack",
			"Line", "Line In Jack";

		codec_dai: simple-audio-card,codec {
			sound-dai = <&wm8904_1a>;
		};

		simple-audio-card,cpu {
			sound-dai = <&sai3>;
		};
	};
};

/* OSM ADC_0, ADC_1 */
&adc1 {
	status = "okay";
};

/* OSM ETH_A */
&eqos {
	phy-handle = <&ethphy_a>;
	phy-mode = "rgmii-id";

	status = "okay";
};

/* OSM ETH_B */
&fec {
	phy-handle = <&ethphy_b>;
	phy-mode = "rgmii-id";

	status = "okay";
};

/* OSM CAN_A */
&flexcan1 {
	status = "okay";
};

/* OSM CAN_B */
&flexcan2 {
	status = "okay";
};

&gpio2 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio_a1>, <&pinctrl_gpio_a2>, <&pinctrl_gpio_a3>,
		    <&pinctrl_gpio_a4>, <&pinctrl_gpio_a5>;
};

&gpio4 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpio_a6>;
};

/* OSM I2C_B */
&lpi2c1 {
	i2c-mux@70 {
		compatible = "nxp,pca9548";
		reg = <0x70>;
		#address-cells = <1>;
		#size-cells = <0>;

		i2c_csi: i2c@0 {
			reg = <0>;
			#address-cells = <1>;
			#size-cells = <0>;
		};

		i2c_lvds: i2c@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;
		};

		/* I2C on DSI connector pin #4 and #6 */
		i2c_dsi_1: i2c@2 {
			reg = <2>;
			#address-cells = <1>;
			#size-cells = <0>;
		};

		/* I2C on DSI connector pin #52 and #54 */
		i2c_dsi_2: i2c@3 {
			reg = <3>;
			#address-cells = <1>;
			#size-cells = <0>;
		};
	};
};

/* OSM I2C_A */
&lpi2c3 {
	status = "okay";

	wm8904_1a: audio-codec@1a {
		compatible = "wlf,wm8904";
		reg = <0x1a>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_i2s_a_mclk>;
		clocks = <&clk IMX93_CLK_SAI3>;
		clock-names = "mclk";
		#sound-dai-cells = <0>;
		AVDD-supply = <&reg_carrier_1p8v>;
		CPVDD-supply = <&reg_carrier_1p8v>;
		DBVDD-supply = <&reg_carrier_1p8v>;
		DCVDD-supply = <&reg_carrier_1p8v>;
		MICVDD-supply = <&reg_carrier_1p8v>;
	};

	gpio@20 {
		compatible = "nxp,pcal6408";
		reg = <0x20>;
		#gpio-cells = <2>;
		gpio-controller;
		gpio-line-names =
			"PWR_CTRL_CAN_A", /* 0 */
			"PWR_CTRL_CAN_B",
			"PWR_CTRL_USB-HUB",
			"LVDS_MUX_CTRL",
			"USB_MUX_CTRL",
			"I2CA_IOEXP_P5",
			"I2CA_IOEXP_P6",
			"I2CA_IOEXP_P7";

		lvds_mux_ctrl: lvds-mux-ctrl-hog {
			gpio-hog;
			gpios = <3 GPIO_ACTIVE_HIGH>;
			line-name = "LVDS_MUX_CTRL";
			output-high;
		};

		usb_mux_ctrl: usb-mux-ctrl-hog {
			gpio-hog;
			gpios = <4 GPIO_ACTIVE_HIGH>;
			line-name = "USB_MUX_CTRL";
			output-low;
		};
	};

	hwmon@40 {
		compatible = "ti,ina219";
		reg = <0x40>;
		shunt-resistor = <10000>;
	};

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

	tcpc@52 {
		compatible = "nxp,ptn5110", "tcpci";
		reg = <0x52>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_a0>;
		interrupt-parent = <&gpio2>;
		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;

		connector {
			compatible = "usb-c-connector";
			label = "USB_A";
			data-role = "dual";
			power-role = "dual";
			try-power-role = "sink";
			self-powered;
			source-pdos = <PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)>;
			sink-pdos = <PDO_FIXED(5000, 0, PDO_FIXED_USB_COMM)>;
			op-sink-microwatt = <0>;

			port {
				usb_c_a_conn_hs: endpoint {
					remote-endpoint = <&usb_a_hs>;
				};
			};
		};
	};

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

/* OSM SPI_B */
&lpspi1 {
	status = "okay";
};

/* OSM SPI_A */
&lpspi8 {
	status = "okay";
};

/* OSM UART_CON, used as the Linux Console */
&lpuart1 {
	status = "okay";
};

/* OSM UART_C */
&lpuart2 {
	status = "okay";
};

/* OSM UART_A */
&lpuart6 {
	status = "okay";
};

/* OSM UART_B */
&lpuart7 {
	status = "okay";
};

/* OSM ETH_MDIO */
&mdio {
	status = "okay";

	ethphy_a: ethernet-phy@2 {
		reg = <2>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_a7>;
		interrupt-parent = <&gpio4>;
		interrupts = <15 IRQ_TYPE_LEVEL_LOW>;
		ti,rx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
		ti,tx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
	};

	ethphy_b: ethernet-phy@3 {
		reg = <3>;
		ti,rx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
		ti,tx-internal-delay = <DP83867_RGMIIDCTL_2_00_NS>;
	};
};

/* OSM I2S_A */
&sai3 {
	status = "okay";
};

/* OSM PWM_0 */
&tpm4 {
	status = "okay";
};

/* OSM PWM_1 */
&tpm5 {
	status = "okay";
};

/* OSM PWM_2 */
&tpm6 {
	status = "okay";
};

/* OSM USB_A */
&usbotg1 {
	status = "okay";

	port {
		usb_a_hs: endpoint {
			remote-endpoint = <&usb_c_a_conn_hs>;
		};
	};
};

/* OSM USB_B */
&usbotg2 {
	status = "okay";
};

/* OSM SDIO_A */
&usdhc2 {
	status = "okay";
};

/* OSM SDIO_B */
&usdhc3 {
	status = "okay";
};