.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | | - * HID driver for Logitech Unifying receivers |
---|
| 3 | + * HID driver for Logitech receivers |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2011 Logitech |
---|
5 | 6 | */ |
---|
6 | 7 | |
---|
7 | | -/* |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | | - |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, write to the Free Software |
---|
20 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
21 | | - * |
---|
22 | | - */ |
---|
23 | 8 | |
---|
24 | 9 | |
---|
25 | 10 | #include <linux/device.h> |
---|
26 | 11 | #include <linux/hid.h> |
---|
27 | 12 | #include <linux/module.h> |
---|
28 | | -#include <linux/usb.h> |
---|
29 | 13 | #include <linux/kfifo.h> |
---|
| 14 | +#include <linux/delay.h> |
---|
| 15 | +#include <linux/usb.h> /* For to_usb_interface for kvm extra intf check */ |
---|
30 | 16 | #include <asm/unaligned.h> |
---|
31 | 17 | #include "hid-ids.h" |
---|
32 | 18 | |
---|
33 | | -#define DJ_MAX_PAIRED_DEVICES 6 |
---|
34 | | -#define DJ_MAX_NUMBER_NOTIFICATIONS 8 |
---|
| 19 | +#define DJ_MAX_PAIRED_DEVICES 7 |
---|
| 20 | +#define DJ_MAX_NUMBER_NOTIFS 8 |
---|
35 | 21 | #define DJ_RECEIVER_INDEX 0 |
---|
36 | 22 | #define DJ_DEVICE_INDEX_MIN 1 |
---|
37 | | -#define DJ_DEVICE_INDEX_MAX 6 |
---|
| 23 | +#define DJ_DEVICE_INDEX_MAX 7 |
---|
38 | 24 | |
---|
39 | 25 | #define DJREPORT_SHORT_LENGTH 15 |
---|
40 | 26 | #define DJREPORT_LONG_LENGTH 32 |
---|
.. | .. |
---|
44 | 30 | |
---|
45 | 31 | #define REPORT_ID_HIDPP_SHORT 0x10 |
---|
46 | 32 | #define REPORT_ID_HIDPP_LONG 0x11 |
---|
| 33 | +#define REPORT_ID_HIDPP_VERY_LONG 0x12 |
---|
47 | 34 | |
---|
48 | 35 | #define HIDPP_REPORT_SHORT_LENGTH 7 |
---|
49 | 36 | #define HIDPP_REPORT_LONG_LENGTH 20 |
---|
.. | .. |
---|
74 | 61 | /* Device Un-Paired Notification */ |
---|
75 | 62 | #define REPORT_TYPE_NOTIF_DEVICE_UNPAIRED 0x40 |
---|
76 | 63 | |
---|
77 | | - |
---|
78 | 64 | /* Connection Status Notification */ |
---|
79 | 65 | #define REPORT_TYPE_NOTIF_CONNECTION_STATUS 0x42 |
---|
80 | 66 | #define CONNECTION_STATUS_PARAM_STATUS 0x00 |
---|
.. | .. |
---|
94 | 80 | #define REPORT_TYPE_LEDS 0x0E |
---|
95 | 81 | |
---|
96 | 82 | /* RF Report types bitfield */ |
---|
97 | | -#define STD_KEYBOARD 0x00000002 |
---|
98 | | -#define STD_MOUSE 0x00000004 |
---|
99 | | -#define MULTIMEDIA 0x00000008 |
---|
100 | | -#define POWER_KEYS 0x00000010 |
---|
101 | | -#define MEDIA_CENTER 0x00000100 |
---|
102 | | -#define KBD_LEDS 0x00004000 |
---|
| 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 MEDIA_CENTER BIT(8) |
---|
| 88 | +#define KBD_LEDS BIT(14) |
---|
| 89 | +/* Fake (bitnr > NUMBER_OF_HID_REPORTS) bit to track HID++ capability */ |
---|
| 90 | +#define HIDPP BIT_ULL(63) |
---|
| 91 | + |
---|
| 92 | +/* HID++ Device Connected Notification */ |
---|
| 93 | +#define REPORT_TYPE_NOTIF_DEVICE_CONNECTED 0x41 |
---|
| 94 | +#define HIDPP_PARAM_PROTO_TYPE 0x00 |
---|
| 95 | +#define HIDPP_PARAM_DEVICE_INFO 0x01 |
---|
| 96 | +#define HIDPP_PARAM_EQUAD_LSB 0x02 |
---|
| 97 | +#define HIDPP_PARAM_EQUAD_MSB 0x03 |
---|
| 98 | +#define HIDPP_PARAM_27MHZ_DEVID 0x03 |
---|
| 99 | +#define HIDPP_DEVICE_TYPE_MASK GENMASK(3, 0) |
---|
| 100 | +#define HIDPP_LINK_STATUS_MASK BIT(6) |
---|
| 101 | +#define HIDPP_MANUFACTURER_MASK BIT(7) |
---|
| 102 | + |
---|
| 103 | +#define HIDPP_DEVICE_TYPE_KEYBOARD 1 |
---|
| 104 | +#define HIDPP_DEVICE_TYPE_MOUSE 2 |
---|
| 105 | + |
---|
| 106 | +#define HIDPP_SET_REGISTER 0x80 |
---|
| 107 | +#define HIDPP_GET_LONG_REGISTER 0x83 |
---|
| 108 | +#define HIDPP_REG_CONNECTION_STATE 0x02 |
---|
| 109 | +#define HIDPP_REG_PAIRING_INFORMATION 0xB5 |
---|
| 110 | +#define HIDPP_PAIRING_INFORMATION 0x20 |
---|
| 111 | +#define HIDPP_FAKE_DEVICE_ARRIVAL 0x02 |
---|
| 112 | + |
---|
| 113 | +enum recvr_type { |
---|
| 114 | + recvr_type_dj, |
---|
| 115 | + recvr_type_hidpp, |
---|
| 116 | + recvr_type_gaming_hidpp, |
---|
| 117 | + recvr_type_mouse_only, |
---|
| 118 | + recvr_type_27mhz, |
---|
| 119 | + recvr_type_bluetooth, |
---|
| 120 | +}; |
---|
103 | 121 | |
---|
104 | 122 | struct dj_report { |
---|
105 | 123 | u8 report_id; |
---|
.. | .. |
---|
108 | 126 | u8 report_params[DJREPORT_SHORT_LENGTH - 3]; |
---|
109 | 127 | }; |
---|
110 | 128 | |
---|
| 129 | +struct hidpp_event { |
---|
| 130 | + u8 report_id; |
---|
| 131 | + u8 device_index; |
---|
| 132 | + u8 sub_id; |
---|
| 133 | + u8 params[HIDPP_REPORT_LONG_LENGTH - 3U]; |
---|
| 134 | +} __packed; |
---|
| 135 | + |
---|
111 | 136 | struct dj_receiver_dev { |
---|
112 | | - struct hid_device *hdev; |
---|
| 137 | + struct hid_device *mouse; |
---|
| 138 | + struct hid_device *keyboard; |
---|
| 139 | + struct hid_device *hidpp; |
---|
113 | 140 | struct dj_device *paired_dj_devices[DJ_MAX_PAIRED_DEVICES + |
---|
114 | 141 | DJ_DEVICE_INDEX_MIN]; |
---|
| 142 | + struct list_head list; |
---|
| 143 | + struct kref kref; |
---|
115 | 144 | struct work_struct work; |
---|
116 | 145 | struct kfifo notif_fifo; |
---|
| 146 | + unsigned long last_query; /* in jiffies */ |
---|
| 147 | + bool ready; |
---|
| 148 | + enum recvr_type type; |
---|
| 149 | + unsigned int unnumbered_application; |
---|
117 | 150 | spinlock_t lock; |
---|
118 | | - bool querying_devices; |
---|
119 | 151 | }; |
---|
120 | 152 | |
---|
121 | 153 | struct dj_device { |
---|
122 | 154 | struct hid_device *hdev; |
---|
123 | 155 | struct dj_receiver_dev *dj_receiver_dev; |
---|
124 | | - u32 reports_supported; |
---|
| 156 | + u64 reports_supported; |
---|
125 | 157 | u8 device_index; |
---|
| 158 | +}; |
---|
| 159 | + |
---|
| 160 | +#define WORKITEM_TYPE_EMPTY 0 |
---|
| 161 | +#define WORKITEM_TYPE_PAIRED 1 |
---|
| 162 | +#define WORKITEM_TYPE_UNPAIRED 2 |
---|
| 163 | +#define WORKITEM_TYPE_UNKNOWN 255 |
---|
| 164 | + |
---|
| 165 | +struct dj_workitem { |
---|
| 166 | + u8 type; /* WORKITEM_TYPE_* */ |
---|
| 167 | + u8 device_index; |
---|
| 168 | + u8 device_type; |
---|
| 169 | + u8 quad_id_msb; |
---|
| 170 | + u8 quad_id_lsb; |
---|
| 171 | + u64 reports_supported; |
---|
126 | 172 | }; |
---|
127 | 173 | |
---|
128 | 174 | /* Keyboard descriptor (1) */ |
---|
.. | .. |
---|
200 | 246 | 0xC0, /* END_COLLECTION */ |
---|
201 | 247 | }; |
---|
202 | 248 | |
---|
| 249 | +/* Mouse descriptor (2) for 27 MHz receiver, only 8 buttons */ |
---|
| 250 | +static const char mse_27mhz_descriptor[] = { |
---|
| 251 | + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
---|
| 252 | + 0x09, 0x02, /* USAGE (Mouse) */ |
---|
| 253 | + 0xA1, 0x01, /* COLLECTION (Application) */ |
---|
| 254 | + 0x85, 0x02, /* REPORT_ID = 2 */ |
---|
| 255 | + 0x09, 0x01, /* USAGE (pointer) */ |
---|
| 256 | + 0xA1, 0x00, /* COLLECTION (physical) */ |
---|
| 257 | + 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
---|
| 258 | + 0x19, 0x01, /* USAGE_MIN (1) */ |
---|
| 259 | + 0x29, 0x08, /* USAGE_MAX (8) */ |
---|
| 260 | + 0x15, 0x00, /* LOGICAL_MIN (0) */ |
---|
| 261 | + 0x25, 0x01, /* LOGICAL_MAX (1) */ |
---|
| 262 | + 0x95, 0x08, /* REPORT_COUNT (8) */ |
---|
| 263 | + 0x75, 0x01, /* REPORT_SIZE (1) */ |
---|
| 264 | + 0x81, 0x02, /* INPUT (data var abs) */ |
---|
| 265 | + 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
---|
| 266 | + 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ |
---|
| 267 | + 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ |
---|
| 268 | + 0x75, 0x0C, /* REPORT_SIZE (12) */ |
---|
| 269 | + 0x95, 0x02, /* REPORT_COUNT (2) */ |
---|
| 270 | + 0x09, 0x30, /* USAGE (X) */ |
---|
| 271 | + 0x09, 0x31, /* USAGE (Y) */ |
---|
| 272 | + 0x81, 0x06, /* INPUT */ |
---|
| 273 | + 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
---|
| 274 | + 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
---|
| 275 | + 0x75, 0x08, /* REPORT_SIZE (8) */ |
---|
| 276 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 277 | + 0x09, 0x38, /* USAGE (wheel) */ |
---|
| 278 | + 0x81, 0x06, /* INPUT */ |
---|
| 279 | + 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
---|
| 280 | + 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
---|
| 281 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 282 | + 0x81, 0x06, /* INPUT */ |
---|
| 283 | + 0xC0, /* END_COLLECTION */ |
---|
| 284 | + 0xC0, /* END_COLLECTION */ |
---|
| 285 | +}; |
---|
| 286 | + |
---|
| 287 | +/* Mouse descriptor (2) for Bluetooth receiver, low-res hwheel, 12 buttons */ |
---|
| 288 | +static const char mse_bluetooth_descriptor[] = { |
---|
| 289 | + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
---|
| 290 | + 0x09, 0x02, /* USAGE (Mouse) */ |
---|
| 291 | + 0xA1, 0x01, /* COLLECTION (Application) */ |
---|
| 292 | + 0x85, 0x02, /* REPORT_ID = 2 */ |
---|
| 293 | + 0x09, 0x01, /* USAGE (pointer) */ |
---|
| 294 | + 0xA1, 0x00, /* COLLECTION (physical) */ |
---|
| 295 | + 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
---|
| 296 | + 0x19, 0x01, /* USAGE_MIN (1) */ |
---|
| 297 | + 0x29, 0x08, /* USAGE_MAX (8) */ |
---|
| 298 | + 0x15, 0x00, /* LOGICAL_MIN (0) */ |
---|
| 299 | + 0x25, 0x01, /* LOGICAL_MAX (1) */ |
---|
| 300 | + 0x95, 0x08, /* REPORT_COUNT (8) */ |
---|
| 301 | + 0x75, 0x01, /* REPORT_SIZE (1) */ |
---|
| 302 | + 0x81, 0x02, /* INPUT (data var abs) */ |
---|
| 303 | + 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
---|
| 304 | + 0x16, 0x01, 0xF8, /* LOGICAL_MIN (-2047) */ |
---|
| 305 | + 0x26, 0xFF, 0x07, /* LOGICAL_MAX (2047) */ |
---|
| 306 | + 0x75, 0x0C, /* REPORT_SIZE (12) */ |
---|
| 307 | + 0x95, 0x02, /* REPORT_COUNT (2) */ |
---|
| 308 | + 0x09, 0x30, /* USAGE (X) */ |
---|
| 309 | + 0x09, 0x31, /* USAGE (Y) */ |
---|
| 310 | + 0x81, 0x06, /* INPUT */ |
---|
| 311 | + 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
---|
| 312 | + 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
---|
| 313 | + 0x75, 0x08, /* REPORT_SIZE (8) */ |
---|
| 314 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 315 | + 0x09, 0x38, /* USAGE (wheel) */ |
---|
| 316 | + 0x81, 0x06, /* INPUT */ |
---|
| 317 | + 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
---|
| 318 | + 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
---|
| 319 | + 0x15, 0xF9, /* LOGICAL_MIN (-7) */ |
---|
| 320 | + 0x25, 0x07, /* LOGICAL_MAX (7) */ |
---|
| 321 | + 0x75, 0x04, /* REPORT_SIZE (4) */ |
---|
| 322 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 323 | + 0x81, 0x06, /* INPUT */ |
---|
| 324 | + 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
---|
| 325 | + 0x19, 0x09, /* USAGE_MIN (9) */ |
---|
| 326 | + 0x29, 0x0C, /* USAGE_MAX (12) */ |
---|
| 327 | + 0x15, 0x00, /* LOGICAL_MIN (0) */ |
---|
| 328 | + 0x25, 0x01, /* LOGICAL_MAX (1) */ |
---|
| 329 | + 0x75, 0x01, /* REPORT_SIZE (1) */ |
---|
| 330 | + 0x95, 0x04, /* REPORT_COUNT (4) */ |
---|
| 331 | + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ |
---|
| 332 | + 0xC0, /* END_COLLECTION */ |
---|
| 333 | + 0xC0, /* END_COLLECTION */ |
---|
| 334 | +}; |
---|
| 335 | + |
---|
| 336 | +/* Gaming Mouse descriptor (2) */ |
---|
| 337 | +static const char mse_high_res_descriptor[] = { |
---|
| 338 | + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ |
---|
| 339 | + 0x09, 0x02, /* USAGE (Mouse) */ |
---|
| 340 | + 0xA1, 0x01, /* COLLECTION (Application) */ |
---|
| 341 | + 0x85, 0x02, /* REPORT_ID = 2 */ |
---|
| 342 | + 0x09, 0x01, /* USAGE (pointer) */ |
---|
| 343 | + 0xA1, 0x00, /* COLLECTION (physical) */ |
---|
| 344 | + 0x05, 0x09, /* USAGE_PAGE (buttons) */ |
---|
| 345 | + 0x19, 0x01, /* USAGE_MIN (1) */ |
---|
| 346 | + 0x29, 0x10, /* USAGE_MAX (16) */ |
---|
| 347 | + 0x15, 0x00, /* LOGICAL_MIN (0) */ |
---|
| 348 | + 0x25, 0x01, /* LOGICAL_MAX (1) */ |
---|
| 349 | + 0x95, 0x10, /* REPORT_COUNT (16) */ |
---|
| 350 | + 0x75, 0x01, /* REPORT_SIZE (1) */ |
---|
| 351 | + 0x81, 0x02, /* INPUT (data var abs) */ |
---|
| 352 | + 0x05, 0x01, /* USAGE_PAGE (generic desktop) */ |
---|
| 353 | + 0x16, 0x01, 0x80, /* LOGICAL_MIN (-32767) */ |
---|
| 354 | + 0x26, 0xFF, 0x7F, /* LOGICAL_MAX (32767) */ |
---|
| 355 | + 0x75, 0x10, /* REPORT_SIZE (16) */ |
---|
| 356 | + 0x95, 0x02, /* REPORT_COUNT (2) */ |
---|
| 357 | + 0x09, 0x30, /* USAGE (X) */ |
---|
| 358 | + 0x09, 0x31, /* USAGE (Y) */ |
---|
| 359 | + 0x81, 0x06, /* INPUT */ |
---|
| 360 | + 0x15, 0x81, /* LOGICAL_MIN (-127) */ |
---|
| 361 | + 0x25, 0x7F, /* LOGICAL_MAX (127) */ |
---|
| 362 | + 0x75, 0x08, /* REPORT_SIZE (8) */ |
---|
| 363 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 364 | + 0x09, 0x38, /* USAGE (wheel) */ |
---|
| 365 | + 0x81, 0x06, /* INPUT */ |
---|
| 366 | + 0x05, 0x0C, /* USAGE_PAGE(consumer) */ |
---|
| 367 | + 0x0A, 0x38, 0x02, /* USAGE(AC Pan) */ |
---|
| 368 | + 0x95, 0x01, /* REPORT_COUNT (1) */ |
---|
| 369 | + 0x81, 0x06, /* INPUT */ |
---|
| 370 | + 0xC0, /* END_COLLECTION */ |
---|
| 371 | + 0xC0, /* END_COLLECTION */ |
---|
| 372 | +}; |
---|
| 373 | + |
---|
203 | 374 | /* Consumer Control descriptor (3) */ |
---|
204 | 375 | static const char consumer_descriptor[] = { |
---|
205 | 376 | 0x05, 0x0C, /* USAGE_PAGE (Consumer Devices) */ |
---|
.. | .. |
---|
209 | 380 | 0x75, 0x10, /* REPORT_SIZE (16) */ |
---|
210 | 381 | 0x95, 0x02, /* REPORT_COUNT (2) */ |
---|
211 | 382 | 0x15, 0x01, /* LOGICAL_MIN (1) */ |
---|
212 | | - 0x26, 0x8C, 0x02, /* LOGICAL_MAX (652) */ |
---|
| 383 | + 0x26, 0xFF, 0x02, /* LOGICAL_MAX (767) */ |
---|
213 | 384 | 0x19, 0x01, /* USAGE_MIN (1) */ |
---|
214 | | - 0x2A, 0x8C, 0x02, /* USAGE_MAX (652) */ |
---|
| 385 | + 0x2A, 0xFF, 0x02, /* USAGE_MAX (767) */ |
---|
215 | 386 | 0x81, 0x00, /* INPUT (Data Ary Abs) */ |
---|
216 | 387 | 0xC0, /* END_COLLECTION */ |
---|
217 | 388 | }; /* */ |
---|
.. | .. |
---|
308 | 479 | /* Make sure all descriptors are present here */ |
---|
309 | 480 | #define MAX_RDESC_SIZE \ |
---|
310 | 481 | (sizeof(kbd_descriptor) + \ |
---|
311 | | - sizeof(mse_descriptor) + \ |
---|
| 482 | + sizeof(mse_bluetooth_descriptor) + \ |
---|
312 | 483 | sizeof(consumer_descriptor) + \ |
---|
313 | 484 | sizeof(syscontrol_descriptor) + \ |
---|
314 | 485 | sizeof(media_descriptor) + \ |
---|
.. | .. |
---|
341 | 512 | static struct hid_ll_driver logi_dj_ll_driver; |
---|
342 | 513 | |
---|
343 | 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 | + |
---|
| 517 | +static LIST_HEAD(dj_hdev_list); |
---|
| 518 | +static DEFINE_MUTEX(dj_hdev_list_lock); |
---|
| 519 | + |
---|
| 520 | +/* |
---|
| 521 | + * dj/HID++ receivers are really a single logical entity, but for BIOS/Windows |
---|
| 522 | + * compatibility they have multiple USB interfaces. On HID++ receivers we need |
---|
| 523 | + * to listen for input reports on both interfaces. The functions below are used |
---|
| 524 | + * to create a single struct dj_receiver_dev for all interfaces belonging to |
---|
| 525 | + * a single USB-device / receiver. |
---|
| 526 | + */ |
---|
| 527 | +static struct dj_receiver_dev *dj_find_receiver_dev(struct hid_device *hdev, |
---|
| 528 | + enum recvr_type type) |
---|
| 529 | +{ |
---|
| 530 | + struct dj_receiver_dev *djrcv_dev; |
---|
| 531 | + char sep; |
---|
| 532 | + |
---|
| 533 | + /* |
---|
| 534 | + * The bluetooth receiver contains a built-in hub and has separate |
---|
| 535 | + * USB-devices for the keyboard and mouse interfaces. |
---|
| 536 | + */ |
---|
| 537 | + sep = (type == recvr_type_bluetooth) ? '.' : '/'; |
---|
| 538 | + |
---|
| 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 | + |
---|
| 558 | + return NULL; |
---|
| 559 | +} |
---|
| 560 | + |
---|
| 561 | +static void dj_release_receiver_dev(struct kref *kref) |
---|
| 562 | +{ |
---|
| 563 | + struct dj_receiver_dev *djrcv_dev = container_of(kref, struct dj_receiver_dev, kref); |
---|
| 564 | + |
---|
| 565 | + list_del(&djrcv_dev->list); |
---|
| 566 | + kfifo_free(&djrcv_dev->notif_fifo); |
---|
| 567 | + kfree(djrcv_dev); |
---|
| 568 | +} |
---|
| 569 | + |
---|
| 570 | +static void dj_put_receiver_dev(struct hid_device *hdev) |
---|
| 571 | +{ |
---|
| 572 | + struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
| 573 | + |
---|
| 574 | + mutex_lock(&dj_hdev_list_lock); |
---|
| 575 | + |
---|
| 576 | + if (djrcv_dev->mouse == hdev) |
---|
| 577 | + djrcv_dev->mouse = NULL; |
---|
| 578 | + if (djrcv_dev->keyboard == hdev) |
---|
| 579 | + djrcv_dev->keyboard = NULL; |
---|
| 580 | + if (djrcv_dev->hidpp == hdev) |
---|
| 581 | + djrcv_dev->hidpp = NULL; |
---|
| 582 | + |
---|
| 583 | + kref_put(&djrcv_dev->kref, dj_release_receiver_dev); |
---|
| 584 | + |
---|
| 585 | + mutex_unlock(&dj_hdev_list_lock); |
---|
| 586 | +} |
---|
| 587 | + |
---|
| 588 | +static struct dj_receiver_dev *dj_get_receiver_dev(struct hid_device *hdev, |
---|
| 589 | + enum recvr_type type, |
---|
| 590 | + unsigned int application, |
---|
| 591 | + bool is_hidpp) |
---|
| 592 | +{ |
---|
| 593 | + struct dj_receiver_dev *djrcv_dev; |
---|
| 594 | + |
---|
| 595 | + mutex_lock(&dj_hdev_list_lock); |
---|
| 596 | + |
---|
| 597 | + djrcv_dev = dj_find_receiver_dev(hdev, type); |
---|
| 598 | + if (!djrcv_dev) { |
---|
| 599 | + djrcv_dev = kzalloc(sizeof(*djrcv_dev), GFP_KERNEL); |
---|
| 600 | + if (!djrcv_dev) |
---|
| 601 | + goto out; |
---|
| 602 | + |
---|
| 603 | + INIT_WORK(&djrcv_dev->work, delayedwork_callback); |
---|
| 604 | + spin_lock_init(&djrcv_dev->lock); |
---|
| 605 | + if (kfifo_alloc(&djrcv_dev->notif_fifo, |
---|
| 606 | + DJ_MAX_NUMBER_NOTIFS * sizeof(struct dj_workitem), |
---|
| 607 | + GFP_KERNEL)) { |
---|
| 608 | + kfree(djrcv_dev); |
---|
| 609 | + djrcv_dev = NULL; |
---|
| 610 | + goto out; |
---|
| 611 | + } |
---|
| 612 | + kref_init(&djrcv_dev->kref); |
---|
| 613 | + list_add_tail(&djrcv_dev->list, &dj_hdev_list); |
---|
| 614 | + djrcv_dev->last_query = jiffies; |
---|
| 615 | + djrcv_dev->type = type; |
---|
| 616 | + } |
---|
| 617 | + |
---|
| 618 | + if (application == HID_GD_KEYBOARD) |
---|
| 619 | + djrcv_dev->keyboard = hdev; |
---|
| 620 | + if (application == HID_GD_MOUSE) |
---|
| 621 | + djrcv_dev->mouse = hdev; |
---|
| 622 | + if (is_hidpp) |
---|
| 623 | + djrcv_dev->hidpp = hdev; |
---|
| 624 | + |
---|
| 625 | + hid_set_drvdata(hdev, djrcv_dev); |
---|
| 626 | +out: |
---|
| 627 | + mutex_unlock(&dj_hdev_list_lock); |
---|
| 628 | + return djrcv_dev; |
---|
| 629 | +} |
---|
344 | 630 | |
---|
345 | 631 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, |
---|
346 | | - struct dj_report *dj_report) |
---|
| 632 | + struct dj_workitem *workitem) |
---|
347 | 633 | { |
---|
348 | 634 | /* Called in delayed work context */ |
---|
349 | 635 | struct dj_device *dj_dev; |
---|
350 | 636 | unsigned long flags; |
---|
351 | 637 | |
---|
352 | 638 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
353 | | - dj_dev = djrcv_dev->paired_dj_devices[dj_report->device_index]; |
---|
354 | | - djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL; |
---|
| 639 | + dj_dev = djrcv_dev->paired_dj_devices[workitem->device_index]; |
---|
| 640 | + djrcv_dev->paired_dj_devices[workitem->device_index] = NULL; |
---|
355 | 641 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
356 | 642 | |
---|
357 | 643 | if (dj_dev != NULL) { |
---|
358 | 644 | hid_destroy_device(dj_dev->hdev); |
---|
359 | 645 | kfree(dj_dev); |
---|
360 | 646 | } else { |
---|
361 | | - dev_err(&djrcv_dev->hdev->dev, "%s: can't destroy a NULL device\n", |
---|
| 647 | + hid_err(djrcv_dev->hidpp, "%s: can't destroy a NULL device\n", |
---|
362 | 648 | __func__); |
---|
363 | 649 | } |
---|
364 | 650 | } |
---|
365 | 651 | |
---|
366 | 652 | static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, |
---|
367 | | - struct dj_report *dj_report) |
---|
| 653 | + struct dj_workitem *workitem) |
---|
368 | 654 | { |
---|
369 | 655 | /* Called in delayed work context */ |
---|
370 | | - struct hid_device *djrcv_hdev = djrcv_dev->hdev; |
---|
371 | | - struct usb_interface *intf = to_usb_interface(djrcv_hdev->dev.parent); |
---|
372 | | - struct usb_device *usbdev = interface_to_usbdev(intf); |
---|
| 656 | + struct hid_device *djrcv_hdev = djrcv_dev->hidpp; |
---|
373 | 657 | struct hid_device *dj_hiddev; |
---|
374 | 658 | struct dj_device *dj_dev; |
---|
| 659 | + u8 device_index = workitem->device_index; |
---|
| 660 | + unsigned long flags; |
---|
375 | 661 | |
---|
376 | 662 | /* Device index goes from 1 to 6, we need 3 bytes to store the |
---|
377 | 663 | * semicolon, the index, and a null terminator |
---|
378 | 664 | */ |
---|
379 | 665 | unsigned char tmpstr[3]; |
---|
380 | 666 | |
---|
381 | | - if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & |
---|
382 | | - SPFUNCTION_DEVICE_LIST_EMPTY) { |
---|
383 | | - dbg_hid("%s: device list is empty\n", __func__); |
---|
384 | | - djrcv_dev->querying_devices = false; |
---|
385 | | - return; |
---|
386 | | - } |
---|
387 | | - |
---|
388 | | - if (djrcv_dev->paired_dj_devices[dj_report->device_index]) { |
---|
| 667 | + /* We are the only one ever adding a device, no need to lock */ |
---|
| 668 | + if (djrcv_dev->paired_dj_devices[device_index]) { |
---|
389 | 669 | /* The device is already known. No need to reallocate it. */ |
---|
390 | 670 | dbg_hid("%s: device is already known\n", __func__); |
---|
391 | 671 | return; |
---|
.. | .. |
---|
393 | 673 | |
---|
394 | 674 | dj_hiddev = hid_allocate_device(); |
---|
395 | 675 | if (IS_ERR(dj_hiddev)) { |
---|
396 | | - dev_err(&djrcv_hdev->dev, "%s: hid_allocate_device failed\n", |
---|
397 | | - __func__); |
---|
| 676 | + hid_err(djrcv_hdev, "%s: hid_allocate_dev failed\n", __func__); |
---|
398 | 677 | return; |
---|
399 | 678 | } |
---|
400 | 679 | |
---|
.. | .. |
---|
402 | 681 | |
---|
403 | 682 | dj_hiddev->dev.parent = &djrcv_hdev->dev; |
---|
404 | 683 | dj_hiddev->bus = BUS_USB; |
---|
405 | | - dj_hiddev->vendor = le16_to_cpu(usbdev->descriptor.idVendor); |
---|
406 | | - dj_hiddev->product = |
---|
407 | | - (dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB] |
---|
408 | | - << 8) | |
---|
409 | | - dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB]; |
---|
410 | | - snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), |
---|
411 | | - "Logitech Unifying Device. Wireless PID:%04x", |
---|
412 | | - dj_hiddev->product); |
---|
| 684 | + dj_hiddev->vendor = djrcv_hdev->vendor; |
---|
| 685 | + dj_hiddev->product = (workitem->quad_id_msb << 8) | |
---|
| 686 | + workitem->quad_id_lsb; |
---|
| 687 | + if (workitem->device_type) { |
---|
| 688 | + const char *type_str = "Device"; |
---|
413 | 689 | |
---|
414 | | - dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE; |
---|
| 690 | + switch (workitem->device_type) { |
---|
| 691 | + case 0x01: type_str = "Keyboard"; break; |
---|
| 692 | + case 0x02: type_str = "Mouse"; break; |
---|
| 693 | + case 0x03: type_str = "Numpad"; break; |
---|
| 694 | + case 0x04: type_str = "Presenter"; break; |
---|
| 695 | + case 0x07: type_str = "Remote Control"; break; |
---|
| 696 | + case 0x08: type_str = "Trackball"; break; |
---|
| 697 | + case 0x09: type_str = "Touchpad"; break; |
---|
| 698 | + } |
---|
| 699 | + snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), |
---|
| 700 | + "Logitech Wireless %s PID:%04x", |
---|
| 701 | + type_str, dj_hiddev->product); |
---|
| 702 | + } else { |
---|
| 703 | + snprintf(dj_hiddev->name, sizeof(dj_hiddev->name), |
---|
| 704 | + "Logitech Wireless Device PID:%04x", |
---|
| 705 | + dj_hiddev->product); |
---|
| 706 | + } |
---|
415 | 707 | |
---|
416 | | - usb_make_path(usbdev, dj_hiddev->phys, sizeof(dj_hiddev->phys)); |
---|
417 | | - snprintf(tmpstr, sizeof(tmpstr), ":%d", dj_report->device_index); |
---|
| 708 | + if (djrcv_dev->type == recvr_type_27mhz) |
---|
| 709 | + dj_hiddev->group = HID_GROUP_LOGITECH_27MHZ_DEVICE; |
---|
| 710 | + else |
---|
| 711 | + dj_hiddev->group = HID_GROUP_LOGITECH_DJ_DEVICE; |
---|
| 712 | + |
---|
| 713 | + memcpy(dj_hiddev->phys, djrcv_hdev->phys, sizeof(djrcv_hdev->phys)); |
---|
| 714 | + snprintf(tmpstr, sizeof(tmpstr), ":%d", device_index); |
---|
418 | 715 | strlcat(dj_hiddev->phys, tmpstr, sizeof(dj_hiddev->phys)); |
---|
419 | 716 | |
---|
420 | 717 | dj_dev = kzalloc(sizeof(struct dj_device), GFP_KERNEL); |
---|
421 | 718 | |
---|
422 | 719 | if (!dj_dev) { |
---|
423 | | - dev_err(&djrcv_hdev->dev, "%s: failed allocating dj_device\n", |
---|
424 | | - __func__); |
---|
| 720 | + hid_err(djrcv_hdev, "%s: failed allocating dj_dev\n", __func__); |
---|
425 | 721 | goto dj_device_allocate_fail; |
---|
426 | 722 | } |
---|
427 | 723 | |
---|
428 | | - dj_dev->reports_supported = get_unaligned_le32( |
---|
429 | | - dj_report->report_params + DEVICE_PAIRED_RF_REPORT_TYPE); |
---|
| 724 | + dj_dev->reports_supported = workitem->reports_supported; |
---|
430 | 725 | dj_dev->hdev = dj_hiddev; |
---|
431 | 726 | dj_dev->dj_receiver_dev = djrcv_dev; |
---|
432 | | - dj_dev->device_index = dj_report->device_index; |
---|
| 727 | + dj_dev->device_index = device_index; |
---|
433 | 728 | dj_hiddev->driver_data = dj_dev; |
---|
434 | 729 | |
---|
435 | | - djrcv_dev->paired_dj_devices[dj_report->device_index] = dj_dev; |
---|
| 730 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
| 731 | + djrcv_dev->paired_dj_devices[device_index] = dj_dev; |
---|
| 732 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
436 | 733 | |
---|
437 | 734 | if (hid_add_device(dj_hiddev)) { |
---|
438 | | - dev_err(&djrcv_hdev->dev, "%s: failed adding dj_device\n", |
---|
439 | | - __func__); |
---|
| 735 | + hid_err(djrcv_hdev, "%s: failed adding dj_device\n", __func__); |
---|
440 | 736 | goto hid_add_device_fail; |
---|
441 | 737 | } |
---|
442 | 738 | |
---|
443 | 739 | return; |
---|
444 | 740 | |
---|
445 | 741 | hid_add_device_fail: |
---|
446 | | - djrcv_dev->paired_dj_devices[dj_report->device_index] = NULL; |
---|
| 742 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
| 743 | + djrcv_dev->paired_dj_devices[device_index] = NULL; |
---|
| 744 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
447 | 745 | kfree(dj_dev); |
---|
448 | 746 | dj_device_allocate_fail: |
---|
449 | 747 | hid_destroy_device(dj_hiddev); |
---|
.. | .. |
---|
454 | 752 | struct dj_receiver_dev *djrcv_dev = |
---|
455 | 753 | container_of(work, struct dj_receiver_dev, work); |
---|
456 | 754 | |
---|
457 | | - struct dj_report dj_report; |
---|
| 755 | + struct dj_workitem workitem; |
---|
458 | 756 | unsigned long flags; |
---|
459 | 757 | int count; |
---|
460 | 758 | int retval; |
---|
.. | .. |
---|
463 | 761 | |
---|
464 | 762 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
465 | 763 | |
---|
466 | | - count = kfifo_out(&djrcv_dev->notif_fifo, &dj_report, |
---|
467 | | - sizeof(struct dj_report)); |
---|
468 | | - |
---|
469 | | - if (count != sizeof(struct dj_report)) { |
---|
470 | | - dev_err(&djrcv_dev->hdev->dev, "%s: workitem triggered without " |
---|
471 | | - "notifications available\n", __func__); |
---|
| 764 | + /* |
---|
| 765 | + * Since we attach to multiple interfaces, we may get scheduled before |
---|
| 766 | + * we are bound to the HID++ interface, catch this. |
---|
| 767 | + */ |
---|
| 768 | + if (!djrcv_dev->ready) { |
---|
| 769 | + pr_warn("%s: delayedwork queued before hidpp interface was enumerated\n", |
---|
| 770 | + __func__); |
---|
472 | 771 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
473 | 772 | return; |
---|
474 | 773 | } |
---|
475 | 774 | |
---|
476 | | - if (!kfifo_is_empty(&djrcv_dev->notif_fifo)) { |
---|
477 | | - if (schedule_work(&djrcv_dev->work) == 0) { |
---|
478 | | - dbg_hid("%s: did not schedule the work item, was " |
---|
479 | | - "already queued\n", __func__); |
---|
480 | | - } |
---|
| 775 | + count = kfifo_out(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
---|
| 776 | + |
---|
| 777 | + if (count != sizeof(workitem)) { |
---|
| 778 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
| 779 | + return; |
---|
481 | 780 | } |
---|
| 781 | + |
---|
| 782 | + if (!kfifo_is_empty(&djrcv_dev->notif_fifo)) |
---|
| 783 | + schedule_work(&djrcv_dev->work); |
---|
482 | 784 | |
---|
483 | 785 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
484 | 786 | |
---|
485 | | - switch (dj_report.report_type) { |
---|
486 | | - case REPORT_TYPE_NOTIF_DEVICE_PAIRED: |
---|
487 | | - logi_dj_recv_add_djhid_device(djrcv_dev, &dj_report); |
---|
| 787 | + switch (workitem.type) { |
---|
| 788 | + case WORKITEM_TYPE_PAIRED: |
---|
| 789 | + logi_dj_recv_add_djhid_device(djrcv_dev, &workitem); |
---|
488 | 790 | break; |
---|
489 | | - case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: |
---|
490 | | - logi_dj_recv_destroy_djhid_device(djrcv_dev, &dj_report); |
---|
| 791 | + case WORKITEM_TYPE_UNPAIRED: |
---|
| 792 | + logi_dj_recv_destroy_djhid_device(djrcv_dev, &workitem); |
---|
491 | 793 | break; |
---|
492 | | - default: |
---|
493 | | - /* A normal report (i. e. not belonging to a pair/unpair notification) |
---|
494 | | - * arriving here, means that the report arrived but we did not have a |
---|
495 | | - * paired dj_device associated to the report's device_index, this |
---|
496 | | - * means that the original "device paired" notification corresponding |
---|
497 | | - * to this dj_device never arrived to this driver. The reason is that |
---|
498 | | - * hid-core discards all packets coming from a device while probe() is |
---|
499 | | - * executing. */ |
---|
500 | | - if (!djrcv_dev->paired_dj_devices[dj_report.device_index]) { |
---|
501 | | - /* ok, we don't know the device, just re-ask the |
---|
502 | | - * receiver for the list of connected devices. */ |
---|
| 794 | + case WORKITEM_TYPE_UNKNOWN: |
---|
503 | 795 | retval = logi_dj_recv_query_paired_devices(djrcv_dev); |
---|
504 | | - if (!retval) { |
---|
505 | | - /* everything went fine, so just leave */ |
---|
506 | | - break; |
---|
| 796 | + if (retval) { |
---|
| 797 | + hid_err(djrcv_dev->hidpp, "%s: logi_dj_recv_query_paired_devices error: %d\n", |
---|
| 798 | + __func__, retval); |
---|
507 | 799 | } |
---|
508 | | - dev_err(&djrcv_dev->hdev->dev, |
---|
509 | | - "%s:logi_dj_recv_query_paired_devices " |
---|
510 | | - "error:%d\n", __func__, retval); |
---|
511 | | - } |
---|
512 | | - dbg_hid("%s: unexpected report type\n", __func__); |
---|
| 800 | + break; |
---|
| 801 | + case WORKITEM_TYPE_EMPTY: |
---|
| 802 | + dbg_hid("%s: device list is empty\n", __func__); |
---|
| 803 | + break; |
---|
513 | 804 | } |
---|
| 805 | +} |
---|
| 806 | + |
---|
| 807 | +/* |
---|
| 808 | + * Sometimes we receive reports for which we do not have a paired dj_device |
---|
| 809 | + * associated with the device_index or report-type to forward the report to. |
---|
| 810 | + * This means that the original "device paired" notification corresponding |
---|
| 811 | + * to the dj_device never arrived to this driver. Possible reasons for this are: |
---|
| 812 | + * 1) hid-core discards all packets coming from a device during probe(). |
---|
| 813 | + * 2) if the receiver is plugged into a KVM switch then the pairing reports |
---|
| 814 | + * are only forwarded to it if the focus is on this PC. |
---|
| 815 | + * This function deals with this by re-asking the receiver for the list of |
---|
| 816 | + * connected devices in the delayed work callback. |
---|
| 817 | + * This function MUST be called with djrcv->lock held. |
---|
| 818 | + */ |
---|
| 819 | +static void logi_dj_recv_queue_unknown_work(struct dj_receiver_dev *djrcv_dev) |
---|
| 820 | +{ |
---|
| 821 | + struct dj_workitem workitem = { .type = WORKITEM_TYPE_UNKNOWN }; |
---|
| 822 | + |
---|
| 823 | + /* Rate limit queries done because of unhandled reports to 2/sec */ |
---|
| 824 | + if (time_before(jiffies, djrcv_dev->last_query + HZ / 2)) |
---|
| 825 | + return; |
---|
| 826 | + |
---|
| 827 | + kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
---|
| 828 | + schedule_work(&djrcv_dev->work); |
---|
514 | 829 | } |
---|
515 | 830 | |
---|
516 | 831 | static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev, |
---|
517 | 832 | struct dj_report *dj_report) |
---|
518 | 833 | { |
---|
519 | 834 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
---|
| 835 | + struct dj_workitem workitem = { |
---|
| 836 | + .device_index = dj_report->device_index, |
---|
| 837 | + }; |
---|
520 | 838 | |
---|
521 | | - kfifo_in(&djrcv_dev->notif_fifo, dj_report, sizeof(struct dj_report)); |
---|
522 | | - |
---|
523 | | - if (schedule_work(&djrcv_dev->work) == 0) { |
---|
524 | | - dbg_hid("%s: did not schedule the work item, was already " |
---|
525 | | - "queued\n", __func__); |
---|
| 839 | + switch (dj_report->report_type) { |
---|
| 840 | + case REPORT_TYPE_NOTIF_DEVICE_PAIRED: |
---|
| 841 | + workitem.type = WORKITEM_TYPE_PAIRED; |
---|
| 842 | + if (dj_report->report_params[DEVICE_PAIRED_PARAM_SPFUNCTION] & |
---|
| 843 | + SPFUNCTION_DEVICE_LIST_EMPTY) { |
---|
| 844 | + workitem.type = WORKITEM_TYPE_EMPTY; |
---|
| 845 | + break; |
---|
| 846 | + } |
---|
| 847 | + fallthrough; |
---|
| 848 | + case REPORT_TYPE_NOTIF_DEVICE_UNPAIRED: |
---|
| 849 | + workitem.quad_id_msb = |
---|
| 850 | + dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_MSB]; |
---|
| 851 | + workitem.quad_id_lsb = |
---|
| 852 | + dj_report->report_params[DEVICE_PAIRED_PARAM_EQUAD_ID_LSB]; |
---|
| 853 | + workitem.reports_supported = get_unaligned_le32( |
---|
| 854 | + dj_report->report_params + |
---|
| 855 | + DEVICE_PAIRED_RF_REPORT_TYPE); |
---|
| 856 | + workitem.reports_supported |= HIDPP; |
---|
| 857 | + if (dj_report->report_type == REPORT_TYPE_NOTIF_DEVICE_UNPAIRED) |
---|
| 858 | + workitem.type = WORKITEM_TYPE_UNPAIRED; |
---|
| 859 | + break; |
---|
| 860 | + default: |
---|
| 861 | + logi_dj_recv_queue_unknown_work(djrcv_dev); |
---|
| 862 | + return; |
---|
526 | 863 | } |
---|
| 864 | + |
---|
| 865 | + kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
---|
| 866 | + schedule_work(&djrcv_dev->work); |
---|
| 867 | +} |
---|
| 868 | + |
---|
| 869 | +/* |
---|
| 870 | + * Some quad/bluetooth keyboards have a builtin touchpad in this case we see |
---|
| 871 | + * only 1 paired device with a device_type of REPORT_TYPE_KEYBOARD. For the |
---|
| 872 | + * touchpad to work we must also forward mouse input reports to the dj_hiddev |
---|
| 873 | + * created for the keyboard (instead of forwarding them to a second paired |
---|
| 874 | + * device with a device_type of REPORT_TYPE_MOUSE as we normally would). |
---|
| 875 | + */ |
---|
| 876 | +static const u16 kbd_builtin_touchpad_ids[] = { |
---|
| 877 | + 0xb309, /* Dinovo Edge */ |
---|
| 878 | + 0xb30c, /* Dinovo Mini */ |
---|
| 879 | +}; |
---|
| 880 | + |
---|
| 881 | +static void logi_hidpp_dev_conn_notif_equad(struct hid_device *hdev, |
---|
| 882 | + struct hidpp_event *hidpp_report, |
---|
| 883 | + struct dj_workitem *workitem) |
---|
| 884 | +{ |
---|
| 885 | + struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
| 886 | + int i, id; |
---|
| 887 | + |
---|
| 888 | + workitem->type = WORKITEM_TYPE_PAIRED; |
---|
| 889 | + workitem->device_type = hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & |
---|
| 890 | + HIDPP_DEVICE_TYPE_MASK; |
---|
| 891 | + workitem->quad_id_msb = hidpp_report->params[HIDPP_PARAM_EQUAD_MSB]; |
---|
| 892 | + workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_EQUAD_LSB]; |
---|
| 893 | + switch (workitem->device_type) { |
---|
| 894 | + case REPORT_TYPE_KEYBOARD: |
---|
| 895 | + workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA | |
---|
| 896 | + POWER_KEYS | MEDIA_CENTER | |
---|
| 897 | + HIDPP; |
---|
| 898 | + id = (workitem->quad_id_msb << 8) | workitem->quad_id_lsb; |
---|
| 899 | + for (i = 0; i < ARRAY_SIZE(kbd_builtin_touchpad_ids); i++) { |
---|
| 900 | + if (id == kbd_builtin_touchpad_ids[i]) { |
---|
| 901 | + workitem->reports_supported |= STD_MOUSE; |
---|
| 902 | + break; |
---|
| 903 | + } |
---|
| 904 | + } |
---|
| 905 | + break; |
---|
| 906 | + case REPORT_TYPE_MOUSE: |
---|
| 907 | + workitem->reports_supported |= STD_MOUSE | HIDPP; |
---|
| 908 | + if (djrcv_dev->type == recvr_type_mouse_only) |
---|
| 909 | + workitem->reports_supported |= MULTIMEDIA; |
---|
| 910 | + break; |
---|
| 911 | + } |
---|
| 912 | +} |
---|
| 913 | + |
---|
| 914 | +static void logi_hidpp_dev_conn_notif_27mhz(struct hid_device *hdev, |
---|
| 915 | + struct hidpp_event *hidpp_report, |
---|
| 916 | + struct dj_workitem *workitem) |
---|
| 917 | +{ |
---|
| 918 | + workitem->type = WORKITEM_TYPE_PAIRED; |
---|
| 919 | + workitem->quad_id_lsb = hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID]; |
---|
| 920 | + switch (hidpp_report->device_index) { |
---|
| 921 | + case 1: /* Index 1 is always a mouse */ |
---|
| 922 | + case 2: /* Index 2 is always a mouse */ |
---|
| 923 | + workitem->device_type = HIDPP_DEVICE_TYPE_MOUSE; |
---|
| 924 | + workitem->reports_supported |= STD_MOUSE | HIDPP; |
---|
| 925 | + break; |
---|
| 926 | + case 3: /* Index 3 is always the keyboard */ |
---|
| 927 | + case 4: /* Index 4 is used for an optional separate numpad */ |
---|
| 928 | + workitem->device_type = HIDPP_DEVICE_TYPE_KEYBOARD; |
---|
| 929 | + workitem->reports_supported |= STD_KEYBOARD | MULTIMEDIA | |
---|
| 930 | + POWER_KEYS | HIDPP; |
---|
| 931 | + break; |
---|
| 932 | + default: |
---|
| 933 | + hid_warn(hdev, "%s: unexpected device-index %d", __func__, |
---|
| 934 | + hidpp_report->device_index); |
---|
| 935 | + } |
---|
| 936 | +} |
---|
| 937 | + |
---|
| 938 | +static void logi_hidpp_recv_queue_notif(struct hid_device *hdev, |
---|
| 939 | + struct hidpp_event *hidpp_report) |
---|
| 940 | +{ |
---|
| 941 | + /* We are called from atomic context (tasklet && djrcv->lock held) */ |
---|
| 942 | + struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
| 943 | + const char *device_type = "UNKNOWN"; |
---|
| 944 | + struct dj_workitem workitem = { |
---|
| 945 | + .type = WORKITEM_TYPE_EMPTY, |
---|
| 946 | + .device_index = hidpp_report->device_index, |
---|
| 947 | + }; |
---|
| 948 | + |
---|
| 949 | + switch (hidpp_report->params[HIDPP_PARAM_PROTO_TYPE]) { |
---|
| 950 | + case 0x01: |
---|
| 951 | + device_type = "Bluetooth"; |
---|
| 952 | + /* Bluetooth connect packet contents is the same as (e)QUAD */ |
---|
| 953 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 954 | + if (!(hidpp_report->params[HIDPP_PARAM_DEVICE_INFO] & |
---|
| 955 | + HIDPP_MANUFACTURER_MASK)) { |
---|
| 956 | + hid_info(hdev, "Non Logitech device connected on slot %d\n", |
---|
| 957 | + hidpp_report->device_index); |
---|
| 958 | + workitem.reports_supported &= ~HIDPP; |
---|
| 959 | + } |
---|
| 960 | + break; |
---|
| 961 | + case 0x02: |
---|
| 962 | + device_type = "27 Mhz"; |
---|
| 963 | + logi_hidpp_dev_conn_notif_27mhz(hdev, hidpp_report, &workitem); |
---|
| 964 | + break; |
---|
| 965 | + case 0x03: |
---|
| 966 | + device_type = "QUAD or eQUAD"; |
---|
| 967 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 968 | + break; |
---|
| 969 | + case 0x04: |
---|
| 970 | + device_type = "eQUAD step 4 DJ"; |
---|
| 971 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 972 | + break; |
---|
| 973 | + case 0x05: |
---|
| 974 | + device_type = "DFU Lite"; |
---|
| 975 | + break; |
---|
| 976 | + case 0x06: |
---|
| 977 | + device_type = "eQUAD step 4 Lite"; |
---|
| 978 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 979 | + break; |
---|
| 980 | + case 0x07: |
---|
| 981 | + device_type = "eQUAD step 4 Gaming"; |
---|
| 982 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 983 | + workitem.reports_supported |= STD_KEYBOARD; |
---|
| 984 | + break; |
---|
| 985 | + case 0x08: |
---|
| 986 | + device_type = "eQUAD step 4 for gamepads"; |
---|
| 987 | + break; |
---|
| 988 | + case 0x0a: |
---|
| 989 | + device_type = "eQUAD nano Lite"; |
---|
| 990 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 991 | + break; |
---|
| 992 | + case 0x0c: |
---|
| 993 | + device_type = "eQUAD Lightspeed 1"; |
---|
| 994 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 995 | + workitem.reports_supported |= STD_KEYBOARD; |
---|
| 996 | + break; |
---|
| 997 | + case 0x0d: |
---|
| 998 | + device_type = "eQUAD Lightspeed 1.1"; |
---|
| 999 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 1000 | + workitem.reports_supported |= STD_KEYBOARD; |
---|
| 1001 | + break; |
---|
| 1002 | + case 0x0f: |
---|
| 1003 | + case 0x11: |
---|
| 1004 | + device_type = "eQUAD Lightspeed 1.2"; |
---|
| 1005 | + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); |
---|
| 1006 | + workitem.reports_supported |= STD_KEYBOARD; |
---|
| 1007 | + break; |
---|
| 1008 | + } |
---|
| 1009 | + |
---|
| 1010 | + /* custom receiver device (eg. powerplay) */ |
---|
| 1011 | + if (hidpp_report->device_index == 7) { |
---|
| 1012 | + workitem.reports_supported |= HIDPP; |
---|
| 1013 | + } |
---|
| 1014 | + |
---|
| 1015 | + if (workitem.type == WORKITEM_TYPE_EMPTY) { |
---|
| 1016 | + hid_warn(hdev, |
---|
| 1017 | + "unusable device of type %s (0x%02x) connected on slot %d", |
---|
| 1018 | + device_type, |
---|
| 1019 | + hidpp_report->params[HIDPP_PARAM_PROTO_TYPE], |
---|
| 1020 | + hidpp_report->device_index); |
---|
| 1021 | + return; |
---|
| 1022 | + } |
---|
| 1023 | + |
---|
| 1024 | + hid_info(hdev, "device of type %s (0x%02x) connected on slot %d", |
---|
| 1025 | + device_type, hidpp_report->params[HIDPP_PARAM_PROTO_TYPE], |
---|
| 1026 | + hidpp_report->device_index); |
---|
| 1027 | + |
---|
| 1028 | + kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
---|
| 1029 | + schedule_work(&djrcv_dev->work); |
---|
527 | 1030 | } |
---|
528 | 1031 | |
---|
529 | 1032 | static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, |
---|
.. | .. |
---|
552 | 1055 | } |
---|
553 | 1056 | } |
---|
554 | 1057 | |
---|
555 | | -static void logi_dj_recv_forward_report(struct dj_receiver_dev *djrcv_dev, |
---|
556 | | - struct dj_report *dj_report) |
---|
| 1058 | +static void logi_dj_recv_forward_dj(struct dj_receiver_dev *djrcv_dev, |
---|
| 1059 | + struct dj_report *dj_report) |
---|
557 | 1060 | { |
---|
558 | 1061 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
---|
559 | 1062 | struct dj_device *dj_device; |
---|
.. | .. |
---|
573 | 1076 | } |
---|
574 | 1077 | } |
---|
575 | 1078 | |
---|
576 | | -static void logi_dj_recv_forward_hidpp(struct dj_device *dj_dev, u8 *data, |
---|
577 | | - int size) |
---|
| 1079 | +static void logi_dj_recv_forward_report(struct dj_device *dj_dev, u8 *data, |
---|
| 1080 | + int size) |
---|
578 | 1081 | { |
---|
579 | 1082 | /* We are called from atomic context (tasklet && djrcv->lock held) */ |
---|
580 | 1083 | if (hid_input_report(dj_dev->hdev, HID_INPUT_REPORT, data, size, 1)) |
---|
581 | 1084 | dbg_hid("hid_input_report error\n"); |
---|
582 | 1085 | } |
---|
583 | 1086 | |
---|
| 1087 | +static void logi_dj_recv_forward_input_report(struct hid_device *hdev, |
---|
| 1088 | + u8 *data, int size) |
---|
| 1089 | +{ |
---|
| 1090 | + struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
| 1091 | + struct dj_device *dj_dev; |
---|
| 1092 | + unsigned long flags; |
---|
| 1093 | + u8 report = data[0]; |
---|
| 1094 | + int i; |
---|
| 1095 | + |
---|
| 1096 | + if (report > REPORT_TYPE_RFREPORT_LAST) { |
---|
| 1097 | + hid_err(hdev, "Unexpected input report number %d\n", report); |
---|
| 1098 | + return; |
---|
| 1099 | + } |
---|
| 1100 | + |
---|
| 1101 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
| 1102 | + for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) { |
---|
| 1103 | + dj_dev = djrcv_dev->paired_dj_devices[i]; |
---|
| 1104 | + if (dj_dev && (dj_dev->reports_supported & BIT(report))) { |
---|
| 1105 | + logi_dj_recv_forward_report(dj_dev, data, size); |
---|
| 1106 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
| 1107 | + return; |
---|
| 1108 | + } |
---|
| 1109 | + } |
---|
| 1110 | + |
---|
| 1111 | + logi_dj_recv_queue_unknown_work(djrcv_dev); |
---|
| 1112 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
| 1113 | + |
---|
| 1114 | + dbg_hid("No dj-devs handling input report number %d\n", report); |
---|
| 1115 | +} |
---|
| 1116 | + |
---|
584 | 1117 | static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev, |
---|
585 | 1118 | struct dj_report *dj_report) |
---|
586 | 1119 | { |
---|
587 | | - struct hid_device *hdev = djrcv_dev->hdev; |
---|
| 1120 | + struct hid_device *hdev = djrcv_dev->hidpp; |
---|
588 | 1121 | struct hid_report *report; |
---|
589 | 1122 | struct hid_report_enum *output_report_enum; |
---|
590 | 1123 | u8 *data = (u8 *)(&dj_report->device_index); |
---|
.. | .. |
---|
594 | 1127 | report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT]; |
---|
595 | 1128 | |
---|
596 | 1129 | if (!report) { |
---|
597 | | - dev_err(&hdev->dev, "%s: unable to find dj report\n", __func__); |
---|
| 1130 | + hid_err(hdev, "%s: unable to find dj report\n", __func__); |
---|
598 | 1131 | return -ENODEV; |
---|
599 | 1132 | } |
---|
600 | 1133 | |
---|
.. | .. |
---|
606 | 1139 | return 0; |
---|
607 | 1140 | } |
---|
608 | 1141 | |
---|
| 1142 | +static int logi_dj_recv_query_hidpp_devices(struct dj_receiver_dev *djrcv_dev) |
---|
| 1143 | +{ |
---|
| 1144 | + static const u8 template[] = { |
---|
| 1145 | + REPORT_ID_HIDPP_SHORT, |
---|
| 1146 | + HIDPP_RECEIVER_INDEX, |
---|
| 1147 | + HIDPP_SET_REGISTER, |
---|
| 1148 | + HIDPP_REG_CONNECTION_STATE, |
---|
| 1149 | + HIDPP_FAKE_DEVICE_ARRIVAL, |
---|
| 1150 | + 0x00, 0x00 |
---|
| 1151 | + }; |
---|
| 1152 | + u8 *hidpp_report; |
---|
| 1153 | + int retval; |
---|
| 1154 | + |
---|
| 1155 | + hidpp_report = kmemdup(template, sizeof(template), GFP_KERNEL); |
---|
| 1156 | + if (!hidpp_report) |
---|
| 1157 | + return -ENOMEM; |
---|
| 1158 | + |
---|
| 1159 | + retval = hid_hw_raw_request(djrcv_dev->hidpp, |
---|
| 1160 | + REPORT_ID_HIDPP_SHORT, |
---|
| 1161 | + hidpp_report, sizeof(template), |
---|
| 1162 | + HID_OUTPUT_REPORT, |
---|
| 1163 | + HID_REQ_SET_REPORT); |
---|
| 1164 | + |
---|
| 1165 | + kfree(hidpp_report); |
---|
| 1166 | + return (retval < 0) ? retval : 0; |
---|
| 1167 | +} |
---|
| 1168 | + |
---|
609 | 1169 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev) |
---|
610 | 1170 | { |
---|
611 | 1171 | struct dj_report *dj_report; |
---|
612 | 1172 | int retval; |
---|
613 | 1173 | |
---|
614 | | - /* no need to protect djrcv_dev->querying_devices */ |
---|
615 | | - if (djrcv_dev->querying_devices) |
---|
616 | | - return 0; |
---|
| 1174 | + djrcv_dev->last_query = jiffies; |
---|
| 1175 | + |
---|
| 1176 | + if (djrcv_dev->type != recvr_type_dj) |
---|
| 1177 | + return logi_dj_recv_query_hidpp_devices(djrcv_dev); |
---|
617 | 1178 | |
---|
618 | 1179 | dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); |
---|
619 | 1180 | if (!dj_report) |
---|
620 | 1181 | return -ENOMEM; |
---|
621 | 1182 | dj_report->report_id = REPORT_ID_DJ_SHORT; |
---|
622 | | - dj_report->device_index = 0xFF; |
---|
| 1183 | + dj_report->device_index = HIDPP_RECEIVER_INDEX; |
---|
623 | 1184 | dj_report->report_type = REPORT_TYPE_CMD_GET_PAIRED_DEVICES; |
---|
624 | 1185 | retval = logi_dj_recv_send_report(djrcv_dev, dj_report); |
---|
625 | 1186 | kfree(dj_report); |
---|
.. | .. |
---|
630 | 1191 | static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, |
---|
631 | 1192 | unsigned timeout) |
---|
632 | 1193 | { |
---|
633 | | - struct hid_device *hdev = djrcv_dev->hdev; |
---|
| 1194 | + struct hid_device *hdev = djrcv_dev->hidpp; |
---|
634 | 1195 | struct dj_report *dj_report; |
---|
635 | 1196 | u8 *buf; |
---|
636 | | - int retval; |
---|
| 1197 | + int retval = 0; |
---|
637 | 1198 | |
---|
638 | 1199 | dj_report = kzalloc(sizeof(struct dj_report), GFP_KERNEL); |
---|
639 | 1200 | if (!dj_report) |
---|
640 | 1201 | return -ENOMEM; |
---|
641 | | - dj_report->report_id = REPORT_ID_DJ_SHORT; |
---|
642 | | - dj_report->device_index = 0xFF; |
---|
643 | | - dj_report->report_type = REPORT_TYPE_CMD_SWITCH; |
---|
644 | | - dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F; |
---|
645 | | - dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] = (u8)timeout; |
---|
646 | | - retval = logi_dj_recv_send_report(djrcv_dev, dj_report); |
---|
647 | 1202 | |
---|
648 | | - /* |
---|
649 | | - * Ugly sleep to work around a USB 3.0 bug when the receiver is still |
---|
650 | | - * processing the "switch-to-dj" command while we send an other command. |
---|
651 | | - * 50 msec should gives enough time to the receiver to be ready. |
---|
652 | | - */ |
---|
653 | | - msleep(50); |
---|
| 1203 | + if (djrcv_dev->type == recvr_type_dj) { |
---|
| 1204 | + dj_report->report_id = REPORT_ID_DJ_SHORT; |
---|
| 1205 | + dj_report->device_index = HIDPP_RECEIVER_INDEX; |
---|
| 1206 | + dj_report->report_type = REPORT_TYPE_CMD_SWITCH; |
---|
| 1207 | + dj_report->report_params[CMD_SWITCH_PARAM_DEVBITFIELD] = 0x3F; |
---|
| 1208 | + dj_report->report_params[CMD_SWITCH_PARAM_TIMEOUT_SECONDS] = |
---|
| 1209 | + (u8)timeout; |
---|
| 1210 | + |
---|
| 1211 | + retval = logi_dj_recv_send_report(djrcv_dev, dj_report); |
---|
| 1212 | + |
---|
| 1213 | + /* |
---|
| 1214 | + * Ugly sleep to work around a USB 3.0 bug when the receiver is |
---|
| 1215 | + * still processing the "switch-to-dj" command while we send an |
---|
| 1216 | + * other command. |
---|
| 1217 | + * 50 msec should gives enough time to the receiver to be ready. |
---|
| 1218 | + */ |
---|
| 1219 | + msleep(50); |
---|
| 1220 | + } |
---|
654 | 1221 | |
---|
655 | 1222 | /* |
---|
656 | 1223 | * Magical bits to set up hidpp notifications when the dj devices |
---|
.. | .. |
---|
664 | 1231 | memset(buf, 0, HIDPP_REPORT_SHORT_LENGTH); |
---|
665 | 1232 | |
---|
666 | 1233 | buf[0] = REPORT_ID_HIDPP_SHORT; |
---|
667 | | - buf[1] = 0xFF; |
---|
| 1234 | + buf[1] = HIDPP_RECEIVER_INDEX; |
---|
668 | 1235 | buf[2] = 0x80; |
---|
669 | 1236 | buf[3] = 0x00; |
---|
670 | 1237 | buf[4] = 0x00; |
---|
.. | .. |
---|
682 | 1249 | |
---|
683 | 1250 | static int logi_dj_ll_open(struct hid_device *hid) |
---|
684 | 1251 | { |
---|
685 | | - dbg_hid("%s:%s\n", __func__, hid->phys); |
---|
| 1252 | + dbg_hid("%s: %s\n", __func__, hid->phys); |
---|
686 | 1253 | return 0; |
---|
687 | 1254 | |
---|
688 | 1255 | } |
---|
689 | 1256 | |
---|
690 | 1257 | static void logi_dj_ll_close(struct hid_device *hid) |
---|
691 | 1258 | { |
---|
692 | | - dbg_hid("%s:%s\n", __func__, hid->phys); |
---|
| 1259 | + dbg_hid("%s: %s\n", __func__, hid->phys); |
---|
693 | 1260 | } |
---|
694 | 1261 | |
---|
695 | 1262 | /* |
---|
696 | 1263 | * Register 0xB5 is "pairing information". It is solely intended for the |
---|
697 | 1264 | * receiver, so do not overwrite the device index. |
---|
698 | 1265 | */ |
---|
699 | | -static u8 unifying_pairing_query[] = {0x10, 0xff, 0x83, 0xb5}; |
---|
700 | | -static u8 unifying_pairing_answer[] = {0x11, 0xff, 0x83, 0xb5}; |
---|
| 1266 | +static u8 unifying_pairing_query[] = { REPORT_ID_HIDPP_SHORT, |
---|
| 1267 | + HIDPP_RECEIVER_INDEX, |
---|
| 1268 | + HIDPP_GET_LONG_REGISTER, |
---|
| 1269 | + HIDPP_REG_PAIRING_INFORMATION }; |
---|
| 1270 | +static u8 unifying_pairing_answer[] = { REPORT_ID_HIDPP_LONG, |
---|
| 1271 | + HIDPP_RECEIVER_INDEX, |
---|
| 1272 | + HIDPP_GET_LONG_REGISTER, |
---|
| 1273 | + HIDPP_REG_PAIRING_INFORMATION }; |
---|
701 | 1274 | |
---|
702 | 1275 | static int logi_dj_ll_raw_request(struct hid_device *hid, |
---|
703 | 1276 | unsigned char reportnum, __u8 *buf, |
---|
.. | .. |
---|
710 | 1283 | int ret; |
---|
711 | 1284 | |
---|
712 | 1285 | if ((buf[0] == REPORT_ID_HIDPP_SHORT) || |
---|
713 | | - (buf[0] == REPORT_ID_HIDPP_LONG)) { |
---|
| 1286 | + (buf[0] == REPORT_ID_HIDPP_LONG) || |
---|
| 1287 | + (buf[0] == REPORT_ID_HIDPP_VERY_LONG)) { |
---|
714 | 1288 | if (count < 2) |
---|
715 | 1289 | return -EINVAL; |
---|
716 | 1290 | |
---|
.. | .. |
---|
721 | 1295 | buf[4] = (buf[4] & 0xf0) | (djdev->device_index - 1); |
---|
722 | 1296 | else |
---|
723 | 1297 | buf[1] = djdev->device_index; |
---|
724 | | - return hid_hw_raw_request(djrcv_dev->hdev, reportnum, buf, |
---|
| 1298 | + return hid_hw_raw_request(djrcv_dev->hidpp, reportnum, buf, |
---|
725 | 1299 | count, report_type, reqtype); |
---|
726 | 1300 | } |
---|
727 | 1301 | |
---|
728 | 1302 | if (buf[0] != REPORT_TYPE_LEDS) |
---|
729 | 1303 | return -EINVAL; |
---|
| 1304 | + |
---|
| 1305 | + if (djrcv_dev->type != recvr_type_dj && count >= 2) { |
---|
| 1306 | + if (!djrcv_dev->keyboard) { |
---|
| 1307 | + hid_warn(hid, "Received REPORT_TYPE_LEDS request before the keyboard interface was enumerated\n"); |
---|
| 1308 | + return 0; |
---|
| 1309 | + } |
---|
| 1310 | + /* usbhid overrides the report ID and ignores the first byte */ |
---|
| 1311 | + return hid_hw_raw_request(djrcv_dev->keyboard, 0, buf, count, |
---|
| 1312 | + report_type, reqtype); |
---|
| 1313 | + } |
---|
730 | 1314 | |
---|
731 | 1315 | out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC); |
---|
732 | 1316 | if (!out_buf) |
---|
.. | .. |
---|
739 | 1323 | out_buf[1] = djdev->device_index; |
---|
740 | 1324 | memcpy(out_buf + 2, buf, count); |
---|
741 | 1325 | |
---|
742 | | - ret = hid_hw_raw_request(djrcv_dev->hdev, out_buf[0], out_buf, |
---|
| 1326 | + ret = hid_hw_raw_request(djrcv_dev->hidpp, out_buf[0], out_buf, |
---|
743 | 1327 | DJREPORT_SHORT_LENGTH, report_type, reqtype); |
---|
744 | 1328 | |
---|
745 | 1329 | kfree(out_buf); |
---|
.. | .. |
---|
769 | 1353 | return -ENOMEM; |
---|
770 | 1354 | |
---|
771 | 1355 | if (djdev->reports_supported & STD_KEYBOARD) { |
---|
772 | | - dbg_hid("%s: sending a kbd descriptor, reports_supported: %x\n", |
---|
| 1356 | + dbg_hid("%s: sending a kbd descriptor, reports_supported: %llx\n", |
---|
773 | 1357 | __func__, djdev->reports_supported); |
---|
774 | 1358 | rdcat(rdesc, &rsize, kbd_descriptor, sizeof(kbd_descriptor)); |
---|
775 | 1359 | } |
---|
776 | 1360 | |
---|
777 | 1361 | if (djdev->reports_supported & STD_MOUSE) { |
---|
778 | | - dbg_hid("%s: sending a mouse descriptor, reports_supported: " |
---|
779 | | - "%x\n", __func__, djdev->reports_supported); |
---|
780 | | - rdcat(rdesc, &rsize, mse_descriptor, sizeof(mse_descriptor)); |
---|
| 1362 | + dbg_hid("%s: sending a mouse descriptor, reports_supported: %llx\n", |
---|
| 1363 | + __func__, djdev->reports_supported); |
---|
| 1364 | + if (djdev->dj_receiver_dev->type == recvr_type_gaming_hidpp || |
---|
| 1365 | + djdev->dj_receiver_dev->type == recvr_type_mouse_only) |
---|
| 1366 | + rdcat(rdesc, &rsize, mse_high_res_descriptor, |
---|
| 1367 | + sizeof(mse_high_res_descriptor)); |
---|
| 1368 | + else if (djdev->dj_receiver_dev->type == recvr_type_27mhz) |
---|
| 1369 | + rdcat(rdesc, &rsize, mse_27mhz_descriptor, |
---|
| 1370 | + sizeof(mse_27mhz_descriptor)); |
---|
| 1371 | + else if (djdev->dj_receiver_dev->type == recvr_type_bluetooth) |
---|
| 1372 | + rdcat(rdesc, &rsize, mse_bluetooth_descriptor, |
---|
| 1373 | + sizeof(mse_bluetooth_descriptor)); |
---|
| 1374 | + else |
---|
| 1375 | + rdcat(rdesc, &rsize, mse_descriptor, |
---|
| 1376 | + sizeof(mse_descriptor)); |
---|
781 | 1377 | } |
---|
782 | 1378 | |
---|
783 | 1379 | if (djdev->reports_supported & MULTIMEDIA) { |
---|
784 | | - dbg_hid("%s: sending a multimedia report descriptor: %x\n", |
---|
| 1380 | + dbg_hid("%s: sending a multimedia report descriptor: %llx\n", |
---|
785 | 1381 | __func__, djdev->reports_supported); |
---|
786 | 1382 | rdcat(rdesc, &rsize, consumer_descriptor, sizeof(consumer_descriptor)); |
---|
787 | 1383 | } |
---|
788 | 1384 | |
---|
789 | 1385 | if (djdev->reports_supported & POWER_KEYS) { |
---|
790 | | - dbg_hid("%s: sending a power keys report descriptor: %x\n", |
---|
| 1386 | + dbg_hid("%s: sending a power keys report descriptor: %llx\n", |
---|
791 | 1387 | __func__, djdev->reports_supported); |
---|
792 | 1388 | rdcat(rdesc, &rsize, syscontrol_descriptor, sizeof(syscontrol_descriptor)); |
---|
793 | 1389 | } |
---|
794 | 1390 | |
---|
795 | 1391 | if (djdev->reports_supported & MEDIA_CENTER) { |
---|
796 | | - dbg_hid("%s: sending a media center report descriptor: %x\n", |
---|
| 1392 | + dbg_hid("%s: sending a media center report descriptor: %llx\n", |
---|
797 | 1393 | __func__, djdev->reports_supported); |
---|
798 | 1394 | rdcat(rdesc, &rsize, media_descriptor, sizeof(media_descriptor)); |
---|
799 | 1395 | } |
---|
800 | 1396 | |
---|
801 | 1397 | if (djdev->reports_supported & KBD_LEDS) { |
---|
802 | | - dbg_hid("%s: need to send kbd leds report descriptor: %x\n", |
---|
| 1398 | + dbg_hid("%s: need to send kbd leds report descriptor: %llx\n", |
---|
803 | 1399 | __func__, djdev->reports_supported); |
---|
804 | 1400 | } |
---|
805 | 1401 | |
---|
806 | | - rdcat(rdesc, &rsize, hidpp_descriptor, sizeof(hidpp_descriptor)); |
---|
| 1402 | + if (djdev->reports_supported & HIDPP) { |
---|
| 1403 | + dbg_hid("%s: sending a HID++ descriptor, reports_supported: %llx\n", |
---|
| 1404 | + __func__, djdev->reports_supported); |
---|
| 1405 | + rdcat(rdesc, &rsize, hidpp_descriptor, |
---|
| 1406 | + sizeof(hidpp_descriptor)); |
---|
| 1407 | + } |
---|
807 | 1408 | |
---|
808 | 1409 | retval = hid_parse_report(hid, rdesc, rsize); |
---|
809 | 1410 | kfree(rdesc); |
---|
.. | .. |
---|
866 | 1467 | * so ignore those reports too. |
---|
867 | 1468 | */ |
---|
868 | 1469 | if (dj_report->device_index != DJ_RECEIVER_INDEX) |
---|
869 | | - dev_err(&hdev->dev, "%s: invalid device index:%d\n", |
---|
| 1470 | + hid_err(hdev, "%s: invalid device index:%d\n", |
---|
870 | 1471 | __func__, dj_report->device_index); |
---|
871 | 1472 | return false; |
---|
872 | 1473 | } |
---|
.. | .. |
---|
893 | 1494 | } |
---|
894 | 1495 | break; |
---|
895 | 1496 | default: |
---|
896 | | - logi_dj_recv_forward_report(djrcv_dev, dj_report); |
---|
| 1497 | + logi_dj_recv_forward_dj(djrcv_dev, dj_report); |
---|
897 | 1498 | } |
---|
898 | 1499 | |
---|
899 | 1500 | out: |
---|
.. | .. |
---|
907 | 1508 | int size) |
---|
908 | 1509 | { |
---|
909 | 1510 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
910 | | - struct dj_report *dj_report = (struct dj_report *) data; |
---|
| 1511 | + struct hidpp_event *hidpp_report = (struct hidpp_event *) data; |
---|
| 1512 | + struct dj_device *dj_dev; |
---|
911 | 1513 | unsigned long flags; |
---|
912 | | - u8 device_index = dj_report->device_index; |
---|
| 1514 | + u8 device_index = hidpp_report->device_index; |
---|
913 | 1515 | |
---|
914 | 1516 | if (device_index == HIDPP_RECEIVER_INDEX) { |
---|
915 | 1517 | /* special case were the device wants to know its unifying |
---|
.. | .. |
---|
937 | 1539 | * This driver can ignore safely the receiver notifications, |
---|
938 | 1540 | * so ignore those reports too. |
---|
939 | 1541 | */ |
---|
940 | | - dev_err(&hdev->dev, "%s: invalid device index:%d\n", |
---|
941 | | - __func__, dj_report->device_index); |
---|
| 1542 | + hid_err(hdev, "%s: invalid device index:%d\n", __func__, |
---|
| 1543 | + hidpp_report->device_index); |
---|
942 | 1544 | return false; |
---|
943 | 1545 | } |
---|
944 | 1546 | |
---|
945 | 1547 | spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
946 | 1548 | |
---|
947 | | - if (!djrcv_dev->paired_dj_devices[device_index]) |
---|
948 | | - /* received an event for an unknown device, bail out */ |
---|
949 | | - goto out; |
---|
| 1549 | + dj_dev = djrcv_dev->paired_dj_devices[device_index]; |
---|
950 | 1550 | |
---|
951 | | - logi_dj_recv_forward_hidpp(djrcv_dev->paired_dj_devices[device_index], |
---|
952 | | - data, size); |
---|
| 1551 | + /* |
---|
| 1552 | + * With 27 MHz receivers, we do not get an explicit unpair event, |
---|
| 1553 | + * remove the old device if the user has paired a *different* device. |
---|
| 1554 | + */ |
---|
| 1555 | + if (djrcv_dev->type == recvr_type_27mhz && dj_dev && |
---|
| 1556 | + hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED && |
---|
| 1557 | + hidpp_report->params[HIDPP_PARAM_PROTO_TYPE] == 0x02 && |
---|
| 1558 | + hidpp_report->params[HIDPP_PARAM_27MHZ_DEVID] != |
---|
| 1559 | + dj_dev->hdev->product) { |
---|
| 1560 | + struct dj_workitem workitem = { |
---|
| 1561 | + .device_index = hidpp_report->device_index, |
---|
| 1562 | + .type = WORKITEM_TYPE_UNPAIRED, |
---|
| 1563 | + }; |
---|
| 1564 | + kfifo_in(&djrcv_dev->notif_fifo, &workitem, sizeof(workitem)); |
---|
| 1565 | + /* logi_hidpp_recv_queue_notif will queue the work */ |
---|
| 1566 | + dj_dev = NULL; |
---|
| 1567 | + } |
---|
953 | 1568 | |
---|
954 | | -out: |
---|
| 1569 | + if (dj_dev) { |
---|
| 1570 | + logi_dj_recv_forward_report(dj_dev, data, size); |
---|
| 1571 | + } else { |
---|
| 1572 | + if (hidpp_report->sub_id == REPORT_TYPE_NOTIF_DEVICE_CONNECTED) |
---|
| 1573 | + logi_hidpp_recv_queue_notif(hdev, hidpp_report); |
---|
| 1574 | + else |
---|
| 1575 | + logi_dj_recv_queue_unknown_work(djrcv_dev); |
---|
| 1576 | + } |
---|
| 1577 | + |
---|
955 | 1578 | spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
956 | 1579 | |
---|
957 | 1580 | return false; |
---|
.. | .. |
---|
961 | 1584 | struct hid_report *report, u8 *data, |
---|
962 | 1585 | int size) |
---|
963 | 1586 | { |
---|
| 1587 | + struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
964 | 1588 | dbg_hid("%s, size:%d\n", __func__, size); |
---|
| 1589 | + |
---|
| 1590 | + if (!djrcv_dev) |
---|
| 1591 | + return 0; |
---|
| 1592 | + |
---|
| 1593 | + if (!hdev->report_enum[HID_INPUT_REPORT].numbered) { |
---|
| 1594 | + |
---|
| 1595 | + if (djrcv_dev->unnumbered_application == HID_GD_KEYBOARD) { |
---|
| 1596 | + /* |
---|
| 1597 | + * For the keyboard, we can reuse the same report by |
---|
| 1598 | + * using the second byte which is constant in the USB |
---|
| 1599 | + * HID report descriptor. |
---|
| 1600 | + */ |
---|
| 1601 | + data[1] = data[0]; |
---|
| 1602 | + data[0] = REPORT_TYPE_KEYBOARD; |
---|
| 1603 | + |
---|
| 1604 | + logi_dj_recv_forward_input_report(hdev, data, size); |
---|
| 1605 | + |
---|
| 1606 | + /* restore previous state */ |
---|
| 1607 | + data[0] = data[1]; |
---|
| 1608 | + data[1] = 0; |
---|
| 1609 | + } |
---|
| 1610 | + /* |
---|
| 1611 | + * Mouse-only receivers send unnumbered mouse data. The 27 MHz |
---|
| 1612 | + * receiver uses 6 byte packets, the nano receiver 8 bytes. |
---|
| 1613 | + */ |
---|
| 1614 | + if (djrcv_dev->unnumbered_application == HID_GD_MOUSE && |
---|
| 1615 | + size <= 8) { |
---|
| 1616 | + u8 mouse_report[9]; |
---|
| 1617 | + |
---|
| 1618 | + /* Prepend report id */ |
---|
| 1619 | + mouse_report[0] = REPORT_TYPE_MOUSE; |
---|
| 1620 | + memcpy(mouse_report + 1, data, size); |
---|
| 1621 | + logi_dj_recv_forward_input_report(hdev, mouse_report, |
---|
| 1622 | + size + 1); |
---|
| 1623 | + } |
---|
| 1624 | + |
---|
| 1625 | + return false; |
---|
| 1626 | + } |
---|
965 | 1627 | |
---|
966 | 1628 | switch (data[0]) { |
---|
967 | 1629 | case REPORT_ID_DJ_SHORT: |
---|
968 | 1630 | if (size != DJREPORT_SHORT_LENGTH) { |
---|
969 | | - dev_err(&hdev->dev, "DJ report of bad size (%d)", size); |
---|
| 1631 | + hid_err(hdev, "Short DJ report bad size (%d)", size); |
---|
| 1632 | + return false; |
---|
| 1633 | + } |
---|
| 1634 | + return logi_dj_dj_event(hdev, report, data, size); |
---|
| 1635 | + case REPORT_ID_DJ_LONG: |
---|
| 1636 | + if (size != DJREPORT_LONG_LENGTH) { |
---|
| 1637 | + hid_err(hdev, "Long DJ report bad size (%d)", size); |
---|
970 | 1638 | return false; |
---|
971 | 1639 | } |
---|
972 | 1640 | return logi_dj_dj_event(hdev, report, data, size); |
---|
973 | 1641 | case REPORT_ID_HIDPP_SHORT: |
---|
974 | 1642 | if (size != HIDPP_REPORT_SHORT_LENGTH) { |
---|
975 | | - dev_err(&hdev->dev, |
---|
976 | | - "Short HID++ report of bad size (%d)", size); |
---|
| 1643 | + hid_err(hdev, "Short HID++ report bad size (%d)", size); |
---|
977 | 1644 | return false; |
---|
978 | 1645 | } |
---|
979 | 1646 | return logi_dj_hidpp_event(hdev, report, data, size); |
---|
980 | 1647 | case REPORT_ID_HIDPP_LONG: |
---|
981 | 1648 | if (size != HIDPP_REPORT_LONG_LENGTH) { |
---|
982 | | - dev_err(&hdev->dev, |
---|
983 | | - "Long HID++ report of bad size (%d)", size); |
---|
| 1649 | + hid_err(hdev, "Long HID++ report bad size (%d)", size); |
---|
984 | 1650 | return false; |
---|
985 | 1651 | } |
---|
986 | 1652 | return logi_dj_hidpp_event(hdev, report, data, size); |
---|
987 | 1653 | } |
---|
| 1654 | + |
---|
| 1655 | + logi_dj_recv_forward_input_report(hdev, data, size); |
---|
988 | 1656 | |
---|
989 | 1657 | return false; |
---|
990 | 1658 | } |
---|
.. | .. |
---|
992 | 1660 | static int logi_dj_probe(struct hid_device *hdev, |
---|
993 | 1661 | const struct hid_device_id *id) |
---|
994 | 1662 | { |
---|
995 | | - struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
---|
| 1663 | + struct hid_report_enum *rep_enum; |
---|
| 1664 | + struct hid_report *rep; |
---|
996 | 1665 | struct dj_receiver_dev *djrcv_dev; |
---|
| 1666 | + struct usb_interface *intf; |
---|
| 1667 | + unsigned int no_dj_interfaces = 0; |
---|
| 1668 | + bool has_hidpp = false; |
---|
| 1669 | + unsigned long flags; |
---|
997 | 1670 | int retval; |
---|
998 | 1671 | |
---|
999 | | - dbg_hid("%s called for ifnum %d\n", __func__, |
---|
1000 | | - intf->cur_altsetting->desc.bInterfaceNumber); |
---|
1001 | | - |
---|
1002 | | - /* Ignore interfaces 0 and 1, they will not carry any data, dont create |
---|
1003 | | - * any hid_device for them */ |
---|
1004 | | - if (intf->cur_altsetting->desc.bInterfaceNumber != |
---|
1005 | | - LOGITECH_DJ_INTERFACE_NUMBER) { |
---|
1006 | | - dbg_hid("%s: ignoring ifnum %d\n", __func__, |
---|
1007 | | - intf->cur_altsetting->desc.bInterfaceNumber); |
---|
1008 | | - return -ENODEV; |
---|
1009 | | - } |
---|
1010 | | - |
---|
1011 | | - /* Treat interface 2 */ |
---|
1012 | | - |
---|
1013 | | - djrcv_dev = kzalloc(sizeof(struct dj_receiver_dev), GFP_KERNEL); |
---|
1014 | | - if (!djrcv_dev) { |
---|
1015 | | - dev_err(&hdev->dev, |
---|
1016 | | - "%s:failed allocating dj_receiver_dev\n", __func__); |
---|
1017 | | - return -ENOMEM; |
---|
1018 | | - } |
---|
1019 | | - djrcv_dev->hdev = hdev; |
---|
1020 | | - INIT_WORK(&djrcv_dev->work, delayedwork_callback); |
---|
1021 | | - spin_lock_init(&djrcv_dev->lock); |
---|
1022 | | - if (kfifo_alloc(&djrcv_dev->notif_fifo, |
---|
1023 | | - DJ_MAX_NUMBER_NOTIFICATIONS * sizeof(struct dj_report), |
---|
1024 | | - GFP_KERNEL)) { |
---|
1025 | | - dev_err(&hdev->dev, |
---|
1026 | | - "%s:failed allocating notif_fifo\n", __func__); |
---|
1027 | | - kfree(djrcv_dev); |
---|
1028 | | - return -ENOMEM; |
---|
1029 | | - } |
---|
1030 | | - hid_set_drvdata(hdev, djrcv_dev); |
---|
1031 | | - |
---|
1032 | | - /* Call to usbhid to fetch the HID descriptors of interface 2 and |
---|
1033 | | - * subsequently call to the hid/hid-core to parse the fetched |
---|
1034 | | - * descriptors, this will in turn create the hidraw and hiddev nodes |
---|
1035 | | - * for interface 2 of the receiver */ |
---|
| 1672 | + /* |
---|
| 1673 | + * Call to usbhid to fetch the HID descriptors of the current |
---|
| 1674 | + * interface subsequently call to the hid/hid-core to parse the |
---|
| 1675 | + * fetched descriptors. |
---|
| 1676 | + */ |
---|
1036 | 1677 | retval = hid_parse(hdev); |
---|
1037 | 1678 | if (retval) { |
---|
1038 | | - dev_err(&hdev->dev, |
---|
1039 | | - "%s:parse of interface 2 failed\n", __func__); |
---|
1040 | | - goto hid_parse_fail; |
---|
| 1679 | + hid_err(hdev, "%s: parse failed\n", __func__); |
---|
| 1680 | + return retval; |
---|
1041 | 1681 | } |
---|
1042 | 1682 | |
---|
1043 | | - if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT, |
---|
1044 | | - 0, DJREPORT_SHORT_LENGTH - 1)) { |
---|
1045 | | - retval = -ENODEV; |
---|
1046 | | - goto hid_parse_fail; |
---|
| 1683 | + /* |
---|
| 1684 | + * Some KVMs add an extra interface for e.g. mouse emulation. If we |
---|
| 1685 | + * treat these as logitech-dj interfaces then this causes input events |
---|
| 1686 | + * reported through this extra interface to not be reported correctly. |
---|
| 1687 | + * To avoid this, we treat these as generic-hid devices. |
---|
| 1688 | + */ |
---|
| 1689 | + switch (id->driver_data) { |
---|
| 1690 | + case recvr_type_dj: no_dj_interfaces = 3; break; |
---|
| 1691 | + case recvr_type_hidpp: no_dj_interfaces = 2; break; |
---|
| 1692 | + case recvr_type_gaming_hidpp: no_dj_interfaces = 3; break; |
---|
| 1693 | + case recvr_type_mouse_only: no_dj_interfaces = 2; break; |
---|
| 1694 | + case recvr_type_27mhz: no_dj_interfaces = 2; break; |
---|
| 1695 | + case recvr_type_bluetooth: no_dj_interfaces = 2; break; |
---|
1047 | 1696 | } |
---|
| 1697 | + if (hid_is_usb(hdev)) { |
---|
| 1698 | + intf = to_usb_interface(hdev->dev.parent); |
---|
| 1699 | + if (intf && intf->altsetting->desc.bInterfaceNumber >= |
---|
| 1700 | + no_dj_interfaces) { |
---|
| 1701 | + hdev->quirks |= HID_QUIRK_INPUT_PER_APP; |
---|
| 1702 | + return hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
---|
| 1703 | + } |
---|
| 1704 | + } |
---|
| 1705 | + |
---|
| 1706 | + rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
---|
| 1707 | + |
---|
| 1708 | + /* no input reports, bail out */ |
---|
| 1709 | + if (list_empty(&rep_enum->report_list)) |
---|
| 1710 | + return -ENODEV; |
---|
| 1711 | + |
---|
| 1712 | + /* |
---|
| 1713 | + * Check for the HID++ application. |
---|
| 1714 | + * Note: we should theoretically check for HID++ and DJ |
---|
| 1715 | + * collections, but this will do. |
---|
| 1716 | + */ |
---|
| 1717 | + list_for_each_entry(rep, &rep_enum->report_list, list) { |
---|
| 1718 | + if (rep->application == 0xff000001) |
---|
| 1719 | + has_hidpp = true; |
---|
| 1720 | + } |
---|
| 1721 | + |
---|
| 1722 | + /* |
---|
| 1723 | + * Ignore interfaces without DJ/HID++ collection, they will not carry |
---|
| 1724 | + * any data, dont create any hid_device for them. |
---|
| 1725 | + */ |
---|
| 1726 | + if (!has_hidpp && id->driver_data == recvr_type_dj) |
---|
| 1727 | + return -ENODEV; |
---|
| 1728 | + |
---|
| 1729 | + /* get the current application attached to the node */ |
---|
| 1730 | + rep = list_first_entry(&rep_enum->report_list, struct hid_report, list); |
---|
| 1731 | + djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data, |
---|
| 1732 | + rep->application, has_hidpp); |
---|
| 1733 | + if (!djrcv_dev) { |
---|
| 1734 | + hid_err(hdev, "%s: dj_get_receiver_dev failed\n", __func__); |
---|
| 1735 | + return -ENOMEM; |
---|
| 1736 | + } |
---|
| 1737 | + |
---|
| 1738 | + if (!rep_enum->numbered) |
---|
| 1739 | + djrcv_dev->unnumbered_application = rep->application; |
---|
1048 | 1740 | |
---|
1049 | 1741 | /* Starts the usb device and connects to upper interfaces hiddev and |
---|
1050 | 1742 | * hidraw */ |
---|
1051 | | - retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
---|
| 1743 | + retval = hid_hw_start(hdev, HID_CONNECT_HIDRAW|HID_CONNECT_HIDDEV); |
---|
1052 | 1744 | if (retval) { |
---|
1053 | | - dev_err(&hdev->dev, |
---|
1054 | | - "%s:hid_hw_start returned error\n", __func__); |
---|
| 1745 | + hid_err(hdev, "%s: hid_hw_start returned error\n", __func__); |
---|
1055 | 1746 | goto hid_hw_start_fail; |
---|
1056 | 1747 | } |
---|
1057 | 1748 | |
---|
1058 | | - retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); |
---|
1059 | | - if (retval < 0) { |
---|
1060 | | - dev_err(&hdev->dev, |
---|
1061 | | - "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
---|
1062 | | - __func__, retval); |
---|
1063 | | - goto switch_to_dj_mode_fail; |
---|
| 1749 | + if (has_hidpp) { |
---|
| 1750 | + retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); |
---|
| 1751 | + if (retval < 0) { |
---|
| 1752 | + hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
---|
| 1753 | + __func__, retval); |
---|
| 1754 | + goto switch_to_dj_mode_fail; |
---|
| 1755 | + } |
---|
1064 | 1756 | } |
---|
1065 | 1757 | |
---|
1066 | 1758 | /* This is enabling the polling urb on the IN endpoint */ |
---|
1067 | 1759 | retval = hid_hw_open(hdev); |
---|
1068 | 1760 | if (retval < 0) { |
---|
1069 | | - dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", |
---|
| 1761 | + hid_err(hdev, "%s: hid_hw_open returned error:%d\n", |
---|
1070 | 1762 | __func__, retval); |
---|
1071 | 1763 | goto llopen_failed; |
---|
1072 | 1764 | } |
---|
.. | .. |
---|
1074 | 1766 | /* Allow incoming packets to arrive: */ |
---|
1075 | 1767 | hid_device_io_start(hdev); |
---|
1076 | 1768 | |
---|
1077 | | - retval = logi_dj_recv_query_paired_devices(djrcv_dev); |
---|
1078 | | - if (retval < 0) { |
---|
1079 | | - dev_err(&hdev->dev, "%s:logi_dj_recv_query_paired_devices " |
---|
1080 | | - "error:%d\n", __func__, retval); |
---|
1081 | | - goto logi_dj_recv_query_paired_devices_failed; |
---|
| 1769 | + if (has_hidpp) { |
---|
| 1770 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
| 1771 | + djrcv_dev->ready = true; |
---|
| 1772 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
| 1773 | + retval = logi_dj_recv_query_paired_devices(djrcv_dev); |
---|
| 1774 | + if (retval < 0) { |
---|
| 1775 | + hid_err(hdev, "%s: logi_dj_recv_query_paired_devices error:%d\n", |
---|
| 1776 | + __func__, retval); |
---|
| 1777 | + /* |
---|
| 1778 | + * This can happen with a KVM, let the probe succeed, |
---|
| 1779 | + * logi_dj_recv_queue_unknown_work will retry later. |
---|
| 1780 | + */ |
---|
| 1781 | + } |
---|
1082 | 1782 | } |
---|
1083 | 1783 | |
---|
1084 | | - return retval; |
---|
1085 | | - |
---|
1086 | | -logi_dj_recv_query_paired_devices_failed: |
---|
1087 | | - hid_hw_close(hdev); |
---|
| 1784 | + return 0; |
---|
1088 | 1785 | |
---|
1089 | 1786 | llopen_failed: |
---|
1090 | 1787 | switch_to_dj_mode_fail: |
---|
1091 | 1788 | hid_hw_stop(hdev); |
---|
1092 | 1789 | |
---|
1093 | 1790 | hid_hw_start_fail: |
---|
1094 | | -hid_parse_fail: |
---|
1095 | | - kfifo_free(&djrcv_dev->notif_fifo); |
---|
1096 | | - kfree(djrcv_dev); |
---|
1097 | | - hid_set_drvdata(hdev, NULL); |
---|
| 1791 | + dj_put_receiver_dev(hdev); |
---|
1098 | 1792 | return retval; |
---|
1099 | | - |
---|
1100 | 1793 | } |
---|
1101 | 1794 | |
---|
1102 | 1795 | #ifdef CONFIG_PM |
---|
.. | .. |
---|
1105 | 1798 | int retval; |
---|
1106 | 1799 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
1107 | 1800 | |
---|
| 1801 | + if (!djrcv_dev || djrcv_dev->hidpp != hdev) |
---|
| 1802 | + return 0; |
---|
| 1803 | + |
---|
1108 | 1804 | retval = logi_dj_recv_switch_to_dj_mode(djrcv_dev, 0); |
---|
1109 | 1805 | if (retval < 0) { |
---|
1110 | | - dev_err(&hdev->dev, |
---|
1111 | | - "%s:logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
---|
| 1806 | + hid_err(hdev, "%s: logi_dj_recv_switch_to_dj_mode returned error:%d\n", |
---|
1112 | 1807 | __func__, retval); |
---|
1113 | 1808 | } |
---|
1114 | 1809 | |
---|
.. | .. |
---|
1120 | 1815 | { |
---|
1121 | 1816 | struct dj_receiver_dev *djrcv_dev = hid_get_drvdata(hdev); |
---|
1122 | 1817 | struct dj_device *dj_dev; |
---|
| 1818 | + unsigned long flags; |
---|
1123 | 1819 | int i; |
---|
1124 | 1820 | |
---|
1125 | 1821 | dbg_hid("%s\n", __func__); |
---|
| 1822 | + |
---|
| 1823 | + if (!djrcv_dev) |
---|
| 1824 | + return hid_hw_stop(hdev); |
---|
| 1825 | + |
---|
| 1826 | + /* |
---|
| 1827 | + * This ensures that if the work gets requeued from another |
---|
| 1828 | + * interface of the same receiver it will be a no-op. |
---|
| 1829 | + */ |
---|
| 1830 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
| 1831 | + djrcv_dev->ready = false; |
---|
| 1832 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
1126 | 1833 | |
---|
1127 | 1834 | cancel_work_sync(&djrcv_dev->work); |
---|
1128 | 1835 | |
---|
1129 | 1836 | hid_hw_close(hdev); |
---|
1130 | 1837 | hid_hw_stop(hdev); |
---|
1131 | 1838 | |
---|
1132 | | - /* I suppose that at this point the only context that can access |
---|
1133 | | - * the djrecv_data is this thread as the work item is guaranteed to |
---|
1134 | | - * have finished and no more raw_event callbacks should arrive after |
---|
1135 | | - * the remove callback was triggered so no locks are put around the |
---|
1136 | | - * code below */ |
---|
| 1839 | + /* |
---|
| 1840 | + * For proper operation we need access to all interfaces, so we destroy |
---|
| 1841 | + * the paired devices when we're unbound from any interface. |
---|
| 1842 | + * |
---|
| 1843 | + * Note we may still be bound to other interfaces, sharing the same |
---|
| 1844 | + * djrcv_dev, so we need locking here. |
---|
| 1845 | + */ |
---|
1137 | 1846 | for (i = 0; i < (DJ_MAX_PAIRED_DEVICES + DJ_DEVICE_INDEX_MIN); i++) { |
---|
| 1847 | + spin_lock_irqsave(&djrcv_dev->lock, flags); |
---|
1138 | 1848 | dj_dev = djrcv_dev->paired_dj_devices[i]; |
---|
| 1849 | + djrcv_dev->paired_dj_devices[i] = NULL; |
---|
| 1850 | + spin_unlock_irqrestore(&djrcv_dev->lock, flags); |
---|
1139 | 1851 | if (dj_dev != NULL) { |
---|
1140 | 1852 | hid_destroy_device(dj_dev->hdev); |
---|
1141 | 1853 | kfree(dj_dev); |
---|
1142 | | - djrcv_dev->paired_dj_devices[i] = NULL; |
---|
1143 | 1854 | } |
---|
1144 | 1855 | } |
---|
1145 | 1856 | |
---|
1146 | | - kfifo_free(&djrcv_dev->notif_fifo); |
---|
1147 | | - kfree(djrcv_dev); |
---|
1148 | | - hid_set_drvdata(hdev, NULL); |
---|
| 1857 | + dj_put_receiver_dev(hdev); |
---|
1149 | 1858 | } |
---|
1150 | 1859 | |
---|
1151 | 1860 | static const struct hid_device_id logi_dj_receivers[] = { |
---|
1152 | 1861 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
1153 | | - USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER)}, |
---|
| 1862 | + USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER), |
---|
| 1863 | + .driver_data = recvr_type_dj}, |
---|
1154 | 1864 | {HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
1155 | | - USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2)}, |
---|
| 1865 | + USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2), |
---|
| 1866 | + .driver_data = recvr_type_dj}, |
---|
| 1867 | + { /* Logitech Nano mouse only receiver */ |
---|
| 1868 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1869 | + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER), |
---|
| 1870 | + .driver_data = recvr_type_mouse_only}, |
---|
| 1871 | + { /* Logitech Nano (non DJ) receiver */ |
---|
| 1872 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1873 | + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2), |
---|
| 1874 | + .driver_data = recvr_type_hidpp}, |
---|
| 1875 | + { /* Logitech G700(s) receiver (0xc531) */ |
---|
| 1876 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1877 | + 0xc531), |
---|
| 1878 | + .driver_data = recvr_type_gaming_hidpp}, |
---|
| 1879 | + { /* Logitech G602 receiver (0xc537) */ |
---|
| 1880 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1881 | + 0xc537), |
---|
| 1882 | + .driver_data = recvr_type_gaming_hidpp}, |
---|
| 1883 | + { /* Logitech lightspeed receiver (0xc539) */ |
---|
| 1884 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1885 | + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1), |
---|
| 1886 | + .driver_data = recvr_type_gaming_hidpp}, |
---|
| 1887 | + { /* Logitech lightspeed receiver (0xc53f) */ |
---|
| 1888 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1889 | + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1), |
---|
| 1890 | + .driver_data = recvr_type_gaming_hidpp}, |
---|
| 1891 | + { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */ |
---|
| 1892 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER), |
---|
| 1893 | + .driver_data = recvr_type_27mhz}, |
---|
| 1894 | + { /* Logitech powerplay receiver (0xc53a) */ |
---|
| 1895 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1896 | + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY), |
---|
| 1897 | + .driver_data = recvr_type_gaming_hidpp}, |
---|
| 1898 | + { /* Logitech 27 MHz HID++ 1.0 receiver (0xc517) */ |
---|
| 1899 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1900 | + USB_DEVICE_ID_S510_RECEIVER_2), |
---|
| 1901 | + .driver_data = recvr_type_27mhz}, |
---|
| 1902 | + { /* Logitech 27 MHz HID++ 1.0 mouse-only receiver (0xc51b) */ |
---|
| 1903 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1904 | + USB_DEVICE_ID_LOGITECH_27MHZ_MOUSE_RECEIVER), |
---|
| 1905 | + .driver_data = recvr_type_27mhz}, |
---|
| 1906 | + { /* Logitech MX5000 HID++ / bluetooth receiver keyboard intf. */ |
---|
| 1907 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1908 | + 0xc70e), |
---|
| 1909 | + .driver_data = recvr_type_bluetooth}, |
---|
| 1910 | + { /* Logitech MX5000 HID++ / bluetooth receiver mouse intf. */ |
---|
| 1911 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1912 | + 0xc70a), |
---|
| 1913 | + .driver_data = recvr_type_bluetooth}, |
---|
| 1914 | + { /* Logitech MX5500 HID++ / bluetooth receiver keyboard intf. */ |
---|
| 1915 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1916 | + 0xc71b), |
---|
| 1917 | + .driver_data = recvr_type_bluetooth}, |
---|
| 1918 | + { /* Logitech MX5500 HID++ / bluetooth receiver mouse intf. */ |
---|
| 1919 | + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, |
---|
| 1920 | + 0xc71c), |
---|
| 1921 | + .driver_data = recvr_type_bluetooth}, |
---|
1156 | 1922 | {} |
---|
1157 | 1923 | }; |
---|
1158 | 1924 | |
---|