hid-input-quirks.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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_rel(c) hid_map_usage(hidinput, usage, bit, max, EV_REL, (c))
  17. #define map_key(c) hid_map_usage(hidinput, usage, bit, max, EV_KEY, (c))
  18. #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, bit, \
  19. max, EV_KEY, (c))
  20. static int quirk_belkin_wkbd(struct hid_usage *usage,
  21. struct hid_input *hidinput, unsigned long **bit, int *max)
  22. {
  23. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  24. return 0;
  25. switch (usage->hid & HID_USAGE) {
  26. case 0x03a: map_key_clear(KEY_SOUND); break;
  27. case 0x03b: map_key_clear(KEY_CAMERA); break;
  28. case 0x03c: map_key_clear(KEY_DOCUMENTS); break;
  29. default:
  30. return 0;
  31. }
  32. return 1;
  33. }
  34. static int quirk_cherry_cymotion(struct hid_usage *usage,
  35. struct hid_input *hidinput, unsigned long **bit, int *max)
  36. {
  37. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  38. return 0;
  39. switch (usage->hid & HID_USAGE) {
  40. case 0x301: map_key_clear(KEY_PROG1); break;
  41. case 0x302: map_key_clear(KEY_PROG2); break;
  42. case 0x303: map_key_clear(KEY_PROG3); break;
  43. default:
  44. return 0;
  45. }
  46. return 1;
  47. }
  48. static int quirk_gyration_remote(struct hid_usage *usage,
  49. struct hid_input *hidinput, unsigned long **bit, int *max)
  50. {
  51. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  52. return 0;
  53. set_bit(EV_REP, hidinput->input->evbit);
  54. switch(usage->hid & HID_USAGE) {
  55. /* Reported on Gyration MCE Remote */
  56. case 0x00d: map_key_clear(KEY_HOME); break;
  57. case 0x024: map_key_clear(KEY_DVD); break;
  58. case 0x025: map_key_clear(KEY_PVR); break;
  59. case 0x046: map_key_clear(KEY_MEDIA); break;
  60. case 0x047: map_key_clear(KEY_MP3); break;
  61. case 0x049: map_key_clear(KEY_CAMERA); break;
  62. case 0x04a: map_key_clear(KEY_VIDEO); break;
  63. default:
  64. return 0;
  65. }
  66. return 1;
  67. }
  68. static int quirk_chicony_tactical_pad(struct hid_usage *usage,
  69. struct hid_input *hidinput, unsigned long **bit, int *max)
  70. {
  71. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
  72. return 0;
  73. set_bit(EV_REP, hidinput->input->evbit);
  74. switch (usage->hid & HID_USAGE) {
  75. case 0xff01: map_key_clear(BTN_1); break;
  76. case 0xff02: map_key_clear(BTN_2); break;
  77. case 0xff03: map_key_clear(BTN_3); break;
  78. case 0xff04: map_key_clear(BTN_4); break;
  79. case 0xff05: map_key_clear(BTN_5); break;
  80. case 0xff06: map_key_clear(BTN_6); break;
  81. case 0xff07: map_key_clear(BTN_7); break;
  82. case 0xff08: map_key_clear(BTN_8); break;
  83. case 0xff09: map_key_clear(BTN_9); break;
  84. case 0xff0a: map_key_clear(BTN_A); break;
  85. case 0xff0b: map_key_clear(BTN_B); break;
  86. default:
  87. return 0;
  88. }
  89. return 1;
  90. }
  91. static int quirk_petalynx_remote(struct hid_usage *usage,
  92. struct hid_input *hidinput, unsigned long **bit, int *max)
  93. {
  94. if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
  95. ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
  96. return 0;
  97. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
  98. switch(usage->hid & HID_USAGE) {
  99. case 0x05a: map_key_clear(KEY_TEXT); break;
  100. case 0x05b: map_key_clear(KEY_RED); break;
  101. case 0x05c: map_key_clear(KEY_GREEN); break;
  102. case 0x05d: map_key_clear(KEY_YELLOW); break;
  103. case 0x05e: map_key_clear(KEY_BLUE); break;
  104. default:
  105. return 0;
  106. }
  107. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
  108. switch(usage->hid & HID_USAGE) {
  109. case 0x0f6: map_key_clear(KEY_NEXT); break;
  110. case 0x0fa: map_key_clear(KEY_BACK); break;
  111. default:
  112. return 0;
  113. }
  114. return 1;
  115. }
  116. static int quirk_cherry_genius_29e(struct hid_usage *usage,
  117. struct hid_input *hidinput, unsigned long **bit, int *max)
  118. {
  119. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  120. return 0;
  121. switch (usage->hid & HID_USAGE) {
  122. case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
  123. case 0x157: map_key_clear(KEY_SPREADSHEET); break;
  124. case 0x158: map_key_clear(KEY_PRESENTATION); break;
  125. case 0x15c: map_key_clear(KEY_STOP); break;
  126. default:
  127. return 0;
  128. }
  129. return 1;
  130. }
  131. static int quirk_btc_8193(struct hid_usage *usage, struct hid_input *hidinput,
  132. unsigned long **bit, int *max)
  133. {
  134. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  135. return 0;
  136. switch (usage->hid & HID_USAGE) {
  137. case 0x230: map_key(BTN_MOUSE); break;
  138. case 0x231: map_rel(REL_WHEEL); break;
  139. /*
  140. * this keyboard has a scrollwheel implemented in
  141. * totally broken way. We map this usage temporarily
  142. * to HWHEEL and handle it in the event quirk handler
  143. */
  144. case 0x232: map_rel(REL_HWHEEL); break;
  145. default:
  146. return 0;
  147. }
  148. return 1;
  149. }
  150. #define VENDOR_ID_BELKIN 0x1020
  151. #define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
  152. #define VENDOR_ID_CHERRY 0x046a
  153. #define DEVICE_ID_CHERRY_CYMOTION 0x0023
  154. #define VENDOR_ID_CHICONY 0x04f2
  155. #define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
  156. #define VENDOR_ID_EZKEY 0x0518
  157. #define DEVICE_ID_BTC_8193 0x0002
  158. #define VENDOR_ID_GYRATION 0x0c16
  159. #define DEVICE_ID_GYRATION_REMOTE 0x0002
  160. #define VENDOR_ID_MONTEREY 0x0566
  161. #define DEVICE_ID_GENIUS_KB29E 0x3004
  162. #define VENDOR_ID_PETALYNX 0x18b1
  163. #define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
  164. static const struct hid_input_blacklist {
  165. __u16 idVendor;
  166. __u16 idProduct;
  167. int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
  168. int *);
  169. } hid_input_blacklist[] = {
  170. { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
  171. { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion },
  172. { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
  173. { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
  174. { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
  175. { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
  176. { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
  177. { 0, 0, NULL }
  178. };
  179. int hidinput_mapping_quirks(struct hid_usage *usage,
  180. struct hid_input *hi, unsigned long **bit, int *max)
  181. {
  182. struct hid_device *device = input_get_drvdata(hi->input);
  183. int i = 0;
  184. while (hid_input_blacklist[i].quirk) {
  185. if (hid_input_blacklist[i].idVendor == device->vendor &&
  186. hid_input_blacklist[i].idProduct == device->product)
  187. return hid_input_blacklist[i].quirk(usage, hi, bit,
  188. max);
  189. i++;
  190. }
  191. return 0;
  192. }
  193. int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
  194. {
  195. struct input_dev *input;
  196. input = field->hidinput->input;
  197. /* handle the temporary quirky mapping to HWHEEL */
  198. if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
  199. usage->type == EV_REL && usage->code == REL_HWHEEL) {
  200. input_event(input, usage->type, REL_WHEEL, -value);
  201. return 1;
  202. }
  203. /* Gyration MCE remote "Sleep" key */
  204. if (hid->vendor == VENDOR_ID_GYRATION &&
  205. hid->product == DEVICE_ID_GYRATION_REMOTE &&
  206. (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  207. (usage->hid & 0xff) == 0x82) {
  208. input_event(input, usage->type, usage->code, 1);
  209. input_sync(input);
  210. input_event(input, usage->type, usage->code, 0);
  211. input_sync(input);
  212. return 1;
  213. }
  214. return 0;
  215. }