xref: /linux/include/linux/device-id/usb.h (revision d2c9a99135da931377240942d44f3dea104cedb8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_DEVICE_ID_USB_H
3 #define LINUX_DEVICE_ID_USB_H
4 
5 #ifdef __KERNEL__
6 #include <linux/types.h>
7 typedef unsigned long kernel_ulong_t;
8 #endif
9 
10 /*
11  * Device table entry for "new style" table-driven USB drivers.
12  * User mode code can read these tables to choose which modules to load.
13  * Declare the table as a MODULE_DEVICE_TABLE.
14  *
15  * A probe() parameter will point to a matching entry from this table.
16  * Use the driver_info field for each match to hold information tied
17  * to that match:  device quirks, etc.
18  *
19  * Terminate the driver's table with an all-zeroes entry.
20  * Use the flag values to control which fields are compared.
21  */
22 
23 /**
24  * struct usb_device_id - identifies USB devices for probing and hotplugging
25  * @match_flags: Bit mask controlling which of the other fields are used to
26  *	match against new devices. Any field except for driver_info may be
27  *	used, although some only make sense in conjunction with other fields.
28  *	This is usually set by a USB_DEVICE_*() macro, which sets all
29  *	other fields in this structure except for driver_info.
30  * @idVendor: USB vendor ID for a device; numbers are assigned
31  *	by the USB forum to its members.
32  * @idProduct: Vendor-assigned product ID.
33  * @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
34  *	This is also used to identify individual product versions, for
35  *	a range consisting of a single device.
36  * @bcdDevice_hi: High end of version number range.  The range of product
37  *	versions is inclusive.
38  * @bDeviceClass: Class of device; numbers are assigned
39  *	by the USB forum.  Products may choose to implement classes,
40  *	or be vendor-specific.  Device classes specify behavior of all
41  *	the interfaces on a device.
42  * @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
43  * @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
44  * @bInterfaceClass: Class of interface; numbers are assigned
45  *	by the USB forum.  Products may choose to implement classes,
46  *	or be vendor-specific.  Interface classes specify behavior only
47  *	of a given interface; other interfaces may support other classes.
48  * @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
49  * @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
50  * @bInterfaceNumber: Number of interface; composite devices may use
51  *	fixed interface numbers to differentiate between vendor-specific
52  *	interfaces.
53  * @driver_info: Holds information used by the driver.  Usually it holds
54  *	a pointer to a descriptor understood by the driver, or perhaps
55  *	device flags.
56  *
57  * In most cases, drivers will create a table of device IDs by using
58  * USB_DEVICE(), or similar macros designed for that purpose.
59  * They will then export it to userspace using MODULE_DEVICE_TABLE(),
60  * and provide it to the USB core through their usb_driver structure.
61  *
62  * See the usb_match_id() function for information about how matches are
63  * performed.  Briefly, you will normally use one of several macros to help
64  * construct these entries.  Each entry you provide will either identify
65  * one or more specific products, or will identify a class of products
66  * which have agreed to behave the same.  You should put the more specific
67  * matches towards the beginning of your table, so that driver_info can
68  * record quirks of specific products.
69  */
70 struct usb_device_id {
71 	/* which fields to match against? */
72 	__u16		match_flags;
73 
74 	/* Used for product specific matches; range is inclusive */
75 	__u16		idVendor;
76 	__u16		idProduct;
77 	__u16		bcdDevice_lo;
78 	__u16		bcdDevice_hi;
79 
80 	/* Used for device class matches */
81 	__u8		bDeviceClass;
82 	__u8		bDeviceSubClass;
83 	__u8		bDeviceProtocol;
84 
85 	/* Used for interface class matches */
86 	__u8		bInterfaceClass;
87 	__u8		bInterfaceSubClass;
88 	__u8		bInterfaceProtocol;
89 
90 	/* Used for vendor-specific interface matches */
91 	__u8		bInterfaceNumber;
92 
93 	/* not matched against */
94 	kernel_ulong_t	driver_info
95 		__attribute__((aligned(sizeof(kernel_ulong_t))));
96 };
97 
98 /* Some useful macros to use to create struct usb_device_id */
99 #define USB_DEVICE_ID_MATCH_VENDOR		0x0001
100 #define USB_DEVICE_ID_MATCH_PRODUCT		0x0002
101 #define USB_DEVICE_ID_MATCH_DEV_LO		0x0004
102 #define USB_DEVICE_ID_MATCH_DEV_HI		0x0008
103 #define USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
104 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
105 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
106 #define USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
107 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
108 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
109 #define USB_DEVICE_ID_MATCH_INT_NUMBER		0x0400
110 
111 #endif /* ifndef LINUX_DEVICE_ID_USB_H */
112