hid-gyration.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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) 2008 Jiri Slaby
  8. * Copyright (c) 2006-2008 Jiri Kosina
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/input.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include "hid-ids.h"
  21. #define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  22. EV_KEY, (c))
  23. static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  24. struct hid_field *field, struct hid_usage *usage,
  25. unsigned long **bit, int *max)
  26. {
  27. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  28. return 0;
  29. set_bit(EV_REP, hi->input->evbit);
  30. switch (usage->hid & HID_USAGE) {
  31. /* Reported on Gyration MCE Remote */
  32. case 0x00d: gy_map_key_clear(KEY_HOME); break;
  33. case 0x024: gy_map_key_clear(KEY_DVD); break;
  34. case 0x025: gy_map_key_clear(KEY_PVR); break;
  35. case 0x046: gy_map_key_clear(KEY_MEDIA); break;
  36. case 0x047: gy_map_key_clear(KEY_MP3); break;
  37. case 0x048: gy_map_key_clear(KEY_MEDIA); break;
  38. case 0x049: gy_map_key_clear(KEY_CAMERA); break;
  39. case 0x04a: gy_map_key_clear(KEY_VIDEO); break;
  40. case 0x05a: gy_map_key_clear(KEY_TEXT); break;
  41. case 0x05b: gy_map_key_clear(KEY_RED); break;
  42. case 0x05c: gy_map_key_clear(KEY_GREEN); break;
  43. case 0x05d: gy_map_key_clear(KEY_YELLOW); break;
  44. case 0x05e: gy_map_key_clear(KEY_BLUE); break;
  45. default:
  46. return 0;
  47. }
  48. return 1;
  49. }
  50. static int gyration_event(struct hid_device *hdev, struct hid_field *field,
  51. struct hid_usage *usage, __s32 value)
  52. {
  53. if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
  54. return 0;
  55. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  56. (usage->hid & 0xff) == 0x82) {
  57. struct input_dev *input = field->hidinput->input;
  58. input_event(input, usage->type, usage->code, 1);
  59. input_sync(input);
  60. input_event(input, usage->type, usage->code, 0);
  61. input_sync(input);
  62. return 1;
  63. }
  64. return 0;
  65. }
  66. static const struct hid_device_id gyration_devices[] = {
  67. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
  68. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
  69. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
  70. { }
  71. };
  72. MODULE_DEVICE_TABLE(hid, gyration_devices);
  73. static struct hid_driver gyration_driver = {
  74. .name = "gyration",
  75. .id_table = gyration_devices,
  76. .input_mapping = gyration_input_mapping,
  77. .event = gyration_event,
  78. };
  79. module_hid_driver(gyration_driver);
  80. MODULE_LICENSE("GPL");