From 432995c14aa5bc88fcf1fa170cf18411e094cad9 Mon Sep 17 00:00:00 2001
From: Melissa LeBlanc-Williams <melissa@adafruit.com>
Date: Fri, 26 Jan 2024 14:41:42 -0800
Subject: [PATCH 0875/1085] Update touch PiTFT overlays

Expose the invert and swap touch parameters on 2.8" and 3.5" resistive touchscreens. Add
the DRM parameter to the PiTFT 2.2" and 2.8" Capacitive overlay in the same
way it is on the resistive overlays. Change the DRM driver to `adafruit,yx240qv29`
because the rotations are consistent with the FBTFT Driver. Fix the override size parameters
on the 2.8" capacitive PiTFT.

Signed-off-by: Melissa LeBlanc-Williams <melissa@adafruit.com>
---
 arch/arm/boot/dts/overlays/README             |  20 +++
 .../arm/boot/dts/overlays/pitft22-overlay.dts | 102 +++++++-------
 .../overlays/pitft28-capacitive-overlay.dts   | 132 +++++++++---------
 .../overlays/pitft28-resistive-overlay.dts    |  12 +-
 .../overlays/pitft35-resistive-overlay.dts    |  10 +-
 5 files changed, 156 insertions(+), 120 deletions(-)

--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -3532,6 +3532,10 @@ Params: speed                   Display
 
         debug                   Debug output level {0-7}
 
+        drm                     Force the use of the mi0283qt DRM driver (by
+                                default the ili9340 framebuffer driver will
+                                be used in preference if available)
+
 
 Name:   pitft28-capacitive
 Info:   Adafruit PiTFT 2.8" capacitive touch screen
@@ -3544,6 +3548,10 @@ Params: speed                   Display
 
         debug                   Debug output level {0-7}
 
+        drm                     Force the use of the mi0283qt DRM driver (by
+                                default the ili9340 framebuffer driver will
+                                be used in preference if available)
+
         touch-sizex             Touchscreen size x (default 240)
 
         touch-sizey             Touchscreen size y (default 320)
@@ -3570,6 +3578,12 @@ Params: speed                   Display
                                 default the ili9340 framebuffer driver will
                                 be used in preference if available)
 
+        touch-invx              Touchscreen inverted x axis
+
+        touch-invy              Touchscreen inverted y axis
+
+        touch-swapxy            Touchscreen swapped x y axis
+
 
 Name:   pitft35-resistive
 Info:   Adafruit PiTFT 3.5" resistive touch screen
@@ -3586,6 +3600,12 @@ Params: speed                   Display
                                 default the fb_hx8357d framebuffer driver will
                                 be used in preference if available)
 
+        touch-invx              Touchscreen inverted x axis
+
+        touch-invy              Touchscreen inverted y axis
+
+        touch-swapxy            Touchscreen swapped x y axis
+
 
 Name:   pps-gpio
 Info:   Configures the pps-gpio (pulse-per-second time signal via GPIO).
--- a/arch/arm/boot/dts/overlays/pitft22-overlay.dts
+++ b/arch/arm/boot/dts/overlays/pitft22-overlay.dts
@@ -7,63 +7,65 @@
 /plugin/;
 
 / {
-        compatible = "brcm,bcm2835";
+	compatible = "brcm,bcm2835";
 
-        fragment@0 {
-                target = <&spidev0>;
-                __overlay__ {
-                        status = "disabled";
-                };
+	fragment@0 {
+		target = <&spidev0>;
+		__overlay__ {
+			status = "disabled";
+		};
         };
 
-        fragment@1 {
-                target = <&spidev1>;
-                __overlay__ {
-                        status = "disabled";
-                };
-        };
-
-        fragment@2 {
-                target = <&gpio>;
-                __overlay__ {
-                        pitft_pins: pitft_pins {
-                                brcm,pins = <25>;
-                                brcm,function = <1>; /* out */
-                                brcm,pull = <0>; /* none */
-                        };
-                };
-        };
-
-        fragment@3 {
-                target = <&spi0>;
-                __overlay__ {
-                        /* needed to avoid dtc warning */
-                        #address-cells = <1>;
-                        #size-cells = <0>;
-                        status = "okay";
-
-                        pitft: pitft@0{
-                                compatible = "ilitek,ili9340";
-                                reg = <0>;
-                                pinctrl-names = "default";
-                                pinctrl-0 = <&pitft_pins>;
-
-                                spi-max-frequency = <32000000>;
-                                rotate = <90>;
-                                fps = <25>;
-                                bgr;
-                                buswidth = <8>;
-                                dc-gpios = <&gpio 25 0>;
-                                debug = <0>;
-                        };
-
-                };
-        };
-
-        __overrides__ {
-                speed =   <&pitft>,"spi-max-frequency:0";
-                rotate =  <&pitft>,"rotate:0";
-                fps =     <&pitft>,"fps:0";
-                debug =   <&pitft>,"debug:0";
-        };
+	fragment@1 {
+		target = <&spidev1>;
+		__overlay__ {
+			status = "disabled";
+		};
+	};
+
+	fragment@2 {
+		target = <&gpio>;
+		__overlay__ {
+			pitft_pins: pitft_pins {
+				brcm,pins = <25>;
+				brcm,function = <1>; /* out */
+				brcm,pull = <0>; /* none */
+			};
+		};
+	};
+
+	fragment@3 {
+		target = <&spi0>;
+		__overlay__ {
+			/* needed to avoid dtc warning */
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "okay";
+
+			pitft: pitft@0{
+				compatible = "ilitek,ili9340";
+				reg = <0>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&pitft_pins>;
+
+				spi-max-frequency = <32000000>;
+				rotate = <90>;
+				fps = <25>;
+				bgr;
+				buswidth = <8>;
+				dc-gpios = <&gpio 25 0>;
+				debug = <0>;
+			};
+
+		};
+	};
+
+	__overrides__ {
+		speed =   <&pitft>,"spi-max-frequency:0";
+		rotate =  <&pitft>,"rotate:0", /* fbtft */
+				<&pitft>,"rotation:0"; /* drm */
+		fps =     <&pitft>,"fps:0";
+		debug =   <&pitft>,"debug:0";
+		drm =     <&pitft>,"compatible=adafruit,yx240qv29";
+	};
 };
--- a/arch/arm/boot/dts/overlays/pitft28-capacitive-overlay.dts
+++ b/arch/arm/boot/dts/overlays/pitft28-capacitive-overlay.dts
@@ -7,14 +7,14 @@
 /plugin/;
 
 / {
-        compatible = "brcm,bcm2835";
+	compatible = "brcm,bcm2835";
 
-        fragment@0 {
-                target = <&spi0>;
-                __overlay__ {
-                        status = "okay";
-                };
-        };
+	fragment@0 {
+		target = <&spi0>;
+		__overlay__ {
+			status = "okay";
+		};
+	};
 
 	fragment@1 {
 		target = <&spidev0>;
@@ -23,69 +23,71 @@
 		};
 	};
 
-        fragment@2 {
-                target = <&gpio>;
-                __overlay__ {
-                        pitft_pins: pitft_pins {
-                                brcm,pins = <24 25>;
-                                brcm,function = <0 1>; /* in out */
-                                brcm,pull = <2 0>; /* pullup none */
-                        };
-                };
-        };
-
-        fragment@3 {
-                target = <&spi0>;
-                __overlay__ {
-                        /* needed to avoid dtc warning */
-                        #address-cells = <1>;
-                        #size-cells = <0>;
-
-                        pitft: pitft@0{
-                                compatible = "ilitek,ili9340";
-                                reg = <0>;
-                                pinctrl-names = "default";
-                                pinctrl-0 = <&pitft_pins>;
-
-                                spi-max-frequency = <32000000>;
-                                rotate = <90>;
-                                fps = <25>;
-                                bgr;
-                                buswidth = <8>;
-                                dc-gpios = <&gpio 25 0>;
-                                debug = <0>;
-                        };
-                };
-        };
-
-        fragment@4 {
-                target = <&i2c1>;
-                __overlay__ {
-                        /* needed to avoid dtc warning */
-                        #address-cells = <1>;
-                        #size-cells = <0>;
-
-                        ft6236: ft6236@38 {
-                                compatible = "focaltech,ft6236";
-                                reg = <0x38>;
-
-                                interrupt-parent = <&gpio>;
-                                interrupts = <24 2>;
-                                touchscreen-size-x = <240>;
-                                touchscreen-size-y = <320>;
-                        };
-                };
-        };
-
-        __overrides__ {
-                speed =   <&pitft>,"spi-max-frequency:0";
-                rotate =  <&pitft>,"rotate:0";
-                fps =     <&pitft>,"fps:0";
-                debug =   <&pitft>,"debug:0";
-                touch-sizex = <&ft6236>,"touchscreen-size-x?";
-                touch-sizey = <&ft6236>,"touchscreen-size-y?";
-                touch-invx  = <&ft6236>,"touchscreen-inverted-x?";
-                touch-invy  = <&ft6236>,"touchscreen-inverted-y?";
-                touch-swapxy = <&ft6236>,"touchscreen-swapped-x-y?";
-        };
+	fragment@2 {
+		target = <&gpio>;
+		__overlay__ {
+			pitft_pins: pitft_pins {
+				brcm,pins = <24 25>;
+				brcm,function = <0 1>; /* in out */
+				brcm,pull = <2 0>; /* pullup none */
+			};
+		};
+	};
+
+	fragment@3 {
+		target = <&spi0>;
+		__overlay__ {
+			/* needed to avoid dtc warning */
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			pitft: pitft@0{
+				compatible = "ilitek,ili9340";
+				reg = <0>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&pitft_pins>;
+
+				spi-max-frequency = <32000000>;
+				rotate = <90>;
+				fps = <25>;
+				bgr;
+				buswidth = <8>;
+				dc-gpios = <&gpio 25 0>;
+				debug = <0>;
+			};
+		};
+	};
+
+	fragment@4 {
+		target = <&i2c1>;
+		__overlay__ {
+			/* needed to avoid dtc warning */
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			ft6236: ft6236@38 {
+				compatible = "focaltech,ft6236";
+				reg = <0x38>;
+
+				interrupt-parent = <&gpio>;
+				interrupts = <24 2>;
+				touchscreen-size-x = <240>;
+				touchscreen-size-y = <320>;
+			};
+		};
+	};
+
+	__overrides__ {
+		speed =   <&pitft>,"spi-max-frequency:0";
+		rotate =  <&pitft>,"rotate:0", /* fbtft */
+				<&pitft>,"rotation:0"; /* drm */
+		fps =     <&pitft>,"fps:0";
+		debug =   <&pitft>,"debug:0";
+		drm =     <&pitft>,"compatible=adafruit,yx240qv29";
+		touch-sizex = <&ft6236>,"touchscreen-size-x:0";
+		touch-sizey = <&ft6236>,"touchscreen-size-y:0";
+		touch-invx  = <&ft6236>,"touchscreen-inverted-x?";
+		touch-invy  = <&ft6236>,"touchscreen-inverted-y?";
+		touch-swapxy = <&ft6236>,"touchscreen-swapped-x-y?";
+	};
 };
--- a/arch/arm/boot/dts/overlays/pitft28-resistive-overlay.dts
+++ b/arch/arm/boot/dts/overlays/pitft28-resistive-overlay.dts
@@ -49,7 +49,7 @@
 			#size-cells = <0>;
 
 			pitft: pitft@0{
-				compatible = "ilitek,ili9340", "multi-inno,mi0283qt";
+				compatible = "ilitek,ili9340";
 				reg = <0>;
 				pinctrl-names = "default";
 				pinctrl-0 = <&pitft_pins>;
@@ -64,6 +64,9 @@
 			};
 
 			pitft_ts@1 {
+				/* needed to avoid dtc warning */
+				#address-cells = <1>;
+				#interrupt-cells = <1>;
 				compatible = "st,stmpe610";
 				reg = <1>;
 
@@ -72,7 +75,7 @@
 				interrupt-parent = <&gpio>;
 				interrupt-controller;
 
-				stmpe_touchscreen {
+				stmpe_touchscreen: stmpe_touchscreen {
 					compatible = "st,stmpe-ts";
 					st,sample-time = <4>;
 					st,mod-12b = <1>;
@@ -115,6 +118,9 @@
 			  <&pitft>,"rotation:0"; /* drm */
 		fps =     <&pitft>,"fps:0";
 		debug =   <&pitft>,"debug:0";
-		drm =     <&pitft>,"compatible=multi-inno,mi0283qt";
+		drm =     <&pitft>,"compatible=adafruit,yx240qv29";
+		touch-invx  = <&stmpe_touchscreen>,"touchscreen-inverted-x?";
+		touch-invy  = <&stmpe_touchscreen>,"touchscreen-inverted-y?";
+		touch-swapxy = <&stmpe_touchscreen>,"touchscreen-swapped-x-y?";
 	};
 };
--- a/arch/arm/boot/dts/overlays/pitft35-resistive-overlay.dts
+++ b/arch/arm/boot/dts/overlays/pitft35-resistive-overlay.dts
@@ -49,7 +49,7 @@
 			#size-cells = <0>;
 
 			pitft: pitft@0{
-				compatible = "himax,hx8357d", "adafruit,yx350hv15";
+				compatible = "himax,hx8357d";
 				reg = <0>;
 				pinctrl-names = "default";
 				pinctrl-0 = <&pitft_pins>;
@@ -64,6 +64,9 @@
 			};
 
 			pitft_ts@1 {
+				/* needed to avoid dtc warning */
+				#address-cells = <1>;
+				#interrupt-cells = <1>;
 				compatible = "st,stmpe610";
 				reg = <1>;
 
@@ -72,7 +75,7 @@
 				interrupt-parent = <&gpio>;
 				interrupt-controller;
 
-				stmpe_touchscreen {
+				stmpe_touchscreen: stmpe_touchscreen {
 					compatible = "st,stmpe-ts";
 					st,sample-time = <4>;
 					st,mod-12b = <1>;
@@ -117,5 +120,8 @@
 		debug =   <&pitft>,"debug:0";
 		drm =     <&pitft>,"compatible=adafruit,yx350hv15",
 			  <&pitft>,"backlight:0=",<&backlight>;
+		touch-invx  = <&stmpe_touchscreen>,"touchscreen-inverted-x?";
+		touch-invy  = <&stmpe_touchscreen>,"touchscreen-inverted-y?";
+		touch-swapxy = <&stmpe_touchscreen>,"touchscreen-swapped-x-y?";
 	};
 };