input: touchscreen: stm: disable firmware grip for touch_offload

Upon resume, issue command to disable grip suppression when the
filter_grip config flag is clear. Schedule with a 100ms delay during
resume to ensure the command is not missed.

Bug: 143723547
Bug: 139955910
Signed-off-by: Steve Pfetsch <spfetsch@google.com>
Change-Id: I1db9c9053aa45a655b5322153ab4ccd85a47b3b5
diff --git a/fts.c b/fts.c
index ad4ec05..8629758 100644
--- a/fts.c
+++ b/fts.c
@@ -4075,8 +4075,31 @@
 	return 0;
 }
 
+int fts_disable_grip(struct fts_ts_info *info)
+{
+	uint8_t cmd[] = {0xC0, 0x03, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+	int res;
+
+	res = fts_write(cmd, sizeof(cmd));
+	if (res < 0)
+		pr_err("%s: fts_write failed with res=%d.\n", __func__,
+		       res);
+
+	return res;
+}
+
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_OFFLOAD)
 
+static void fts_offload_resume_work(struct work_struct *work)
+{
+	struct delayed_work *dwork = container_of(work, struct delayed_work,
+						  work);
+	struct fts_ts_info *info = container_of(dwork, struct fts_ts_info,
+						offload_resume_work);
+
+	fts_disable_grip(info);
+}
+
 static void fts_populate_coordinate_channel(struct fts_ts_info *info,
 					struct touch_offload_frame *frame,
 					int channel)
@@ -5315,6 +5338,19 @@
 	heatmap_enable();
 #endif
 
+#if IS_ENABLED(CONFIG_TOUCHSCREEN_OFFLOAD)
+	/* Set touch_offload configuration */
+	if (info->offload.offload_running) {
+		pr_info("%s: applying touch_offload settings.\n", __func__);
+		if (!info->offload.config.filter_grip) {
+			/* The grip disable command will not take effect unless
+			 * it is delayed ~100ms.
+			 */
+			schedule_delayed_work(&info->offload_resume_work, 100);
+		}
+	}
+#endif
+
 	fts_enableInterrupt(true);
 
 	complete_all(&info->bus_resumed);
@@ -6276,6 +6312,8 @@
 	info->offload.caps.filter_palm = true;
 	info->offload.caps.num_sensitivity_settings = 1;
 
+	INIT_DELAYED_WORK(&info->offload_resume_work, fts_offload_resume_work);
+
 	info->offload.hcallback = (void *)info;
 	info->offload.report_cb = fts_offload_report;
 	touch_offload_init(&info->offload);
diff --git a/fts.h b/fts.h
index 7db9507..acf52a2 100644
--- a/fts.h
+++ b/fts.h
@@ -420,6 +420,7 @@
 
 #if IS_ENABLED(CONFIG_TOUCHSCREEN_OFFLOAD)
 	struct touch_offload_context offload;
+	struct delayed_work offload_resume_work;
 #endif
 
 	struct delayed_work fwu_work;	/* Work for fw update */