// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
 * Copyright (c) Toradex
 *
 * Toradex DSI to LVDS Adapter on Aquila DSI_1 with Capacitive Touch Display 10.1"
 * Used on Development Board (J44), DSI_1 is exposed via a Samtec LSS-130 connector.
 *
 * https://developer.toradex.com/hardware/accessories/displays/capacitive-touch-display-101inch-lvds
 * https://www.toradex.com/accessories/capacitive-touch-display-10.1-inch-lvds
 * https://developer.toradex.com/hardware/accessories/add-ons/dsi-lvds-adapter
 * https://www.toradex.com/accessories/verdin-dsi-to-lvds-adapter
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/pwm/pwm.h>

&{/} {
	backlight_pwm3: backlight-pwm3 {
		compatible = "pwm-backlight";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_19_dsi_1>;
		brightness-levels = <0 45 63 88 119 158 203 255>;
		default-brightness-level = <4>;
		/* Aquila GPIO_19_DSI_1 (AQUILA B44) */
		enable-gpios = <&main_gpio0 13 GPIO_ACTIVE_HIGH>;
		/* Aquila PWM_3_DSI (AQUILA B46) */
		pwms = <&main_ehrpwm5 0 6666667 PWM_POLARITY_INVERTED>;
	};

	panel-lvds-bridge {
		compatible = "logictechno,lt170410-2whc";
		backlight = <&backlight_pwm3>;
		power-supply = <&reg_3v3_dsi>;

		port {
			panel_lvds_bridge_in: endpoint {
				remote-endpoint = <&dsi_lvds_bridge_out>;
			};
		};
	};

	reg_3v3_dsi: regulator-3v3-dsi {
		compatible = "regulator-fixed";
		regulator-max-microvolt = <3300000>;
		regulator-min-microvolt = <3300000>;
		regulator-name = "+V3.3_DSI";
	};
};

&dphy_tx0 {
	status = "okay";
};

&dsi0 {
	status = "okay";
};

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

	port@0 {
		reg = <0>;

		dsi0_out: endpoint {
			remote-endpoint = <&dsi_lvds_bridge_in>;
		};
	};

	port@1 {
		reg = <1>;

		dsi0_in: endpoint {
			remote-endpoint = <&dpi2_out>;
		};
	};
};

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

	port@2 {
		reg = <2>;

		dpi2_out: endpoint {
			remote-endpoint = <&dsi0_in>;
		};
	};
};

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

	bridge@2c {
		compatible = "ti,sn65dsi84";
		reg = <0x2c>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_20_dsi_1>;
		/* Aquila GPIO_20_DSI_1 (AQUILA B45) */
		enable-gpios = <&main_gpio0 18 GPIO_ACTIVE_HIGH>;

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

			port@0 {
				reg = <0>;

				dsi_lvds_bridge_in: endpoint {
					remote-endpoint = <&dsi0_out>;
					data-lanes = <1 2 3 4>;
				};
			};

			port@2 {
				reg = <2>;

				dsi_lvds_bridge_out: endpoint {
					remote-endpoint = <&panel_lvds_bridge_in>;
				};
			};
		};
	};

	touchscreen@4a {
		compatible = "atmel,maxtouch";
		reg = <0x4a>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio_17_dsi_1>, <&pinctrl_gpio_18_dsi_1>;
		/* Aquila GPIO_17_DSI_1 (AQUILA B42) */
		interrupt-parent = <&main_gpio0>;
		interrupts = <12 IRQ_TYPE_EDGE_FALLING>;
		/* Aquila GPIO_18_DSI_1 (AQUILA B43) */
		reset-gpios = <&main_gpio0 31 GPIO_ACTIVE_LOW>;
	};
};