From 7690dd18ddeda98521f4966e60e1a70b97316d11 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Thu, 7 Sep 2017 17:48:55 -0700 Subject: HID: wacom: generic: Use generic codepath terminology in wacom_wac_pen_report The terminology used to describe the various degrees of pen proximity within the wacom_wac_pen_report function does not match that used elsewhere in the generic codepath. Specifically, the names of the variables "prox" and "range" were inspired by the non-generic codepaths. To make the generic codepath internally consistent, replace these terms with "range" and "sense" respectively. Signed-off-by: Jason Gerecke Signed-off-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index aa692e28b2cd..cdf95e1999d1 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2217,7 +2217,7 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field if (!usage->type || delay_pen_events(wacom_wac)) return; - /* send pen events only when the pen is in/entering/leaving proximity */ + /* send pen events only when the pen is in/entering/leaving range */ if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0]) return; @@ -2236,11 +2236,11 @@ static void wacom_wac_pen_report(struct hid_device *hdev, struct wacom *wacom = hid_get_drvdata(hdev); struct wacom_wac *wacom_wac = &wacom->wacom_wac; struct input_dev *input = wacom_wac->pen_input; - bool prox = wacom_wac->hid_data.inrange_state; - bool range = wacom_wac->hid_data.sense_state; + bool range = wacom_wac->hid_data.inrange_state; + bool sense = wacom_wac->hid_data.sense_state; - if (!wacom_wac->tool[0] && prox) { /* first in prox */ - /* Going into proximity select tool */ + if (!wacom_wac->tool[0] && range) { /* first in range */ + /* Going into range select tool */ if (wacom_wac->hid_data.invert_state) wacom_wac->tool[0] = BTN_TOOL_RUBBER; else if (wacom_wac->id[0]) @@ -2250,7 +2250,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev, } /* keep pen state for touch events */ - wacom_wac->shared->stylus_in_proximity = range; + wacom_wac->shared->stylus_in_proximity = sense; if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) { int id = wacom_wac->id[0]; @@ -2269,10 +2269,10 @@ static void wacom_wac_pen_report(struct hid_device *hdev, */ input_report_key(input, BTN_TOUCH, wacom_wac->hid_data.tipswitch); - input_report_key(input, wacom_wac->tool[0], prox); + input_report_key(input, wacom_wac->tool[0], range); if (wacom_wac->serial[0]) { input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]); - input_report_abs(input, ABS_MISC, prox ? id : 0); + input_report_abs(input, ABS_MISC, range ? id : 0); } wacom_wac->hid_data.tipswitch = false; @@ -2280,7 +2280,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev, input_sync(input); } - if (!prox) { + if (!range) { wacom_wac->tool[0] = 0; wacom_wac->id[0] = 0; wacom_wac->serial[0] = 0; -- cgit v1.2.3 From 4affc2331a70fff3d0d0e8f28ead80aa2b8b589a Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Thu, 7 Sep 2017 17:49:50 -0700 Subject: HID: wacom: generic: Leave tool in prox until it completely leaves sense The legacy Intuos codepath and tablet behavior (e.g. the 1st-gen Intuos Pro, Cintiq 27, etc.) would result in a BTN_TOOL_* event not being cleared to zero until the tool had completely left the sensing range of the tablet. Before the final "out of prox" packet would be sent, zero or more "in range" packets could be sent to indicate that a pen was still detectable but not within a useful distance. These "in range" packets were used by the driver to keep touch input disabled at greater pen distances. In addition to keeping the `stylus_in_proximity` flag set, the driver would leave the current BTN_TOOL_* marked as being in proximity as well. The new HID codepath also sets `stylus_in_proximity` based on the "sense" flag, but does not leave the current BTN_TOOL_* marked as being in prox. This information is potentially useful to for a future userspace-based palm rejection, so this patch modifies the driver to continue sending it. Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index cdf95e1999d1..9b3a247ee552 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2217,8 +2217,8 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field if (!usage->type || delay_pen_events(wacom_wac)) return; - /* send pen events only when the pen is in/entering/leaving range */ - if (!wacom_wac->hid_data.inrange_state && !wacom_wac->tool[0]) + /* send pen events only when the pen is in range */ + if (!wacom_wac->hid_data.inrange_state) return; input_event(input, usage->type, usage->code, value); @@ -2269,10 +2269,10 @@ static void wacom_wac_pen_report(struct hid_device *hdev, */ input_report_key(input, BTN_TOUCH, wacom_wac->hid_data.tipswitch); - input_report_key(input, wacom_wac->tool[0], range); + input_report_key(input, wacom_wac->tool[0], sense); if (wacom_wac->serial[0]) { input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]); - input_report_abs(input, ABS_MISC, range ? id : 0); + input_report_abs(input, ABS_MISC, sense ? id : 0); } wacom_wac->hid_data.tipswitch = false; @@ -2280,7 +2280,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev, input_sync(input); } - if (!range) { + if (!sense) { wacom_wac->tool[0] = 0; wacom_wac->id[0] = 0; wacom_wac->serial[0] = 0; -- cgit v1.2.3 From 3e70969e44ee52d72053145dab2cbad74109c685 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Thu, 7 Sep 2017 17:51:06 -0700 Subject: HID: wacom: generic: Send BTN_TOOL_PEN in prox once the pen enters range When a pen is first able to to be sensed by the tablet, we would like to inform userspace that a tool is nearby so that it can attempt to perform palm rejection. Unfortunately, we don't know any information about the tool that is nearby, so the best we can do is send a prox event for a generic BTN_TOOL_PEN. If the pen later comes closer and enters proximity, we can determine the actual tool type and send BTN_TOOL_PEN out of prox if necessary. Signed-off-by: Ping Cheng Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 9b3a247ee552..929a1ceabc21 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2247,6 +2247,17 @@ static void wacom_wac_pen_report(struct hid_device *hdev, wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]); else wacom_wac->tool[0] = BTN_TOOL_PEN; + + if (wacom_wac->shared->stylus_in_proximity && + wacom_wac->tool[0] != BTN_TOOL_PEN) { + input_report_key(input, BTN_TOOL_PEN, 0); + input_sync(input); + } + } + else if (!wacom_wac->tool[0] && !range) { /* entering in sense */ + input_report_key(input, BTN_TOOL_PEN, sense); + input_report_key(input, BTN_TOUCH, 0); + input_sync(input); } /* keep pen state for touch events */ -- cgit v1.2.3 From 5b40104edfb003b1e8bae3e546771e6edb59c6b7 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Thu, 7 Sep 2017 17:52:15 -0700 Subject: HID: wacom: generic: Reset events back to zero when pen leaves As a pen leaves, we need to be sure to reset all events back to zero so that userspace is able to get the complete pen state when it enters proximity again. Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 929a1ceabc21..2926e36cb684 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2218,10 +2218,10 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field return; /* send pen events only when the pen is in range */ - if (!wacom_wac->hid_data.inrange_state) - return; - - input_event(input, usage->type, usage->code, value); + if (wacom_wac->hid_data.inrange_state) + input_event(input, usage->type, usage->code, value); + else if (wacom_wac->shared->stylus_in_proximity && !wacom_wac->hid_data.sense_state) + input_event(input, usage->type, usage->code, 0); } static void wacom_wac_pen_pre_report(struct hid_device *hdev, -- cgit v1.2.3 From 2f84723de7cdd031f293b900fecd68ddbec3feaa Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Thu, 5 Oct 2017 11:14:02 -0700 Subject: Revert "HID: wacom: generic: Send BTN_TOOL_PEN in prox once the pen enters range" This reverts commit 3e70969e44ee52d72053145dab2cbad74109c685. This commit causes a few problems for userspace. The most noteworthy are problems related to the distinguishing of different pens and pointer jumps when entering proximity. Userspace is written with the expectation that a pen will provide its tool ID and serial number (if available) in the very first in-prox report. By sending BTN_TOOL_PEN when the tablet starts communicating rather than waiting until a tool ID/serial number is available, userspace ends up treating all pens as being the same and lacking a serial number. Similarly, userspace assumes that the first report will contain X/Y data, but by marking the pen as being in-prox without an X/Y coordinate, userspace ends up warping the pen to the last- known X/Y location. As of commit 5b40104edfb0 ("HID: wacom: generic: Reset events back to zero when pen leaves") this means warping to (0,0). Signed-off-by: Jason Gerecke Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 2926e36cb684..e3223b0c4f90 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2247,17 +2247,6 @@ static void wacom_wac_pen_report(struct hid_device *hdev, wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]); else wacom_wac->tool[0] = BTN_TOOL_PEN; - - if (wacom_wac->shared->stylus_in_proximity && - wacom_wac->tool[0] != BTN_TOOL_PEN) { - input_report_key(input, BTN_TOOL_PEN, 0); - input_sync(input); - } - } - else if (!wacom_wac->tool[0] && !range) { /* entering in sense */ - input_report_key(input, BTN_TOOL_PEN, sense); - input_report_key(input, BTN_TOUCH, 0); - input_sync(input); } /* keep pen state for touch events */ -- cgit v1.2.3 From 9e429d564926d3bca49907fa03031da705ad6f2c Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Tue, 7 Nov 2017 08:25:17 -0800 Subject: HID: wacom: generic: Send BTN_STYLUS3 when both barrel switches are set The Wacom Pro Pen 3D includes a third barrel switch which is intended to be particularly useful in applications where one frequency uses pan, zoom, and rotate to navigate around a scene or model. The pen is compatible with the MobileStudio Pro, 2nd-gen Intuos Pro, and Cintiq Pro. When the third button is pressed, these devices set both the HID_DG_BARRELSWITCH and HID_DG_BARRELSWITCH2 usages since their HID descriptors do not include a usage specific to the button. Rather than send both BTN_STYLUS and BTN_STYLUS2 when the third button is pressed, userspace (libinput) has requested that we detect this condition and report a newly-defined BTN_STYLUS3 event instead. We could define a quirk specific to devices compatible with the Pro Pen 3D, but the liklihood of seeing both barrel switch bits set with other pens/devices is low enough to not worry about (pens mechanically prevent accidental activation of multiple switches). Signed-off-by: Jason Gerecke Acked-by: Dmitry Torokhov Acked-by: Peter Hutterer Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 18 ++++++++++++++++-- drivers/hid/wacom_wac.h | 2 ++ include/uapi/linux/input-event-codes.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index e3223b0c4f90..16af6886e828 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2140,6 +2140,12 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field case HID_DG_TIPSWITCH: wacom_wac->hid_data.tipswitch |= value; return; + case HID_DG_BARRELSWITCH: + wacom_wac->hid_data.barrelswitch = value; + return; + case HID_DG_BARRELSWITCH2: + wacom_wac->hid_data.barrelswitch2 = value; + return; case HID_DG_TOOLSERIALNUMBER: if (value) { wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); @@ -2254,6 +2260,12 @@ static void wacom_wac_pen_report(struct hid_device *hdev, if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) { int id = wacom_wac->id[0]; + int sw_state = wacom_wac->hid_data.barrelswitch | + (wacom_wac->hid_data.barrelswitch2 << 1); + + input_report_key(input, BTN_STYLUS, sw_state == 1); + input_report_key(input, BTN_STYLUS2, sw_state == 2); + input_report_key(input, BTN_STYLUS3, sw_state == 3); /* * Non-USI EMR tools should have their IDs mangled to @@ -3300,9 +3312,11 @@ int wacom_setup_pen_input_capabilities(struct input_dev *input_dev, else __set_bit(INPUT_PROP_POINTER, input_dev->propbit); - if (features->type == HID_GENERIC) - /* setup has already been done */ + if (features->type == HID_GENERIC) { + /* setup has already been done; apply otherwise-undetectible quirks */ + input_set_capability(input_dev, EV_KEY, BTN_STYLUS3); return 0; + } __set_bit(BTN_TOUCH, input_dev->keybit); __set_bit(ABS_MISC, input_dev->absbit); diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 8a03654048bf..69dda27e8dde 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -291,6 +291,8 @@ struct hid_data { bool inrange_state; bool invert_state; bool tipswitch; + bool barrelswitch; + bool barrelswitch2; int x; int y; int pressure; diff --git a/include/uapi/linux/input-event-codes.h b/include/uapi/linux/input-event-codes.h index 179891074b3c..9b3a522f50d1 100644 --- a/include/uapi/linux/input-event-codes.h +++ b/include/uapi/linux/input-event-codes.h @@ -406,6 +406,7 @@ #define BTN_TOOL_MOUSE 0x146 #define BTN_TOOL_LENS 0x147 #define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */ +#define BTN_STYLUS3 0x149 #define BTN_TOUCH 0x14a #define BTN_STYLUS 0x14b #define BTN_STYLUS2 0x14c -- cgit v1.2.3 From 5b01b3b8b122fde7fbe116803f7863667b4c5beb Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 3 Nov 2017 18:29:47 +0100 Subject: HID: Wacom: switch Dell canvas into highres mode The Dell Canvas exports 2 collections for the Pen part. The only difference between the 2 is that the default one has half the resolution of the second one. The Windows driver switches the tablet into the second mode, so we should behave the same. Signed-off-by: Benjamin Tissoires Reviewed-by: Jason Gerecke --- drivers/hid/wacom_sys.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 735bfbbcaa82..ab3178bef0b6 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -196,6 +196,13 @@ static void wacom_feature_mapping(struct hid_device *hdev, kfree(data); break; } + + if (hdev->vendor == USB_VENDOR_ID_WACOM && + hdev->product == 0x4200 /* Dell Canvas 27 */ && + field->application == HID_UP_MSVENDOR) { + wacom->wacom_wac.mode_report = field->report->id; + wacom->wacom_wac.mode_value = 2; + } } /* -- cgit v1.2.3