1515#include <linux/usb/quirks.h>
1616#include "usb.h"
1717
18- /* List of quirky USB devices. Please keep this list ordered by:
18+ /* Lists of quirky USB devices, split in device quirks and interface quirks.
19+ * Device quirks are applied at the very beginning of the enumeration process,
20+ * right after reading the device descriptor. They can thus only match on device
21+ * information.
22+ *
23+ * Interface quirks are applied after reading all the configuration descriptors.
24+ * They can match on both device and interface information.
25+ *
26+ * Note that the DELAY_INIT and HONOR_BNUMINTERFACES quirks do not make sense as
27+ * interface quirks, as they only influence the enumeration process which is run
28+ * before processing the interface quirks.
29+ *
30+ * Please keep the lists ordered by:
1931 * 1) Vendor ID
2032 * 2) Product ID
2133 * 3) Class ID
22- *
23- * as we want specific devices to be overridden first, and only after that, any
24- * class specific quirks.
25- *
26- * Right now the logic aborts if it finds a valid device in the table, we might
27- * want to change that in the future if it turns out that a whole class of
28- * devices is broken...
2934 */
3035static const struct usb_device_id usb_quirk_list [] = {
3136 /* CBM - Flash disk */
@@ -156,31 +161,64 @@ static const struct usb_device_id usb_quirk_list[] = {
156161 { } /* terminating entry must be last */
157162};
158163
159- static const struct usb_device_id * find_id (struct usb_device * udev )
164+ static const struct usb_device_id usb_interface_quirk_list [] = {
165+ { } /* terminating entry must be last */
166+ };
167+
168+ static bool usb_match_any_interface (struct usb_device * udev ,
169+ const struct usb_device_id * id )
170+ {
171+ unsigned int i ;
172+
173+ for (i = 0 ; i < udev -> descriptor .bNumConfigurations ; ++ i ) {
174+ struct usb_host_config * cfg = & udev -> config [i ];
175+ unsigned int j ;
176+
177+ for (j = 0 ; j < cfg -> desc .bNumInterfaces ; ++ j ) {
178+ struct usb_interface_cache * cache ;
179+ struct usb_host_interface * intf ;
180+
181+ cache = cfg -> intf_cache [j ];
182+ if (cache -> num_altsetting == 0 )
183+ continue ;
184+
185+ intf = & cache -> altsetting [0 ];
186+ if (usb_match_one_id_intf (udev , intf , id ))
187+ return true;
188+ }
189+ }
190+
191+ return false;
192+ }
193+
194+ static u32 __usb_detect_quirks (struct usb_device * udev ,
195+ const struct usb_device_id * id )
160196{
161- const struct usb_device_id * id = usb_quirk_list ;
197+ u32 quirks = 0 ;
162198
163- for (; id -> idVendor || id -> bDeviceClass || id -> bInterfaceClass ||
164- id -> driver_info ; id ++ ) {
165- if (usb_match_device (udev , id ))
166- return id ;
199+ for (; id -> match_flags ; id ++ ) {
200+ if (!usb_match_device (udev , id ))
201+ continue ;
202+
203+ if ((id -> match_flags & USB_DEVICE_ID_MATCH_INT_INFO ) &&
204+ !usb_match_any_interface (udev , id ))
205+ continue ;
206+
207+ quirks |= (u32 )(id -> driver_info );
167208 }
168- return NULL ;
209+
210+ return quirks ;
169211}
170212
171213/*
172214 * Detect any quirks the device has, and do any housekeeping for it if needed.
173215 */
174216void usb_detect_quirks (struct usb_device * udev )
175217{
176- const struct usb_device_id * id = usb_quirk_list ;
177-
178- id = find_id (udev );
179- if (id )
180- udev -> quirks = (u32 )(id -> driver_info );
218+ udev -> quirks = __usb_detect_quirks (udev , usb_quirk_list );
181219 if (udev -> quirks )
182220 dev_dbg (& udev -> dev , "USB quirks for this device: %x\n" ,
183- udev -> quirks );
221+ udev -> quirks );
184222
185223 /* For the present, all devices default to USB-PERSIST enabled */
186224#if 0 /* was: #ifdef CONFIG_PM */
@@ -197,3 +235,16 @@ void usb_detect_quirks(struct usb_device *udev)
197235 udev -> persist_enabled = 1 ;
198236#endif /* CONFIG_PM */
199237}
238+
239+ void usb_detect_interface_quirks (struct usb_device * udev )
240+ {
241+ u32 quirks ;
242+
243+ quirks = __usb_detect_quirks (udev , usb_interface_quirk_list );
244+ if (quirks == 0 )
245+ return ;
246+
247+ dev_dbg (& udev -> dev , "USB interface quirks for this device: %x\n" ,
248+ quirks );
249+ udev -> quirks |= quirks ;
250+ }
0 commit comments