// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
 * Copyright (c) Toradex
 *
 * Toradex DSI to LVDS Adapter on Verdin DSI_1 with Capacitive Touch Display
 * 10.1". Used on Dahlia (X17) and Development Board (X48) that expose DSI_1
 * 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_i2s_2_d_out_dsi_1_bkl_en>;
		brightness-levels = <0 45 63 88 119 158 203 255>;
		default-brightness-level = <4>;
		/* Verdin I2S_2_D_OUT (SODIMM 46) - DSI_1_BKL_EN_LVDS */
		enable-gpios = <&gpio3 24 GPIO_ACTIVE_HIGH>;
		power-supply = <&reg_3p3v>;
		/* Verdin PWM_3_DSI (SODIMM 19) - PWM_3_DSI_LVDS */
		pwms = <&pwm1 0 6666667 PWM_POLARITY_INVERTED>;
	};

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

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

	reg_dsi_lvds: regulator-dsi-lvds {
		compatible = "regulator-fixed";
		/* Verdin CTRL_SLEEP_MOCI# (SODIMM 256) */
		gpios = <&gpio5 1 GPIO_ACTIVE_HIGH>;
		enable-active-high;
		regulator-boot-on;
		regulator-name = "DSI_1_PWR_EN";
	};
};

&atmel_mxt_ts {
	vdd-supply = <&reg_dsi_lvds>;

	status = "okay";
};

&lcdif {
	status = "okay";
};

&lvds_ti_sn65dsi84 {
	vcc-supply = <&reg_dsi_lvds>;

	status = "okay";

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

		port@0 {
			reg = <0>;

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

		port@2 {
			reg = <2>;

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

&mipi_dsi {
	samsung,esc-clock-frequency = <16000000>;

	status = "okay";
};

&mipi_dsi_out {
	remote-endpoint = <&dsi_lvds_bridge_in>;
};