blob: 920f48a49a87021a513b4e395a903044a558abf5 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Oliver Neukum7ceec1f2007-01-26 14:26:21 +01002/*
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>
Oliver Neukum7ceec1f2007-01-26 14:26:21 +01007 */
8
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +08009#include <linux/moduleparam.h>
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010010#include <linux/usb.h>
11#include <linux/usb/quirks.h>
Huang Rui78689432013-09-16 23:47:28 +080012#include <linux/usb/hcd.h>
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010013#include "usb.h"
14
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +080015struct quirk_entry {
16 u16 vid;
17 u16 pid;
18 u32 flags;
19};
20
21static DEFINE_MUTEX(quirk_mutex);
22
23static struct quirk_entry *quirk_list;
24static unsigned int quirk_count;
25
26static char quirks_param[128];
27
28static int quirks_param_set(const char *val, const struct kernel_param *kp)
29{
30 char *p, *field;
31 u16 vid, pid;
32 u32 flags;
33 size_t i;
Kai-Heng Fenga0305012018-03-24 03:26:35 +080034 int err;
35
36 err = param_set_copystring(val, kp);
37 if (err)
38 return err;
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +080039
40 mutex_lock(&quirk_mutex);
41
Kai-Heng Fenga0305012018-03-24 03:26:35 +080042 if (!*val) {
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +080043 quirk_count = 0;
44 kfree(quirk_list);
45 quirk_list = NULL;
46 goto unlock;
47 }
48
49 for (quirk_count = 1, i = 0; val[i]; i++)
50 if (val[i] == ',')
51 quirk_count++;
52
53 if (quirk_list) {
54 kfree(quirk_list);
55 quirk_list = NULL;
56 }
57
58 quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
59 GFP_KERNEL);
60 if (!quirk_list) {
61 mutex_unlock(&quirk_mutex);
62 return -ENOMEM;
63 }
64
65 for (i = 0, p = (char *)val; p && *p;) {
66 /* Each entry consists of VID:PID:flags */
67 field = strsep(&p, ":");
68 if (!field)
69 break;
70
71 if (kstrtou16(field, 16, &vid))
72 break;
73
74 field = strsep(&p, ":");
75 if (!field)
76 break;
77
78 if (kstrtou16(field, 16, &pid))
79 break;
80
81 field = strsep(&p, ",");
82 if (!field || !*field)
83 break;
84
85 /* Collect the flags */
86 for (flags = 0; *field; field++) {
87 switch (*field) {
88 case 'a':
89 flags |= USB_QUIRK_STRING_FETCH_255;
90 break;
91 case 'b':
92 flags |= USB_QUIRK_RESET_RESUME;
93 break;
94 case 'c':
95 flags |= USB_QUIRK_NO_SET_INTF;
96 break;
97 case 'd':
98 flags |= USB_QUIRK_CONFIG_INTF_STRINGS;
99 break;
100 case 'e':
101 flags |= USB_QUIRK_RESET;
102 break;
103 case 'f':
104 flags |= USB_QUIRK_HONOR_BNUMINTERFACES;
105 break;
106 case 'g':
107 flags |= USB_QUIRK_DELAY_INIT;
108 break;
109 case 'h':
110 flags |= USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL;
111 break;
112 case 'i':
113 flags |= USB_QUIRK_DEVICE_QUALIFIER;
114 break;
115 case 'j':
116 flags |= USB_QUIRK_IGNORE_REMOTE_WAKEUP;
117 break;
118 case 'k':
119 flags |= USB_QUIRK_NO_LPM;
120 break;
121 case 'l':
122 flags |= USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL;
123 break;
124 case 'm':
125 flags |= USB_QUIRK_DISCONNECT_SUSPEND;
126 break;
Kai-Heng Feng4d8d5a32018-03-24 03:26:36 +0800127 case 'n':
128 flags |= USB_QUIRK_DELAY_CTRL_MSG;
129 break;
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800130 /* Ignore unrecognized flag characters */
131 }
132 }
133
134 quirk_list[i++] = (struct quirk_entry)
135 { .vid = vid, .pid = pid, .flags = flags };
136 }
137
138 if (i < quirk_count)
139 quirk_count = i;
140
141unlock:
142 mutex_unlock(&quirk_mutex);
143
Kai-Heng Fenga0305012018-03-24 03:26:35 +0800144 return 0;
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800145}
146
147static const struct kernel_param_ops quirks_param_ops = {
148 .set = quirks_param_set,
149 .get = param_get_string,
150};
151
152static struct kparam_string quirks_param_string = {
153 .maxlen = sizeof(quirks_param),
154 .string = quirks_param,
155};
156
157module_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
158MODULE_PARM_DESC(quirks, "Add/modify USB quirks by specifying quirks=vendorID:productID:quirks");
159
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200160/* Lists of quirky USB devices, split in device quirks and interface quirks.
161 * Device quirks are applied at the very beginning of the enumeration process,
162 * right after reading the device descriptor. They can thus only match on device
163 * information.
164 *
165 * Interface quirks are applied after reading all the configuration descriptors.
166 * They can match on both device and interface information.
167 *
168 * Note that the DELAY_INIT and HONOR_BNUMINTERFACES quirks do not make sense as
169 * interface quirks, as they only influence the enumeration process which is run
170 * before processing the interface quirks.
171 *
172 * Please keep the lists ordered by:
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100173 * 1) Vendor ID
174 * 2) Product ID
175 * 3) Class ID
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100176 */
177static const struct usb_device_id usb_quirk_list[] = {
Oliver Neukumce059162007-09-04 16:11:41 +0200178 /* CBM - Flash disk */
179 { USB_DEVICE(0x0204, 0x6025), .driver_info = USB_QUIRK_RESET_RESUME },
Alan Stern14f35462008-02-27 15:43:47 -0500180
Lukáš Lalinskýd9b29972017-01-20 19:46:34 +0100181 /* WORLDE easy key (easykey.25) MIDI controller */
182 { USB_DEVICE(0x0218, 0x0401), .driver_info =
183 USB_QUIRK_CONFIG_INTF_STRINGS },
184
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100185 /* HP 5300/5370C scanner */
Alan Stern14f35462008-02-27 15:43:47 -0500186 { USB_DEVICE(0x03f0, 0x0701), .driver_info =
187 USB_QUIRK_STRING_FETCH_255 },
Oliver Neukume6a20ff2007-08-28 10:34:22 +0200188
Oliver Neukumb68a42b2008-02-04 16:34:11 +0100189 /* Creative SB Audigy 2 NX */
190 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
191
Hans de Goede81099f92016-05-19 17:12:19 +0200192 /* USB3503 */
193 { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME },
194
Hans de Goede263e80b2014-11-24 11:22:38 +0100195 /* Microsoft Wireless Laser Mouse 6000 Receiver */
196 { USB_DEVICE(0x045e, 0x00e1), .driver_info = USB_QUIRK_RESET_RESUME },
197
Andreas Fleigbc009ec2012-12-05 16:17:49 +0100198 /* Microsoft LifeCam-VX700 v2.0 */
199 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
200
Dmitry Fleytman Dmitry Fleytman7f038d22017-12-19 06:02:04 +0200201 /* Logitech HD Pro Webcams C920, C920-C, C925e and C930e */
Julius Wernere0429362014-03-04 10:52:39 -0800202 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT },
Dmitry Fleytmana1279ef2017-08-25 10:38:35 +0300203 { USB_DEVICE(0x046d, 0x0841), .driver_info = USB_QUIRK_DELAY_INIT },
Julius Wernere0429362014-03-04 10:52:39 -0800204 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT },
Dmitry Fleytman Dmitry Fleytman7f038d22017-12-19 06:02:04 +0200205 { USB_DEVICE(0x046d, 0x085b), .driver_info = USB_QUIRK_DELAY_INIT },
Julius Wernere0429362014-03-04 10:52:39 -0800206
Vincent Palatin72194732015-10-01 14:10:22 -0700207 /* Logitech ConferenceCam CC3000e */
208 { USB_DEVICE(0x046d, 0x0847), .driver_info = USB_QUIRK_DELAY_INIT },
209 { USB_DEVICE(0x046d, 0x0848), .driver_info = USB_QUIRK_DELAY_INIT },
210
211 /* Logitech PTZ Pro Camera */
212 { USB_DEVICE(0x046d, 0x0853), .driver_info = USB_QUIRK_DELAY_INIT },
213
Laurent Pincharte387ef52012-07-19 12:39:14 +0200214 /* Logitech Quickcam Fusion */
215 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME },
Oliver Neukum2394d67e2011-09-13 08:42:21 +0200216
Laurent Pincharte387ef52012-07-19 12:39:14 +0200217 /* Logitech Quickcam Orbit MP */
218 { USB_DEVICE(0x046d, 0x08c2), .driver_info = USB_QUIRK_RESET_RESUME },
Oliver Neukum2394d67e2011-09-13 08:42:21 +0200219
Laurent Pincharte387ef52012-07-19 12:39:14 +0200220 /* Logitech Quickcam Pro for Notebook */
221 { USB_DEVICE(0x046d, 0x08c3), .driver_info = USB_QUIRK_RESET_RESUME },
Jon Levell5b253d82011-09-29 20:42:52 +0100222
Laurent Pincharte387ef52012-07-19 12:39:14 +0200223 /* Logitech Quickcam Pro 5000 */
224 { USB_DEVICE(0x046d, 0x08c5), .driver_info = USB_QUIRK_RESET_RESUME },
Oliver Neukum2394d67e2011-09-13 08:42:21 +0200225
Laurent Pincharte387ef52012-07-19 12:39:14 +0200226 /* Logitech Quickcam OEM Dell Notebook */
227 { USB_DEVICE(0x046d, 0x08c6), .driver_info = USB_QUIRK_RESET_RESUME },
Josh Boyer60c71ca2011-10-26 13:53:17 -0400228
Laurent Pincharte387ef52012-07-19 12:39:14 +0200229 /* Logitech Quickcam OEM Cisco VT Camera II */
230 { USB_DEVICE(0x046d, 0x08c7), .driver_info = USB_QUIRK_RESET_RESUME },
sordna0d145d72011-10-27 21:06:26 -0700231
Phil Dibowitz93362a82010-07-22 00:05:01 +0200232 /* Logitech Harmony 700-series */
233 { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT },
234
Alan Stern14f35462008-02-27 15:43:47 -0500235 /* Philips PSC805 audio device */
236 { USB_DEVICE(0x0471, 0x0155), .driver_info = USB_QUIRK_RESET_RESUME },
237
Yao-Wen Mao8484bf22015-08-31 14:24:09 +0800238 /* Plantronic Audio 655 DSP */
239 { USB_DEVICE(0x047f, 0xc008), .driver_info = USB_QUIRK_RESET_RESUME },
240
241 /* Plantronic Audio 648 USB */
242 { USB_DEVICE(0x047f, 0xc013), .driver_info = USB_QUIRK_RESET_RESUME },
243
Paul Mortier47f19c02010-07-09 13:18:50 +0100244 /* Artisman Watchdog Dongle */
245 { USB_DEVICE(0x04b4, 0x0526), .driver_info =
246 USB_QUIRK_CONFIG_INTF_STRINGS },
247
Alan Stern92fc7a82012-09-04 10:41:02 -0400248 /* Microchip Joss Optical infrared touchboard device */
249 { USB_DEVICE(0x04d8, 0x000c), .driver_info =
250 USB_QUIRK_CONFIG_INTF_STRINGS },
251
Oliver Neukum304ab4a2013-08-14 11:01:46 +0200252 /* CarrolTouch 4000U */
253 { USB_DEVICE(0x04e7, 0x0009), .driver_info = USB_QUIRK_RESET_RESUME },
254
255 /* CarrolTouch 4500U */
256 { USB_DEVICE(0x04e7, 0x0030), .driver_info = USB_QUIRK_RESET_RESUME },
257
Maciej Szmigiero72a012c2011-02-05 21:52:00 +0100258 /* Samsung Android phone modem - ID conflict with SPH-I500 */
259 { USB_DEVICE(0x04e8, 0x6601), .driver_info =
260 USB_QUIRK_CONFIG_INTF_STRINGS },
261
Johan Hovoldc68929f2014-08-25 17:51:27 +0200262 /* Elan Touchscreen */
263 { USB_DEVICE(0x04f3, 0x0089), .driver_info =
264 USB_QUIRK_DEVICE_QUALIFIER },
265
Adel Gadllah876af5d2014-10-09 09:29:29 +0200266 { USB_DEVICE(0x04f3, 0x009b), .driver_info =
267 USB_QUIRK_DEVICE_QUALIFIER },
268
Oliver Neukuma32c99e2014-11-17 17:11:42 +0100269 { USB_DEVICE(0x04f3, 0x010c), .driver_info =
270 USB_QUIRK_DEVICE_QUALIFIER },
271
Logan Gunthorpedc703ec2015-05-09 11:09:11 -0600272 { USB_DEVICE(0x04f3, 0x0125), .driver_info =
273 USB_QUIRK_DEVICE_QUALIFIER },
274
Adel Gadllahd7499472014-10-09 09:29:30 +0200275 { USB_DEVICE(0x04f3, 0x016f), .driver_info =
276 USB_QUIRK_DEVICE_QUALIFIER },
277
Joseph Salisbury25b1f9a2016-07-06 21:18:51 -0400278 { USB_DEVICE(0x04f3, 0x0381), .driver_info =
279 USB_QUIRK_NO_LPM },
280
Adrien Vergédf36c5b2015-11-24 16:02:04 +0100281 { USB_DEVICE(0x04f3, 0x21b8), .driver_info =
282 USB_QUIRK_DEVICE_QUALIFIER },
283
Oliver Neukumb68a42b2008-02-04 16:34:11 +0100284 /* Roland SC-8820 */
285 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME },
286
287 /* Edirol SD-20 */
288 { USB_DEVICE(0x0582, 0x0027), .driver_info = USB_QUIRK_RESET_RESUME },
289
Oliver Neukumbac6b032013-04-30 10:18:04 +0200290 /* Alcor Micro Corp. Hub */
291 { USB_DEVICE(0x058f, 0x9254), .driver_info = USB_QUIRK_RESET_RESUME },
292
Oliver Neukum90d95ef2008-06-17 11:56:55 -0400293 /* appletouch */
294 { USB_DEVICE(0x05ac, 0x021a), .driver_info = USB_QUIRK_RESET_RESUME },
295
Kai-Heng Fenge43a12f2017-11-14 01:31:15 -0500296 /* Genesys Logic hub, internally used by KY-688 USB 3.1 Type-C Hub */
297 { USB_DEVICE(0x05e3, 0x0612), .driver_info = USB_QUIRK_NO_LPM },
298
Oliver Neukumb9096d92017-12-12 16:11:30 +0100299 /* ELSA MicroLink 56K */
300 { USB_DEVICE(0x05cc, 0x2267), .driver_info = USB_QUIRK_RESET_RESUME },
301
Kai-Heng Feng7496cfe2017-08-08 17:51:27 +0800302 /* Genesys Logic hub, internally used by Moshi USB to Ethernet Adapter */
303 { USB_DEVICE(0x05e3, 0x0616), .driver_info = USB_QUIRK_NO_LPM },
304
René Rebe598eff62008-05-27 09:05:46 +0200305 /* Avision AV600U */
306 { USB_DEVICE(0x0638, 0x0a13), .driver_info =
307 USB_QUIRK_STRING_FETCH_255 },
308
Alan Stern1662e3a2009-03-18 14:28:53 -0400309 /* Saitek Cyborg Gold Joystick */
310 { USB_DEVICE(0x06a3, 0x0006), .driver_info =
311 USB_QUIRK_CONFIG_INTF_STRINGS },
312
Oliver Neukum35284b32012-01-03 09:58:54 +0100313 /* Guillemot Webcam Hercules Dualpix Exchange (2nd ID) */
Oliver Neukum2394d67e2011-09-13 08:42:21 +0200314 { USB_DEVICE(0x06f8, 0x0804), .driver_info = USB_QUIRK_RESET_RESUME },
315
Oliver Neukum35284b32012-01-03 09:58:54 +0100316 /* Guillemot Webcam Hercules Dualpix Exchange*/
317 { USB_DEVICE(0x06f8, 0x3005), .driver_info = USB_QUIRK_RESET_RESUME },
318
Steffen Müller166cb702012-04-30 13:05:34 +0200319 /* Midiman M-Audio Keystation 88es */
320 { USB_DEVICE(0x0763, 0x0192), .driver_info = USB_QUIRK_RESET_RESUME },
321
Lamarque Vieira Souza86833692007-09-04 12:15:08 -0300322 /* M-Systems Flash Disk Pioneers */
323 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
324
Samuel Thibault32433672017-03-13 20:50:08 +0100325 /* Baum Vario Ultra */
326 { USB_DEVICE(0x0904, 0x6101), .driver_info =
327 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
328 { USB_DEVICE(0x0904, 0x6102), .driver_info =
329 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
330 { USB_DEVICE(0x0904, 0x6103), .driver_info =
331 USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL },
332
Alan Stern3c18e302011-02-17 10:26:38 -0500333 /* Keytouch QWERTY Panel keyboard */
334 { USB_DEVICE(0x0926, 0x3333), .driver_info =
335 USB_QUIRK_CONFIG_INTF_STRINGS },
336
Alan Stern392e1d92008-03-11 10:20:12 -0400337 /* X-Rite/Gretag-Macbeth Eye-One Pro display colorimeter */
338 { USB_DEVICE(0x0971, 0x2000), .driver_info = USB_QUIRK_NO_SET_INTF },
339
Oliver Neukum63ab71d2010-07-14 18:26:22 +0200340 /* Broadcom BCM92035DGROM BT dongle */
341 { USB_DEVICE(0x0a5c, 0x2021), .driver_info = USB_QUIRK_RESET_RESUME },
342
Oliver Neukum4294bca2013-10-14 16:22:40 +0200343 /* MAYA44USB sound device */
344 { USB_DEVICE(0x0a92, 0x0091), .driver_info = USB_QUIRK_RESET_RESUME },
345
Hans de Goede81099f92016-05-19 17:12:19 +0200346 /* ASUS Base Station(T100) */
347 { USB_DEVICE(0x0b05, 0x17e0), .driver_info =
348 USB_QUIRK_IGNORE_REMOTE_WAKEUP },
349
Alan Stern14f35462008-02-27 15:43:47 -0500350 /* Action Semiconductor flash disk */
351 { USB_DEVICE(0x10d6, 0x2200), .driver_info =
352 USB_QUIRK_STRING_FETCH_255 },
Alan Stern6bc6cff2007-05-04 11:53:03 -0400353
Daniel Drake8dd8d2c2017-10-18 15:15:01 +0800354 /* Huawei 4G LTE module */
355 { USB_DEVICE(0x12d1, 0x15bb), .driver_info =
356 USB_QUIRK_DISCONNECT_SUSPEND },
357 { USB_DEVICE(0x12d1, 0x15c3), .driver_info =
358 USB_QUIRK_DISCONNECT_SUSPEND },
359
Lamarque Vieira Souza86833692007-09-04 12:15:08 -0300360 /* SKYMEDI USB_DRIVE */
361 { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME },
362
James P Michels IIIcd83ce92014-07-27 13:28:04 -0400363 /* Razer - Razer Blade Keyboard */
364 { USB_DEVICE(0x1532, 0x0116), .driver_info =
365 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
366
Hans de Goede317149c2010-03-29 12:03:17 +0200367 /* BUILDWIN Photo Frame */
368 { USB_DEVICE(0x1908, 0x1315), .driver_info =
369 USB_QUIRK_HONOR_BNUMINTERFACES },
370
Macpaul Line5dff0e2015-01-23 14:39:02 +0800371 /* Protocol and OTG Electrical Test Device */
372 { USB_DEVICE(0x1a0a, 0x0200), .driver_info =
373 USB_QUIRK_LINEAR_UFRAME_INTR_BINTERVAL },
374
Jack Stocker7a1646d2018-02-15 18:24:10 +0000375 /* Corsair K70 RGB */
376 { USB_DEVICE(0x1b1c, 0x1b13), .driver_info = USB_QUIRK_DELAY_INIT },
377
Kai-Heng Fengde3af5b2017-08-16 10:53:20 +0800378 /* Corsair Strafe RGB */
Danilo Krummrichcb88a052018-03-06 09:38:49 +0100379 { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT |
380 USB_QUIRK_DELAY_CTRL_MSG },
Kai-Heng Fengde3af5b2017-08-16 10:53:20 +0800381
Bernhard Rosenkraenzera0fea602017-11-03 16:46:02 +0100382 /* Corsair K70 LUX */
383 { USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT },
384
Felipe Balbi28115012017-10-03 11:16:43 +0300385 /* MIDI keyboard WORLDE MINI */
386 { USB_DEVICE(0x1c75, 0x0204), .driver_info =
387 USB_QUIRK_CONFIG_INTF_STRINGS },
388
Hans de Goede32cb0b32016-05-19 17:12:20 +0200389 /* Acer C120 LED Projector */
390 { USB_DEVICE(0x1de1, 0xc102), .driver_info = USB_QUIRK_NO_LPM },
391
Alan Sternad87e032015-12-10 15:27:21 -0500392 /* Blackmagic Design Intensity Shuttle */
393 { USB_DEVICE(0x1edb, 0xbd3b), .driver_info = USB_QUIRK_NO_LPM },
394
395 /* Blackmagic Design UltraStudio SDI */
396 { USB_DEVICE(0x1edb, 0xbd4f), .driver_info = USB_QUIRK_NO_LPM },
397
Devin Heitmueller68367962017-06-27 13:08:51 -0400398 /* Hauppauge HVR-950q */
399 { USB_DEVICE(0x2040, 0x7200), .driver_info =
400 USB_QUIRK_CONFIG_INTF_STRINGS },
401
Hans de Goede81099f92016-05-19 17:12:19 +0200402 /* INTEL VALUE SSD */
403 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
404
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100405 { } /* terminating entry must be last */
406};
407
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200408static const struct usb_device_id usb_interface_quirk_list[] = {
Laurent Pincharte387ef52012-07-19 12:39:14 +0200409 /* Logitech UVC Cameras */
410 { USB_VENDOR_AND_INTERFACE_INFO(0x046d, USB_CLASS_VIDEO, 1, 0),
411 .driver_info = USB_QUIRK_RESET_RESUME },
412
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200413 { } /* terminating entry must be last */
414};
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100415
Huang Rui78689432013-09-16 23:47:28 +0800416static const struct usb_device_id usb_amd_resume_quirk_list[] = {
417 /* Lenovo Mouse with Pixart controller */
418 { USB_DEVICE(0x17ef, 0x602e), .driver_info = USB_QUIRK_RESET_RESUME },
419
420 /* Pixart Mouse */
421 { USB_DEVICE(0x093a, 0x2500), .driver_info = USB_QUIRK_RESET_RESUME },
422 { USB_DEVICE(0x093a, 0x2510), .driver_info = USB_QUIRK_RESET_RESUME },
423 { USB_DEVICE(0x093a, 0x2521), .driver_info = USB_QUIRK_RESET_RESUME },
Sandeep Singhe7887872017-08-04 16:35:56 +0530424 { USB_DEVICE(0x03f0, 0x2b4a), .driver_info = USB_QUIRK_RESET_RESUME },
Huang Rui78689432013-09-16 23:47:28 +0800425
426 /* Logitech Optical Mouse M90/M100 */
427 { USB_DEVICE(0x046d, 0xc05a), .driver_info = USB_QUIRK_RESET_RESUME },
428
429 { } /* terminating entry must be last */
430};
431
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200432static bool usb_match_any_interface(struct usb_device *udev,
433 const struct usb_device_id *id)
434{
435 unsigned int i;
436
437 for (i = 0; i < udev->descriptor.bNumConfigurations; ++i) {
438 struct usb_host_config *cfg = &udev->config[i];
439 unsigned int j;
440
441 for (j = 0; j < cfg->desc.bNumInterfaces; ++j) {
442 struct usb_interface_cache *cache;
443 struct usb_host_interface *intf;
444
445 cache = cfg->intf_cache[j];
446 if (cache->num_altsetting == 0)
447 continue;
448
449 intf = &cache->altsetting[0];
450 if (usb_match_one_id_intf(udev, intf, id))
451 return true;
452 }
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100453 }
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200454
455 return false;
456}
457
Fengguang Wu00d5f282013-09-26 11:56:50 -0700458static int usb_amd_resume_quirk(struct usb_device *udev)
Huang Rui78689432013-09-16 23:47:28 +0800459{
460 struct usb_hcd *hcd;
461
462 hcd = bus_to_hcd(udev->bus);
463 /* The device should be attached directly to root hub */
464 if (udev->level == 1 && hcd->amd_resume_bug == 1)
465 return 1;
466
467 return 0;
468}
469
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800470static u32 usb_detect_static_quirks(struct usb_device *udev,
471 const struct usb_device_id *id)
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200472{
473 u32 quirks = 0;
474
475 for (; id->match_flags; id++) {
476 if (!usb_match_device(udev, id))
477 continue;
478
479 if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_INFO) &&
480 !usb_match_any_interface(udev, id))
481 continue;
482
483 quirks |= (u32)(id->driver_info);
484 }
485
486 return quirks;
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100487}
488
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800489static u32 usb_detect_dynamic_quirks(struct usb_device *udev)
490{
491 u16 vid = le16_to_cpu(udev->descriptor.idVendor);
492 u16 pid = le16_to_cpu(udev->descriptor.idProduct);
493 int i, flags = 0;
494
495 mutex_lock(&quirk_mutex);
496
497 for (i = 0; i < quirk_count; i++) {
498 if (vid == quirk_list[i].vid && pid == quirk_list[i].pid) {
499 flags = quirk_list[i].flags;
500 break;
501 }
502 }
503
504 mutex_unlock(&quirk_mutex);
505
506 return flags;
507}
508
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100509/*
510 * Detect any quirks the device has, and do any housekeeping for it if needed.
511 */
512void usb_detect_quirks(struct usb_device *udev)
513{
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800514 udev->quirks = usb_detect_static_quirks(udev, usb_quirk_list);
Huang Rui78689432013-09-16 23:47:28 +0800515
516 /*
517 * Pixart-based mice would trigger remote wakeup issue on AMD
518 * Yangtze chipset, so set them as RESET_RESUME flag.
519 */
520 if (usb_amd_resume_quirk(udev))
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800521 udev->quirks |= usb_detect_static_quirks(udev,
Huang Rui78689432013-09-16 23:47:28 +0800522 usb_amd_resume_quirk_list);
523
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800524 udev->quirks ^= usb_detect_dynamic_quirks(udev);
525
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100526 if (udev->quirks)
527 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200528 udev->quirks);
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100529
Julius Werner4f482032013-03-13 15:57:31 -0700530#ifdef CONFIG_USB_DEFAULT_PERSIST
531 if (!(udev->quirks & USB_QUIRK_RESET))
532 udev->persist_enabled = 1;
533#else
Alan Sternfeccc302008-03-03 15:15:59 -0500534 /* Hubs are automatically enabled for USB-PERSIST */
535 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
536 udev->persist_enabled = 1;
Julius Werner4f482032013-03-13 15:57:31 -0700537#endif /* CONFIG_USB_DEFAULT_PERSIST */
Oliver Neukum7ceec1f2007-01-26 14:26:21 +0100538}
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200539
540void usb_detect_interface_quirks(struct usb_device *udev)
541{
542 u32 quirks;
543
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800544 quirks = usb_detect_static_quirks(udev, usb_interface_quirk_list);
Laurent Pinchart80da2e02012-07-19 12:39:13 +0200545 if (quirks == 0)
546 return;
547
548 dev_dbg(&udev->dev, "USB interface quirks for this device: %x\n",
549 quirks);
550 udev->quirks |= quirks;
551}
Kai-Heng Feng027bd6c2018-03-20 00:26:06 +0800552
553void usb_release_quirk_list(void)
554{
555 mutex_lock(&quirk_mutex);
556 kfree(quirk_list);
557 quirk_list = NULL;
558 mutex_unlock(&quirk_mutex);
559}