// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (c) 2025, Arduino SRL
 */

/dts-v1/;

#include <dt-bindings/leds/common.h>
#include <dt-bindings/usb/pd.h>
#include "agatti.dtsi"
#include "pm4125.dtsi"

/delete-node/ &cont_splash_memory;

/ {
	model = "Arduino UnoQ";
	compatible = "arduino,imola", "qcom,qrb2210", "qcom,qcm2290";
	chassis-type = "embedded";

	aliases {
		serial0 = &uart4;
		serial1 = &uart2;
		serial2 = &uart3;
		sdhc1 = &sdhc_1;
	};

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

	gpio-keys {
		compatible = "gpio-keys";
		label = "gpio-keys";
		pinctrl-0 = <&key_volp_n>, <&key_vold_n>;
		pinctrl-names = "default";

		key-volume-up {
			label = "Volume Up";
			linux,code = <KEY_VOLUMEUP>;
			gpios = <&tlmm 96 GPIO_ACTIVE_LOW>;
			debounce-interval = <15>;
			linux,can-disable;
			wakeup-source;
		};

		key-volume-down {
			label = "Volume Down";
			linux,code = <KEY_VOLUMEDOWN>;
			gpios = <&tlmm 36 GPIO_ACTIVE_LOW>;
			debounce-interval = <15>;
			linux,can-disable;
			wakeup-source;
		};
	};

	leds: leds {
		compatible = "gpio-leds";

		led-bt {
			label = "unoq:bt-blue2";
			function = LED_FUNCTION_BLUETOOTH;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&tlmm 47 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "bluetooth-power";
			default-state = "off";
		};

		led-panic {
			label = "unoq:panic-red2";
			function = LED_FUNCTION_INDICATOR;
			color = <LED_COLOR_ID_RED>;
			gpios = <&tlmm 39 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "none";
			default-state = "off";
			panic-indicator;
		};

		led-wlan {
			label = "unoq:wlan-green2";
			function = LED_FUNCTION_WLAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&tlmm 40 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "phy0tx";
			default-state = "off";
		};

		ledb: led-user-blue {
			label = "unoq:user-blue1";
			gpios = <&tlmm 60 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_BLUE>;
		};

		ledg: led-user-green {
			label = "unoq:user-green1";
			gpios = <&tlmm 42 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_GREEN>;
		};

		ledr: led-user-red {
			label = "unoq:user-red1";
			gpios = <&tlmm 41 GPIO_ACTIVE_HIGH>;
			color = <LED_COLOR_ID_RED>;
		};
	};

	multi-led {
		compatible = "leds-group-multicolor";
		color = <LED_COLOR_ID_RGB>;
		function = LED_FUNCTION_INDICATOR;
		leds = <&ledr>, <&ledg>, <&ledb>;
	};

	vreg_anx_30: regulator-anx-30 {
		compatible = "regulator-fixed";
		regulator-name = "anx30";
		regulator-min-microvolt = <3000000>;
		regulator-max-microvolt = <3000000>;
		regulator-always-on;
		regulator-boot-on;
	};

	/* PM4125 charger out, supplied by VBAT */
	vph_pwr: regulator-vph-pwr {
		compatible = "regulator-fixed";
		regulator-name = "vph_pwr";
		regulator-min-microvolt = <3700000>;
		regulator-max-microvolt = <3700000>;
		regulator-always-on;
		regulator-boot-on;
	};
};

&gpi_dma0 {
	status = "okay";
};

&gpu {
	status = "okay";
};

&gpu_zap_shader {
	firmware-name = "qcom/qcm2290/a702_zap.mbn";
};

&i2c0 {
	clock-frequency = <100000>;

	status = "okay";
};

&i2c1 {
	clock-frequency = <100000>;

	status = "okay";

	anx7625: encoder@58 {
		compatible = "analogix,anx7625";
		reg = <0x58>;
		interrupts-extended = <&tlmm 81 IRQ_TYPE_EDGE_FALLING>;
		vdd10-supply = <&pm4125_l11>;
		vdd18-supply = <&pm4125_l15>;
		vdd33-supply = <&vreg_anx_30>;
		analogix,audio-enable;
		analogix,lane0-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
		analogix,lane1-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;

		pinctrl-0 = <&anx7625_int_pin>, <&anx7625_cable_det_pin>;

		connector {
			compatible = "usb-c-connector";
			power-role = "sink";
			data-role = "dual";
			try-power-role = "sink";

			pd-revision = /bits/ 8 <0x03 0x00 0x00 0x00>;
			op-sink-microwatt = <15000000>;
			sink-pdos = <PDO_FIXED(5000, 3000, PDO_FIXED_USB_COMM)
				     PDO_VAR(5000, 20000, 3000)>;

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

				port@0 {
					reg = <0>;

					anx_hs_in: endpoint {
						remote-endpoint = <&usb_dwc3_hs>;
					};
				};

				port@1 {
					reg = <1>;

					anx_ss_in: endpoint {
						remote-endpoint = <&usb_qmpphy_out>;
					};
				};
			};
		};

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

			port@0 {
				reg = <0>;

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

&mdss {
	status = "okay";
};

&mdss_dsi0 {
	vdda-supply = <&pm4125_l5>;

	status = "okay";
};

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

&mdss_dsi0_phy {
	status = "okay";
};

&pm4125_vbus {
	regulator-min-microvolt = <5000000>;
	regulator-max-microvolt = <5000000>;

	status = "okay";
};

&qupv3_id_0 {
	status = "okay";
};

&remoteproc_adsp {
	firmware-name = "qcom/qcm2290/adsp.mbn";

	status = "okay";
};

&remoteproc_mpss {
	firmware-name = "qcom/qcm2290/modem.mbn";

	status = "okay";
};

&rpm_requests {
	regulators {
		compatible = "qcom,rpm-pm2250-regulators";
		vdd_s3-supply = <&vph_pwr>;
		vdd_s4-supply = <&vph_pwr>;
		vdd_l1_l2_l3_l5_l6_l7_l8_l9_l10_l11_l12-supply = <&pm4125_s3>;
		vdd_l4_l17_l18_l19_l20_l21_l22-supply = <&vph_pwr>;
		vdd_l13_l14_l15_l16-supply = <&pm4125_s4>;

		pm4125_s3: s3 {
			/* 0.4V-1.6625V -> 1.3V (Power tree requirements) */
			regulator-min-microvolt = <1352000>;
			regulator-max-microvolt = <1352000>;
			regulator-boot-on;
		};

		pm4125_s4: s4 {
			/* 1.2V-2.35V -> 2.05V (Power tree requirements) */
			regulator-min-microvolt = <2072000>;
			regulator-max-microvolt = <2072000>;
			regulator-boot-on;
		};

		pm4125_l2: l2 {
			/* LPDDR4X VDD2 */
			regulator-min-microvolt = <1136000>;
			regulator-max-microvolt = <1136000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm4125_l3: l3 {
			/* LPDDR4X VDDQ */
			regulator-min-microvolt = <616000>;
			regulator-max-microvolt = <616000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm4125_l4: l4 {
			/* max = 3.05V -> max = 2.7 to disable 3V signaling (SDHCI2) */
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <2700000>;
			regulator-allow-set-load;
		};

		pm4125_l5: l5 {
			/* CSI/DSI */
			regulator-min-microvolt = <1232000>;
			regulator-max-microvolt = <1232000>;
			regulator-allow-set-load;
			regulator-boot-on;
		};

		pm4125_l6: l6 {
			/* DRAM PLL */
			regulator-min-microvolt = <928000>;
			regulator-max-microvolt = <928000>;
			regulator-always-on;
			regulator-boot-on;
		};

		pm4125_l7: l7 {
			/* Wi-Fi CX */
			regulator-min-microvolt = <664000>;
			regulator-max-microvolt = <664000>;
		};

		pm4125_l10: l10 {
			/* Wi-Fi RFA */
			regulator-min-microvolt = <1304000>;
			regulator-max-microvolt = <1304000>;
		};

		pm4125_l11: l11 {
			/* ANX7625 DVDD1P0V/AVDD1P0V */
			regulator-min-microvolt = <1000000>;
			regulator-max-microvolt = <1000000>;
			regulator-boot-on;
			regulator-always-on;
		};

		pm4125_l12: l12 {
			/* USB PHYs */
			regulator-min-microvolt = <928000>;
			regulator-max-microvolt = <928000>;
			regulator-allow-set-load;
			regulator-boot-on;
		};

		pm4125_l13: l13 {
			/* USB/QFPROM/PLLs */
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
			regulator-boot-on;
		};

		pm4125_l14: l14 {
			/* SDHCI1 EMMC VCCQ */
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
			/* Broken hardware, never turn it off! */
			regulator-always-on;
		};

		pm4125_l15: l15 {
			/* VDDIO */
			regulator-min-microvolt = <1800000>;
			regulator-max-microvolt = <1800000>;
			regulator-allow-set-load;
			regulator-always-on;
			regulator-boot-on;
		};

		pm4125_l20: l20 {
			/* SDHCI1 EMMC */
			regulator-min-microvolt = <2400000>;
			regulator-max-microvolt = <3600000>;
			regulator-allow-set-load;
		};

		pm4125_l21: l21 {
			/* USB HS */
			regulator-min-microvolt = <2960000>;
			regulator-max-microvolt = <3300000>;
			regulator-allow-set-load;
			regulator-boot-on;
		};

		pm4125_l22: l22 {
			/* Wi-Fi VDD */
			regulator-min-microvolt = <3312000>;
			regulator-max-microvolt = <3312000>;
		};
	};
};

&sdhc_1 {
	vmmc-supply = <&pm4125_l20>;
	vqmmc-supply = <&pm4125_l14>;
	pinctrl-0 = <&sdc1_state_on>;
	pinctrl-1 = <&sdc1_state_off>;
	pinctrl-names = "default", "sleep";
	mmc-hs400-1_8v;
	mmc-hs200-1_8v;
	non-removable;
	supports-cqe;
	no-sdio;
	no-sd;

	status = "okay";
};

&spi5 {
	status = "okay";

	mcu@0 {
		compatible = "arduino,unoq-mcu";
		reg = <0>;
	};
};

&tlmm {
	jmisc_gpio18: jmisc-gpio18-state {
		pins = "gpio18";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	jmisc_gpio28: jmisc-gpio28-state {
		pins = "gpio28";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	key_vold_n: key-vold-n-state {
		pins = "gpio36";
		function = "gpio";
		bias-pull-up;
		output-disable;
	};

	anx7625_cable_det_pin: anx7625-cable-det-pins-state {
		pins = "gpio46";
		function = "gpio";
		drive-strength = <16>;
		output-disable;
		bias-pull-up;
	};

	anx7625_int_pin: anx7625-int-pins-state {
		pins = "gpio81";
		function = "gpio";
		drive-strength = <16>;
		output-disable;
		bias-pull-up;
	};

	key_volp_n: key-volp-n-state {
		pins = "gpio96";
		function = "gpio";
		bias-pull-up;
		output-disable;
	};

	jmisc_gpio98: jmisc-gpio98-state {
		pins = "gpio98";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	jmisc_gpio99: jmisc-gpio99-state {
		pins = "gpio99";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	jmisc_gpio100: jmisc-gpio100-state {
		pins = "gpio100";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};

	jmisc_gpio101: jmisc-gpio101-state {
		pins = "gpio101";
		function = "gpio";
		drive-strength = <2>;
		bias-pull-down;
	};
};

&uart2 {
	status = "okay";
};

/* UART connected to Bluetooth */
&uart3 {
	status = "okay";

	bluetooth {
		compatible = "qcom,wcn3988-bt";

		vddio-supply = <&pm4125_l15>;
		vddxo-supply = <&pm4125_l13>;
		vddrf-supply = <&pm4125_l10>;
		vddch0-supply = <&pm4125_l22>;
		enable-gpios = <&tlmm 87 GPIO_ACTIVE_HIGH>;
		max-speed = <3000000>;
	};
};

/* UART exposed in JCTL */
&uart4 {
	compatible = "qcom,geni-debug-uart";

	status = "okay";
};

&usb {
	status = "okay";
};

&usb_dwc3_hs {
	remote-endpoint = <&anx_hs_in>;
};

&usb_hsphy {
	vdd-supply = <&pm4125_l12>;
	vdda-pll-supply = <&pm4125_l13>;
	vdda-phy-dpdm-supply = <&pm4125_l21>;

	status = "okay";
};

&usb_qmpphy {
	vdda-phy-supply = <&pm4125_l12>;
	vdda-pll-supply = <&pm4125_l13>;

	status = "okay";
};

&usb_qmpphy_out {
	remote-endpoint = <&anx_ss_in>;
};

&wifi {
	vdd-0.8-cx-mx-supply = <&pm4125_l7>;
	vdd-1.8-xo-supply = <&pm4125_l13>;
	vdd-1.3-rfa-supply = <&pm4125_l10>;
	vdd-3.3-ch0-supply = <&pm4125_l22>;
	qcom,ath10k-calibration-variant = "ArduinoImola";
	firmware-name = "qcm2290";

	status = "okay";
};

&xo_board {
	clock-frequency = <38400000>;
};