hid-logitech-dj.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HID driver for Logitech receivers
  4. *
  5. * Copyright (c) 2011 Logitech
  6. */
  7. #include <linux/device.h>
  8. #include <linux/hid.h>
  9. #include <linux/module.h>
  10. #include <linux/kfifo.h>
  11. #include <linux/delay.h>
  12. #include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */
  13. #include <linux/unaligned.h>
  14. #include "hid-ids.h"
  15. #define DJ_MAX_PAIRED_DEVICES 7
  16. #define DJ_MAX_NUMBER_NOTIFS 8
  17. #define DJ_RECEIVER_INDEX 0
  18. #define DJ_DEVICE_INDEX_MIN 1
  19. #define DJ_DEVICE_INDEX_MAX 7
  20. #define DJREPORT_SHORT_LENGTH 15
  21. #define DJREPORT_LONG_LENGTH 32
  22. #define REPORT_ID_DJ_SHORT 0x20
  23. #define REPORT_ID_DJ_LONG 0x21
  24. #define REPORT_ID_HIDPP_SHORT 0x10
  25. #define REPORT_ID_HIDPP_LONG 0x11
  26. #define REPORT_ID_HIDPP_VERY_LONG 0x12
  27. #define HIDPP_REPORT_SHORT_LENGTH 7
  28. #define HIDPP_REPORT_LONG_LENGTH 20
  29. #define HIDPP_RECEIVER_INDEX 0xff
  30. #define REPORT_TYPE_RFREPORT_FIRST 0x01
  31. #define REPORT_TYPE_RFREPORT_LAST 0x1F
  32. /* Command Switch to DJ mode */
  33. #define REPORT_TYPE_CMD_SWITCH 0x80
  34. #define CMD_SWITCH_PARAM_DEVBITFIELD 0x00
  35. #define CMD_SWITCH_PARAM_TIMEOUT_SECONDS 0x01
  36. #define TIMEOUT_NO_KEEPALIVE 0x00
  37. /* Command to Get the list of Paired devices */
  38. #define REPORT_TYPE_CMD_GET_PAIRED_DEVICES 0x81
  39. /* Device Paired Notification */
  40. #define REPORT_TYPE_NOTIF_DEVICE_PAIRED 0x41
  41. #define SPFUNCTION_MORE_NOTIF_EXPECTED 0x01
  42. #define SPFUNCTION_DEVICE_LIST_EMPTY 0x02
  43. #define DEVICE_PAIRED_PARAM_SPFUNCTION 0x00
  44. #define DEVICE_PAIRED_PARAM_EQUAD_ID_LSB 0x01
  45. #define DEVICE_PAIRED_PARAM_EQUAD_ID_MSB 0x02
  46. #define DEVICE_PAIRED_RF_REPORT_TYPE 0x03
  47. /* Device Un-Paired Notification */
  48. #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40
  49. /* Connection Status Notification */
  50. #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42
  51. #define CONNECTION_STATUS_PARAM_STATUS 0x00
  52. #define STATUS_LINKLOSS 0x01
  53. /* Error Notification */
  54. #define REPORT_TYPE_NOTIF_ERROR 0x7F
  55. #define NOTIF_ERROR_PARAM_ETYPE 0x00
  56. #define ETYPE_KEEPALIVE_TIMEOUT 0x01
  57. /* supported DJ HID && RF report types */
  58. #define REPORT_TYPE_KEYBOARD 0x01
  59. #define REPORT_TYPE_MOUSE 0x02
  60. #define REPORT_TYPE_CONSUMER_CONTROL 0x03
  61. #define REPORT_TYPE_SYSTEM_CONTROL 0x04
  62. #define REPORT_TYPE_MEDIA_CENTER 0x08
  63. #define REPORT_TYPE_LEDS 0x0E
  64. /* RF Report types bitfield */
  65. #define STD_KEYBOARD BIT(1)
  66. #define STD_MOUSE BIT(2)
  67. #define MULTIMEDIA BIT(3)
  68. #define POWER_KEYS BIT(4)
  69. #define KBD_MOUSE BIT(5)
  70. #define MEDIA_CENTER BIT(8)
  71. #define KBD_LEDS BIT(14)
  72. /* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */
  73. #define HIDPP BIT_ULL(63)
  74. /* HID++ Device Connected Notification */
  75. #define REPORT_TYPE_NOTIF_DEVICE_CONNECTED 0x41
  76. #define HIDPP_PARAM_PROTO_TYPE 0x00
  77. #define HIDPP_PARAM_DEVICE_INFO 0x01
  78. #define HIDPP_PARAM_EQUAD_LSB 0x02
  79. #define HIDPP_PARAM_EQUAD_MSB 0x03
  80. #define HIDPP_PARAM_27MHZ_DEVID 0x03
  81. #define HIDPP_DEVICE_TYPE_MASK GENMASK(3, 0)
  82. #define HIDPP_LINK_STATUS_MASK BIT(6)
  83. #define HIDPP_MANUFACTURER_MASK BIT(7)
  84. #define HIDPP_27MHZ_SECURE_MASK BIT(7)
  85. #define HIDPP_DEVICE_TYPE_KEYBOARD 1
  86. #define HIDPP_DEVICE_TYPE_MOUSE 2
  87. #define HIDPP_SET_REGISTER 0x80
  88. #define HIDPP_GET_LONG_REGISTER 0x83
  89. #define HIDPP_REG_CONNECTION_STATE 0x02
  90. #define HIDPP_REG_PAIRING_INFORMATION 0xB5
  91. #define HIDPP_PAIRING_INFORMATION 0x20
  92. #define HIDPP_FAKE_DEVICE_ARRIVAL 0x02
  93. enum recvr_type {
  94. recvr_type_dj,
  95. recvr_type_hidpp,
  96. recvr_type_gaming_hidpp,
  97. recvr_type_mouse_only,
  98. recvr_type_27mhz,
  99. recvr_type_bluetooth,
  100. recvr_type_dinovo,
  101. };
  102. struct dj_report {
  103. u8 report_id;
  104. u8 device_index;
  105. u8 report_type;
  106. u8 report_params[DJREPORT_SHORT_LENGTH - 3];
  107. };
  108. struct hidpp_event {
  109. u8 report_id;
  110. u8 device_index;
  111. u8 sub_id;
  112. u8 params[HIDPP_REPORT_LONG_LENGTH - 3U];
  113. } __packed;
  114. struct dj_receiver_dev {
  115. struct hid_device *mouse;
  116. struct hid_device *keyboard;
  117. struct hid_device *hidpp;
  118. struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES +
  119. DJ_DEVICE_INDEX_MIN];
  120. struct list_head list;
  121. struct kref kref;
  122. struct work_struct work;
  123. struct kfifo notif_fifo;
  124. unsigned long last_query; /* in jiffies */
  125. bool ready;
  126. enum recvr_type type;
  127. unsigned int unnumbered_application;
  128. spinlock_t lock;
  129. };
  130. struct dj_device {
  131. struct hid_device *hdev;
  132. struct dj_receiver_dev *dj_receiver_dev;
  133. u64 reports_supported;
  134. u8 device_index;
  135. };
  136. #define WORKITEM_TYPE_EMPTY 0
  137. #define WORKITEM_TYPE_PAIRED 1
  138. #define WORKITEM_TYPE_UNPAIRED 2
  139. #define WORKITEM_TYPE_UNKNOWN 255
  140. struct dj_workitem {
  141. u8 type; /* WORKITEM_TYPE_* */
  142. u8 device_index;
  143. u8 device_type;
  144. u8 quad_id_msb;
  145. u8 quad_id_lsb;
  146. u64 reports_supported;
  147. };
  148. /* Keyboard descriptor (1) */
  149. static const char kbd_descriptor[] = {
  150. 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */
  151. 0x09, 0x06, /* USAGE (Keyboard) */
  152. 0xA1, 0x01, /* COLLECTION (Application) */
  153. 0x85, 0x01, /* REPORT_ID (1) */
  154. 0x95, 0x08, /* REPORT_COUNT (8) */
  155. 0x75, 0x01, /* REPORT_SIZE (1) */
  156. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  157. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
  158. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
  159. 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */
  160. 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */
  161. 0x81, 0x02, /* INPUT (Data,Var,Abs) */
  162. 0x95, 0x06, /* REPORT_COUNT (6) */
  163. 0x75, 0x08, /* REPORT_SIZE (8) */
  164. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  165. 0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */
  166. 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
  167. 0x19, 0x00, /* USAGE_MINIMUM (no event) */
  168. 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */
  169. 0x81, 0x00, /* INPUT (Data,Ary,Abs) */
  170. 0x85, 0x0e, /* REPORT_ID (14) */
  171. 0x05, 0x08, /* USAGE PAGE (LED page) */
  172. 0x95, 0x05, /* REPORT COUNT (5) */
  173. 0x75, 0x01, /* REPORT SIZE (1) */
  174. 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
  175. 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
  176. 0x19, 0x01, /* USAGE MINIMUM (1) */
  177. 0x29, 0x05, /* USAGE MAXIMUM (5) */
  178. 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */
  179. 0x95, 0x01, /* REPORT COUNT (1) */
  180. 0x75, 0x03, /* REPORT SIZE (3) */
  181. 0x91, 0x01, /* OUTPUT (Constant) */
  182. 0xC0
  183. };
  184. /* Mouse descriptor (2) */
  185. static const char mse_descriptor[] = {
  186. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  187. 0x09, 0x02, /* USAGE (Mouse) */
  188. 0xA1, 0x01, /* COLLECTION (Application) */
  189. 0x85, 0x02, /* REPORT_ID = 2 */
  190. 0x09, 0x01, /* USAGE (pointer) */
  191. 0xA1, 0x00, /* COLLECTION (physical) */
  192. 0x05, 0x09, /* USAGE_PAGE (buttons) */
  193. 0x19, 0x01, /* USAGE_MIN (1) */
  194. 0x29, 0x10, /* USAGE_MAX (16) */
  195. 0x15, 0x00, /* LOGICAL_MIN (0) */
  196. 0x25, 0x01, /* LOGICAL_MAX (1) */
  197. 0x95, 0x10, /* REPORT_COUNT (16) */
  198. 0x75, 0x01, /* REPORT_SIZE (1) */
  199. 0x81, 0x02, /* INPUT (data var abs) */
  200. 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
  201. 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
  202. 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
  203. 0x75, 0x0C, /* REPORT_SIZE (12) */
  204. 0x95, 0x02, /* REPORT_COUNT (2) */
  205. 0x09, 0x30, /* USAGE (X) */
  206. 0x09, 0x31, /* USAGE (Y) */
  207. 0x81, 0x06, /* INPUT */
  208. 0x15, 0x81, /* LOGICAL_MIN (-127) */
  209. 0x25, 0x7F, /* LOGICAL_MAX (127) */
  210. 0x75, 0x08, /* REPORT_SIZE (8) */
  211. 0x95, 0x01, /* REPORT_COUNT (1) */
  212. 0x09, 0x38, /* USAGE (wheel) */
  213. 0x81, 0x06, /* INPUT */
  214. 0x05, 0x0C, /* USAGE_PAGE(consumer) */
  215. 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
  216. 0x95, 0x01, /* REPORT_COUNT (1) */
  217. 0x81, 0x06, /* INPUT */
  218. 0xC0, /* END_COLLECTION */
  219. 0xC0, /* END_COLLECTION */
  220. };
  221. /* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */
  222. static const char mse_27mhz_descriptor[] = {
  223. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  224. 0x09, 0x02, /* USAGE (Mouse) */
  225. 0xA1, 0x01, /* COLLECTION (Application) */
  226. 0x85, 0x02, /* REPORT_ID = 2 */
  227. 0x09, 0x01, /* USAGE (pointer) */
  228. 0xA1, 0x00, /* COLLECTION (physical) */
  229. 0x05, 0x09, /* USAGE_PAGE (buttons) */
  230. 0x19, 0x01, /* USAGE_MIN (1) */
  231. 0x29, 0x08, /* USAGE_MAX (8) */
  232. 0x15, 0x00, /* LOGICAL_MIN (0) */
  233. 0x25, 0x01, /* LOGICAL_MAX (1) */
  234. 0x95, 0x08, /* REPORT_COUNT (8) */
  235. 0x75, 0x01, /* REPORT_SIZE (1) */
  236. 0x81, 0x02, /* INPUT (data var abs) */
  237. 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
  238. 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
  239. 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
  240. 0x75, 0x0C, /* REPORT_SIZE (12) */
  241. 0x95, 0x02, /* REPORT_COUNT (2) */
  242. 0x09, 0x30, /* USAGE (X) */
  243. 0x09, 0x31, /* USAGE (Y) */
  244. 0x81, 0x06, /* INPUT */
  245. 0x15, 0x81, /* LOGICAL_MIN (-127) */
  246. 0x25, 0x7F, /* LOGICAL_MAX (127) */
  247. 0x75, 0x08, /* REPORT_SIZE (8) */
  248. 0x95, 0x01, /* REPORT_COUNT (1) */
  249. 0x09, 0x38, /* USAGE (wheel) */
  250. 0x81, 0x06, /* INPUT */
  251. 0x05, 0x0C, /* USAGE_PAGE(consumer) */
  252. 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
  253. 0x95, 0x01, /* REPORT_COUNT (1) */
  254. 0x81, 0x06, /* INPUT */
  255. 0xC0, /* END_COLLECTION */
  256. 0xC0, /* END_COLLECTION */
  257. };
  258. /* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */
  259. static const char mse_bluetooth_descriptor[] = {
  260. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  261. 0x09, 0x02, /* USAGE (Mouse) */
  262. 0xA1, 0x01, /* COLLECTION (Application) */
  263. 0x85, 0x02, /* REPORT_ID = 2 */
  264. 0x09, 0x01, /* USAGE (pointer) */
  265. 0xA1, 0x00, /* COLLECTION (physical) */
  266. 0x05, 0x09, /* USAGE_PAGE (buttons) */
  267. 0x19, 0x01, /* USAGE_MIN (1) */
  268. 0x29, 0x08, /* USAGE_MAX (8) */
  269. 0x15, 0x00, /* LOGICAL_MIN (0) */
  270. 0x25, 0x01, /* LOGICAL_MAX (1) */
  271. 0x95, 0x08, /* REPORT_COUNT (8) */
  272. 0x75, 0x01, /* REPORT_SIZE (1) */
  273. 0x81, 0x02, /* INPUT (data var abs) */
  274. 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
  275. 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
  276. 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
  277. 0x75, 0x0C, /* REPORT_SIZE (12) */
  278. 0x95, 0x02, /* REPORT_COUNT (2) */
  279. 0x09, 0x30, /* USAGE (X) */
  280. 0x09, 0x31, /* USAGE (Y) */
  281. 0x81, 0x06, /* INPUT */
  282. 0x15, 0x81, /* LOGICAL_MIN (-127) */
  283. 0x25, 0x7F, /* LOGICAL_MAX (127) */
  284. 0x75, 0x08, /* REPORT_SIZE (8) */
  285. 0x95, 0x01, /* REPORT_COUNT (1) */
  286. 0x09, 0x38, /* USAGE (wheel) */
  287. 0x81, 0x06, /* INPUT */
  288. 0x05, 0x0C, /* USAGE_PAGE(consumer) */
  289. 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
  290. 0x15, 0xF9, /* LOGICAL_MIN (-7) */
  291. 0x25, 0x07, /* LOGICAL_MAX (7) */
  292. 0x75, 0x04, /* REPORT_SIZE (4) */
  293. 0x95, 0x01, /* REPORT_COUNT (1) */
  294. 0x81, 0x06, /* INPUT */
  295. 0x05, 0x09, /* USAGE_PAGE (buttons) */
  296. 0x19, 0x09, /* USAGE_MIN (9) */
  297. 0x29, 0x0C, /* USAGE_MAX (12) */
  298. 0x15, 0x00, /* LOGICAL_MIN (0) */
  299. 0x25, 0x01, /* LOGICAL_MAX (1) */
  300. 0x75, 0x01, /* REPORT_SIZE (1) */
  301. 0x95, 0x04, /* REPORT_COUNT (4) */
  302. 0x81, 0x02, /* INPUT (Data,Var,Abs) */
  303. 0xC0, /* END_COLLECTION */
  304. 0xC0, /* END_COLLECTION */
  305. };
  306. /* Mouse descriptor (5) for Bluetooth receiver, normal-res hwheel, 8 buttons */
  307. static const char mse5_bluetooth_descriptor[] = {
  308. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  309. 0x09, 0x02, /* Usage (Mouse) */
  310. 0xa1, 0x01, /* Collection (Application) */
  311. 0x85, 0x05, /* Report ID (5) */
  312. 0x09, 0x01, /* Usage (Pointer) */
  313. 0xa1, 0x00, /* Collection (Physical) */
  314. 0x05, 0x09, /* Usage Page (Button) */
  315. 0x19, 0x01, /* Usage Minimum (1) */
  316. 0x29, 0x08, /* Usage Maximum (8) */
  317. 0x15, 0x00, /* Logical Minimum (0) */
  318. 0x25, 0x01, /* Logical Maximum (1) */
  319. 0x95, 0x08, /* Report Count (8) */
  320. 0x75, 0x01, /* Report Size (1) */
  321. 0x81, 0x02, /* Input (Data,Var,Abs) */
  322. 0x05, 0x01, /* Usage Page (Generic Desktop) */
  323. 0x16, 0x01, 0xf8, /* Logical Minimum (-2047) */
  324. 0x26, 0xff, 0x07, /* Logical Maximum (2047) */
  325. 0x75, 0x0c, /* Report Size (12) */
  326. 0x95, 0x02, /* Report Count (2) */
  327. 0x09, 0x30, /* Usage (X) */
  328. 0x09, 0x31, /* Usage (Y) */
  329. 0x81, 0x06, /* Input (Data,Var,Rel) */
  330. 0x15, 0x81, /* Logical Minimum (-127) */
  331. 0x25, 0x7f, /* Logical Maximum (127) */
  332. 0x75, 0x08, /* Report Size (8) */
  333. 0x95, 0x01, /* Report Count (1) */
  334. 0x09, 0x38, /* Usage (Wheel) */
  335. 0x81, 0x06, /* Input (Data,Var,Rel) */
  336. 0x05, 0x0c, /* Usage Page (Consumer Devices) */
  337. 0x0a, 0x38, 0x02, /* Usage (AC Pan) */
  338. 0x15, 0x81, /* Logical Minimum (-127) */
  339. 0x25, 0x7f, /* Logical Maximum (127) */
  340. 0x75, 0x08, /* Report Size (8) */
  341. 0x95, 0x01, /* Report Count (1) */
  342. 0x81, 0x06, /* Input (Data,Var,Rel) */
  343. 0xc0, /* End Collection */
  344. 0xc0, /* End Collection */
  345. };
  346. /* Gaming Mouse descriptor (2) */
  347. static const char mse_high_res_descriptor[] = {
  348. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  349. 0x09, 0x02, /* USAGE (Mouse) */
  350. 0xA1, 0x01, /* COLLECTION (Application) */
  351. 0x85, 0x02, /* REPORT_ID = 2 */
  352. 0x09, 0x01, /* USAGE (pointer) */
  353. 0xA1, 0x00, /* COLLECTION (physical) */
  354. 0x05, 0x09, /* USAGE_PAGE (buttons) */
  355. 0x19, 0x01, /* USAGE_MIN (1) */
  356. 0x29, 0x10, /* USAGE_MAX (16) */
  357. 0x15, 0x00, /* LOGICAL_MIN (0) */
  358. 0x25, 0x01, /* LOGICAL_MAX (1) */
  359. 0x95, 0x10, /* REPORT_COUNT (16) */
  360. 0x75, 0x01, /* REPORT_SIZE (1) */
  361. 0x81, 0x02, /* INPUT (data var abs) */
  362. 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
  363. 0x16, 0x01, 0x80, /* LOGICAL_MIN (-32767) */
  364. 0x26, 0xFF, 0x7F, /* LOGICAL_MAX (32767) */
  365. 0x75, 0x10, /* REPORT_SIZE (16) */
  366. 0x95, 0x02, /* REPORT_COUNT (2) */
  367. 0x09, 0x30, /* USAGE (X) */
  368. 0x09, 0x31, /* USAGE (Y) */
  369. 0x81, 0x06, /* INPUT */
  370. 0x15, 0x81, /* LOGICAL_MIN (-127) */
  371. 0x25, 0x7F, /* LOGICAL_MAX (127) */
  372. 0x75, 0x08, /* REPORT_SIZE (8) */
  373. 0x95, 0x01, /* REPORT_COUNT (1) */
  374. 0x09, 0x38, /* USAGE (wheel) */
  375. 0x81, 0x06, /* INPUT */
  376. 0x05, 0x0C, /* USAGE_PAGE(consumer) */
  377. 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
  378. 0x95, 0x01, /* REPORT_COUNT (1) */
  379. 0x81, 0x06, /* INPUT */
  380. 0xC0, /* END_COLLECTION */
  381. 0xC0, /* END_COLLECTION */
  382. };
  383. /* Consumer Control descriptor (3) */
  384. static const char consumer_descriptor[] = {
  385. 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
  386. 0x09, 0x01, /* USAGE (Consumer Control) */
  387. 0xA1, 0x01, /* COLLECTION (Application) */
  388. 0x85, 0x03, /* REPORT_ID = 3 */
  389. 0x75, 0x10, /* REPORT_SIZE (16) */
  390. 0x95, 0x02, /* REPORT_COUNT (2) */
  391. 0x15, 0x01, /* LOGICAL_MIN (1) */
  392. 0x26, 0xFF, 0x02, /* LOGICAL_MAX (767) */
  393. 0x19, 0x01, /* USAGE_MIN (1) */
  394. 0x2A, 0xFF, 0x02, /* USAGE_MAX (767) */
  395. 0x81, 0x00, /* INPUT (Data Ary Abs) */
  396. 0xC0, /* END_COLLECTION */
  397. }; /* */
  398. /* System control descriptor (4) */
  399. static const char syscontrol_descriptor[] = {
  400. 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
  401. 0x09, 0x80, /* USAGE (System Control) */
  402. 0xA1, 0x01, /* COLLECTION (Application) */
  403. 0x85, 0x04, /* REPORT_ID = 4 */
  404. 0x75, 0x02, /* REPORT_SIZE (2) */
  405. 0x95, 0x01, /* REPORT_COUNT (1) */
  406. 0x15, 0x01, /* LOGICAL_MIN (1) */
  407. 0x25, 0x03, /* LOGICAL_MAX (3) */
  408. 0x09, 0x82, /* USAGE (System Sleep) */
  409. 0x09, 0x81, /* USAGE (System Power Down) */
  410. 0x09, 0x83, /* USAGE (System Wake Up) */
  411. 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */
  412. 0x75, 0x06, /* REPORT_SIZE (6) */
  413. 0x81, 0x03, /* INPUT (Cnst Var Abs) */
  414. 0xC0, /* END_COLLECTION */
  415. };
  416. /* Media descriptor (8) */
  417. static const char media_descriptor[] = {
  418. 0x06, 0xbc, 0xff, /* Usage Page 0xffbc */
  419. 0x09, 0x88, /* Usage 0x0088 */
  420. 0xa1, 0x01, /* BeginCollection */
  421. 0x85, 0x08, /* Report ID 8 */
  422. 0x19, 0x01, /* Usage Min 0x0001 */
  423. 0x29, 0xff, /* Usage Max 0x00ff */
  424. 0x15, 0x01, /* Logical Min 1 */
  425. 0x26, 0xff, 0x00, /* Logical Max 255 */
  426. 0x75, 0x08, /* Report Size 8 */
  427. 0x95, 0x01, /* Report Count 1 */
  428. 0x81, 0x00, /* Input */
  429. 0xc0, /* EndCollection */
  430. }; /* */
  431. /* HIDPP descriptor */
  432. static const char hidpp_descriptor[] = {
  433. 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
  434. 0x09, 0x01, /* Usage (Vendor Usage 1) */
  435. 0xa1, 0x01, /* Collection (Application) */
  436. 0x85, 0x10, /* Report ID (16) */
  437. 0x75, 0x08, /* Report Size (8) */
  438. 0x95, 0x06, /* Report Count (6) */
  439. 0x15, 0x00, /* Logical Minimum (0) */
  440. 0x26, 0xff, 0x00, /* Logical Maximum (255) */
  441. 0x09, 0x01, /* Usage (Vendor Usage 1) */
  442. 0x81, 0x00, /* Input (Data,Arr,Abs) */
  443. 0x09, 0x01, /* Usage (Vendor Usage 1) */
  444. 0x91, 0x00, /* Output (Data,Arr,Abs) */
  445. 0xc0, /* End Collection */
  446. 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
  447. 0x09, 0x02, /* Usage (Vendor Usage 2) */
  448. 0xa1, 0x01, /* Collection (Application) */
  449. 0x85, 0x11, /* Report ID (17) */
  450. 0x75, 0x08, /* Report Size (8) */
  451. 0x95, 0x13, /* Report Count (19) */
  452. 0x15, 0x00, /* Logical Minimum (0) */
  453. 0x26, 0xff, 0x00, /* Logical Maximum (255) */
  454. 0x09, 0x02, /* Usage (Vendor Usage 2) */
  455. 0x81, 0x00, /* Input (Data,Arr,Abs) */
  456. 0x09, 0x02, /* Usage (Vendor Usage 2) */
  457. 0x91, 0x00, /* Output (Data,Arr,Abs) */
  458. 0xc0, /* End Collection */
  459. 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
  460. 0x09, 0x04, /* Usage (Vendor Usage 0x04) */
  461. 0xa1, 0x01, /* Collection (Application) */
  462. 0x85, 0x20, /* Report ID (32) */
  463. 0x75, 0x08, /* Report Size (8) */
  464. 0x95, 0x0e, /* Report Count (14) */
  465. 0x15, 0x00, /* Logical Minimum (0) */
  466. 0x26, 0xff, 0x00, /* Logical Maximum (255) */
  467. 0x09, 0x41, /* Usage (Vendor Usage 0x41) */
  468. 0x81, 0x00, /* Input (Data,Arr,Abs) */
  469. 0x09, 0x41, /* Usage (Vendor Usage 0x41) */
  470. 0x91, 0x00, /* Output (Data,Arr,Abs) */
  471. 0x85, 0x21, /* Report ID (33) */
  472. 0x95, 0x1f, /* Report Count (31) */
  473. 0x15, 0x00, /* Logical Minimum (0) */
  474. 0x26, 0xff, 0x00, /* Logical Maximum (255) */
  475. 0x09, 0x42, /* Usage (Vendor Usage 0x42) */
  476. 0x81, 0x00, /* Input (Data,Arr,Abs) */
  477. 0x09, 0x42, /* Usage (Vendor Usage 0x42) */
  478. 0x91, 0x00, /* Output (Data,Arr,Abs) */
  479. 0xc0, /* End Collection */
  480. };
  481. /* Maximum size of all defined hid reports in bytes (including report id) */
  482. #define MAX_REPORT_SIZE 8
  483. /* Make sure all descriptors are present here */
  484. #define MAX_RDESC_SIZE \
  485. (sizeof(kbd_descriptor) + \
  486. sizeof(mse_bluetooth_descriptor) + \
  487. sizeof(mse5_bluetooth_descriptor) + \
  488. sizeof(consumer_descriptor) + \
  489. sizeof(syscontrol_descriptor) + \
  490. sizeof(media_descriptor) + \
  491. sizeof(hidpp_descriptor))
  492. /* Number of possible hid report types that can be created by this driver.
  493. *
  494. * Right now, RF report types have the same report types (or report id's)
  495. * than the hid report created from those RF reports. In the future
  496. * this doesnt have to be true.
  497. *
  498. * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds
  499. * to hid report id 0x01, this is standard keyboard. Same thing applies to mice
  500. * reports and consumer control, etc. If a new RF report is created, it doesn't
  501. * has to have the same report id as its corresponding hid report, so an
  502. * translation may have to take place for future report types.
  503. */
  504. #define NUMBER_OF_HID_REPORTS 32
  505. static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = {
  506. [1] = 8, /* Standard keyboard */
  507. [2] = 8, /* Standard mouse */
  508. [3] = 5, /* Consumer control */
  509. [4] = 2, /* System control */
  510. [8] = 2, /* Media Center */
  511. };
  512. #define LOGITECH_DJ_INTERFACE_NUMBER 0x02
  513. static const struct hid_ll_driver logi_dj_ll_driver;
  514. static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
  515. static void delayedwork_callback(struct work_struct *work);
  516. static LIST_HEAD(dj_hdev_list);
  517. static DEFINE_MUTEX(dj_hdev_list_lock);
  518. static bool recvr_type_is_bluetooth(enum recvr_type type)
  519. {
  520. return type == recvr_type_bluetooth || type == recvr_type_dinovo;
  521. }
  522. /*
  523. * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows
  524. * compatibility they have multiple USB interfaces. On HID++ receivers we need
  525. * to listen for input reports on both interfaces. The functions below are used
  526. * to create a single struct dj_receiver_dev for all interfaces belonging to
  527. * a single USB-device / receiver.
  528. */
  529. static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev,
  530. enum recvr_type type)
  531. {
  532. struct dj_receiver_dev *djrcv_dev;
  533. char sep;
  534. /*
  535. * The bluetooth receiver contains a built-in hub and has separate
  536. * USB-devices for the keyboard and mouse interfaces.
  537. */
  538. sep = recvr_type_is_bluetooth(type) ? '.' : '/';
  539. /* Try to find an already-probed interface from the same device */
  540. list_for_each_entry(djrcv_dev, &dj_hdev_list, list) {
  541. if (djrcv_dev->mouse &&
  542. hid_compare_device_paths(hdev, djrcv_dev->mouse, sep)) {
  543. kref_get(&djrcv_dev->kref);
  544. return djrcv_dev;
  545. }
  546. if (djrcv_dev->keyboard &&
  547. hid_compare_device_paths(hdev, djrcv_dev->keyboard, sep)) {
  548. kref_get(&djrcv_dev->kref);
  549. return djrcv_dev;
  550. }
  551. if (djrcv_dev->hidpp &&
  552. hid_compare_device_paths(hdev, djrcv_dev->hidpp, sep)) {
  553. kref_get(&djrcv_dev->kref);
  554. return djrcv_dev;
  555. }
  556. }
  557. return NULL;
  558. }
  559. static void dj_release_receiver_dev(struct kref *kref)
  560. {
  561. struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref);
  562. list_del(&djrcv_dev->list);
  563. kfifo_free(&djrcv_dev->notif_fifo);
  564. kfree(djrcv_dev);
  565. }
  566. static void dj_put_receiver_dev(struct hid_device *hdev)
  567. {
  568. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  569. mutex_lock(&dj_hdev_list_lock);
  570. if (djrcv_dev->mouse == hdev)
  571. djrcv_dev->mouse = NULL;
  572. if (djrcv_dev->keyboard == hdev)
  573. djrcv_dev->keyboard = NULL;
  574. if (djrcv_dev->hidpp == hdev)
  575. djrcv_dev->hidpp = NULL;
  576. kref_put(&djrcv_dev->kref, dj_release_receiver_dev);
  577. mutex_unlock(&dj_hdev_list_lock);
  578. }
  579. static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev,
  580. enum recvr_type type,
  581. unsigned int application,
  582. bool is_hidpp)
  583. {
  584. struct dj_receiver_dev *djrcv_dev;
  585. mutex_lock(&dj_hdev_list_lock);
  586. djrcv_dev = dj_find_receiver_dev(hdev, type);
  587. if (!djrcv_dev) {
  588. djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL);
  589. if (!djrcv_dev)
  590. goto out;
  591. INIT_WORK(&djrcv_dev->work, delayedwork_callback);
  592. spin_lock_init(&djrcv_dev->lock);
  593. if (kfifo_alloc(&djrcv_dev->notif_fifo,
  594. DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem),
  595. GFP_KERNEL)) {
  596. kfree(djrcv_dev);
  597. djrcv_dev = NULL;
  598. goto out;
  599. }
  600. kref_init(&djrcv_dev->kref);
  601. list_add_tail(&djrcv_dev->list, &dj_hdev_list);
  602. djrcv_dev->last_query = jiffies;
  603. djrcv_dev->type = type;
  604. }
  605. if (application == HID_GD_KEYBOARD)
  606. djrcv_dev->keyboard = hdev;
  607. if (application == HID_GD_MOUSE)
  608. djrcv_dev->mouse = hdev;
  609. if (is_hidpp)
  610. djrcv_dev->hidpp = hdev;
  611. hid_set_drvdata(hdev, djrcv_dev);
  612. out:
  613. mutex_unlock(&dj_hdev_list_lock);
  614. return djrcv_dev;
  615. }
  616. static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,
  617. struct dj_workitem *workitem)
  618. {
  619. /* Called in delayed work context */
  620. struct dj_device *dj_dev;
  621. unsigned long flags;
  622. spin_lock_irqsave(&djrcv_dev->lock, flags);
  623. dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index];
  624. djrcv_dev->paired_dj_devices[workitem->device_index] = NULL;
  625. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  626. if (dj_dev != NULL) {
  627. hid_destroy_device(dj_dev->hdev);
  628. kfree(dj_dev);
  629. } else {
  630. hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n",
  631. __func__);
  632. }
  633. }
  634. static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
  635. struct dj_workitem *workitem)
  636. {
  637. /* Called in delayed work context */
  638. struct hid_device *djrcv_hdev = djrcv_dev->hidpp;
  639. struct hid_device *dj_hiddev;
  640. struct dj_device *dj_dev;
  641. u8 device_index = workitem->device_index;
  642. unsigned long flags;
  643. /* Device index goes from 1 to 6, we need 3 bytes to store the
  644. * semicolon, the index, and a null terminator
  645. */
  646. unsigned char tmpstr[3];
  647. /* We are the only one ever adding a device, no need to lock */
  648. if (djrcv_dev->paired_dj_devices[device_index]) {
  649. /* The device is already known. No need to reallocate it. */
  650. dbg_hid("%s: device is already known\n", __func__);
  651. return;
  652. }
  653. dj_hiddev = hid_allocate_device();
  654. if (IS_ERR(dj_hiddev)) {
  655. hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__);
  656. return;
  657. }
  658. dj_hiddev->ll_driver = &logi_dj_ll_driver;
  659. dj_hiddev->dev.parent = &djrcv_hdev->dev;
  660. dj_hiddev->bus = BUS_USB;
  661. dj_hiddev->vendor = djrcv_hdev->vendor;
  662. dj_hiddev->product = (workitem->quad_id_msb << 8) |
  663. workitem->quad_id_lsb;
  664. if (workitem->device_type) {
  665. const char *type_str = "Device";
  666. switch (workitem->device_type) {
  667. case 0x01: type_str = "Keyboard"; break;
  668. case 0x02: type_str = "Mouse"; break;
  669. case 0x03: type_str = "Numpad"; break;
  670. case 0x04: type_str = "Presenter"; break;
  671. case 0x07: type_str = "Remote Control"; break;
  672. case 0x08: type_str = "Trackball"; break;
  673. case 0x09: type_str = "Touchpad"; break;
  674. }
  675. snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
  676. "Logitech Wireless %s PID:%04x",
  677. type_str, dj_hiddev->product);
  678. } else {
  679. snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
  680. "Logitech Wireless Device PID:%04x",
  681. dj_hiddev->product);
  682. }
  683. if (djrcv_dev->type == recvr_type_27mhz)
  684. dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE;
  685. else
  686. dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;
  687. memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys));
  688. snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index);
  689. strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys));
  690. dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL);
  691. if (!dj_dev) {
  692. hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__);
  693. goto dj_device_allocate_fail;
  694. }
  695. dj_dev->reports_supported = workitem->reports_supported;
  696. dj_dev->hdev = dj_hiddev;
  697. dj_dev->dj_receiver_dev = djrcv_dev;
  698. dj_dev->device_index = device_index;
  699. dj_hiddev->driver_data = dj_dev;
  700. spin_lock_irqsave(&djrcv_dev->lock, flags);
  701. djrcv_dev->paired_dj_devices[device_index] = dj_dev;
  702. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  703. if (hid_add_device(dj_hiddev)) {
  704. hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__);
  705. goto hid_add_device_fail;
  706. }
  707. return;
  708. hid_add_device_fail:
  709. spin_lock_irqsave(&djrcv_dev->lock, flags);
  710. djrcv_dev->paired_dj_devices[device_index] = NULL;
  711. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  712. kfree(dj_dev);
  713. dj_device_allocate_fail:
  714. hid_destroy_device(dj_hiddev);
  715. }
  716. static void delayedwork_callback(struct work_struct *work)
  717. {
  718. struct dj_receiver_dev *djrcv_dev =
  719. container_of(work, struct dj_receiver_dev, work);
  720. struct dj_workitem workitem;
  721. unsigned long flags;
  722. int count;
  723. int retval;
  724. dbg_hid("%s\n", __func__);
  725. spin_lock_irqsave(&djrcv_dev->lock, flags);
  726. /*
  727. * Since we attach to multiple interfaces, we may get scheduled before
  728. * we are bound to the HID++ interface, catch this.
  729. */
  730. if (!djrcv_dev->ready) {
  731. pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n",
  732. __func__);
  733. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  734. return;
  735. }
  736. count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  737. if (count != sizeof(workitem)) {
  738. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  739. return;
  740. }
  741. if (!kfifo_is_empty(&djrcv_dev->notif_fifo))
  742. schedule_work(&djrcv_dev->work);
  743. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  744. switch (workitem.type) {
  745. case WORKITEM_TYPE_PAIRED:
  746. logi_dj_recv_add_djhid_device(djrcv_dev, &workitem);
  747. break;
  748. case WORKITEM_TYPE_UNPAIRED:
  749. logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem);
  750. break;
  751. case WORKITEM_TYPE_UNKNOWN:
  752. retval = logi_dj_recv_query_paired_devices(djrcv_dev);
  753. if (retval) {
  754. hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n",
  755. __func__, retval);
  756. }
  757. break;
  758. case WORKITEM_TYPE_EMPTY:
  759. dbg_hid("%s: device list is empty\n", __func__);
  760. break;
  761. }
  762. }
  763. /*
  764. * Sometimes we receive reports for which we do not have a paired dj_device
  765. * associated with the device_index or report-type to forward the report to.
  766. * This means that the original "device paired" notification corresponding
  767. * to the dj_device never arrived to this driver. Possible reasons for this are:
  768. * 1) hid-core discards all packets coming from a device during probe().
  769. * 2) if the receiver is plugged into a KVM switch then the pairing reports
  770. * are only forwarded to it if the focus is on this PC.
  771. * This function deals with this by re-asking the receiver for the list of
  772. * connected devices in the delayed work callback.
  773. * This function MUST be called with djrcv->lock held.
  774. */
  775. static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev)
  776. {
  777. struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN };
  778. /* Rate limit queries done because of unhandled reports to 2/sec */
  779. if (time_before(jiffies, djrcv_dev->last_query + HZ / 2))
  780. return;
  781. kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  782. schedule_work(&djrcv_dev->work);
  783. }
  784. static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,
  785. struct dj_report *dj_report)
  786. {
  787. /* We are called from atomic context (tasklet && djrcv->lock held) */
  788. struct dj_workitem workitem = {
  789. .device_index = dj_report->device_index,
  790. };
  791. switch (dj_report->report_type) {
  792. case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
  793. workitem.type = WORKITEM_TYPE_PAIRED;
  794. if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &
  795. SPFUNCTION_DEVICE_LIST_EMPTY) {
  796. workitem.type = WORKITEM_TYPE_EMPTY;
  797. break;
  798. }
  799. fallthrough;
  800. case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
  801. workitem.quad_id_msb =
  802. dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB];
  803. workitem.quad_id_lsb =
  804. dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];
  805. workitem.reports_supported = get_unaligned_le32(
  806. dj_report->report_params +
  807. DEVICE_PAIRED_RF_REPORT_TYPE);
  808. workitem.reports_supported |= HIDPP;
  809. if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED)
  810. workitem.type = WORKITEM_TYPE_UNPAIRED;
  811. break;
  812. default:
  813. logi_dj_recv_queue_unknown_work(djrcv_dev);
  814. return;
  815. }
  816. kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  817. schedule_work(&djrcv_dev->work);
  818. }
  819. /*
  820. * Some quad/bluetooth keyboards have a builtin touchpad in this case we see
  821. * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the
  822. * touchpad to work we must also forward mouse input reports to the dj_hiddev
  823. * created for the keyboard (instead of forwarding them to a second paired
  824. * device with a device_type of REPORT_TYPE_MOUSE as we normally would).
  825. *
  826. * On Dinovo receivers the keyboard's touchpad and an optional paired actual
  827. * mouse send separate input reports, INPUT(2) aka STD_MOUSE for the mouse
  828. * and INPUT(5) aka KBD_MOUSE for the keyboard's touchpad.
  829. *
  830. * On MX5x00 receivers (which can also be paired with a Dinovo keyboard)
  831. * INPUT(2) is used for both an optional paired actual mouse and for the
  832. * keyboard's touchpad.
  833. */
  834. static const u16 kbd_builtin_touchpad_ids[] = {
  835. 0xb309, /* Dinovo Edge */
  836. 0xb30c, /* Dinovo Mini */
  837. };
  838. static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev,
  839. struct hidpp_event *hidpp_report,
  840. struct dj_workitem *workitem)
  841. {
  842. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  843. int i, id;
  844. workitem->type = WORKITEM_TYPE_PAIRED;
  845. workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
  846. HIDPP_DEVICE_TYPE_MASK;
  847. workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB];
  848. workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB];
  849. switch (workitem->device_type) {
  850. case REPORT_TYPE_KEYBOARD:
  851. workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
  852. POWER_KEYS | MEDIA_CENTER |
  853. HIDPP;
  854. id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb;
  855. for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) {
  856. if (id == kbd_builtin_touchpad_ids[i]) {
  857. if (djrcv_dev->type == recvr_type_dinovo)
  858. workitem->reports_supported |= KBD_MOUSE;
  859. else
  860. workitem->reports_supported |= STD_MOUSE;
  861. break;
  862. }
  863. }
  864. break;
  865. case REPORT_TYPE_MOUSE:
  866. workitem->reports_supported |= STD_MOUSE | HIDPP | MULTIMEDIA;
  867. break;
  868. }
  869. }
  870. static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev,
  871. struct hidpp_event *hidpp_report,
  872. struct dj_workitem *workitem)
  873. {
  874. workitem->type = WORKITEM_TYPE_PAIRED;
  875. workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID];
  876. switch (hidpp_report->device_index) {
  877. case 1: /* Index 1 is always a mouse */
  878. case 2: /* Index 2 is always a mouse */
  879. workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE;
  880. workitem->reports_supported |= STD_MOUSE | HIDPP;
  881. break;
  882. case 3: /* Index 3 is always the keyboard */
  883. if (hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & HIDPP_27MHZ_SECURE_MASK) {
  884. hid_info(hdev, "Keyboard connection is encrypted\n");
  885. } else {
  886. hid_warn(hdev, "Keyboard events are send over the air in plain-text / unencrypted\n");
  887. hid_warn(hdev, "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n");
  888. }
  889. fallthrough;
  890. case 4: /* Index 4 is used for an optional separate numpad */
  891. workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD;
  892. workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
  893. POWER_KEYS | HIDPP;
  894. break;
  895. default:
  896. hid_warn(hdev, "%s: unexpected device-index %d", __func__,
  897. hidpp_report->device_index);
  898. }
  899. }
  900. static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
  901. struct hidpp_event *hidpp_report)
  902. {
  903. /* We are called from atomic context (tasklet && djrcv->lock held) */
  904. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  905. const char *device_type = "UNKNOWN";
  906. struct dj_workitem workitem = {
  907. .type = WORKITEM_TYPE_EMPTY,
  908. .device_index = hidpp_report->device_index,
  909. };
  910. switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) {
  911. case 0x01:
  912. device_type = "Bluetooth";
  913. /* Bluetooth connect packet contents is the same as (e)QUAD */
  914. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  915. if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
  916. HIDPP_MANUFACTURER_MASK)) {
  917. hid_info(hdev, "Non Logitech device connected on slot %d\n",
  918. hidpp_report->device_index);
  919. workitem.reports_supported &= ~HIDPP;
  920. }
  921. break;
  922. case 0x02:
  923. device_type = "27 Mhz";
  924. logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem);
  925. break;
  926. case 0x03:
  927. device_type = "QUAD or eQUAD";
  928. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  929. break;
  930. case 0x04:
  931. device_type = "eQUAD step 4 DJ";
  932. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  933. break;
  934. case 0x05:
  935. device_type = "DFU Lite";
  936. break;
  937. case 0x06:
  938. device_type = "eQUAD step 4 Lite";
  939. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  940. break;
  941. case 0x07:
  942. device_type = "eQUAD step 4 Gaming";
  943. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  944. workitem.reports_supported |= STD_KEYBOARD;
  945. break;
  946. case 0x08:
  947. device_type = "eQUAD step 4 for gamepads";
  948. break;
  949. case 0x0a:
  950. device_type = "eQUAD nano Lite";
  951. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  952. break;
  953. case 0x0c:
  954. device_type = "eQUAD Lightspeed 1";
  955. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  956. workitem.reports_supported |= STD_KEYBOARD;
  957. break;
  958. case 0x0d:
  959. device_type = "eQUAD Lightspeed 1.1";
  960. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  961. workitem.reports_supported |= STD_KEYBOARD;
  962. break;
  963. case 0x0f:
  964. case 0x11:
  965. device_type = "eQUAD Lightspeed 1.2";
  966. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  967. workitem.reports_supported |= STD_KEYBOARD;
  968. break;
  969. }
  970. /* custom receiver device (eg. powerplay) */
  971. if (hidpp_report->device_index == 7) {
  972. workitem.reports_supported |= HIDPP;
  973. }
  974. if (workitem.type == WORKITEM_TYPE_EMPTY) {
  975. hid_warn(hdev,
  976. "unusable device of type %s (0x%02x) connected on slot %d",
  977. device_type,
  978. hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
  979. hidpp_report->device_index);
  980. return;
  981. }
  982. hid_info(hdev, "device of type %s (0x%02x) connected on slot %d",
  983. device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
  984. hidpp_report->device_index);
  985. kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  986. schedule_work(&djrcv_dev->work);
  987. }
  988. static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
  989. struct dj_report *dj_report)
  990. {
  991. /* We are called from atomic context (tasklet && djrcv->lock held) */
  992. unsigned int i;
  993. u8 reportbuffer[MAX_REPORT_SIZE];
  994. struct dj_device *djdev;
  995. djdev = djrcv_dev->paired_dj_devices[dj_report->device_index];
  996. memset(reportbuffer, 0, sizeof(reportbuffer));
  997. for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) {
  998. if (djdev->reports_supported & (1 << i)) {
  999. reportbuffer[0] = i;
  1000. if (hid_input_report(djdev->hdev,
  1001. HID_INPUT_REPORT,
  1002. reportbuffer,
  1003. hid_reportid_size_map[i], 1)) {
  1004. dbg_hid("hid_input_report error sending null "
  1005. "report\n");
  1006. }
  1007. }
  1008. }
  1009. }
  1010. static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev,
  1011. struct dj_report *dj_report)
  1012. {
  1013. /* We are called from atomic context (tasklet && djrcv->lock held) */
  1014. struct dj_device *dj_device;
  1015. dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index];
  1016. if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) ||
  1017. (hid_reportid_size_map[dj_report->report_type] == 0)) {
  1018. dbg_hid("invalid report type:%x\n", dj_report->report_type);
  1019. return;
  1020. }
  1021. if (hid_input_report(dj_device->hdev,
  1022. HID_INPUT_REPORT, &dj_report->report_type,
  1023. hid_reportid_size_map[dj_report->report_type], 1)) {
  1024. dbg_hid("hid_input_report error\n");
  1025. }
  1026. }
  1027. static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data,
  1028. int size)
  1029. {
  1030. /* We are called from atomic context (tasklet && djrcv->lock held) */
  1031. if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))
  1032. dbg_hid("hid_input_report error\n");
  1033. }
  1034. static void logi_dj_recv_forward_input_report(struct hid_device *hdev,
  1035. u8 *data, int size)
  1036. {
  1037. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1038. struct dj_device *dj_dev;
  1039. unsigned long flags;
  1040. u8 report = data[0];
  1041. int i;
  1042. if (report > REPORT_TYPE_RFREPORT_LAST) {
  1043. hid_err(hdev, "Unexpected input report number %d\n", report);
  1044. return;
  1045. }
  1046. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1047. for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
  1048. dj_dev = djrcv_dev->paired_dj_devices[i];
  1049. if (dj_dev && (dj_dev->reports_supported & BIT(report))) {
  1050. logi_dj_recv_forward_report(dj_dev, data, size);
  1051. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1052. return;
  1053. }
  1054. }
  1055. logi_dj_recv_queue_unknown_work(djrcv_dev);
  1056. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1057. dbg_hid("No dj-devs handling input report number %d\n", report);
  1058. }
  1059. static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
  1060. struct dj_report *dj_report)
  1061. {
  1062. struct hid_device *hdev = djrcv_dev->hidpp;
  1063. struct hid_report *report;
  1064. struct hid_report_enum *output_report_enum;
  1065. u8 *data = (u8 *)(&dj_report->device_index);
  1066. unsigned int i;
  1067. output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
  1068. report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
  1069. if (!report) {
  1070. hid_err(hdev, "%s: unable to find dj report\n", __func__);
  1071. return -ENODEV;
  1072. }
  1073. for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++)
  1074. report->field[0]->value[i] = data[i];
  1075. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  1076. return 0;
  1077. }
  1078. static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev)
  1079. {
  1080. static const u8 template[] = {
  1081. REPORT_ID_HIDPP_SHORT,
  1082. HIDPP_RECEIVER_INDEX,
  1083. HIDPP_SET_REGISTER,
  1084. HIDPP_REG_CONNECTION_STATE,
  1085. HIDPP_FAKE_DEVICE_ARRIVAL,
  1086. 0x00, 0x00
  1087. };
  1088. u8 *hidpp_report;
  1089. int retval;
  1090. hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL);
  1091. if (!hidpp_report)
  1092. return -ENOMEM;
  1093. retval = hid_hw_raw_request(djrcv_dev->hidpp,
  1094. REPORT_ID_HIDPP_SHORT,
  1095. hidpp_report, sizeof(template),
  1096. HID_OUTPUT_REPORT,
  1097. HID_REQ_SET_REPORT);
  1098. kfree(hidpp_report);
  1099. return (retval < 0) ? retval : 0;
  1100. }
  1101. static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
  1102. {
  1103. struct dj_report *dj_report;
  1104. int retval;
  1105. djrcv_dev->last_query = jiffies;
  1106. if (djrcv_dev->type != recvr_type_dj)
  1107. return logi_dj_recv_query_hidpp_devices(djrcv_dev);
  1108. dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
  1109. if (!dj_report)
  1110. return -ENOMEM;
  1111. dj_report->report_id = REPORT_ID_DJ_SHORT;
  1112. dj_report->device_index = HIDPP_RECEIVER_INDEX;
  1113. dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES;
  1114. retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
  1115. kfree(dj_report);
  1116. return retval;
  1117. }
  1118. static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
  1119. unsigned timeout)
  1120. {
  1121. struct hid_device *hdev = djrcv_dev->hidpp;
  1122. struct dj_report *dj_report;
  1123. u8 *buf;
  1124. int retval = 0;
  1125. dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
  1126. if (!dj_report)
  1127. return -ENOMEM;
  1128. if (djrcv_dev->type == recvr_type_dj) {
  1129. dj_report->report_id = REPORT_ID_DJ_SHORT;
  1130. dj_report->device_index = HIDPP_RECEIVER_INDEX;
  1131. dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
  1132. dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
  1133. dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] =
  1134. (u8)timeout;
  1135. retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
  1136. /*
  1137. * Ugly sleep to work around a USB 3.0 bug when the receiver is
  1138. * still processing the "switch-to-dj" command while we send an
  1139. * other command.
  1140. * 50 msec should gives enough time to the receiver to be ready.
  1141. */
  1142. msleep(50);
  1143. if (retval) {
  1144. kfree(dj_report);
  1145. return retval;
  1146. }
  1147. }
  1148. /*
  1149. * Magical bits to set up hidpp notifications when the dj devices
  1150. * are connected/disconnected.
  1151. *
  1152. * We can reuse dj_report because HIDPP_REPORT_SHORT_LENGTH is smaller
  1153. * than DJREPORT_SHORT_LENGTH.
  1154. */
  1155. buf = (u8 *)dj_report;
  1156. memset(buf, 0, HIDPP_REPORT_SHORT_LENGTH);
  1157. buf[0] = REPORT_ID_HIDPP_SHORT;
  1158. buf[1] = HIDPP_RECEIVER_INDEX;
  1159. buf[2] = 0x80;
  1160. buf[3] = 0x00;
  1161. buf[4] = 0x00;
  1162. buf[5] = 0x09;
  1163. buf[6] = 0x00;
  1164. retval = hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
  1165. HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT,
  1166. HID_REQ_SET_REPORT);
  1167. kfree(dj_report);
  1168. return retval;
  1169. }
  1170. static int logi_dj_ll_open(struct hid_device *hid)
  1171. {
  1172. dbg_hid("%s: %s\n", __func__, hid->phys);
  1173. return 0;
  1174. }
  1175. static void logi_dj_ll_close(struct hid_device *hid)
  1176. {
  1177. dbg_hid("%s: %s\n", __func__, hid->phys);
  1178. }
  1179. /*
  1180. * Register 0xB5 is "pairing information". It is solely intended for the
  1181. * receiver, so do not overwrite the device index.
  1182. */
  1183. static u8 unifying_pairing_query[] = { REPORT_ID_HIDPP_SHORT,
  1184. HIDPP_RECEIVER_INDEX,
  1185. HIDPP_GET_LONG_REGISTER,
  1186. HIDPP_REG_PAIRING_INFORMATION };
  1187. static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG,
  1188. HIDPP_RECEIVER_INDEX,
  1189. HIDPP_GET_LONG_REGISTER,
  1190. HIDPP_REG_PAIRING_INFORMATION };
  1191. static int logi_dj_ll_raw_request(struct hid_device *hid,
  1192. unsigned char reportnum, __u8 *buf,
  1193. size_t count, unsigned char report_type,
  1194. int reqtype)
  1195. {
  1196. struct dj_device *djdev = hid->driver_data;
  1197. struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
  1198. u8 *out_buf;
  1199. int ret;
  1200. if ((buf[0] == REPORT_ID_HIDPP_SHORT) ||
  1201. (buf[0] == REPORT_ID_HIDPP_LONG) ||
  1202. (buf[0] == REPORT_ID_HIDPP_VERY_LONG)) {
  1203. if (count < 2)
  1204. return -EINVAL;
  1205. /* special case where we should not overwrite
  1206. * the device_index */
  1207. if (count == 7 && !memcmp(buf, unifying_pairing_query,
  1208. sizeof(unifying_pairing_query)))
  1209. buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1);
  1210. else
  1211. buf[1] = djdev->device_index;
  1212. return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf,
  1213. count, report_type, reqtype);
  1214. }
  1215. if (buf[0] != REPORT_TYPE_LEDS)
  1216. return -EINVAL;
  1217. if (djrcv_dev->type != recvr_type_dj && count >= 2) {
  1218. if (!djrcv_dev->keyboard) {
  1219. hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n");
  1220. return 0;
  1221. }
  1222. /* usbhid overrides the report ID and ignores the first byte */
  1223. return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count,
  1224. report_type, reqtype);
  1225. }
  1226. out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC);
  1227. if (!out_buf)
  1228. return -ENOMEM;
  1229. if (count > DJREPORT_SHORT_LENGTH - 2)
  1230. count = DJREPORT_SHORT_LENGTH - 2;
  1231. out_buf[0] = REPORT_ID_DJ_SHORT;
  1232. out_buf[1] = djdev->device_index;
  1233. memcpy(out_buf + 2, buf, count);
  1234. ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf,
  1235. DJREPORT_SHORT_LENGTH, report_type, reqtype);
  1236. kfree(out_buf);
  1237. return ret;
  1238. }
  1239. static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size)
  1240. {
  1241. memcpy(rdesc + *rsize, data, size);
  1242. *rsize += size;
  1243. }
  1244. static int logi_dj_ll_parse(struct hid_device *hid)
  1245. {
  1246. struct dj_device *djdev = hid->driver_data;
  1247. unsigned int rsize = 0;
  1248. char *rdesc;
  1249. int retval;
  1250. dbg_hid("%s\n", __func__);
  1251. djdev->hdev->version = 0x0111;
  1252. djdev->hdev->country = 0x00;
  1253. rdesc = kmalloc(MAX_RDESC_SIZE, GFP_KERNEL);
  1254. if (!rdesc)
  1255. return -ENOMEM;
  1256. if (djdev->reports_supported & STD_KEYBOARD) {
  1257. dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n",
  1258. __func__, djdev->reports_supported);
  1259. rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
  1260. }
  1261. if (djdev->reports_supported & STD_MOUSE) {
  1262. dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n",
  1263. __func__, djdev->reports_supported);
  1264. if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp ||
  1265. djdev->dj_receiver_dev->type == recvr_type_mouse_only)
  1266. rdcat(rdesc, &rsize, mse_high_res_descriptor,
  1267. sizeof(mse_high_res_descriptor));
  1268. else if (djdev->dj_receiver_dev->type == recvr_type_27mhz)
  1269. rdcat(rdesc, &rsize, mse_27mhz_descriptor,
  1270. sizeof(mse_27mhz_descriptor));
  1271. else if (recvr_type_is_bluetooth(djdev->dj_receiver_dev->type))
  1272. rdcat(rdesc, &rsize, mse_bluetooth_descriptor,
  1273. sizeof(mse_bluetooth_descriptor));
  1274. else
  1275. rdcat(rdesc, &rsize, mse_descriptor,
  1276. sizeof(mse_descriptor));
  1277. }
  1278. if (djdev->reports_supported & KBD_MOUSE) {
  1279. dbg_hid("%s: sending a kbd-mouse descriptor, reports_supported: %llx\n",
  1280. __func__, djdev->reports_supported);
  1281. rdcat(rdesc, &rsize, mse5_bluetooth_descriptor,
  1282. sizeof(mse5_bluetooth_descriptor));
  1283. }
  1284. if (djdev->reports_supported & MULTIMEDIA) {
  1285. dbg_hid("%s: sending a multimedia report descriptor: %llx\n",
  1286. __func__, djdev->reports_supported);
  1287. rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
  1288. }
  1289. if (djdev->reports_supported & POWER_KEYS) {
  1290. dbg_hid("%s: sending a power keys report descriptor: %llx\n",
  1291. __func__, djdev->reports_supported);
  1292. rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
  1293. }
  1294. if (djdev->reports_supported & MEDIA_CENTER) {
  1295. dbg_hid("%s: sending a media center report descriptor: %llx\n",
  1296. __func__, djdev->reports_supported);
  1297. rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
  1298. }
  1299. if (djdev->reports_supported & KBD_LEDS) {
  1300. dbg_hid("%s: need to send kbd leds report descriptor: %llx\n",
  1301. __func__, djdev->reports_supported);
  1302. }
  1303. if (djdev->reports_supported & HIDPP) {
  1304. dbg_hid("%s: sending a HID++ descriptor, reports_supported: %llx\n",
  1305. __func__, djdev->reports_supported);
  1306. rdcat(rdesc, &rsize, hidpp_descriptor,
  1307. sizeof(hidpp_descriptor));
  1308. }
  1309. retval = hid_parse_report(hid, rdesc, rsize);
  1310. kfree(rdesc);
  1311. return retval;
  1312. }
  1313. static int logi_dj_ll_start(struct hid_device *hid)
  1314. {
  1315. dbg_hid("%s\n", __func__);
  1316. return 0;
  1317. }
  1318. static void logi_dj_ll_stop(struct hid_device *hid)
  1319. {
  1320. dbg_hid("%s\n", __func__);
  1321. }
  1322. static bool logi_dj_ll_may_wakeup(struct hid_device *hid)
  1323. {
  1324. struct dj_device *djdev = hid->driver_data;
  1325. struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
  1326. return hid_hw_may_wakeup(djrcv_dev->hidpp);
  1327. }
  1328. static const struct hid_ll_driver logi_dj_ll_driver = {
  1329. .parse = logi_dj_ll_parse,
  1330. .start = logi_dj_ll_start,
  1331. .stop = logi_dj_ll_stop,
  1332. .open = logi_dj_ll_open,
  1333. .close = logi_dj_ll_close,
  1334. .raw_request = logi_dj_ll_raw_request,
  1335. .may_wakeup = logi_dj_ll_may_wakeup,
  1336. };
  1337. static int logi_dj_dj_event(struct hid_device *hdev,
  1338. struct hid_report *report, u8 *data,
  1339. int size)
  1340. {
  1341. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1342. struct dj_report *dj_report = (struct dj_report *) data;
  1343. unsigned long flags;
  1344. /*
  1345. * Here we receive all data coming from iface 2, there are 3 cases:
  1346. *
  1347. * 1) Data is intended for this driver i. e. data contains arrival,
  1348. * departure, etc notifications, in which case we queue them for delayed
  1349. * processing by the work queue. We return 1 to hid-core as no further
  1350. * processing is required from it.
  1351. *
  1352. * 2) Data informs a connection change, if the change means rf link
  1353. * loss, then we must send a null report to the upper layer to discard
  1354. * potentially pressed keys that may be repeated forever by the input
  1355. * layer. Return 1 to hid-core as no further processing is required.
  1356. *
  1357. * 3) Data is an actual input event from a paired DJ device in which
  1358. * case we forward it to the correct hid device (via hid_input_report()
  1359. * ) and return 1 so hid-core does not anything else with it.
  1360. */
  1361. if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
  1362. (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
  1363. /*
  1364. * Device index is wrong, bail out.
  1365. * This driver can ignore safely the receiver notifications,
  1366. * so ignore those reports too.
  1367. */
  1368. if (dj_report->device_index != DJ_RECEIVER_INDEX)
  1369. hid_err(hdev, "%s: invalid device index:%d\n",
  1370. __func__, dj_report->device_index);
  1371. return false;
  1372. }
  1373. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1374. if (!djrcv_dev->paired_dj_devices[dj_report->device_index]) {
  1375. /* received an event for an unknown device, bail out */
  1376. logi_dj_recv_queue_notification(djrcv_dev, dj_report);
  1377. goto out;
  1378. }
  1379. switch (dj_report->report_type) {
  1380. case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
  1381. /* pairing notifications are handled above the switch */
  1382. break;
  1383. case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
  1384. logi_dj_recv_queue_notification(djrcv_dev, dj_report);
  1385. break;
  1386. case REPORT_TYPE_NOTIF_CONNECTION_STATUS:
  1387. if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] ==
  1388. STATUS_LINKLOSS) {
  1389. logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
  1390. }
  1391. break;
  1392. default:
  1393. logi_dj_recv_forward_dj(djrcv_dev, dj_report);
  1394. }
  1395. out:
  1396. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1397. return true;
  1398. }
  1399. static int logi_dj_hidpp_event(struct hid_device *hdev,
  1400. struct hid_report *report, u8 *data,
  1401. int size)
  1402. {
  1403. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1404. struct hidpp_event *hidpp_report = (struct hidpp_event *) data;
  1405. struct dj_device *dj_dev;
  1406. unsigned long flags;
  1407. u8 device_index = hidpp_report->device_index;
  1408. if (device_index == HIDPP_RECEIVER_INDEX) {
  1409. /* special case were the device wants to know its unifying
  1410. * name */
  1411. if (size == HIDPP_REPORT_LONG_LENGTH &&
  1412. !memcmp(data, unifying_pairing_answer,
  1413. sizeof(unifying_pairing_answer)))
  1414. device_index = (data[4] & 0x0F) + 1;
  1415. else
  1416. return false;
  1417. }
  1418. /*
  1419. * Data is from the HID++ collection, in this case, we forward the
  1420. * data to the corresponding child dj device and return 0 to hid-core
  1421. * so he data also goes to the hidraw device of the receiver. This
  1422. * allows a user space application to implement the full HID++ routing
  1423. * via the receiver.
  1424. */
  1425. if ((device_index < DJ_DEVICE_INDEX_MIN) ||
  1426. (device_index > DJ_DEVICE_INDEX_MAX)) {
  1427. /*
  1428. * Device index is wrong, bail out.
  1429. * This driver can ignore safely the receiver notifications,
  1430. * so ignore those reports too.
  1431. */
  1432. hid_err(hdev, "%s: invalid device index:%d\n", __func__,
  1433. hidpp_report->device_index);
  1434. return false;
  1435. }
  1436. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1437. dj_dev = djrcv_dev->paired_dj_devices[device_index];
  1438. /*
  1439. * With 27 MHz receivers, we do not get an explicit unpair event,
  1440. * remove the old device if the user has paired a *different* device.
  1441. */
  1442. if (djrcv_dev->type == recvr_type_27mhz && dj_dev &&
  1443. hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED &&
  1444. hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 &&
  1445. hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] !=
  1446. dj_dev->hdev->product) {
  1447. struct dj_workitem workitem = {
  1448. .device_index = hidpp_report->device_index,
  1449. .type = WORKITEM_TYPE_UNPAIRED,
  1450. };
  1451. kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  1452. /* logi_hidpp_recv_queue_notif will queue the work */
  1453. dj_dev = NULL;
  1454. }
  1455. if (dj_dev) {
  1456. logi_dj_recv_forward_report(dj_dev, data, size);
  1457. } else {
  1458. if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED)
  1459. logi_hidpp_recv_queue_notif(hdev, hidpp_report);
  1460. else
  1461. logi_dj_recv_queue_unknown_work(djrcv_dev);
  1462. }
  1463. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1464. return false;
  1465. }
  1466. static int logi_dj_raw_event(struct hid_device *hdev,
  1467. struct hid_report *report, u8 *data,
  1468. int size)
  1469. {
  1470. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1471. dbg_hid("%s, size:%d\n", __func__, size);
  1472. if (!djrcv_dev)
  1473. return 0;
  1474. if (!hdev->report_enum[HID_INPUT_REPORT].numbered) {
  1475. if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) {
  1476. /*
  1477. * For the keyboard, we can reuse the same report by
  1478. * using the second byte which is constant in the USB
  1479. * HID report descriptor.
  1480. */
  1481. data[1] = data[0];
  1482. data[0] = REPORT_TYPE_KEYBOARD;
  1483. logi_dj_recv_forward_input_report(hdev, data, size);
  1484. /* restore previous state */
  1485. data[0] = data[1];
  1486. data[1] = 0;
  1487. }
  1488. /*
  1489. * Mouse-only receivers send unnumbered mouse data. The 27 MHz
  1490. * receiver uses 6 byte packets, the nano receiver 8 bytes.
  1491. */
  1492. if (djrcv_dev->unnumbered_application == HID_GD_MOUSE &&
  1493. size <= 8) {
  1494. u8 mouse_report[9];
  1495. /* Prepend report id */
  1496. mouse_report[0] = REPORT_TYPE_MOUSE;
  1497. memcpy(mouse_report + 1, data, size);
  1498. logi_dj_recv_forward_input_report(hdev, mouse_report,
  1499. size + 1);
  1500. }
  1501. return false;
  1502. }
  1503. switch (data[0]) {
  1504. case REPORT_ID_DJ_SHORT:
  1505. if (size != DJREPORT_SHORT_LENGTH) {
  1506. hid_err(hdev, "Short DJ report bad size (%d)", size);
  1507. return false;
  1508. }
  1509. return logi_dj_dj_event(hdev, report, data, size);
  1510. case REPORT_ID_DJ_LONG:
  1511. if (size != DJREPORT_LONG_LENGTH) {
  1512. hid_err(hdev, "Long DJ report bad size (%d)", size);
  1513. return false;
  1514. }
  1515. return logi_dj_dj_event(hdev, report, data, size);
  1516. case REPORT_ID_HIDPP_SHORT:
  1517. if (size != HIDPP_REPORT_SHORT_LENGTH) {
  1518. hid_err(hdev, "Short HID++ report bad size (%d)", size);
  1519. return false;
  1520. }
  1521. return logi_dj_hidpp_event(hdev, report, data, size);
  1522. case REPORT_ID_HIDPP_LONG:
  1523. if (size != HIDPP_REPORT_LONG_LENGTH) {
  1524. hid_err(hdev, "Long HID++ report bad size (%d)", size);
  1525. return false;
  1526. }
  1527. return logi_dj_hidpp_event(hdev, report, data, size);
  1528. }
  1529. logi_dj_recv_forward_input_report(hdev, data, size);
  1530. return false;
  1531. }
  1532. static int logi_dj_probe(struct hid_device *hdev,
  1533. const struct hid_device_id *id)
  1534. {
  1535. struct hid_report_enum *rep_enum;
  1536. struct hid_report *rep;
  1537. struct dj_receiver_dev *djrcv_dev;
  1538. struct usb_interface *intf;
  1539. unsigned int no_dj_interfaces = 0;
  1540. bool has_hidpp = false;
  1541. unsigned long flags;
  1542. int retval;
  1543. /*
  1544. * Call to usbhid to fetch the HID descriptors of the current
  1545. * interface subsequently call to the hid/hid-core to parse the
  1546. * fetched descriptors.
  1547. */
  1548. retval = hid_parse(hdev);
  1549. if (retval) {
  1550. hid_err(hdev, "%s: parse failed\n", __func__);
  1551. return retval;
  1552. }
  1553. /*
  1554. * Some KVMs add an extra interface for e.g. mouse emulation. If we
  1555. * treat these as logitech-dj interfaces then this causes input events
  1556. * reported through this extra interface to not be reported correctly.
  1557. * To avoid this, we treat these as generic-hid devices.
  1558. */
  1559. switch (id->driver_data) {
  1560. case recvr_type_dj: no_dj_interfaces = 3; break;
  1561. case recvr_type_hidpp: no_dj_interfaces = 2; break;
  1562. case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break;
  1563. case recvr_type_mouse_only: no_dj_interfaces = 2; break;
  1564. case recvr_type_27mhz: no_dj_interfaces = 2; break;
  1565. case recvr_type_bluetooth: no_dj_interfaces = 2; break;
  1566. case recvr_type_dinovo: no_dj_interfaces = 2; break;
  1567. }
  1568. if (hid_is_usb(hdev)) {
  1569. intf = to_usb_interface(hdev->dev.parent);
  1570. if (intf && intf->altsetting->desc.bInterfaceNumber >=
  1571. no_dj_interfaces) {
  1572. hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
  1573. return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1574. }
  1575. }
  1576. rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
  1577. /* no input reports, bail out */
  1578. if (list_empty(&rep_enum->report_list))
  1579. return -ENODEV;
  1580. /*
  1581. * Check for the HID++ application.
  1582. * Note: we should theoretically check for HID++ and DJ
  1583. * collections, but this will do.
  1584. */
  1585. list_for_each_entry(rep, &rep_enum->report_list, list) {
  1586. if (rep->application == 0xff000001)
  1587. has_hidpp = true;
  1588. }
  1589. /*
  1590. * Ignore interfaces without DJ/HID++ collection, they will not carry
  1591. * any data, dont create any hid_device for them.
  1592. */
  1593. if (!has_hidpp && id->driver_data == recvr_type_dj)
  1594. return -ENODEV;
  1595. /* get the current application attached to the node */
  1596. rep = list_first_entry(&rep_enum->report_list, struct hid_report, list);
  1597. djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data,
  1598. rep->application, has_hidpp);
  1599. if (!djrcv_dev) {
  1600. hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__);
  1601. return -ENOMEM;
  1602. }
  1603. if (!rep_enum->numbered)
  1604. djrcv_dev->unnumbered_application = rep->application;
  1605. /* Starts the usb device and connects to upper interfaces hiddev and
  1606. * hidraw */
  1607. retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV);
  1608. if (retval) {
  1609. hid_err(hdev, "%s: hid_hw_start returned error\n", __func__);
  1610. goto hid_hw_start_fail;
  1611. }
  1612. if (has_hidpp) {
  1613. retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
  1614. if (retval < 0) {
  1615. hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
  1616. __func__, retval);
  1617. goto switch_to_dj_mode_fail;
  1618. }
  1619. }
  1620. /* This is enabling the polling urb on the IN endpoint */
  1621. retval = hid_hw_open(hdev);
  1622. if (retval < 0) {
  1623. hid_err(hdev, "%s: hid_hw_open returned error:%d\n",
  1624. __func__, retval);
  1625. goto llopen_failed;
  1626. }
  1627. /* Allow incoming packets to arrive: */
  1628. hid_device_io_start(hdev);
  1629. if (has_hidpp) {
  1630. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1631. djrcv_dev->ready = true;
  1632. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1633. retval = logi_dj_recv_query_paired_devices(djrcv_dev);
  1634. if (retval < 0) {
  1635. hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n",
  1636. __func__, retval);
  1637. /*
  1638. * This can happen with a KVM, let the probe succeed,
  1639. * logi_dj_recv_queue_unknown_work will retry later.
  1640. */
  1641. }
  1642. }
  1643. return 0;
  1644. llopen_failed:
  1645. switch_to_dj_mode_fail:
  1646. hid_hw_stop(hdev);
  1647. hid_hw_start_fail:
  1648. dj_put_receiver_dev(hdev);
  1649. return retval;
  1650. }
  1651. #ifdef CONFIG_PM
  1652. static int logi_dj_reset_resume(struct hid_device *hdev)
  1653. {
  1654. int retval;
  1655. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1656. if (!djrcv_dev || djrcv_dev->hidpp != hdev)
  1657. return 0;
  1658. retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
  1659. if (retval < 0) {
  1660. hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
  1661. __func__, retval);
  1662. }
  1663. return 0;
  1664. }
  1665. #endif
  1666. static void logi_dj_remove(struct hid_device *hdev)
  1667. {
  1668. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1669. struct dj_device *dj_dev;
  1670. unsigned long flags;
  1671. int i;
  1672. dbg_hid("%s\n", __func__);
  1673. if (!djrcv_dev)
  1674. return hid_hw_stop(hdev);
  1675. /*
  1676. * This ensures that if the work gets requeued from another
  1677. * interface of the same receiver it will be a no-op.
  1678. */
  1679. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1680. djrcv_dev->ready = false;
  1681. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1682. cancel_work_sync(&djrcv_dev->work);
  1683. hid_hw_close(hdev);
  1684. hid_hw_stop(hdev);
  1685. /*
  1686. * For proper operation we need access to all interfaces, so we destroy
  1687. * the paired devices when we're unbound from any interface.
  1688. *
  1689. * Note we may still be bound to other interfaces, sharing the same
  1690. * djrcv_dev, so we need locking here.
  1691. */
  1692. for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
  1693. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1694. dj_dev = djrcv_dev->paired_dj_devices[i];
  1695. djrcv_dev->paired_dj_devices[i] = NULL;
  1696. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1697. if (dj_dev != NULL) {
  1698. hid_destroy_device(dj_dev->hdev);
  1699. kfree(dj_dev);
  1700. }
  1701. }
  1702. dj_put_receiver_dev(hdev);
  1703. }
  1704. static const struct hid_device_id logi_dj_receivers[] = {
  1705. { /* Logitech unifying receiver (0xc52b) */
  1706. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1707. USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER),
  1708. .driver_data = recvr_type_dj},
  1709. { /* Logitech unifying receiver (0xc532) */
  1710. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1711. USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2),
  1712. .driver_data = recvr_type_dj},
  1713. { /* Logitech Nano mouse only receiver (0xc52f) */
  1714. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1715. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER),
  1716. .driver_data = recvr_type_mouse_only},
  1717. { /* Logitech Nano (non DJ) receiver (0xc534) */
  1718. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1719. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2),
  1720. .driver_data = recvr_type_hidpp},
  1721. { /* Logitech G700(s) receiver (0xc531) */
  1722. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1723. USB_DEVICE_ID_LOGITECH_G700_RECEIVER),
  1724. .driver_data = recvr_type_gaming_hidpp},
  1725. { /* Logitech G602 receiver (0xc537) */
  1726. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1727. 0xc537),
  1728. .driver_data = recvr_type_gaming_hidpp},
  1729. { /* Logitech lightspeed receiver (0xc539) */
  1730. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1731. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1),
  1732. .driver_data = recvr_type_gaming_hidpp},
  1733. { /* Logitech powerplay receiver (0xc53a) */
  1734. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1735. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY),
  1736. .driver_data = recvr_type_gaming_hidpp},
  1737. { /* Logitech lightspeed receiver (0xc53f) */
  1738. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1739. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1),
  1740. .driver_data = recvr_type_gaming_hidpp},
  1741. { /* Logitech lightspeed receiver (0xc543) */
  1742. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1743. USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_2),
  1744. .driver_data = recvr_type_gaming_hidpp},
  1745. { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */
  1746. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
  1747. .driver_data = recvr_type_27mhz},
  1748. { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */
  1749. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1750. USB_DEVICE_ID_S510_RECEIVER_2),
  1751. .driver_data = recvr_type_27mhz},
  1752. { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */
  1753. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1754. USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER),
  1755. .driver_data = recvr_type_27mhz},
  1756. { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. (0xc70e) */
  1757. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1758. USB_DEVICE_ID_MX5000_RECEIVER_KBD_DEV),
  1759. .driver_data = recvr_type_bluetooth},
  1760. { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. (0xc70a) */
  1761. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1762. USB_DEVICE_ID_MX5000_RECEIVER_MOUSE_DEV),
  1763. .driver_data = recvr_type_bluetooth},
  1764. { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. (0xc71b) */
  1765. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1766. USB_DEVICE_ID_MX5500_RECEIVER_KBD_DEV),
  1767. .driver_data = recvr_type_bluetooth},
  1768. { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. (0xc71c) */
  1769. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1770. USB_DEVICE_ID_MX5500_RECEIVER_MOUSE_DEV),
  1771. .driver_data = recvr_type_bluetooth},
  1772. { /* Logitech Dinovo Edge HID++ / bluetooth receiver keyboard intf. (0xc713) */
  1773. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1774. USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_KBD_DEV),
  1775. .driver_data = recvr_type_dinovo},
  1776. { /* Logitech Dinovo Edge HID++ / bluetooth receiver mouse intf. (0xc714) */
  1777. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1778. USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_MOUSE_DEV),
  1779. .driver_data = recvr_type_dinovo},
  1780. { /* Logitech DiNovo Mini HID++ / bluetooth receiver mouse intf. (0xc71e) */
  1781. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1782. USB_DEVICE_ID_DINOVO_MINI_RECEIVER_KBD_DEV),
  1783. .driver_data = recvr_type_dinovo},
  1784. { /* Logitech DiNovo Mini HID++ / bluetooth receiver keyboard intf. (0xc71f) */
  1785. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1786. USB_DEVICE_ID_DINOVO_MINI_RECEIVER_MOUSE_DEV),
  1787. .driver_data = recvr_type_dinovo},
  1788. {}
  1789. };
  1790. MODULE_DEVICE_TABLE(hid, logi_dj_receivers);
  1791. static struct hid_driver logi_djreceiver_driver = {
  1792. .name = "logitech-djreceiver",
  1793. .id_table = logi_dj_receivers,
  1794. .probe = logi_dj_probe,
  1795. .remove = logi_dj_remove,
  1796. .raw_event = logi_dj_raw_event,
  1797. #ifdef CONFIG_PM
  1798. .reset_resume = logi_dj_reset_resume,
  1799. #endif
  1800. };
  1801. module_hid_driver(logi_djreceiver_driver);
  1802. MODULE_DESCRIPTION("HID driver for Logitech receivers");
  1803. MODULE_LICENSE("GPL");
  1804. MODULE_AUTHOR("Logitech");
  1805. MODULE_AUTHOR("Nestor Lopez Casado");
  1806. MODULE_AUTHOR("nlopezcasad@logitech.com");