hid-input-quirks.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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_abs(c) do { usage->code = c; usage->type = EV_ABS; *bit = input->absbit; *max = ABS_MAX; } while (0)
  17. #define map_rel(c) do { usage->code = c; usage->type = EV_REL; *bit = input->relbit; *max = REL_MAX; } while (0)
  18. #define map_key(c) do { usage->code = c; usage->type = EV_KEY; *bit = input->keybit; *max = KEY_MAX; } while (0)
  19. #define map_led(c) do { usage->code = c; usage->type = EV_LED; *bit = input->ledbit; *max = LED_MAX; } while (0)
  20. #define map_abs_clear(c) do { map_abs(c); clear_bit(c, *bit); } while (0)
  21. #define map_key_clear(c) do { map_key(c); clear_bit(c, *bit); } while (0)
  22. static int quirk_belkin_wkbd(struct hid_usage *usage, struct input_dev *input,
  23. unsigned long **bit, int *max)
  24. {
  25. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  26. return 0;
  27. switch (usage->hid & HID_USAGE) {
  28. case 0x03a: map_key_clear(KEY_SOUND); break;
  29. case 0x03b: map_key_clear(KEY_CAMERA); break;
  30. case 0x03c: map_key_clear(KEY_DOCUMENTS); break;
  31. default:
  32. return 0;
  33. }
  34. return 1;
  35. }
  36. static int quirk_cherry_cymotion(struct hid_usage *usage, struct input_dev *input,
  37. unsigned long **bit, int *max)
  38. {
  39. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  40. return 0;
  41. switch (usage->hid & HID_USAGE) {
  42. case 0x301: map_key_clear(KEY_PROG1); break;
  43. case 0x302: map_key_clear(KEY_PROG2); break;
  44. case 0x303: map_key_clear(KEY_PROG3); break;
  45. default:
  46. return 0;
  47. }
  48. return 1;
  49. }
  50. static int quirk_logitech_ultrax_remote(struct hid_usage *usage, struct input_dev *input,
  51. unsigned long **bit, int *max)
  52. {
  53. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  54. return 0;
  55. set_bit(EV_REP, input->evbit);
  56. switch(usage->hid & HID_USAGE) {
  57. /* Reported on Logitech Ultra X Media Remote */
  58. case 0x004: map_key_clear(KEY_AGAIN); break;
  59. case 0x00d: map_key_clear(KEY_HOME); break;
  60. case 0x024: map_key_clear(KEY_SHUFFLE); break;
  61. case 0x025: map_key_clear(KEY_TV); break;
  62. case 0x026: map_key_clear(KEY_MENU); break;
  63. case 0x031: map_key_clear(KEY_AUDIO); break;
  64. case 0x032: map_key_clear(KEY_TEXT); break;
  65. case 0x033: map_key_clear(KEY_LAST); break;
  66. case 0x047: map_key_clear(KEY_MP3); break;
  67. case 0x048: map_key_clear(KEY_DVD); break;
  68. case 0x049: map_key_clear(KEY_MEDIA); break;
  69. case 0x04a: map_key_clear(KEY_VIDEO); break;
  70. case 0x04b: map_key_clear(KEY_ANGLE); break;
  71. case 0x04c: map_key_clear(KEY_LANGUAGE); break;
  72. case 0x04d: map_key_clear(KEY_SUBTITLE); break;
  73. case 0x051: map_key_clear(KEY_RED); break;
  74. case 0x052: map_key_clear(KEY_CLOSE); break;
  75. default:
  76. return 0;
  77. }
  78. return 1;
  79. }
  80. static int quirk_chicony_tactical_pad(struct hid_usage *usage, struct input_dev *input,
  81. unsigned long **bit, int *max)
  82. {
  83. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
  84. return 0;
  85. set_bit(EV_REP, input->evbit);
  86. switch (usage->hid & HID_USAGE) {
  87. case 0xff01: map_key_clear(BTN_1); break;
  88. case 0xff02: map_key_clear(BTN_2); break;
  89. case 0xff03: map_key_clear(BTN_3); break;
  90. case 0xff04: map_key_clear(BTN_4); break;
  91. case 0xff05: map_key_clear(BTN_5); break;
  92. case 0xff06: map_key_clear(BTN_6); break;
  93. case 0xff07: map_key_clear(BTN_7); break;
  94. case 0xff08: map_key_clear(BTN_8); break;
  95. case 0xff09: map_key_clear(BTN_9); break;
  96. case 0xff0a: map_key_clear(BTN_A); break;
  97. case 0xff0b: map_key_clear(BTN_B); break;
  98. default:
  99. return 0;
  100. }
  101. return 1;
  102. }
  103. static int quirk_microsoft_ergonomy_kb(struct hid_usage *usage, struct input_dev *input,
  104. unsigned long **bit, int *max)
  105. {
  106. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
  107. return 0;
  108. switch(usage->hid & HID_USAGE) {
  109. case 0xfd06: map_key_clear(KEY_CHAT); break;
  110. case 0xfd07: map_key_clear(KEY_PHONE); break;
  111. case 0xff05:
  112. set_bit(EV_REP, input->evbit);
  113. map_key_clear(KEY_F13);
  114. set_bit(KEY_F14, input->keybit);
  115. set_bit(KEY_F15, input->keybit);
  116. set_bit(KEY_F16, input->keybit);
  117. set_bit(KEY_F17, input->keybit);
  118. set_bit(KEY_F18, input->keybit);
  119. default:
  120. return 0;
  121. }
  122. return 1;
  123. }
  124. static int quirk_microsoft_presenter_8k(struct hid_usage *usage, struct input_dev *input,
  125. unsigned long **bit, int *max)
  126. {
  127. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
  128. return 0;
  129. set_bit(EV_REP, input->evbit);
  130. switch(usage->hid & HID_USAGE) {
  131. case 0xfd08: map_key_clear(KEY_FORWARD); break;
  132. case 0xfd09: map_key_clear(KEY_BACK); break;
  133. case 0xfd0b: map_key_clear(KEY_PLAYPAUSE); break;
  134. case 0xfd0e: map_key_clear(KEY_CLOSE); break;
  135. case 0xfd0f: map_key_clear(KEY_PLAY); break;
  136. default:
  137. return 0;
  138. }
  139. return 1;
  140. }
  141. static int quirk_petalynx_remote(struct hid_usage *usage, struct input_dev *input,
  142. unsigned long **bit, int *max)
  143. {
  144. if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
  145. ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
  146. return 0;
  147. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
  148. switch(usage->hid & HID_USAGE) {
  149. case 0x05a: map_key_clear(KEY_TEXT); break;
  150. case 0x05b: map_key_clear(KEY_RED); break;
  151. case 0x05c: map_key_clear(KEY_GREEN); break;
  152. case 0x05d: map_key_clear(KEY_YELLOW); break;
  153. case 0x05e: map_key_clear(KEY_BLUE); break;
  154. default:
  155. return 0;
  156. }
  157. if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
  158. switch(usage->hid & HID_USAGE) {
  159. case 0x0f6: map_key_clear(KEY_NEXT); break;
  160. case 0x0fa: map_key_clear(KEY_BACK); break;
  161. default:
  162. return 0;
  163. }
  164. return 1;
  165. }
  166. static int quirk_logitech_wireless(struct hid_usage *usage, struct input_dev *input,
  167. unsigned long **bit, int *max)
  168. {
  169. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  170. return 0;
  171. switch (usage->hid & HID_USAGE) {
  172. case 0x1001: map_key_clear(KEY_MESSENGER); break;
  173. case 0x1003: map_key_clear(KEY_SOUND); break;
  174. case 0x1004: map_key_clear(KEY_VIDEO); break;
  175. case 0x1005: map_key_clear(KEY_AUDIO); break;
  176. case 0x100a: map_key_clear(KEY_DOCUMENTS); break;
  177. case 0x1011: map_key_clear(KEY_PREVIOUSSONG); break;
  178. case 0x1012: map_key_clear(KEY_NEXTSONG); break;
  179. case 0x1013: map_key_clear(KEY_CAMERA); break;
  180. case 0x1014: map_key_clear(KEY_MESSENGER); break;
  181. case 0x1015: map_key_clear(KEY_RECORD); break;
  182. case 0x1016: map_key_clear(KEY_PLAYER); break;
  183. case 0x1017: map_key_clear(KEY_EJECTCD); break;
  184. case 0x1018: map_key_clear(KEY_MEDIA); break;
  185. case 0x1019: map_key_clear(KEY_PROG1); break;
  186. case 0x101a: map_key_clear(KEY_PROG2); break;
  187. case 0x101b: map_key_clear(KEY_PROG3); break;
  188. case 0x101f: map_key_clear(KEY_ZOOMIN); break;
  189. case 0x1020: map_key_clear(KEY_ZOOMOUT); break;
  190. case 0x1021: map_key_clear(KEY_ZOOMRESET); break;
  191. case 0x1023: map_key_clear(KEY_CLOSE); break;
  192. case 0x1027: map_key_clear(KEY_MENU); break;
  193. /* this one is marked as 'Rotate' */
  194. case 0x1028: map_key_clear(KEY_ANGLE); break;
  195. case 0x1029: map_key_clear(KEY_SHUFFLE); break;
  196. case 0x102a: map_key_clear(KEY_BACK); break;
  197. case 0x102b: map_key_clear(KEY_CYCLEWINDOWS); break;
  198. case 0x1041: map_key_clear(KEY_BATTERY); break;
  199. case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break;
  200. case 0x1043: map_key_clear(KEY_SPREADSHEET); break;
  201. case 0x1044: map_key_clear(KEY_PRESENTATION); break;
  202. case 0x1045: map_key_clear(KEY_UNDO); break;
  203. case 0x1046: map_key_clear(KEY_REDO); break;
  204. case 0x1047: map_key_clear(KEY_PRINT); break;
  205. case 0x1048: map_key_clear(KEY_SAVE); break;
  206. case 0x1049: map_key_clear(KEY_PROG1); break;
  207. case 0x104a: map_key_clear(KEY_PROG2); break;
  208. case 0x104b: map_key_clear(KEY_PROG3); break;
  209. case 0x104c: map_key_clear(KEY_PROG4); break;
  210. default:
  211. return 0;
  212. }
  213. return 1;
  214. }
  215. static int quirk_cherry_genius_29e(struct hid_usage *usage, struct input_dev *input,
  216. unsigned long **bit, int *max)
  217. {
  218. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  219. return 0;
  220. switch (usage->hid & HID_USAGE) {
  221. case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
  222. case 0x157: map_key_clear(KEY_SPREADSHEET); break;
  223. case 0x158: map_key_clear(KEY_PRESENTATION); break;
  224. case 0x15c: map_key_clear(KEY_STOP); break;
  225. default:
  226. return 0;
  227. }
  228. return 1;
  229. }
  230. static int quirk_btc_8193(struct hid_usage *usage, struct input_dev *input,
  231. unsigned long **bit, int *max)
  232. {
  233. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  234. return 0;
  235. switch (usage->hid & HID_USAGE) {
  236. case 0x230: map_key(BTN_MOUSE); break;
  237. case 0x231: map_rel(REL_WHEEL); break;
  238. /*
  239. * this keyboard has a scrollwheel implemented in
  240. * totally broken way. We map this usage temporarily
  241. * to HWHEEL and handle it in the event quirk handler
  242. */
  243. case 0x232: map_rel(REL_HWHEEL); break;
  244. default:
  245. return 0;
  246. }
  247. return 1;
  248. }
  249. static int quirk_sunplus_wdesktop(struct hid_usage *usage, struct input_dev *input,
  250. unsigned long **bit, int *max)
  251. {
  252. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  253. return 0;
  254. switch (usage->hid & HID_USAGE) {
  255. case 0x2003: map_key_clear(KEY_ZOOMIN); break;
  256. case 0x2103: map_key_clear(KEY_ZOOMOUT); break;
  257. default:
  258. return 0;
  259. }
  260. return 1;
  261. }
  262. #define VENDOR_ID_BELKIN 0x1020
  263. #define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
  264. #define VENDOR_ID_CHERRY 0x046a
  265. #define DEVICE_ID_CHERRY_CYMOTION 0x0023
  266. #define VENDOR_ID_CHICONY 0x04f2
  267. #define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
  268. #define VENDOR_ID_EZKEY 0x0518
  269. #define DEVICE_ID_BTC_8193 0x0002
  270. #define VENDOR_ID_LOGITECH 0x046d
  271. #define DEVICE_ID_LOGITECH_RECEIVER 0xc101
  272. #define DEVICE_ID_S510_RECEIVER 0xc50c
  273. #define DEVICE_ID_S510_RECEIVER_2 0xc517
  274. #define DEVICE_ID_MX3000_RECEIVER 0xc513
  275. #define VENDOR_ID_MICROSOFT 0x045e
  276. #define DEVICE_ID_MS4K 0x00db
  277. #define DEVICE_ID_MS6K 0x00f9
  278. #define DEVICE_IS_MS_PRESENTER_8K_BT 0x0701
  279. #define DEVICE_ID_MS_PRESENTER_8K_USB 0x0713
  280. #define VENDOR_ID_MONTEREY 0x0566
  281. #define DEVICE_ID_GENIUS_KB29E 0x3004
  282. #define VENDOR_ID_PETALYNX 0x18b1
  283. #define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
  284. #define VENDOR_ID_SUNPLUS 0x04fc
  285. #define DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
  286. static const struct hid_input_blacklist {
  287. __u16 idVendor;
  288. __u16 idProduct;
  289. int (*quirk)(struct hid_usage *, struct input_dev *, unsigned long **, int *);
  290. } hid_input_blacklist[] = {
  291. { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
  292. { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion },
  293. { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
  294. { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
  295. { VENDOR_ID_LOGITECH, DEVICE_ID_LOGITECH_RECEIVER, quirk_logitech_ultrax_remote },
  296. { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER, quirk_logitech_wireless },
  297. { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER_2, quirk_logitech_wireless },
  298. { VENDOR_ID_LOGITECH, DEVICE_ID_MX3000_RECEIVER, quirk_logitech_wireless },
  299. { VENDOR_ID_MICROSOFT, DEVICE_ID_MS4K, quirk_microsoft_ergonomy_kb },
  300. { VENDOR_ID_MICROSOFT, DEVICE_ID_MS6K, quirk_microsoft_ergonomy_kb },
  301. { VENDOR_ID_MICROSOFT, DEVICE_IS_MS_PRESENTER_8K_BT, quirk_microsoft_presenter_8k },
  302. { VENDOR_ID_MICROSOFT, DEVICE_ID_MS_PRESENTER_8K_USB, quirk_microsoft_presenter_8k },
  303. { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
  304. { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
  305. { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop },
  306. { 0, 0, NULL }
  307. };
  308. int hidinput_mapping_quirks(struct hid_usage *usage,
  309. struct input_dev *input,
  310. unsigned long **bit, int *max)
  311. {
  312. struct hid_device *device = input_get_drvdata(input);
  313. int i = 0;
  314. while (hid_input_blacklist[i].quirk) {
  315. if (hid_input_blacklist[i].idVendor == device->vendor &&
  316. hid_input_blacklist[i].idProduct == device->product)
  317. return hid_input_blacklist[i].quirk(usage, input, bit, max);
  318. i++;
  319. }
  320. return 0;
  321. }
  322. int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
  323. {
  324. struct input_dev *input;
  325. input = field->hidinput->input;
  326. if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
  327. || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) {
  328. if (value) hid->quirks |= HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
  329. else hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
  330. return 1;
  331. }
  332. if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
  333. (usage->type == EV_REL) &&
  334. (usage->code == REL_WHEEL)) {
  335. hid->delayed_value = value;
  336. return 1;
  337. }
  338. if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
  339. (usage->hid == 0x000100b8)) {
  340. input_event(input, EV_REL, value ? REL_HWHEEL : REL_WHEEL, hid->delayed_value);
  341. return 1;
  342. }
  343. if ((hid->quirks & HID_QUIRK_INVERT_HWHEEL) && (usage->code == REL_HWHEEL)) {
  344. input_event(input, usage->type, usage->code, -value);
  345. return 1;
  346. }
  347. if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON) && (usage->code == REL_WHEEL)) {
  348. input_event(input, usage->type, REL_HWHEEL, value);
  349. return 1;
  350. }
  351. if ((hid->quirks & HID_QUIRK_APPLE_HAS_FN) && hidinput_apple_event(hid, input, usage, value))
  352. return 1;
  353. /* Handling MS keyboards special buttons */
  354. if (hid->quirks & HID_QUIRK_MICROSOFT_KEYS &&
  355. usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
  356. int key = 0;
  357. static int last_key = 0;
  358. switch (value) {
  359. case 0x01: key = KEY_F14; break;
  360. case 0x02: key = KEY_F15; break;
  361. case 0x04: key = KEY_F16; break;
  362. case 0x08: key = KEY_F17; break;
  363. case 0x10: key = KEY_F18; break;
  364. default: break;
  365. }
  366. if (key) {
  367. input_event(input, usage->type, key, 1);
  368. last_key = key;
  369. } else {
  370. input_event(input, usage->type, last_key, 0);
  371. }
  372. }
  373. /* handle the temporary quirky mapping to HWHEEL */
  374. if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
  375. usage->type == EV_REL && usage->code == REL_HWHEEL) {
  376. input_event(input, usage->type, REL_WHEEL, -value);
  377. return 1;
  378. }
  379. return 0;
  380. }