1 // SPDX-License-Identifier: GPL-2.0-only
3 * HID driver for Logitech receivers
5 * Copyright (c) 2011 Logitech
10 #include <linux/device.h>
11 #include <linux/hid.h>
12 #include <linux/module.h>
13 #include <linux/kfifo.h>
14 #include <linux/delay.h>
15 #include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */
16 #include <asm/unaligned.h>
19 #define DJ_MAX_PAIRED_DEVICES 7
20 #define DJ_MAX_NUMBER_NOTIFS 8
21 #define DJ_RECEIVER_INDEX 0
22 #define DJ_DEVICE_INDEX_MIN 1
23 #define DJ_DEVICE_INDEX_MAX 7
25 #define DJREPORT_SHORT_LENGTH 15
26 #define DJREPORT_LONG_LENGTH 32
28 #define REPORT_ID_DJ_SHORT 0x20
29 #define REPORT_ID_DJ_LONG 0x21
31 #define REPORT_ID_HIDPP_SHORT 0x10
32 #define REPORT_ID_HIDPP_LONG 0x11
33 #define REPORT_ID_HIDPP_VERY_LONG 0x12
35 #define HIDPP_REPORT_SHORT_LENGTH 7
36 #define HIDPP_REPORT_LONG_LENGTH 20
38 #define HIDPP_RECEIVER_INDEX 0xff
40 #define REPORT_TYPE_RFREPORT_FIRST 0x01
41 #define REPORT_TYPE_RFREPORT_LAST 0x1F
43 /* Command Switch to DJ mode */
44 #define REPORT_TYPE_CMD_SWITCH 0x80
45 #define CMD_SWITCH_PARAM_DEVBITFIELD 0x00
46 #define CMD_SWITCH_PARAM_TIMEOUT_SECONDS 0x01
47 #define TIMEOUT_NO_KEEPALIVE 0x00
49 /* Command to Get the list of Paired devices */
50 #define REPORT_TYPE_CMD_GET_PAIRED_DEVICES 0x81
52 /* Device Paired Notification */
53 #define REPORT_TYPE_NOTIF_DEVICE_PAIRED 0x41
54 #define SPFUNCTION_MORE_NOTIF_EXPECTED 0x01
55 #define SPFUNCTION_DEVICE_LIST_EMPTY 0x02
56 #define DEVICE_PAIRED_PARAM_SPFUNCTION 0x00
57 #define DEVICE_PAIRED_PARAM_EQUAD_ID_LSB 0x01
58 #define DEVICE_PAIRED_PARAM_EQUAD_ID_MSB 0x02
59 #define DEVICE_PAIRED_RF_REPORT_TYPE 0x03
61 /* Device Un-Paired Notification */
62 #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40
64 /* Connection Status Notification */
65 #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42
66 #define CONNECTION_STATUS_PARAM_STATUS 0x00
67 #define STATUS_LINKLOSS 0x01
69 /* Error Notification */
70 #define REPORT_TYPE_NOTIF_ERROR 0x7F
71 #define NOTIF_ERROR_PARAM_ETYPE 0x00
72 #define ETYPE_KEEPALIVE_TIMEOUT 0x01
74 /* supported DJ HID && RF report types */
75 #define REPORT_TYPE_KEYBOARD 0x01
76 #define REPORT_TYPE_MOUSE 0x02
77 #define REPORT_TYPE_CONSUMER_CONTROL 0x03
78 #define REPORT_TYPE_SYSTEM_CONTROL 0x04
79 #define REPORT_TYPE_MEDIA_CENTER 0x08
80 #define REPORT_TYPE_LEDS 0x0E
82 /* RF Report types bitfield */
83 #define STD_KEYBOARD BIT(1)
84 #define STD_MOUSE BIT(2)
85 #define MULTIMEDIA BIT(3)
86 #define POWER_KEYS BIT(4)
87 #define KBD_MOUSE BIT(5)
88 #define MEDIA_CENTER BIT(8)
89 #define KBD_LEDS BIT(14)
90 /* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */
91 #define HIDPP BIT_ULL(63)
93 /* HID++ Device Connected Notification */
94 #define REPORT_TYPE_NOTIF_DEVICE_CONNECTED 0x41
95 #define HIDPP_PARAM_PROTO_TYPE 0x00
96 #define HIDPP_PARAM_DEVICE_INFO 0x01
97 #define HIDPP_PARAM_EQUAD_LSB 0x02
98 #define HIDPP_PARAM_EQUAD_MSB 0x03
99 #define HIDPP_PARAM_27MHZ_DEVID 0x03
100 #define HIDPP_DEVICE_TYPE_MASK GENMASK(3, 0)
101 #define HIDPP_LINK_STATUS_MASK BIT(6)
102 #define HIDPP_MANUFACTURER_MASK BIT(7)
104 #define HIDPP_DEVICE_TYPE_KEYBOARD 1
105 #define HIDPP_DEVICE_TYPE_MOUSE 2
107 #define HIDPP_SET_REGISTER 0x80
108 #define HIDPP_GET_LONG_REGISTER 0x83
109 #define HIDPP_REG_CONNECTION_STATE 0x02
110 #define HIDPP_REG_PAIRING_INFORMATION 0xB5
111 #define HIDPP_PAIRING_INFORMATION 0x20
112 #define HIDPP_FAKE_DEVICE_ARRIVAL 0x02
117 recvr_type_gaming_hidpp,
118 recvr_type_mouse_only,
120 recvr_type_bluetooth,
128 u8 report_params[DJREPORT_SHORT_LENGTH - 3];
135 u8 params[HIDPP_REPORT_LONG_LENGTH - 3U];
138 struct dj_receiver_dev {
139 struct hid_device *mouse;
140 struct hid_device *keyboard;
141 struct hid_device *hidpp;
142 struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES +
143 DJ_DEVICE_INDEX_MIN];
144 struct list_head list;
146 struct work_struct work;
147 struct kfifo notif_fifo;
148 unsigned long last_query; /* in jiffies */
150 enum recvr_type type;
151 unsigned int unnumbered_application;
156 struct hid_device *hdev;
157 struct dj_receiver_dev *dj_receiver_dev;
158 u64 reports_supported;
162 #define WORKITEM_TYPE_EMPTY 0
163 #define WORKITEM_TYPE_PAIRED 1
164 #define WORKITEM_TYPE_UNPAIRED 2
165 #define WORKITEM_TYPE_UNKNOWN 255
168 u8 type; /* WORKITEM_TYPE_* */
173 u64 reports_supported;
176 /* Keyboard descriptor (1) */
177 static const char kbd_descriptor[] = {
178 0x05, 0x01, /* USAGE_PAGE (generic Desktop) */
179 0x09, 0x06, /* USAGE (Keyboard) */
180 0xA1, 0x01, /* COLLECTION (Application) */
181 0x85, 0x01, /* REPORT_ID (1) */
182 0x95, 0x08, /* REPORT_COUNT (8) */
183 0x75, 0x01, /* REPORT_SIZE (1) */
184 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
185 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
186 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
187 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */
188 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */
189 0x81, 0x02, /* INPUT (Data,Var,Abs) */
190 0x95, 0x06, /* REPORT_COUNT (6) */
191 0x75, 0x08, /* REPORT_SIZE (8) */
192 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
193 0x26, 0xFF, 0x00, /* LOGICAL_MAXIMUM (255) */
194 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
195 0x19, 0x00, /* USAGE_MINIMUM (no event) */
196 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */
197 0x81, 0x00, /* INPUT (Data,Ary,Abs) */
198 0x85, 0x0e, /* REPORT_ID (14) */
199 0x05, 0x08, /* USAGE PAGE (LED page) */
200 0x95, 0x05, /* REPORT COUNT (5) */
201 0x75, 0x01, /* REPORT SIZE (1) */
202 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
203 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
204 0x19, 0x01, /* USAGE MINIMUM (1) */
205 0x29, 0x05, /* USAGE MAXIMUM (5) */
206 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */
207 0x95, 0x01, /* REPORT COUNT (1) */
208 0x75, 0x03, /* REPORT SIZE (3) */
209 0x91, 0x01, /* OUTPUT (Constant) */
213 /* Mouse descriptor (2) */
214 static const char mse_descriptor[] = {
215 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
216 0x09, 0x02, /* USAGE (Mouse) */
217 0xA1, 0x01, /* COLLECTION (Application) */
218 0x85, 0x02, /* REPORT_ID = 2 */
219 0x09, 0x01, /* USAGE (pointer) */
220 0xA1, 0x00, /* COLLECTION (physical) */
221 0x05, 0x09, /* USAGE_PAGE (buttons) */
222 0x19, 0x01, /* USAGE_MIN (1) */
223 0x29, 0x10, /* USAGE_MAX (16) */
224 0x15, 0x00, /* LOGICAL_MIN (0) */
225 0x25, 0x01, /* LOGICAL_MAX (1) */
226 0x95, 0x10, /* REPORT_COUNT (16) */
227 0x75, 0x01, /* REPORT_SIZE (1) */
228 0x81, 0x02, /* INPUT (data var abs) */
229 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
230 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
231 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
232 0x75, 0x0C, /* REPORT_SIZE (12) */
233 0x95, 0x02, /* REPORT_COUNT (2) */
234 0x09, 0x30, /* USAGE (X) */
235 0x09, 0x31, /* USAGE (Y) */
236 0x81, 0x06, /* INPUT */
237 0x15, 0x81, /* LOGICAL_MIN (-127) */
238 0x25, 0x7F, /* LOGICAL_MAX (127) */
239 0x75, 0x08, /* REPORT_SIZE (8) */
240 0x95, 0x01, /* REPORT_COUNT (1) */
241 0x09, 0x38, /* USAGE (wheel) */
242 0x81, 0x06, /* INPUT */
243 0x05, 0x0C, /* USAGE_PAGE(consumer) */
244 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
245 0x95, 0x01, /* REPORT_COUNT (1) */
246 0x81, 0x06, /* INPUT */
247 0xC0, /* END_COLLECTION */
248 0xC0, /* END_COLLECTION */
251 /* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */
252 static const char mse_27mhz_descriptor[] = {
253 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
254 0x09, 0x02, /* USAGE (Mouse) */
255 0xA1, 0x01, /* COLLECTION (Application) */
256 0x85, 0x02, /* REPORT_ID = 2 */
257 0x09, 0x01, /* USAGE (pointer) */
258 0xA1, 0x00, /* COLLECTION (physical) */
259 0x05, 0x09, /* USAGE_PAGE (buttons) */
260 0x19, 0x01, /* USAGE_MIN (1) */
261 0x29, 0x08, /* USAGE_MAX (8) */
262 0x15, 0x00, /* LOGICAL_MIN (0) */
263 0x25, 0x01, /* LOGICAL_MAX (1) */
264 0x95, 0x08, /* REPORT_COUNT (8) */
265 0x75, 0x01, /* REPORT_SIZE (1) */
266 0x81, 0x02, /* INPUT (data var abs) */
267 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
268 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
269 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
270 0x75, 0x0C, /* REPORT_SIZE (12) */
271 0x95, 0x02, /* REPORT_COUNT (2) */
272 0x09, 0x30, /* USAGE (X) */
273 0x09, 0x31, /* USAGE (Y) */
274 0x81, 0x06, /* INPUT */
275 0x15, 0x81, /* LOGICAL_MIN (-127) */
276 0x25, 0x7F, /* LOGICAL_MAX (127) */
277 0x75, 0x08, /* REPORT_SIZE (8) */
278 0x95, 0x01, /* REPORT_COUNT (1) */
279 0x09, 0x38, /* USAGE (wheel) */
280 0x81, 0x06, /* INPUT */
281 0x05, 0x0C, /* USAGE_PAGE(consumer) */
282 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
283 0x95, 0x01, /* REPORT_COUNT (1) */
284 0x81, 0x06, /* INPUT */
285 0xC0, /* END_COLLECTION */
286 0xC0, /* END_COLLECTION */
289 /* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */
290 static const char mse_bluetooth_descriptor[] = {
291 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
292 0x09, 0x02, /* USAGE (Mouse) */
293 0xA1, 0x01, /* COLLECTION (Application) */
294 0x85, 0x02, /* REPORT_ID = 2 */
295 0x09, 0x01, /* USAGE (pointer) */
296 0xA1, 0x00, /* COLLECTION (physical) */
297 0x05, 0x09, /* USAGE_PAGE (buttons) */
298 0x19, 0x01, /* USAGE_MIN (1) */
299 0x29, 0x08, /* USAGE_MAX (8) */
300 0x15, 0x00, /* LOGICAL_MIN (0) */
301 0x25, 0x01, /* LOGICAL_MAX (1) */
302 0x95, 0x08, /* REPORT_COUNT (8) */
303 0x75, 0x01, /* REPORT_SIZE (1) */
304 0x81, 0x02, /* INPUT (data var abs) */
305 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
306 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */
307 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */
308 0x75, 0x0C, /* REPORT_SIZE (12) */
309 0x95, 0x02, /* REPORT_COUNT (2) */
310 0x09, 0x30, /* USAGE (X) */
311 0x09, 0x31, /* USAGE (Y) */
312 0x81, 0x06, /* INPUT */
313 0x15, 0x81, /* LOGICAL_MIN (-127) */
314 0x25, 0x7F, /* LOGICAL_MAX (127) */
315 0x75, 0x08, /* REPORT_SIZE (8) */
316 0x95, 0x01, /* REPORT_COUNT (1) */
317 0x09, 0x38, /* USAGE (wheel) */
318 0x81, 0x06, /* INPUT */
319 0x05, 0x0C, /* USAGE_PAGE(consumer) */
320 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
321 0x15, 0xF9, /* LOGICAL_MIN (-7) */
322 0x25, 0x07, /* LOGICAL_MAX (7) */
323 0x75, 0x04, /* REPORT_SIZE (4) */
324 0x95, 0x01, /* REPORT_COUNT (1) */
325 0x81, 0x06, /* INPUT */
326 0x05, 0x09, /* USAGE_PAGE (buttons) */
327 0x19, 0x09, /* USAGE_MIN (9) */
328 0x29, 0x0C, /* USAGE_MAX (12) */
329 0x15, 0x00, /* LOGICAL_MIN (0) */
330 0x25, 0x01, /* LOGICAL_MAX (1) */
331 0x75, 0x01, /* REPORT_SIZE (1) */
332 0x95, 0x04, /* REPORT_COUNT (4) */
333 0x81, 0x02, /* INPUT (Data,Var,Abs) */
334 0xC0, /* END_COLLECTION */
335 0xC0, /* END_COLLECTION */
338 /* Mouse descriptor (5) for Bluetooth receiver, normal-res hwheel, 8 buttons */
339 static const char mse5_bluetooth_descriptor[] = {
340 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
341 0x09, 0x02, /* Usage (Mouse) */
342 0xa1, 0x01, /* Collection (Application) */
343 0x85, 0x05, /* Report ID (5) */
344 0x09, 0x01, /* Usage (Pointer) */
345 0xa1, 0x00, /* Collection (Physical) */
346 0x05, 0x09, /* Usage Page (Button) */
347 0x19, 0x01, /* Usage Minimum (1) */
348 0x29, 0x08, /* Usage Maximum (8) */
349 0x15, 0x00, /* Logical Minimum (0) */
350 0x25, 0x01, /* Logical Maximum (1) */
351 0x95, 0x08, /* Report Count (8) */
352 0x75, 0x01, /* Report Size (1) */
353 0x81, 0x02, /* Input (Data,Var,Abs) */
354 0x05, 0x01, /* Usage Page (Generic Desktop) */
355 0x16, 0x01, 0xf8, /* Logical Minimum (-2047) */
356 0x26, 0xff, 0x07, /* Logical Maximum (2047) */
357 0x75, 0x0c, /* Report Size (12) */
358 0x95, 0x02, /* Report Count (2) */
359 0x09, 0x30, /* Usage (X) */
360 0x09, 0x31, /* Usage (Y) */
361 0x81, 0x06, /* Input (Data,Var,Rel) */
362 0x15, 0x81, /* Logical Minimum (-127) */
363 0x25, 0x7f, /* Logical Maximum (127) */
364 0x75, 0x08, /* Report Size (8) */
365 0x95, 0x01, /* Report Count (1) */
366 0x09, 0x38, /* Usage (Wheel) */
367 0x81, 0x06, /* Input (Data,Var,Rel) */
368 0x05, 0x0c, /* Usage Page (Consumer Devices) */
369 0x0a, 0x38, 0x02, /* Usage (AC Pan) */
370 0x15, 0x81, /* Logical Minimum (-127) */
371 0x25, 0x7f, /* Logical Maximum (127) */
372 0x75, 0x08, /* Report Size (8) */
373 0x95, 0x01, /* Report Count (1) */
374 0x81, 0x06, /* Input (Data,Var,Rel) */
375 0xc0, /* End Collection */
376 0xc0, /* End Collection */
379 /* Gaming Mouse descriptor (2) */
380 static const char mse_high_res_descriptor[] = {
381 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
382 0x09, 0x02, /* USAGE (Mouse) */
383 0xA1, 0x01, /* COLLECTION (Application) */
384 0x85, 0x02, /* REPORT_ID = 2 */
385 0x09, 0x01, /* USAGE (pointer) */
386 0xA1, 0x00, /* COLLECTION (physical) */
387 0x05, 0x09, /* USAGE_PAGE (buttons) */
388 0x19, 0x01, /* USAGE_MIN (1) */
389 0x29, 0x10, /* USAGE_MAX (16) */
390 0x15, 0x00, /* LOGICAL_MIN (0) */
391 0x25, 0x01, /* LOGICAL_MAX (1) */
392 0x95, 0x10, /* REPORT_COUNT (16) */
393 0x75, 0x01, /* REPORT_SIZE (1) */
394 0x81, 0x02, /* INPUT (data var abs) */
395 0x05, 0x01, /* USAGE_PAGE (generic desktop) */
396 0x16, 0x01, 0x80, /* LOGICAL_MIN (-32767) */
397 0x26, 0xFF, 0x7F, /* LOGICAL_MAX (32767) */
398 0x75, 0x10, /* REPORT_SIZE (16) */
399 0x95, 0x02, /* REPORT_COUNT (2) */
400 0x09, 0x30, /* USAGE (X) */
401 0x09, 0x31, /* USAGE (Y) */
402 0x81, 0x06, /* INPUT */
403 0x15, 0x81, /* LOGICAL_MIN (-127) */
404 0x25, 0x7F, /* LOGICAL_MAX (127) */
405 0x75, 0x08, /* REPORT_SIZE (8) */
406 0x95, 0x01, /* REPORT_COUNT (1) */
407 0x09, 0x38, /* USAGE (wheel) */
408 0x81, 0x06, /* INPUT */
409 0x05, 0x0C, /* USAGE_PAGE(consumer) */
410 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */
411 0x95, 0x01, /* REPORT_COUNT (1) */
412 0x81, 0x06, /* INPUT */
413 0xC0, /* END_COLLECTION */
414 0xC0, /* END_COLLECTION */
417 /* Consumer Control descriptor (3) */
418 static const char consumer_descriptor[] = {
419 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */
420 0x09, 0x01, /* USAGE (Consumer Control) */
421 0xA1, 0x01, /* COLLECTION (Application) */
422 0x85, 0x03, /* REPORT_ID = 3 */
423 0x75, 0x10, /* REPORT_SIZE (16) */
424 0x95, 0x02, /* REPORT_COUNT (2) */
425 0x15, 0x01, /* LOGICAL_MIN (1) */
426 0x26, 0xFF, 0x02, /* LOGICAL_MAX (767) */
427 0x19, 0x01, /* USAGE_MIN (1) */
428 0x2A, 0xFF, 0x02, /* USAGE_MAX (767) */
429 0x81, 0x00, /* INPUT (Data Ary Abs) */
430 0xC0, /* END_COLLECTION */
433 /* System control descriptor (4) */
434 static const char syscontrol_descriptor[] = {
435 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
436 0x09, 0x80, /* USAGE (System Control) */
437 0xA1, 0x01, /* COLLECTION (Application) */
438 0x85, 0x04, /* REPORT_ID = 4 */
439 0x75, 0x02, /* REPORT_SIZE (2) */
440 0x95, 0x01, /* REPORT_COUNT (1) */
441 0x15, 0x01, /* LOGICAL_MIN (1) */
442 0x25, 0x03, /* LOGICAL_MAX (3) */
443 0x09, 0x82, /* USAGE (System Sleep) */
444 0x09, 0x81, /* USAGE (System Power Down) */
445 0x09, 0x83, /* USAGE (System Wake Up) */
446 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */
447 0x75, 0x06, /* REPORT_SIZE (6) */
448 0x81, 0x03, /* INPUT (Cnst Var Abs) */
449 0xC0, /* END_COLLECTION */
452 /* Media descriptor (8) */
453 static const char media_descriptor[] = {
454 0x06, 0xbc, 0xff, /* Usage Page 0xffbc */
455 0x09, 0x88, /* Usage 0x0088 */
456 0xa1, 0x01, /* BeginCollection */
457 0x85, 0x08, /* Report ID 8 */
458 0x19, 0x01, /* Usage Min 0x0001 */
459 0x29, 0xff, /* Usage Max 0x00ff */
460 0x15, 0x01, /* Logical Min 1 */
461 0x26, 0xff, 0x00, /* Logical Max 255 */
462 0x75, 0x08, /* Report Size 8 */
463 0x95, 0x01, /* Report Count 1 */
464 0x81, 0x00, /* Input */
465 0xc0, /* EndCollection */
468 /* HIDPP descriptor */
469 static const char hidpp_descriptor[] = {
470 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
471 0x09, 0x01, /* Usage (Vendor Usage 1) */
472 0xa1, 0x01, /* Collection (Application) */
473 0x85, 0x10, /* Report ID (16) */
474 0x75, 0x08, /* Report Size (8) */
475 0x95, 0x06, /* Report Count (6) */
476 0x15, 0x00, /* Logical Minimum (0) */
477 0x26, 0xff, 0x00, /* Logical Maximum (255) */
478 0x09, 0x01, /* Usage (Vendor Usage 1) */
479 0x81, 0x00, /* Input (Data,Arr,Abs) */
480 0x09, 0x01, /* Usage (Vendor Usage 1) */
481 0x91, 0x00, /* Output (Data,Arr,Abs) */
482 0xc0, /* End Collection */
483 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
484 0x09, 0x02, /* Usage (Vendor Usage 2) */
485 0xa1, 0x01, /* Collection (Application) */
486 0x85, 0x11, /* Report ID (17) */
487 0x75, 0x08, /* Report Size (8) */
488 0x95, 0x13, /* Report Count (19) */
489 0x15, 0x00, /* Logical Minimum (0) */
490 0x26, 0xff, 0x00, /* Logical Maximum (255) */
491 0x09, 0x02, /* Usage (Vendor Usage 2) */
492 0x81, 0x00, /* Input (Data,Arr,Abs) */
493 0x09, 0x02, /* Usage (Vendor Usage 2) */
494 0x91, 0x00, /* Output (Data,Arr,Abs) */
495 0xc0, /* End Collection */
496 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
497 0x09, 0x04, /* Usage (Vendor Usage 0x04) */
498 0xa1, 0x01, /* Collection (Application) */
499 0x85, 0x20, /* Report ID (32) */
500 0x75, 0x08, /* Report Size (8) */
501 0x95, 0x0e, /* Report Count (14) */
502 0x15, 0x00, /* Logical Minimum (0) */
503 0x26, 0xff, 0x00, /* Logical Maximum (255) */
504 0x09, 0x41, /* Usage (Vendor Usage 0x41) */
505 0x81, 0x00, /* Input (Data,Arr,Abs) */
506 0x09, 0x41, /* Usage (Vendor Usage 0x41) */
507 0x91, 0x00, /* Output (Data,Arr,Abs) */
508 0x85, 0x21, /* Report ID (33) */
509 0x95, 0x1f, /* Report Count (31) */
510 0x15, 0x00, /* Logical Minimum (0) */
511 0x26, 0xff, 0x00, /* Logical Maximum (255) */
512 0x09, 0x42, /* Usage (Vendor Usage 0x42) */
513 0x81, 0x00, /* Input (Data,Arr,Abs) */
514 0x09, 0x42, /* Usage (Vendor Usage 0x42) */
515 0x91, 0x00, /* Output (Data,Arr,Abs) */
516 0xc0, /* End Collection */
519 /* Maximum size of all defined hid reports in bytes (including report id) */
520 #define MAX_REPORT_SIZE 8
522 /* Make sure all descriptors are present here */
523 #define MAX_RDESC_SIZE \
524 (sizeof(kbd_descriptor) + \
525 sizeof(mse_bluetooth_descriptor) + \
526 sizeof(mse5_bluetooth_descriptor) + \
527 sizeof(consumer_descriptor) + \
528 sizeof(syscontrol_descriptor) + \
529 sizeof(media_descriptor) + \
530 sizeof(hidpp_descriptor))
532 /* Number of possible hid report types that can be created by this driver.
534 * Right now, RF report types have the same report types (or report id's)
535 * than the hid report created from those RF reports. In the future
536 * this doesnt have to be true.
538 * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds
539 * to hid report id 0x01, this is standard keyboard. Same thing applies to mice
540 * reports and consumer control, etc. If a new RF report is created, it doesn't
541 * has to have the same report id as its corresponding hid report, so an
542 * translation may have to take place for future report types.
544 #define NUMBER_OF_HID_REPORTS 32
545 static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = {
546 [1] = 8, /* Standard keyboard */
547 [2] = 8, /* Standard mouse */
548 [3] = 5, /* Consumer control */
549 [4] = 2, /* System control */
550 [8] = 2, /* Media Center */
554 #define LOGITECH_DJ_INTERFACE_NUMBER 0x02
556 static struct hid_ll_driver logi_dj_ll_driver;
558 static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev);
559 static void delayedwork_callback(struct work_struct *work);
561 static LIST_HEAD(dj_hdev_list);
562 static DEFINE_MUTEX(dj_hdev_list_lock);
564 static bool recvr_type_is_bluetooth(enum recvr_type type)
566 return type == recvr_type_bluetooth || type == recvr_type_dinovo;
570 * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows
571 * compatibility they have multiple USB interfaces. On HID++ receivers we need
572 * to listen for input reports on both interfaces. The functions below are used
573 * to create a single struct dj_receiver_dev for all interfaces belonging to
574 * a single USB-device / receiver.
576 static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev,
577 enum recvr_type type)
579 struct dj_receiver_dev *djrcv_dev;
583 * The bluetooth receiver contains a built-in hub and has separate
584 * USB-devices for the keyboard and mouse interfaces.
586 sep = recvr_type_is_bluetooth(type) ? '.' : '/';
588 /* Try to find an already-probed interface from the same device */
589 list_for_each_entry(djrcv_dev, &dj_hdev_list, list) {
590 if (djrcv_dev->mouse &&
591 hid_compare_device_paths(hdev, djrcv_dev->mouse, sep)) {
592 kref_get(&djrcv_dev->kref);
595 if (djrcv_dev->keyboard &&
596 hid_compare_device_paths(hdev, djrcv_dev->keyboard, sep)) {
597 kref_get(&djrcv_dev->kref);
600 if (djrcv_dev->hidpp &&
601 hid_compare_device_paths(hdev, djrcv_dev->hidpp, sep)) {
602 kref_get(&djrcv_dev->kref);
610 static void dj_release_receiver_dev(struct kref *kref)
612 struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref);
614 list_del(&djrcv_dev->list);
615 kfifo_free(&djrcv_dev->notif_fifo);
619 static void dj_put_receiver_dev(struct hid_device *hdev)
621 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
623 mutex_lock(&dj_hdev_list_lock);
625 if (djrcv_dev->mouse == hdev)
626 djrcv_dev->mouse = NULL;
627 if (djrcv_dev->keyboard == hdev)
628 djrcv_dev->keyboard = NULL;
629 if (djrcv_dev->hidpp == hdev)
630 djrcv_dev->hidpp = NULL;
632 kref_put(&djrcv_dev->kref, dj_release_receiver_dev);
634 mutex_unlock(&dj_hdev_list_lock);
637 static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev,
638 enum recvr_type type,
639 unsigned int application,
642 struct dj_receiver_dev *djrcv_dev;
644 mutex_lock(&dj_hdev_list_lock);
646 djrcv_dev = dj_find_receiver_dev(hdev, type);
648 djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL);
652 INIT_WORK(&djrcv_dev->work, delayedwork_callback);
653 spin_lock_init(&djrcv_dev->lock);
654 if (kfifo_alloc(&djrcv_dev->notif_fifo,
655 DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem),
661 kref_init(&djrcv_dev->kref);
662 list_add_tail(&djrcv_dev->list, &dj_hdev_list);
663 djrcv_dev->last_query = jiffies;
664 djrcv_dev->type = type;
667 if (application == HID_GD_KEYBOARD)
668 djrcv_dev->keyboard = hdev;
669 if (application == HID_GD_MOUSE)
670 djrcv_dev->mouse = hdev;
672 djrcv_dev->hidpp = hdev;
674 hid_set_drvdata(hdev, djrcv_dev);
676 mutex_unlock(&dj_hdev_list_lock);
680 static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev,
681 struct dj_workitem *workitem)
683 /* Called in delayed work context */
684 struct dj_device *dj_dev;
687 spin_lock_irqsave(&djrcv_dev->lock, flags);
688 dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index];
689 djrcv_dev->paired_dj_devices[workitem->device_index] = NULL;
690 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
692 if (dj_dev != NULL) {
693 hid_destroy_device(dj_dev->hdev);
696 hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n",
701 static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
702 struct dj_workitem *workitem)
704 /* Called in delayed work context */
705 struct hid_device *djrcv_hdev = djrcv_dev->hidpp;
706 struct hid_device *dj_hiddev;
707 struct dj_device *dj_dev;
708 u8 device_index = workitem->device_index;
711 /* Device index goes from 1 to 6, we need 3 bytes to store the
712 * semicolon, the index, and a null terminator
714 unsigned char tmpstr[3];
716 /* We are the only one ever adding a device, no need to lock */
717 if (djrcv_dev->paired_dj_devices[device_index]) {
718 /* The device is already known. No need to reallocate it. */
719 dbg_hid("%s: device is already known\n", __func__);
723 dj_hiddev = hid_allocate_device();
724 if (IS_ERR(dj_hiddev)) {
725 hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__);
729 dj_hiddev->ll_driver = &logi_dj_ll_driver;
731 dj_hiddev->dev.parent = &djrcv_hdev->dev;
732 dj_hiddev->bus = BUS_USB;
733 dj_hiddev->vendor = djrcv_hdev->vendor;
734 dj_hiddev->product = (workitem->quad_id_msb << 8) |
735 workitem->quad_id_lsb;
736 if (workitem->device_type) {
737 const char *type_str = "Device";
739 switch (workitem->device_type) {
740 case 0x01: type_str = "Keyboard"; break;
741 case 0x02: type_str = "Mouse"; break;
742 case 0x03: type_str = "Numpad"; break;
743 case 0x04: type_str = "Presenter"; break;
744 case 0x07: type_str = "Remote Control"; break;
745 case 0x08: type_str = "Trackball"; break;
746 case 0x09: type_str = "Touchpad"; break;
748 snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
749 "Logitech Wireless %s PID:%04x",
750 type_str, dj_hiddev->product);
752 snprintf(dj_hiddev->name, sizeof(dj_hiddev->name),
753 "Logitech Wireless Device PID:%04x",
757 if (djrcv_dev->type == recvr_type_27mhz)
758 dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE;
760 dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE;
762 memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys));
763 snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index);
764 strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys));
766 dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL);
769 hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__);
770 goto dj_device_allocate_fail;
773 dj_dev->reports_supported = workitem->reports_supported;
774 dj_dev->hdev = dj_hiddev;
775 dj_dev->dj_receiver_dev = djrcv_dev;
776 dj_dev->device_index = device_index;
777 dj_hiddev->driver_data = dj_dev;
779 spin_lock_irqsave(&djrcv_dev->lock, flags);
780 djrcv_dev->paired_dj_devices[device_index] = dj_dev;
781 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
783 if (hid_add_device(dj_hiddev)) {
784 hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__);
785 goto hid_add_device_fail;
791 spin_lock_irqsave(&djrcv_dev->lock, flags);
792 djrcv_dev->paired_dj_devices[device_index] = NULL;
793 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
795 dj_device_allocate_fail:
796 hid_destroy_device(dj_hiddev);
799 static void delayedwork_callback(struct work_struct *work)
801 struct dj_receiver_dev *djrcv_dev =
802 container_of(work, struct dj_receiver_dev, work);
804 struct dj_workitem workitem;
809 dbg_hid("%s\n", __func__);
811 spin_lock_irqsave(&djrcv_dev->lock, flags);
814 * Since we attach to multiple interfaces, we may get scheduled before
815 * we are bound to the HID++ interface, catch this.
817 if (!djrcv_dev->ready) {
818 pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n",
820 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
824 count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
826 if (count != sizeof(workitem)) {
827 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
831 if (!kfifo_is_empty(&djrcv_dev->notif_fifo))
832 schedule_work(&djrcv_dev->work);
834 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
836 switch (workitem.type) {
837 case WORKITEM_TYPE_PAIRED:
838 logi_dj_recv_add_djhid_device(djrcv_dev, &workitem);
840 case WORKITEM_TYPE_UNPAIRED:
841 logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem);
843 case WORKITEM_TYPE_UNKNOWN:
844 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
846 hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n",
850 case WORKITEM_TYPE_EMPTY:
851 dbg_hid("%s: device list is empty\n", __func__);
857 * Sometimes we receive reports for which we do not have a paired dj_device
858 * associated with the device_index or report-type to forward the report to.
859 * This means that the original "device paired" notification corresponding
860 * to the dj_device never arrived to this driver. Possible reasons for this are:
861 * 1) hid-core discards all packets coming from a device during probe().
862 * 2) if the receiver is plugged into a KVM switch then the pairing reports
863 * are only forwarded to it if the focus is on this PC.
864 * This function deals with this by re-asking the receiver for the list of
865 * connected devices in the delayed work callback.
866 * This function MUST be called with djrcv->lock held.
868 static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev)
870 struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN };
872 /* Rate limit queries done because of unhandled reports to 2/sec */
873 if (time_before(jiffies, djrcv_dev->last_query + HZ / 2))
876 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
877 schedule_work(&djrcv_dev->work);
880 static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,
881 struct dj_report *dj_report)
883 /* We are called from atomic context (tasklet && djrcv->lock held) */
884 struct dj_workitem workitem = {
885 .device_index = dj_report->device_index,
888 switch (dj_report->report_type) {
889 case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
890 workitem.type = WORKITEM_TYPE_PAIRED;
891 if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] &
892 SPFUNCTION_DEVICE_LIST_EMPTY) {
893 workitem.type = WORKITEM_TYPE_EMPTY;
897 case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
898 workitem.quad_id_msb =
899 dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB];
900 workitem.quad_id_lsb =
901 dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB];
902 workitem.reports_supported = get_unaligned_le32(
903 dj_report->report_params +
904 DEVICE_PAIRED_RF_REPORT_TYPE);
905 workitem.reports_supported |= HIDPP;
906 if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED)
907 workitem.type = WORKITEM_TYPE_UNPAIRED;
910 logi_dj_recv_queue_unknown_work(djrcv_dev);
914 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
915 schedule_work(&djrcv_dev->work);
919 * Some quad/bluetooth keyboards have a builtin touchpad in this case we see
920 * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the
921 * touchpad to work we must also forward mouse input reports to the dj_hiddev
922 * created for the keyboard (instead of forwarding them to a second paired
923 * device with a device_type of REPORT_TYPE_MOUSE as we normally would).
925 * On Dinovo receivers the keyboard's touchpad and an optional paired actual
926 * mouse send separate input reports, INPUT(2) aka STD_MOUSE for the mouse
927 * and INPUT(5) aka KBD_MOUSE for the keyboard's touchpad.
929 * On MX5x00 receivers (which can also be paired with a Dinovo keyboard)
930 * INPUT(2) is used for both an optional paired actual mouse and for the
931 * keyboard's touchpad.
933 static const u16 kbd_builtin_touchpad_ids[] = {
934 0xb309, /* Dinovo Edge */
935 0xb30c, /* Dinovo Mini */
938 static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev,
939 struct hidpp_event *hidpp_report,
940 struct dj_workitem *workitem)
942 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
945 workitem->type = WORKITEM_TYPE_PAIRED;
946 workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
947 HIDPP_DEVICE_TYPE_MASK;
948 workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB];
949 workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB];
950 switch (workitem->device_type) {
951 case REPORT_TYPE_KEYBOARD:
952 workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
953 POWER_KEYS | MEDIA_CENTER |
955 id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb;
956 for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) {
957 if (id == kbd_builtin_touchpad_ids[i]) {
958 if (djrcv_dev->type == recvr_type_dinovo)
959 workitem->reports_supported |= KBD_MOUSE;
961 workitem->reports_supported |= STD_MOUSE;
966 case REPORT_TYPE_MOUSE:
967 workitem->reports_supported |= STD_MOUSE | HIDPP;
968 if (djrcv_dev->type == recvr_type_mouse_only)
969 workitem->reports_supported |= MULTIMEDIA;
974 static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev,
975 struct hidpp_event *hidpp_report,
976 struct dj_workitem *workitem)
978 workitem->type = WORKITEM_TYPE_PAIRED;
979 workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID];
980 switch (hidpp_report->device_index) {
981 case 1: /* Index 1 is always a mouse */
982 case 2: /* Index 2 is always a mouse */
983 workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE;
984 workitem->reports_supported |= STD_MOUSE | HIDPP;
986 case 3: /* Index 3 is always the keyboard */
987 case 4: /* Index 4 is used for an optional separate numpad */
988 workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD;
989 workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA |
993 hid_warn(hdev, "%s: unexpected device-index %d", __func__,
994 hidpp_report->device_index);
998 static void logi_hidpp_recv_queue_notif(struct hid_device *hdev,
999 struct hidpp_event *hidpp_report)
1001 /* We are called from atomic context (tasklet && djrcv->lock held) */
1002 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1003 const char *device_type = "UNKNOWN";
1004 struct dj_workitem workitem = {
1005 .type = WORKITEM_TYPE_EMPTY,
1006 .device_index = hidpp_report->device_index,
1009 switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) {
1011 device_type = "Bluetooth";
1012 /* Bluetooth connect packet contents is the same as (e)QUAD */
1013 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1014 if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] &
1015 HIDPP_MANUFACTURER_MASK)) {
1016 hid_info(hdev, "Non Logitech device connected on slot %d\n",
1017 hidpp_report->device_index);
1018 workitem.reports_supported &= ~HIDPP;
1022 device_type = "27 Mhz";
1023 logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem);
1026 device_type = "QUAD or eQUAD";
1027 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1030 device_type = "eQUAD step 4 DJ";
1031 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1034 device_type = "DFU Lite";
1037 device_type = "eQUAD step 4 Lite";
1038 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1041 device_type = "eQUAD step 4 Gaming";
1042 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1043 workitem.reports_supported |= STD_KEYBOARD;
1046 device_type = "eQUAD step 4 for gamepads";
1049 device_type = "eQUAD nano Lite";
1050 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1053 device_type = "eQUAD Lightspeed 1";
1054 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1055 workitem.reports_supported |= STD_KEYBOARD;
1058 device_type = "eQUAD Lightspeed 1.1";
1059 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1060 workitem.reports_supported |= STD_KEYBOARD;
1063 device_type = "eQUAD Lightspeed 1.2";
1064 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem);
1065 workitem.reports_supported |= STD_KEYBOARD;
1069 /* custom receiver device (eg. powerplay) */
1070 if (hidpp_report->device_index == 7) {
1071 workitem.reports_supported |= HIDPP;
1074 if (workitem.type == WORKITEM_TYPE_EMPTY) {
1076 "unusable device of type %s (0x%02x) connected on slot %d",
1078 hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
1079 hidpp_report->device_index);
1083 hid_info(hdev, "device of type %s (0x%02x) connected on slot %d",
1084 device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE],
1085 hidpp_report->device_index);
1087 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1088 schedule_work(&djrcv_dev->work);
1091 static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev,
1092 struct dj_report *dj_report)
1094 /* We are called from atomic context (tasklet && djrcv->lock held) */
1096 u8 reportbuffer[MAX_REPORT_SIZE];
1097 struct dj_device *djdev;
1099 djdev = djrcv_dev->paired_dj_devices[dj_report->device_index];
1101 memset(reportbuffer, 0, sizeof(reportbuffer));
1103 for (i = 0; i < NUMBER_OF_HID_REPORTS; i++) {
1104 if (djdev->reports_supported & (1 << i)) {
1105 reportbuffer[0] = i;
1106 if (hid_input_report(djdev->hdev,
1109 hid_reportid_size_map[i], 1)) {
1110 dbg_hid("hid_input_report error sending null "
1117 static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev,
1118 struct dj_report *dj_report)
1120 /* We are called from atomic context (tasklet && djrcv->lock held) */
1121 struct dj_device *dj_device;
1123 dj_device = djrcv_dev->paired_dj_devices[dj_report->device_index];
1125 if ((dj_report->report_type > ARRAY_SIZE(hid_reportid_size_map) - 1) ||
1126 (hid_reportid_size_map[dj_report->report_type] == 0)) {
1127 dbg_hid("invalid report type:%x\n", dj_report->report_type);
1131 if (hid_input_report(dj_device->hdev,
1132 HID_INPUT_REPORT, &dj_report->report_type,
1133 hid_reportid_size_map[dj_report->report_type], 1)) {
1134 dbg_hid("hid_input_report error\n");
1138 static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data,
1141 /* We are called from atomic context (tasklet && djrcv->lock held) */
1142 if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1))
1143 dbg_hid("hid_input_report error\n");
1146 static void logi_dj_recv_forward_input_report(struct hid_device *hdev,
1149 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1150 struct dj_device *dj_dev;
1151 unsigned long flags;
1152 u8 report = data[0];
1155 if (report > REPORT_TYPE_RFREPORT_LAST) {
1156 hid_err(hdev, "Unexpected input report number %d\n", report);
1160 spin_lock_irqsave(&djrcv_dev->lock, flags);
1161 for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1162 dj_dev = djrcv_dev->paired_dj_devices[i];
1163 if (dj_dev && (dj_dev->reports_supported & BIT(report))) {
1164 logi_dj_recv_forward_report(dj_dev, data, size);
1165 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1170 logi_dj_recv_queue_unknown_work(djrcv_dev);
1171 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1173 dbg_hid("No dj-devs handling input report number %d\n", report);
1176 static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
1177 struct dj_report *dj_report)
1179 struct hid_device *hdev = djrcv_dev->hidpp;
1180 struct hid_report *report;
1181 struct hid_report_enum *output_report_enum;
1182 u8 *data = (u8 *)(&dj_report->device_index);
1185 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
1186 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
1189 hid_err(hdev, "%s: unable to find dj report\n", __func__);
1193 for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++)
1194 report->field[0]->value[i] = data[i];
1196 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
1201 static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev)
1203 static const u8 template[] = {
1204 REPORT_ID_HIDPP_SHORT,
1205 HIDPP_RECEIVER_INDEX,
1207 HIDPP_REG_CONNECTION_STATE,
1208 HIDPP_FAKE_DEVICE_ARRIVAL,
1214 hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL);
1218 retval = hid_hw_raw_request(djrcv_dev->hidpp,
1219 REPORT_ID_HIDPP_SHORT,
1220 hidpp_report, sizeof(template),
1222 HID_REQ_SET_REPORT);
1224 kfree(hidpp_report);
1225 return (retval < 0) ? retval : 0;
1228 static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)
1230 struct dj_report *dj_report;
1233 djrcv_dev->last_query = jiffies;
1235 if (djrcv_dev->type != recvr_type_dj)
1236 return logi_dj_recv_query_hidpp_devices(djrcv_dev);
1238 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
1241 dj_report->report_id = REPORT_ID_DJ_SHORT;
1242 dj_report->device_index = HIDPP_RECEIVER_INDEX;
1243 dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES;
1244 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
1250 static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev,
1253 struct hid_device *hdev = djrcv_dev->hidpp;
1254 struct dj_report *dj_report;
1258 dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL);
1262 if (djrcv_dev->type == recvr_type_dj) {
1263 dj_report->report_id = REPORT_ID_DJ_SHORT;
1264 dj_report->device_index = HIDPP_RECEIVER_INDEX;
1265 dj_report->report_type = REPORT_TYPE_CMD_SWITCH;
1266 dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F;
1267 dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] =
1270 retval = logi_dj_recv_send_report(djrcv_dev, dj_report);
1273 * Ugly sleep to work around a USB 3.0 bug when the receiver is
1274 * still processing the "switch-to-dj" command while we send an
1276 * 50 msec should gives enough time to the receiver to be ready.
1282 * Magical bits to set up hidpp notifications when the dj devices
1283 * are connected/disconnected.
1285 * We can reuse dj_report because HIDPP_REPORT_SHORT_LENGTH is smaller
1286 * than DJREPORT_SHORT_LENGTH.
1288 buf = (u8 *)dj_report;
1290 memset(buf, 0, HIDPP_REPORT_SHORT_LENGTH);
1292 buf[0] = REPORT_ID_HIDPP_SHORT;
1293 buf[1] = HIDPP_RECEIVER_INDEX;
1300 hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf,
1301 HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT,
1302 HID_REQ_SET_REPORT);
1309 static int logi_dj_ll_open(struct hid_device *hid)
1311 dbg_hid("%s: %s\n", __func__, hid->phys);
1316 static void logi_dj_ll_close(struct hid_device *hid)
1318 dbg_hid("%s: %s\n", __func__, hid->phys);
1322 * Register 0xB5 is "pairing information". It is solely intended for the
1323 * receiver, so do not overwrite the device index.
1325 static u8 unifying_pairing_query[] = { REPORT_ID_HIDPP_SHORT,
1326 HIDPP_RECEIVER_INDEX,
1327 HIDPP_GET_LONG_REGISTER,
1328 HIDPP_REG_PAIRING_INFORMATION };
1329 static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG,
1330 HIDPP_RECEIVER_INDEX,
1331 HIDPP_GET_LONG_REGISTER,
1332 HIDPP_REG_PAIRING_INFORMATION };
1334 static int logi_dj_ll_raw_request(struct hid_device *hid,
1335 unsigned char reportnum, __u8 *buf,
1336 size_t count, unsigned char report_type,
1339 struct dj_device *djdev = hid->driver_data;
1340 struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
1344 if ((buf[0] == REPORT_ID_HIDPP_SHORT) ||
1345 (buf[0] == REPORT_ID_HIDPP_LONG) ||
1346 (buf[0] == REPORT_ID_HIDPP_VERY_LONG)) {
1350 /* special case where we should not overwrite
1351 * the device_index */
1352 if (count == 7 && !memcmp(buf, unifying_pairing_query,
1353 sizeof(unifying_pairing_query)))
1354 buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1);
1356 buf[1] = djdev->device_index;
1357 return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf,
1358 count, report_type, reqtype);
1361 if (buf[0] != REPORT_TYPE_LEDS)
1364 if (djrcv_dev->type != recvr_type_dj && count >= 2) {
1365 if (!djrcv_dev->keyboard) {
1366 hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n");
1369 /* usbhid overrides the report ID and ignores the first byte */
1370 return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count,
1371 report_type, reqtype);
1374 out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC);
1378 if (count > DJREPORT_SHORT_LENGTH - 2)
1379 count = DJREPORT_SHORT_LENGTH - 2;
1381 out_buf[0] = REPORT_ID_DJ_SHORT;
1382 out_buf[1] = djdev->device_index;
1383 memcpy(out_buf + 2, buf, count);
1385 ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf,
1386 DJREPORT_SHORT_LENGTH, report_type, reqtype);
1392 static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size)
1394 memcpy(rdesc + *rsize, data, size);
1398 static int logi_dj_ll_parse(struct hid_device *hid)
1400 struct dj_device *djdev = hid->driver_data;
1401 unsigned int rsize = 0;
1405 dbg_hid("%s\n", __func__);
1407 djdev->hdev->version = 0x0111;
1408 djdev->hdev->country = 0x00;
1410 rdesc = kmalloc(MAX_RDESC_SIZE, GFP_KERNEL);
1414 if (djdev->reports_supported & STD_KEYBOARD) {
1415 dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n",
1416 __func__, djdev->reports_supported);
1417 rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor));
1420 if (djdev->reports_supported & STD_MOUSE) {
1421 dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n",
1422 __func__, djdev->reports_supported);
1423 if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp ||
1424 djdev->dj_receiver_dev->type == recvr_type_mouse_only)
1425 rdcat(rdesc, &rsize, mse_high_res_descriptor,
1426 sizeof(mse_high_res_descriptor));
1427 else if (djdev->dj_receiver_dev->type == recvr_type_27mhz)
1428 rdcat(rdesc, &rsize, mse_27mhz_descriptor,
1429 sizeof(mse_27mhz_descriptor));
1430 else if (recvr_type_is_bluetooth(djdev->dj_receiver_dev->type))
1431 rdcat(rdesc, &rsize, mse_bluetooth_descriptor,
1432 sizeof(mse_bluetooth_descriptor));
1434 rdcat(rdesc, &rsize, mse_descriptor,
1435 sizeof(mse_descriptor));
1438 if (djdev->reports_supported & KBD_MOUSE) {
1439 dbg_hid("%s: sending a kbd-mouse descriptor, reports_supported: %llx\n",
1440 __func__, djdev->reports_supported);
1441 rdcat(rdesc, &rsize, mse5_bluetooth_descriptor,
1442 sizeof(mse5_bluetooth_descriptor));
1445 if (djdev->reports_supported & MULTIMEDIA) {
1446 dbg_hid("%s: sending a multimedia report descriptor: %llx\n",
1447 __func__, djdev->reports_supported);
1448 rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor));
1451 if (djdev->reports_supported & POWER_KEYS) {
1452 dbg_hid("%s: sending a power keys report descriptor: %llx\n",
1453 __func__, djdev->reports_supported);
1454 rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor));
1457 if (djdev->reports_supported & MEDIA_CENTER) {
1458 dbg_hid("%s: sending a media center report descriptor: %llx\n",
1459 __func__, djdev->reports_supported);
1460 rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor));
1463 if (djdev->reports_supported & KBD_LEDS) {
1464 dbg_hid("%s: need to send kbd leds report descriptor: %llx\n",
1465 __func__, djdev->reports_supported);
1468 if (djdev->reports_supported & HIDPP) {
1469 dbg_hid("%s: sending a HID++ descriptor, reports_supported: %llx\n",
1470 __func__, djdev->reports_supported);
1471 rdcat(rdesc, &rsize, hidpp_descriptor,
1472 sizeof(hidpp_descriptor));
1475 retval = hid_parse_report(hid, rdesc, rsize);
1481 static int logi_dj_ll_start(struct hid_device *hid)
1483 dbg_hid("%s\n", __func__);
1487 static void logi_dj_ll_stop(struct hid_device *hid)
1489 dbg_hid("%s\n", __func__);
1492 static bool logi_dj_ll_may_wakeup(struct hid_device *hid)
1494 struct dj_device *djdev = hid->driver_data;
1495 struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev;
1497 return hid_hw_may_wakeup(djrcv_dev->hidpp);
1500 static struct hid_ll_driver logi_dj_ll_driver = {
1501 .parse = logi_dj_ll_parse,
1502 .start = logi_dj_ll_start,
1503 .stop = logi_dj_ll_stop,
1504 .open = logi_dj_ll_open,
1505 .close = logi_dj_ll_close,
1506 .raw_request = logi_dj_ll_raw_request,
1507 .may_wakeup = logi_dj_ll_may_wakeup,
1510 static int logi_dj_dj_event(struct hid_device *hdev,
1511 struct hid_report *report, u8 *data,
1514 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1515 struct dj_report *dj_report = (struct dj_report *) data;
1516 unsigned long flags;
1519 * Here we receive all data coming from iface 2, there are 3 cases:
1521 * 1) Data is intended for this driver i. e. data contains arrival,
1522 * departure, etc notifications, in which case we queue them for delayed
1523 * processing by the work queue. We return 1 to hid-core as no further
1524 * processing is required from it.
1526 * 2) Data informs a connection change, if the change means rf link
1527 * loss, then we must send a null report to the upper layer to discard
1528 * potentially pressed keys that may be repeated forever by the input
1529 * layer. Return 1 to hid-core as no further processing is required.
1531 * 3) Data is an actual input event from a paired DJ device in which
1532 * case we forward it to the correct hid device (via hid_input_report()
1533 * ) and return 1 so hid-core does not anything else with it.
1536 if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
1537 (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
1539 * Device index is wrong, bail out.
1540 * This driver can ignore safely the receiver notifications,
1541 * so ignore those reports too.
1543 if (dj_report->device_index != DJ_RECEIVER_INDEX)
1544 hid_err(hdev, "%s: invalid device index:%d\n",
1545 __func__, dj_report->device_index);
1549 spin_lock_irqsave(&djrcv_dev->lock, flags);
1551 if (!djrcv_dev->paired_dj_devices[dj_report->device_index]) {
1552 /* received an event for an unknown device, bail out */
1553 logi_dj_recv_queue_notification(djrcv_dev, dj_report);
1557 switch (dj_report->report_type) {
1558 case REPORT_TYPE_NOTIF_DEVICE_PAIRED:
1559 /* pairing notifications are handled above the switch */
1561 case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED:
1562 logi_dj_recv_queue_notification(djrcv_dev, dj_report);
1564 case REPORT_TYPE_NOTIF_CONNECTION_STATUS:
1565 if (dj_report->report_params[CONNECTION_STATUS_PARAM_STATUS] ==
1567 logi_dj_recv_forward_null_report(djrcv_dev, dj_report);
1571 logi_dj_recv_forward_dj(djrcv_dev, dj_report);
1575 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1580 static int logi_dj_hidpp_event(struct hid_device *hdev,
1581 struct hid_report *report, u8 *data,
1584 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1585 struct hidpp_event *hidpp_report = (struct hidpp_event *) data;
1586 struct dj_device *dj_dev;
1587 unsigned long flags;
1588 u8 device_index = hidpp_report->device_index;
1590 if (device_index == HIDPP_RECEIVER_INDEX) {
1591 /* special case were the device wants to know its unifying
1593 if (size == HIDPP_REPORT_LONG_LENGTH &&
1594 !memcmp(data, unifying_pairing_answer,
1595 sizeof(unifying_pairing_answer)))
1596 device_index = (data[4] & 0x0F) + 1;
1602 * Data is from the HID++ collection, in this case, we forward the
1603 * data to the corresponding child dj device and return 0 to hid-core
1604 * so he data also goes to the hidraw device of the receiver. This
1605 * allows a user space application to implement the full HID++ routing
1609 if ((device_index < DJ_DEVICE_INDEX_MIN) ||
1610 (device_index > DJ_DEVICE_INDEX_MAX)) {
1612 * Device index is wrong, bail out.
1613 * This driver can ignore safely the receiver notifications,
1614 * so ignore those reports too.
1616 hid_err(hdev, "%s: invalid device index:%d\n", __func__,
1617 hidpp_report->device_index);
1621 spin_lock_irqsave(&djrcv_dev->lock, flags);
1623 dj_dev = djrcv_dev->paired_dj_devices[device_index];
1626 * With 27 MHz receivers, we do not get an explicit unpair event,
1627 * remove the old device if the user has paired a *different* device.
1629 if (djrcv_dev->type == recvr_type_27mhz && dj_dev &&
1630 hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED &&
1631 hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 &&
1632 hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] !=
1633 dj_dev->hdev->product) {
1634 struct dj_workitem workitem = {
1635 .device_index = hidpp_report->device_index,
1636 .type = WORKITEM_TYPE_UNPAIRED,
1638 kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem));
1639 /* logi_hidpp_recv_queue_notif will queue the work */
1644 logi_dj_recv_forward_report(dj_dev, data, size);
1646 if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED)
1647 logi_hidpp_recv_queue_notif(hdev, hidpp_report);
1649 logi_dj_recv_queue_unknown_work(djrcv_dev);
1652 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1657 static int logi_dj_raw_event(struct hid_device *hdev,
1658 struct hid_report *report, u8 *data,
1661 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1662 dbg_hid("%s, size:%d\n", __func__, size);
1667 if (!hdev->report_enum[HID_INPUT_REPORT].numbered) {
1669 if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) {
1671 * For the keyboard, we can reuse the same report by
1672 * using the second byte which is constant in the USB
1673 * HID report descriptor.
1676 data[0] = REPORT_TYPE_KEYBOARD;
1678 logi_dj_recv_forward_input_report(hdev, data, size);
1680 /* restore previous state */
1685 * Mouse-only receivers send unnumbered mouse data. The 27 MHz
1686 * receiver uses 6 byte packets, the nano receiver 8 bytes.
1688 if (djrcv_dev->unnumbered_application == HID_GD_MOUSE &&
1692 /* Prepend report id */
1693 mouse_report[0] = REPORT_TYPE_MOUSE;
1694 memcpy(mouse_report + 1, data, size);
1695 logi_dj_recv_forward_input_report(hdev, mouse_report,
1703 case REPORT_ID_DJ_SHORT:
1704 if (size != DJREPORT_SHORT_LENGTH) {
1705 hid_err(hdev, "Short DJ report bad size (%d)", size);
1708 return logi_dj_dj_event(hdev, report, data, size);
1709 case REPORT_ID_DJ_LONG:
1710 if (size != DJREPORT_LONG_LENGTH) {
1711 hid_err(hdev, "Long DJ report bad size (%d)", size);
1714 return logi_dj_dj_event(hdev, report, data, size);
1715 case REPORT_ID_HIDPP_SHORT:
1716 if (size != HIDPP_REPORT_SHORT_LENGTH) {
1717 hid_err(hdev, "Short HID++ report bad size (%d)", size);
1720 return logi_dj_hidpp_event(hdev, report, data, size);
1721 case REPORT_ID_HIDPP_LONG:
1722 if (size != HIDPP_REPORT_LONG_LENGTH) {
1723 hid_err(hdev, "Long HID++ report bad size (%d)", size);
1726 return logi_dj_hidpp_event(hdev, report, data, size);
1729 logi_dj_recv_forward_input_report(hdev, data, size);
1734 static int logi_dj_probe(struct hid_device *hdev,
1735 const struct hid_device_id *id)
1737 struct hid_report_enum *rep_enum;
1738 struct hid_report *rep;
1739 struct dj_receiver_dev *djrcv_dev;
1740 struct usb_interface *intf;
1741 unsigned int no_dj_interfaces = 0;
1742 bool has_hidpp = false;
1743 unsigned long flags;
1747 * Call to usbhid to fetch the HID descriptors of the current
1748 * interface subsequently call to the hid/hid-core to parse the
1749 * fetched descriptors.
1751 retval = hid_parse(hdev);
1753 hid_err(hdev, "%s: parse failed\n", __func__);
1758 * Some KVMs add an extra interface for e.g. mouse emulation. If we
1759 * treat these as logitech-dj interfaces then this causes input events
1760 * reported through this extra interface to not be reported correctly.
1761 * To avoid this, we treat these as generic-hid devices.
1763 switch (id->driver_data) {
1764 case recvr_type_dj: no_dj_interfaces = 3; break;
1765 case recvr_type_hidpp: no_dj_interfaces = 2; break;
1766 case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break;
1767 case recvr_type_mouse_only: no_dj_interfaces = 2; break;
1768 case recvr_type_27mhz: no_dj_interfaces = 2; break;
1769 case recvr_type_bluetooth: no_dj_interfaces = 2; break;
1770 case recvr_type_dinovo: no_dj_interfaces = 2; break;
1772 if (hid_is_using_ll_driver(hdev, &usb_hid_driver)) {
1773 intf = to_usb_interface(hdev->dev.parent);
1774 if (intf && intf->altsetting->desc.bInterfaceNumber >=
1776 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
1777 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1781 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
1783 /* no input reports, bail out */
1784 if (list_empty(&rep_enum->report_list))
1788 * Check for the HID++ application.
1789 * Note: we should theoretically check for HID++ and DJ
1790 * collections, but this will do.
1792 list_for_each_entry(rep, &rep_enum->report_list, list) {
1793 if (rep->application == 0xff000001)
1798 * Ignore interfaces without DJ/HID++ collection, they will not carry
1799 * any data, dont create any hid_device for them.
1801 if (!has_hidpp && id->driver_data == recvr_type_dj)
1804 /* get the current application attached to the node */
1805 rep = list_first_entry(&rep_enum->report_list, struct hid_report, list);
1806 djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data,
1807 rep->application, has_hidpp);
1809 hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__);
1813 if (!rep_enum->numbered)
1814 djrcv_dev->unnumbered_application = rep->application;
1816 /* Starts the usb device and connects to upper interfaces hiddev and
1818 retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV);
1820 hid_err(hdev, "%s: hid_hw_start returned error\n", __func__);
1821 goto hid_hw_start_fail;
1825 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1827 hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1829 goto switch_to_dj_mode_fail;
1833 /* This is enabling the polling urb on the IN endpoint */
1834 retval = hid_hw_open(hdev);
1836 hid_err(hdev, "%s: hid_hw_open returned error:%d\n",
1841 /* Allow incoming packets to arrive: */
1842 hid_device_io_start(hdev);
1845 spin_lock_irqsave(&djrcv_dev->lock, flags);
1846 djrcv_dev->ready = true;
1847 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1848 retval = logi_dj_recv_query_paired_devices(djrcv_dev);
1850 hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n",
1853 * This can happen with a KVM, let the probe succeed,
1854 * logi_dj_recv_queue_unknown_work will retry later.
1862 switch_to_dj_mode_fail:
1866 dj_put_receiver_dev(hdev);
1871 static int logi_dj_reset_resume(struct hid_device *hdev)
1874 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1876 if (!djrcv_dev || djrcv_dev->hidpp != hdev)
1879 retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0);
1881 hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n",
1889 static void logi_dj_remove(struct hid_device *hdev)
1891 struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev);
1892 struct dj_device *dj_dev;
1893 unsigned long flags;
1896 dbg_hid("%s\n", __func__);
1899 return hid_hw_stop(hdev);
1902 * This ensures that if the work gets requeued from another
1903 * interface of the same receiver it will be a no-op.
1905 spin_lock_irqsave(&djrcv_dev->lock, flags);
1906 djrcv_dev->ready = false;
1907 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1909 cancel_work_sync(&djrcv_dev->work);
1915 * For proper operation we need access to all interfaces, so we destroy
1916 * the paired devices when we're unbound from any interface.
1918 * Note we may still be bound to other interfaces, sharing the same
1919 * djrcv_dev, so we need locking here.
1921 for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) {
1922 spin_lock_irqsave(&djrcv_dev->lock, flags);
1923 dj_dev = djrcv_dev->paired_dj_devices[i];
1924 djrcv_dev->paired_dj_devices[i] = NULL;
1925 spin_unlock_irqrestore(&djrcv_dev->lock, flags);
1926 if (dj_dev != NULL) {
1927 hid_destroy_device(dj_dev->hdev);
1932 dj_put_receiver_dev(hdev);
1935 static const struct hid_device_id logi_dj_receivers[] = {
1936 { /* Logitech unifying receiver (0xc52b) */
1937 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1938 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER),
1939 .driver_data = recvr_type_dj},
1940 { /* Logitech unifying receiver (0xc532) */
1941 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1942 USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2),
1943 .driver_data = recvr_type_dj},
1945 { /* Logitech Nano mouse only receiver (0xc52f) */
1946 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1947 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER),
1948 .driver_data = recvr_type_mouse_only},
1949 { /* Logitech Nano (non DJ) receiver (0xc534) */
1950 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1951 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2),
1952 .driver_data = recvr_type_hidpp},
1954 { /* Logitech G700(s) receiver (0xc531) */
1955 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1956 USB_DEVICE_ID_LOGITECH_G700_RECEIVER),
1957 .driver_data = recvr_type_gaming_hidpp},
1958 { /* Logitech G602 receiver (0xc537) */
1959 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1961 .driver_data = recvr_type_gaming_hidpp},
1962 { /* Logitech lightspeed receiver (0xc539) */
1963 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1964 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1),
1965 .driver_data = recvr_type_gaming_hidpp},
1966 { /* Logitech powerplay receiver (0xc53a) */
1967 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1968 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY),
1969 .driver_data = recvr_type_gaming_hidpp},
1970 { /* Logitech lightspeed receiver (0xc53f) */
1971 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1972 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1),
1973 .driver_data = recvr_type_gaming_hidpp},
1975 { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */
1976 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
1977 .driver_data = recvr_type_27mhz},
1978 { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */
1979 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1980 USB_DEVICE_ID_S510_RECEIVER_2),
1981 .driver_data = recvr_type_27mhz},
1982 { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */
1983 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1984 USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER),
1985 .driver_data = recvr_type_27mhz},
1987 { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. (0xc70e) */
1988 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1989 USB_DEVICE_ID_MX5000_RECEIVER_KBD_DEV),
1990 .driver_data = recvr_type_bluetooth},
1991 { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. (0xc70a) */
1992 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1993 USB_DEVICE_ID_MX5000_RECEIVER_MOUSE_DEV),
1994 .driver_data = recvr_type_bluetooth},
1995 { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. (0xc71b) */
1996 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
1997 USB_DEVICE_ID_MX5500_RECEIVER_KBD_DEV),
1998 .driver_data = recvr_type_bluetooth},
1999 { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. (0xc71c) */
2000 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2001 USB_DEVICE_ID_MX5500_RECEIVER_MOUSE_DEV),
2002 .driver_data = recvr_type_bluetooth},
2004 { /* Logitech Dinovo Edge HID++ / bluetooth receiver keyboard intf. (0xc713) */
2005 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2006 USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_KBD_DEV),
2007 .driver_data = recvr_type_dinovo},
2008 { /* Logitech Dinovo Edge HID++ / bluetooth receiver mouse intf. (0xc714) */
2009 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2010 USB_DEVICE_ID_DINOVO_EDGE_RECEIVER_MOUSE_DEV),
2011 .driver_data = recvr_type_dinovo},
2012 { /* Logitech DiNovo Mini HID++ / bluetooth receiver mouse intf. (0xc71e) */
2013 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2014 USB_DEVICE_ID_DINOVO_MINI_RECEIVER_KBD_DEV),
2015 .driver_data = recvr_type_dinovo},
2016 { /* Logitech DiNovo Mini HID++ / bluetooth receiver keyboard intf. (0xc71f) */
2017 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH,
2018 USB_DEVICE_ID_DINOVO_MINI_RECEIVER_MOUSE_DEV),
2019 .driver_data = recvr_type_dinovo},
2023 MODULE_DEVICE_TABLE(hid, logi_dj_receivers);
2025 static struct hid_driver logi_djreceiver_driver = {
2026 .name = "logitech-djreceiver",
2027 .id_table = logi_dj_receivers,
2028 .probe = logi_dj_probe,
2029 .remove = logi_dj_remove,
2030 .raw_event = logi_dj_raw_event,
2032 .reset_resume = logi_dj_reset_resume,
2036 module_hid_driver(logi_djreceiver_driver);
2038 MODULE_LICENSE("GPL");
2039 MODULE_AUTHOR("Logitech");
2040 MODULE_AUTHOR("Nestor Lopez Casado");
2041 MODULE_AUTHOR("nlopezcasad@logitech.com");