hid-lg.c 35 KB

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