// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
/*
 * Copyright (C) 2023 DH electronics GmbH
 *
 * DHCOM iMX6ULL variant:
 * DHCM-iMX6ULL-C080-R051-F0409-SPI-E2-CAN2-RTC-WBT-ADC-I-01D2
 * DHCOR PCB number: 578-200 or newer
 * DHCOM PCB number: 579-200 or newer
 * PDK2 PCB number: 516-400 or newer
 */
/dts-v1/;

#include "imx6ull-dhcom-som.dtsi"

/ {
	model = "DH electronics i.MX6ULL DHCOM on Premium Developer Kit (2)";
	compatible = "dh,imx6ull-dhcom-pdk2", "dh,imx6ull-dhcom-som",
		     "dh,imx6ull-dhcor-som", "fsl,imx6ull";

	clk_ext_audio_codec: clock-codec {
		compatible = "fixed-clock";
		#clock-cells = <0>;
		clock-frequency = <24000000>;
	};

	display_bl: display-bl {
		compatible = "pwm-backlight";
		brightness-levels = <0 16 22 30 40 55 75 102 138 188 255>;
		default-brightness-level = <8>;
		enable-gpios = <&gpio5 8 GPIO_ACTIVE_HIGH>; /* GPIO G */
		power-supply = <&reg_panel_3v3>;
		pwms = <&pwm1 0 50000 PWM_POLARITY_INVERTED>;
	};

	gpio-keys {
		compatible = "gpio-keys";

		button-0 {
			gpios = <&gpio5 0 GPIO_ACTIVE_LOW>; /* GPIO A */
			label = "TA1-GPIO-A";
			linux,code = <KEY_A>;
			wakeup-source;
		};

		button-1 {
			gpios = <&gpio5 1 GPIO_ACTIVE_LOW>; /* GPIO B */
			label = "TA2-GPIO-B";
			linux,code = <KEY_B>;
			wakeup-source;
		};

		button-2 {
			gpios = <&gpio5 2 GPIO_ACTIVE_LOW>; /* GPIO C */
			label = "TA3-GPIO-C";
			linux,code = <KEY_C>;
			wakeup-source;
		};

		button-3 {
			gpios = <&gpio5 3 GPIO_ACTIVE_LOW>; /* GPIO D */
			label = "TA4-GPIO-D";
			linux,code = <KEY_D>;
			wakeup-source;
		};
	};

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

		/*
		 * Disable PDK2 LED5, because GPIO E is
		 * already used as touch interrupt.
		 */
		led-0 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <5>; /* PDK2 LED5 */
			gpios = <&gpio5 4 GPIO_ACTIVE_HIGH>; /* GPIO E */
			status = "disabled";
		};

		led-1 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <6>; /* PDK2 LED6 */
			gpios = <&gpio5 7 GPIO_ACTIVE_HIGH>; /* GPIO F */
		};

		/*
		 * Disable PDK2 LED7, because GPIO H is
		 * already used for WiFi pin WL_REG_ON.
		 */
		led-2 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <7>; /* PDK2 LED7 */
			gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>; /* GPIO H */
			status = "disabled";
		};

		/*
		 * Disable PDK2 LED8, because GPIO I is
		 * already used for BT pin BT_REG_ON.
		 */
		led-3 {
			color = <LED_COLOR_ID_GREEN>;
			default-state = "off";
			function = LED_FUNCTION_INDICATOR;
			function-enumerator = <8>; /* PDK2 LED8 */
			gpios = <&gpio1 18 GPIO_ACTIVE_HIGH>; /* GPIO I */
			status = "disabled";
		};
	};

	panel {
		compatible = "edt,etm0700g0edh6";
		backlight = <&display_bl>;
		power-supply = <&reg_panel_3v3>;

		port {
			lcd_panel_in: endpoint {
				remote-endpoint = <&lcd_display_out>;
			};
		};
	};

	/* Filtered supply voltage */
	reg_pdk2_24v: regulator-pdk2-24v {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-max-microvolt = <24000000>;
		regulator-min-microvolt = <24000000>;
		regulator-name = "24V_PDK2";
	};

	/* PDK2 U35 */
	reg_pdk2_3v3: regulator-pdk2-3v3 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-name = "3V3_PDK2";
		vin-supply = <&reg_pdk2_24v>;
	};

	/* 560-200 U1 */
	reg_panel_3v3: regulator-panel-3v3 {
		compatible = "regulator-fixed";
		regulator-always-on;
		regulator-min-microvolt = <3300000>;
		regulator-max-microvolt = <3300000>;
		regulator-name = "3V3_PANEL";
		vin-supply = <&reg_pdk2_24v>;
	};

	sound {
		compatible = "simple-audio-card";
		simple-audio-card,bitclock-master = <&dailink_master>;
		simple-audio-card,format = "i2s";
		simple-audio-card,frame-master = <&dailink_master>;
		simple-audio-card,name = "sgtl5000";
		simple-audio-card,routing =
			"MIC_IN", "Mic Jack",
			"Mic Jack", "Mic Bias",
			"LINE_IN", "Line In Jack",
			"Headphone Jack", "HP_OUT";
		simple-audio-card,widgets =
			"Microphone", "Mic Jack",
			"Line", "Line In Jack",
			"Headphone", "Headphone Jack";

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

		dailink_master: simple-audio-card,codec {
			clocks = <&clk_ext_audio_codec>;
			sound-dai = <&sgtl5000>;
		};
	};
};

/* DHCOM I2C1 */
&i2c2 {
	sgtl5000: audio-codec@a {
		compatible = "fsl,sgtl5000";
		reg = <0x0a>;
		#sound-dai-cells = <0>;
		clocks = <&clk_ext_audio_codec>;
		VDDA-supply = <&reg_pdk2_3v3>;
		VDDIO-supply = <&reg_pdk2_3v3>;
	};

	touchscreen@38 {
		compatible = "edt,edt-ft5406";
		reg = <0x38>;
		interrupt-parent = <&gpio5>;
		interrupts = <4 IRQ_TYPE_EDGE_FALLING>; /* GPIO E */
		power-supply = <&reg_panel_3v3>;
	};
};

&lcdif {
	status = "okay";

	port {
		lcd_display_out: endpoint {
			remote-endpoint = <&lcd_panel_in>;
		};
	};
};

&pwm1 {
	status = "okay";
};

&sai2 {
	status = "okay";
};
