hid-lg.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /*
  2. * HID driver for some logitech "special" devices
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2007 Jiri Kosina
  8. * Copyright (c) 2008 Jiri Slaby
  9. * Copyright (c) 2010 Hendrik Iben
  10. */
  11. /*
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. #include <linux/device.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include <linux/random.h>
  21. #include <linux/sched.h>
  22. #include <linux/usb.h>
  23. #include <linux/wait.h>
  24. #include "usbhid/usbhid.h"
  25. #include "hid-ids.h"
  26. #include "hid-lg.h"
  27. #define LG_RDESC 0x001
  28. #define LG_BAD_RELATIVE_KEYS 0x002
  29. #define LG_DUPLICATE_USAGES 0x004
  30. #define LG_EXPANDED_KEYMAP 0x010
  31. #define LG_IGNORE_DOUBLED_WHEEL 0x020
  32. #define LG_WIRELESS 0x040
  33. #define LG_INVERT_HWHEEL 0x080
  34. #define LG_NOGET 0x100
  35. #define LG_FF 0x200
  36. #define LG_FF2 0x400
  37. #define LG_RDESC_REL_ABS 0x800
  38. #define LG_FF3 0x1000
  39. #define LG_FF4 0x2000
  40. /* Size of the original descriptors of the Driving Force (and Pro) wheels */
  41. #define DF_RDESC_ORIG_SIZE 130
  42. #define DFP_RDESC_ORIG_SIZE 97
  43. #define FV_RDESC_ORIG_SIZE 130
  44. #define MOMO_RDESC_ORIG_SIZE 87
  45. #define MOMO2_RDESC_ORIG_SIZE 87
  46. /* Fixed report descriptors for Logitech Driving Force (and Pro)
  47. * wheel controllers
  48. *
  49. * The original descriptors hide the separate throttle and brake axes in
  50. * a custom vendor usage page, providing only a combined value as
  51. * GenericDesktop.Y.
  52. * These descriptors remove the combined Y axis and instead report
  53. * separate throttle (Y) and brake (RZ).
  54. */
  55. static __u8 df_rdesc_fixed[] = {
  56. 0x05, 0x01, /* Usage Page (Desktop), */
  57. 0x09, 0x04, /* Usage (Joystik), */
  58. 0xA1, 0x01, /* Collection (Application), */
  59. 0xA1, 0x02, /* Collection (Logical), */
  60. 0x95, 0x01, /* Report Count (1), */
  61. 0x75, 0x0A, /* Report Size (10), */
  62. 0x14, /* Logical Minimum (0), */
  63. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  64. 0x34, /* Physical Minimum (0), */
  65. 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
  66. 0x09, 0x30, /* Usage (X), */
  67. 0x81, 0x02, /* Input (Variable), */
  68. 0x95, 0x0C, /* Report Count (12), */
  69. 0x75, 0x01, /* Report Size (1), */
  70. 0x25, 0x01, /* Logical Maximum (1), */
  71. 0x45, 0x01, /* Physical Maximum (1), */
  72. 0x05, 0x09, /* Usage (Buttons), */
  73. 0x19, 0x01, /* Usage Minimum (1), */
  74. 0x29, 0x0c, /* Usage Maximum (12), */
  75. 0x81, 0x02, /* Input (Variable), */
  76. 0x95, 0x02, /* Report Count (2), */
  77. 0x06, 0x00, 0xFF, /* Usage Page (Vendor: 65280), */
  78. 0x09, 0x01, /* Usage (?: 1), */
  79. 0x81, 0x02, /* Input (Variable), */
  80. 0x05, 0x01, /* Usage Page (Desktop), */
  81. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  82. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  83. 0x95, 0x01, /* Report Count (1), */
  84. 0x75, 0x08, /* Report Size (8), */
  85. 0x81, 0x02, /* Input (Variable), */
  86. 0x25, 0x07, /* Logical Maximum (7), */
  87. 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
  88. 0x75, 0x04, /* Report Size (4), */
  89. 0x65, 0x14, /* Unit (Degrees), */
  90. 0x09, 0x39, /* Usage (Hat Switch), */
  91. 0x81, 0x42, /* Input (Variable, Null State), */
  92. 0x75, 0x01, /* Report Size (1), */
  93. 0x95, 0x04, /* Report Count (4), */
  94. 0x65, 0x00, /* Unit (none), */
  95. 0x06, 0x00, 0xFF, /* Usage Page (Vendor: 65280), */
  96. 0x09, 0x01, /* Usage (?: 1), */
  97. 0x25, 0x01, /* Logical Maximum (1), */
  98. 0x45, 0x01, /* Physical Maximum (1), */
  99. 0x81, 0x02, /* Input (Variable), */
  100. 0x05, 0x01, /* Usage Page (Desktop), */
  101. 0x95, 0x01, /* Report Count (1), */
  102. 0x75, 0x08, /* Report Size (8), */
  103. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  104. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  105. 0x09, 0x31, /* Usage (Y), */
  106. 0x81, 0x02, /* Input (Variable), */
  107. 0x09, 0x35, /* Usage (Rz), */
  108. 0x81, 0x02, /* Input (Variable), */
  109. 0xC0, /* End Collection, */
  110. 0xA1, 0x02, /* Collection (Logical), */
  111. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  112. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  113. 0x95, 0x07, /* Report Count (7), */
  114. 0x75, 0x08, /* Report Size (8), */
  115. 0x09, 0x03, /* Usage (?: 3), */
  116. 0x91, 0x02, /* Output (Variable), */
  117. 0xC0, /* End Collection, */
  118. 0xC0 /* End Collection */
  119. };
  120. static __u8 dfp_rdesc_fixed[] = {
  121. 0x05, 0x01, /* Usage Page (Desktop), */
  122. 0x09, 0x04, /* Usage (Joystik), */
  123. 0xA1, 0x01, /* Collection (Application), */
  124. 0xA1, 0x02, /* Collection (Logical), */
  125. 0x95, 0x01, /* Report Count (1), */
  126. 0x75, 0x0E, /* Report Size (14), */
  127. 0x14, /* Logical Minimum (0), */
  128. 0x26, 0xFF, 0x3F, /* Logical Maximum (16383), */
  129. 0x34, /* Physical Minimum (0), */
  130. 0x46, 0xFF, 0x3F, /* Physical Maximum (16383), */
  131. 0x09, 0x30, /* Usage (X), */
  132. 0x81, 0x02, /* Input (Variable), */
  133. 0x95, 0x0E, /* Report Count (14), */
  134. 0x75, 0x01, /* Report Size (1), */
  135. 0x25, 0x01, /* Logical Maximum (1), */
  136. 0x45, 0x01, /* Physical Maximum (1), */
  137. 0x05, 0x09, /* Usage Page (Button), */
  138. 0x19, 0x01, /* Usage Minimum (01h), */
  139. 0x29, 0x0E, /* Usage Maximum (0Eh), */
  140. 0x81, 0x02, /* Input (Variable), */
  141. 0x05, 0x01, /* Usage Page (Desktop), */
  142. 0x95, 0x01, /* Report Count (1), */
  143. 0x75, 0x04, /* Report Size (4), */
  144. 0x25, 0x07, /* Logical Maximum (7), */
  145. 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
  146. 0x65, 0x14, /* Unit (Degrees), */
  147. 0x09, 0x39, /* Usage (Hat Switch), */
  148. 0x81, 0x42, /* Input (Variable, Nullstate), */
  149. 0x65, 0x00, /* Unit, */
  150. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  151. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  152. 0x75, 0x08, /* Report Size (8), */
  153. 0x81, 0x01, /* Input (Constant), */
  154. 0x09, 0x31, /* Usage (Y), */
  155. 0x81, 0x02, /* Input (Variable), */
  156. 0x09, 0x35, /* Usage (Rz), */
  157. 0x81, 0x02, /* Input (Variable), */
  158. 0x81, 0x01, /* Input (Constant), */
  159. 0xC0, /* End Collection, */
  160. 0xA1, 0x02, /* Collection (Logical), */
  161. 0x09, 0x02, /* Usage (02h), */
  162. 0x95, 0x07, /* Report Count (7), */
  163. 0x91, 0x02, /* Output (Variable), */
  164. 0xC0, /* End Collection, */
  165. 0xC0 /* End Collection */
  166. };
  167. static __u8 fv_rdesc_fixed[] = {
  168. 0x05, 0x01, /* Usage Page (Desktop), */
  169. 0x09, 0x04, /* Usage (Joystik), */
  170. 0xA1, 0x01, /* Collection (Application), */
  171. 0xA1, 0x02, /* Collection (Logical), */
  172. 0x95, 0x01, /* Report Count (1), */
  173. 0x75, 0x0A, /* Report Size (10), */
  174. 0x15, 0x00, /* Logical Minimum (0), */
  175. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  176. 0x35, 0x00, /* Physical Minimum (0), */
  177. 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
  178. 0x09, 0x30, /* Usage (X), */
  179. 0x81, 0x02, /* Input (Variable), */
  180. 0x95, 0x0C, /* Report Count (12), */
  181. 0x75, 0x01, /* Report Size (1), */
  182. 0x25, 0x01, /* Logical Maximum (1), */
  183. 0x45, 0x01, /* Physical Maximum (1), */
  184. 0x05, 0x09, /* Usage Page (Button), */
  185. 0x19, 0x01, /* Usage Minimum (01h), */
  186. 0x29, 0x0C, /* Usage Maximum (0Ch), */
  187. 0x81, 0x02, /* Input (Variable), */
  188. 0x95, 0x02, /* Report Count (2), */
  189. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  190. 0x09, 0x01, /* Usage (01h), */
  191. 0x81, 0x02, /* Input (Variable), */
  192. 0x09, 0x02, /* Usage (02h), */
  193. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  194. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  195. 0x95, 0x01, /* Report Count (1), */
  196. 0x75, 0x08, /* Report Size (8), */
  197. 0x81, 0x02, /* Input (Variable), */
  198. 0x05, 0x01, /* Usage Page (Desktop), */
  199. 0x25, 0x07, /* Logical Maximum (7), */
  200. 0x46, 0x3B, 0x01, /* Physical Maximum (315), */
  201. 0x75, 0x04, /* Report Size (4), */
  202. 0x65, 0x14, /* Unit (Degrees), */
  203. 0x09, 0x39, /* Usage (Hat Switch), */
  204. 0x81, 0x42, /* Input (Variable, Null State), */
  205. 0x75, 0x01, /* Report Size (1), */
  206. 0x95, 0x04, /* Report Count (4), */
  207. 0x65, 0x00, /* Unit, */
  208. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  209. 0x09, 0x01, /* Usage (01h), */
  210. 0x25, 0x01, /* Logical Maximum (1), */
  211. 0x45, 0x01, /* Physical Maximum (1), */
  212. 0x81, 0x02, /* Input (Variable), */
  213. 0x05, 0x01, /* Usage Page (Desktop), */
  214. 0x95, 0x01, /* Report Count (1), */
  215. 0x75, 0x08, /* Report Size (8), */
  216. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  217. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  218. 0x09, 0x31, /* Usage (Y), */
  219. 0x81, 0x02, /* Input (Variable), */
  220. 0x09, 0x32, /* Usage (Z), */
  221. 0x81, 0x02, /* Input (Variable), */
  222. 0xC0, /* End Collection, */
  223. 0xA1, 0x02, /* Collection (Logical), */
  224. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  225. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  226. 0x95, 0x07, /* Report Count (7), */
  227. 0x75, 0x08, /* Report Size (8), */
  228. 0x09, 0x03, /* Usage (03h), */
  229. 0x91, 0x02, /* Output (Variable), */
  230. 0xC0, /* End Collection, */
  231. 0xC0 /* End Collection */
  232. };
  233. static __u8 momo_rdesc_fixed[] = {
  234. 0x05, 0x01, /* Usage Page (Desktop), */
  235. 0x09, 0x04, /* Usage (Joystik), */
  236. 0xA1, 0x01, /* Collection (Application), */
  237. 0xA1, 0x02, /* Collection (Logical), */
  238. 0x95, 0x01, /* Report Count (1), */
  239. 0x75, 0x0A, /* Report Size (10), */
  240. 0x15, 0x00, /* Logical Minimum (0), */
  241. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  242. 0x35, 0x00, /* Physical Minimum (0), */
  243. 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
  244. 0x09, 0x30, /* Usage (X), */
  245. 0x81, 0x02, /* Input (Variable), */
  246. 0x95, 0x08, /* Report Count (8), */
  247. 0x75, 0x01, /* Report Size (1), */
  248. 0x25, 0x01, /* Logical Maximum (1), */
  249. 0x45, 0x01, /* Physical Maximum (1), */
  250. 0x05, 0x09, /* Usage Page (Button), */
  251. 0x19, 0x01, /* Usage Minimum (01h), */
  252. 0x29, 0x08, /* Usage Maximum (08h), */
  253. 0x81, 0x02, /* Input (Variable), */
  254. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  255. 0x75, 0x0E, /* Report Size (14), */
  256. 0x95, 0x01, /* Report Count (1), */
  257. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  258. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  259. 0x09, 0x00, /* Usage (00h), */
  260. 0x81, 0x02, /* Input (Variable), */
  261. 0x05, 0x01, /* Usage Page (Desktop), */
  262. 0x75, 0x08, /* Report Size (8), */
  263. 0x09, 0x31, /* Usage (Y), */
  264. 0x81, 0x02, /* Input (Variable), */
  265. 0x09, 0x32, /* Usage (Z), */
  266. 0x81, 0x02, /* Input (Variable), */
  267. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  268. 0x09, 0x01, /* Usage (01h), */
  269. 0x81, 0x02, /* Input (Variable), */
  270. 0xC0, /* End Collection, */
  271. 0xA1, 0x02, /* Collection (Logical), */
  272. 0x09, 0x02, /* Usage (02h), */
  273. 0x95, 0x07, /* Report Count (7), */
  274. 0x91, 0x02, /* Output (Variable), */
  275. 0xC0, /* End Collection, */
  276. 0xC0 /* End Collection */
  277. };
  278. static __u8 momo2_rdesc_fixed[] = {
  279. 0x05, 0x01, /* Usage Page (Desktop), */
  280. 0x09, 0x04, /* Usage (Joystik), */
  281. 0xA1, 0x01, /* Collection (Application), */
  282. 0xA1, 0x02, /* Collection (Logical), */
  283. 0x95, 0x01, /* Report Count (1), */
  284. 0x75, 0x0A, /* Report Size (10), */
  285. 0x15, 0x00, /* Logical Minimum (0), */
  286. 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */
  287. 0x35, 0x00, /* Physical Minimum (0), */
  288. 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */
  289. 0x09, 0x30, /* Usage (X), */
  290. 0x81, 0x02, /* Input (Variable), */
  291. 0x95, 0x0A, /* Report Count (10), */
  292. 0x75, 0x01, /* Report Size (1), */
  293. 0x25, 0x01, /* Logical Maximum (1), */
  294. 0x45, 0x01, /* Physical Maximum (1), */
  295. 0x05, 0x09, /* Usage Page (Button), */
  296. 0x19, 0x01, /* Usage Minimum (01h), */
  297. 0x29, 0x0A, /* Usage Maximum (0Ah), */
  298. 0x81, 0x02, /* Input (Variable), */
  299. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  300. 0x09, 0x00, /* Usage (00h), */
  301. 0x95, 0x04, /* Report Count (4), */
  302. 0x81, 0x02, /* Input (Variable), */
  303. 0x95, 0x01, /* Report Count (1), */
  304. 0x75, 0x08, /* Report Size (8), */
  305. 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
  306. 0x46, 0xFF, 0x00, /* Physical Maximum (255), */
  307. 0x09, 0x01, /* Usage (01h), */
  308. 0x81, 0x02, /* Input (Variable), */
  309. 0x05, 0x01, /* Usage Page (Desktop), */
  310. 0x09, 0x31, /* Usage (Y), */
  311. 0x81, 0x02, /* Input (Variable), */
  312. 0x09, 0x32, /* Usage (Z), */
  313. 0x81, 0x02, /* Input (Variable), */
  314. 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
  315. 0x09, 0x00, /* Usage (00h), */
  316. 0x81, 0x02, /* Input (Variable), */
  317. 0xC0, /* End Collection, */
  318. 0xA1, 0x02, /* Collection (Logical), */
  319. 0x09, 0x02, /* Usage (02h), */
  320. 0x95, 0x07, /* Report Count (7), */
  321. 0x91, 0x02, /* Output (Variable), */
  322. 0xC0, /* End Collection, */
  323. 0xC0 /* End Collection */
  324. };
  325. /*
  326. * Certain Logitech keyboards send in report #3 keys which are far
  327. * above the logical maximum described in descriptor. This extends
  328. * the original value of 0x28c of logical maximum to 0x104d
  329. */
  330. static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  331. unsigned int *rsize)
  332. {
  333. struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
  334. struct usb_device_descriptor *udesc;
  335. __u16 bcdDevice, rev_maj, rev_min;
  336. if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
  337. rdesc[84] == 0x8c && rdesc[85] == 0x02) {
  338. hid_info(hdev,
  339. "fixing up Logitech keyboard report descriptor\n");
  340. rdesc[84] = rdesc[89] = 0x4d;
  341. rdesc[85] = rdesc[90] = 0x10;
  342. }
  343. if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
  344. rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
  345. rdesc[49] == 0x81 && rdesc[50] == 0x06) {
  346. hid_info(hdev,
  347. "fixing up rel/abs in Logitech report descriptor\n");
  348. rdesc[33] = rdesc[50] = 0x02;
  349. }
  350. switch (hdev->product) {
  351. /* Several wheels report as this id when operating in emulation mode. */
  352. case USB_DEVICE_ID_LOGITECH_WHEEL:
  353. udesc = &(hid_to_usb_dev(hdev)->descriptor);
  354. if (!udesc) {
  355. hid_err(hdev, "NULL USB device descriptor\n");
  356. break;
  357. }
  358. bcdDevice = le16_to_cpu(udesc->bcdDevice);
  359. rev_maj = bcdDevice >> 8;
  360. rev_min = bcdDevice & 0xff;
  361. /* Update the report descriptor for only the Driving Force wheel */
  362. if (rev_maj == 1 && rev_min == 2 &&
  363. *rsize == DF_RDESC_ORIG_SIZE) {
  364. hid_info(hdev,
  365. "fixing up Logitech Driving Force report descriptor\n");
  366. rdesc = df_rdesc_fixed;
  367. *rsize = sizeof(df_rdesc_fixed);
  368. }
  369. break;
  370. case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
  371. if (*rsize == MOMO_RDESC_ORIG_SIZE) {
  372. hid_info(hdev,
  373. "fixing up Logitech Momo Force (Red) report descriptor\n");
  374. rdesc = momo_rdesc_fixed;
  375. *rsize = sizeof(momo_rdesc_fixed);
  376. }
  377. break;
  378. case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
  379. if (*rsize == MOMO2_RDESC_ORIG_SIZE) {
  380. hid_info(hdev,
  381. "fixing up Logitech Momo Racing Force (Black) report descriptor\n");
  382. rdesc = momo2_rdesc_fixed;
  383. *rsize = sizeof(momo2_rdesc_fixed);
  384. }
  385. break;
  386. case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
  387. if (*rsize == FV_RDESC_ORIG_SIZE) {
  388. hid_info(hdev,
  389. "fixing up Logitech Formula Vibration report descriptor\n");
  390. rdesc = fv_rdesc_fixed;
  391. *rsize = sizeof(fv_rdesc_fixed);
  392. }
  393. break;
  394. case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
  395. if (*rsize == DFP_RDESC_ORIG_SIZE) {
  396. hid_info(hdev,
  397. "fixing up Logitech Driving Force Pro report descriptor\n");
  398. rdesc = dfp_rdesc_fixed;
  399. *rsize = sizeof(dfp_rdesc_fixed);
  400. }
  401. break;
  402. case USB_DEVICE_ID_LOGITECH_WII_WHEEL:
  403. if (*rsize >= 101 && rdesc[41] == 0x95 && rdesc[42] == 0x0B &&
  404. rdesc[47] == 0x05 && rdesc[48] == 0x09) {
  405. hid_info(hdev, "fixing up Logitech Speed Force Wireless report descriptor\n");
  406. rdesc[41] = 0x05;
  407. rdesc[42] = 0x09;
  408. rdesc[47] = 0x95;
  409. rdesc[48] = 0x0B;
  410. }
  411. break;
  412. }
  413. return rdesc;
  414. }
  415. #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
  416. EV_KEY, (c))
  417. static int lg_ultrax_remote_mapping(struct hid_input *hi,
  418. struct hid_usage *usage, unsigned long **bit, int *max)
  419. {
  420. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  421. return 0;
  422. set_bit(EV_REP, hi->input->evbit);
  423. switch (usage->hid & HID_USAGE) {
  424. /* Reported on Logitech Ultra X Media Remote */
  425. case 0x004: lg_map_key_clear(KEY_AGAIN); break;
  426. case 0x00d: lg_map_key_clear(KEY_HOME); break;
  427. case 0x024: lg_map_key_clear(KEY_SHUFFLE); break;
  428. case 0x025: lg_map_key_clear(KEY_TV); break;
  429. case 0x026: lg_map_key_clear(KEY_MENU); break;
  430. case 0x031: lg_map_key_clear(KEY_AUDIO); break;
  431. case 0x032: lg_map_key_clear(KEY_TEXT); break;
  432. case 0x033: lg_map_key_clear(KEY_LAST); break;
  433. case 0x047: lg_map_key_clear(KEY_MP3); break;
  434. case 0x048: lg_map_key_clear(KEY_DVD); break;
  435. case 0x049: lg_map_key_clear(KEY_MEDIA); break;
  436. case 0x04a: lg_map_key_clear(KEY_VIDEO); break;
  437. case 0x04b: lg_map_key_clear(KEY_ANGLE); break;
  438. case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break;
  439. case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break;
  440. case 0x051: lg_map_key_clear(KEY_RED); break;
  441. case 0x052: lg_map_key_clear(KEY_CLOSE); break;
  442. default:
  443. return 0;
  444. }
  445. return 1;
  446. }
  447. static int lg_dinovo_mapping(struct hid_input *hi, struct hid_usage *usage,
  448. unsigned long **bit, int *max)
  449. {
  450. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
  451. return 0;
  452. switch (usage->hid & HID_USAGE) {
  453. case 0x00d: lg_map_key_clear(KEY_MEDIA); break;
  454. default:
  455. return 0;
  456. }
  457. return 1;
  458. }
  459. static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage,
  460. unsigned long **bit, int *max)
  461. {
  462. if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
  463. return 0;
  464. switch (usage->hid & HID_USAGE) {
  465. case 0x1001: lg_map_key_clear(KEY_MESSENGER); break;
  466. case 0x1003: lg_map_key_clear(KEY_SOUND); break;
  467. case 0x1004: lg_map_key_clear(KEY_VIDEO); break;
  468. case 0x1005: lg_map_key_clear(KEY_AUDIO); break;
  469. case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break;
  470. /* The following two entries are Playlist 1 and 2 on the MX3200 */
  471. case 0x100f: lg_map_key_clear(KEY_FN_1); break;
  472. case 0x1010: lg_map_key_clear(KEY_FN_2); break;
  473. case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break;
  474. case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break;
  475. case 0x1013: lg_map_key_clear(KEY_CAMERA); break;
  476. case 0x1014: lg_map_key_clear(KEY_MESSENGER); break;
  477. case 0x1015: lg_map_key_clear(KEY_RECORD); break;
  478. case 0x1016: lg_map_key_clear(KEY_PLAYER); break;
  479. case 0x1017: lg_map_key_clear(KEY_EJECTCD); break;
  480. case 0x1018: lg_map_key_clear(KEY_MEDIA); break;
  481. case 0x1019: lg_map_key_clear(KEY_PROG1); break;
  482. case 0x101a: lg_map_key_clear(KEY_PROG2); break;
  483. case 0x101b: lg_map_key_clear(KEY_PROG3); break;
  484. case 0x101c: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
  485. case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break;
  486. case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break;
  487. case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break;
  488. case 0x1023: lg_map_key_clear(KEY_CLOSE); break;
  489. case 0x1027: lg_map_key_clear(KEY_MENU); break;
  490. /* this one is marked as 'Rotate' */
  491. case 0x1028: lg_map_key_clear(KEY_ANGLE); break;
  492. case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break;
  493. case 0x102a: lg_map_key_clear(KEY_BACK); break;
  494. case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
  495. case 0x102d: lg_map_key_clear(KEY_WWW); break;
  496. /* The following two are 'Start/answer call' and 'End/reject call'
  497. on the MX3200 */
  498. case 0x1031: lg_map_key_clear(KEY_OK); break;
  499. case 0x1032: lg_map_key_clear(KEY_CANCEL); break;
  500. case 0x1041: lg_map_key_clear(KEY_BATTERY); break;
  501. case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break;
  502. case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break;
  503. case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break;
  504. case 0x1045: lg_map_key_clear(KEY_UNDO); break;
  505. case 0x1046: lg_map_key_clear(KEY_REDO); break;
  506. case 0x1047: lg_map_key_clear(KEY_PRINT); break;
  507. case 0x1048: lg_map_key_clear(KEY_SAVE); break;
  508. case 0x1049: lg_map_key_clear(KEY_PROG1); break;
  509. case 0x104a: lg_map_key_clear(KEY_PROG2); break;
  510. case 0x104b: lg_map_key_clear(KEY_PROG3); break;
  511. case 0x104c: lg_map_key_clear(KEY_PROG4); break;
  512. default:
  513. return 0;
  514. }
  515. return 1;
  516. }
  517. static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  518. struct hid_field *field, struct hid_usage *usage,
  519. unsigned long **bit, int *max)
  520. {
  521. /* extended mapping for certain Logitech hardware (Logitech cordless
  522. desktop LX500) */
  523. static const u8 e_keymap[] = {
  524. 0,216, 0,213,175,156, 0, 0, 0, 0,
  525. 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
  526. 174,167,152,161,112, 0, 0, 0,154, 0,
  527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  530. 0, 0, 0, 0, 0,183,184,185,186,187,
  531. 188,189,190,191,192,193,194, 0, 0, 0
  532. };
  533. struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
  534. unsigned int hid = usage->hid;
  535. if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
  536. lg_ultrax_remote_mapping(hi, usage, bit, max))
  537. return 1;
  538. if (hdev->product == USB_DEVICE_ID_DINOVO_MINI &&
  539. lg_dinovo_mapping(hi, usage, bit, max))
  540. return 1;
  541. if ((drv_data->quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
  542. return 1;
  543. if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
  544. return 0;
  545. hid &= HID_USAGE;
  546. /* Special handling for Logitech Cordless Desktop */
  547. if (field->application == HID_GD_MOUSE) {
  548. if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) &&
  549. (hid == 7 || hid == 8))
  550. return -1;
  551. } else {
  552. if ((drv_data->quirks & LG_EXPANDED_KEYMAP) &&
  553. hid < ARRAY_SIZE(e_keymap) &&
  554. e_keymap[hid] != 0) {
  555. hid_map_usage(hi, usage, bit, max, EV_KEY,
  556. e_keymap[hid]);
  557. return 1;
  558. }
  559. }
  560. return 0;
  561. }
  562. static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  563. struct hid_field *field, struct hid_usage *usage,
  564. unsigned long **bit, int *max)
  565. {
  566. struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
  567. if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
  568. (field->flags & HID_MAIN_ITEM_RELATIVE))
  569. field->flags &= ~HID_MAIN_ITEM_RELATIVE;
  570. if ((drv_data->quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
  571. usage->type == EV_REL || usage->type == EV_ABS))
  572. clear_bit(usage->code, *bit);
  573. /* Ensure that Logitech wheels are not given a default fuzz/flat value */
  574. if (usage->type == EV_ABS && (usage->code == ABS_X ||
  575. usage->code == ABS_Y || usage->code == ABS_Z ||
  576. usage->code == ABS_RZ)) {
  577. switch (hdev->product) {
  578. case USB_DEVICE_ID_LOGITECH_WHEEL:
  579. case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL:
  580. case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
  581. case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
  582. case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
  583. case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
  584. case USB_DEVICE_ID_LOGITECH_WII_WHEEL:
  585. case USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2:
  586. case USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL:
  587. field->application = HID_GD_MULTIAXIS;
  588. break;
  589. default:
  590. break;
  591. }
  592. }
  593. return 0;
  594. }
  595. static int lg_event(struct hid_device *hdev, struct hid_field *field,
  596. struct hid_usage *usage, __s32 value)
  597. {
  598. struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
  599. if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
  600. input_event(field->hidinput->input, usage->type, usage->code,
  601. -value);
  602. return 1;
  603. }
  604. if (drv_data->quirks & LG_FF4) {
  605. return lg4ff_adjust_input_event(hdev, field, usage, value, drv_data);
  606. }
  607. return 0;
  608. }
  609. static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
  610. {
  611. unsigned int connect_mask = HID_CONNECT_DEFAULT;
  612. struct lg_drv_data *drv_data;
  613. int ret;
  614. drv_data = kzalloc(sizeof(struct lg_drv_data), GFP_KERNEL);
  615. if (!drv_data) {
  616. hid_err(hdev, "Insufficient memory, cannot allocate driver data\n");
  617. return -ENOMEM;
  618. }
  619. drv_data->quirks = id->driver_data;
  620. hid_set_drvdata(hdev, (void *)drv_data);
  621. if (drv_data->quirks & LG_NOGET)
  622. hdev->quirks |= HID_QUIRK_NOGET;
  623. ret = hid_parse(hdev);
  624. if (ret) {
  625. hid_err(hdev, "parse failed\n");
  626. goto err_free;
  627. }
  628. if (drv_data->quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4))
  629. connect_mask &= ~HID_CONNECT_FF;
  630. ret = hid_hw_start(hdev, connect_mask);
  631. if (ret) {
  632. hid_err(hdev, "hw start failed\n");
  633. goto err_free;
  634. }
  635. /* Setup wireless link with Logitech Wii wheel */
  636. if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) {
  637. unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  638. ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
  639. if (ret >= 0) {
  640. /* insert a little delay of 10 jiffies ~ 40ms */
  641. wait_queue_head_t wait;
  642. init_waitqueue_head (&wait);
  643. wait_event_interruptible_timeout(wait, 0, 10);
  644. /* Select random Address */
  645. buf[1] = 0xB2;
  646. get_random_bytes(&buf[2], 2);
  647. ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
  648. }
  649. }
  650. if (drv_data->quirks & LG_FF)
  651. lgff_init(hdev);
  652. if (drv_data->quirks & LG_FF2)
  653. lg2ff_init(hdev);
  654. if (drv_data->quirks & LG_FF3)
  655. lg3ff_init(hdev);
  656. if (drv_data->quirks & LG_FF4)
  657. lg4ff_init(hdev);
  658. return 0;
  659. err_free:
  660. kfree(drv_data);
  661. return ret;
  662. }
  663. static void lg_remove(struct hid_device *hdev)
  664. {
  665. struct lg_drv_data *drv_data = hid_get_drvdata(hdev);
  666. if (drv_data->quirks & LG_FF4)
  667. lg4ff_deinit(hdev);
  668. hid_hw_stop(hdev);
  669. kfree(drv_data);
  670. }
  671. static const struct hid_device_id lg_devices[] = {
  672. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
  673. .driver_data = LG_RDESC | LG_WIRELESS },
  674. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
  675. .driver_data = LG_RDESC | LG_WIRELESS },
  676. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
  677. .driver_data = LG_RDESC | LG_WIRELESS },
  678. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
  679. .driver_data = LG_BAD_RELATIVE_KEYS },
  680. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP),
  681. .driver_data = LG_DUPLICATE_USAGES },
  682. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE),
  683. .driver_data = LG_DUPLICATE_USAGES },
  684. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI),
  685. .driver_data = LG_DUPLICATE_USAGES },
  686. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD),
  687. .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
  688. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500),
  689. .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
  690. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D),
  691. .driver_data = LG_NOGET },
  692. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL),
  693. .driver_data = LG_NOGET | LG_FF4 },
  694. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD),
  695. .driver_data = LG_FF2 },
  696. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD),
  697. .driver_data = LG_FF },
  698. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2),
  699. .driver_data = LG_FF },
  700. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D),
  701. .driver_data = LG_FF },
  702. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO),
  703. .driver_data = LG_FF },
  704. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL),
  705. .driver_data = LG_NOGET | LG_FF4 },
  706. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2),
  707. .driver_data = LG_FF4 },
  708. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_VIBRATION_WHEEL),
  709. .driver_data = LG_FF2 },
  710. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL),
  711. .driver_data = LG_FF4 },
  712. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL),
  713. .driver_data = LG_FF4 },
  714. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL),
  715. .driver_data = LG_FF4 },
  716. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL),
  717. .driver_data = LG_NOGET | LG_FF4 },
  718. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL),
  719. .driver_data = LG_FF4 },
  720. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG),
  721. .driver_data = LG_FF },
  722. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
  723. .driver_data = LG_FF2 },
  724. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940),
  725. .driver_data = LG_FF3 },
  726. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR),
  727. .driver_data = LG_RDESC_REL_ABS },
  728. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER),
  729. .driver_data = LG_RDESC_REL_ABS },
  730. { }
  731. };
  732. MODULE_DEVICE_TABLE(hid, lg_devices);
  733. static struct hid_driver lg_driver = {
  734. .name = "logitech",
  735. .id_table = lg_devices,
  736. .report_fixup = lg_report_fixup,
  737. .input_mapping = lg_input_mapping,
  738. .input_mapped = lg_input_mapped,
  739. .event = lg_event,
  740. .probe = lg_probe,
  741. .remove = lg_remove,
  742. };
  743. module_hid_driver(lg_driver);
  744. MODULE_LICENSE("GPL");