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