From 29b9e14846f1ff201c4c1ba4fdb868dcdce6c760 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 25 Jun 2018 13:24:34 -0700 Subject: HID: wacom: Replace touch_max fixup code with static touch_max definitions Detecting the number of supported touches for a particular device used to be tricky, both because early forms of the driver didn't have a very good HID parser and because early hardware didn't always advertise the actual number. At the time, we added a block of code which would ensure that touch_max would always be equal to at least 1 on any touch device, and relied on setting touch_max to e.g. 2 only for the multitouch-capable exceptions. The common case has since flipped, and the driver and descriptors can reliably detect the number of touches supported by modern sensors. Because of this, it makes sense to remove the fixup code and instead place static declarations of "touch_max = 1" for these old devices. It isn't entirely clear if all 2-finger devices actually report a maximum number of touches so we leave these declarations still in place. For the eagle-eyed, the "> BAMBOO_PT" condition was originally equivalent to ">= TABLETPC", which is what the intent was. This commit doesn't have to consider the types introduced in the interim since they shouldn't be affected, hence why only the tablet PC definitions have been modified. Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index d6797535fff9..6b67c6907caa 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -361,16 +361,6 @@ static void wacom_usage_mapping(struct hid_device *hdev, else return; - /* - * Bamboo models do not support HID_DG_CONTACTMAX. - * And, Bamboo Pen only descriptor contains touch. - */ - if (features->type > BAMBOO_PT) { - /* ISDv4 touch devices at least supports one touch point */ - if (finger && !features->touch_max) - features->touch_max = 1; - } - /* * ISDv4 devices which predate HID's adoption of the * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its -- cgit v1.2.3 From 578325120ec122db98b3d57e833d16c1bdac6ec6 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 25 Jun 2018 13:24:35 -0700 Subject: HID: wacom: Move handling of HID quirks into a dedicated function We want to keep device-specific quirks as contained as possible so that the the code remains maintainable. Our 'wacom_setup_device_quirks' function is the usual place for this, but some quirks need to be applied to the HID descriptor as it is parsed. This commit introduces a new function which is called for each usage so that any HID-specific quirks can be applied. The function now houses quirks that were being done in 'wacom_feature_mapping' and 'wacom_usage_mapping'. Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 92 +++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 38 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 6b67c6907caa..3a4cf2666a7c 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -210,6 +210,57 @@ static int wacom_calc_hid_res(int logical_extents, int physical_extents, return hidinput_calc_abs_res(&field, ABS_X); } +static void wacom_hid_usage_quirk(struct hid_device *hdev, + struct hid_field *field, struct hid_usage *usage) +{ + struct wacom *wacom = hid_get_drvdata(hdev); + struct wacom_features *features = &wacom->wacom_wac.features; + unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); + + /* + * The Dell Canvas 27 needs to be switched to its vendor-defined + * report to provide the best resolution. + */ + if (hdev->vendor == USB_VENDOR_ID_WACOM && + hdev->product == 0x4200 && + field->application == HID_UP_MSVENDOR) { + wacom->wacom_wac.mode_report = field->report->id; + wacom->wacom_wac.mode_value = 2; + } + + /* + * ISDv4 devices which predate HID's adoption of the + * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its + * position instead. We can accurately detect if a + * usage with that value should be HID_DG_BARRELSWITCH2 + * based on the surrounding usages, which have remained + * constant across generations. + */ + if (features->type == HID_GENERIC && + usage->hid == 0x000D0000 && + field->application == HID_DG_PEN && + field->physical == HID_DG_STYLUS) { + int i = usage->usage_index; + + if (i-4 >= 0 && i+1 < field->maxusage && + field->usage[i-4].hid == HID_DG_TIPSWITCH && + field->usage[i-3].hid == HID_DG_BARRELSWITCH && + field->usage[i-2].hid == HID_DG_ERASER && + field->usage[i-1].hid == HID_DG_INVERT && + field->usage[i+1].hid == HID_DG_INRANGE) { + usage->hid = HID_DG_BARRELSWITCH2; + } + } + + /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ + if (hdev->vendor == USB_VENDOR_ID_WACOM && + hdev->product == 0x0358 && + WACOM_PEN_FIELD(field) && + equivalent_usage == HID_GD_Y) { + field->logical_maximum = 43200; + } +} + static void wacom_feature_mapping(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage) { @@ -221,6 +272,8 @@ static void wacom_feature_mapping(struct hid_device *hdev, int ret; u32 n; + wacom_hid_usage_quirk(hdev, field, usage); + switch (equivalent_usage) { case HID_DG_CONTACTMAX: /* leave touch_max as is if predefined */ @@ -300,13 +353,6 @@ 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; - } } /* @@ -361,37 +407,7 @@ static void wacom_usage_mapping(struct hid_device *hdev, else return; - /* - * ISDv4 devices which predate HID's adoption of the - * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its - * position instead. We can accurately detect if a - * usage with that value should be HID_DG_BARRELSWITCH2 - * based on the surrounding usages, which have remained - * constant across generations. - */ - if (features->type == HID_GENERIC && - usage->hid == 0x000D0000 && - field->application == HID_DG_PEN && - field->physical == HID_DG_STYLUS) { - int i = usage->usage_index; - - if (i-4 >= 0 && i+1 < field->maxusage && - field->usage[i-4].hid == HID_DG_TIPSWITCH && - field->usage[i-3].hid == HID_DG_BARRELSWITCH && - field->usage[i-2].hid == HID_DG_ERASER && - field->usage[i-1].hid == HID_DG_INVERT && - field->usage[i+1].hid == HID_DG_INRANGE) { - usage->hid = HID_DG_BARRELSWITCH2; - } - } - - /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ - if (hdev->vendor == USB_VENDOR_ID_WACOM && - hdev->product == 0x0358 && - WACOM_PEN_FIELD(field) && - wacom_equivalent_usage(usage->hid) == HID_GD_Y) { - field->logical_maximum = 43200; - } + wacom_hid_usage_quirk(hdev, field, usage); switch (usage->hid) { case HID_GD_X: -- cgit v1.2.3 From 418b573b431310306db31e445594317ba62f5508 Mon Sep 17 00:00:00 2001 From: Ping Cheng Date: Mon, 25 Jun 2018 13:24:36 -0700 Subject: HID: wacom: convert Wacom custom usages to standard HID usages Otherwise the switch would not catch the proper usages. Signed-off-by: Ping Cheng Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 3a4cf2666a7c..52e85d21e40f 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -394,6 +394,7 @@ static void wacom_usage_mapping(struct hid_device *hdev, struct wacom_features *features = &wacom->wacom_wac.features; bool finger = WACOM_FINGER_FIELD(field); bool pen = WACOM_PEN_FIELD(field); + unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); /* * Requiring Stylus Usage will ignore boot mouse @@ -409,7 +410,7 @@ static void wacom_usage_mapping(struct hid_device *hdev, wacom_hid_usage_quirk(hdev, field, usage); - switch (usage->hid) { + switch (equivalent_usage) { case HID_GD_X: features->x_max = field->logical_maximum; if (finger) { -- cgit v1.2.3