hid-kye.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. * HID driver for Kye/Genius devices not fully compliant with HID standard
  3. *
  4. * Copyright (c) 2009 Jiri Kosina
  5. * Copyright (c) 2009 Tomas Hanak
  6. * Copyright (c) 2012 Nikolai Kondrashov
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include <linux/usb.h>
  18. #include "usbhid/usbhid.h"
  19. #include "hid-ids.h"
  20. /*
  21. * See EasyPen i405X description, device and HID report descriptors at
  22. * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_i405X
  23. */
  24. /* Original EasyPen i405X report descriptor size */
  25. #define EASYPEN_I405X_RDESC_ORIG_SIZE 476
  26. /* Fixed EasyPen i405X report descriptor */
  27. static __u8 easypen_i405x_rdesc_fixed[] = {
  28. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  29. 0x09, 0x01, /* Usage (01h), */
  30. 0xA1, 0x01, /* Collection (Application), */
  31. 0x85, 0x05, /* Report ID (5), */
  32. 0x09, 0x01, /* Usage (01h), */
  33. 0x15, 0x80, /* Logical Minimum (-128), */
  34. 0x25, 0x7F, /* Logical Maximum (127), */
  35. 0x75, 0x08, /* Report Size (8), */
  36. 0x95, 0x07, /* Report Count (7), */
  37. 0xB1, 0x02, /* Feature (Variable), */
  38. 0xC0, /* End Collection, */
  39. 0x05, 0x0D, /* Usage Page (Digitizer), */
  40. 0x09, 0x02, /* Usage (Pen), */
  41. 0xA1, 0x01, /* Collection (Application), */
  42. 0x85, 0x10, /* Report ID (16), */
  43. 0x09, 0x20, /* Usage (Stylus), */
  44. 0xA0, /* Collection (Physical), */
  45. 0x14, /* Logical Minimum (0), */
  46. 0x25, 0x01, /* Logical Maximum (1), */
  47. 0x75, 0x01, /* Report Size (1), */
  48. 0x09, 0x42, /* Usage (Tip Switch), */
  49. 0x09, 0x44, /* Usage (Barrel Switch), */
  50. 0x09, 0x46, /* Usage (Tablet Pick), */
  51. 0x95, 0x03, /* Report Count (3), */
  52. 0x81, 0x02, /* Input (Variable), */
  53. 0x95, 0x04, /* Report Count (4), */
  54. 0x81, 0x03, /* Input (Constant, Variable), */
  55. 0x09, 0x32, /* Usage (In Range), */
  56. 0x95, 0x01, /* Report Count (1), */
  57. 0x81, 0x02, /* Input (Variable), */
  58. 0x75, 0x10, /* Report Size (16), */
  59. 0x95, 0x01, /* Report Count (1), */
  60. 0xA4, /* Push, */
  61. 0x05, 0x01, /* Usage Page (Desktop), */
  62. 0x55, 0xFD, /* Unit Exponent (-3), */
  63. 0x65, 0x13, /* Unit (Inch), */
  64. 0x34, /* Physical Minimum (0), */
  65. 0x09, 0x30, /* Usage (X), */
  66. 0x46, 0x7C, 0x15, /* Physical Maximum (5500), */
  67. 0x26, 0x00, 0x37, /* Logical Maximum (14080), */
  68. 0x81, 0x02, /* Input (Variable), */
  69. 0x09, 0x31, /* Usage (Y), */
  70. 0x46, 0xA0, 0x0F, /* Physical Maximum (4000), */
  71. 0x26, 0x00, 0x28, /* Logical Maximum (10240), */
  72. 0x81, 0x02, /* Input (Variable), */
  73. 0xB4, /* Pop, */
  74. 0x09, 0x30, /* Usage (Tip Pressure), */
  75. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  76. 0x81, 0x02, /* Input (Variable), */
  77. 0xC0, /* End Collection, */
  78. 0xC0 /* End Collection */
  79. };
  80. /*
  81. * See MousePen i608X description, device and HID report descriptors at
  82. * http://sf.net/apps/mediawiki/digimend/?title=KYE_MousePen_i608X
  83. */
  84. /* Original MousePen i608X report descriptor size */
  85. #define MOUSEPEN_I608X_RDESC_ORIG_SIZE 476
  86. /* Fixed MousePen i608X report descriptor */
  87. static __u8 mousepen_i608x_rdesc_fixed[] = {
  88. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  89. 0x09, 0x01, /* Usage (01h), */
  90. 0xA1, 0x01, /* Collection (Application), */
  91. 0x85, 0x05, /* Report ID (5), */
  92. 0x09, 0x01, /* Usage (01h), */
  93. 0x15, 0x80, /* Logical Minimum (-128), */
  94. 0x25, 0x7F, /* Logical Maximum (127), */
  95. 0x75, 0x08, /* Report Size (8), */
  96. 0x95, 0x07, /* Report Count (7), */
  97. 0xB1, 0x02, /* Feature (Variable), */
  98. 0xC0, /* End Collection, */
  99. 0x05, 0x0D, /* Usage Page (Digitizer), */
  100. 0x09, 0x02, /* Usage (Pen), */
  101. 0xA1, 0x01, /* Collection (Application), */
  102. 0x85, 0x10, /* Report ID (16), */
  103. 0x09, 0x20, /* Usage (Stylus), */
  104. 0xA0, /* Collection (Physical), */
  105. 0x14, /* Logical Minimum (0), */
  106. 0x25, 0x01, /* Logical Maximum (1), */
  107. 0x75, 0x01, /* Report Size (1), */
  108. 0x09, 0x42, /* Usage (Tip Switch), */
  109. 0x09, 0x44, /* Usage (Barrel Switch), */
  110. 0x09, 0x46, /* Usage (Tablet Pick), */
  111. 0x95, 0x03, /* Report Count (3), */
  112. 0x81, 0x02, /* Input (Variable), */
  113. 0x95, 0x04, /* Report Count (4), */
  114. 0x81, 0x03, /* Input (Constant, Variable), */
  115. 0x09, 0x32, /* Usage (In Range), */
  116. 0x95, 0x01, /* Report Count (1), */
  117. 0x81, 0x02, /* Input (Variable), */
  118. 0x75, 0x10, /* Report Size (16), */
  119. 0x95, 0x01, /* Report Count (1), */
  120. 0xA4, /* Push, */
  121. 0x05, 0x01, /* Usage Page (Desktop), */
  122. 0x55, 0xFD, /* Unit Exponent (-3), */
  123. 0x65, 0x13, /* Unit (Inch), */
  124. 0x34, /* Physical Minimum (0), */
  125. 0x09, 0x30, /* Usage (X), */
  126. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  127. 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
  128. 0x81, 0x02, /* Input (Variable), */
  129. 0x09, 0x31, /* Usage (Y), */
  130. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  131. 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
  132. 0x81, 0x02, /* Input (Variable), */
  133. 0xB4, /* Pop, */
  134. 0x09, 0x30, /* Usage (Tip Pressure), */
  135. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  136. 0x81, 0x02, /* Input (Variable), */
  137. 0xC0, /* End Collection, */
  138. 0xC0, /* End Collection, */
  139. 0x05, 0x01, /* Usage Page (Desktop), */
  140. 0x09, 0x02, /* Usage (Mouse), */
  141. 0xA1, 0x01, /* Collection (Application), */
  142. 0x85, 0x11, /* Report ID (17), */
  143. 0x09, 0x01, /* Usage (Pointer), */
  144. 0xA0, /* Collection (Physical), */
  145. 0x14, /* Logical Minimum (0), */
  146. 0xA4, /* Push, */
  147. 0x05, 0x09, /* Usage Page (Button), */
  148. 0x75, 0x01, /* Report Size (1), */
  149. 0x19, 0x01, /* Usage Minimum (01h), */
  150. 0x29, 0x03, /* Usage Maximum (03h), */
  151. 0x25, 0x01, /* Logical Maximum (1), */
  152. 0x95, 0x03, /* Report Count (3), */
  153. 0x81, 0x02, /* Input (Variable), */
  154. 0x95, 0x05, /* Report Count (5), */
  155. 0x81, 0x01, /* Input (Constant), */
  156. 0xB4, /* Pop, */
  157. 0x95, 0x01, /* Report Count (1), */
  158. 0xA4, /* Push, */
  159. 0x55, 0xFD, /* Unit Exponent (-3), */
  160. 0x65, 0x13, /* Unit (Inch), */
  161. 0x34, /* Physical Minimum (0), */
  162. 0x75, 0x10, /* Report Size (16), */
  163. 0x09, 0x30, /* Usage (X), */
  164. 0x46, 0x40, 0x1F, /* Physical Maximum (8000), */
  165. 0x26, 0x00, 0x50, /* Logical Maximum (20480), */
  166. 0x81, 0x02, /* Input (Variable), */
  167. 0x09, 0x31, /* Usage (Y), */
  168. 0x46, 0x70, 0x17, /* Physical Maximum (6000), */
  169. 0x26, 0x00, 0x3C, /* Logical Maximum (15360), */
  170. 0x81, 0x02, /* Input (Variable), */
  171. 0xB4, /* Pop, */
  172. 0x75, 0x08, /* Report Size (8), */
  173. 0x09, 0x38, /* Usage (Wheel), */
  174. 0x15, 0xFF, /* Logical Minimum (-1), */
  175. 0x25, 0x01, /* Logical Maximum (1), */
  176. 0x81, 0x06, /* Input (Variable, Relative), */
  177. 0x81, 0x01, /* Input (Constant), */
  178. 0xC0, /* End Collection, */
  179. 0xC0 /* End Collection */
  180. };
  181. /*
  182. * See EasyPen M610X description, device and HID report descriptors at
  183. * http://sf.net/apps/mediawiki/digimend/?title=KYE_EasyPen_M610X
  184. */
  185. /* Original EasyPen M610X report descriptor size */
  186. #define EASYPEN_M610X_RDESC_ORIG_SIZE 476
  187. /* Fixed EasyPen M610X report descriptor */
  188. static __u8 easypen_m610x_rdesc_fixed[] = {
  189. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  190. 0x09, 0x01, /* Usage (01h), */
  191. 0xA1, 0x01, /* Collection (Application), */
  192. 0x85, 0x05, /* Report ID (5), */
  193. 0x09, 0x01, /* Usage (01h), */
  194. 0x15, 0x80, /* Logical Minimum (-128), */
  195. 0x25, 0x7F, /* Logical Maximum (127), */
  196. 0x75, 0x08, /* Report Size (8), */
  197. 0x95, 0x07, /* Report Count (7), */
  198. 0xB1, 0x02, /* Feature (Variable), */
  199. 0xC0, /* End Collection, */
  200. 0x05, 0x0D, /* Usage Page (Digitizer), */
  201. 0x09, 0x02, /* Usage (Pen), */
  202. 0xA1, 0x01, /* Collection (Application), */
  203. 0x85, 0x10, /* Report ID (16), */
  204. 0x09, 0x20, /* Usage (Stylus), */
  205. 0xA0, /* Collection (Physical), */
  206. 0x14, /* Logical Minimum (0), */
  207. 0x25, 0x01, /* Logical Maximum (1), */
  208. 0x75, 0x01, /* Report Size (1), */
  209. 0x09, 0x42, /* Usage (Tip Switch), */
  210. 0x09, 0x44, /* Usage (Barrel Switch), */
  211. 0x09, 0x46, /* Usage (Tablet Pick), */
  212. 0x95, 0x03, /* Report Count (3), */
  213. 0x81, 0x02, /* Input (Variable), */
  214. 0x95, 0x04, /* Report Count (4), */
  215. 0x81, 0x03, /* Input (Constant, Variable), */
  216. 0x09, 0x32, /* Usage (In Range), */
  217. 0x95, 0x01, /* Report Count (1), */
  218. 0x81, 0x02, /* Input (Variable), */
  219. 0x75, 0x10, /* Report Size (16), */
  220. 0x95, 0x01, /* Report Count (1), */
  221. 0xA4, /* Push, */
  222. 0x05, 0x01, /* Usage Page (Desktop), */
  223. 0x55, 0xFD, /* Unit Exponent (-3), */
  224. 0x65, 0x13, /* Unit (Inch), */
  225. 0x34, /* Physical Minimum (0), */
  226. 0x09, 0x30, /* Usage (X), */
  227. 0x46, 0x10, 0x27, /* Physical Maximum (10000), */
  228. 0x27, 0x00, 0xA0, 0x00, 0x00, /* Logical Maximum (40960), */
  229. 0x81, 0x02, /* Input (Variable), */
  230. 0x09, 0x31, /* Usage (Y), */
  231. 0x46, 0x6A, 0x18, /* Physical Maximum (6250), */
  232. 0x26, 0x00, 0x64, /* Logical Maximum (25600), */
  233. 0x81, 0x02, /* Input (Variable), */
  234. 0xB4, /* Pop, */
  235. 0x09, 0x30, /* Usage (Tip Pressure), */
  236. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  237. 0x81, 0x02, /* Input (Variable), */
  238. 0xC0, /* End Collection, */
  239. 0xC0, /* End Collection, */
  240. 0x05, 0x0C, /* Usage Page (Consumer), */
  241. 0x09, 0x01, /* Usage (Consumer Control), */
  242. 0xA1, 0x01, /* Collection (Application), */
  243. 0x85, 0x12, /* Report ID (18), */
  244. 0x14, /* Logical Minimum (0), */
  245. 0x25, 0x01, /* Logical Maximum (1), */
  246. 0x75, 0x01, /* Report Size (1), */
  247. 0x95, 0x04, /* Report Count (4), */
  248. 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
  249. 0x0A, 0x79, 0x02, /* Usage (AC Redo Or Repeat), */
  250. 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
  251. 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
  252. 0x81, 0x02, /* Input (Variable), */
  253. 0x95, 0x01, /* Report Count (1), */
  254. 0x75, 0x14, /* Report Size (20), */
  255. 0x81, 0x03, /* Input (Constant, Variable), */
  256. 0x75, 0x20, /* Report Size (32), */
  257. 0x81, 0x03, /* Input (Constant, Variable), */
  258. 0xC0 /* End Collection */
  259. };
  260. static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  261. unsigned int *rsize)
  262. {
  263. switch (hdev->product) {
  264. case USB_DEVICE_ID_KYE_ERGO_525V:
  265. /* the fixups that need to be done:
  266. * - change led usage page to button for extra buttons
  267. * - report size 8 count 1 must be size 1 count 8 for button
  268. * bitfield
  269. * - change the button usage range to 4-7 for the extra
  270. * buttons
  271. */
  272. if (*rsize >= 75 &&
  273. rdesc[61] == 0x05 && rdesc[62] == 0x08 &&
  274. rdesc[63] == 0x19 && rdesc[64] == 0x08 &&
  275. rdesc[65] == 0x29 && rdesc[66] == 0x0f &&
  276. rdesc[71] == 0x75 && rdesc[72] == 0x08 &&
  277. rdesc[73] == 0x95 && rdesc[74] == 0x01) {
  278. hid_info(hdev,
  279. "fixing up Kye/Genius Ergo Mouse "
  280. "report descriptor\n");
  281. rdesc[62] = 0x09;
  282. rdesc[64] = 0x04;
  283. rdesc[66] = 0x07;
  284. rdesc[72] = 0x01;
  285. rdesc[74] = 0x08;
  286. }
  287. break;
  288. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  289. if (*rsize == EASYPEN_I405X_RDESC_ORIG_SIZE) {
  290. rdesc = easypen_i405x_rdesc_fixed;
  291. *rsize = sizeof(easypen_i405x_rdesc_fixed);
  292. }
  293. break;
  294. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  295. if (*rsize == MOUSEPEN_I608X_RDESC_ORIG_SIZE) {
  296. rdesc = mousepen_i608x_rdesc_fixed;
  297. *rsize = sizeof(mousepen_i608x_rdesc_fixed);
  298. }
  299. break;
  300. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  301. if (*rsize == EASYPEN_M610X_RDESC_ORIG_SIZE) {
  302. rdesc = easypen_m610x_rdesc_fixed;
  303. *rsize = sizeof(easypen_m610x_rdesc_fixed);
  304. }
  305. break;
  306. }
  307. return rdesc;
  308. }
  309. /**
  310. * Enable fully-functional tablet mode by setting a special feature report.
  311. *
  312. * @hdev: HID device
  313. *
  314. * The specific report ID and data were discovered by sniffing the
  315. * Windows driver traffic.
  316. */
  317. static int kye_tablet_enable(struct hid_device *hdev)
  318. {
  319. struct list_head *list;
  320. struct list_head *head;
  321. struct hid_report *report;
  322. __s32 *value;
  323. list = &hdev->report_enum[HID_FEATURE_REPORT].report_list;
  324. list_for_each(head, list) {
  325. report = list_entry(head, struct hid_report, list);
  326. if (report->id == 5)
  327. break;
  328. }
  329. if (head == list) {
  330. hid_err(hdev, "tablet-enabling feature report not found\n");
  331. return -ENODEV;
  332. }
  333. if (report->maxfield < 1 || report->field[0]->report_count < 7) {
  334. hid_err(hdev, "invalid tablet-enabling feature report\n");
  335. return -ENODEV;
  336. }
  337. value = report->field[0]->value;
  338. value[0] = 0x12;
  339. value[1] = 0x10;
  340. value[2] = 0x11;
  341. value[3] = 0x12;
  342. value[4] = 0x00;
  343. value[5] = 0x00;
  344. value[6] = 0x00;
  345. usbhid_submit_report(hdev, report, USB_DIR_OUT);
  346. return 0;
  347. }
  348. static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
  349. {
  350. int ret;
  351. ret = hid_parse(hdev);
  352. if (ret) {
  353. hid_err(hdev, "parse failed\n");
  354. goto err;
  355. }
  356. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  357. if (ret) {
  358. hid_err(hdev, "hw start failed\n");
  359. goto err;
  360. }
  361. switch (id->product) {
  362. case USB_DEVICE_ID_KYE_EASYPEN_I405X:
  363. case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
  364. case USB_DEVICE_ID_KYE_EASYPEN_M610X:
  365. ret = kye_tablet_enable(hdev);
  366. if (ret) {
  367. hid_err(hdev, "tablet enabling failed\n");
  368. goto enabling_err;
  369. }
  370. break;
  371. }
  372. return 0;
  373. enabling_err:
  374. hid_hw_stop(hdev);
  375. err:
  376. return ret;
  377. }
  378. static const struct hid_device_id kye_devices[] = {
  379. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  380. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  381. USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  382. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  383. USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  384. { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
  385. USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  386. { }
  387. };
  388. MODULE_DEVICE_TABLE(hid, kye_devices);
  389. static struct hid_driver kye_driver = {
  390. .name = "kye",
  391. .id_table = kye_devices,
  392. .probe = kye_probe,
  393. .report_fixup = kye_report_fixup,
  394. };
  395. static int __init kye_init(void)
  396. {
  397. return hid_register_driver(&kye_driver);
  398. }
  399. static void __exit kye_exit(void)
  400. {
  401. hid_unregister_driver(&kye_driver);
  402. }
  403. module_init(kye_init);
  404. module_exit(kye_exit);
  405. MODULE_LICENSE("GPL");