diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-04-18 16:52:12 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-04-18 16:52:12 +0000 |
commit | 14a510aff28c5e5a7417f6ee39377d7ae947635d (patch) | |
tree | b50b893c8cdfb020c2904709568930422447736e | |
parent | 9340af5b251551388d2191fc4887839dcd7f5f26 (diff) | |
download | rockbox-14a510aff28c5e5a7417f6ee39377d7ae947635d.tar.gz rockbox-14a510aff28c5e5a7417f6ee39377d7ae947635d.zip |
Sync from recent linux source (FS#10142, by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20729 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/export/usb_ch9.h | 392 |
1 files changed, 209 insertions, 183 deletions
diff --git a/firmware/export/usb_ch9.h b/firmware/export/usb_ch9.h index 350f063fe0..560a737354 100644 --- a/firmware/export/usb_ch9.h +++ b/firmware/export/usb_ch9.h | |||
@@ -27,7 +27,12 @@ | |||
27 | * This file holds USB constants and structures that are needed for | 27 | * This file holds USB constants and structures that are needed for |
28 | * USB device APIs. These are used by the USB device model, which is | 28 | * USB device APIs. These are used by the USB device model, which is |
29 | * defined in chapter 9 of the USB 2.0 specification and in the | 29 | * defined in chapter 9 of the USB 2.0 specification and in the |
30 | * Wireless USB 1.0 (spread around). | 30 | * Wireless USB 1.0 (spread around). Linux has several APIs in C that |
31 | * need these: | ||
32 | * | ||
33 | * - the master/host side Linux-USB kernel driver API; | ||
34 | * - the "usbfs" user space API; and | ||
35 | * - the Linux "gadget" slave/device/peripheral side driver API. | ||
31 | * | 36 | * |
32 | * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems | 37 | * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems |
33 | * act either as a USB master/host or as a USB slave/device. That means | 38 | * act either as a USB master/host or as a USB slave/device. That means |
@@ -55,34 +60,55 @@ | |||
55 | 60 | ||
56 | #include <inttypes.h> | 61 | #include <inttypes.h> |
57 | 62 | ||
63 | /*-------------------------------------------------------------------------*/ | ||
64 | |||
65 | /* CONTROL REQUEST SUPPORT */ | ||
66 | |||
58 | /* | 67 | /* |
59 | * USB directions | 68 | * USB directions |
60 | * | 69 | * |
61 | * This bit flag is used in endpoint descriptors' bEndpointAddress field. | 70 | * This bit flag is used in endpoint descriptors' bEndpointAddress field. |
62 | * It's also one of three fields in control requests bRequestType. | 71 | * It's also one of three fields in control requests bRequestType. |
63 | */ | 72 | */ |
64 | #define USB_DIR_OUT 0 /* to device */ | 73 | #define USB_DIR_OUT 0 /* to device */ |
65 | #define USB_DIR_IN 0x80 /* to host */ | 74 | #define USB_DIR_IN 0x80 /* to host */ |
66 | 75 | ||
67 | /* | 76 | /* |
68 | * USB types, the second of three bRequestType fields | 77 | * USB types, the second of three bRequestType fields |
69 | */ | 78 | */ |
70 | #define USB_TYPE_MASK (0x03 << 5) | 79 | #define USB_TYPE_MASK (0x03 << 5) |
71 | #define USB_TYPE_STANDARD (0x00 << 5) | 80 | #define USB_TYPE_STANDARD (0x00 << 5) |
72 | #define USB_TYPE_CLASS (0x01 << 5) | 81 | #define USB_TYPE_CLASS (0x01 << 5) |
73 | #define USB_TYPE_VENDOR (0x02 << 5) | 82 | #define USB_TYPE_VENDOR (0x02 << 5) |
74 | #define USB_TYPE_RESERVED (0x03 << 5) | 83 | #define USB_TYPE_RESERVED (0x03 << 5) |
75 | 84 | ||
76 | /* | 85 | /* |
77 | * USB recipients, the third of three bRequestType fields | 86 | * USB recipients, the third of three bRequestType fields |
78 | */ | 87 | */ |
79 | #define USB_RECIP_MASK 0x1f | 88 | #define USB_RECIP_MASK 0x1f |
80 | #define USB_RECIP_DEVICE 0x00 | 89 | #define USB_RECIP_DEVICE 0x00 |
81 | #define USB_RECIP_INTERFACE 0x01 | 90 | #define USB_RECIP_INTERFACE 0x01 |
82 | #define USB_RECIP_ENDPOINT 0x02 | 91 | #define USB_RECIP_ENDPOINT 0x02 |
83 | #define USB_RECIP_OTHER 0x03 | 92 | #define USB_RECIP_OTHER 0x03 |
84 | 93 | ||
85 | /*-------------------------------------------------------------------------*/ | 94 | /* |
95 | * Standard requests, for the bRequest field of a SETUP packet. | ||
96 | * | ||
97 | * These are qualified by the bRequestType field, so that for example | ||
98 | * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved | ||
99 | * by a GET_STATUS request. | ||
100 | */ | ||
101 | #define USB_REQ_GET_STATUS 0x00 | ||
102 | #define USB_REQ_CLEAR_FEATURE 0x01 | ||
103 | #define USB_REQ_SET_FEATURE 0x03 | ||
104 | #define USB_REQ_SET_ADDRESS 0x05 | ||
105 | #define USB_REQ_GET_DESCRIPTOR 0x06 | ||
106 | #define USB_REQ_SET_DESCRIPTOR 0x07 | ||
107 | #define USB_REQ_GET_CONFIGURATION 0x08 | ||
108 | #define USB_REQ_SET_CONFIGURATION 0x09 | ||
109 | #define USB_REQ_GET_INTERFACE 0x0A | ||
110 | #define USB_REQ_SET_INTERFACE 0x0B | ||
111 | #define USB_REQ_SYNCH_FRAME 0x0C | ||
86 | 112 | ||
87 | /** | 113 | /** |
88 | * struct usb_ctrlrequest - SETUP data for a USB device control request | 114 | * struct usb_ctrlrequest - SETUP data for a USB device control request |
@@ -91,34 +117,24 @@ | |||
91 | * @wValue: matches the USB wValue field (le16 byte order) | 117 | * @wValue: matches the USB wValue field (le16 byte order) |
92 | * @wIndex: matches the USB wIndex field (le16 byte order) | 118 | * @wIndex: matches the USB wIndex field (le16 byte order) |
93 | * @wLength: matches the USB wLength field (le16 byte order) | 119 | * @wLength: matches the USB wLength field (le16 byte order) |
120 | * | ||
121 | * This structure is used to send control requests to a USB device. It matches | ||
122 | * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the | ||
123 | * USB spec for a fuller description of the different fields, and what they are | ||
124 | * used for. | ||
125 | * | ||
126 | * Note that the driver for any interface can issue control requests. | ||
127 | * For most devices, interfaces don't coordinate with each other, so | ||
128 | * such requests may be made at any time. | ||
94 | */ | 129 | */ |
95 | struct usb_ctrlrequest { | 130 | struct usb_ctrlrequest { |
96 | uint8_t bRequestType; | 131 | uint8_t bRequestType; |
97 | uint8_t bRequest; | 132 | uint8_t bRequest; |
98 | uint16_t wValue; | 133 | uint16_t wValue; |
99 | uint16_t wIndex; | 134 | uint16_t wIndex; |
100 | uint16_t wLength; | 135 | uint16_t wLength; |
101 | } __attribute__ ((packed)); | 136 | } __attribute__ ((packed)); |
102 | 137 | ||
103 | /* | ||
104 | * Standard requests, for the bRequest field of a SETUP packet. | ||
105 | * | ||
106 | * These are qualified by the bRequestType field, so that for example | ||
107 | * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved | ||
108 | * by a GET_STATUS request. | ||
109 | */ | ||
110 | #define USB_REQ_GET_STATUS 0x00 | ||
111 | #define USB_REQ_CLEAR_FEATURE 0x01 | ||
112 | #define USB_REQ_SET_FEATURE 0x03 | ||
113 | #define USB_REQ_SET_ADDRESS 0x05 | ||
114 | #define USB_REQ_GET_DESCRIPTOR 0x06 | ||
115 | #define USB_REQ_SET_DESCRIPTOR 0x07 | ||
116 | #define USB_REQ_GET_CONFIGURATION 0x08 | ||
117 | #define USB_REQ_SET_CONFIGURATION 0x09 | ||
118 | #define USB_REQ_GET_INTERFACE 0x0A | ||
119 | #define USB_REQ_SET_INTERFACE 0x0B | ||
120 | #define USB_REQ_SYNCH_FRAME 0x0C | ||
121 | |||
122 | /*-------------------------------------------------------------------------*/ | 138 | /*-------------------------------------------------------------------------*/ |
123 | 139 | ||
124 | /* | 140 | /* |
@@ -138,9 +154,9 @@ struct usb_ctrlrequest { | |||
138 | #define USB_DT_STRING 0x03 | 154 | #define USB_DT_STRING 0x03 |
139 | #define USB_DT_INTERFACE 0x04 | 155 | #define USB_DT_INTERFACE 0x04 |
140 | #define USB_DT_ENDPOINT 0x05 | 156 | #define USB_DT_ENDPOINT 0x05 |
141 | #define USB_DT_DEVICE_QUALIFIER 0x06 | 157 | #define USB_DT_DEVICE_QUALIFIER 0x06 |
142 | #define USB_DT_OTHER_SPEED_CONFIG 0x07 | 158 | #define USB_DT_OTHER_SPEED_CONFIG 0x07 |
143 | #define USB_DT_INTERFACE_POWER 0x08 | 159 | #define USB_DT_INTERFACE_POWER 0x08 |
144 | /* these are from a minor usb 2.0 revision (ECN) */ | 160 | /* these are from a minor usb 2.0 revision (ECN) */ |
145 | #define USB_DT_OTG 0x09 | 161 | #define USB_DT_OTG 0x09 |
146 | #define USB_DT_DEBUG 0x0a | 162 | #define USB_DT_DEBUG 0x0a |
@@ -154,61 +170,71 @@ struct usb_ctrlrequest { | |||
154 | #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11 | 170 | #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11 |
155 | #define USB_DT_WIRE_ADAPTER 0x21 | 171 | #define USB_DT_WIRE_ADAPTER 0x21 |
156 | #define USB_DT_RPIPE 0x22 | 172 | #define USB_DT_RPIPE 0x22 |
173 | #define USB_DT_CS_RADIO_CONTROL 0x23 | ||
157 | 174 | ||
158 | /* Conventional codes for class-specific descriptors. The convention is | 175 | /* Conventional codes for class-specific descriptors. The convention is |
159 | * defined in the USB "Common Class" Spec (3.11). Individual class specs | 176 | * defined in the USB "Common Class" Spec (3.11). Individual class specs |
160 | * are authoritative for their usage, not the "common class" writeup. | 177 | * are authoritative for their usage, not the "common class" writeup. |
161 | */ | 178 | */ |
162 | #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE) | 179 | #define USB_DT_CS_DEVICE (USB_TYPE_CLASS | USB_DT_DEVICE) |
163 | #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG) | 180 | #define USB_DT_CS_CONFIG (USB_TYPE_CLASS | USB_DT_CONFIG) |
164 | #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING) | 181 | #define USB_DT_CS_STRING (USB_TYPE_CLASS | USB_DT_STRING) |
165 | #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE) | 182 | #define USB_DT_CS_INTERFACE (USB_TYPE_CLASS | USB_DT_INTERFACE) |
166 | #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT) | 183 | #define USB_DT_CS_ENDPOINT (USB_TYPE_CLASS | USB_DT_ENDPOINT) |
184 | |||
185 | /* All standard descriptors have these 2 fields at the beginning */ | ||
186 | struct usb_descriptor_header { | ||
187 | uint8_t bLength; | ||
188 | uint8_t bDescriptorType; | ||
189 | } __attribute__ ((packed)); | ||
190 | |||
167 | 191 | ||
168 | /*-------------------------------------------------------------------------*/ | 192 | /*-------------------------------------------------------------------------*/ |
169 | 193 | ||
170 | /* USB_DT_DEVICE: Device descriptor */ | 194 | /* USB_DT_DEVICE: Device descriptor */ |
171 | struct usb_device_descriptor { | 195 | struct usb_device_descriptor { |
172 | uint8_t bLength; | 196 | uint8_t bLength; |
173 | uint8_t bDescriptorType; | 197 | uint8_t bDescriptorType; |
174 | uint16_t bcdUSB; | 198 | |
175 | uint8_t bDeviceClass; | 199 | uint16_t bcdUSB; |
176 | uint8_t bDeviceSubClass; | 200 | uint8_t bDeviceClass; |
177 | uint8_t bDeviceProtocol; | 201 | uint8_t bDeviceSubClass; |
178 | uint8_t bMaxPacketSize0; | 202 | uint8_t bDeviceProtocol; |
179 | uint16_t idVendor; | 203 | uint8_t bMaxPacketSize0; |
180 | uint16_t idProduct; | 204 | uint16_t idVendor; |
181 | uint16_t bcdDevice; | 205 | uint16_t idProduct; |
182 | uint8_t iManufacturer; | 206 | uint16_t bcdDevice; |
183 | uint8_t iProduct; | 207 | uint8_t iManufacturer; |
184 | uint8_t iSerialNumber; | 208 | uint8_t iProduct; |
185 | uint8_t bNumConfigurations; | 209 | uint8_t iSerialNumber; |
210 | uint8_t bNumConfigurations; | ||
186 | } __attribute__ ((packed)); | 211 | } __attribute__ ((packed)); |
187 | 212 | ||
188 | #define USB_DT_DEVICE_SIZE 18 | 213 | #define USB_DT_DEVICE_SIZE 18 |
214 | |||
189 | 215 | ||
190 | /* | 216 | /* |
191 | * Device and/or Interface Class codes | 217 | * Device and/or Interface Class codes |
192 | * as found in bDeviceClass or bInterfaceClass | 218 | * as found in bDeviceClass or bInterfaceClass |
193 | * and defined by www.usb.org documents | 219 | * and defined by www.usb.org documents |
194 | */ | 220 | */ |
195 | #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ | 221 | #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ |
196 | #define USB_CLASS_AUDIO 1 | 222 | #define USB_CLASS_AUDIO 1 |
197 | #define USB_CLASS_COMM 2 | 223 | #define USB_CLASS_COMM 2 |
198 | #define USB_CLASS_HID 3 | 224 | #define USB_CLASS_HID 3 |
199 | #define USB_CLASS_PHYSICAL 5 | 225 | #define USB_CLASS_PHYSICAL 5 |
200 | #define USB_CLASS_STILL_IMAGE 6 | 226 | #define USB_CLASS_STILL_IMAGE 6 |
201 | #define USB_CLASS_PRINTER 7 | 227 | #define USB_CLASS_PRINTER 7 |
202 | #define USB_CLASS_MASS_STORAGE 8 | 228 | #define USB_CLASS_MASS_STORAGE 8 |
203 | #define USB_CLASS_HUB 9 | 229 | #define USB_CLASS_HUB 9 |
204 | #define USB_CLASS_CDC_DATA 0x0a | 230 | #define USB_CLASS_CDC_DATA 0x0a |
205 | #define USB_CLASS_CSCID 0x0b /* chip+ smart card */ | 231 | #define USB_CLASS_CSCID 0x0b /* chip+ smart card */ |
206 | #define USB_CLASS_CONTENT_SEC 0x0d /* content security */ | 232 | #define USB_CLASS_CONTENT_SEC 0x0d /* content security */ |
207 | #define USB_CLASS_VIDEO 0x0e | 233 | #define USB_CLASS_VIDEO 0x0e |
208 | #define USB_CLASS_WIRELESS_CONTROLLER 0xe0 | 234 | #define USB_CLASS_WIRELESS_CONTROLLER 0xe0 |
209 | #define USB_CLASS_MISC 0xef | 235 | #define USB_CLASS_MISC 0xef |
210 | #define USB_CLASS_APP_SPEC 0xfe | 236 | #define USB_CLASS_APP_SPEC 0xfe |
211 | #define USB_CLASS_VENDOR_SPEC 0xff | 237 | #define USB_CLASS_VENDOR_SPEC 0xff |
212 | 238 | ||
213 | /*-------------------------------------------------------------------------*/ | 239 | /*-------------------------------------------------------------------------*/ |
214 | 240 | ||
@@ -221,32 +247,33 @@ struct usb_device_descriptor { | |||
221 | * descriptors. | 247 | * descriptors. |
222 | */ | 248 | */ |
223 | struct usb_config_descriptor { | 249 | struct usb_config_descriptor { |
224 | uint8_t bLength; | 250 | uint8_t bLength; |
225 | uint8_t bDescriptorType; | 251 | uint8_t bDescriptorType; |
226 | uint16_t wTotalLength; | 252 | |
227 | uint8_t bNumInterfaces; | 253 | uint16_t wTotalLength; |
228 | uint8_t bConfigurationValue; | 254 | uint8_t bNumInterfaces; |
229 | uint8_t iConfiguration; | 255 | uint8_t bConfigurationValue; |
230 | uint8_t bmAttributes; | 256 | uint8_t iConfiguration; |
231 | uint8_t bMaxPower; | 257 | uint8_t bmAttributes; |
258 | uint8_t bMaxPower; | ||
232 | } __attribute__ ((packed)); | 259 | } __attribute__ ((packed)); |
233 | 260 | ||
234 | #define USB_DT_CONFIG_SIZE 9 | 261 | #define USB_DT_CONFIG_SIZE 9 |
235 | 262 | ||
236 | /* from config descriptor bmAttributes */ | 263 | /* from config descriptor bmAttributes */ |
237 | #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */ | 264 | #define USB_CONFIG_ATT_ONE (1 << 7) /* must be set */ |
238 | #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ | 265 | #define USB_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ |
239 | #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ | 266 | #define USB_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ |
240 | #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */ | 267 | #define USB_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */ |
241 | 268 | ||
242 | /*-------------------------------------------------------------------------*/ | 269 | /*-------------------------------------------------------------------------*/ |
243 | 270 | ||
244 | /* USB_DT_STRING: String descriptor */ | 271 | /* USB_DT_STRING: String descriptor */ |
245 | struct usb_string_descriptor { | 272 | struct usb_string_descriptor { |
246 | uint8_t bLength; | 273 | uint8_t bLength; |
247 | uint8_t bDescriptorType; | 274 | uint8_t bDescriptorType; |
248 | 275 | ||
249 | uint16_t wString[]; /* UTF-16LE encoded */ | 276 | uint16_t wString[]; /* UTF-16LE encoded */ |
250 | } __attribute__ ((packed)); | 277 | } __attribute__ ((packed)); |
251 | 278 | ||
252 | /* note that "string" zero is special, it holds language codes that | 279 | /* note that "string" zero is special, it holds language codes that |
@@ -257,130 +284,129 @@ struct usb_string_descriptor { | |||
257 | 284 | ||
258 | /* USB_DT_INTERFACE: Interface descriptor */ | 285 | /* USB_DT_INTERFACE: Interface descriptor */ |
259 | struct usb_interface_descriptor { | 286 | struct usb_interface_descriptor { |
260 | uint8_t bLength; | 287 | uint8_t bLength; |
261 | uint8_t bDescriptorType; | 288 | uint8_t bDescriptorType; |
262 | 289 | ||
263 | uint8_t bInterfaceNumber; | 290 | uint8_t bInterfaceNumber; |
264 | uint8_t bAlternateSetting; | 291 | uint8_t bAlternateSetting; |
265 | uint8_t bNumEndpoints; | 292 | uint8_t bNumEndpoints; |
266 | uint8_t bInterfaceClass; | 293 | uint8_t bInterfaceClass; |
267 | uint8_t bInterfaceSubClass; | 294 | uint8_t bInterfaceSubClass; |
268 | uint8_t bInterfaceProtocol; | 295 | uint8_t bInterfaceProtocol; |
269 | uint8_t iInterface; | 296 | uint8_t iInterface; |
270 | } __attribute__ ((packed)); | 297 | } __attribute__ ((packed)); |
271 | 298 | ||
272 | #define USB_DT_INTERFACE_SIZE 9 | 299 | #define USB_DT_INTERFACE_SIZE 9 |
273 | 300 | ||
274 | /*-------------------------------------------------------------------------*/ | 301 | /*-------------------------------------------------------------------------*/ |
275 | 302 | ||
276 | /* USB_DT_ENDPOINT: Endpoint descriptor */ | 303 | /* USB_DT_ENDPOINT: Endpoint descriptor */ |
277 | struct usb_endpoint_descriptor { | 304 | struct usb_endpoint_descriptor { |
278 | uint8_t bLength; | 305 | uint8_t bLength; |
279 | uint8_t bDescriptorType; | 306 | uint8_t bDescriptorType; |
280 | 307 | ||
281 | uint8_t bEndpointAddress; | 308 | uint8_t bEndpointAddress; |
282 | uint8_t bmAttributes; | 309 | uint8_t bmAttributes; |
283 | uint16_t wMaxPacketSize; | 310 | uint16_t wMaxPacketSize; |
284 | uint8_t bInterval; | 311 | uint8_t bInterval; |
285 | |||
286 | /* NOTE: these two are _only_ in audio endpoints. */ | ||
287 | /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */ | ||
288 | //uint8_t bRefresh; | ||
289 | //uint8_t bSynchAddress; | ||
290 | } __attribute__ ((packed)); | 312 | } __attribute__ ((packed)); |
291 | 313 | ||
292 | #define USB_DT_ENDPOINT_SIZE 7 | 314 | #define USB_DT_ENDPOINT_SIZE 7 |
293 | #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ | 315 | #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ |
316 | |||
317 | |||
318 | /* | ||
319 | * Endpoints | ||
320 | */ | ||
321 | #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ | ||
322 | #define USB_ENDPOINT_DIR_MASK 0x80 | ||
323 | |||
324 | #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ | ||
325 | #define USB_ENDPOINT_XFER_CONTROL 0 | ||
326 | #define USB_ENDPOINT_XFER_ISOC 1 | ||
327 | #define USB_ENDPOINT_XFER_BULK 2 | ||
328 | #define USB_ENDPOINT_XFER_INT 3 | ||
329 | #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 | ||
330 | |||
294 | 331 | ||
295 | /*-------------------------------------------------------------------------*/ | 332 | /*-------------------------------------------------------------------------*/ |
296 | 333 | ||
297 | /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */ | 334 | /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */ |
298 | struct usb_qualifier_descriptor { | 335 | struct usb_qualifier_descriptor { |
299 | uint8_t bLength; | 336 | uint8_t bLength; |
300 | uint8_t bDescriptorType; | 337 | uint8_t bDescriptorType; |
301 | 338 | ||
302 | uint16_t bcdUSB; | 339 | uint16_t bcdUSB; |
303 | uint8_t bDeviceClass; | 340 | uint8_t bDeviceClass; |
304 | uint8_t bDeviceSubClass; | 341 | uint8_t bDeviceSubClass; |
305 | uint8_t bDeviceProtocol; | 342 | uint8_t bDeviceProtocol; |
306 | uint8_t bMaxPacketSize0; | 343 | uint8_t bMaxPacketSize0; |
307 | uint8_t bNumConfigurations; | 344 | uint8_t bNumConfigurations; |
308 | uint8_t bRESERVED; | 345 | uint8_t bRESERVED; |
309 | } __attribute__ ((packed)); | 346 | } __attribute__ ((packed)); |
310 | 347 | ||
348 | |||
311 | /*-------------------------------------------------------------------------*/ | 349 | /*-------------------------------------------------------------------------*/ |
312 | 350 | ||
313 | /* USB_DT_OTG (from OTG 1.0a supplement) */ | 351 | /* USB_DT_OTG (from OTG 1.0a supplement) */ |
314 | struct usb_otg_descriptor { | 352 | struct usb_otg_descriptor { |
315 | uint8_t bLength; | 353 | uint8_t bLength; |
316 | uint8_t bDescriptorType; | 354 | uint8_t bDescriptorType; |
317 | 355 | ||
318 | uint8_t bmAttributes; /* support for HNP, SRP, etc */ | 356 | uint8_t bmAttributes; /* support for HNP, SRP, etc */ |
319 | } __attribute__ ((packed)); | 357 | } __attribute__ ((packed)); |
320 | 358 | ||
321 | /* from usb_otg_descriptor.bmAttributes */ | 359 | /* from usb_otg_descriptor.bmAttributes */ |
322 | #define USB_OTG_SRP (1 << 0) | 360 | #define USB_OTG_SRP (1 << 0) |
323 | #define USB_OTG_HNP (1 << 1) /* swap host/device roles */ | 361 | #define USB_OTG_HNP (1 << 1) /* swap host/device roles */ |
324 | 362 | ||
325 | /*-------------------------------------------------------------------------*/ | 363 | /*-------------------------------------------------------------------------*/ |
326 | 364 | ||
327 | /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */ | 365 | /* USB_DT_DEBUG: for special highspeed devices, replacing serial console */ |
328 | struct usb_debug_descriptor { | 366 | struct usb_debug_descriptor { |
329 | uint8_t bLength; | 367 | uint8_t bLength; |
330 | uint8_t bDescriptorType; | 368 | uint8_t bDescriptorType; |
331 | 369 | ||
332 | /* bulk endpoints with 8 byte maxpacket */ | 370 | /* bulk endpoints with 8 byte maxpacket */ |
333 | uint8_t bDebugInEndpoint; | 371 | uint8_t bDebugInEndpoint; |
334 | uint8_t bDebugOutEndpoint; | 372 | uint8_t bDebugOutEndpoint; |
335 | }; | 373 | } __attribute__((packed)); |
336 | 374 | ||
337 | /*-------------------------------------------------------------------------*/ | 375 | /*-------------------------------------------------------------------------*/ |
338 | 376 | /* USB 2.0 defines three speeds, here's how Linux identifies them */ | |
339 | /* | ||
340 | * Endpoints | ||
341 | */ | ||
342 | #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ | ||
343 | #define USB_ENDPOINT_XFER_CONTROL 0 | ||
344 | #define USB_ENDPOINT_XFER_ISOC 1 | ||
345 | #define USB_ENDPOINT_XFER_BULK 2 | ||
346 | #define USB_ENDPOINT_XFER_INT 3 | ||
347 | 377 | ||
348 | enum usb_device_speed { | 378 | enum usb_device_speed { |
349 | USB_SPEED_UNKNOWN = 0, /* enumerating */ | 379 | USB_SPEED_UNKNOWN = 0, /* enumerating */ |
350 | USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ | 380 | USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */ |
351 | USB_SPEED_HIGH, /* usb 2.0 */ | 381 | USB_SPEED_HIGH, /* usb 2.0 */ |
352 | USB_SPEED_VARIABLE, /* wireless (usb 2.5) */ | 382 | USB_SPEED_VARIABLE, /* wireless (usb 2.5) */ |
353 | }; | 383 | }; |
354 | 384 | ||
355 | enum usb_device_state { | 385 | enum usb_device_state { |
356 | /* NOTATTACHED isn't in the USB spec, and this state acts | 386 | /* NOTATTACHED isn't in the USB spec, and this state acts |
357 | * the same as ATTACHED ... but it's clearer this way. | 387 | * the same as ATTACHED ... but it's clearer this way. |
358 | */ | 388 | */ |
359 | USB_STATE_NOTATTACHED = 0, | 389 | USB_STATE_NOTATTACHED = 0, |
360 | 390 | ||
361 | /* chapter 9 and authentication (wireless) device states */ | 391 | /* chapter 9 and authentication (wireless) device states */ |
362 | USB_STATE_ATTACHED, | 392 | USB_STATE_ATTACHED, |
363 | USB_STATE_POWERED, /* wired */ | 393 | USB_STATE_POWERED, /* wired */ |
364 | USB_STATE_UNAUTHENTICATED, /* auth */ | 394 | USB_STATE_UNAUTHENTICATED, /* auth */ |
365 | USB_STATE_RECONNECTING, /* auth */ | 395 | USB_STATE_RECONNECTING, /* auth */ |
366 | USB_STATE_DEFAULT, /* limited function */ | 396 | USB_STATE_DEFAULT, /* limited function */ |
367 | USB_STATE_ADDRESS, | 397 | USB_STATE_ADDRESS, |
368 | USB_STATE_CONFIGURED, /* most functions */ | 398 | USB_STATE_CONFIGURED, /* most functions */ |
369 | 399 | ||
370 | USB_STATE_SUSPENDED | 400 | USB_STATE_SUSPENDED |
371 | 401 | ||
372 | /* NOTE: there are actually four different SUSPENDED | 402 | /* NOTE: there are actually four different SUSPENDED |
373 | * states, returning to POWERED, DEFAULT, ADDRESS, or | 403 | * states, returning to POWERED, DEFAULT, ADDRESS, or |
374 | * CONFIGURED respectively when SOF tokens flow again. | 404 | * CONFIGURED respectively when SOF tokens flow again. |
375 | */ | 405 | * At this level there's no difference between L1 and L2 |
406 | * suspend states. (L2 being original USB 1.1 suspend.) | ||
407 | */ | ||
376 | }; | 408 | }; |
377 | 409 | ||
378 | /* All standard descriptors have these 2 fields at the beginning */ | ||
379 | struct usb_descriptor_header { | ||
380 | uint8_t bLength; | ||
381 | uint8_t bDescriptorType; | ||
382 | } __attribute__ ((packed)); | ||
383 | |||
384 | /** | 410 | /** |
385 | * struct usb_string - wraps a C string and its USB id | 411 | * struct usb_string - wraps a C string and its USB id |
386 | * @id:the (nonzero) ID for this string | 412 | * @id:the (nonzero) ID for this string |
@@ -390,8 +416,8 @@ struct usb_descriptor_header { | |||
390 | * together with its ID. | 416 | * together with its ID. |
391 | */ | 417 | */ |
392 | struct usb_string { | 418 | struct usb_string { |
393 | uint8_t id; | 419 | uint8_t id; |
394 | const char* s; | 420 | const char* s; |
395 | }; | 421 | }; |
396 | 422 | ||
397 | /** | 423 | /** |
@@ -403,8 +429,8 @@ struct usb_string { | |||
403 | * strings for a given language. | 429 | * strings for a given language. |
404 | */ | 430 | */ |
405 | struct usb_gadget_strings { | 431 | struct usb_gadget_strings { |
406 | uint16_t language; /* 0x0409 for en-us */ | 432 | uint16_t language; /* 0x0409 for en-us */ |
407 | struct usb_string* strings; | 433 | struct usb_string* strings; |
408 | }; | 434 | }; |
409 | 435 | ||
410 | #endif /*_CH9_H_*/ | 436 | #endif /*_CH9_H_*/ |