Jiri Slaby | 1f243e3 | 2008-06-24 21:11:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for some ezkey "special" devices |
| 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
| 7 | * Copyright (c) 2006-2007 Jiri Kosina |
| 8 | * Copyright (c) 2007 Paul Walmsley |
| 9 | * Copyright (c) 2008 Jiri Slaby |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the Free |
| 15 | * Software Foundation; either version 2 of the License, or (at your option) |
| 16 | * any later version. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/input.h> |
| 21 | #include <linux/hid.h> |
| 22 | #include <linux/module.h> |
| 23 | |
| 24 | #include "hid-ids.h" |
| 25 | |
| 26 | #define ez_map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c)) |
| 27 | #define ez_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c)) |
| 28 | |
| 29 | static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 30 | struct hid_field *field, struct hid_usage *usage, |
| 31 | unsigned long **bit, int *max) |
| 32 | { |
| 33 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) |
| 34 | return 0; |
| 35 | |
| 36 | switch (usage->hid & HID_USAGE) { |
| 37 | case 0x230: ez_map_key(BTN_MOUSE); break; |
| 38 | case 0x231: ez_map_rel(REL_WHEEL); break; |
| 39 | /* |
| 40 | * this keyboard has a scrollwheel implemented in |
| 41 | * totally broken way. We map this usage temporarily |
| 42 | * to HWHEEL and handle it in the event quirk handler |
| 43 | */ |
| 44 | case 0x232: ez_map_rel(REL_HWHEEL); break; |
| 45 | default: |
| 46 | return 0; |
| 47 | } |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | static int ez_event(struct hid_device *hdev, struct hid_field *field, |
| 52 | struct hid_usage *usage, __s32 value) |
| 53 | { |
| 54 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || |
| 55 | !usage->type) |
| 56 | return 0; |
| 57 | |
| 58 | /* handle the temporary quirky mapping to HWHEEL */ |
| 59 | if (usage->type == EV_REL && usage->code == REL_HWHEEL) { |
| 60 | struct input_dev *input = field->hidinput->input; |
| 61 | input_event(input, usage->type, REL_WHEEL, -value); |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static const struct hid_device_id ez_devices[] = { |
| 69 | { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) }, |
| 70 | { } |
| 71 | }; |
| 72 | MODULE_DEVICE_TABLE(hid, ez_devices); |
| 73 | |
| 74 | static struct hid_driver ez_driver = { |
| 75 | .name = "ezkey", |
| 76 | .id_table = ez_devices, |
| 77 | .input_mapping = ez_input_mapping, |
| 78 | .event = ez_event, |
| 79 | }; |
| 80 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 81 | static int __init ez_init(void) |
Jiri Slaby | 1f243e3 | 2008-06-24 21:11:21 +0200 | [diff] [blame] | 82 | { |
| 83 | return hid_register_driver(&ez_driver); |
| 84 | } |
| 85 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 86 | static void __exit ez_exit(void) |
Jiri Slaby | 1f243e3 | 2008-06-24 21:11:21 +0200 | [diff] [blame] | 87 | { |
| 88 | hid_unregister_driver(&ez_driver); |
| 89 | } |
| 90 | |
| 91 | module_init(ez_init); |
| 92 | module_exit(ez_exit); |
| 93 | MODULE_LICENSE("GPL"); |