xref: /openbmc/linux/drivers/usb/core/quirks.c (revision 64c70b1c)
1 /*
2  * USB device quirk handling logic and table
3  *
4  * Copyright (c) 2007 Oliver Neukum
5  * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation, version 2.
10  *
11  *
12  */
13 
14 #include <linux/usb.h>
15 #include <linux/usb/quirks.h>
16 #include "usb.h"
17 
18 /* List of quirky USB devices.  Please keep this list ordered by:
19  * 	1) Vendor ID
20  * 	2) Product ID
21  * 	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...
29  */
30 static const struct usb_device_id usb_quirk_list[] = {
31 	/* HP 5300/5370C scanner */
32 	{ USB_DEVICE(0x03f0, 0x0701), .driver_info = USB_QUIRK_STRING_FETCH_255 },
33 	/* Seiko Epson Corp - Perfection 1670 */
34 	{ USB_DEVICE(0x04b8, 0x011f), .driver_info = USB_QUIRK_NO_AUTOSUSPEND },
35 	/* Elsa MicroLink 56k (V.250) */
36 	{ USB_DEVICE(0x05cc, 0x2267), .driver_info = USB_QUIRK_NO_AUTOSUSPEND },
37 
38 	{ }  /* terminating entry must be last */
39 };
40 
41 static void usb_autosuspend_quirk(struct usb_device *udev)
42 {
43 #ifdef	CONFIG_USB_SUSPEND
44 	/* disable autosuspend, but allow the user to re-enable it via sysfs */
45 	udev->autosuspend_disabled = 1;
46 #endif
47 }
48 
49 static const struct usb_device_id *find_id(struct usb_device *udev)
50 {
51 	const struct usb_device_id *id = usb_quirk_list;
52 
53 	for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
54 			id->driver_info; id++) {
55 		if (usb_match_device(udev, id))
56 			return id;
57 	}
58 	return NULL;
59 }
60 
61 /*
62  * Detect any quirks the device has, and do any housekeeping for it if needed.
63  */
64 void usb_detect_quirks(struct usb_device *udev)
65 {
66 	const struct usb_device_id *id = usb_quirk_list;
67 
68 	id = find_id(udev);
69 	if (id)
70 		udev->quirks = (u32)(id->driver_info);
71 	if (udev->quirks)
72 		dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
73 				udev->quirks);
74 
75 	/* do any special quirk handling here if needed */
76 	if (udev->quirks & USB_QUIRK_NO_AUTOSUSPEND)
77 		usb_autosuspend_quirk(udev);
78 }
79