tma525c: add delay before releasing touch events

Mitigate the problem that focus window is not ready when we release the
touch events.

Test:
1. Set CPU refrequencies to 1708800, flash local build and then verify
   for 100 times that there's no unregistered swipe found.
2. Set CPU refrequencies to 1363200, flash local build and then verify
   for 100 times that there's no unregistered swipe found.
3. Set CPU refrequencies to 864000, flash local build and then verify
   for 100 times that there's no unregistered swipe found.
4. Set CPU refrequencies to 614400, flash local build and then verify
   for 100 times that there's no unregistered swipe found.

Bug: 325982179
Test: Verified with the 4 conditions above that there's no unregistered
swipe happened.
Change-Id: I888ef184159a850426eea10645f3d54980fe8bf8
Signed-off-by: Simon Wei <jentsewei@google.com>
diff --git a/tma525c/pt_core.c b/tma525c/pt_core.c
index 41dc908..466a946 100644
--- a/tma525c/pt_core.c
+++ b/tma525c/pt_core.c
@@ -41,6 +41,7 @@
 #endif /* PT_PTSBC_SUPPORT */
 
 #define PT_CORE_STARTUP_RETRY_COUNT 3
+#define PT_REPORT_TOUCH_EVENT_DELAY_TIME_MS 80
 
 MODULE_FIRMWARE(PT_FW_FILE_NAME);
 
@@ -48,6 +49,7 @@
 static const char *pt_driver_core_version = PT_DRIVER_VERSION;
 static const char *pt_driver_core_date = PT_DRIVER_DATE;
 struct pt_input_event touch_event_list_head;
+struct workqueue_struct *pt_touch_event_delay_wq;
 
 struct pt_hid_field {
 	int report_count;
@@ -13409,7 +13411,7 @@
 	}
 }
 
-void pt_release_queued_input_event(void)
+void pt_release_queued_input_event(struct work_struct *work)
 {
 	struct pt_input_event *event;
 	struct pt_input_event *next_event;
@@ -17270,7 +17272,9 @@
 	switch (notification->notif_type) {
 	case DRM_PANEL_EVENT_UNBLANK:
 		if (!notification->notif_data.early_trigger) {
-			pt_release_queued_input_event();
+			queue_delayed_work(pt_touch_event_delay_wq,
+					   &core_data->delay_touch_event_work,
+					   msecs_to_jiffies(PT_REPORT_TOUCH_EVENT_DELAY_TIME_MS));
 			pt_touch_display_resume(core_data);
 		}
 		break;
@@ -22618,6 +22622,9 @@
 	nanohub_touch_register_listener(on_mcu_display_state_change,
 					NANOHUB_TOUCH_COMMAND_LISTEN_ON_DISPLAY_STATE);
 	pt_add_core(cd->dev);
+	INIT_DELAYED_WORK(&cd->delay_touch_event_work, pt_release_queued_input_event);
+	pt_touch_event_delay_wq =
+		alloc_workqueue("pt_touch_event_delay_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
 #ifdef PT_PTSBC_SUPPORT
 	/*
 	 * For the PtSBC, on the first bring up, I2C/SPI will not be ready
diff --git a/tma525c/pt_regs.h b/tma525c/pt_regs.h
index d0b54a1..14afe93 100644
--- a/tma525c/pt_regs.h
+++ b/tma525c/pt_regs.h
@@ -1911,6 +1911,7 @@
 	bool hw_detect_enabled;
 #endif
 	ktime_t timestamp; /* time that the event was first received from the touch IC */
+	struct delayed_work delay_touch_event_work;
 };
 
 struct gd_sensor {