diff options
author | Super Liu <supercjliu@google.com> | 2023-04-06 05:19:59 +0000 |
---|---|---|
committer | Super Liu <supercjliu@google.com> | 2023-04-06 08:03:06 +0000 |
commit | 44aab581f2b8ed6170a722fe45631dbe6b6363d9 (patch) | |
tree | 71d68fb3e96ea85bb69284e83d2905dc9f281ccd | |
parent | 136b2a450f13df6f5486358bae6c1497d888a92f (diff) | |
download | goodix_touch-44aab581f2b8ed6170a722fe45631dbe6b6363d9.tar.gz |
Revert^2 "touch/goodix: Import driver v1.2.5a"
f712abc5966e36bed62e9417e41b991267161d75
Change-Id: Id404af70d6efb49a9661068b559cc0a79c48145d
-rw-r--r-- | goodix_brl_hw.c | 33 | ||||
-rw-r--r-- | goodix_ts_core.c | 134 | ||||
-rw-r--r-- | goodix_ts_core.h | 32 |
3 files changed, 121 insertions, 78 deletions
diff --git a/goodix_brl_hw.c b/goodix_brl_hw.c index fca0a18..7fc0d20 100644 --- a/goodix_brl_hw.c +++ b/goodix_brl_hw.c @@ -1059,6 +1059,9 @@ static void goodix_parse_pen( int16_t x_angle, y_angle; int i; + if ((buf[0] & 0x0F) == POINT_TYPE_STYLUS_HOVER) + pen_data->is_hover = true; + pen_data->coords.status = TS_TOUCH; pen_data->coords.x = le16_to_cpup((__le16 *)(buf + 2)); pen_data->coords.y = le16_to_cpup((__le16 *)(buf + 4)); @@ -1068,6 +1071,13 @@ static void goodix_parse_pen( pen_data->coords.tilt_x = x_angle / 100; pen_data->coords.tilt_y = y_angle / 100; + /* ble pen data */ + pen_data->custom_flag = event_head[3] & 0x01; + if (pen_data->custom_flag) { + pen_data->tx1_freq_index = buf[19]; + pen_data->tx2_freq_index = buf[20]; + } + cur_key_map = (buf[3] & 0x0F) >> 1; for (i = 0; i < GOODIX_MAX_PEN_KEY; i++) { pen_data->keys[i].code = goodix_pen_btn_code[i]; @@ -1226,7 +1236,7 @@ static int brl_event_handler(struct goodix_ts_core *cd, */ if (event_data->type & (GOODIX_TOUCH_EVENT >> 4)) - return goodix_touch_handler(cd, ts_event, + goodix_touch_handler(cd, ts_event, (struct goodix_ts_touch_event_data *)event_data); if (event_data->type & (GOODIX_REQUEST_EVENT >> 4)) { @@ -1239,27 +1249,6 @@ static int brl_event_handler(struct goodix_ts_core *cd, ts_event->request_code = REQUEST_TYPE_RESET; else if (request->request_type == BRL_REQUEST_CODE_UPDATE) ts_event->request_code = REQUEST_TYPE_UPDATE; - else if (request->request_type == BRL_REQUEST_PEN_FREQ_HOP) - if (request->data_len && !checksum_cmp(request->data, - request->data_len + 2, - CHECKSUM_MODE_U8_LE)) { - if (request->data_len + 2 <= - GOODIX_REQUEST_DATA_LEN) { - memcpy(ts_event->request_data, - request->data, - request->data_len + 2); - ts_event->request_code = - REQUEST_PEN_FREQ_HOP; - } else { - ts_err("request data len exceed limit %d", - request->data_len + 2); - } - } else { - ts_info("invalid request data %d", - request->data_len); - ts_info("request data:%*ph", request->data_len, - request->data); - } else ts_debug("unsupported request code 0x%x", request->request_type); diff --git a/goodix_ts_core.c b/goodix_ts_core.c index 7f0c9b2..e92fc5b 100644 --- a/goodix_ts_core.c +++ b/goodix_ts_core.c @@ -168,6 +168,22 @@ static ssize_t chip_info_show(struct device *dev, return cnt; } +/* reset chip */ +static ssize_t goodix_ts_reset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct goodix_ts_core *core_data = dev_get_drvdata(dev); + struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops; + + if (!buf || count <= 0) + return -EINVAL; + if (buf[0] != '0') + hw_ops->reset(core_data, GOODIX_NORMAL_RESET_DELAY_MS); + return count; +} + /* read config */ static ssize_t read_cfg_show( struct device *dev, struct device_attribute *attr, char *buf) @@ -552,81 +568,96 @@ static ssize_t goodix_ts_debug_log_store(struct device *dev, return count; } -int goodix_update_pen_freq(struct goodix_ts_core *cd, u8 *data, int len) +static int goodix_refresh_pen_pair(struct goodix_ts_core *cd) { struct goodix_ble_data *ble_data = &cd->ble_data; + u8 checksum = 0; + int i; - if (len > sizeof(ble_data->freq)) { - ts_err("pen freq data exceed limit"); - return -EINVAL; - } mutex_lock(&ble_data->lock); - memset(ble_data->freq, 0, sizeof(ble_data->freq)); - memcpy(ble_data->freq, data, len); - ble_data->freq_ready = 1; + ble_data->cmd.cmd = 0xC5; + ble_data->cmd.len = 5; + ble_data->cmd.data[0] = 1; + ble_data->cmd.data[1] = ble_data->tx1_freq_index; + ble_data->cmd.data[2] = ble_data->tx2_freq_index; + ble_data->cmd.data[3] = 0; + ble_data->cmd.data[4] = 0; + for (i = 0; i < 7; i++) + checksum += ble_data->cmd.buf[i]; + ble_data->cmd.data[5] = checksum; mutex_unlock(&ble_data->lock); - sysfs_notify(&cd->pdev->dev.kobj, NULL, "pen_freq"); - ts_debug("send pen freq hop event"); + sysfs_notify(&cd->pdev->dev.kobj, NULL, "pen_get"); + ts_info("pen pair event"); return 0; } /* debug level show */ -static ssize_t goodix_ts_pen_freq_show( - struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t goodix_ts_pen_get_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct goodix_ts_core *core_data = dev_get_drvdata(dev); struct goodix_ble_data *ble_data = &core_data->ble_data; mutex_lock(&ble_data->lock); - memcpy(buf, ble_data->freq, sizeof(ble_data->freq)); - ble_data->freq_ready = 0; + memcpy(buf, ble_data->cmd.buf, sizeof(ble_data->cmd)); mutex_unlock(&ble_data->lock); - return sizeof(ble_data->freq); + return sizeof(ble_data->cmd); } /* debug level store */ static ssize_t goodix_ts_pen_debug_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) + struct device_attribute *attr, + const char *buf, size_t count) { - int pen_freq; struct goodix_ts_core *core_data = dev_get_drvdata(dev); - struct goodix_ble_data *ble_data = &core_data->ble_data; - - sscanf(buf, "%d", &pen_freq); - ts_debug("set new pen_freq %d", pen_freq); - ble_data->freq[0] = 0xC0; - ble_data->freq[1] = 1; - ble_data->freq[2] = pen_freq & 0xFF; - sysfs_notify(&core_data->pdev->dev.kobj, NULL, "pen_freq"); + sysfs_notify(&core_data->pdev->dev.kobj, NULL, "pen_get"); return count; } -static ssize_t goodix_ts_pen_hogp_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t goodix_ts_pen_set_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - struct goodix_hid_hogp *tmp_prs; struct goodix_ts_core *core_data = dev_get_drvdata(dev); struct goodix_ble_data *ble_data = &core_data->ble_data; + struct goodix_ble_cmd temp_cmd; + struct goodix_ts_cmd cmd; - if (count < sizeof(ble_data->hogp)) { - ts_err("data count to short"); + if (count > sizeof(temp_cmd)) { + ts_err("data count to long"); return -EINVAL; } + ts_debug("get ble cmd:%*ph", (int)count, buf); mutex_lock(&ble_data->lock); - memcpy(ble_data->hogp, buf, sizeof(ble_data->hogp)); - ble_data->hogp_ready = 1; + memcpy(temp_cmd.buf, buf, count); + switch (temp_cmd.cmd) { + case 0x4B: + ble_data->pressure = (temp_cmd.data[1] << 8) | temp_cmd.data[0]; + ble_data->hogp_ready = 1; + break; + case 0xC4: + cmd.cmd = 0xAA; + cmd.len = 6; + cmd.data[0] = temp_cmd.data[1]; + cmd.data[1] = temp_cmd.data[2]; + core_data->hw_ops->send_cmd(core_data, &cmd); + cmd.cmd = 0xBB; + cmd.len = 5; + cmd.data[0] = temp_cmd.data[4]; + core_data->hw_ops->send_cmd(core_data, &cmd); + break; + } mutex_unlock(&ble_data->lock); - tmp_prs = (struct goodix_hid_hogp *)ble_data->hogp; - ts_debug("set ble pen data: %d, key %x", tmp_prs->pressure, - tmp_prs->key); return count; } static DEVICE_ATTR(driver_info, 0440, driver_info_show, NULL); static DEVICE_ATTR(chip_info, 0440, chip_info_show, NULL); +static DEVICE_ATTR(hw_reset, 0220, NULL, goodix_ts_reset_store); /* [GOOG] */ static DEVICE_ATTR(send_cfg, 0220, NULL, goodix_ts_send_cfg_store); static DEVICE_ATTR(read_cfg, 0440, read_cfg_show, NULL); static DEVICE_ATTR(reg_rw, 0664, goodix_ts_reg_rw_show, goodix_ts_reg_rw_store); @@ -636,22 +667,23 @@ static DEVICE_ATTR( esd_info, 0664, goodix_ts_esd_info_show, goodix_ts_esd_info_store); static DEVICE_ATTR( debug_log, 0664, goodix_ts_debug_log_show, goodix_ts_debug_log_store); -static DEVICE_ATTR(pen_freq, 0440, goodix_ts_pen_freq_show, NULL); +static DEVICE_ATTR(pen_get, 0440, goodix_ts_pen_get_show, NULL); static DEVICE_ATTR(pen_debug, 0220, NULL, goodix_ts_pen_debug_store); -static DEVICE_ATTR(pen_hogp, 0220, NULL, goodix_ts_pen_hogp_store); +static DEVICE_ATTR(pen_set, 0220, NULL, goodix_ts_pen_set_store); static struct attribute *sysfs_attrs[] = { &dev_attr_driver_info.attr, &dev_attr_chip_info.attr, + &dev_attr_hw_reset.attr,/* [GOOG] use touch_apis.c to create `reset` sysfs instead */ &dev_attr_send_cfg.attr, &dev_attr_read_cfg.attr, &dev_attr_reg_rw.attr, &dev_attr_irq_info.attr, &dev_attr_esd_info.attr, &dev_attr_debug_log.attr, - &dev_attr_pen_freq.attr, + &dev_attr_pen_get.attr, &dev_attr_pen_debug.attr, - &dev_attr_pen_hogp.attr, + &dev_attr_pen_set.attr, NULL, }; @@ -1437,7 +1469,6 @@ static void goodix_ts_report_pen( { struct input_dev *dev = cd->pen_dev; int i; - struct goodix_hid_hogp *hogp; struct goodix_ble_data *ble_data = &cd->ble_data; char trace_tag[128]; ktime_t pen_ktime; @@ -1452,14 +1483,16 @@ static void goodix_ts_report_pen( ktime_to_ns(cd->coords_timestamp), ktime_to_ns(pen_ktime), ktime_to_ns(ktime_sub(pen_ktime, cd->coords_timestamp))); ATRACE_BEGIN(trace_tag); - input_report_key(dev, BTN_TOUCH, 1); + if (pen_data->is_hover) + input_report_key(dev, BTN_TOUCH, 0); + else + input_report_key(dev, BTN_TOUCH, 1); input_report_key(dev, BTN_TOOL_PEN, 1); input_report_abs(dev, ABS_X, pen_data->coords.x); input_report_abs(dev, ABS_Y, pen_data->coords.y); mutex_lock(&ble_data->lock); if (ble_data->hogp_ready) { - hogp = (struct goodix_hid_hogp *)ble_data->hogp; - cd->pen_pressure = hogp->pressure; + cd->pen_pressure = ble_data->pressure; ts_debug("update pen pressure from ble %d", cd->pen_pressure); } @@ -1482,6 +1515,15 @@ static void goodix_ts_report_pen( pen_data->coords.tilt_y, pen_data->keys[0].status == TS_TOUCH ? 1 : 0, pen_data->keys[1].status == TS_TOUCH ? 1 : 0); + + if (pen_data->custom_flag) { + if (ble_data->tx1_freq_index != pen_data->tx1_freq_index || + ble_data->tx2_freq_index != pen_data->tx2_freq_index) { + ble_data->tx1_freq_index = pen_data->tx1_freq_index; + ble_data->tx2_freq_index = pen_data->tx2_freq_index; + goodix_refresh_pen_pair(cd); + } + } } else { scnprintf(trace_tag, sizeof(trace_tag), "stylus-inactive: IN_TS=%lld TS=%lld DELTA=%lld ns.\n", @@ -1670,9 +1712,6 @@ static int goodix_ts_request_handle( else if (ts_event->request_code == REQUEST_TYPE_UPDATE) ret = goodix_do_fw_update(cd, UPDATE_MODE_FORCE | UPDATE_MODE_BLOCK | UPDATE_MODE_SRC_REQUEST); - else if (ts_event->request_code == REQUEST_PEN_FREQ_HOP) - ret = goodix_update_pen_freq(cd, ts_event->request_data, - sizeof(ts_event->request_data)); else ts_info("can not handle request type 0x%x", ts_event->request_code); @@ -2100,6 +2139,9 @@ static int goodix_ts_input_dev_config(struct goodix_ts_core *core_data) input_set_capability(input_dev, EV_KEY, KEY_WAKEUP); input_set_capability(input_dev, EV_KEY, KEY_GOTO); + core_data->ble_data.tx1_freq_index = 0xFF; + core_data->ble_data.tx2_freq_index = 0xFF; + r = input_register_device(input_dev); if (r < 0) { ts_err("Unable to register input device"); diff --git a/goodix_ts_core.h b/goodix_ts_core.h index cfd7bca..cf13bdf 100644 --- a/goodix_ts_core.h +++ b/goodix_ts_core.h @@ -57,7 +57,7 @@ #define GOODIX_CORE_DRIVER_NAME "goodix_ts" #define GOODIX_PEN_DRIVER_NAME "goodix_ts,pen" -#define GOODIX_DRIVER_VERSION "v1.2.5" +#define GOODIX_DRIVER_VERSION "v1.2.5a" #define GOODIX_MAX_TOUCH 10 #define GOODIX_PEN_MAX_PRESSURE 4096 #define GOODIX_MAX_PEN_KEY 2 @@ -545,27 +545,40 @@ struct goodix_ts_key { int code; }; -#define GOODIX_MAX_PEN_FREQ_DATA_LEN 16 -#define GOODIX_HOGP_INFO_LEN 3 - #pragma pack(1) -struct goodix_hid_hogp { - u16 pressure; - u8 key; +struct goodix_ble_cmd { + union { + struct { + u8 cmd; + u8 len; + u8 data[32]; + }; + u8 buf[34]; + }; }; #pragma pack() +#define GOODIX_MAX_PEN_FREQ_DATA_LEN 16 +#define GOODIX_HOGP_INFO_LEN 3 + struct goodix_ble_data { u8 freq[GOODIX_MAX_PEN_FREQ_DATA_LEN]; - u8 hogp[GOODIX_HOGP_INFO_LEN]; + int sync_status; + int tx1_freq_index; + int tx2_freq_index; int hogp_ready; - int freq_ready; + int pressure; + struct goodix_ble_cmd cmd; struct mutex lock; }; struct goodix_pen_data { struct goodix_pen_coords coords; struct goodix_ts_key keys[GOODIX_MAX_PEN_KEY]; + bool is_hover; + bool custom_flag; + int tx1_freq_index; + int tx2_freq_index; }; /* @@ -970,6 +983,5 @@ int goodix_do_inspect(struct goodix_ts_core *cd, struct ts_rawdata_info *info); int goodix_ts_report_gesture(struct goodix_ts_core *cd, struct goodix_ts_event *event); void goodix_ts_report_status(struct goodix_ts_core *core_data, struct goodix_ts_event *ts_event); -int goodix_update_pen_freq(struct goodix_ts_core *cd, u8 *data, int len); #endif |