hid-input-quirks.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * HID-input usage mapping quirks
  3. *
  4. * This is used to handle HID-input mappings for devices violating
  5. * HUT 1.12 specification.
  6. *
  7. * Copyright (c) 2007-2008 Jiri Kosina
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License
  13. */
  14. #include <linux/input.h>
  15. #include <linux/hid.h>
  16. #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, bit, \
  17. max, EV_KEY, (c))
  18. static int quirk_gyration_remote(struct hid_usage *usage,
  19. struct hid_input *hidinput, unsigned long **bit, int *max)
  20. {
  21. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  22. return 0;
  23. set_bit(EV_REP, hidinput->input->evbit);
  24. switch(usage->hid & HID_USAGE) {
  25. /* Reported on Gyration MCE Remote */
  26. case 0x00d: map_key_clear(KEY_HOME); break;
  27. case 0x024: map_key_clear(KEY_DVD); break;
  28. case 0x025: map_key_clear(KEY_PVR); break;
  29. case 0x046: map_key_clear(KEY_MEDIA); break;
  30. case 0x047: map_key_clear(KEY_MP3); break;
  31. case 0x049: map_key_clear(KEY_CAMERA); break;
  32. case 0x04a: map_key_clear(KEY_VIDEO); break;
  33. default:
  34. return 0;
  35. }
  36. return 1;
  37. }
  38. static int quirk_petalynx_remote(struct hid_usage *usage,
  39. struct hid_input *hidinput, unsigned long **bit, int *max)
  40. {
  41. if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
  42. ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
  43. return 0;
  44. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
  45. switch(usage->hid & HID_USAGE) {
  46. case 0x05a: map_key_clear(KEY_TEXT); break;
  47. case 0x05b: map_key_clear(KEY_RED); break;
  48. case 0x05c: map_key_clear(KEY_GREEN); break;
  49. case 0x05d: map_key_clear(KEY_YELLOW); break;
  50. case 0x05e: map_key_clear(KEY_BLUE); break;
  51. default:
  52. return 0;
  53. }
  54. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
  55. switch(usage->hid & HID_USAGE) {
  56. case 0x0f6: map_key_clear(KEY_NEXT); break;
  57. case 0x0fa: map_key_clear(KEY_BACK); break;
  58. default:
  59. return 0;
  60. }
  61. return 1;
  62. }
  63. static int quirk_cherry_genius_29e(struct hid_usage *usage,
  64. struct hid_input *hidinput, unsigned long **bit, int *max)
  65. {
  66. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  67. return 0;
  68. switch (usage->hid & HID_USAGE) {
  69. case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
  70. case 0x157: map_key_clear(KEY_SPREADSHEET); break;
  71. case 0x158: map_key_clear(KEY_PRESENTATION); break;
  72. case 0x15c: map_key_clear(KEY_STOP); break;
  73. default:
  74. return 0;
  75. }
  76. return 1;
  77. }
  78. #define VENDOR_ID_GYRATION 0x0c16
  79. #define DEVICE_ID_GYRATION_REMOTE 0x0002
  80. #define VENDOR_ID_MONTEREY 0x0566
  81. #define DEVICE_ID_GENIUS_KB29E 0x3004
  82. #define VENDOR_ID_PETALYNX 0x18b1
  83. #define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
  84. static const struct hid_input_blacklist {
  85. __u16 idVendor;
  86. __u16 idProduct;
  87. int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
  88. int *);
  89. } hid_input_blacklist[] = {
  90. { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
  91. { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
  92. { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
  93. { 0, 0, NULL }
  94. };
  95. int hidinput_mapping_quirks(struct hid_usage *usage,
  96. struct hid_input *hi, unsigned long **bit, int *max)
  97. {
  98. struct hid_device *device = input_get_drvdata(hi->input);
  99. int i = 0;
  100. while (hid_input_blacklist[i].quirk) {
  101. if (hid_input_blacklist[i].idVendor == device->vendor &&
  102. hid_input_blacklist[i].idProduct == device->product)
  103. return hid_input_blacklist[i].quirk(usage, hi, bit,
  104. max);
  105. i++;
  106. }
  107. return 0;
  108. }
  109. int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
  110. {
  111. struct input_dev *input;
  112. input = field->hidinput->input;
  113. /* Gyration MCE remote "Sleep" key */
  114. if (hid->vendor == VENDOR_ID_GYRATION &&
  115. hid->product == DEVICE_ID_GYRATION_REMOTE &&
  116. (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  117. (usage->hid & 0xff) == 0x82) {
  118. input_event(input, usage->type, usage->code, 1);
  119. input_sync(input);
  120. input_event(input, usage->type, usage->code, 0);
  121. input_sync(input);
  122. return 1;
  123. }
  124. return 0;
  125. }