1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * HID driver for some ezkey "special" devices
4 *
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
8 * Copyright (c) 2006-2007 Jiri Kosina
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12 /*
13 */
14
15 #include <linux/device.h>
16 #include <linux/input.h>
17 #include <linux/hid.h>
18 #include <linux/module.h>
19
20 #include "hid-ids.h"
21
22 #define ez_map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c))
23 #define ez_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c))
24
ez_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)25 static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi,
26 struct hid_field *field, struct hid_usage *usage,
27 unsigned long **bit, int *max)
28 {
29 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
30 return 0;
31
32 switch (usage->hid & HID_USAGE) {
33 case 0x230: ez_map_key(BTN_MOUSE); break;
34 case 0x231: ez_map_rel(REL_WHEEL); break;
35 /*
36 * this keyboard has a scrollwheel implemented in
37 * totally broken way. We map this usage temporarily
38 * to HWHEEL and handle it in the event quirk handler
39 */
40 case 0x232: ez_map_rel(REL_HWHEEL); break;
41 default:
42 return 0;
43 }
44 return 1;
45 }
46
ez_event(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage,__s32 value)47 static int ez_event(struct hid_device *hdev, struct hid_field *field,
48 struct hid_usage *usage, __s32 value)
49 {
50 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
51 !usage->type)
52 return 0;
53
54 /* handle the temporary quirky mapping to HWHEEL */
55 if (usage->type == EV_REL && usage->code == REL_HWHEEL) {
56 struct input_dev *input = field->hidinput->input;
57 input_event(input, usage->type, REL_WHEEL, -value);
58 return 1;
59 }
60
61 return 0;
62 }
63
64 static const struct hid_device_id ez_devices[] = {
65 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
66 { }
67 };
68 MODULE_DEVICE_TABLE(hid, ez_devices);
69
70 static struct hid_driver ez_driver = {
71 .name = "ezkey",
72 .id_table = ez_devices,
73 .input_mapping = ez_input_mapping,
74 .event = ez_event,
75 };
76 module_hid_driver(ez_driver);
77
78 MODULE_DESCRIPTION("HID driver for some ezkey \"special\" devices");
79 MODULE_LICENSE("GPL");
80