All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gerecke <killertofu@gmail.com>
To: linux-input@vger.kernel.org, Jiri Kosina <jkosina@suse.cz>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Ping Cheng <pinglinux@gmail.com>,
	Ping Cheng <ping.cheng@wacom.com>,
	Aaron Skomra <skomra@gmail.com>,
	Jason Gerecke <killertofu@gmail.com>,
	Jason Gerecke <jason.gerecke@wacom.com>
Subject: [PATCH v2 12/18] HID: wacom: generic: Support tool ID and additional tool types
Date: Fri,  7 Oct 2016 15:16:47 -0700	[thread overview]
Message-ID: <20161007221653.26941-12-killertofu@gmail.com> (raw)
In-Reply-To: <20161007221653.26941-1-killertofu@gmail.com>

Devices following the new Custom HID mode specification (as well as even
some recent component sensors which use the same standard HID usage)
are capable of reporting tool ID information that we need to relay to
userspace. This patch adds support for reading and relaying the tool
type information, which is (unfortunately) split across two usages.
We also advertise the existence of tool types beyond BTN_TOOL_PEN
that might be available.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/wacom_wac.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++---
 drivers/hid/wacom_wac.h |  4 ++-
 2 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 60f065b..f2aadc4 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -1450,6 +1450,8 @@ static int wacom_equivalent_usage(int usage)
 		if (subpage == WACOM_HID_SP_DIGITIZER ||
 		    subpage == WACOM_HID_SP_DIGITIZERINFO ||
 		    usage == WACOM_HID_WD_SENSE ||
+		    usage == WACOM_HID_WD_SERIALHI ||
+		    usage == WACOM_HID_WD_TOOLTYPE ||
 		    usage == WACOM_HID_WD_DISTANCE) {
 			return usage;
 		}
@@ -1551,6 +1553,17 @@ static void wacom_wac_pen_usage_mapping(struct hid_device *hdev,
 		features->quirks |= WACOM_QUIRK_SENSE;
 		wacom_map_usage(input, usage, field, EV_KEY, BTN_TOOL_PEN, 0);
 		break;
+	case WACOM_HID_WD_SERIALHI:
+		wacom_map_usage(input, usage, field, EV_ABS, ABS_MISC, 0);
+		set_bit(EV_KEY, input->evbit);
+		input_set_capability(input, EV_KEY, BTN_TOOL_PEN);
+		input_set_capability(input, EV_KEY, BTN_TOOL_RUBBER);
+		input_set_capability(input, EV_KEY, BTN_TOOL_BRUSH);
+		input_set_capability(input, EV_KEY, BTN_TOOL_PENCIL);
+		input_set_capability(input, EV_KEY, BTN_TOOL_AIRBRUSH);
+		input_set_capability(input, EV_KEY, BTN_TOOL_MOUSE);
+		input_set_capability(input, EV_KEY, BTN_TOOL_LENS);
+		break;
 	case WACOM_HID_WD_FINGERWHEEL:
 		wacom_map_usage(input, usage, field, EV_ABS, ABS_WHEEL, 0);
 		break;
@@ -1587,9 +1600,35 @@ static int wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field,
 	case HID_DG_TIPSWITCH:
 		wacom_wac->hid_data.tipswitch |= value;
 		return 0;
+	case HID_DG_TOOLSERIALNUMBER:
+		wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFF);
+		wacom_wac->serial[0] |= value;
+		return 0;
 	case WACOM_HID_WD_SENSE:
 		wacom_wac->hid_data.sense_state = value;
 		return 0;
+	case WACOM_HID_WD_SERIALHI:
+		wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF);
+		wacom_wac->serial[0] |= ((__u64)value) << 32;
+		/*
+		 * Non-USI EMR devices may contain additional tool type
+		 * information here. See WACOM_HID_WD_TOOLTYPE case for
+		 * more details.
+		 */
+		if (value >> 20 == 1) {
+			wacom_wac->id[0] |= value & 0xFFFFF;
+		}
+		return 0;
+	case WACOM_HID_WD_TOOLTYPE:
+		/*
+		 * Some devices (MobileStudio Pro, and possibly later
+		 * devices as well) do not return the complete tool
+		 * type in their WACOM_HID_WD_TOOLTYPE usage. Use a
+		 * bitwise OR so the complete value can be built
+		 * up over time :(
+		 */
+		wacom_wac->id[0] |= value;
+		return 0;
 	}
 
 	/* send pen events only when touch is up or forced out
@@ -1622,26 +1661,51 @@ static void wacom_wac_pen_report(struct hid_device *hdev,
 	bool prox = wacom_wac->hid_data.inrange_state;
 	bool range = wacom_wac->hid_data.sense_state;
 
-	if (!wacom_wac->tool[0] && prox) /* first in prox */
+	if (!wacom_wac->tool[0] && prox) { /* first in prox */
 		/* Going into proximity select tool */
-		wacom_wac->tool[0] = wacom_wac->hid_data.invert_state ?
-						BTN_TOOL_RUBBER : BTN_TOOL_PEN;
+		if (wacom_wac->hid_data.invert_state)
+			wacom_wac->tool[0] = BTN_TOOL_RUBBER;
+		else if (wacom_wac->id[0])
+			wacom_wac->tool[0] = wacom_intuos_get_tool_type(wacom_wac->id[0]);
+		else
+			wacom_wac->tool[0] = BTN_TOOL_PEN;
+	}
 
 	/* keep pen state for touch events */
 	wacom_wac->shared->stylus_in_proximity = range;
 
 	if (!delay_pen_events(wacom_wac) && wacom_wac->tool[0]) {
+		int id = wacom_wac->id[0];
+
+		/*
+		 * Non-USI EMR tools should have their IDs mangled to
+		 * match the legacy behavior of wacom_intuos_general
+		 */
+		if (wacom_wac->serial[0] >> 52 == 1)
+			id = wacom_intuos_id_mangle(id);
+
+		/*
+		 * To ensure compatibility with xf86-input-wacom, we should
+		 * report the BTN_TOOL_* event prior to the ABS_MISC or
+		 * MSC_SERIAL events.
+		 */
 		input_report_key(input, BTN_TOUCH,
 				wacom_wac->hid_data.tipswitch);
 		input_report_key(input, wacom_wac->tool[0], prox);
+		if (wacom_wac->serial[0]) {
+			input_event(input, EV_MSC, MSC_SERIAL, wacom_wac->serial[0]);
+			input_report_abs(input, ABS_MISC, id);
+		}
 
 		wacom_wac->hid_data.tipswitch = false;
 
 		input_sync(input);
 	}
 
-	if (!prox)
+	if (!prox) {
 		wacom_wac->tool[0] = 0;
+		wacom_wac->id[0] = 0;
+	}
 }
 
 static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index e8779c7..3926ff4 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -90,6 +90,8 @@
 #define WACOM_HID_SP_DIGITIZERINFO      0x00100000
 #define WACOM_HID_WD_DIGITIZER          (WACOM_HID_UP_WACOMDIGITIZER | 0x01)
 #define WACOM_HID_WD_SENSE              (WACOM_HID_UP_WACOMDIGITIZER | 0x36)
+#define WACOM_HID_WD_SERIALHI           (WACOM_HID_UP_WACOMDIGITIZER | 0x5c)
+#define WACOM_HID_WD_TOOLTYPE           (WACOM_HID_UP_WACOMDIGITIZER | 0x77)
 #define WACOM_HID_WD_DISTANCE           (WACOM_HID_UP_WACOMDIGITIZER | 0x0132)
 #define WACOM_HID_WD_FINGERWHEEL        (WACOM_HID_UP_WACOMDIGITIZER | 0x0d03)
 #define WACOM_HID_WD_DATAMODE           (WACOM_HID_UP_WACOMDIGITIZER | 0x1002)
@@ -247,7 +249,7 @@ struct wacom_wac {
 	unsigned char data[WACOM_PKGLEN_MAX];
 	int tool[2];
 	int id[2];
-	__u32 serial[2];
+	__u64 serial[2];
 	bool reporting_data;
 	struct wacom_features features;
 	struct wacom_shared *shared;
-- 
2.10.0


  parent reply	other threads:[~2016-10-07 22:18 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06 21:22 [PATCH 00/19] HID: wacom: Add support for MobileStudio Pro Jason Gerecke
2016-10-06 21:22 ` [PATCH 01/19] HID: wacom: Update vendor-defined usage names to better match standards Jason Gerecke
2016-10-06 21:22 ` [PATCH 02/19] HID: wacom: Have WACOM_PEN_FIELD and WACOM_FINGER_FIELD recgonize more fields Jason Gerecke
2016-10-06 21:22 ` [PATCH 03/19] HID: wacom: Refactor button-to-key translation into function Jason Gerecke
2016-10-06 21:22 ` [PATCH 04/19] HID: wacom: Detect and correct descriptors missing HID_DG_BARRELSWITCH2 Jason Gerecke
2016-10-06 21:22 ` [PATCH 05/19] HID: wacom: generic: Strip off excessive name prefixing Jason Gerecke
2016-10-06 21:22 ` [PATCH 06/19] HID: wacom: generic: Add support for height, tilt, and twist usages Jason Gerecke
2016-10-06 21:22 ` [PATCH 07/19] HID: wacom: generic: Support and use 'Custom HID' mode and usages Jason Gerecke
2016-10-06 21:22 ` [PATCH 08/19] HID: wacom: generic: Add support for vendor-defined "Distance" usage Jason Gerecke
2016-10-06 21:22 ` [PATCH 09/19] HID: wacom: generic: Add support for vendor-defined "Fingerwheel" usage Jason Gerecke
2016-10-06 21:22 ` [PATCH 10/19] HID: wacom: generic: Add support for vendor-defined "Sense" usage Jason Gerecke
2016-10-06 21:22 ` [PATCH 11/19] HID: wacom: Read and internally use corrected Intuos tool IDs Jason Gerecke
2016-10-06 21:22 ` [PATCH 12/19] HID: wacom: generic: Support tool ID and additional tool types Jason Gerecke
2016-10-06 21:22 ` [PATCH 13/19] HID: wacom: generic: Pass 'hdev' to 'wacom_map_usage' Jason Gerecke
2016-10-07 15:46   ` Benjamin Tissoires
2016-10-07 20:53     ` Jason Gerecke
2016-10-06 21:22 ` [PATCH 14/19] HID: wacom: Fix sensor outbounds and redefine as offsets from each edge Jason Gerecke
2016-10-06 21:22 ` [PATCH 15/19] HID: wacom: generic: Add support for sensor offsets Jason Gerecke
2016-10-06 21:22 ` [PATCH 16/19] HID: wacom: generic: Introduce pad support Jason Gerecke
2016-10-06 21:22 ` [PATCH 17/19] HID: wacom: generic: Add support for battery status on pen and pad interfaces Jason Gerecke
2016-10-06 21:22 ` [PATCH 18/19] HID: wacom: generic: Extend pad support Jason Gerecke
2016-10-06 21:22 ` [PATCH 19/19] HID: input: Recognize ABS_WHEEL in hidinput_calc_abs_res Jason Gerecke
2016-10-07 15:41 ` [PATCH 00/19] HID: wacom: Add support for MobileStudio Pro Benjamin Tissoires
2016-10-07 22:16 ` [PATCH v2 01/18] HID: wacom: Update vendor-defined usage names to better match standards Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 02/18] HID: wacom: Have WACOM_PEN_FIELD and WACOM_FINGER_FIELD recgonize more fields Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 03/18] HID: wacom: Refactor button-to-key translation into function Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 04/18] HID: wacom: Detect and correct descriptors missing HID_DG_BARRELSWITCH2 Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 05/18] HID: wacom: generic: Strip off excessive name prefixing Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 06/18] HID: wacom: generic: Add support for height, tilt, and twist usages Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 07/18] HID: wacom: generic: Support and use 'Custom HID' mode and usages Jason Gerecke
2016-10-18 15:26     ` Jiri Kosina
2016-10-18 17:09       ` Jason Gerecke
2016-10-18 21:39         ` Jiri Kosina
2016-10-20  1:04           ` Jason Gerecke
2016-10-20  8:32             ` Jiri Kosina
2016-10-07 22:16   ` [PATCH v2 08/18] HID: wacom: generic: Add support for vendor-defined "Distance" usage Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 09/18] HID: wacom: generic: Add support for vendor-defined "Fingerwheel" usage Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 10/18] HID: wacom: generic: Add support for vendor-defined "Sense" usage Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 11/18] HID: wacom: Read and internally use corrected Intuos tool IDs Jason Gerecke
2016-10-07 22:16   ` Jason Gerecke [this message]
2016-10-07 22:16   ` [PATCH v2 13/18] HID: wacom: Fix sensor outbounds and redefine as offsets from each edge Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 14/18] HID: wacom: generic: Add support for sensor offsets Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 15/18] HID: wacom: generic: Introduce pad support Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 16/18] HID: wacom: generic: Add support for battery status on pen and pad interfaces Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 17/18] HID: wacom: generic: Extend pad support Jason Gerecke
2016-10-07 22:16   ` [PATCH v2 18/18] HID: input: Recognize ABS_WHEEL in hidinput_calc_abs_res Jason Gerecke
2016-10-20  1:03 ` [PATCH v3 01/18] HID: wacom: Update vendor-defined usage names to better match standards Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 02/18] HID: wacom: Have WACOM_PEN_FIELD and WACOM_FINGER_FIELD recgonize more fields Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 03/18] HID: wacom: Refactor button-to-key translation into function Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 04/18] HID: wacom: Detect and correct descriptors missing HID_DG_BARRELSWITCH2 Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 05/18] HID: wacom: generic: Strip off excessive name prefixing Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 06/18] HID: wacom: generic: Add support for height, tilt, and twist usages Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 07/18] HID: wacom: generic: Support and use 'Custom HID' mode and usages Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 08/18] HID: wacom: generic: Add support for vendor-defined "Distance" usage Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 09/18] HID: wacom: generic: Add support for vendor-defined "Fingerwheel" usage Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 10/18] HID: wacom: generic: Add support for vendor-defined "Sense" usage Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 11/18] HID: wacom: Read and internally use corrected Intuos tool IDs Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 12/18] HID: wacom: generic: Support tool ID and additional tool types Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 13/18] HID: wacom: Fix sensor outbounds and redefine as offsets from each edge Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 14/18] HID: wacom: generic: Add support for sensor offsets Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 15/18] HID: wacom: generic: Introduce pad support Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 16/18] HID: wacom: generic: Add support for battery status on pen and pad interfaces Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 17/18] HID: wacom: generic: Extend pad support Jason Gerecke
2016-10-20  1:03   ` [PATCH v3 18/18] HID: input: Recognize ABS_WHEEL in hidinput_calc_abs_res Jason Gerecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161007221653.26941-12-killertofu@gmail.com \
    --to=killertofu@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jason.gerecke@wacom.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=ping.cheng@wacom.com \
    --cc=pinglinux@gmail.com \
    --cc=skomra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.