hid-kye.c 18 KB

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