hid-input-quirks.c 15 KB

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