// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/**
 * Lincoln tech Solutions OLDI panel (LCD185-101CT) and touch DT overlay for AM625-BeaglePlay
 *
 * Copyright (C) 2026 Texas Instruments Incorporated - https://www.ti.com/
 */

/dts-v1/;
/plugin/;

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

&{/} {
	backlight: backlight {
		compatible = "pwm-backlight";
		pinctrl-names = "default";
		pinctrl-0 = <&backlight_pins_default>;
		brightness-levels = <0 4 8 16 32 64 128 255>;
		default-brightness-level = <6>;
		enable-gpios = <&main_gpio0 0 GPIO_ACTIVE_HIGH>;
		pwms = <&epwm0 1 20000 0>;
	};

	lcd {
		compatible = "lincolntech,lcd185-101ct";
		backlight = <&backlight>;
		/*
		* Note that the OLDI TX 0 transmits the odd set of pixels
		* while the OLDI TX 1 transmits the even set. This is a
		* fixed configuration in the IP integration and is not
		* changeable. The properties, "dual-lvds-odd-pixels" and
		* "dual-lvds-even-pixels" have been used to merely
		* identify if a Dual Link configuration is required.
		* Swapping them will cause an error in the dss oldi driver.
		*/
		power-supply = <&vsys_5v0>;
		ports {
			#address-cells = <1>;
			#size-cells = <0>;

			port@0 {
				reg = <0>;
				dual-lvds-odd-pixels;
				lcd_in0: endpoint {
					remote-endpoint = <&oldi_0_out>;
				};
			};
			port@1 {
				reg = <1>;
				dual-lvds-even-pixels;
				lcd_in1: endpoint {
					remote-endpoint = <&oldi_1_out>;
				};
			};
		};
	};
};

&main_pmx0 {
	touchscreen_pins_default: touchscreen-default-pins {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x01b4, PIN_OUTPUT, 7) /* (A13) SPI0_CS0.GPIO1_15 */
			AM62X_IOPAD(0x00a0, PIN_INPUT, 7) /* (K25) GPMC0_WPn.GPIO0_39 */
		>;
	};

	backlight_pins_default: bl-default-pins {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x0000, PIN_OUTPUT, 7) /* (H24) OSPI0_CLK.GPIO0_0 */
			AM62X_IOPAD(0x01b8, PIN_OUTPUT, 2) /* (C13) SPI0_CS1.EHRPWM0_B */
		>;
	};
};

&dss {
	status = "okay";
};

&oldi0 {
	status = "okay";
	ti,companion-oldi = <&oldi1>;
};

&oldi1 {
	status = "okay";
	ti,secondary-oldi;
	ti,companion-oldi = <&oldi0>;
};

&oldi0_port0 {
	oldi_0_in: endpoint {
		remote-endpoint = <&dpi0_out0>;
	};
};

&oldi0_port1 {
	oldi_0_out: endpoint {
		remote-endpoint = <&lcd_in0>;
	};
};

&oldi1_port0 {
	oldi_1_in: endpoint {
		remote-endpoint = <&dpi0_out1>;
	};
};

&oldi1_port1 {
	oldi_1_out: endpoint {
		remote-endpoint = <&lcd_in1>;
	};
};

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

	/* VP1: Output to OLDI */
	port@0 {
		reg = <0>;
		#address-cells = <1>;
		#size-cells = <0>;

		dpi0_out0: endpoint@0 {
			reg = <0>;
			remote-endpoint = <&oldi_0_in>;
		};
		dpi0_out1: endpoint@1 {
			reg = <1>;
			remote-endpoint = <&oldi_1_in>;
		};
	};
};

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

	eeprom@57 {
		compatible = "atmel,24c256";
		reg = <0x57>;
	};

	touchscreen@5d {
		compatible = "goodix,gt928";
		reg = <0x5d>;
		pinctrl-names = "default";
		pinctrl-0 = <&touchscreen_pins_default>;
		interrupt-parent = <&main_gpio0>;
		interrupts = <39 IRQ_TYPE_EDGE_FALLING>;
		irq-gpios = <&main_gpio0 39 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&main_gpio1 15 GPIO_ACTIVE_HIGH>;
		touchscreen-size-x = <1920>;
		touchscreen-size-y = <1200>;
	};
};

&epwm0 {
	status = "okay";
};