Skip to content

Commit 1c703b5

Browse files
Nicolas Saenz JulienneJiri Kosina
authored andcommitted
HID: input: fix a4tech horizontal wheel custom usage
Some a4tech mice use the 'GenericDesktop.00b8' usage to inform whether the previous wheel report was horizontal or vertical. Before c01908a ("HID: input: add mapping for "Toggle Display" key") this usage was being mapped to 'Relative.Misc'. After the patch it's simply ignored (usage->type == 0 & usage->code == 0). Which ultimately makes hid-a4tech ignore the WHEEL/HWHEEL selection event, as it has no usage->type. We shouldn't rely on a mapping for that usage as it's nonstandard and doesn't really map to an input event. So we bypass the mapping and make sure the custom event handling properly handles both reports. Fixes: c01908a ("HID: input: add mapping for "Toggle Display" key") Signed-off-by: Nicolas Saenz Julienne <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 49869d2 commit 1c703b5

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

drivers/hid/hid-a4tech.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,36 @@
2323
#define A4_2WHEEL_MOUSE_HACK_7 0x01
2424
#define A4_2WHEEL_MOUSE_HACK_B8 0x02
2525

26+
#define A4_WHEEL_ORIENTATION (HID_UP_GENDESK | 0x000000b8)
27+
2628
struct a4tech_sc {
2729
unsigned long quirks;
2830
unsigned int hw_wheel;
2931
__s32 delayed_value;
3032
};
3133

34+
static int a4_input_mapping(struct hid_device *hdev, struct hid_input *hi,
35+
struct hid_field *field, struct hid_usage *usage,
36+
unsigned long **bit, int *max)
37+
{
38+
struct a4tech_sc *a4 = hid_get_drvdata(hdev);
39+
40+
if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8 &&
41+
usage->hid == A4_WHEEL_ORIENTATION) {
42+
/*
43+
* We do not want to have this usage mapped to anything as it's
44+
* nonstandard and doesn't really behave like an HID report.
45+
* It's only selecting the orientation (vertical/horizontal) of
46+
* the previous mouse wheel report. The input_events will be
47+
* generated once both reports are recorded in a4_event().
48+
*/
49+
return -1;
50+
}
51+
52+
return 0;
53+
54+
}
55+
3256
static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
3357
struct hid_field *field, struct hid_usage *usage,
3458
unsigned long **bit, int *max)
@@ -52,8 +76,7 @@ static int a4_event(struct hid_device *hdev, struct hid_field *field,
5276
struct a4tech_sc *a4 = hid_get_drvdata(hdev);
5377
struct input_dev *input;
5478

55-
if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
56-
!usage->type)
79+
if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
5780
return 0;
5881

5982
input = field->hidinput->input;
@@ -64,7 +87,7 @@ static int a4_event(struct hid_device *hdev, struct hid_field *field,
6487
return 1;
6588
}
6689

67-
if (usage->hid == 0x000100b8) {
90+
if (usage->hid == A4_WHEEL_ORIENTATION) {
6891
input_event(input, EV_REL, value ? REL_HWHEEL :
6992
REL_WHEEL, a4->delayed_value);
7093
input_event(input, EV_REL, value ? REL_HWHEEL_HI_RES :
@@ -131,6 +154,7 @@ MODULE_DEVICE_TABLE(hid, a4_devices);
131154
static struct hid_driver a4_driver = {
132155
.name = "a4tech",
133156
.id_table = a4_devices,
157+
.input_mapping = a4_input_mapping,
134158
.input_mapped = a4_input_mapped,
135159
.event = a4_event,
136160
.probe = a4_probe,

0 commit comments

Comments
 (0)