// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright 2022-2026 Josua Mayer <josua@solid-run.com>
 */

/dts-v1/;

#include "imx8dxl-sr-som.dtsi"

/ {
	compatible = "solidrun,imx8dxl-hummingboard-telematics",
		     "solidrun,imx8dxl-sr-som", "fsl,imx8dxl";
	model = "SolidRun i.MX8DXL HummingBoard Telematics";

	aliases {
		/* override ethernet aliases from imx8dxl.dtsi */
		ethernet0 = &eqos;
		ethernet1 = &switch_port1;
		ethernet2 = &switch_port2;
		ethernet3 = &switch_port3;
		ethernet4 = &switch_port4;
		ethernet5 = &switch_port5;
		ethernet6 = &switch_port6;
		ethernet7 = &switch_port7;
		ethernet8 = &switch_port8;
		ethernet9 = &switch_port9;
		ethernet10 = &switch_port10;
		gpio8 = &tca6408_u2;
		mmc2 = &usdhc3;
		rtc0 = &carrier_rtc;
		rtc1 = &rtc;
		serial1 = &lpuart1;
	};

	osc_32k: clock-osc-32k {
		compatible = "fixed-clock";
		clock-frequency = <32768>;
		#clock-cells = <0>;
	};

	v_1_1: regulator-1-1 {
		compatible = "regulator-fixed";
		regulator-name = "1v1";
		pinctrl-0 = <&regulator_1v1_pins>;
		pinctrl-names = "default";
		regulator-always-on;
		regulator-max-microvolt = <1100000>;
		regulator-min-microvolt = <1100000>;
		vin-supply = <&v_5_0>;
		gpio = <&lsio_gpio4 5 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	v_5_0: regulator-5-0 {
		compatible = "regulator-fixed";
		regulator-name = "5v0";
		regulator-max-microvolt = <5000000>;
		regulator-min-microvolt = <5000000>;
	};

	/* can transceiver builtin regulator (STBN1 pin) */
	reg_flexcan1_stby: regulator-flexcan1-standby {
		compatible = "regulator-fixed";
		regulator-name = "flexcan1-standby";
		regulator-max-microvolt = <3300000>;
		regulator-min-microvolt = <3300000>;
		gpio = <&tca6408_u2 2 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	/* can transceiver builtin regulator (STBN2 pin) */
	reg_flexcan2_stby: regulator-flexcan2-standby {
		compatible = "regulator-fixed";
		regulator-name = "flexcan2-standby";
		regulator-max-microvolt = <3300000>;
		regulator-min-microvolt = <3300000>;
		gpio = <&tca6408_u2 3 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	modem_vbat: regulator-modem-vbat {
		compatible = "regulator-fixed";
		regulator-name = "modem-vbat";
		pinctrl-0 = <&regulator_modem_vbat_pins>;
		pinctrl-names = "default";
		regulator-max-microvolt = <3600000>;
		regulator-min-microvolt = <3600000>;
		vin-supply = <&v_5_0>;
		gpio = <&lsio_gpio0 14 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		/*
		 * Cellular Modem uses VBAT, RESET_N and PWRKEY for
		 * power-sequencing. USB core does not currently
		 * support this, keep vbat on permanently and let
		 * userspace deal with reset/pwrkey.
		 */
		regulator-always-on;
		regulator-boot-on;
	};

	vbus1: regulator-vbus-1 {
		compatible = "regulator-fixed";
		regulator-name = "vbus1";
		pinctrl-0 = <&regulator_usb1_vbus_pins>;
		pinctrl-names = "default";
		regulator-max-microvolt = <5000000>;
		regulator-min-microvolt = <5000000>;
		gpio = <&lsio_gpio0 16 GPIO_ACTIVE_HIGH>;
		enable-active-high;
	};

	usdhc3_pwrseq: usdhc3-pwrseq {
		compatible = "mmc-pwrseq-simple";
		reset-gpios = <&lsio_gpio0 15 GPIO_ACTIVE_LOW>;
	};
};

&dma_apbh {
	status = "disabled";
};

&eqos {
	/* delays are added by connected ethernet-switch cpu port */
	phy-mode = "rgmii-id";
	rx-internal-delay-ps = <0>;
	tx-internal-delay-ps = <0>;
	pinctrl-0 = <&eqos_pins>;
	pinctrl-names = "default";
	status = "okay";

	fixed-link {
		full-duplex;
		speed = <1000>;
	};
};

&flexcan1 {
	pinctrl-0 = <&flexcan1_pins>;
	pinctrl-names = "default";
	xceiver-supply = <&reg_flexcan1_stby>;
	status = "okay";

	can-transceiver {
		max-bitrate = <5000000>;
	};
};

&flexcan2 {
	pinctrl-0 = <&flexcan2_pins>;
	pinctrl-names = "default";
	xceiver-supply = <&reg_flexcan2_stby>;
	status = "okay";

	can-transceiver {
		max-bitrate = <5000000>;
	};
};

&i2c2 {
	/* routed to J14: SDA(51), SCL(53) */

	/* regulator@18 */

	tca6408_u2: gpio@20 {
		compatible = "ti,tca6408";
		reg = <0x20>;
		#interrupt-cells = <2>;
		interrupt-controller;
		#gpio-cells = <2>;
		gpio-controller;
		gpio-line-names = "DIG_IN1", "DIG_IN2", "CAN_STNB1", "CAN_STNB2",
				  "DIG_OUT1", "DIG_OUT2", "", "";
		interrupts-extended = <&lsio_gpio0 20 IRQ_TYPE_EDGE_FALLING>;
		pinctrl-0 = <&tca6408_u2_int_pins>;
		pinctrl-names = "default";
	};

	carrier_rtc: rtc@32 {
		compatible = "epson,rx8111";
		reg = <0x32>;
	};
};

&iomuxc {
	bluetooth_pins: pinctrl-bluetooth-grp {
		fsl,pins = <
			/* BT_REG_ON: io without pull (module integrates pd) */
			IMX8DXL_SPI3_SCK_LSIO_GPIO0_IO13			0x0000061
		>;
	};

	eqos_pins: pinctrl-eqos-grp {
		fsl,pins = <
			/* MDIO to Switch */
			/* enet0 mdio pads supplied with 3.3v */
			/* IMX8DXL_COMP_CTL_GPIO_1V8_3V3_GPIOCT */
			IMX8DXL_ENET0_MDC_CONN_EQOS_MDC				0x06000020
			IMX8DXL_ENET0_MDIO_CONN_EQOS_MDIO			0x06000020
			/* RGMII to Switch */
			IMX8DXL_ENET1_RGMII_TX_CTL_CONN_EQOS_RGMII_TX_CTL	0x06000020
			IMX8DXL_ENET1_RGMII_TXC_CONN_EQOS_RGMII_TXC		0x06000020
			IMX8DXL_ENET1_RGMII_TXD0_CONN_EQOS_RGMII_TXD0		0x06000020
			IMX8DXL_ENET1_RGMII_TXD1_CONN_EQOS_RGMII_TXD1		0x06000020
			IMX8DXL_ENET1_RGMII_TXD2_CONN_EQOS_RGMII_TXD2		0x06000020
			IMX8DXL_ENET1_RGMII_TXD3_CONN_EQOS_RGMII_TXD3		0x06000020
			IMX8DXL_ENET1_RGMII_RXC_CONN_EQOS_RGMII_RXC		0x06000020
			IMX8DXL_ENET1_RGMII_RX_CTL_CONN_EQOS_RGMII_RX_CTL	0x06000020
			IMX8DXL_ENET1_RGMII_RXD0_CONN_EQOS_RGMII_RXD0		0x06000020
			IMX8DXL_ENET1_RGMII_RXD1_CONN_EQOS_RGMII_RXD1		0x06000020
			IMX8DXL_ENET1_RGMII_RXD2_CONN_EQOS_RGMII_RXD2		0x06000020
			IMX8DXL_ENET1_RGMII_RXD3_CONN_EQOS_RGMII_RXD3		0x06000020
		>;
	};

	flexcan1_pins: pinctrl-flexcan1-grp {
		fsl,pins = <
			IMX8DXL_FLEXCAN0_TX_ADMA_FLEXCAN0_TX			0x00000021
			IMX8DXL_FLEXCAN0_RX_ADMA_FLEXCAN0_RX			0x00000021
		>;
	};

	flexcan2_pins: pinctrl-flexcan2-grp {
		fsl,pins = <
			IMX8DXL_FLEXCAN1_TX_ADMA_FLEXCAN1_TX			0x00000021
			IMX8DXL_FLEXCAN1_RX_ADMA_FLEXCAN1_RX			0x00000021
		>;
	};

	lpspi0_pins: pinctrl-lpspi0-grp {
		fsl,pins = <
			IMX8DXL_SPI0_SCK_ADMA_SPI0_SCK				0x600004c
			IMX8DXL_SPI0_SDO_ADMA_SPI0_SDO				0x600004c
			IMX8DXL_SPI0_SDI_ADMA_SPI0_SDI				0x600004c
			IMX8DXL_SPI0_CS0_LSIO_GPIO1_IO08			0x0000021
			IMX8DXL_SPI0_CS1_LSIO_GPIO1_IO07			0x0000021
		>;
	};

	lpuart1_pins: pinctrl-lpuart1-grp {
		fsl,pins = <
			IMX8DXL_UART1_RX_ADMA_UART1_RX				0x06000020
			IMX8DXL_UART1_TX_ADMA_UART1_TX				0x06000020
			IMX8DXL_UART1_CTS_B_ADMA_UART1_CTS_B			0x06000020
			IMX8DXL_UART1_RTS_B_ADMA_UART1_RTS_B			0x06000020
		>;
	};

	modem_pins: pinctrl-lte-grp {
		fsl,pins = <
			/* modem RESET_N: io open drain drive 2mA */
			IMX8DXL_ADC_IN3_LSIO_GPIO1_IO11	0x2000061

			/* modem PWRKEY: io open drain with pull-up, drive 2mA */
			IMX8DXL_ADC_IN2_LSIO_GPIO1_IO12	0x2000021
		>;
	};

	regulator_1v1_pins: pinctrl-regulator-1-1-grp {
		fsl,pins = <
			/* SW_PE: io without pull-up */
			IMX8DXL_USB_SS3_TC2_LSIO_GPIO4_IO05			0x0000061
		>;
	};

	regulator_modem_vbat_pins: pinctrl-regulator-modem-vbat-grp {
		fsl,pins = <
			/*
			 * RF_PWR: io without pull-up,
			 * has either external pull-up (R1117) or pull-down (R1118).
			 * With pull-up Modem will boot at system power-up,
			 * with pull-down modem will enter power-down mode once
			 * vbat is enabled -> toggle pwrkey to boot modem.
			 * Hence pull-up (R1117) is preferred.
			 */
			IMX8DXL_SPI3_SDO_LSIO_GPIO0_IO14			0x0000061
		>;
	};

	regulator_usb1_vbus_pins: pinctrl-regulator-usb1-vbus-grp {
		fsl,pins = <
			/* regulator enable: open-drain with pull-up & low drive strength */
			IMX8DXL_SPI3_CS0_LSIO_GPIO0_IO16			0x2000021
		>;
	};

	switch_pins: pinctrl-switch-grp {
		fsl,pins = <
			/* SW_RSTn: io without pull-up */
			IMX8DXL_USB_SS3_TC0_LSIO_GPIO4_IO03			0x0000021

			/* SW_CORE_RSTn: io without pull-up */
			IMX8DXL_USB_SS3_TC1_LSIO_GPIO4_IO04			0x0000021

			/* INT_N: io without pull-up */
			IMX8DXL_USB_SS3_TC3_LSIO_GPIO4_IO06			0x0000021
		>;
	};

	tca6408_u2_int_pins: pinctrl-tca6408-u2-int-grp {
		fsl,pins = <
			/* gpio-expander interrupt: io with pull-up */
			IMX8DXL_MCLK_OUT0_LSIO_GPIO0_IO20			0x0000021
		>;
	};

	usdhc3_pins: pinctrl-usdhc3-grp {
		fsl,pins = <
			IMX8DXL_ENET0_RGMII_TXC_CONN_USDHC2_CLK			0x06000040
			IMX8DXL_ENET0_RGMII_TX_CTL_CONN_USDHC2_CMD		0x00000021
			IMX8DXL_ENET0_RGMII_TXD0_CONN_USDHC2_DATA0		0x00000021
			IMX8DXL_ENET0_RGMII_TXD1_CONN_USDHC2_DATA1		0x00000021
			IMX8DXL_ENET0_RGMII_TXD2_CONN_USDHC2_DATA2		0x00000021
			IMX8DXL_ENET0_RGMII_TXD3_CONN_USDHC2_DATA3		0x00000021
		>;
	};

	wifi_pins: pinctrl-wifi-grp {
		fsl,pins = <
			/* WL_REG_ON: io without pull (module integrates pd) */
			IMX8DXL_SPI3_SDI_LSIO_GPIO0_IO15			0x0000061
		>;
	};
};

&lpspi0 {
	cs-gpios = <&lsio_gpio1 8 GPIO_ACTIVE_LOW>, <&lsio_gpio1 7 GPIO_ACTIVE_LOW>;
	pinctrl-0 = <&lpspi0_pins>, <&switch_pins>;
	pinctrl-names = "default";
	status = "okay";

	ethernet-switch@0 {
		compatible = "nxp,sja1110a";
		reg = <0>;
		reset-gpios = <&lsio_gpio4 3 GPIO_ACTIVE_LOW>;
		spi-max-frequency = <4000000>;

		ethernet-ports {
			#address-cells = <1>;
			#size-cells = <0>;

			/* 100Base-TX on connector J26 */
			switch_port1: port@1 {
				reg = <0x1>;
				phy-handle = <&switch_port1_base_tx_phy>;
				phy-mode = "internal";
			};

			/* CPU */
			switch_port2: port@2 {
				reg = <0x2>;
				ethernet = <&eqos>;
				phy-mode = "rgmii-id";
				rx-internal-delay-ps = <2000>;
				tx-internal-delay-ps = <2000>;

				fixed-link {
					full-duplex;
					speed = <1000>;
				};
			};

			/* sgmii on addon board connector J21 */
			switch_port3: port@3 {
				reg = <0x3>;
				status = "disabled";
			};

			/* sgmii on addon board connector J21 */
			switch_port4: port@4 {
				reg = <0x4>;
				status = "disabled";
			};

			/* 100base-t1 on addon board connector J21 */
			switch_port5: port@5 {
				reg = <0x5>;
				phy-handle = <&switch_port5_base_t1_phy>;
				phy-mode = "internal";
				status = "disabled";
			};

			/* 100base-t1 on addon board connector J21 */
			switch_port6: port@6 {
				reg = <0x6>;
				phy-handle = <&switch_port6_base_t1_phy>;
				phy-mode = "internal";
				status = "disabled";
			};

			/* 100base-t1 on addon board connector J21 */
			switch_port7: port@7 {
				reg = <0x7>;
				phy-handle = <&switch_port7_base_t1_phy>;
				phy-mode = "internal";
				status = "disabled";
			};

			/* 100base-t1 on addon board connector J21 */
			switch_port8: port@8 {
				reg = <0x8>;
				phy-handle = <&switch_port8_base_t1_phy>;
				phy-mode = "internal";
				status = "disabled";
			};

			/* 100base-t1 on addon board connector J21 */
			switch_port9: port@9 {
				reg = <0x9>;
				phy-handle = <&switch_port9_base_t1_phy>;
				phy-mode = "internal";
				status = "disabled";
			};

			/* 100Base-T1 on connector J26 */
			switch_port10: port@a {
				reg = <0xa>;
				phy-handle = <&switch_port10_base_t1_phy>;
				phy-mode = "internal";
			};
		};

		mdios {
			#address-cells = <1>;
			#size-cells = <0>;

			mdio@0 {
				compatible = "nxp,sja1110-base-t1-mdio";
				reg = <0>;
				#address-cells = <1>;
				#size-cells = <0>;

				/* 100base-t1 on addon board connector J21 */
				switch_port5_base_t1_phy: ethernet-phy@1 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x1>;
					status = "disabled";
				};

				/* 100base-t1 on addon board connector J21 */
				switch_port6_base_t1_phy: ethernet-phy@2 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x2>;
					status = "disabled";
				};

				/* 100base-t1 on addon board connector J21 */
				switch_port7_base_t1_phy: ethernet-phy@3 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x3>;
					status = "disabled";
				};

				/* 100base-t1 on addon board connector J21 */
				switch_port8_base_t1_phy: ethernet-phy@4 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x4>;
					status = "disabled";
				};

				/* 100base-t1 on addon board connector J21 */
				switch_port9_base_t1_phy: ethernet-phy@5 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x5>;
					status = "disabled";
				};

				/* 100Base-T1 on connector J26 */
				switch_port10_base_t1_phy: ethernet-phy@6 {
					compatible = "ethernet-phy-ieee802.3-c45";
					reg = <0x6>;
				};
			};

			mdio@1 {
				compatible = "nxp,sja1110-base-tx-mdio";
				reg = <1>;
				#address-cells = <1>;
				#size-cells = <0>;

				/* 100Base-TX on connector J26 */
				switch_port1_base_tx_phy: ethernet-phy@1 {
					reg = <0x1>;
				};
			};
		};
	};
};

/* bluetooth */
&lpuart1 {
	pinctrl-0 = <&lpuart1_pins>, <&bluetooth_pins>;
	pinctrl-names = "default";
	uart-has-rtscts;
	status = "okay";

	bluetooth {
		compatible = "brcm,bcm4345c5";
		clocks = <&osc_32k>;
		clock-names = "lpo";
		/* Murata 1MW module supports max. 3M baud */
		max-speed = <3000000>;
		shutdown-gpios = <&lsio_gpio0 13 GPIO_ACTIVE_HIGH>;
		/* link fixed supplies to avoid fall-back lookup by name */
		vbat-supply = <&v_3_3>;
		vddio-supply = <&v_1_8>;
	};
};

&lsio_gpio1 {
	gpio-line-names = "", "", "", "", "", "", "", "",
			  "", "", "", "CELL_RESET_N", "CELL_PWRKEY", "", "", "",
			  "", "", "", "", "", "", "", "",
			  "", "", "", "", "", "", "", "";
};

&usbotg1 {
	dr_mode = "host";
	vbus-supply = <&vbus1>;
};

/* cellular modem */
&usbotg2 {
	#address-cells = <1>;
	#size-cells = <0>;
	adp-disable;
	disable-over-current;
	dr_mode = "host";
	hnp-disable;
	pinctrl-0 = <&modem_pins>;
	pinctrl-names = "default";
	power-active-high;
	srp-disable;
	vbus-supply = <&v_5_0>;
	status = "okay";

	usb-device@1 {
		compatible = "usb2c7c,125";
		reg = <1>;
		vbus-supply = <&v_3_3>;
		vdd-supply = <&modem_vbat>;
	};
};

&usbphy2 {
	status = "okay";
};

/* WiFi */
&usdhc3 {
	bus-width = <4>;
	cap-sdio-irq;
	mmc-pwrseq = <&usdhc3_pwrseq>;
	non-removable;
	no-sd;
	pinctrl-0 = <&usdhc3_pins>, <&wifi_pins>;
	pinctrl-names = "default";
	vmmc-supply = <&v_3_3>;
	vqmmc-supply = <&v_1_8>;
	status = "okay";
};