hid-gyration.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * HID driver for some gyration "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) 2007 Paul Walmsley
  8. * Copyright (c) 2008 Jiri Slaby
  9. * Copyright (c) 2006-2008 Jiri Kosina
  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 gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  23. EV_KEY, (c))
  24. static int gyration_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_LOGIVENDOR)
  29. return 0;
  30. set_bit(EV_REP, hi->input->evbit);
  31. switch (usage->hid & HID_USAGE) {
  32. /* Reported on Gyration MCE Remote */
  33. case 0x00d: gy_map_key_clear(KEY_HOME); break;
  34. case 0x024: gy_map_key_clear(KEY_DVD); break;
  35. case 0x025: gy_map_key_clear(KEY_PVR); break;
  36. case 0x046: gy_map_key_clear(KEY_MEDIA); break;
  37. case 0x047: gy_map_key_clear(KEY_MP3); break;
  38. case 0x048: gy_map_key_clear(KEY_MEDIA); break;
  39. case 0x049: gy_map_key_clear(KEY_CAMERA); break;
  40. case 0x04a: gy_map_key_clear(KEY_VIDEO); break;
  41. default:
  42. return 0;
  43. }
  44. return 1;
  45. }
  46. static int gyration_event(struct hid_device *hdev, struct hid_field *field,
  47. struct hid_usage *usage, __s32 value)
  48. {
  49. struct input_dev *input = field->hidinput->input;
  50. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  51. (usage->hid & 0xff) == 0x82) {
  52. input_event(input, usage->type, usage->code, 1);
  53. input_sync(input);
  54. input_event(input, usage->type, usage->code, 0);
  55. input_sync(input);
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. static const struct hid_device_id gyration_devices[] = {
  61. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
  62. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
  63. { }
  64. };
  65. MODULE_DEVICE_TABLE(hid, gyration_devices);
  66. static struct hid_driver gyration_driver = {
  67. .name = "gyration",
  68. .id_table = gyration_devices,
  69. .input_mapping = gyration_input_mapping,
  70. .event = gyration_event,
  71. };
  72. static int gyration_init(void)
  73. {
  74. return hid_register_driver(&gyration_driver);
  75. }
  76. static void gyration_exit(void)
  77. {
  78. hid_unregister_driver(&gyration_driver);
  79. }
  80. module_init(gyration_init);
  81. module_exit(gyration_exit);
  82. MODULE_LICENSE("GPL");