123cd1385SRemy Bohmer /*
223cd1385SRemy Bohmer * This file holds USB constants and structures that are needed for
323cd1385SRemy Bohmer * USB device APIs. These are used by the USB device model, which is
423cd1385SRemy Bohmer * defined in chapter 9 of the USB 2.0 specification and in the
523cd1385SRemy Bohmer * Wireless USB 1.0 (spread around). Linux has several APIs in C that
623cd1385SRemy Bohmer * need these:
723cd1385SRemy Bohmer *
823cd1385SRemy Bohmer * - the master/host side Linux-USB kernel driver API;
923cd1385SRemy Bohmer * - the "usbfs" user space API; and
1023cd1385SRemy Bohmer * - the Linux "gadget" slave/device/peripheral side driver API.
1123cd1385SRemy Bohmer *
1223cd1385SRemy Bohmer * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
1323cd1385SRemy Bohmer * act either as a USB master/host or as a USB slave/device. That means
1423cd1385SRemy Bohmer * the master and slave side APIs benefit from working well together.
1523cd1385SRemy Bohmer *
1623cd1385SRemy Bohmer * There's also "Wireless USB", using low power short range radios for
1723cd1385SRemy Bohmer * peripheral interconnection but otherwise building on the USB framework.
1823cd1385SRemy Bohmer *
1923cd1385SRemy Bohmer * Note all descriptors are declared '__attribute__((packed))' so that:
2023cd1385SRemy Bohmer *
2123cd1385SRemy Bohmer * [a] they never get padded, either internally (USB spec writers
2223cd1385SRemy Bohmer * probably handled that) or externally;
2323cd1385SRemy Bohmer *
2423cd1385SRemy Bohmer * [b] so that accessing bigger-than-a-bytes fields will never
2523cd1385SRemy Bohmer * generate bus errors on any platform, even when the location of
2623cd1385SRemy Bohmer * its descriptor inside a bundle isn't "naturally aligned", and
2723cd1385SRemy Bohmer *
2823cd1385SRemy Bohmer * [c] for consistency, removing all doubt even when it appears to
2923cd1385SRemy Bohmer * someone that the two other points are non-issues for that
3023cd1385SRemy Bohmer * particular descriptor type.
3123cd1385SRemy Bohmer */
3223cd1385SRemy Bohmer
3323cd1385SRemy Bohmer #ifndef __LINUX_USB_CH9_H
3423cd1385SRemy Bohmer #define __LINUX_USB_CH9_H
3523cd1385SRemy Bohmer
3623cd1385SRemy Bohmer #include <linux/types.h> /* __u8 etc */
3782651c39SIlya Yanok #include <asm/byteorder.h> /* le16_to_cpu */
38f903a20dSVivek Gautam #include <asm/unaligned.h> /* get_unaligned() */
3923cd1385SRemy Bohmer
4023cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
4123cd1385SRemy Bohmer
4223cd1385SRemy Bohmer /* CONTROL REQUEST SUPPORT */
4323cd1385SRemy Bohmer
4423cd1385SRemy Bohmer /*
4523cd1385SRemy Bohmer * USB directions
4623cd1385SRemy Bohmer *
4723cd1385SRemy Bohmer * This bit flag is used in endpoint descriptors' bEndpointAddress field.
4823cd1385SRemy Bohmer * It's also one of three fields in control requests bRequestType.
4923cd1385SRemy Bohmer */
5023cd1385SRemy Bohmer #define USB_DIR_OUT 0 /* to device */
5123cd1385SRemy Bohmer #define USB_DIR_IN 0x80 /* to host */
5223cd1385SRemy Bohmer
5323cd1385SRemy Bohmer /*
5423cd1385SRemy Bohmer * USB types, the second of three bRequestType fields
5523cd1385SRemy Bohmer */
5623cd1385SRemy Bohmer #define USB_TYPE_MASK (0x03 << 5)
5723cd1385SRemy Bohmer #define USB_TYPE_STANDARD (0x00 << 5)
5823cd1385SRemy Bohmer #define USB_TYPE_CLASS (0x01 << 5)
5923cd1385SRemy Bohmer #define USB_TYPE_VENDOR (0x02 << 5)
6023cd1385SRemy Bohmer #define USB_TYPE_RESERVED (0x03 << 5)
6123cd1385SRemy Bohmer
6223cd1385SRemy Bohmer /*
6323cd1385SRemy Bohmer * USB recipients, the third of three bRequestType fields
6423cd1385SRemy Bohmer */
6523cd1385SRemy Bohmer #define USB_RECIP_MASK 0x1f
6623cd1385SRemy Bohmer #define USB_RECIP_DEVICE 0x00
6723cd1385SRemy Bohmer #define USB_RECIP_INTERFACE 0x01
6823cd1385SRemy Bohmer #define USB_RECIP_ENDPOINT 0x02
6923cd1385SRemy Bohmer #define USB_RECIP_OTHER 0x03
7023cd1385SRemy Bohmer /* From Wireless USB 1.0 */
7123cd1385SRemy Bohmer #define USB_RECIP_PORT 0x04
7223cd1385SRemy Bohmer #define USB_RECIP_RPIPE 0x05
7323cd1385SRemy Bohmer
7423cd1385SRemy Bohmer /*
7523cd1385SRemy Bohmer * Standard requests, for the bRequest field of a SETUP packet.
7623cd1385SRemy Bohmer *
7723cd1385SRemy Bohmer * These are qualified by the bRequestType field, so that for example
7823cd1385SRemy Bohmer * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
7923cd1385SRemy Bohmer * by a GET_STATUS request.
8023cd1385SRemy Bohmer */
8123cd1385SRemy Bohmer #define USB_REQ_GET_STATUS 0x00
8223cd1385SRemy Bohmer #define USB_REQ_CLEAR_FEATURE 0x01
8323cd1385SRemy Bohmer #define USB_REQ_SET_FEATURE 0x03
8423cd1385SRemy Bohmer #define USB_REQ_SET_ADDRESS 0x05
8523cd1385SRemy Bohmer #define USB_REQ_GET_DESCRIPTOR 0x06
8623cd1385SRemy Bohmer #define USB_REQ_SET_DESCRIPTOR 0x07
8723cd1385SRemy Bohmer #define USB_REQ_GET_CONFIGURATION 0x08
8823cd1385SRemy Bohmer #define USB_REQ_SET_CONFIGURATION 0x09
8923cd1385SRemy Bohmer #define USB_REQ_GET_INTERFACE 0x0A
9023cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE 0x0B
9123cd1385SRemy Bohmer #define USB_REQ_SYNCH_FRAME 0x0C
9282651c39SIlya Yanok #define USB_REQ_SET_SEL 0x30
9382651c39SIlya Yanok #define USB_REQ_SET_ISOCH_DELAY 0x31
9423cd1385SRemy Bohmer
9523cd1385SRemy Bohmer #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
9623cd1385SRemy Bohmer #define USB_REQ_GET_ENCRYPTION 0x0E
9723cd1385SRemy Bohmer #define USB_REQ_RPIPE_ABORT 0x0E
9823cd1385SRemy Bohmer #define USB_REQ_SET_HANDSHAKE 0x0F
9923cd1385SRemy Bohmer #define USB_REQ_RPIPE_RESET 0x0F
10023cd1385SRemy Bohmer #define USB_REQ_GET_HANDSHAKE 0x10
10123cd1385SRemy Bohmer #define USB_REQ_SET_CONNECTION 0x11
10223cd1385SRemy Bohmer #define USB_REQ_SET_SECURITY_DATA 0x12
10323cd1385SRemy Bohmer #define USB_REQ_GET_SECURITY_DATA 0x13
10423cd1385SRemy Bohmer #define USB_REQ_SET_WUSB_DATA 0x14
10523cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
10623cd1385SRemy Bohmer #define USB_REQ_LOOPBACK_DATA_READ 0x16
10723cd1385SRemy Bohmer #define USB_REQ_SET_INTERFACE_DS 0x17
10823cd1385SRemy Bohmer
10982651c39SIlya Yanok /* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command,
11082651c39SIlya Yanok * used by hubs to put ports into a new L1 suspend state, except that it
11182651c39SIlya Yanok * forgot to define its number ...
11282651c39SIlya Yanok */
11382651c39SIlya Yanok
11423cd1385SRemy Bohmer /*
11523cd1385SRemy Bohmer * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
11623cd1385SRemy Bohmer * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
11782651c39SIlya Yanok * are at most sixteen features of each type.) Hubs may also support a
11882651c39SIlya Yanok * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
11923cd1385SRemy Bohmer */
12023cd1385SRemy Bohmer #define USB_DEVICE_SELF_POWERED 0 /* (read only) */
12123cd1385SRemy Bohmer #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
12223cd1385SRemy Bohmer #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
12323cd1385SRemy Bohmer #define USB_DEVICE_BATTERY 2 /* (wireless) */
12423cd1385SRemy Bohmer #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
12523cd1385SRemy Bohmer #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
12623cd1385SRemy Bohmer #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
12723cd1385SRemy Bohmer #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
12823cd1385SRemy Bohmer #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
12923cd1385SRemy Bohmer
13082651c39SIlya Yanok /*
13182651c39SIlya Yanok * Test Mode Selectors
13282651c39SIlya Yanok * See USB 2.0 spec Table 9-7
13382651c39SIlya Yanok */
13482651c39SIlya Yanok #define TEST_J 1
13582651c39SIlya Yanok #define TEST_K 2
13682651c39SIlya Yanok #define TEST_SE0_NAK 3
13782651c39SIlya Yanok #define TEST_PACKET 4
13882651c39SIlya Yanok #define TEST_FORCE_EN 5
13982651c39SIlya Yanok
14082651c39SIlya Yanok /*
14182651c39SIlya Yanok * New Feature Selectors as added by USB 3.0
14282651c39SIlya Yanok * See USB 3.0 spec Table 9-6
14382651c39SIlya Yanok */
14482651c39SIlya Yanok #define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */
14582651c39SIlya Yanok #define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */
14682651c39SIlya Yanok #define USB_DEVICE_LTM_ENABLE 50 /* dev may send LTM */
14782651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND 0 /* function suspend */
14882651c39SIlya Yanok
14982651c39SIlya Yanok #define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
15082651c39SIlya Yanok /*
15182651c39SIlya Yanok * Suspend Options, Table 9-7 USB 3.0 spec
15282651c39SIlya Yanok */
15382651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
15482651c39SIlya Yanok #define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))
15582651c39SIlya Yanok
15623cd1385SRemy Bohmer #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
15723cd1385SRemy Bohmer
15882651c39SIlya Yanok /* Bit array elements as returned by the USB_REQ_GET_STATUS request. */
15982651c39SIlya Yanok #define USB_DEV_STAT_U1_ENABLED 2 /* transition into U1 state */
16082651c39SIlya Yanok #define USB_DEV_STAT_U2_ENABLED 3 /* transition into U2 state */
16182651c39SIlya Yanok #define USB_DEV_STAT_LTM_ENABLED 4 /* Latency tolerance messages */
16223cd1385SRemy Bohmer
16323cd1385SRemy Bohmer /**
16423cd1385SRemy Bohmer * struct usb_ctrlrequest - SETUP data for a USB device control request
16523cd1385SRemy Bohmer * @bRequestType: matches the USB bmRequestType field
16623cd1385SRemy Bohmer * @bRequest: matches the USB bRequest field
16723cd1385SRemy Bohmer * @wValue: matches the USB wValue field (le16 byte order)
16823cd1385SRemy Bohmer * @wIndex: matches the USB wIndex field (le16 byte order)
16923cd1385SRemy Bohmer * @wLength: matches the USB wLength field (le16 byte order)
17023cd1385SRemy Bohmer *
17123cd1385SRemy Bohmer * This structure is used to send control requests to a USB device. It matches
17223cd1385SRemy Bohmer * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the
17323cd1385SRemy Bohmer * USB spec for a fuller description of the different fields, and what they are
17423cd1385SRemy Bohmer * used for.
17523cd1385SRemy Bohmer *
17623cd1385SRemy Bohmer * Note that the driver for any interface can issue control requests.
17723cd1385SRemy Bohmer * For most devices, interfaces don't coordinate with each other, so
17823cd1385SRemy Bohmer * such requests may be made at any time.
17923cd1385SRemy Bohmer */
18023cd1385SRemy Bohmer struct usb_ctrlrequest {
18123cd1385SRemy Bohmer __u8 bRequestType;
18223cd1385SRemy Bohmer __u8 bRequest;
18323cd1385SRemy Bohmer __le16 wValue;
18423cd1385SRemy Bohmer __le16 wIndex;
18523cd1385SRemy Bohmer __le16 wLength;
18623cd1385SRemy Bohmer } __attribute__ ((packed));
18723cd1385SRemy Bohmer
18823cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
18923cd1385SRemy Bohmer
19023cd1385SRemy Bohmer /*
19123cd1385SRemy Bohmer * STANDARD DESCRIPTORS ... as returned by GET_DESCRIPTOR, or
19223cd1385SRemy Bohmer * (rarely) accepted by SET_DESCRIPTOR.
19323cd1385SRemy Bohmer *
19423cd1385SRemy Bohmer * Note that all multi-byte values here are encoded in little endian
19582651c39SIlya Yanok * byte order "on the wire". Within the kernel and when exposed
19682651c39SIlya Yanok * through the Linux-USB APIs, they are not converted to cpu byte
19782651c39SIlya Yanok * order; it is the responsibility of the client code to do this.
19882651c39SIlya Yanok * The single exception is when device and configuration descriptors (but
19982651c39SIlya Yanok * not other descriptors) are read from usbfs (i.e. /proc/bus/usb/BBB/DDD);
20082651c39SIlya Yanok * in this case the fields are converted to host endianness by the kernel.
20123cd1385SRemy Bohmer */
20223cd1385SRemy Bohmer
20323cd1385SRemy Bohmer /*
20423cd1385SRemy Bohmer * Descriptor types ... USB 2.0 spec table 9.5
20523cd1385SRemy Bohmer */
20623cd1385SRemy Bohmer #define USB_DT_DEVICE 0x01
20723cd1385SRemy Bohmer #define USB_DT_CONFIG 0x02
20823cd1385SRemy Bohmer #define USB_DT_STRING 0x03
20923cd1385SRemy Bohmer #define USB_DT_INTERFACE 0x04
21023cd1385SRemy Bohmer #define USB_DT_ENDPOINT 0x05
21123cd1385SRemy Bohmer #define USB_DT_DEVICE_QUALIFIER 0x06
21223cd1385SRemy Bohmer #define USB_DT_OTHER_SPEED_CONFIG 0x07
21323cd1385SRemy Bohmer #define USB_DT_INTERFACE_POWER 0x08
21423cd1385SRemy Bohmer /* these are from a minor usb 2.0 revision (ECN) */
21523cd1385SRemy Bohmer #define USB_DT_OTG 0x09
21623cd1385SRemy Bohmer #define USB_DT_DEBUG 0x0a
21723cd1385SRemy Bohmer #define USB_DT_INTERFACE_ASSOCIATION 0x0b
21823cd1385SRemy Bohmer /* these are from the Wireless USB spec */
21923cd1385SRemy Bohmer #define USB_DT_SECURITY 0x0c
22023cd1385SRemy Bohmer #define USB_DT_KEY 0x0d
22123cd1385SRemy Bohmer #define USB_DT_ENCRYPTION_TYPE 0x0e
22223cd1385SRemy Bohmer #define USB_DT_BOS 0x0f
22323cd1385SRemy Bohmer #define USB_DT_DEVICE_CAPABILITY 0x10
22423cd1385SRemy Bohmer #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
22523cd1385SRemy Bohmer #define USB_DT_WIRE_ADAPTER 0x21
22623cd1385SRemy Bohmer #define USB_DT_RPIPE 0x22
22782651c39SIlya Yanok #define USB_DT_CS_RADIO_CONTROL 0x23
22882651c39SIlya Yanok /* From the T10 UAS specification */
22982651c39SIlya Yanok #define USB_DT_PIPE_USAGE 0x24
23082651c39SIlya Yanok /* From the USB 3.0 spec */
23182651c39SIlya Yanok #define USB_DT_SS_ENDPOINT_COMP 0x30
232d8a26f03SSimon Glass /* From HID 1.11 spec */
233d8a26f03SSimon Glass #define USB_DT_HID_REPORT 0x22
23423cd1385SRemy Bohmer
23523cd1385SRemy Bohmer /* Conventional codes for class-specific descriptors. The convention is
23623cd1385SRemy Bohmer * defined in the USB "Common Class" Spec (3.11). Individual class specs
23723cd1385SRemy Bohmer * are authoritative for their usage, not the "common class" writeup.
23823cd1385SRemy Bohmer */
23923cd1385SRemy Bohmer #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE)
24023cd1385SRemy Bohmer #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG)
24123cd1385SRemy Bohmer #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING)
24223cd1385SRemy Bohmer #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE)
24323cd1385SRemy Bohmer #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT)
24423cd1385SRemy Bohmer
24523cd1385SRemy Bohmer /* All standard descriptors have these 2 fields at the beginning */
24623cd1385SRemy Bohmer struct usb_descriptor_header {
24723cd1385SRemy Bohmer __u8 bLength;
24823cd1385SRemy Bohmer __u8 bDescriptorType;
24923cd1385SRemy Bohmer } __attribute__ ((packed));
25023cd1385SRemy Bohmer
25182651c39SIlya Yanok
25282651c39SIlya Yanok /*-------------------------------------------------------------------------*/
25382651c39SIlya Yanok
25482651c39SIlya Yanok /* USB_DT_DEVICE: Device descriptor */
25582651c39SIlya Yanok struct usb_device_descriptor {
25682651c39SIlya Yanok __u8 bLength;
25782651c39SIlya Yanok __u8 bDescriptorType;
25882651c39SIlya Yanok
25982651c39SIlya Yanok __le16 bcdUSB;
26082651c39SIlya Yanok __u8 bDeviceClass;
26182651c39SIlya Yanok __u8 bDeviceSubClass;
26282651c39SIlya Yanok __u8 bDeviceProtocol;
26382651c39SIlya Yanok __u8 bMaxPacketSize0;
26482651c39SIlya Yanok __le16 idVendor;
26582651c39SIlya Yanok __le16 idProduct;
26682651c39SIlya Yanok __le16 bcdDevice;
26782651c39SIlya Yanok __u8 iManufacturer;
26882651c39SIlya Yanok __u8 iProduct;
26982651c39SIlya Yanok __u8 iSerialNumber;
27082651c39SIlya Yanok __u8 bNumConfigurations;
27182651c39SIlya Yanok } __attribute__ ((packed));
27282651c39SIlya Yanok
27323cd1385SRemy Bohmer #define USB_DT_DEVICE_SIZE 18
27423cd1385SRemy Bohmer
27523cd1385SRemy Bohmer
27623cd1385SRemy Bohmer /*
27723cd1385SRemy Bohmer * Device and/or Interface Class codes
27823cd1385SRemy Bohmer * as found in bDeviceClass or bInterfaceClass
27923cd1385SRemy Bohmer * and defined by www.usb.org documents
28023cd1385SRemy Bohmer */
28123cd1385SRemy Bohmer #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
28223cd1385SRemy Bohmer #define USB_CLASS_AUDIO 1
28323cd1385SRemy Bohmer #define USB_CLASS_COMM 2
28423cd1385SRemy Bohmer #define USB_CLASS_HID 3
28523cd1385SRemy Bohmer #define USB_CLASS_PHYSICAL 5
28623cd1385SRemy Bohmer #define USB_CLASS_STILL_IMAGE 6
28723cd1385SRemy Bohmer #define USB_CLASS_PRINTER 7
28823cd1385SRemy Bohmer #define USB_CLASS_MASS_STORAGE 8
28923cd1385SRemy Bohmer #define USB_CLASS_HUB 9
29023cd1385SRemy Bohmer #define USB_CLASS_CDC_DATA 0x0a
29123cd1385SRemy Bohmer #define USB_CLASS_CSCID 0x0b /* chip+ smart card */
29223cd1385SRemy Bohmer #define USB_CLASS_CONTENT_SEC 0x0d /* content security */
29323cd1385SRemy Bohmer #define USB_CLASS_VIDEO 0x0e
29423cd1385SRemy Bohmer #define USB_CLASS_WIRELESS_CONTROLLER 0xe0
29523cd1385SRemy Bohmer #define USB_CLASS_MISC 0xef
29623cd1385SRemy Bohmer #define USB_CLASS_APP_SPEC 0xfe
29723cd1385SRemy Bohmer #define USB_CLASS_VENDOR_SPEC 0xff
29823cd1385SRemy Bohmer
29982651c39SIlya Yanok #define USB_SUBCLASS_VENDOR_SPEC 0xff
30082651c39SIlya Yanok
30123cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
30223cd1385SRemy Bohmer
30323cd1385SRemy Bohmer /* USB_DT_CONFIG: Configuration descriptor information.
30423cd1385SRemy Bohmer *
30523cd1385SRemy Bohmer * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
30623cd1385SRemy Bohmer * descriptor type is different. Highspeed-capable devices can look
30723cd1385SRemy Bohmer * different depending on what speed they're currently running. Only
30823cd1385SRemy Bohmer * devices with a USB_DT_DEVICE_QUALIFIER have any OTHER_SPEED_CONFIG
30923cd1385SRemy Bohmer * descriptors.
31023cd1385SRemy Bohmer */
31123cd1385SRemy Bohmer struct usb_config_descriptor {
31223cd1385SRemy Bohmer __u8 bLength;
31323cd1385SRemy Bohmer __u8 bDescriptorType;
31423cd1385SRemy Bohmer
31523cd1385SRemy Bohmer __le16 wTotalLength;
31623cd1385SRemy Bohmer __u8 bNumInterfaces;
31723cd1385SRemy Bohmer __u8 bConfigurationValue;
31823cd1385SRemy Bohmer __u8 iConfiguration;
31923cd1385SRemy Bohmer __u8 bmAttributes;
32023cd1385SRemy Bohmer __u8 bMaxPower;
32123cd1385SRemy Bohmer } __attribute__ ((packed));
32223cd1385SRemy Bohmer
32323cd1385SRemy Bohmer #define USB_DT_CONFIG_SIZE 9
32423cd1385SRemy Bohmer
32523cd1385SRemy Bohmer /* from config descriptor bmAttributes */
32623cd1385SRemy Bohmer #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */
32723cd1385SRemy Bohmer #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */
32823cd1385SRemy Bohmer #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */
32923cd1385SRemy Bohmer #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */
33023cd1385SRemy Bohmer
33182651c39SIlya Yanok /*-------------------------------------------------------------------------*/
33282651c39SIlya Yanok
33382651c39SIlya Yanok /* USB_DT_STRING: String descriptor */
33482651c39SIlya Yanok struct usb_string_descriptor {
33582651c39SIlya Yanok __u8 bLength;
33682651c39SIlya Yanok __u8 bDescriptorType;
33782651c39SIlya Yanok
33882651c39SIlya Yanok __le16 wData[1]; /* UTF-16LE encoded */
33982651c39SIlya Yanok } __attribute__ ((packed));
34082651c39SIlya Yanok
34123cd1385SRemy Bohmer /* note that "string" zero is special, it holds language codes that
34223cd1385SRemy Bohmer * the device supports, not Unicode characters.
34323cd1385SRemy Bohmer */
34423cd1385SRemy Bohmer
34582651c39SIlya Yanok /*-------------------------------------------------------------------------*/
34682651c39SIlya Yanok
34782651c39SIlya Yanok /* USB_DT_INTERFACE: Interface descriptor */
34882651c39SIlya Yanok struct usb_interface_descriptor {
34982651c39SIlya Yanok __u8 bLength;
35082651c39SIlya Yanok __u8 bDescriptorType;
35182651c39SIlya Yanok
35282651c39SIlya Yanok __u8 bInterfaceNumber;
35382651c39SIlya Yanok __u8 bAlternateSetting;
35482651c39SIlya Yanok __u8 bNumEndpoints;
35582651c39SIlya Yanok __u8 bInterfaceClass;
35682651c39SIlya Yanok __u8 bInterfaceSubClass;
35782651c39SIlya Yanok __u8 bInterfaceProtocol;
35882651c39SIlya Yanok __u8 iInterface;
35982651c39SIlya Yanok } __attribute__ ((packed));
36082651c39SIlya Yanok
36123cd1385SRemy Bohmer #define USB_DT_INTERFACE_SIZE 9
36282651c39SIlya Yanok
36382651c39SIlya Yanok /*-------------------------------------------------------------------------*/
36482651c39SIlya Yanok
36582651c39SIlya Yanok /* USB_DT_ENDPOINT: Endpoint descriptor */
36682651c39SIlya Yanok struct usb_endpoint_descriptor {
36782651c39SIlya Yanok __u8 bLength;
36882651c39SIlya Yanok __u8 bDescriptorType;
36982651c39SIlya Yanok
37082651c39SIlya Yanok __u8 bEndpointAddress;
37182651c39SIlya Yanok __u8 bmAttributes;
37282651c39SIlya Yanok __le16 wMaxPacketSize;
37382651c39SIlya Yanok __u8 bInterval;
37482651c39SIlya Yanok
37582651c39SIlya Yanok /* NOTE: these two are _only_ in audio endpoints. */
37682651c39SIlya Yanok /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
37782651c39SIlya Yanok __u8 bRefresh;
37882651c39SIlya Yanok __u8 bSynchAddress;
37982651c39SIlya Yanok } __attribute__ ((packed));
38082651c39SIlya Yanok
38123cd1385SRemy Bohmer #define USB_DT_ENDPOINT_SIZE 7
38223cd1385SRemy Bohmer #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
38323cd1385SRemy Bohmer
3848e2b6619SSimon Glass /* Used to access common fields */
3858e2b6619SSimon Glass struct usb_generic_descriptor {
3868e2b6619SSimon Glass __u8 bLength;
3878e2b6619SSimon Glass __u8 bDescriptorType;
3888e2b6619SSimon Glass };
38923cd1385SRemy Bohmer
390d8a26f03SSimon Glass struct __packed usb_class_hid_descriptor {
391d8a26f03SSimon Glass u8 bLength;
392d8a26f03SSimon Glass u8 bDescriptorType;
393d8a26f03SSimon Glass u16 bcdCDC;
394d8a26f03SSimon Glass u8 bCountryCode;
395d8a26f03SSimon Glass u8 bNumDescriptors; /* 0x01 */
396d8a26f03SSimon Glass u8 bDescriptorType0;
397d8a26f03SSimon Glass u16 wDescriptorLength0;
398d8a26f03SSimon Glass /* optional descriptors are not supported. */
399d8a26f03SSimon Glass };
400d8a26f03SSimon Glass
401d8a26f03SSimon Glass struct __packed usb_class_report_descriptor {
402d8a26f03SSimon Glass u8 bLength; /* dummy */
403d8a26f03SSimon Glass u8 bDescriptorType;
404d8a26f03SSimon Glass u16 wLength;
405d8a26f03SSimon Glass u8 bData[0];
406d8a26f03SSimon Glass };
407d8a26f03SSimon Glass
40823cd1385SRemy Bohmer /*
40923cd1385SRemy Bohmer * Endpoints
41023cd1385SRemy Bohmer */
41123cd1385SRemy Bohmer #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
41223cd1385SRemy Bohmer #define USB_ENDPOINT_DIR_MASK 0x80
41323cd1385SRemy Bohmer
41423cd1385SRemy Bohmer #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
41523cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_CONTROL 0
41623cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_ISOC 1
41723cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_BULK 2
41823cd1385SRemy Bohmer #define USB_ENDPOINT_XFER_INT 3
41923cd1385SRemy Bohmer #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
42023cd1385SRemy Bohmer
421*f51966bfSBin Meng #define USB_ENDPOINT_MAXP_MASK 0x07ff
422*f51966bfSBin Meng #define USB_EP_MAXP_MULT_SHIFT 11
423*f51966bfSBin Meng #define USB_EP_MAXP_MULT_MASK (3 << USB_EP_MAXP_MULT_SHIFT)
424*f51966bfSBin Meng #define USB_EP_MAXP_MULT(m) \
425*f51966bfSBin Meng (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
426*f51966bfSBin Meng
42782651c39SIlya Yanok /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
42882651c39SIlya Yanok #define USB_ENDPOINT_INTRTYPE 0x30
42982651c39SIlya Yanok #define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
43082651c39SIlya Yanok #define USB_ENDPOINT_INTR_NOTIFICATION (1 << 4)
43182651c39SIlya Yanok
43282651c39SIlya Yanok #define USB_ENDPOINT_SYNCTYPE 0x0c
43382651c39SIlya Yanok #define USB_ENDPOINT_SYNC_NONE (0 << 2)
43482651c39SIlya Yanok #define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
43582651c39SIlya Yanok #define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
43682651c39SIlya Yanok #define USB_ENDPOINT_SYNC_SYNC (3 << 2)
43782651c39SIlya Yanok
43882651c39SIlya Yanok #define USB_ENDPOINT_USAGE_MASK 0x30
43982651c39SIlya Yanok #define USB_ENDPOINT_USAGE_DATA 0x00
44082651c39SIlya Yanok #define USB_ENDPOINT_USAGE_FEEDBACK 0x10
44182651c39SIlya Yanok #define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */
44282651c39SIlya Yanok
44382651c39SIlya Yanok /*-------------------------------------------------------------------------*/
44482651c39SIlya Yanok
44582651c39SIlya Yanok /**
44682651c39SIlya Yanok * usb_endpoint_num - get the endpoint's number
44782651c39SIlya Yanok * @epd: endpoint to be checked
44882651c39SIlya Yanok *
44982651c39SIlya Yanok * Returns @epd's number: 0 to 15.
45082651c39SIlya Yanok */
usb_endpoint_num(const struct usb_endpoint_descriptor * epd)45182651c39SIlya Yanok static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
45282651c39SIlya Yanok {
45382651c39SIlya Yanok return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
45482651c39SIlya Yanok }
45582651c39SIlya Yanok
45682651c39SIlya Yanok /**
45782651c39SIlya Yanok * usb_endpoint_type - get the endpoint's transfer type
45882651c39SIlya Yanok * @epd: endpoint to be checked
45982651c39SIlya Yanok *
46082651c39SIlya Yanok * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
46182651c39SIlya Yanok * to @epd's transfer type.
46282651c39SIlya Yanok */
usb_endpoint_type(const struct usb_endpoint_descriptor * epd)46382651c39SIlya Yanok static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
46482651c39SIlya Yanok {
46582651c39SIlya Yanok return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
46682651c39SIlya Yanok }
46782651c39SIlya Yanok
46882651c39SIlya Yanok /**
46982651c39SIlya Yanok * usb_endpoint_dir_in - check if the endpoint has IN direction
47082651c39SIlya Yanok * @epd: endpoint to be checked
47182651c39SIlya Yanok *
47282651c39SIlya Yanok * Returns true if the endpoint is of type IN, otherwise it returns false.
47382651c39SIlya Yanok */
usb_endpoint_dir_in(const struct usb_endpoint_descriptor * epd)47482651c39SIlya Yanok static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
47582651c39SIlya Yanok {
47682651c39SIlya Yanok return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
47782651c39SIlya Yanok }
47882651c39SIlya Yanok
47982651c39SIlya Yanok /**
48082651c39SIlya Yanok * usb_endpoint_dir_out - check if the endpoint has OUT direction
48182651c39SIlya Yanok * @epd: endpoint to be checked
48282651c39SIlya Yanok *
48382651c39SIlya Yanok * Returns true if the endpoint is of type OUT, otherwise it returns false.
48482651c39SIlya Yanok */
usb_endpoint_dir_out(const struct usb_endpoint_descriptor * epd)48582651c39SIlya Yanok static inline int usb_endpoint_dir_out(
48682651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
48782651c39SIlya Yanok {
48882651c39SIlya Yanok return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
48982651c39SIlya Yanok }
49082651c39SIlya Yanok
49182651c39SIlya Yanok /**
49282651c39SIlya Yanok * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
49382651c39SIlya Yanok * @epd: endpoint to be checked
49482651c39SIlya Yanok *
49582651c39SIlya Yanok * Returns true if the endpoint is of type bulk, otherwise it returns false.
49682651c39SIlya Yanok */
usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor * epd)49782651c39SIlya Yanok static inline int usb_endpoint_xfer_bulk(
49882651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
49982651c39SIlya Yanok {
50082651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
50182651c39SIlya Yanok USB_ENDPOINT_XFER_BULK);
50282651c39SIlya Yanok }
50382651c39SIlya Yanok
50482651c39SIlya Yanok /**
50582651c39SIlya Yanok * usb_endpoint_xfer_control - check if the endpoint has control transfer type
50682651c39SIlya Yanok * @epd: endpoint to be checked
50782651c39SIlya Yanok *
50882651c39SIlya Yanok * Returns true if the endpoint is of type control, otherwise it returns false.
50982651c39SIlya Yanok */
usb_endpoint_xfer_control(const struct usb_endpoint_descriptor * epd)51082651c39SIlya Yanok static inline int usb_endpoint_xfer_control(
51182651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
51282651c39SIlya Yanok {
51382651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
51482651c39SIlya Yanok USB_ENDPOINT_XFER_CONTROL);
51582651c39SIlya Yanok }
51682651c39SIlya Yanok
51782651c39SIlya Yanok /**
51882651c39SIlya Yanok * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
51982651c39SIlya Yanok * @epd: endpoint to be checked
52082651c39SIlya Yanok *
52182651c39SIlya Yanok * Returns true if the endpoint is of type interrupt, otherwise it returns
52282651c39SIlya Yanok * false.
52382651c39SIlya Yanok */
usb_endpoint_xfer_int(const struct usb_endpoint_descriptor * epd)52482651c39SIlya Yanok static inline int usb_endpoint_xfer_int(
52582651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
52682651c39SIlya Yanok {
52782651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
52882651c39SIlya Yanok USB_ENDPOINT_XFER_INT);
52982651c39SIlya Yanok }
53082651c39SIlya Yanok
53182651c39SIlya Yanok /**
53282651c39SIlya Yanok * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
53382651c39SIlya Yanok * @epd: endpoint to be checked
53482651c39SIlya Yanok *
53582651c39SIlya Yanok * Returns true if the endpoint is of type isochronous, otherwise it returns
53682651c39SIlya Yanok * false.
53782651c39SIlya Yanok */
usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor * epd)53882651c39SIlya Yanok static inline int usb_endpoint_xfer_isoc(
53982651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
54082651c39SIlya Yanok {
54182651c39SIlya Yanok return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
54282651c39SIlya Yanok USB_ENDPOINT_XFER_ISOC);
54382651c39SIlya Yanok }
54482651c39SIlya Yanok
54582651c39SIlya Yanok /**
54682651c39SIlya Yanok * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
54782651c39SIlya Yanok * @epd: endpoint to be checked
54882651c39SIlya Yanok *
54982651c39SIlya Yanok * Returns true if the endpoint has bulk transfer type and IN direction,
55082651c39SIlya Yanok * otherwise it returns false.
55182651c39SIlya Yanok */
usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor * epd)55282651c39SIlya Yanok static inline int usb_endpoint_is_bulk_in(
55382651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
55482651c39SIlya Yanok {
55582651c39SIlya Yanok return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
55682651c39SIlya Yanok }
55782651c39SIlya Yanok
55882651c39SIlya Yanok /**
55982651c39SIlya Yanok * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
56082651c39SIlya Yanok * @epd: endpoint to be checked
56182651c39SIlya Yanok *
56282651c39SIlya Yanok * Returns true if the endpoint has bulk transfer type and OUT direction,
56382651c39SIlya Yanok * otherwise it returns false.
56482651c39SIlya Yanok */
usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor * epd)56582651c39SIlya Yanok static inline int usb_endpoint_is_bulk_out(
56682651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
56782651c39SIlya Yanok {
56882651c39SIlya Yanok return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
56982651c39SIlya Yanok }
57082651c39SIlya Yanok
57182651c39SIlya Yanok /**
57282651c39SIlya Yanok * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
57382651c39SIlya Yanok * @epd: endpoint to be checked
57482651c39SIlya Yanok *
57582651c39SIlya Yanok * Returns true if the endpoint has interrupt transfer type and IN direction,
57682651c39SIlya Yanok * otherwise it returns false.
57782651c39SIlya Yanok */
usb_endpoint_is_int_in(const struct usb_endpoint_descriptor * epd)57882651c39SIlya Yanok static inline int usb_endpoint_is_int_in(
57982651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
58082651c39SIlya Yanok {
58182651c39SIlya Yanok return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
58282651c39SIlya Yanok }
58382651c39SIlya Yanok
58482651c39SIlya Yanok /**
58582651c39SIlya Yanok * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
58682651c39SIlya Yanok * @epd: endpoint to be checked
58782651c39SIlya Yanok *
58882651c39SIlya Yanok * Returns true if the endpoint has interrupt transfer type and OUT direction,
58982651c39SIlya Yanok * otherwise it returns false.
59082651c39SIlya Yanok */
usb_endpoint_is_int_out(const struct usb_endpoint_descriptor * epd)59182651c39SIlya Yanok static inline int usb_endpoint_is_int_out(
59282651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
59382651c39SIlya Yanok {
59482651c39SIlya Yanok return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
59582651c39SIlya Yanok }
59682651c39SIlya Yanok
59782651c39SIlya Yanok /**
59882651c39SIlya Yanok * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
59982651c39SIlya Yanok * @epd: endpoint to be checked
60082651c39SIlya Yanok *
60182651c39SIlya Yanok * Returns true if the endpoint has isochronous transfer type and IN direction,
60282651c39SIlya Yanok * otherwise it returns false.
60382651c39SIlya Yanok */
usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor * epd)60482651c39SIlya Yanok static inline int usb_endpoint_is_isoc_in(
60582651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
60682651c39SIlya Yanok {
60782651c39SIlya Yanok return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
60882651c39SIlya Yanok }
60982651c39SIlya Yanok
61082651c39SIlya Yanok /**
61182651c39SIlya Yanok * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
61282651c39SIlya Yanok * @epd: endpoint to be checked
61382651c39SIlya Yanok *
61482651c39SIlya Yanok * Returns true if the endpoint has isochronous transfer type and OUT direction,
61582651c39SIlya Yanok * otherwise it returns false.
61682651c39SIlya Yanok */
usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * epd)61782651c39SIlya Yanok static inline int usb_endpoint_is_isoc_out(
61882651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
61982651c39SIlya Yanok {
62082651c39SIlya Yanok return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
62182651c39SIlya Yanok }
62282651c39SIlya Yanok
62382651c39SIlya Yanok /**
62482651c39SIlya Yanok * usb_endpoint_maxp - get endpoint's max packet size
62582651c39SIlya Yanok * @epd: endpoint to be checked
62682651c39SIlya Yanok *
62782651c39SIlya Yanok * Returns @epd's max packet
62882651c39SIlya Yanok */
usb_endpoint_maxp(const struct usb_endpoint_descriptor * epd)62982651c39SIlya Yanok static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
63082651c39SIlya Yanok {
631f903a20dSVivek Gautam return __le16_to_cpu(get_unaligned(&epd->wMaxPacketSize));
63282651c39SIlya Yanok }
63382651c39SIlya Yanok
634*f51966bfSBin Meng /**
635*f51966bfSBin Meng * usb_endpoint_maxp_mult - get endpoint's transactional opportunities
636*f51966bfSBin Meng * @epd: endpoint to be checked
637*f51966bfSBin Meng *
638*f51966bfSBin Meng * Return @epd's wMaxPacketSize[12:11] + 1
639*f51966bfSBin Meng */
640*f51966bfSBin Meng static inline int
usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor * epd)641*f51966bfSBin Meng usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd)
642*f51966bfSBin Meng {
643*f51966bfSBin Meng int maxp = __le16_to_cpu(epd->wMaxPacketSize);
644*f51966bfSBin Meng
645*f51966bfSBin Meng return USB_EP_MAXP_MULT(maxp) + 1;
646*f51966bfSBin Meng }
647*f51966bfSBin Meng
usb_endpoint_interrupt_type(const struct usb_endpoint_descriptor * epd)64882651c39SIlya Yanok static inline int usb_endpoint_interrupt_type(
64982651c39SIlya Yanok const struct usb_endpoint_descriptor *epd)
65082651c39SIlya Yanok {
65182651c39SIlya Yanok return epd->bmAttributes & USB_ENDPOINT_INTRTYPE;
65282651c39SIlya Yanok }
65382651c39SIlya Yanok
65482651c39SIlya Yanok /*-------------------------------------------------------------------------*/
65582651c39SIlya Yanok
65682651c39SIlya Yanok /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
65782651c39SIlya Yanok struct usb_ss_ep_comp_descriptor {
65882651c39SIlya Yanok __u8 bLength;
65982651c39SIlya Yanok __u8 bDescriptorType;
66082651c39SIlya Yanok
66182651c39SIlya Yanok __u8 bMaxBurst;
66282651c39SIlya Yanok __u8 bmAttributes;
66382651c39SIlya Yanok __le16 wBytesPerInterval;
66482651c39SIlya Yanok } __attribute__ ((packed));
66582651c39SIlya Yanok
66682651c39SIlya Yanok #define USB_DT_SS_EP_COMP_SIZE 6
66782651c39SIlya Yanok
66882651c39SIlya Yanok /* Bits 4:0 of bmAttributes if this is a bulk endpoint */
66982651c39SIlya Yanok static inline int
usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor * comp)67082651c39SIlya Yanok usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp)
67182651c39SIlya Yanok {
67282651c39SIlya Yanok int max_streams;
67382651c39SIlya Yanok
67482651c39SIlya Yanok if (!comp)
67582651c39SIlya Yanok return 0;
67682651c39SIlya Yanok
67782651c39SIlya Yanok max_streams = comp->bmAttributes & 0x1f;
67882651c39SIlya Yanok
67982651c39SIlya Yanok if (!max_streams)
68082651c39SIlya Yanok return 0;
68182651c39SIlya Yanok
68282651c39SIlya Yanok max_streams = 1 << max_streams;
68382651c39SIlya Yanok
68482651c39SIlya Yanok return max_streams;
68582651c39SIlya Yanok }
68682651c39SIlya Yanok
68782651c39SIlya Yanok /* Bits 1:0 of bmAttributes if this is an isoc endpoint */
68882651c39SIlya Yanok #define USB_SS_MULT(p) (1 + ((p) & 0x3))
68923cd1385SRemy Bohmer
69023cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
69123cd1385SRemy Bohmer
69223cd1385SRemy Bohmer /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
69323cd1385SRemy Bohmer struct usb_qualifier_descriptor {
69423cd1385SRemy Bohmer __u8 bLength;
69523cd1385SRemy Bohmer __u8 bDescriptorType;
69623cd1385SRemy Bohmer
69723cd1385SRemy Bohmer __le16 bcdUSB;
69823cd1385SRemy Bohmer __u8 bDeviceClass;
69923cd1385SRemy Bohmer __u8 bDeviceSubClass;
70023cd1385SRemy Bohmer __u8 bDeviceProtocol;
70123cd1385SRemy Bohmer __u8 bMaxPacketSize0;
70223cd1385SRemy Bohmer __u8 bNumConfigurations;
70323cd1385SRemy Bohmer __u8 bRESERVED;
70423cd1385SRemy Bohmer } __attribute__ ((packed));
70523cd1385SRemy Bohmer
70623cd1385SRemy Bohmer
70723cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
70823cd1385SRemy Bohmer
70923cd1385SRemy Bohmer /* USB_DT_OTG (from OTG 1.0a supplement) */
71023cd1385SRemy Bohmer struct usb_otg_descriptor {
71123cd1385SRemy Bohmer __u8 bLength;
71223cd1385SRemy Bohmer __u8 bDescriptorType;
71323cd1385SRemy Bohmer
71423cd1385SRemy Bohmer __u8 bmAttributes; /* support for HNP, SRP, etc */
71523cd1385SRemy Bohmer } __attribute__ ((packed));
71623cd1385SRemy Bohmer
71723cd1385SRemy Bohmer /* from usb_otg_descriptor.bmAttributes */
71823cd1385SRemy Bohmer #define USB_OTG_SRP (1 << 0)
71923cd1385SRemy Bohmer #define USB_OTG_HNP (1 << 1) /* swap host/device roles */
72023cd1385SRemy Bohmer
72123cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
72223cd1385SRemy Bohmer
72323cd1385SRemy Bohmer /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */
72423cd1385SRemy Bohmer struct usb_debug_descriptor {
72523cd1385SRemy Bohmer __u8 bLength;
72623cd1385SRemy Bohmer __u8 bDescriptorType;
72723cd1385SRemy Bohmer
72823cd1385SRemy Bohmer /* bulk endpoints with 8 byte maxpacket */
72923cd1385SRemy Bohmer __u8 bDebugInEndpoint;
73023cd1385SRemy Bohmer __u8 bDebugOutEndpoint;
73123cd1385SRemy Bohmer } __attribute__((packed));
73223cd1385SRemy Bohmer
73323cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
73423cd1385SRemy Bohmer
73523cd1385SRemy Bohmer /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
73623cd1385SRemy Bohmer struct usb_interface_assoc_descriptor {
73723cd1385SRemy Bohmer __u8 bLength;
73823cd1385SRemy Bohmer __u8 bDescriptorType;
73923cd1385SRemy Bohmer
74023cd1385SRemy Bohmer __u8 bFirstInterface;
74123cd1385SRemy Bohmer __u8 bInterfaceCount;
74223cd1385SRemy Bohmer __u8 bFunctionClass;
74323cd1385SRemy Bohmer __u8 bFunctionSubClass;
74423cd1385SRemy Bohmer __u8 bFunctionProtocol;
74523cd1385SRemy Bohmer __u8 iFunction;
74623cd1385SRemy Bohmer } __attribute__ ((packed));
74723cd1385SRemy Bohmer
74823cd1385SRemy Bohmer
74923cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
75023cd1385SRemy Bohmer
75123cd1385SRemy Bohmer /* USB_DT_SECURITY: group of wireless security descriptors, including
75223cd1385SRemy Bohmer * encryption types available for setting up a CC/association.
75323cd1385SRemy Bohmer */
75423cd1385SRemy Bohmer struct usb_security_descriptor {
75523cd1385SRemy Bohmer __u8 bLength;
75623cd1385SRemy Bohmer __u8 bDescriptorType;
75723cd1385SRemy Bohmer
75823cd1385SRemy Bohmer __le16 wTotalLength;
75923cd1385SRemy Bohmer __u8 bNumEncryptionTypes;
76023cd1385SRemy Bohmer } __attribute__((packed));
76123cd1385SRemy Bohmer
76223cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
76323cd1385SRemy Bohmer
76423cd1385SRemy Bohmer /* USB_DT_KEY: used with {GET,SET}_SECURITY_DATA; only public keys
76523cd1385SRemy Bohmer * may be retrieved.
76623cd1385SRemy Bohmer */
76723cd1385SRemy Bohmer struct usb_key_descriptor {
76823cd1385SRemy Bohmer __u8 bLength;
76923cd1385SRemy Bohmer __u8 bDescriptorType;
77023cd1385SRemy Bohmer
77123cd1385SRemy Bohmer __u8 tTKID[3];
77223cd1385SRemy Bohmer __u8 bReserved;
77323cd1385SRemy Bohmer __u8 bKeyData[0];
77423cd1385SRemy Bohmer } __attribute__((packed));
77523cd1385SRemy Bohmer
77623cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
77723cd1385SRemy Bohmer
77823cd1385SRemy Bohmer /* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */
77923cd1385SRemy Bohmer struct usb_encryption_descriptor {
78023cd1385SRemy Bohmer __u8 bLength;
78123cd1385SRemy Bohmer __u8 bDescriptorType;
78223cd1385SRemy Bohmer
78323cd1385SRemy Bohmer __u8 bEncryptionType;
78423cd1385SRemy Bohmer #define USB_ENC_TYPE_UNSECURE 0
78523cd1385SRemy Bohmer #define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */
78623cd1385SRemy Bohmer #define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */
78723cd1385SRemy Bohmer #define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */
78823cd1385SRemy Bohmer __u8 bEncryptionValue; /* use in SET_ENCRYPTION */
78923cd1385SRemy Bohmer __u8 bAuthKeyIndex;
79023cd1385SRemy Bohmer } __attribute__((packed));
79123cd1385SRemy Bohmer
79223cd1385SRemy Bohmer
79323cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
79423cd1385SRemy Bohmer
79582651c39SIlya Yanok /* USB_DT_BOS: group of device-level capabilities */
79623cd1385SRemy Bohmer struct usb_bos_descriptor {
79723cd1385SRemy Bohmer __u8 bLength;
79823cd1385SRemy Bohmer __u8 bDescriptorType;
79923cd1385SRemy Bohmer
80023cd1385SRemy Bohmer __le16 wTotalLength;
80123cd1385SRemy Bohmer __u8 bNumDeviceCaps;
80223cd1385SRemy Bohmer } __attribute__((packed));
80323cd1385SRemy Bohmer
80482651c39SIlya Yanok #define USB_DT_BOS_SIZE 5
80523cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
80623cd1385SRemy Bohmer
80723cd1385SRemy Bohmer /* USB_DT_DEVICE_CAPABILITY: grouped with BOS */
80823cd1385SRemy Bohmer struct usb_dev_cap_header {
80923cd1385SRemy Bohmer __u8 bLength;
81023cd1385SRemy Bohmer __u8 bDescriptorType;
81123cd1385SRemy Bohmer __u8 bDevCapabilityType;
81223cd1385SRemy Bohmer } __attribute__((packed));
81323cd1385SRemy Bohmer
81423cd1385SRemy Bohmer #define USB_CAP_TYPE_WIRELESS_USB 1
81523cd1385SRemy Bohmer
81623cd1385SRemy Bohmer struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
81723cd1385SRemy Bohmer __u8 bLength;
81823cd1385SRemy Bohmer __u8 bDescriptorType;
81923cd1385SRemy Bohmer __u8 bDevCapabilityType;
82023cd1385SRemy Bohmer
82123cd1385SRemy Bohmer __u8 bmAttributes;
82223cd1385SRemy Bohmer #define USB_WIRELESS_P2P_DRD (1 << 1)
82323cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_MASK (3 << 2)
82423cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_SELF (1 << 2)
82523cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
82623cd1385SRemy Bohmer #define USB_WIRELESS_BEACON_NONE (3 << 2)
82723cd1385SRemy Bohmer __le16 wPHYRates; /* bit rates, Mbps */
82823cd1385SRemy Bohmer #define USB_WIRELESS_PHY_53 (1 << 0) /* always set */
82923cd1385SRemy Bohmer #define USB_WIRELESS_PHY_80 (1 << 1)
83023cd1385SRemy Bohmer #define USB_WIRELESS_PHY_107 (1 << 2) /* always set */
83123cd1385SRemy Bohmer #define USB_WIRELESS_PHY_160 (1 << 3)
83223cd1385SRemy Bohmer #define USB_WIRELESS_PHY_200 (1 << 4) /* always set */
83323cd1385SRemy Bohmer #define USB_WIRELESS_PHY_320 (1 << 5)
83423cd1385SRemy Bohmer #define USB_WIRELESS_PHY_400 (1 << 6)
83523cd1385SRemy Bohmer #define USB_WIRELESS_PHY_480 (1 << 7)
83623cd1385SRemy Bohmer __u8 bmTFITXPowerInfo; /* TFI power levels */
83723cd1385SRemy Bohmer __u8 bmFFITXPowerInfo; /* FFI power levels */
83823cd1385SRemy Bohmer __le16 bmBandGroup;
83923cd1385SRemy Bohmer __u8 bReserved;
84023cd1385SRemy Bohmer } __attribute__((packed));
84123cd1385SRemy Bohmer
84282651c39SIlya Yanok /* USB 2.0 Extension descriptor */
84382651c39SIlya Yanok #define USB_CAP_TYPE_EXT 2
84482651c39SIlya Yanok
84582651c39SIlya Yanok struct usb_ext_cap_descriptor { /* Link Power Management */
84682651c39SIlya Yanok __u8 bLength;
84782651c39SIlya Yanok __u8 bDescriptorType;
84882651c39SIlya Yanok __u8 bDevCapabilityType;
84982651c39SIlya Yanok __le32 bmAttributes;
85082651c39SIlya Yanok #define USB_LPM_SUPPORT (1 << 1) /* supports LPM */
85182651c39SIlya Yanok #define USB_BESL_SUPPORT (1 << 2) /* supports BESL */
85282651c39SIlya Yanok #define USB_BESL_BASELINE_VALID (1 << 3) /* Baseline BESL valid*/
85382651c39SIlya Yanok #define USB_BESL_DEEP_VALID (1 << 4) /* Deep BESL valid */
85482651c39SIlya Yanok #define USB_GET_BESL_BASELINE(p) (((p) & (0xf << 8)) >> 8)
85582651c39SIlya Yanok #define USB_GET_BESL_DEEP(p) (((p) & (0xf << 12)) >> 12)
85682651c39SIlya Yanok } __attribute__((packed));
85782651c39SIlya Yanok
85882651c39SIlya Yanok #define USB_DT_USB_EXT_CAP_SIZE 7
85982651c39SIlya Yanok
86082651c39SIlya Yanok /*
86182651c39SIlya Yanok * SuperSpeed USB Capability descriptor: Defines the set of SuperSpeed USB
86282651c39SIlya Yanok * specific device level capabilities
86382651c39SIlya Yanok */
86482651c39SIlya Yanok #define USB_SS_CAP_TYPE 3
86582651c39SIlya Yanok struct usb_ss_cap_descriptor { /* Link Power Management */
86682651c39SIlya Yanok __u8 bLength;
86782651c39SIlya Yanok __u8 bDescriptorType;
86882651c39SIlya Yanok __u8 bDevCapabilityType;
86982651c39SIlya Yanok __u8 bmAttributes;
87082651c39SIlya Yanok #define USB_LTM_SUPPORT (1 << 1) /* supports LTM */
87182651c39SIlya Yanok __le16 wSpeedSupported;
87282651c39SIlya Yanok #define USB_LOW_SPEED_OPERATION (1) /* Low speed operation */
87382651c39SIlya Yanok #define USB_FULL_SPEED_OPERATION (1 << 1) /* Full speed operation */
87482651c39SIlya Yanok #define USB_HIGH_SPEED_OPERATION (1 << 2) /* High speed operation */
87582651c39SIlya Yanok #define USB_5GBPS_OPERATION (1 << 3) /* Operation at 5Gbps */
87682651c39SIlya Yanok __u8 bFunctionalitySupport;
87782651c39SIlya Yanok __u8 bU1devExitLat;
87882651c39SIlya Yanok __le16 bU2DevExitLat;
87982651c39SIlya Yanok } __attribute__((packed));
88082651c39SIlya Yanok
88182651c39SIlya Yanok #define USB_DT_USB_SS_CAP_SIZE 10
88282651c39SIlya Yanok
88382651c39SIlya Yanok /*
88482651c39SIlya Yanok * Container ID Capability descriptor: Defines the instance unique ID used to
88582651c39SIlya Yanok * identify the instance across all operating modes
88682651c39SIlya Yanok */
88782651c39SIlya Yanok #define CONTAINER_ID_TYPE 4
88882651c39SIlya Yanok struct usb_ss_container_id_descriptor {
88982651c39SIlya Yanok __u8 bLength;
89082651c39SIlya Yanok __u8 bDescriptorType;
89182651c39SIlya Yanok __u8 bDevCapabilityType;
89282651c39SIlya Yanok __u8 bReserved;
89382651c39SIlya Yanok __u8 ContainerID[16]; /* 128-bit number */
89482651c39SIlya Yanok } __attribute__((packed));
89582651c39SIlya Yanok
89682651c39SIlya Yanok #define USB_DT_USB_SS_CONTN_ID_SIZE 20
89723cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
89823cd1385SRemy Bohmer
89923cd1385SRemy Bohmer /* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with
90023cd1385SRemy Bohmer * each endpoint descriptor for a wireless device
90123cd1385SRemy Bohmer */
90223cd1385SRemy Bohmer struct usb_wireless_ep_comp_descriptor {
90323cd1385SRemy Bohmer __u8 bLength;
90423cd1385SRemy Bohmer __u8 bDescriptorType;
90523cd1385SRemy Bohmer
90623cd1385SRemy Bohmer __u8 bMaxBurst;
90723cd1385SRemy Bohmer __u8 bMaxSequence;
90823cd1385SRemy Bohmer __le16 wMaxStreamDelay;
90923cd1385SRemy Bohmer __le16 wOverTheAirPacketSize;
91023cd1385SRemy Bohmer __u8 bOverTheAirInterval;
91123cd1385SRemy Bohmer __u8 bmCompAttributes;
91223cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */
91323cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_NO 0
91423cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SWITCH 1
91523cd1385SRemy Bohmer #define USB_ENDPOINT_SWITCH_SCALE 2
91623cd1385SRemy Bohmer } __attribute__((packed));
91723cd1385SRemy Bohmer
91823cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
91923cd1385SRemy Bohmer
92023cd1385SRemy Bohmer /* USB_REQ_SET_HANDSHAKE is a four-way handshake used between a wireless
92123cd1385SRemy Bohmer * host and a device for connection set up, mutual authentication, and
92223cd1385SRemy Bohmer * exchanging short lived session keys. The handshake depends on a CC.
92323cd1385SRemy Bohmer */
92423cd1385SRemy Bohmer struct usb_handshake {
92523cd1385SRemy Bohmer __u8 bMessageNumber;
92623cd1385SRemy Bohmer __u8 bStatus;
92723cd1385SRemy Bohmer __u8 tTKID[3];
92823cd1385SRemy Bohmer __u8 bReserved;
92923cd1385SRemy Bohmer __u8 CDID[16];
93023cd1385SRemy Bohmer __u8 nonce[16];
93123cd1385SRemy Bohmer __u8 MIC[8];
93223cd1385SRemy Bohmer } __attribute__((packed));
93323cd1385SRemy Bohmer
93423cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
93523cd1385SRemy Bohmer
93623cd1385SRemy Bohmer /* USB_REQ_SET_CONNECTION modifies or revokes a connection context (CC).
93723cd1385SRemy Bohmer * A CC may also be set up using non-wireless secure channels (including
93823cd1385SRemy Bohmer * wired USB!), and some devices may support CCs with multiple hosts.
93923cd1385SRemy Bohmer */
94023cd1385SRemy Bohmer struct usb_connection_context {
94123cd1385SRemy Bohmer __u8 CHID[16]; /* persistent host id */
94223cd1385SRemy Bohmer __u8 CDID[16]; /* device id (unique w/in host context) */
94323cd1385SRemy Bohmer __u8 CK[16]; /* connection key */
94423cd1385SRemy Bohmer } __attribute__((packed));
94523cd1385SRemy Bohmer
94623cd1385SRemy Bohmer /*-------------------------------------------------------------------------*/
94723cd1385SRemy Bohmer
94823cd1385SRemy Bohmer /* USB 2.0 defines three speeds, here's how Linux identifies them */
94923cd1385SRemy Bohmer
95023cd1385SRemy Bohmer enum usb_device_speed {
95123cd1385SRemy Bohmer USB_SPEED_UNKNOWN = 0, /* enumerating */
95223cd1385SRemy Bohmer USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
95323cd1385SRemy Bohmer USB_SPEED_HIGH, /* usb 2.0 */
95482651c39SIlya Yanok USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
95582651c39SIlya Yanok USB_SPEED_SUPER, /* usb 3.0 */
95623cd1385SRemy Bohmer };
95723cd1385SRemy Bohmer
95882651c39SIlya Yanok #ifdef __KERNEL__
95982651c39SIlya Yanok
96082651c39SIlya Yanok /**
96182651c39SIlya Yanok * usb_speed_string() - Returns human readable-name of the speed.
96282651c39SIlya Yanok * @speed: The speed to return human-readable name for. If it's not
96382651c39SIlya Yanok * any of the speeds defined in usb_device_speed enum, string for
96482651c39SIlya Yanok * USB_SPEED_UNKNOWN will be returned.
96582651c39SIlya Yanok */
96682651c39SIlya Yanok extern const char *usb_speed_string(enum usb_device_speed speed);
96782651c39SIlya Yanok
96882651c39SIlya Yanok #endif
96982651c39SIlya Yanok
97023cd1385SRemy Bohmer enum usb_device_state {
97123cd1385SRemy Bohmer /* NOTATTACHED isn't in the USB spec, and this state acts
97223cd1385SRemy Bohmer * the same as ATTACHED ... but it's clearer this way.
97323cd1385SRemy Bohmer */
97423cd1385SRemy Bohmer USB_STATE_NOTATTACHED = 0,
97523cd1385SRemy Bohmer
97623cd1385SRemy Bohmer /* chapter 9 and authentication (wireless) device states */
97723cd1385SRemy Bohmer USB_STATE_ATTACHED,
97823cd1385SRemy Bohmer USB_STATE_POWERED, /* wired */
97923cd1385SRemy Bohmer USB_STATE_RECONNECTING, /* auth */
98082651c39SIlya Yanok USB_STATE_UNAUTHENTICATED, /* auth */
98123cd1385SRemy Bohmer USB_STATE_DEFAULT, /* limited function */
98223cd1385SRemy Bohmer USB_STATE_ADDRESS,
98323cd1385SRemy Bohmer USB_STATE_CONFIGURED, /* most functions */
98423cd1385SRemy Bohmer
98523cd1385SRemy Bohmer USB_STATE_SUSPENDED
98623cd1385SRemy Bohmer
98723cd1385SRemy Bohmer /* NOTE: there are actually four different SUSPENDED
98823cd1385SRemy Bohmer * states, returning to POWERED, DEFAULT, ADDRESS, or
98923cd1385SRemy Bohmer * CONFIGURED respectively when SOF tokens flow again.
99082651c39SIlya Yanok * At this level there's no difference between L1 and L2
99182651c39SIlya Yanok * suspend states. (L2 being original USB 1.1 suspend.)
99223cd1385SRemy Bohmer */
99323cd1385SRemy Bohmer };
99423cd1385SRemy Bohmer
99582651c39SIlya Yanok enum usb3_link_state {
99682651c39SIlya Yanok USB3_LPM_U0 = 0,
99782651c39SIlya Yanok USB3_LPM_U1,
99882651c39SIlya Yanok USB3_LPM_U2,
99982651c39SIlya Yanok USB3_LPM_U3
100082651c39SIlya Yanok };
100182651c39SIlya Yanok
100282651c39SIlya Yanok /*
100382651c39SIlya Yanok * A U1 timeout of 0x0 means the parent hub will reject any transitions to U1.
100482651c39SIlya Yanok * 0xff means the parent hub will accept transitions to U1, but will not
100582651c39SIlya Yanok * initiate a transition.
100682651c39SIlya Yanok *
100782651c39SIlya Yanok * A U1 timeout of 0x1 to 0x7F also causes the hub to initiate a transition to
100882651c39SIlya Yanok * U1 after that many microseconds. Timeouts of 0x80 to 0xFE are reserved
100982651c39SIlya Yanok * values.
101082651c39SIlya Yanok *
101182651c39SIlya Yanok * A U2 timeout of 0x0 means the parent hub will reject any transitions to U2.
101282651c39SIlya Yanok * 0xff means the parent hub will accept transitions to U2, but will not
101382651c39SIlya Yanok * initiate a transition.
101482651c39SIlya Yanok *
101582651c39SIlya Yanok * A U2 timeout of 0x1 to 0xFE also causes the hub to initiate a transition to
101682651c39SIlya Yanok * U2 after N*256 microseconds. Therefore a U2 timeout value of 0x1 means a U2
101782651c39SIlya Yanok * idle timer of 256 microseconds, 0x2 means 512 microseconds, 0xFE means
101882651c39SIlya Yanok * 65.024ms.
101982651c39SIlya Yanok */
102082651c39SIlya Yanok #define USB3_LPM_DISABLED 0x0
102182651c39SIlya Yanok #define USB3_LPM_U1_MAX_TIMEOUT 0x7F
102282651c39SIlya Yanok #define USB3_LPM_U2_MAX_TIMEOUT 0xFE
102382651c39SIlya Yanok #define USB3_LPM_DEVICE_INITIATED 0xFF
102482651c39SIlya Yanok
102582651c39SIlya Yanok struct usb_set_sel_req {
102682651c39SIlya Yanok __u8 u1_sel;
102782651c39SIlya Yanok __u8 u1_pel;
102882651c39SIlya Yanok __le16 u2_sel;
102982651c39SIlya Yanok __le16 u2_pel;
103082651c39SIlya Yanok } __attribute__ ((packed));
103182651c39SIlya Yanok
103282651c39SIlya Yanok /*
103382651c39SIlya Yanok * The Set System Exit Latency control transfer provides one byte each for
103482651c39SIlya Yanok * U1 SEL and U1 PEL, so the max exit latency is 0xFF. U2 SEL and U2 PEL each
103582651c39SIlya Yanok * are two bytes long.
103682651c39SIlya Yanok */
103782651c39SIlya Yanok #define USB3_LPM_MAX_U1_SEL_PEL 0xFF
103882651c39SIlya Yanok #define USB3_LPM_MAX_U2_SEL_PEL 0xFFFF
103982651c39SIlya Yanok
104082651c39SIlya Yanok /*-------------------------------------------------------------------------*/
104182651c39SIlya Yanok
104282651c39SIlya Yanok /*
104382651c39SIlya Yanok * As per USB compliance update, a device that is actively drawing
104482651c39SIlya Yanok * more than 100mA from USB must report itself as bus-powered in
104582651c39SIlya Yanok * the GetStatus(DEVICE) call.
104682651c39SIlya Yanok * http://compliance.usb.org/index.asp?UpdateFile=Electrical&Format=Standard#34
104782651c39SIlya Yanok */
104882651c39SIlya Yanok #define USB_SELF_POWER_VBUS_MAX_DRAW 100
104982651c39SIlya Yanok
1050f84c052aSSimon Glass /**
1051f84c052aSSimon Glass * struct usb_string - wraps a C string and its USB id
1052f84c052aSSimon Glass * @id:the (nonzero) ID for this string
1053f84c052aSSimon Glass * @s:the string, in UTF-8 encoding
1054f84c052aSSimon Glass *
1055f84c052aSSimon Glass * If you're using usb_gadget_get_string(), use this to wrap a string
1056f84c052aSSimon Glass * together with its ID.
1057f84c052aSSimon Glass */
1058f84c052aSSimon Glass struct usb_string {
1059f84c052aSSimon Glass u8 id;
1060f84c052aSSimon Glass const char *s;
1061f84c052aSSimon Glass };
1062f84c052aSSimon Glass
106323cd1385SRemy Bohmer #endif /* __LINUX_USB_CH9_H */
1064