diff options
author | Wendly Li <wendlyli@google.com> | 2023-02-18 11:52:18 +0000 |
---|---|---|
committer | Wendly Li <wendlyli@google.com> | 2023-03-08 10:15:40 +0000 |
commit | 627ba2d292693075128e50f9c385d0873906dcfc (patch) | |
tree | affdd7018fc42f16ca617632f0b9bb76f459b448 | |
parent | a04472525a4aae588e6894246d50304923fbcc76 (diff) | |
download | common-627ba2d292693075128e50f9c385d0873906dcfc.tar.gz |
touch/gti: Add coordinate filter
Bug: 269560488
Test: Check fw_coord_filter works properly
Change-Id: I7fc4113a2ecf100d786c0dff856e9334c584fc84
Signed-off-by: Wendly Li <wendlyli@google.com>
-rw-r--r-- | goog_touch_interface.c | 128 | ||||
-rw-r--r-- | goog_touch_interface.h | 31 |
2 files changed, 153 insertions, 6 deletions
diff --git a/goog_touch_interface.c b/goog_touch_interface.c index 697dcdb..bfd044c 100644 --- a/goog_touch_interface.c +++ b/goog_touch_interface.c @@ -332,6 +332,10 @@ static ssize_t force_active_show( struct device *dev, struct device_attribute *attr, char *buf); static ssize_t force_active_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size); +static ssize_t fw_coord_filter_show(struct device *dev, + struct device_attribute *attr, char *buf); +static ssize_t fw_coord_filter_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size); static ssize_t fw_grip_show(struct device *dev, struct device_attribute *attr, char *buf); static ssize_t fw_grip_store(struct device *dev, @@ -384,6 +388,7 @@ static ssize_t vrr_enabled_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size); static DEVICE_ATTR_RW(force_active); +static DEVICE_ATTR_RW(fw_coord_filter); static DEVICE_ATTR_RW(fw_grip); static DEVICE_ATTR_RW(fw_palm); static DEVICE_ATTR_RO(fw_ver); @@ -401,6 +406,7 @@ static DEVICE_ATTR_RW(vrr_enabled); static struct attribute *goog_attributes[] = { &dev_attr_force_active.attr, + &dev_attr_fw_coord_filter.attr, &dev_attr_fw_grip.attr, &dev_attr_fw_palm.attr, &dev_attr_fw_ver.attr, @@ -485,6 +491,70 @@ static ssize_t force_active_store(struct device *dev, return size; } +static ssize_t fw_coord_filter_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int ret = 0; + ssize_t buf_idx = 0; + struct goog_touch_interface *gti = dev_get_drvdata(dev); + struct gti_coord_filter_cmd *cmd = >i->cmd.coord_filter_cmd; + + if (!gti->coord_filter_enabled) { + buf_idx += scnprintf(buf + buf_idx, PAGE_SIZE - buf_idx, + "error: not supported!\n"); + GOOG_INFO(gti, "%s", buf); + return buf_idx; + } + + cmd->setting = GTI_COORD_FILTER_DISABLE; + ret = goog_process_vendor_cmd(gti, GTI_CMD_GET_COORD_FILTER_ENABLED); + if (ret == -EOPNOTSUPP) { + buf_idx += scnprintf(buf + buf_idx, PAGE_SIZE - buf_idx, + "error: not supported!\n"); + } else if (ret) { + buf_idx += scnprintf(buf + buf_idx, PAGE_SIZE - buf_idx, + "error: %d!\n", ret); + } else { + buf_idx += scnprintf(buf + buf_idx, PAGE_SIZE - buf_idx, + "result: %u\n", cmd->setting | (gti->ignore_coord_filter_update << 1)); + } + GOOG_INFO(gti, "%s", buf); + + return buf_idx; +} + +static ssize_t fw_coord_filter_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = 0; + struct goog_touch_interface *gti = dev_get_drvdata(dev); + int fw_coord_filter; + + if (kstrtou32(buf, 10, &fw_coord_filter)) { + GOOG_INFO(gti, "error: invalid input!\n"); + return -EINVAL; + } + + if (!gti->coord_filter_enabled) { + GOOG_INFO(gti, "error: not supported!\n"); + return -EOPNOTSUPP; + } + + gti->fw_coord_filter_enabled = fw_coord_filter & 0x01; + gti->ignore_coord_filter_update = (fw_coord_filter >> 1) & 0x01; + gti->cmd.coord_filter_cmd.setting = gti->fw_coord_filter_enabled ? + GTI_COORD_FILTER_ENABLE : GTI_COORD_FILTER_DISABLE; + ret = goog_process_vendor_cmd(gti, GTI_CMD_SET_COORD_FILTER_ENABLED); + if (ret == -EOPNOTSUPP) + GOOG_INFO(gti, "error: not supported!\n"); + else if (ret) + GOOG_INFO(gti, "error: %d!\n", ret); + else + GOOG_INFO(gti, "fw_coord_filter= %u\n", fw_coord_filter); + + return size; +} + static ssize_t fw_grip_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1500,6 +1570,10 @@ int goog_process_vendor_cmd(struct goog_touch_interface *gti, enum gti_cmd_type case GTI_CMD_GET_CONTEXT_STYLUS: ret = gti->options.get_context_stylus(private_data, >i->cmd.context_stylus_cmd); break; + case GTI_CMD_GET_COORD_FILTER_ENABLED: + ret = gti->options.get_coord_filter_enabled(private_data, + >i->cmd.coord_filter_cmd); + break; case GTI_CMD_GET_FW_VERSION: ret = gti->options.get_fw_version(private_data, >i->cmd.fw_version_cmd); break; @@ -1552,6 +1626,10 @@ int goog_process_vendor_cmd(struct goog_touch_interface *gti, enum gti_cmd_type ret = gti->options.set_continuous_report(private_data, >i->cmd.continuous_report_cmd); break; + case GTI_CMD_SET_COORD_FILTER_ENABLED: + ret = gti->options.set_coord_filter_enabled(private_data, + >i->cmd.coord_filter_cmd); + break; case GTI_CMD_SET_GRIP_MODE: GOOG_INFO(gti, "Set firmware grip %s", gti->cmd.grip_cmd.setting == GTI_GRIP_ENABLE ? @@ -1975,6 +2053,8 @@ void goog_offload_populate_frame(struct goog_touch_interface *gti, void goog_update_fw_settings(struct goog_touch_interface *gti) { int ret = 0; + bool enabled = false; + if(!gti->ignore_grip_update) { if (gti->offload.offload_running && gti->offload.config.filter_grip) gti->cmd.grip_cmd.setting = GTI_GRIP_DISABLE; @@ -1995,6 +2075,23 @@ void goog_update_fw_settings(struct goog_touch_interface *gti) GOOG_WARN(gti, "unexpected return(%d)!", ret); } + if (gti->coord_filter_enabled) { + if (!gti->ignore_coord_filter_update) { + if (gti->offload.offload_running && gti->offload.config.coord_filter) + enabled = false; + else + enabled = gti->default_coord_filter_enabled; + } else { + enabled = gti->fw_coord_filter_enabled; + } + + gti->cmd.coord_filter_cmd.setting = enabled ? + GTI_COORD_FILTER_ENABLE : GTI_COORD_FILTER_DISABLE; + ret = goog_process_vendor_cmd(gti, GTI_CMD_SET_COORD_FILTER_ENABLED); + if (ret) + GOOG_WARN(gti, "unexpected return(%d)!", ret); + } + gti->cmd.screen_protector_mode_cmd.setting = gti->screen_protector_mode_setting; ret = goog_process_vendor_cmd(gti, GTI_CMD_SET_SCREEN_PROTECTOR_MODE); if (ret != 0) @@ -2192,6 +2289,8 @@ int goog_offload_probe(struct goog_touch_interface *gti) gti->offload.caps.size_reporting = true; gti->offload.caps.filter_grip = true; gti->offload.caps.filter_palm = true; + gti->offload.caps.coord_filter = gti->coord_filter_enabled && + of_property_read_bool(np, "goog,offload-caps-coord-filter"); gti->offload.caps.num_sensitivity_settings = 1; gti->offload.caps.rotation_reporting = of_property_read_bool(np, "goog,offload-caps-rotation-reporting"); @@ -2217,6 +2316,9 @@ int goog_offload_probe(struct goog_touch_interface *gti) "goog,default-grip-disabled") ? GTI_GRIP_DISABLE : GTI_GRIP_ENABLE; gti->default_palm_enabled = of_property_read_bool(np, "goog,default-palm-disabled") ? GTI_PALM_DISABLE : GTI_PALM_ENABLE; + gti->default_coord_filter_enabled = of_property_read_bool(np, + "goog,default-coord-filter-disabled") ? + GTI_COORD_FILTER_DISABLE : GTI_COORD_FILTER_ENABLE; gti->heatmap_buf_size = gti->offload.caps.tx_size * gti->offload.caps.rx_size * sizeof(u16); gti->heatmap_buf = devm_kzalloc(gti->vendor_dev, gti->heatmap_buf_size, GFP_KERNEL); @@ -2519,6 +2621,12 @@ static int goog_get_context_stylus_nop( return -ESRCH; } +static int goog_get_coord_filter_enabled_nop( + void *private_data, struct gti_coord_filter_cmd *cmd) +{ + return -ESRCH; +} + static int goog_get_fw_version_nop( void *private_data, struct gti_fw_version_cmd *cmd) { @@ -2609,6 +2717,12 @@ static int goog_set_continuous_report_nop( return -ESRCH; } +static int goog_set_coord_filter_enabled_nop( + void *private_data, struct gti_coord_filter_cmd *cmd) +{ + return -ESRCH; +} + static int goog_set_grip_mode_nop( void *private_data, struct gti_grip_cmd *cmd) { @@ -2717,15 +2831,21 @@ void goog_init_options(struct goog_touch_interface *gti, struct gti_optional_configuration *options) { /* Initialize the common features. */ + gti->mf_mode = GTI_MF_MODE_DEFAULT; + gti->screen_protector_mode_setting = GTI_SCREEN_PROTECTOR_MODE_DISABLE; + gti->display_state = GTI_DISPLAY_STATE_ON; + if (gti->vendor_dev) { struct device_node *np = gti->vendor_dev->of_node; gti->ignore_force_active = of_property_read_bool(np, "goog,ignore-force-active"); + gti->coord_filter_enabled = of_property_read_bool(np, "goog,coord-filter-enabled"); } /* Initialize default functions. */ gti->options.get_context_driver = goog_get_context_driver_nop; gti->options.get_context_stylus = goog_get_context_stylus_nop; + gti->options.get_coord_filter_enabled = goog_get_coord_filter_enabled_nop; gti->options.get_fw_version = goog_get_fw_version_nop; gti->options.get_grip_mode = goog_get_grip_mode_nop; gti->options.get_irq_mode = goog_get_irq_mode_nop; @@ -2741,6 +2861,7 @@ void goog_init_options(struct goog_touch_interface *gti, gti->options.reset = goog_reset_nop; gti->options.selftest = goog_selftest_nop; gti->options.set_continuous_report = goog_set_continuous_report_nop; + gti->options.set_coord_filter_enabled = goog_set_coord_filter_enabled_nop; gti->options.set_grip_mode = goog_set_grip_mode_nop; gti->options.set_heatmap_enabled = goog_set_heatmap_enabled_nop; gti->options.set_irq_mode = goog_set_irq_mode_nop; @@ -2756,6 +2877,8 @@ void goog_init_options(struct goog_touch_interface *gti, gti->options.get_context_driver = options->get_context_driver; if (options->get_context_stylus) gti->options.get_context_stylus = options->get_context_stylus; + if (options->get_coord_filter_enabled) + gti->options.get_coord_filter_enabled = options->get_coord_filter_enabled; if (options->get_fw_version) gti->options.get_fw_version = options->get_fw_version; if (options->get_grip_mode) @@ -2788,6 +2911,8 @@ void goog_init_options(struct goog_touch_interface *gti, gti->options.selftest = options->selftest; if (options->set_continuous_report) gti->options.set_continuous_report = options->set_continuous_report; + if (options->set_coord_filter_enabled) + gti->options.set_coord_filter_enabled = options->set_coord_filter_enabled; if (options->set_grip_mode) gti->options.set_grip_mode = options->set_grip_mode; if (options->set_heatmap_enabled) @@ -3399,9 +3524,6 @@ struct goog_touch_interface *goog_touch_interface_probe( gti->vendor_dev = dev; gti->vendor_input_dev = input_dev; gti->vendor_default_handler = default_handler; - gti->mf_mode = GTI_MF_MODE_DEFAULT; - gti->screen_protector_mode_setting = GTI_SCREEN_PROTECTOR_MODE_DISABLE; - gti->display_state = GTI_DISPLAY_STATE_ON; mutex_init(>i->input_lock); mutex_init(>i->input_process_lock); } diff --git a/goog_touch_interface.h b/goog_touch_interface.h index d6c1205..e970c1a 100644 --- a/goog_touch_interface.h +++ b/goog_touch_interface.h @@ -49,6 +49,7 @@ enum gti_cmd_type : u32 { GTI_CMD_GET_OPS_START = 0x200, GTI_CMD_GET_CONTEXT_DRIVER, GTI_CMD_GET_CONTEXT_STYLUS, + GTI_CMD_GET_COORD_FILTER_ENABLED, GTI_CMD_GET_FW_VERSION, GTI_CMD_GET_GRIP_MODE, GTI_CMD_GET_IRQ_MODE, @@ -67,6 +68,7 @@ enum gti_cmd_type : u32 { /* GTI_CMD_SET operations. */ GTI_CMD_SET_OPS_START = 0x400, GTI_CMD_SET_CONTINUOUS_REPORT, + GTI_CMD_SET_COORD_FILTER_ENABLED, GTI_CMD_SET_GRIP_MODE, GTI_CMD_SET_HEATMAP_ENABLED, GTI_CMD_SET_IRQ_MODE, @@ -83,6 +85,11 @@ enum gti_continuous_report_setting : u32 { GTI_CONTINUOUS_REPORT_DRIVER_DEFAULT, }; +enum gti_coord_filter_setting : u32 { + GTI_COORD_FILTER_DISABLE = 0, + GTI_COORD_FILTER_ENABLE, +}; + enum gti_display_state_setting : u32 { GTI_DISPLAY_STATE_OFF = 0, GTI_DISPLAY_STATE_ON, @@ -321,6 +328,10 @@ struct gti_debug_input { struct gti_debug_coord released; }; +struct gti_coord_filter_cmd { + enum gti_coord_filter_setting setting; +}; + struct gti_display_state_cmd { enum gti_display_state_setting setting; }; @@ -389,6 +400,7 @@ struct gti_sensor_data_cmd { * @context_driver_cmd: command to update touch offload driver context. * @context_stylus_cmd: command to update touch offload stylus context. * @continuous_report_cmd: command to set continuous reporting. + * @coord_filter_cmd: command to set/get coordinate filter enabled. * @display_state_cmd: command to notify display state. * @display_vrefresh_cmd: command to notify display vertical refresh rate. * @fw_version_cmd: command to get fw version. @@ -410,6 +422,7 @@ struct gti_union_cmd_data { struct gti_context_driver_cmd context_driver_cmd; struct gti_context_stylus_cmd context_stylus_cmd; struct gti_continuous_report_cmd continuous_report_cmd; + struct gti_coord_filter_cmd coord_filter_cmd; struct gti_display_state_cmd display_state_cmd; struct gti_display_vrefresh_cmd display_vrefresh_cmd; struct gti_fw_version_cmd fw_version_cmd; @@ -441,6 +454,7 @@ struct gti_fw_status_data { * struct gti_optional_configuration - optional configuration by vendor driver. * @get_context_driver: vendor driver operation to update touch offload driver context. * @get_context_stylus: vendor driver operation to update touch offload stylus context. + * @get_coord_filter_enabled: vendor driver operation to get the coordinate filter enabled. * @get_fw_version: vendor driver operation to get fw version info. * @get_grip_mode: vendor driver operation to get the grip mode setting. * @get_irq_mode: vendor driver operation to get irq mode setting. @@ -456,6 +470,7 @@ struct gti_fw_status_data { * @reset: vendor driver operation to exec reset. * @selftest: vendor driver operation to exec self-test. * @set_continuous_report: vendor driver operation to apply the continuous reporting setting. + * @set_coord_filter_enabled: vendor driver operation to apply the coordinate filter enabled. * @set_grip_mode: vendor driver operation to apply the grip setting. * @set_heatmap_enabled: vendor driver operation to apply the heatmap setting. * @set_irq_mode: vendor driver operation to apply the irq setting. @@ -468,6 +483,7 @@ struct gti_fw_status_data { struct gti_optional_configuration { int (*get_context_driver)(void *private_data, struct gti_context_driver_cmd *cmd); int (*get_context_stylus)(void *private_data, struct gti_context_stylus_cmd *cmd); + int (*get_coord_filter_enabled)(void *private_data, struct gti_coord_filter_cmd *cmd); int (*get_fw_version)(void *private_data, struct gti_fw_version_cmd *cmd); int (*get_grip_mode)(void *private_data, struct gti_grip_cmd *cmd); int (*get_irq_mode)(void *private_data, struct gti_irq_cmd *cmd); @@ -484,6 +500,7 @@ struct gti_optional_configuration { int (*reset)(void *private_data, struct gti_reset_cmd *cmd); int (*selftest)(void *private_data, struct gti_selftest_cmd *cmd); int (*set_continuous_report)(void *private_data, struct gti_continuous_report_cmd *cmd); + int (*set_coord_filter_enabled)(void *private_data, struct gti_coord_filter_cmd *cmd); int (*set_grip_mode)(void *private_data, struct gti_grip_cmd *cmd); int (*set_heatmap_enabled)(void *private_data, struct gti_heatmap_cmd *cmd); int (*set_irq_mode)(void *private_data, struct gti_irq_cmd *cmd); @@ -561,14 +578,18 @@ struct gti_pm { * @fw_status: firmware status such as water_mode, noise_level, etc. * @context_changed: flags that indicate driver status changing. * @panel_is_lp_mode: display is in low power mode. - * @offload_enable: touch offload is enabled or not. - * @v4l2_enable: v4l2 is enabled or not. - * @tbn_enable: tbn is enabled or not. + * @offload_enabled: touch offload is enabled or not. + * @v4l2_enabled: v4l2 is enabled or not. + * @tbn_enabled: tbn is enabled or not. + * @coord_filter_enabled: coordinate filter is enabled or not. * @input_timestamp_changed: input timestamp changed from touch vendor driver. * @ignore_grip_update: Ignore fw_grip status updates made on offload state change. * @default_grip_enabled: the grip default setting. * @ignore_palm_update: Ignore fw_palm status updates made on offload state change. * @default_palm_enabled: the palm default setting. + * @ignore_coord_filter_update: Ignore fw_coordinate_filter status updates. + * @fw_coord_filter_enabled: the current setting of coordinate filter. + * @default_coord_filter_enabled: the default setting of coordinate filter. * @lptw_triggered: LPTW is triggered or not. * @ignore_force_active: Ignore the force_active sysfs request. * @offload_id: id that used by touch offload. @@ -637,11 +658,15 @@ struct goog_touch_interface { bool offload_enabled; bool v4l2_enabled; bool tbn_enabled; + bool coord_filter_enabled; bool input_timestamp_changed; bool ignore_grip_update; bool default_grip_enabled; bool ignore_palm_update; bool default_palm_enabled; + bool ignore_coord_filter_update; + bool fw_coord_filter_enabled; + bool default_coord_filter_enabled; bool lptw_triggered; bool ignore_force_active; union { |