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

/dts-v1/;

#include <dt-bindings/net/ti-dp83867.h>
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/usb/pd.h>
#include "imx95-toradex-osm.dtsi"

/ {
	model = "Toradex OSM iMX95 on OSM Development Board";
	compatible = "toradex,osm-imx95-dev",
		     "toradex,osm-imx95",
		     "fsl,imx95";

	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 1V8";
	};

	sfp: sfp {
		compatible = "sff,sfp";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_b0>, <&pinctrl_gpio_b1>,
			    <&pinctrl_gpio_b2>, <&pinctrl_gpio_b3>;
		i2c-bus = <&i2c_mux_carrier_sfp>;
		los-gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
		maximum-power-milliwatt = <3000>;
		mod-def0-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
		rate-select0-gpios = <&som_gpio_expander_0 4 GPIO_ACTIVE_HIGH>;
		rate-select1-gpios = <&som_gpio_expander_1 3 GPIO_ACTIVE_HIGH>;
		tx-disable-gpios = <&gpio5 11 GPIO_ACTIVE_HIGH>;
		tx-fault-gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>;
	};

	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 {
			clocks = <&scmi_clk IMX95_CLK_SAI3>;
			sound-dai = <&wm8904_1a>;
		};

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

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

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

	status = "okay";
};

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

	status = "okay";
};

/* OSM ETH_C */
&enetc_port2 {
	managed = "in-band-status";
	phy-mode = "10gbase-r";
	sfp = <&sfp>;

	status = "okay";
};

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

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

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

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

	fan_controller: fan-controller@19 {
		compatible = "ti,amc6821";
		reg = <0x19>;
		#pwm-cells = <2>;

		fan {
			cooling-levels = <255>;
			pwms = <&fan_controller 40000 PWM_POLARITY_INVERTED>;
		};
	};

	wm8904_1a: audio-codec@1a {
		compatible = "wlf,wm8904";
		reg = <0x1a>;
		clocks = <&scmi_clk IMX95_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-low;
		};

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

	power-monitor@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 = <&gpio5>;
		interrupts = <0 IRQ_TYPE_LEVEL_LOW>;

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

			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 I2C_B */
&lpi2c5 {
	status = "okay";

	i2c-mux@70 {
		compatible = "nxp,pca9548";
		reg = <0x70>;
		#address-cells = <1>;
		#size-cells = <0>;

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

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

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

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

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

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

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

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

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

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

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

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

&netc_blk_ctrl {
	status = "okay";
};

/* OSM MDIO, shared between all ethernet ports */
&netc_emdio {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_mdio>;

	status = "okay";

	ethphy_a: ethernet-phy@2 {
		reg = <2>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_a7>;
		interrupt-parent = <&gpio1>;
		interrupts = <11 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>;
	};
};

&netc_timer {
	status = "okay";
};

&netcmix_blk_ctrl {
	status = "okay";
};

&pcie0 {
	status = "okay";
};

&pcie1 {
	status = "okay";
};

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

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

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

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

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

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

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

/* OSM USB_C */
&usb3 {
	status = "okay";
};

&usb3_phy {
	status = "okay";
};

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

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