hid-logitech-dj.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053
  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 <asm/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 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;
  867. if (djrcv_dev->type == recvr_type_mouse_only)
  868. workitem->reports_supported |= MULTIMEDIA;
  869. break;
  870. }
  871. }
  872. static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev,
  873. struct hidpp_event *hidpp_report,
  874. struct dj_workitem *workitem)
  875. {
  876. workitem->type = WORKITEM_TYPE_PAIRED;
  877. workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID];
  878. switch (hidpp_report->device_index) {
  879. case 1: /* Index 1 is always a mouse */
  880. case 2: /* Index 2 is always a mouse */
  881. workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE;
  882. workitem->reports_supported |= STD_MOUSE | HIDPP;
  883. break;
  884. case 3: /* Index 3 is always the keyboard */
  885. if (hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & HIDPP_27MHZ_SECURE_MASK) {
  886. hid_info(hdev, "Keyboard connection is encrypted\n");
  887. } else {
  888. hid_warn(hdev, "Keyboard events are send over the air in plain-text / unencrypted\n");
  889. hid_warn(hdev, "See: https://gitlab.freedesktop.org/jwrdegoede/logitech-27mhz-keyboard-encryption-setup/\n");
  890. }
  891. fallthrough;
  892. case 4: /* Index 4 is used for an optional separate numpad */
  893. workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD;
  894. workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
  895. POWER_KEYS | HIDPP;
  896. break;
  897. default:
  898. hid_warn(hdev, "%s: unexpected device-index %d", __func__,
  899. hidpp_report->device_index);
  900. }
  901. }
  902. static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
  903. struct hidpp_event *hidpp_report)
  904. {
  905. /* We are called from atomic context (tasklet && djrcv->lock held) */
  906. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  907. const char *device_type = "UNKNOWN";
  908. struct dj_workitem workitem = {
  909. .type = WORKITEM_TYPE_EMPTY,
  910. .device_index = hidpp_report->device_index,
  911. };
  912. switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) {
  913. case 0x01:
  914. device_type = "Bluetooth";
  915. /* Bluetooth connect packet contents is the same as (e)QUAD */
  916. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  917. if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
  918. HIDPP_MANUFACTURER_MASK)) {
  919. hid_info(hdev, "Non Logitech device connected on slot %d\n",
  920. hidpp_report->device_index);
  921. workitem.reports_supported &= ~HIDPP;
  922. }
  923. break;
  924. case 0x02:
  925. device_type = "27 Mhz";
  926. logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem);
  927. break;
  928. case 0x03:
  929. device_type = "QUAD or eQUAD";
  930. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  931. break;
  932. case 0x04:
  933. device_type = "eQUAD step 4 DJ";
  934. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  935. break;
  936. case 0x05:
  937. device_type = "DFU Lite";
  938. break;
  939. case 0x06:
  940. device_type = "eQUAD step 4 Lite";
  941. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  942. break;
  943. case 0x07:
  944. device_type = "eQUAD step 4 Gaming";
  945. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  946. workitem.reports_supported |= STD_KEYBOARD;
  947. break;
  948. case 0x08:
  949. device_type = "eQUAD step 4 for gamepads";
  950. break;
  951. case 0x0a:
  952. device_type = "eQUAD nano Lite";
  953. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  954. break;
  955. case 0x0c:
  956. device_type = "eQUAD Lightspeed 1";
  957. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  958. workitem.reports_supported |= STD_KEYBOARD;
  959. break;
  960. case 0x0d:
  961. device_type = "eQUAD Lightspeed 1.1";
  962. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  963. workitem.reports_supported |= STD_KEYBOARD;
  964. break;
  965. case 0x0f:
  966. case 0x11:
  967. device_type = "eQUAD Lightspeed 1.2";
  968. logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
  969. workitem.reports_supported |= STD_KEYBOARD;
  970. break;
  971. }
  972. /* custom receiver device (eg. powerplay) */
  973. if (hidpp_report->device_index == 7) {
  974. workitem.reports_supported |= HIDPP;
  975. }
  976. if (workitem.type == WORKITEM_TYPE_EMPTY) {
  977. hid_warn(hdev,
  978. "unusable device of type %s (0x%02x) connected on slot %d",
  979. device_type,
  980. hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
  981. hidpp_report->device_index);
  982. return;
  983. }
  984. hid_info(hdev, "device of type %s (0x%02x) connected on slot %d",
  985. device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
  986. hidpp_report->device_index);
  987. kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
  988. schedule_work(&djrcv_dev->work);
  989. }
  990. static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
  991. struct dj_report *dj_report)
  992. {
  993. /* We are called from atomic context (tasklet && djrcv->lock held) */
  994. unsigned int i;
  995. u8 reportbuffer[MAX_REPORT_SIZE];
  996. struct dj_device *djdev;
  997. djdev = djrcv_dev->paired_dj_devices[dj_report->device_index];
  998. memset(reportbuffer, 0, sizeof(reportbuffer));
  999. for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) {
  1000. if (djdev->reports_supported & (1 << i)) {
  1001. reportbuffer[0] = i;
  1002. if (hid_input_report(djdev->hdev,
  1003. HID_INPUT_REPORT,
  1004. reportbuffer,
  1005. hid_reportid_size_map[i], 1)) {
  1006. dbg_hid("hid_input_report error sending null "
  1007. "report\n");
  1008. }
  1009. }
  1010. }
  1011. }
  1012. static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev,
  1013. struct dj_report *dj_report)
  1014. {
  1015. /* We are called from atomic context (tasklet && djrcv->lock held) */
  1016. struct dj_device *dj_device;
  1017. dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index];
  1018. if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) ||
  1019. (hid_reportid_size_map[dj_report->report_type] == 0)) {
  1020. dbg_hid("invalid report type:%x\n", dj_report->report_type);
  1021. return;
  1022. }
  1023. if (hid_input_report(dj_device->hdev,
  1024. HID_INPUT_REPORT, &dj_report->report_type,
  1025. hid_reportid_size_map[dj_report->report_type], 1)) {
  1026. dbg_hid("hid_input_report error\n");
  1027. }
  1028. }
  1029. static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data,
  1030. int size)
  1031. {
  1032. /* We are called from atomic context (tasklet && djrcv->lock held) */
  1033. if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))
  1034. dbg_hid("hid_input_report error\n");
  1035. }
  1036. static void logi_dj_recv_forward_input_report(struct hid_device *hdev,
  1037. u8 *data, int size)
  1038. {
  1039. struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
  1040. struct dj_device *dj_dev;
  1041. unsigned long flags;
  1042. u8 report = data[0];
  1043. int i;
  1044. if (report > REPORT_TYPE_RFREPORT_LAST) {
  1045. hid_err(hdev, "Unexpected input report number %d\n", report);
  1046. return;
  1047. }
  1048. spin_lock_irqsave(&djrcv_dev->lock, flags);
  1049. for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
  1050. dj_dev = djrcv_dev->paired_dj_devices[i];
  1051. if (dj_dev && (dj_dev->reports_supported & BIT(report))) {
  1052. logi_dj_recv_forward_report(dj_dev, data, size);
  1053. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1054. return;
  1055. }
  1056. }
  1057. logi_dj_recv_queue_unknown_work(djrcv_dev);
  1058. spin_unlock_irqrestore(&djrcv_dev->lock, flags);
  1059. dbg_hid("No dj-devs handling input report number %d\n", report);
  1060. }
  1061. static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
  1062. struct dj_report *dj_report)
  1063. {
  1064. struct hid_device *hdev = djrcv_dev->hidpp;
  1065. struct hid_report *report;
  1066. struct hid_report_enum *output_report_enum;
  1067. u8 *data = (u8 *)(&dj_report->device_index);
  1068. unsigned int i;
  1069. output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
  1070. report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
  1071. if (!report) {
  1072. hid_err(hdev, "%s: unable to find dj report\n", __func__);
  1073. return -ENODEV;
  1074. }
  1075. for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++)
  1076. report->field[0]->value[i] = data[i];
  1077. hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
  1078. return 0;
  1079. }
  1080. static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev)
  1081. {
  1082. static const u8 template[] = {
  1083. REPORT_ID_HIDPP_SHORT,
  1084. HIDPP_RECEIVER_INDEX,
  1085. HIDPP_SET_REGISTER,
  1086. HIDPP_REG_CONNECTION_STATE,
  1087. HIDPP_FAKE_DEVICE_ARRIVAL,
  1088. 0x00, 0x00
  1089. };
  1090. u8 *hidpp_report;
  1091. int retval;
  1092. hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL);
  1093. if (!hidpp_report)
  1094. return -ENOMEM;
  1095. retval = hid_hw_raw_request(djrcv_dev->hidpp,
  1096. REPORT_ID_HIDPP_SHORT,
  1097. hidpp_report, sizeof(template),
  1098. HID_OUTPUT_REPORT,
  1099. HID_REQ_SET_REPORT);
  1100. kfree(hidpp_report);
  1101. return (retval < 0) ? retval : 0;
  1102. }
  1103. static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
  1104. {
  1105. struct dj_report *dj_report;
  1106. int retval;
  1107. djrcv_dev->last_query = jiffies;
  1108. if (djrcv_dev->type != recvr_type_dj)
  1109. return logi_dj_recv_query_hidpp_devices(djrcv_dev);
  1110. dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
  1111. if (!dj_report)
  1112. return -ENOMEM;
  1113. dj_report->report_id = REPORT_ID_DJ_SHORT;
  1114. dj_report->device_index = HIDPP_RECEIVER_INDEX;
  1115. dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES;
  1116. retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
  1117. kfree(dj_report);
  1118. return retval;
  1119. }
  1120. static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
  1121. unsigned timeout)
  1122. {
  1123. struct hid_device *hdev = djrcv_dev->hidpp;
  1124. struct dj_report *dj_report;
  1125. u8 *buf;
  1126. int retval = 0;
  1127. dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
  1128. if (!dj_report)
  1129. return -ENOMEM;
  1130. if (djrcv_dev->type == recvr_type_dj) {
  1131. dj_report->report_id = REPORT_ID_DJ_SHORT;
  1132. dj_report->device_index = HIDPP_RECEIVER_INDEX;
  1133. dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
  1134. dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
  1135. dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] =
  1136. (u8)timeout;
  1137. retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
  1138. /*
  1139. * Ugly sleep to work around a USB 3.0 bug when the receiver is
  1140. * still processing the "switch-to-dj" command while we send an
  1141. * other command.
  1142. * 50 msec should gives enough time to the receiver to be ready.
  1143. */
  1144. msleep(50);
  1145. if (retval)
  1146. return retval;
  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 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 27 MHz HID++ 1.0 receiver (0xc513) */
  1742. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
  1743. .driver_data = recvr_type_27mhz},
  1744. { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */
  1745. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1746. USB_DEVICE_ID_S510_RECEIVER_2),
  1747. .driver_data = recvr_type_27mhz},
  1748. { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */
  1749. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1750. USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER),
  1751. .driver_data = recvr_type_27mhz},
  1752. { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. (0xc70e) */
  1753. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1754. USB_DEVICE_ID_MX5000_RECEIVER_KBD_DEV),
  1755. .driver_data = recvr_type_bluetooth},
  1756. { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. (0xc70a) */
  1757. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1758. USB_DEVICE_ID_MX5000_RECEIVER_MOUSE_DEV),
  1759. .driver_data = recvr_type_bluetooth},
  1760. { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. (0xc71b) */
  1761. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1762. USB_DEVICE_ID_MX5500_RECEIVER_KBD_DEV),
  1763. .driver_data = recvr_type_bluetooth},
  1764. { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. (0xc71c) */
  1765. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1766. USB_DEVICE_ID_MX5500_RECEIVER_MOUSE_DEV),
  1767. .driver_data = recvr_type_bluetooth},
  1768. { /* Logitech Dinovo Edge HID++ / bluetooth receiver keyboard intf. (0xc713) */
  1769. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1770. USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_KBD_DEV),
  1771. .driver_data = recvr_type_dinovo},
  1772. { /* Logitech Dinovo Edge HID++ / bluetooth receiver mouse intf. (0xc714) */
  1773. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1774. USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_MOUSE_DEV),
  1775. .driver_data = recvr_type_dinovo},
  1776. { /* Logitech DiNovo Mini HID++ / bluetooth receiver mouse intf. (0xc71e) */
  1777. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1778. USB_DEVICE_ID_DINOVO_MINI_RECEIVER_KBD_DEV),
  1779. .driver_data = recvr_type_dinovo},
  1780. { /* Logitech DiNovo Mini HID++ / bluetooth receiver keyboard intf. (0xc71f) */
  1781. HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
  1782. USB_DEVICE_ID_DINOVO_MINI_RECEIVER_MOUSE_DEV),
  1783. .driver_data = recvr_type_dinovo},
  1784. {}
  1785. };
  1786. MODULE_DEVICE_TABLE(hid, logi_dj_receivers);
  1787. static struct hid_driver logi_djreceiver_driver = {
  1788. .name = "logitech-djreceiver",
  1789. .id_table = logi_dj_receivers,
  1790. .probe = logi_dj_probe,
  1791. .remove = logi_dj_remove,
  1792. .raw_event = logi_dj_raw_event,
  1793. #ifdef CONFIG_PM
  1794. .reset_resume = logi_dj_reset_resume,
  1795. #endif
  1796. };
  1797. module_hid_driver(logi_djreceiver_driver);
  1798. MODULE_LICENSE("GPL");
  1799. MODULE_AUTHOR("Logitech");
  1800. MODULE_AUTHOR("Nestor Lopez Casado");
  1801. MODULE_AUTHOR("[email protected]");