// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/*
 * Copyright (c) Toradex
 *
 * Toradex Capacitive Touch Display 10.1" connected via Verdin AM62 OLDI
 * on carrier boards with a Toradex standard LVDS display connector
 * (e.g., Mallow).
 *
 * https://developer.toradex.com/hardware/accessories/displays/capacitive-touch-display-101inch-lvds
 * https://www.toradex.com/accessories/capacitive-touch-display-10.1-inch-lvds
 */

/dts-v1/;
/plugin/;

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

&{/} {
	backlight_pwm2: backlight-pwm2 {
		compatible = "pwm-backlight";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_i2s_2_d_out_gpio>;
		brightness-levels = <0 45 63 88 119 158 203 255>;
		default-brightness-level = <4>;
		/* Verdin I2S_2_D_OUT as GPIO (SODIMM 46) */
		enable-gpios = <&main_gpio0 34 GPIO_ACTIVE_HIGH>;
		/* Verdin PWM_2 (SODIMM 16) */
		pwms = <&epwm0 1 6666667 PWM_POLARITY_INVERTED>;
	};

	panel-lvds-native {
		compatible = "logictechno,lt170410-2whc";
		backlight = <&backlight_pwm2>;
		power-supply = <&reg_3v3_lvds>;

		port {
			panel_lvds_native_in: endpoint {
				remote-endpoint = <&oldi0_out>;
			};
		};
	};

	reg_3v3_lvds: regulator-3v3-lvds {
		compatible = "regulator-fixed";
		regulator-max-microvolt = <3300000>;
		regulator-min-microvolt = <3300000>;
		regulator-name = "+V3.3_LVDS";
	};
};

&dss {
	status = "okay";
};

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

	/* DSS VP1: internal DPI output to OLDIx */
	port@0 {
		reg = <0>;

		dss0_out: endpoint {
			remote-endpoint = <&oldi0_in>;
		};
	};
};

/* Verdin I2C_2_DSI */
&main_i2c2 {
	#address-cells = <1>;
	#size-cells = <0>;

	touchscreen@4a {
		compatible = "atmel,maxtouch";
		reg = <0x4a>;
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_i2s_2_d_in_gpio>, <&pinctrl_i2s_2_sync_gpio>;
		/* Verdin I2S_2_SYNC as GPIO (SODIMM 44) */
		interrupt-parent = <&main_gpio0>;
		interrupts = <37 IRQ_TYPE_EDGE_FALLING>;
		/* Verdin I2S_2_D_IN as GPIO (SODIMM 48) */
		reset-gpios = <&main_gpio0 33 GPIO_ACTIVE_LOW>;
	};
};

&main_pmx0 {
	/* Mallow Touch RST */
	pinctrl_i2s_2_d_in_gpio: main-gpio0-33-default-pins {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x0088, PIN_INPUT, 7) /* (L24) GPMC0_OEn_REn.GPIO0_33 */ /* SODIMM 48 */
		>;
	};

	/* Mallow Touch INT# */
	pinctrl_i2s_2_sync_gpio: main-gpio0-37-default-pins {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x0098, PIN_INPUT, 7) /* (U23) GPMC0_WAIT0.GPIO0_37 */ /* SODIMM 44 */
		>;
	};
};

&oldi0 {
	status = "okay";
};

&oldi0_port0 {
	oldi0_in: endpoint {
		remote-endpoint = <&dss0_out>;
	};
};

&oldi0_port1 {
	oldi0_out: endpoint {
		remote-endpoint = <&panel_lvds_native_in>;
	};
};