Skip to content

Commit

Permalink
HID: wacom: Discover device_type from HID descriptor for all devices
Browse files Browse the repository at this point in the history
Currently, we assume a device_type of BTN_TOOL_PEN before scanning the
HID descriptor and then change the device_type if what we discover
proves that assumption wrong. This way of doing things makes it more
difficult to figure out if a device (particularly a HID_GENERIC device)
actually does tablet/touch input or is something completley different.

This patch leaves device_type at its initial value of 0 and then calls
'wacom_parse_hid' for every device (not just those that have touch).
As we map the usages, we can set the device_type as before. After we're
finished, we can then check if the value is still zero and do whatever
is most appropriate.

Detecting the pen can be a little tricky on most Wacom devices because
the descriptors describe opaque blobs. Fortunately, older Wacom tablets
have the HID_DG_DIGITIZER usage on the pen's application collection and
newer tablets seem to have a similar vendor-defined usage that we can
trigger on.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Reviewed-by: Ping Cheng <pingc@wacom.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Jason Gerecke authored and Jiri Kosina committed May 4, 2015
1 parent 8d80f79 commit 042628a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
23 changes: 13 additions & 10 deletions drivers/hid/wacom_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ static void wacom_usage_mapping(struct hid_device *hdev,
* X/Y values and some cases of invalid Digitizer X/Y
* values commonly reported.
*/
if (!pen && !finger)
if (pen)
features->device_type = BTN_TOOL_PEN;
else if (finger)
features->device_type = BTN_TOOL_FINGER;
else
return;

/*
Expand All @@ -198,14 +202,11 @@ static void wacom_usage_mapping(struct hid_device *hdev,
case HID_GD_X:
features->x_max = field->logical_maximum;
if (finger) {
features->device_type = BTN_TOOL_FINGER;
features->x_phy = field->physical_maximum;
if (features->type != BAMBOO_PT) {
features->unit = field->unit;
features->unitExpo = field->unit_exponent;
}
} else {
features->device_type = BTN_TOOL_PEN;
}
break;
case HID_GD_Y:
Expand Down Expand Up @@ -425,7 +426,6 @@ static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
struct usb_interface *intf = wacom->intf;

/* default features */
features->device_type = BTN_TOOL_PEN;
features->x_fuzz = 4;
features->y_fuzz = 4;
features->pressure_fuzz = 0;
Expand All @@ -446,10 +446,6 @@ static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
}
}

/* only devices that support touch need to retrieve the info */
if (features->type < BAMBOO_PT)
return;

wacom_parse_hid(hdev, features);
}

Expand Down Expand Up @@ -1529,8 +1525,15 @@ static int wacom_probe(struct hid_device *hdev,

/* Retrieve the physical and logical size for touch devices */
wacom_retrieve_hid_descriptor(hdev, features);

wacom_setup_device_quirks(wacom);

if (!features->device_type && features->type != WIRELESS) {
dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.",
hdev->name, "Assuming pen");

features->device_type = BTN_TOOL_PEN;
}

wacom_calculate_res(features);

wacom_update_name(wacom);
Expand Down
8 changes: 5 additions & 3 deletions drivers/hid/wacom_wac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2186,13 +2186,15 @@ void wacom_setup_device_quirks(struct wacom *wacom)

features->x_max = 4096;
features->y_max = 4096;
} else {
features->device_type = BTN_TOOL_PEN;
}
}

/*
* Same thing for Bamboo PAD
* Raw Wacom-mode pen and touch events both come from interface
* 0, whose HID descriptor has an application usage of 0xFF0D
* (i.e., WACOM_VENDORDEFINED_PEN). We route pen packets back
* out through the HID_GENERIC device created for interface 1,
* so rewrite this one to be of type BTN_TOOL_FINGER.
*/
if (features->type == BAMBOO_PAD)
features->device_type = BTN_TOOL_FINGER;
Expand Down
6 changes: 5 additions & 1 deletion drivers/hid/wacom_wac.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@
#define WACOM_QUIRK_MONITOR 0x0004
#define WACOM_QUIRK_BATTERY 0x0008

#define WACOM_VENDORDEFINED_PEN 0xff0d0001

#define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \
((f)->physical == HID_DG_STYLUS) || \
((f)->physical == HID_DG_PEN) || \
((f)->application == HID_DG_PEN))
((f)->application == HID_DG_PEN) || \
((f)->application == HID_DG_DIGITIZER) || \
((f)->application == WACOM_VENDORDEFINED_PEN))
#define WACOM_FINGER_FIELD(f) (((f)->logical == HID_DG_FINGER) || \
((f)->physical == HID_DG_FINGER) || \
((f)->application == HID_DG_TOUCHSCREEN))
Expand Down

0 comments on commit 042628a

Please sign in to comment.