summaryrefslogtreecommitdiff
path: root/drivers/hid/wacom_sys.c
diff options
context:
space:
mode:
authorJason Gerecke <killertofu@gmail.com>2017-11-10 11:50:01 -0800
committerJiri Kosina <jkosina@suse.cz>2017-11-21 13:04:35 +0100
commit83417206427bdf0fef9fa69957807194f25923c3 (patch)
treee7d1350d7acd2ddcbb116c203a5b5ad8552f033b /drivers/hid/wacom_sys.c
parent99acedadde157a02b21761fd406ef7adc7615533 (diff)
HID: wacom: Queue events with missing type/serial data for later processing
Userspace expects to receive tool type and serial number information for the active pen in the very first kernel report, if such data is supported by the hardware. While this expectation is not an issue for EMR devices, AES sensors will often send several packets worth of in- range data before relaying type/serial data to the kernel. Sending this data "late" can result in proximity-tracking issues by xf86-input-wacom, or an inability to distinguish different pens by input-wacom. Options for dealing with this situation include ignoring reports from the tablet until we get the necessary data, or using the information from the last-seen pen instead of the (eventual) real data. Neither option is particularly attractive: the former results in truncated strokes and the latter causes issues with switching between pens. This commit instead opts to queue up events with missing information until we receive a report which contains it. At that point, we can update the driver's state variables (id[0] and serial[0]) and replay the queued events. Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/wacom_sys.c')
-rw-r--r--drivers/hid/wacom_sys.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index ee71ad9b6cc1..c9eadf632564 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -56,6 +56,107 @@ static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
return retval;
}
+static void wacom_wac_queue_insert(struct hid_device *hdev,
+ struct kfifo_rec_ptr_2 *fifo,
+ u8 *raw_data, int size)
+{
+ bool warned = false;
+
+ while (kfifo_avail(fifo) < size) {
+ if (!warned)
+ hid_warn(hdev, "%s: kfifo has filled, starting to drop events\n", __func__);
+ warned = true;
+
+ kfifo_skip(fifo);
+ }
+
+ kfifo_in(fifo, raw_data, size);
+}
+
+static void wacom_wac_queue_flush(struct hid_device *hdev,
+ struct kfifo_rec_ptr_2 *fifo)
+{
+ while (!kfifo_is_empty(fifo)) {
+ u8 buf[WACOM_PKGLEN_MAX];
+ int size;
+ int err;
+
+ size = kfifo_out(fifo, buf, sizeof(buf));
+ err = hid_report_raw_event(hdev, HID_INPUT_REPORT, buf, size, false);
+ if (err) {
+ hid_warn(hdev, "%s: unable to flush event due to error %d\n",
+ __func__, err);
+ }
+ }
+}
+
+static int wacom_wac_pen_serial_enforce(struct hid_device *hdev,
+ struct hid_report *report, u8 *raw_data, int size)
+{
+ struct wacom *wacom = hid_get_drvdata(hdev);
+ struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+ struct wacom_features *features = &wacom_wac->features;
+ bool flush = false;
+ bool insert = false;
+ int i, j;
+
+ if (wacom_wac->serial[0] || !(features->quirks & WACOM_QUIRK_TOOLSERIAL))
+ return 0;
+
+ /* Queue events which have invalid tool type or serial number */
+ for (i = 0; i < report->maxfield; i++) {
+ for (j = 0; j < report->field[i]->maxusage; j++) {
+ struct hid_field *field = report->field[i];
+ struct hid_usage *usage = &field->usage[j];
+ unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid);
+ unsigned int offset;
+ unsigned int size;
+ unsigned int value;
+
+ if (equivalent_usage != HID_DG_INRANGE &&
+ equivalent_usage != HID_DG_TOOLSERIALNUMBER &&
+ equivalent_usage != WACOM_HID_WD_SERIALHI &&
+ equivalent_usage != WACOM_HID_WD_TOOLTYPE)
+ continue;
+
+ offset = field->report_offset;
+ size = field->report_size;
+ value = hid_field_extract(hdev, raw_data+1, offset + j * size, size);
+
+ /* If we go out of range, we need to flush the queue ASAP */
+ if (equivalent_usage == HID_DG_INRANGE)
+ value = !value;
+
+ if (value) {
+ flush = true;
+ switch (equivalent_usage) {
+ case HID_DG_TOOLSERIALNUMBER:
+ wacom_wac->serial[0] = value;
+ break;
+
+ case WACOM_HID_WD_SERIALHI:
+ wacom_wac->serial[0] |= ((__u64)value) << 32;
+ break;
+
+ case WACOM_HID_WD_TOOLTYPE:
+ wacom_wac->id[0] = value;
+ break;
+ }
+ }
+ else {
+ insert = true;
+ }
+ }
+ }
+
+ if (flush)
+ wacom_wac_queue_flush(hdev, &wacom_wac->pen_fifo);
+ else if (insert)
+ wacom_wac_queue_insert(hdev, &wacom_wac->pen_fifo, raw_data, size);
+
+ return insert && !flush;
+}
+
static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
u8 *raw_data, int size)
{
@@ -64,6 +165,9 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
if (size > WACOM_PKGLEN_MAX)
return 1;
+ if (wacom_wac_pen_serial_enforce(hdev, report, raw_data, size))
+ return -1;
+
memcpy(wacom->wacom_wac.data, raw_data, size);
wacom_wac_irq(&wacom->wacom_wac, size);
@@ -2580,6 +2684,10 @@ static int wacom_probe(struct hid_device *hdev,
goto fail;
}
+ error = kfifo_alloc(&wacom_wac->pen_fifo, WACOM_PKGLEN_MAX, GFP_KERNEL);
+ if (error)
+ goto fail;
+
wacom_wac->hid_data.inputmode = -1;
wacom_wac->mode_report = -1;
@@ -2643,6 +2751,8 @@ static void wacom_remove(struct hid_device *hdev)
if (wacom->wacom_wac.features.type != REMOTE)
wacom_release_resources(wacom);
+ kfifo_free(&wacom_wac->pen_fifo);
+
hid_set_drvdata(hdev, NULL);
}