// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
 */

/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h>

#include "monaco-monza-som.dtsi"

/ {
	model = "Arduino VENTUNO Q";
	compatible = "arduino,monza", "qcom,qcs8300";

	aliases {
		ethernet0 = &ethernet0;
		i2c1 = &i2c1;
		serial0 = &uart7;
		serial1 = &uart10;
	};

	chosen {
		stdout-path = "serial0:115200n8";
	};

	gpio-keys {
		compatible = "gpio-keys";
		pinctrl-0 = <&gpio_keys_default>;
		pinctrl-names = "default";

		button-sleep {
			label = "Sleep Key";
			linux,code = <KEY_SLEEP>;
			gpios = <&tlmm 69 GPIO_ACTIVE_HIGH>;
			debounce-interval = <60>;
			wakeup-source;
		};

		button-home {
			label = "Home Key";
			linux,code = <KEY_HOMEPAGE>;
			gpios = <&tlmm 79 GPIO_ACTIVE_LOW>;
			debounce-interval = <60>;
		};
	};

	hdmi-connector {
		compatible = "hdmi-connector";
		label = "hdmi";
		type = "a";

		port {
			hdmi_connector_in: endpoint {
				remote-endpoint = <&adv7535_out>;
			};
		};
	};

	sound {
		compatible = "qcom,qcs8275-sndcard";
		model = "arduino-monza";
		audio-routing = "IN12",  "Headset Mic12",
				"Headset Mic12",  "MICBIAS",
				"IN56",  "Headset Mic56",
				"Headset Mic56",  "MICBIAS",
				"MIC1",  "MICBIAS",
				"Headphone",  "HPL",
				"Headphone",  "HPR",
				"Receiver",  "RCVL",
				"Receiver",  "RCVR",
				"Speaker",  "SPKL",
				"Speaker",  "SPKR";

		pinctrl-0 = <&quad_mi2s_active>, <&quad_mclk_active>,  <&lpi_i2s4_active>;
		pinctrl-names = "default";

		pri-i2s-playback-dai-link {
			link-name = "Analog Playback";

			codec {
				sound-dai = <&max98091>;
			};

			cpu {
				sound-dai = <&q6apmbedai 137>;
			};

			platform {
				sound-dai = <&q6apm>;
			};
		};

		pri-i2s-capture-dai-link {
			link-name = "Analog Capture";

			codec {
				sound-dai = <&max98091>;
			};

			cpu {
				sound-dai = <&q6apmbedai 138>;
			};

			platform {
				sound-dai = <&q6apm>;
			};
		};

		hdmi-mi2s-playback-dai-link {
			link-name = "HDMI Playback";

			codec {
				sound-dai = <&adv7535>;
			};

			cpu {
				sound-dai = <&q6apmbedai 145>;
			};

			platform {
				sound-dai = <&q6apm>;
			};
		};

		displayport-0-dai-link {
			link-name = "DisplayPort0 Playback";

			codec {
				sound-dai = <&mdss_dp0>;
			};

			cpu {
				sound-dai = <&q6apmbedai DISPLAY_PORT_RX_0>;
			};

			platform {
				sound-dai = <&q6apm>;
			};
		};
	};

	vdc_3v3: regulator-3v3 {
		compatible = "regulator-fixed";
		regulator-name = "vdc_3v3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
	};

	vdc_1v8: regulator-1v8 {
		compatible = "regulator-fixed";
		regulator-name = "vdc_1v8";
		regulator-min-microvolt = <1800000>;
		regulator-max-microvolt = <1800000>;
	};

	vdc_5v: regulator-5v0 {
		compatible = "regulator-fixed";
		regulator-name = "vdc_5v";
		regulator-min-microvolt = <5000000>;
		regulator-max-microvolt = <5000000>;
		gpio = <&tlmm 49 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		regulator-always-on;
		startup-delay-us = <20000>;
	};

	vreg_nvme: regulator-3p3-m2 {
		compatible = "regulator-fixed";
		regulator-name = "vreg_m2_3p3";
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		gpio = <&tlmm 51 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		startup-delay-us = <20000>;
	};
};

&cci1 {
	status = "okay";
};

&cci1_i2c1 {
	led-controller@22 {
		compatible = "nxp,pca9635";
		reg = <0x22>;
		#address-cells = <1>;
		#size-cells = <0>;

		multi-led@0 {
			reg = <0>;
			color = <LED_COLOR_ID_RGB>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			led@0 {
				reg = <0>;
				color = <LED_COLOR_ID_RED>;
			};

			led@1 {
				reg = <1>;
				color = <LED_COLOR_ID_GREEN>;
			};

			led@2 {
				reg = <2>;
				color = <LED_COLOR_ID_BLUE>;
			};
		};

		multi-led@1 {
			reg = <1>;
			color = <LED_COLOR_ID_RGB>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <2>;
			#address-cells = <1>;
			#size-cells = <0>;

			led@3 {
				reg = <3>;
				color = <LED_COLOR_ID_RED>;
			};

			led@4 {
				reg = <4>;
				color = <LED_COLOR_ID_GREEN>;
			};

			led@5 {
				reg = <5>;
				color = <LED_COLOR_ID_BLUE>;
			};
		};

		multi-led@2 {
			reg = <2>;
			color = <LED_COLOR_ID_RGB>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <3>;
			#address-cells = <1>;
			#size-cells = <0>;

			led@6 {
				reg = <6>;
				color = <LED_COLOR_ID_RED>;
			};

			led@7 {
				reg = <7>;
				color = <LED_COLOR_ID_GREEN>;
			};

			led@8 {
				reg = <8>;
				color = <LED_COLOR_ID_BLUE>;
			};
		};

		multi-led@3 {
			reg = <3>;
			color = <LED_COLOR_ID_RGB>;
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <4>;
			#address-cells = <1>;
			#size-cells = <0>;

			led@9 {
				reg = <9>;
				color = <LED_COLOR_ID_RED>;
			};

			led@a {
				reg = <10>;
				color = <LED_COLOR_ID_GREEN>;
			};

			led@b {
				reg = <11>;
				color = <LED_COLOR_ID_BLUE>;
			};
		};
	};

	fan_controller: fan-controller@2f {
		compatible = "microchip,emc2305";
		reg = <0x2f>;
		#address-cells = <1>;
		#size-cells = <0>;
		#pwm-cells = <3>;

		fan: fan@0 {
			reg = <0x0>;
			pwms = <&fan_controller 26000 PWM_POLARITY_INVERTED 1>;
			#cooling-cells = <2>;
		};
	};
};

&ethernet0 {
	phy-mode = "2500base-x";
	phy-handle = <&hsgmii_phy0>;

	pinctrl-0 = <&ethernet0_default>;
	pinctrl-names = "default";

	snps,mtl-rx-config = <&mtl_rx_setup>;
	snps,mtl-tx-config = <&mtl_tx_setup>;

	status = "okay";

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

		hsgmii_phy0: ethernet-phy@1c {
			compatible = "ethernet-phy-id004d.d101";
			reg = <0x1c>;
			reset-gpios = <&tlmm 50 GPIO_ACTIVE_LOW>;
			reset-assert-us = <11000>;
			reset-deassert-us = <70000>;
		};
	};

	mtl_rx_setup: rx-queues-config {
		snps,rx-queues-to-use = <4>;
		snps,rx-sched-sp;

		queue0 {
			snps,dcb-algorithm;
			snps,map-to-dma-channel = <0x0>;
			snps,route-up;
			snps,priority = <0x1>;
		};

		queue1 {
			snps,dcb-algorithm;
			snps,map-to-dma-channel = <0x1>;
			snps,route-ptp;
		};

		queue2 {
			snps,avb-algorithm;
			snps,map-to-dma-channel = <0x2>;
			snps,route-avcp;
		};

		queue3 {
			snps,avb-algorithm;
			snps,map-to-dma-channel = <0x3>;
			snps,priority = <0xc>;
		};
	};

	mtl_tx_setup: tx-queues-config {
		snps,tx-queues-to-use = <4>;

		queue0 {
			snps,dcb-algorithm;
		};

		queue1 {
			snps,dcb-algorithm;
		};

		queue2 {
			snps,avb-algorithm;
			snps,send_slope = <0x1000>;
			snps,idle_slope = <0x1000>;
			snps,high_credit = <0x3e800>;
			snps,low_credit = <0xffc18000>;
		};

		queue3 {
			snps,avb-algorithm;
			snps,send_slope = <0x1000>;
			snps,idle_slope = <0x1000>;
			snps,high_credit = <0x3e800>;
			snps,low_credit = <0xffc18000>;
		};
	};
};

&i2c12 {
	clock-frequency = <400000>;

	status = "okay";

	typec@8 {
		compatible = "cypress,cypd4226";
		reg = <0x08>;
		pinctrl-0 = <&typec_default_state>;
		pinctrl-names = "default";
		interrupts-extended = <&tlmm 3 IRQ_TYPE_LEVEL_LOW>;

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

		connector@0 {
			compatible = "usb-c-connector";
			reg = <0>;
			label = "USB-C";
			data-role = "dual";
			power-role = "dual";

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

				port@0 {
					reg = <0>;

					ucsi_hs_ccg_p0: endpoint {
						remote-endpoint = <&usb_1_dwc3_hs>;
					};
				};

				port@1 {
					reg = <1>;

					ucsi_ss_ccg_p0: endpoint {
						remote-endpoint = <&usb_1_dwc3_ss>;
					};
				};
			};
		};
	};

	max98091: audio-codec@10 {
		compatible = "maxim,max98091";
		reg = <0x10>;
		pinctrl-0 = <&max98091_default>;
		pinctrl-names = "default";
		interrupts-extended = <&tlmm 16 IRQ_TYPE_LEVEL_HIGH>; /* GPIO_16 */
		clocks = <&q6prmcc LPASS_CLK_ID_MCLK_3 LPASS_CLK_ATTRIBUTE_COUPLE_NO>;
		clock-names = "mclk";
		#sound-dai-cells = <0>;
	};

	adv7535: bridge@3d {
		compatible = "adi,adv7535";
		reg = <0x3d>;
		pinctrl-0 = <&adv7535_default>;
		pinctrl-names = "default";
		interrupts-extended = <&tlmm 93 IRQ_TYPE_EDGE_FALLING>;
		avdd-supply = <&vdc_1v8>;
		dvdd-supply = <&vdc_1v8>;
		pvdd-supply = <&vdc_1v8>;
		a2vdd-supply = <&vdc_1v8>;
		v3p3-supply = <&vdc_3v3>;
		v1p2-supply = <&vdc_1v8>;
		adi,dsi-lanes = <4>;
		#sound-dai-cells = <0>;

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

			port@0 {
				reg = <0>;
				adv7535_in: endpoint {
					remote-endpoint = <&mdss_dsi0_out>;
				};
			};

			port@1 {
				reg = <1>;
				adv7535_out: endpoint {
					remote-endpoint = <&hdmi_connector_in>;
				};
			};
		};
	};

	power-sensor@40 {
		compatible = "ti,ina232";
		reg = <0x40>;
		shunt-resistor = <2000>;
	};
};

&mdss {
	status = "okay";
};

&mdss_dp0 {
	status = "okay";
};

&mdss_dp0_out {
	data-lanes = <0 1 2 3>;
	link-frequencies = /bits/ 64 <1620000000 2700000000 5400000000 8100000000>;
};

&mdss_dp0_phy {
	status = "okay";
};

&mdss_dsi0 {
	status = "okay";
};

&mdss_dsi0_out {
	remote-endpoint = <&adv7535_in>;
	data-lanes = <0 1 2 3>;
};

&mdss_dsi0_phy {
	status = "okay";
};

&pcie0 {
	pinctrl-0 = <&pcie0_default_state>;
	pinctrl-names = "default";

	vddpe-3v3-supply = <&vdc_3v3>;
};

&pcie1 {
	pinctrl-0 = <&pcie1_default_state>;
	pinctrl-names = "default";

	vddpe-3v3-supply = <&vreg_nvme>;
};

&pcieport0 {
	reset-gpios = <&tlmm 2 GPIO_ACTIVE_LOW>;

	pcie@0,0 {
		#address-cells = <3>;
		#size-cells = <2>;
		device_type = "pci";
		bus-range = <0x01 0xff>;
		ranges;
		reg = <0x010000 0x00 0x00 0x00 0x00>;

		pcie@2,0 {
			#address-cells = <3>;
			#size-cells = <2>;
			device_type = "pci";
			bus-range = <0x00 0xff>;
			ranges;
			reg = <0x021000 0x00 0x00 0x00 0x00>;

			usb@0 {
				compatible = "pci104c,8241";
				reg = <0 0 0 0 0>;
				ti,pwron-active-high;
			};
		};
	};
};

&pcieport1 {
	reset-gpios = <&tlmm 23 GPIO_ACTIVE_LOW>;
};

&thermal_zones {
	cpuss-0-0-thermal {
		trips {
			cpuss0_active0: cpuss-active0 {
				temperature = <50000>;
				hysteresis = <4000>;
				type = "active";
			};

			cpuss0_active1: cpuss-active1 {
				temperature = <60000>;
				hysteresis = <4000>;
				type = "active";
			};

			cpuss0_active2: cpuss-active2 {
				temperature = <70000>;
				hysteresis = <4000>;
				type = "active";
			};

			cpuss0_active3: cpuss-active3 {
				temperature = <80000>;
				hysteresis = <4000>;
				type = "active";
			};
		};

		cooling-maps {
			map-active0 {
				trip = <&cpuss0_active0>;
				cooling-device = <&fan 4 4>;
			};

			map-active1 {
				trip = <&cpuss0_active1>;
				cooling-device = <&fan 6 6>;
			};

			map-active2 {
				trip = <&cpuss0_active2>;
				cooling-device = <&fan 8 8>;
			};

			map-active3 {
				trip = <&cpuss0_active3>;
				cooling-device = <&fan 10 THERMAL_NO_LIMIT>;
			};
		};
	};
};

&tlmm {
	gpio-line-names = "", "", "", "", "",
			  "", "", "", "", "",
			  "JMISC_SPI_MISO", "JMISC_SPI_MOSI", "JMISC_SPI_SCK", "JMISC_SPI_CS0", "JMISC_SPI_CS1",
			  "JMISC_CS2", "", "JHAT_P03_I2C_SDA", "JHAT_P05_I2C_SCL", "JHAT_P27_EEPROM_SDA",
			  "JHAT_P28_EEPROM_SDL", "", "", "", "",
			  "JHAT_P21_SPI_MISO", "JHAT_P19_SPI_MOSI", "JHAT_P23_SPI_SCLK", "JHAT_P24_SPI_CE0", "",
			  "", "MCU_I2C1_SDA", "MCU_I2C1_SDL", "", "",
			  "", "", "JOMEGA_SPI_SCK", "JOMEGA_SPI_CS", "JOMEGA_SPI_MISO",
			  "JOMEGA_SPI_MOSI", "", "MCU_PG11", "JCTL_UART_DBG_TX", "JCTL_UART_DBG_RX",
			  "", "", "MCU_BOOT0", "CYPD_SWCLK", "",
			  "", "", "FORCE_USB_BOOT", "", "",
			  "", "", "JMEDIA_SOC_CC0_SDA", "JMEDIA_SOC_CC0_SCL", "JMEDIA_SOC_CC1_SDA",
			  "JMEDIA_SOC_CC1_SCL", "", "", "MCU_PG12", "",
			  "FLAT0_P17_GPIO", "", "JMEDIA_SOC_CAM_MCLK0", "JMEDIA_SOC_CAM_MCLK1", "MCU_PG9",
			  "MCU_PA13_SWDIO", "MCU_PA14_SWCLK", "", "JMISC_SOC_GPIO_0", "JMISC_SOC_GPIO_1",
			  "FLAT1_P17_GPIO", "", "JHAT_P32_PWM0", "MCU_NRST", "USER_BUTTON",
			  "JHAT_P31_GPIO", "JHAT_P33_GPIO",  "FLAT2_P17_GPIO", "JHAT_P07_GPCLK0", "JHAT_P36_UART_CTS",
			  "JHAT_P11_UART_RFR", "JHAT_P08_UART_TX", "JHAT_P10_UART_RX", "JHAT_P26_SPI_CE1", "JHAT_P29_GPIO",
			  "JHAT_P15_GPIO", "", "MCU_PG10", "", "CYPD_SWDIO",
			  "MCU_PG13", "MCU_PG14", "", "", "",
			  "", "", "", "", "CYPD_NRES",
			  "JHAT_P16_GPIO", "JHAT_P18_GPIO", "JHAT_P22_GPIO", "JHAT_P37_GPIO", "JHAT_P13_GPIO",
			  "", "", "", "", "",
			  "", "JHAT_P12_PCM_CLK", "JHAT_P35_PCM_FS", "JHAT_P38_PCM_DIN", "JHAT_P40_PCM_DOUT",
			  "", "", "", "", "",
			  "", "", "", "", "",
			  "", "", "";

	pcie0_default_state: pcie0-default-state {
		wake-pins {
			pins = "gpio0";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};

		clkreq-pins {
			pins = "gpio1";
			function = "pcie0_clkreq";
			drive-strength = <2>;
			bias-pull-up;
		};

		perst-pins {
			pins = "gpio2";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};
	};

	typec_default_state: typec-default-state {
		pins = "gpio3";
		function = "gpio";
		bias-disable;
	};

	ethernet0_default: ethernet0-default-state {
		ethernet0_mdc: ethernet0-mdc-pins {
			pins = "gpio5";
			function = "emac0_mdc";
			drive-strength = <16>;
			bias-pull-up;
		};

		ethernet0_mdio: ethernet0-mdio-pins {
			pins = "gpio6";
			function = "emac0_mdio";
			drive-strength = <16>;
			bias-pull-up;
		};
	};

	max98091_default: max98091-default-state {
		pins = "gpio16";
		function = "gpio";
		bias-pull-up;
	};

	pcie1_default_state: pcie1-default-state {
		wake-pins {
			pins = "gpio21";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};

		clkreq-pins {
			pins = "gpio22";
			function = "pcie1_clkreq";
			drive-strength = <2>;
			bias-pull-up;
		};

		perst-pins {
			pins = "gpio23";
			function = "gpio";
			drive-strength = <2>;
			bias-pull-up;
		};
	};

	gpio_keys_default: gpio-keys-default-state {
		horizontal-button-pins {
			pins = "gpio69";
			function = "gpio";
			bias-pull-down;
		};

		vertical-button-pins {
			pins = "gpio79";
			function = "gpio";
			bias-disable;
		};
	};

	adv7535_default: adv7535-default-state {
		pins = "gpio93";
		function = "gpio";
		bias-pull-up;
	};
};

&uart7 {
	status = "okay";
};

&uart10 {
	status = "okay";

	bluetooth: bluetooth {
		compatible = "qcom,qca2066-bt";
		enable-gpios = <&tlmm 55 GPIO_ACTIVE_HIGH>;
		clocks = <&sleep_clk>;
	};
};

&usb_1 {
	status = "okay";
};

&usb_1_dwc3_hs {
	remote-endpoint = <&ucsi_hs_ccg_p0>;
};

&usb_1_dwc3_ss {
	remote-endpoint = <&ucsi_ss_ccg_p0>;
};

/* Internally connected to the MCU (e.g. for DFU). */
&usb_2 {
	dr_mode = "host";

	status = "okay";
};