hid-ezkey.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. #include <linux/device.h>
  18. #include <linux/input.h>
  19. #include <linux/hid.h>
  20. #include <linux/module.h>
  21. #include "hid-ids.h"
  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. static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  25. struct hid_field *field, struct hid_usage *usage,
  26. unsigned long **bit, int *max)
  27. {
  28. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  29. return 0;
  30. switch (usage->hid & HID_USAGE) {
  31. case 0x230: ez_map_key(BTN_MOUSE); break;
  32. case 0x231: ez_map_rel(REL_WHEEL); break;
  33. /*
  34. * this keyboard has a scrollwheel implemented in
  35. * totally broken way. We map this usage temporarily
  36. * to HWHEEL and handle it in the event quirk handler
  37. */
  38. case 0x232: ez_map_rel(REL_HWHEEL); break;
  39. default:
  40. return 0;
  41. }
  42. return 1;
  43. }
  44. static int ez_event(struct hid_device *hdev, struct hid_field *field,
  45. struct hid_usage *usage, __s32 value)
  46. {
  47. if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
  48. !usage->type)
  49. return 0;
  50. /* handle the temporary quirky mapping to HWHEEL */
  51. if (usage->type == EV_REL && usage->code == REL_HWHEEL) {
  52. struct input_dev *input = field->hidinput->input;
  53. input_event(input, usage->type, REL_WHEEL, -value);
  54. return 1;
  55. }
  56. return 0;
  57. }
  58. static const struct hid_device_id ez_devices[] = {
  59. { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
  60. { }
  61. };
  62. MODULE_DEVICE_TABLE(hid, ez_devices);
  63. static struct hid_driver ez_driver = {
  64. .name = "ezkey",
  65. .id_table = ez_devices,
  66. .input_mapping = ez_input_mapping,
  67. .event = ez_event,
  68. };
  69. static int __init ez_init(void)
  70. {
  71. return hid_register_driver(&ez_driver);
  72. }
  73. static void __exit ez_exit(void)
  74. {
  75. hid_unregister_driver(&ez_driver);
  76. }
  77. module_init(ez_init);
  78. module_exit(ez_exit);
  79. MODULE_LICENSE("GPL");