From d0732879a8fe169c58e3ced5d79d4ca1a627b4f0 Mon Sep 17 00:00:00 2001 From: davidycchen Date: Mon, 14 Feb 2022 16:51:30 +0800 Subject: synaptics: support to enable/disable the firmware grip and plam mode Support to enable/disable the firmware grip/palm by sysfs node and dynamically change the mode depending on offload_running status. Bug: 199104316 Test: write sysfs node and check if the mode changing correctly. Signed-off-by: davidycchen Change-Id: I00318352b1146210ed582265f4c82c386f228e4b --- syna_tcm2.c | 40 +++++++- syna_tcm2.h | 2 + syna_tcm2_sysfs.c | 187 ++++++++++++++++++++++++++++++++++++++ tcm/synaptics_touchcom_core_dev.h | 1 + 4 files changed, 229 insertions(+), 1 deletion(-) diff --git a/syna_tcm2.c b/syna_tcm2.c index dc76ddd..584275d 100644 --- a/syna_tcm2.c +++ b/syna_tcm2.c @@ -272,6 +272,32 @@ static void syna_dev_set_heatmap_mode(struct syna_tcm *tcm, bool en) } } +/** + * syna_dev_restore_feature_setting() + * + * Restore the feature settings after the device resume. + * + * @param + * [ in] tcm: tcm driver handle + * + * @return + * on success, 0; otherwise, negative value on error. + */ +static void syna_dev_restore_feature_setting(struct syna_tcm *tcm) +{ + syna_dev_set_heatmap_mode(tcm, true); + + syna_tcm_set_dynamic_config(tcm->tcm_dev, + DC_ENABLE_PALM_REJECTION, + (tcm->enable_fw_palm & 0x01), + RESP_IN_POLLING); + + syna_tcm_set_dynamic_config(tcm->tcm_dev, + DC_ENABLE_GRIP_SUPPRESSION, + (tcm->enable_fw_grip & 0x01), + RESP_IN_POLLING); +} + #ifdef ENABLE_CUSTOM_TOUCH_ENTITY /** * syna_dev_parse_custom_touch_data_cb() @@ -553,6 +579,7 @@ static void syna_dev_report_input_events(struct syna_tcm *tcm) break; case FINGER: case GLOVED_OBJECT: + case PALM: x = object_data[idx].x_pos; y = object_data[idx].y_pos; wx = object_data[idx].x_width; @@ -839,6 +866,13 @@ static void syna_offload_set_running(struct syna_tcm *tcm, bool running) if (tcm->offload.offload_running != running) { tcm->offload.offload_running = running; } + if (tcm->offload.offload_running == tcm->enable_fw_grip && tcm->enable_fw_grip < 2) { + tcm->enable_fw_grip = tcm->offload.offload_running ? 0 : 1; + syna_tcm_set_dynamic_config(tcm->tcm_dev, + DC_ENABLE_GRIP_SUPPRESSION, + tcm->enable_fw_grip, + RESP_IN_POLLING); + } } static void syna_offload_report(void *handle, @@ -1734,7 +1768,7 @@ static int syna_dev_resume(struct device *dev) goto exit; } - syna_dev_set_heatmap_mode(tcm, true); + syna_dev_restore_feature_setting(tcm); retval = 0; @@ -2517,6 +2551,10 @@ static int syna_dev_probe(struct platform_device *pdev) } #endif + tcm->enable_fw_grip = 0x00; + tcm->enable_fw_palm = 0x01; + syna_dev_restore_feature_setting(tcm); + #if defined(USE_DRM_BRIDGE) retval = syna_register_panel_bridge(tcm); #elif defined(ENABLE_DISP_NOTIFIER) diff --git a/syna_tcm2.h b/syna_tcm2.h index 703c65c..08c8765 100644 --- a/syna_tcm2.h +++ b/syna_tcm2.h @@ -453,6 +453,8 @@ struct syna_tcm { s16 *raw_data_buffer; struct completion raw_data_completion; bool high_sensitivity_mode; + u8 enable_fw_grip; + u8 enable_fw_palm; #if defined(USE_DRM_BRIDGE) struct drm_bridge panel_bridge; diff --git a/syna_tcm2_sysfs.c b/syna_tcm2_sysfs.c index a4512c9..c9e535c 100644 --- a/syna_tcm2_sysfs.c +++ b/syna_tcm2_sysfs.c @@ -973,6 +973,191 @@ static struct kobj_attribute kobj_attr_high_sensitivity = __ATTR(high_sensitivity, 0664, syna_sysfs_high_sensitivity_show, syna_sysfs_high_sensitivity_store); +/** + * syna_sysfs_fw_grip_show() + * + * Attribute to show current grip suppression mode. + * + * @param + * [ in] kobj: an instance of kobj + * [ in] attr: an instance of kobj attribute structure + * [out] buf: string buffer shown on console + * + * @return + * on success, number of characters being output; + * otherwise, negative value on error. + */ +static ssize_t syna_sysfs_fw_grip_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int retval = 0; + struct device *p_dev; + struct kobject *p_kobj; + struct syna_tcm *tcm; + + p_kobj = g_sysfs_dir->parent; + p_dev = container_of(p_kobj, struct device, kobj); + tcm = dev_get_drvdata(p_dev); + + syna_pal_mutex_lock(&g_extif_mutex); + + retval = scnprintf(buf, PAGE_SIZE, "%u\n", tcm->enable_fw_grip); + + syna_pal_mutex_unlock(&g_extif_mutex); + return retval; +} + +/** + * syna_sysfs_fw_grip_store() + * + * Attribute to set grip suppression mode. + * 0 - Disable fw grip suppression. + * 1 - Enable fw grip suppression. + * 2 - Force disable fw grip suppression. + * 3 - Force enable fw grip suppression. + * + * @param + * [ in] kobj: an instance of kobj + * [ in] attr: an instance of kobj attribute structure + * [ in] buf: string buffer input + * [ in] count: size of buffer input + * + * @return + * on success, return count; otherwise, return error code + */ +static ssize_t syna_sysfs_fw_grip_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int retval = count; + u8 input; + struct device *p_dev; + struct kobject *p_kobj; + struct syna_tcm *tcm; + + p_kobj = g_sysfs_dir->parent; + p_dev = container_of(p_kobj, struct device, kobj); + tcm = dev_get_drvdata(p_dev); + + if (kstrtou8(buf, 16, &input)) { + LOGE("Invalid input %s", buf); + return -EINVAL; + } + + syna_set_bus_ref(tcm, SYNA_BUS_REF_SYSFS, true); + syna_pal_mutex_lock(&g_extif_mutex); + + tcm->enable_fw_grip = input; + + retval = syna_tcm_set_dynamic_config(tcm->tcm_dev, + DC_ENABLE_GRIP_SUPPRESSION, + (input & 0x01), + RESP_IN_ATTN); + + LOGI("Set fw grip suppression mode %u.\n", tcm->enable_fw_grip); + + retval = count; + + syna_pal_mutex_unlock(&g_extif_mutex); + syna_set_bus_ref(tcm, SYNA_BUS_REF_SYSFS, false); + return retval; +} + +static struct kobj_attribute kobj_attr_fw_grip = + __ATTR(fw_grip, 0664, syna_sysfs_fw_grip_show, + syna_sysfs_fw_grip_store); + +/** + * syna_sysfs_fw_palm_show() + * + * Attribute to show current palm rejection mode. + * + * @param + * [ in] kobj: an instance of kobj + * [ in] attr: an instance of kobj attribute structure + * [out] buf: string buffer shown on console + * + * @return + * on success, number of characters being output; + * otherwise, negative value on error. + */ +static ssize_t syna_sysfs_fw_palm_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int retval = 0; + struct device *p_dev; + struct kobject *p_kobj; + struct syna_tcm *tcm; + + p_kobj = g_sysfs_dir->parent; + p_dev = container_of(p_kobj, struct device, kobj); + tcm = dev_get_drvdata(p_dev); + + syna_pal_mutex_lock(&g_extif_mutex); + + retval = scnprintf(buf, PAGE_SIZE, "%u\n", tcm->enable_fw_palm); + + syna_pal_mutex_unlock(&g_extif_mutex); + return retval; +} + +/** + * syna_sysfs_fw_palm_store() + * + * Attribute to set palm rejection mode. + * 0 - Disable fw palm rejection. + * 1 - Enable fw palm rejection. + * 2 - Force disable fw palm rejection. + * 3 - Force enable fw palm rejection. + * + * @param + * [ in] kobj: an instance of kobj + * [ in] attr: an instance of kobj attribute structure + * [ in] buf: string buffer input + * [ in] count: size of buffer input + * + * @return + * on success, return count; otherwise, return error code + */ +static ssize_t syna_sysfs_fw_palm_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + int retval = count; + u8 input; + struct device *p_dev; + struct kobject *p_kobj; + struct syna_tcm *tcm; + + p_kobj = g_sysfs_dir->parent; + p_dev = container_of(p_kobj, struct device, kobj); + tcm = dev_get_drvdata(p_dev); + + if (kstrtou8(buf, 16, &input)) { + LOGE("Invalid input %s", buf); + return -EINVAL; + } + + syna_set_bus_ref(tcm, SYNA_BUS_REF_SYSFS, true); + syna_pal_mutex_lock(&g_extif_mutex); + + tcm->enable_fw_palm = input; + + retval = syna_tcm_set_dynamic_config(tcm->tcm_dev, + DC_ENABLE_PALM_REJECTION, + (input & 0x01), + RESP_IN_ATTN); + + LOGI("Set fw palm rejection mode %u.\n", tcm->enable_fw_palm); + + retval = count; + + syna_pal_mutex_unlock(&g_extif_mutex); + syna_set_bus_ref(tcm, SYNA_BUS_REF_SYSFS, false); + return retval; +} + +static struct kobj_attribute kobj_attr_fw_palm = + __ATTR(fw_palm, 0664, syna_sysfs_fw_palm_show, + syna_sysfs_fw_palm_store); /** * declaration of sysfs attributes @@ -985,6 +1170,8 @@ static struct attribute *attrs[] = { &kobj_attr_force_active.attr, &kobj_attr_get_raw_data.attr, &kobj_attr_high_sensitivity.attr, + &kobj_attr_fw_grip.attr, + &kobj_attr_fw_palm.attr, NULL, }; diff --git a/tcm/synaptics_touchcom_core_dev.h b/tcm/synaptics_touchcom_core_dev.h index 204357f..700a340 100644 --- a/tcm/synaptics_touchcom_core_dev.h +++ b/tcm/synaptics_touchcom_core_dev.h @@ -209,6 +209,7 @@ enum dynamic_tcm_config_id { DC_DISABLE_PROXIMITY = 0x10, DC_HIGH_SENSITIVIRY_MODE = 0xCB, DC_FORCE_DOZE_MODE = 0xF0, + DC_ENABLE_PALM_REJECTION = 0xF3, }; /** -- cgit v1.2.3