hid-ezkey.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <linux/device.h>
  14. #include <linux/input.h>
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include "hid-ids.h"
  18. #define ez_map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c))
  19. #define ez_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c))
  20. static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  21. struct hid_field *field, struct hid_usage *usage,
  22. unsigned long **bit, int *max)
  23. {
  24. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  25. return 0;
  26. switch (usage->hid & HID_USAGE) {
  27. case 0x230: ez_map_key(BTN_MOUSE); break;
  28. case 0x231: ez_map_rel(REL_WHEEL); break;
  29. /*
  30. * this keyboard has a scrollwheel implemented in
  31. * totally broken way. We map this usage temporarily
  32. * to HWHEEL and handle it in the event quirk handler
  33. */
  34. case 0x232: ez_map_rel(REL_HWHEEL); break;
  35. default:
  36. return 0;
  37. }
  38. return 1;
  39. }
  40. static int ez_event(struct hid_device *hdev, struct hid_field *field,
  41. struct hid_usage *usage, __s32 value)
  42. {
  43. if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
  44. !usage->type)
  45. return 0;
  46. /* handle the temporary quirky mapping to HWHEEL */
  47. if (usage->type == EV_REL && usage->code == REL_HWHEEL) {
  48. struct input_dev *input = field->hidinput->input;
  49. input_event(input, usage->type, REL_WHEEL, -value);
  50. return 1;
  51. }
  52. return 0;
  53. }
  54. static const struct hid_device_id ez_devices[] = {
  55. { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
  56. { }
  57. };
  58. MODULE_DEVICE_TABLE(hid, ez_devices);
  59. static struct hid_driver ez_driver = {
  60. .name = "ezkey",
  61. .id_table = ez_devices,
  62. .input_mapping = ez_input_mapping,
  63. .event = ez_event,
  64. };
  65. module_hid_driver(ez_driver);
  66. MODULE_LICENSE("GPL");