42faaeead81b
[openwrt/staging/blogic.git] /
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * USB device quirk handling logic and table
4 *
5 * Copyright (c) 2007 Oliver Neukum
6 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
7 */
8
9 #include <linux/usb.h>
10 #include <linux/usb/quirks.h>
11 #include <linux/usb/hcd.h>
12 #include "usb.h"
13
14 struct quirk_entry {
15 u16 vid;
16 u16 pid;
17 u32 flags;
18 };
19
20 static DEFINE_MUTEX(quirk_mutex);
21
22 static struct quirk_entry *quirk_list;
23 static unsigned int quirk_count;
24
25 static char quirks_param[128];
26
27 static int quirks_param_set(const char *val, const struct kernel_param *kp)
28 {
29 char *p, *field;
30 u16 vid, pid;
31 u32 flags;
32 size_t i;
33
34 mutex_lock(&quirk_mutex);
35
36 if (!val || !*val) {
37 quirk_count = 0;
38 kfree(quirk_list);
39 quirk_list = NULL;
40 goto unlock;
41 }
42
43 for (quirk_count = 1, i = 0; val[i]; i++)
44 if (val[i] == ',')
45 quirk_count++;
46
47 if (quirk_list) {
48 kfree(quirk_list);
49 quirk_list = NULL;
50 }
51
52 quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
53 GFP_KERNEL);
54 if (!quirk_list) {
55 mutex_unlock(&quirk_mutex);
56 return -ENOMEM;
57 }
58
59 for (i = 0, p = (char *)val; p && *p;) {
60 /* Each entry consists of VID:PID:flags */
61 field = strsep(&p, ":");
62 if (!field)
63 break;
64
65 if (kstrtou16(field, 16, &vid))
66 break;
67
68 field = strsep(&p, ":");
69 if (!field)
70 break;
71
72 if (kstrtou16(field, 16, &pid))
73 break;
74
75 field = strsep(&p, ",");
76 if (!field || !*field)
77 break;
78
79 /* Collect the flags */
80 for (flags = 0; *field; field++) {
81 switch (*field) {
82 case 'a':
83 flags |= USB_QUIRK_STRING_FETCH_255;
84 break;
85 case 'b':
86 flags |= USB_QUIRK_RESET_RESUME;
87 break;
88 case 'c':
89 flags |= USB_QUIRK_NO_SET_INTF;
90 break;
91 case 'd':
92 flags |= USB_QUIRK_CONFIG_INTF_STRINGS;
93 break;
94 case 'e':
95 flags |= USB_QUIRK_RESET;
96 break;
97 case 'f':
98 flags |= USB_QUIRK_HONOR_BNUMINTERFACES;
99 break;
100 case 'g':
101 flags |= USB_QUIRK_DELAY_INIT;
102 break;
103 case 'h':
104 flags |= USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL;
105 break;
106 case 'i':
107 flags |= USB_QUIRK_DEVICE_QUALIFIER;
108 break;
109 case 'j':
110 flags |= USB_QUIRK_IGNORE_REMOTE_WAKEUP;
111 break;
112 case 'k':
113 flags |= USB_QUIRK_NO_LPM;
114 break;
115 case 'l':
116 flags |= USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL;
117 break;
118 case 'm':
119 flags |= USB_QUIRK_DISCONNECT_SUSPEND;
120 break;
121 /* Ignore unrecognized flag characters */
122 }
123 }
124
125 quirk_list[i++] = (struct quirk_entry)
126 { .vid = vid, .pid = pid, .flags = flags };
127 }
128
129 if (i < quirk_count)
130 quirk_count = i;
131
132 unlock:
133 mutex_unlock(&quirk_mutex);
134
135 return param_set_copystring(val, kp);
136 }
137
138 static const struct kernel_param_ops quirks_param_ops = {
139 .set = quirks_param_set,
140 .get = param_get_string,
141 };
142
143 static struct kparam_string quirks_param_string = {
144 .maxlen = sizeof(quirks_param),
145 .string = quirks_param,
146 };
147
148 module_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
149 MODULE_PARM_DESC(quirks, "Add/modify USB quirks by specifying quirks=vendorID:productID:quirks");
150
151 /* Lists of quirky USB devices, split in device quirks and interface quirks.
152 * Device quirks are applied at the very beginning of the enumeration process,
153 * right after reading the device descriptor. They can thus only match on device
154 * information.
155 *
156 * Interface quirks are applied after reading all the configuration descriptors.
157 * They can match on both device and interface information.
158 *
159 * Note that the DELAY_INIT and HONOR_BNUMINTERFACES quirks do not make sense as
160 * interface quirks, as they only influence the enumeration process which is run
161 * before processing the interface quirks.
162 *
163 * Please keep the lists ordered by:
164 * 1) Vendor ID
165 * 2) Product ID
166 * 3) Class ID
167 */
168 static const struct usb_device_id usb_quirk_list[] = {
169 /* CBM - Flash disk */
170 { USB_DEVICE(0x0204, 0x6025), .driver_info = USB_QUIRK_RESET_RESUME },
171
172 /* WORLDE easy key (easykey.25) MIDI controller */
173 { USB_DEVICE(0x0218, 0x0401), .driver_info =
174 USB_QUIRK_CONFIG_INTF_STRINGS },
175
176 /* HP 5300/5370C scanner */
177 { USB_DEVICE(0x03f0, 0x0701), .driver_info =
178 USB_QUIRK_STRING_FETCH_255 },
179
180 /* Creative SB Audigy 2 NX */
181 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
182
183 /* USB3503 */
184 { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME },
185
186 /* Microsoft Wireless Laser Mouse 6000 Receiver */
187 { USB_DEVICE(0x045e, 0x00e1), .driver_info = USB_QUIRK_RESET_RESUME },
188
189 /* Microsoft LifeCam-VX700 v2.0 */
190 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
191
192 /* Logitech HD Pro Webcams C920, C920-C, C925e and C930e */
193 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT },
194 { USB_DEVICE(0x046d, 0x0841), .driver_info = USB_QUIRK_DELAY_INIT },
195 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT },
196 { USB_DEVICE(0x046d, 0x085b), .driver_info = USB_QUIRK_DELAY_INIT },
197
198 /* Logitech ConferenceCam CC3000e */
199 { USB_DEVICE(0x046d, 0x0847), .driver_info = USB_QUIRK_DELAY_INIT },
200 { USB_DEVICE(0x046d, 0x0848), .driver_info = USB_QUIRK_DELAY_INIT },
201
202 /* Logitech PTZ Pro Camera */
203 { USB_DEVICE(0x046d, 0x0853), .driver_info = USB_QUIRK_DELAY_INIT },
204
205 /* Logitech Quickcam Fusion */
206 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME },
207
208 /* Logitech Quickcam Orbit MP */
209 { USB_DEVICE(0x046d, 0x08c2), .driver_info = USB_QUIRK_RESET_RESUME },
210
211 /* Logitech Quickcam Pro for Notebook */
212 { USB_DEVICE(0x046d, 0x08c3), .driver_info = USB_QUIRK_RESET_RESUME },
213
214 /* Logitech Quickcam Pro 5000 */
215 { USB_DEVICE(0x046d, 0x08c5), .driver_info = USB_QUIRK_RESET_RESUME },
216
217 /* Logitech Quickcam OEM Dell Notebook */
218 { USB_DEVICE(0x046d, 0x08c6), .driver_info = USB_QUIRK_RESET_RESUME },
219
220 /* Logitech Quickcam OEM Cisco VT Camera II */
221 { USB_DEVICE(0x046d, 0x08c7), .driver_info = USB_QUIRK_RESET_RESUME },
222
223 /* Logitech Harmony 700-series */
224 { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT },
225
226 /* Philips PSC805 audio device */
227 { USB_DEVICE(0x0471, 0x0155), .driver_info = USB_QUIRK_RESET_RESUME },
228
229 /* Plantronic Audio 655 DSP */
230 { USB_DEVICE(0x047f, 0xc008), .driver_info = USB_QUIRK_RESET_RESUME },
231
232 /* Plantronic Audio 648 USB */
233 { USB_DEVICE(0x047f, 0xc013), .driver_info = USB_QUIRK_RESET_RESUME },
234
235 /* Artisman Watchdog Dongle */
236 { USB_DEVICE(0x04b4, 0x0526), .driver_info =
237 USB_QUIRK_CONFIG_INTF_STRINGS },
238
239 /* Microchip Joss Optical infrared touchboard device */
240 { USB_DEVICE(0x04d8, 0x000c), .driver_info =
241 USB_QUIRK_CONFIG_INTF_STRINGS },
242
243 /* CarrolTouch 4000U */
244 { USB_DEVICE(0x04e7, 0x0009), .driver_info = USB_QUIRK_RESET_RESUME },
245
246 /* CarrolTouch 4500U */
247 { USB_DEVICE(0x04e7, 0x0030), .driver_info = USB_QUIRK_RESET_RESUME },
248
249 /* Samsung Android phone modem - ID conflict with SPH-I500 */
250 { USB_DEVICE(0x04e8, 0x6601), .driver_info =
251 USB_QUIRK_CONFIG_INTF_STRINGS },
252
253 /* Elan Touchscreen */
254 { USB_DEVICE(0x04f3, 0x0089), .driver_info =
255 USB_QUIRK_DEVICE_QUALIFIER },
256
257 { USB_DEVICE(0x04f3, 0x009b), .driver_info =
258 USB_QUIRK_DEVICE_QUALIFIER },
259
260 { USB_DEVICE(0x04f3, 0x010c), .driver_info =
261 USB_QUIRK_DEVICE_QUALIFIER },
262
263 { USB_DEVICE(0x04f3, 0x0125), .driver_info =
264 USB_QUIRK_DEVICE_QUALIFIER },
265
266 { USB_DEVICE(0x04f3, 0x016f), .driver_info =
267 USB_QUIRK_DEVICE_QUALIFIER },
268
269 { USB_DEVICE(0x04f3, 0x0381), .driver_info =
270 USB_QUIRK_NO_LPM },
271
272 { USB_DEVICE(0x04f3, 0x21b8), .driver_info =
273 USB_QUIRK_DEVICE_QUALIFIER },
274
275 /* Roland SC-8820 */
276 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME },
277
278 /* Edirol SD-20 */
279 { USB_DEVICE(0x0582, 0x0027), .driver_info = USB_QUIRK_RESET_RESUME },
280
281 /* Alcor Micro Corp. Hub */
282 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME },
283
284 /* appletouch */
285 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME },
286
287 /* Genesys Logic hub, internally used by KY-688 USB 3.1 Type-C Hub */
288 { USB_DEVICE(0x05e3, 0x0612), .driver_info = USB_QUIRK_NO_LPM },
289
290 /* ELSA MicroLink 56K */
291 { USB_DEVICE(0x05cc, 0x2267), .driver_info = USB_QUIRK_RESET_RESUME },
292
293 /* Genesys Logic hub, internally used by Moshi USB to Ethernet Adapter */
294 { USB_DEVICE(0x05e3, 0x0616), .driver_info = USB_QUIRK_NO_LPM },
295
296 /* Avision AV600U */
297 { USB_DEVICE(0x0638, 0x0a13), .driver_info =
298 USB_QUIRK_STRING_FETCH_255 },
299
300 /* Saitek Cyborg Gold Joystick */
301 { USB_DEVICE(0x06a3, 0x0006), .driver_info =
302 USB_QUIRK_CONFIG_INTF_STRINGS },
303
304 /* Guillemot Webcam Hercules Dualpix Exchange (2nd ID) */
305 { USB_DEVICE(0x06f8, 0x0804), .driver_info = USB_QUIRK_RESET_RESUME },
306
307 /* Guillemot Webcam Hercules Dualpix Exchange*/
308 { USB_DEVICE(0x06f8, 0x3005), .driver_info = USB_QUIRK_RESET_RESUME },
309
310 /* Midiman M-Audio Keystation 88es */
311 { USB_DEVICE(0x0763, 0x0192), .driver_info = USB_QUIRK_RESET_RESUME },
312
313 /* M-Systems Flash Disk Pioneers */
314 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
315
316 /* Baum Vario Ultra */
317 { USB_DEVICE(0x0904, 0x6101), .driver_info =
318 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
319 { USB_DEVICE(0x0904, 0x6102), .driver_info =
320 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
321 { USB_DEVICE(0x0904, 0x6103), .driver_info =
322 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
323
324 /* Keytouch QWERTY Panel keyboard */
325 { USB_DEVICE(0x0926, 0x3333), .driver_info =
326 USB_QUIRK_CONFIG_INTF_STRINGS },
327
328 /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */
329 { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF },
330
331 /* Broadcom BCM92035DGROM BT dongle */
332 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME },
333
334 /* MAYA44USB sound device */
335 { USB_DEVICE(0x0a92, 0x0091), .driver_info = USB_QUIRK_RESET_RESUME },
336
337 /* ASUS Base Station(T100) */
338 { USB_DEVICE(0x0b05, 0x17e0), .driver_info =
339 USB_QUIRK_IGNORE_REMOTE_WAKEUP },
340
341 /* Action Semiconductor flash disk */
342 { USB_DEVICE(0x10d6, 0x2200), .driver_info =
343 USB_QUIRK_STRING_FETCH_255 },
344
345 /* Huawei 4G LTE module */
346 { USB_DEVICE(0x12d1, 0x15bb), .driver_info =
347 USB_QUIRK_DISCONNECT_SUSPEND },
348 { USB_DEVICE(0x12d1, 0x15c3), .driver_info =
349 USB_QUIRK_DISCONNECT_SUSPEND },
350
351 /* SKYMEDI USB_DRIVE */
352 { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME },
353
354 /* Razer - Razer Blade Keyboard */
355 { USB_DEVICE(0x1532, 0x0116), .driver_info =
356 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
357
358 /* BUILDWIN Photo Frame */
359 { USB_DEVICE(0x1908, 0x1315), .driver_info =
360 USB_QUIRK_HONOR_BNUMINTERFACES },
361
362 /* Protocol and OTG Electrical Test Device */
363 { USB_DEVICE(0x1a0a, 0x0200), .driver_info =
364 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
365
366 /* Corsair K70 RGB */
367 { USB_DEVICE(0x1b1c, 0x1b13), .driver_info = USB_QUIRK_DELAY_INIT },
368
369 /* Corsair Strafe RGB */
370 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT },
371
372 /* Corsair K70 LUX */
373 { USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT },
374
375 /* MIDI keyboard WORLDE MINI */
376 { USB_DEVICE(0x1c75, 0x0204), .driver_info =
377 USB_QUIRK_CONFIG_INTF_STRINGS },
378
379 /* Acer C120 LED Projector */
380 { USB_DEVICE(0x1de1, 0xc102), .driver_info = USB_QUIRK_NO_LPM },
381
382 /* Blackmagic Design Intensity Shuttle */
383 { USB_DEVICE(0x1edb, 0xbd3b), .driver_info = USB_QUIRK_NO_LPM },
384
385 /* Blackmagic Design UltraStudio SDI */
386 { USB_DEVICE(0x1edb, 0xbd4f), .driver_info = USB_QUIRK_NO_LPM },
387
388 /* Hauppauge HVR-950q */
389 { USB_DEVICE(0x2040, 0x7200), .driver_info =
390 USB_QUIRK_CONFIG_INTF_STRINGS },
391
392 /* INTEL VALUE SSD */
393 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
394
395 { } /* terminating entry must be last */
396 };
397
398 static const struct usb_device_id usb_interface_quirk_list[] = {
399 /* Logitech UVC Cameras */
400 { USB_VENDOR_AND_INTERFACE_INFO(0x046d, USB_CLASS_VIDEO, 1, 0),
401 .driver_info = USB_QUIRK_RESET_RESUME },
402
403 { } /* terminating entry must be last */
404 };
405
406 static const struct usb_device_id usb_amd_resume_quirk_list[] = {
407 /* Lenovo Mouse with Pixart controller */
408 { USB_DEVICE(0x17ef, 0x602e), .driver_info = USB_QUIRK_RESET_RESUME },
409
410 /* Pixart Mouse */
411 { USB_DEVICE(0x093a, 0x2500), .driver_info = USB_QUIRK_RESET_RESUME },
412 { USB_DEVICE(0x093a, 0x2510), .driver_info = USB_QUIRK_RESET_RESUME },
413 { USB_DEVICE(0x093a, 0x2521), .driver_info = USB_QUIRK_RESET_RESUME },
414 { USB_DEVICE(0x03f0, 0x2b4a), .driver_info = USB_QUIRK_RESET_RESUME },
415
416 /* Logitech Optical Mouse M90/M100 */
417 { USB_DEVICE(0x046d, 0xc05a), .driver_info = USB_QUIRK_RESET_RESUME },
418
419 { } /* terminating entry must be last */
420 };
421
422 static bool usb_match_any_interface(struct usb_device *udev,
423 const struct usb_device_id *id)
424 {
425 unsigned int i;
426
427 for (i = 0; i < udev->descriptor.bNumConfigurations; ++i) {
428 struct usb_host_config *cfg = &udev->config[i];
429 unsigned int j;
430
431 for (j = 0; j < cfg->desc.bNumInterfaces; ++j) {
432 struct usb_interface_cache *cache;
433 struct usb_host_interface *intf;
434
435 cache = cfg->intf_cache[j];
436 if (cache->num_altsetting == 0)
437 continue;
438
439 intf = &cache->altsetting[0];
440 if (usb_match_one_id_intf(udev, intf, id))
441 return true;
442 }
443 }
444
445 return false;
446 }
447
448 static int usb_amd_resume_quirk(struct usb_device *udev)
449 {
450 struct usb_hcd *hcd;
451
452 hcd = bus_to_hcd(udev->bus);
453 /* The device should be attached directly to root hub */
454 if (udev->level == 1 && hcd->amd_resume_bug == 1)
455 return 1;
456
457 return 0;
458 }
459
460 static u32 usb_detect_static_quirks(struct usb_device *udev,
461 const struct usb_device_id *id)
462 {
463 u32 quirks = 0;
464
465 for (; id->match_flags; id++) {
466 if (!usb_match_device(udev, id))
467 continue;
468
469 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_INFO) &&
470 !usb_match_any_interface(udev, id))
471 continue;
472
473 quirks |= (u32)(id->driver_info);
474 }
475
476 return quirks;
477 }
478
479 static u32 usb_detect_dynamic_quirks(struct usb_device *udev)
480 {
481 u16 vid = le16_to_cpu(udev->descriptor.idVendor);
482 u16 pid = le16_to_cpu(udev->descriptor.idProduct);
483 int i, flags = 0;
484
485 mutex_lock(&quirk_mutex);
486
487 for (i = 0; i < quirk_count; i++) {
488 if (vid == quirk_list[i].vid && pid == quirk_list[i].pid) {
489 flags = quirk_list[i].flags;
490 break;
491 }
492 }
493
494 mutex_unlock(&quirk_mutex);
495
496 return flags;
497 }
498
499 /*
500 * Detect any quirks the device has, and do any housekeeping for it if needed.
501 */
502 void usb_detect_quirks(struct usb_device *udev)
503 {
504 udev->quirks = usb_detect_static_quirks(udev, usb_quirk_list);
505
506 /*
507 * Pixart-based mice would trigger remote wakeup issue on AMD
508 * Yangtze chipset, so set them as RESET_RESUME flag.
509 */
510 if (usb_amd_resume_quirk(udev))
511 udev->quirks |= usb_detect_static_quirks(udev,
512 usb_amd_resume_quirk_list);
513
514 udev->quirks ^= usb_detect_dynamic_quirks(udev);
515
516 if (udev->quirks)
517 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
518 udev->quirks);
519
520 #ifdef CONFIG_USB_DEFAULT_PERSIST
521 if (!(udev->quirks & USB_QUIRK_RESET))
522 udev->persist_enabled = 1;
523 #else
524 /* Hubs are automatically enabled for USB-PERSIST */
525 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
526 udev->persist_enabled = 1;
527 #endif /* CONFIG_USB_DEFAULT_PERSIST */
528 }
529
530 void usb_detect_interface_quirks(struct usb_device *udev)
531 {
532 u32 quirks;
533
534 quirks = usb_detect_static_quirks(udev, usb_interface_quirk_list);
535 if (quirks == 0)
536 return;
537
538 dev_dbg(&udev->dev, "USB interface quirks for this device: %x\n",
539 quirks);
540 udev->quirks |= quirks;
541 }
542
543 void usb_release_quirk_list(void)
544 {
545 mutex_lock(&quirk_mutex);
546 kfree(quirk_list);
547 quirk_list = NULL;
548 mutex_unlock(&quirk_mutex);
549 }