From 10199d3dbd2e7e8deb8b0d9c5c57dc1a9772a2ff Mon Sep 17 00:00:00 2001 From: dengwei1 Date: Wed, 13 Apr 2022 15:57:49 +0800 Subject: [PATCH] tundra: input touch add touch time sysfs Driver will log the last touch down event timestamp and expose it via sysfs. This feature utilized by sensors to mitigate false detection of back tap gestures. Change-Id: I2907acdf1a560a6ca923b9fc20243fef642d7b90 Signed-off-by: dengwei1 Reviewed-on: https://gerrit.mot.com/2241177 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Wang Wang Submit-Approved: Jira Key --- .../touchscreen/goodix_berlin_mmi/Android.mk | 4 +++ .../touchscreen/goodix_berlin_mmi/Kbuild | 4 +++ .../goodix_berlin_mmi/goodix_ts_core.c | 20 ++++++++++- .../goodix_berlin_mmi/goodix_ts_core.h | 6 ++++ .../goodix_berlin_mmi/goodix_ts_mmi.c | 34 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/Android.mk b/drivers/input/touchscreen/goodix_berlin_mmi/Android.mk index 046e0c9cbf00..6a7d2046e665 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/Android.mk +++ b/drivers/input/touchscreen/goodix_berlin_mmi/Android.mk @@ -33,6 +33,10 @@ ifeq ($(TOUCHSCREEN_FOD),true) KBUILD_OPTIONS += CONFIG_GTP_FOD=y endif +ifeq ($(TOUCHSCREEN_LAST_TIME),true) + KBUILD_OPTIONS += CONFIG_GTP_LAST_TIME=y +endif + include $(CLEAR_VARS) LOCAL_MODULE := goodix_brl_mmi.ko LOCAL_MODULE_TAGS := optional diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/Kbuild b/drivers/input/touchscreen/goodix_berlin_mmi/Kbuild index 034c9147719d..6610d5834e62 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/Kbuild +++ b/drivers/input/touchscreen/goodix_berlin_mmi/Kbuild @@ -50,6 +50,10 @@ ifneq ($(filter m y,$(CONFIG_TARGET_BUILD_FACROTY)),) EXTRA_CFLAGS += -DGTP_SAVE_IN_CSV endif +ifneq ($(filter m y,$(CONFIG_GTP_LAST_TIME)),) + EXTRA_CFLAGS += -DCONFIG_GTP_LAST_TIME +endif + ifneq ($(filter m y,$(CONFIG_INPUT_TOUCHSCREEN_MMI)),) EXTRA_CFLAGS += -DCONFIG_INPUT_TOUCHSCREEN_MMI goodix_brl_mmi-objs += goodix_ts_mmi.o diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.c b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.c index c0bece3e719c..876792ec2389 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.c +++ b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.c @@ -1182,8 +1182,13 @@ static void goodix_ts_report_finger(struct input_dev *dev, { unsigned int touch_num = touch_data->touch_num; int i; -#ifdef CONFIG_GTP_FOD +#ifdef CONFIG_GTP_LAST_TIME + static uint8_t touchdown[GOODIX_MAX_TOUCH]; +#endif +#if defined (CONFIG_GTP_FOD) || defined (CONFIG_GTP_LAST_TIME) struct goodix_ts_core *core_data = goodix_modules.core_data; +#endif +#ifdef CONFIG_GTP_FOD struct goodix_ts_event *ts_event = &goodix_modules.core_data ->ts_event; #endif mutex_lock(&dev->mutex); @@ -1193,6 +1198,13 @@ static void goodix_ts_report_finger(struct input_dev *dev, ts_debug("report: id %d, x %d, y %d, w %d", i, touch_data->coords[i].x, touch_data->coords[i].y, touch_data->coords[i].w); +#ifdef CONFIG_GTP_LAST_TIME + if (touchdown[i] == 0) { + core_data->last_event_time = ktime_get(); + ts_debug("TOUCH: [%d] logged timestamp\n", i); + touchdown[i] = 1; + } +#endif input_mt_slot(dev, i); input_mt_report_slot_state(dev, MT_TOOL_FINGER, true); input_report_abs(dev, ABS_MT_POSITION_X, @@ -1202,6 +1214,12 @@ static void goodix_ts_report_finger(struct input_dev *dev, input_report_abs(dev, ABS_MT_TOUCH_MAJOR, touch_data->coords[i].w); } else { +#ifdef CONFIG_GTP_LAST_TIME + if (touchdown[i] == 1) { + ts_debug("TOUCH: [%d] release\n", i); + touchdown[i] = 0; + } +#endif input_mt_slot(dev, i); input_mt_report_slot_state(dev, MT_TOOL_FINGER, false); } diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.h b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.h index 58aa668af501..40d7faec33b4 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.h +++ b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_core.h @@ -27,6 +27,9 @@ #ifdef CONFIG_GTP_ENABLE_PM_QOS #include #endif +#ifdef CONFIG_GTP_LAST_TIME +#include +#endif #define GOODIX_CORE_DRIVER_NAME "goodix_ts" #define GOODIX_PEN_DRIVER_NAME "goodix_ts,pen" @@ -539,6 +542,9 @@ struct goodix_ts_core { unsigned char gesture_type; int zerotap_data[1]; int fod_enable; +#endif +#ifdef CONFIG_GTP_LAST_TIME + ktime_t last_event_time; #endif atomic_t pm_resume; wait_queue_head_t pm_wq; diff --git a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_mmi.c b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_mmi.c index 00db2b0a052c..2875001ea12f 100644 --- a/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_mmi.c +++ b/drivers/input/touchscreen/goodix_berlin_mmi/goodix_ts_mmi.c @@ -43,6 +43,10 @@ static ssize_t goodix_ts_stylus_mode_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t goodix_ts_sensitivity_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size); +#ifdef CONFIG_GTP_LAST_TIME +static ssize_t goodix_ts_timestamp_show(struct device *dev, + struct device_attribute *attr, char *buf); +#endif static DEVICE_ATTR(edge, (S_IRUGO | S_IWUSR | S_IWGRP), goodix_ts_edge_show, goodix_ts_edge_store); @@ -52,6 +56,9 @@ static DEVICE_ATTR(stylus_mode, (S_IRUGO | S_IWUSR | S_IWGRP), goodix_ts_stylus_mode_show, goodix_ts_stylus_mode_store); static DEVICE_ATTR(sensitivity, (S_IRUGO | S_IWUSR | S_IWGRP), NULL, goodix_ts_sensitivity_store); +#ifdef CONFIG_GTP_LAST_TIME +static DEVICE_ATTR(timestamp, S_IRUGO, goodix_ts_timestamp_show, NULL); +#endif /* hal settings */ #define ROTATE_0 0 @@ -98,6 +105,10 @@ static int goodix_ts_mmi_extend_attribute_group(struct device *dev, struct attri if (core_data->board_data.sensitivity_ctrl) ADD_ATTR(sensitivity); +#ifdef CONFIG_GTP_LAST_TIME + ADD_ATTR(timestamp); +#endif + if (idx) { ext_attributes[idx] = NULL; *group = &ext_attr_group; @@ -577,6 +588,29 @@ static ssize_t goodix_ts_edge_show(struct device *dev, core_data->set_mode.edge_mode[1], core_data->set_mode.edge_mode[0]); } +#ifdef CONFIG_GTP_LAST_TIME +static ssize_t goodix_ts_timestamp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct platform_device *pdev; + struct goodix_ts_core *core_data; + ktime_t last_ktime; + struct timespec64 last_ts; + + dev = MMI_DEV_TO_TS_DEV(dev); + GET_GOODIX_DATA(dev); + + mutex_lock(&core_data->mode_lock); + last_ktime = core_data->last_event_time; + core_data->last_event_time = 0; + mutex_unlock(&core_data->mode_lock); + + last_ts = ktime_to_timespec64(last_ktime); + + return scnprintf(buf, PAGE_SIZE, "%lld.%ld\n", last_ts.tv_sec, last_ts.tv_nsec); +} +#endif + static int goodix_ts_mmi_methods_get_vendor(struct device *dev, void *cdata) { return scnprintf(TO_CHARP(cdata), TS_MMI_MAX_VENDOR_LEN, "%s", "goodix"); }