xref: /openbmc/u-boot/include/usbdescriptors.h (revision 9b914727)
1 /*
2  * (C) Copyright 2003
3  * Gerry Hamel, geh@ti.com, Texas Instruments
4  *
5  * Based on
6  * linux/drivers/usbd/usb-function.h - USB Function
7  *
8  * Copyright (c) 2000, 2001, 2002 Lineo
9  * Copyright (c) 2001 Hewlett Packard
10  *
11  * By:
12  *	Stuart Lynne <sl@lineo.com>,
13  *	Tom Rushworth <tbr@lineo.com>,
14  *	Bruce Balden <balden@lineo.com>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29  *
30  */
31 
32 /* USB Descriptors - Create a complete description of all of the
33  * function driver capabilities. These map directly to the USB descriptors.
34  *
35  * This heirarchy is created by the functions drivers and is passed to the
36  * usb-device driver when the function driver is registered.
37  *
38  *  device
39  *	configuration
40  *	     interface
41  *		alternate
42  *		     class
43  *		     class
44  *		alternate
45  *		     endpoint
46  *		     endpoint
47  *	     interface
48  *		alternate
49  *		     endpoint
50  *		     endpoint
51  *	configuration
52  *	     interface
53  *		alternate
54  *		     endpoint
55  *		     endpoint
56  *
57  *
58  * The configuration structures refer to the USB Configurations that will be
59  * made available to a USB HOST during the enumeration process.
60  *
61  * The USB HOST will select a configuration and optionally an interface with
62  * the usb set configuration and set interface commands.
63  *
64  * The selected interface (or the default interface if not specifically
65  * selected) will define the list of endpoints that will be used.
66  *
67  * The configuration and interfaces are stored in an array that is indexed
68  * by the specified configuratin or interface number minus one.
69  *
70  * A configuration number of zero is used to specify a return to the unconfigured
71  * state.
72  *
73  */
74 
75 
76 #ifndef __USBDESCRIPTORS_H__
77 #define __USBDESCRIPTORS_H__
78 
79 #include <asm/types.h>
80 
81 /*
82  * communications class types
83  *
84  * c.f. CDC  USB Class Definitions for Communications Devices
85  * c.f. WMCD USB CDC Subclass Specification for Wireless Mobile Communications Devices
86  *
87  */
88 
89 #define CLASS_BCD_VERSION		0x0110
90 
91 /* c.f. CDC 4.1 Table 14 */
92 #define COMMUNICATIONS_DEVICE_CLASS	0x02
93 
94 /* c.f. CDC 4.2 Table 15 */
95 #define COMMUNICATIONS_INTERFACE_CLASS_CONTROL	0x02
96 #define COMMUNICATIONS_INTERFACE_CLASS_DATA		0x0A
97 #define COMMUNICATIONS_INTERFACE_CLASS_VENDOR	0x0FF
98 
99 /* c.f. CDC 4.3 Table 16 */
100 #define COMMUNICATIONS_NO_SUBCLASS		0x00
101 #define COMMUNICATIONS_DLCM_SUBCLASS	0x01
102 #define COMMUNICATIONS_ACM_SUBCLASS		0x02
103 #define COMMUNICATIONS_TCM_SUBCLASS		0x03
104 #define COMMUNICATIONS_MCCM_SUBCLASS	0x04
105 #define COMMUNICATIONS_CCM_SUBCLASS		0x05
106 #define COMMUNICATIONS_ENCM_SUBCLASS	0x06
107 #define COMMUNICATIONS_ANCM_SUBCLASS	0x07
108 
109 /* c.f. WMCD 5.1 */
110 #define COMMUNICATIONS_WHCM_SUBCLASS	0x08
111 #define COMMUNICATIONS_DMM_SUBCLASS		0x09
112 #define COMMUNICATIONS_MDLM_SUBCLASS	0x0a
113 #define COMMUNICATIONS_OBEX_SUBCLASS	0x0b
114 
115 /* c.f. CDC 4.4 Table 17 */
116 #define COMMUNICATIONS_NO_PROTOCOL		0x00
117 #define COMMUNICATIONS_V25TER_PROTOCOL	0x01	/*Common AT Hayes compatible*/
118 
119 /* c.f. CDC 4.5 Table 18 */
120 #define DATA_INTERFACE_CLASS		0x0a
121 
122 /* c.f. CDC 4.6 No Table */
123 #define DATA_INTERFACE_SUBCLASS_NONE	0x00	/* No subclass pertinent */
124 
125 /* c.f. CDC 4.7 Table 19 */
126 #define DATA_INTERFACE_PROTOCOL_NONE	0x00	/* No class protcol required */
127 
128 
129 /* c.f. CDC 5.2.3 Table 24 */
130 #define CS_INTERFACE		0x24
131 #define CS_ENDPOINT			0x25
132 
133 /*
134  * bDescriptorSubtypes
135  *
136  * c.f. CDC 5.2.3 Table 25
137  * c.f. WMCD 5.3 Table 5.3
138  */
139 
140 #define USB_ST_HEADER		0x00
141 #define USB_ST_CMF			0x01
142 #define USB_ST_ACMF			0x02
143 #define USB_ST_DLMF			0x03
144 #define USB_ST_TRF			0x04
145 #define USB_ST_TCLF			0x05
146 #define USB_ST_UF			0x06
147 #define USB_ST_CSF			0x07
148 #define USB_ST_TOMF			0x08
149 #define USB_ST_USBTF		0x09
150 #define USB_ST_NCT			0x0a
151 #define USB_ST_PUF			0x0b
152 #define USB_ST_EUF			0x0c
153 #define USB_ST_MCMF			0x0d
154 #define USB_ST_CCMF			0x0e
155 #define USB_ST_ENF			0x0f
156 #define USB_ST_ATMNF		0x10
157 
158 #define USB_ST_WHCM			0x11
159 #define USB_ST_MDLM			0x12
160 #define USB_ST_MDLMD		0x13
161 #define USB_ST_DMM			0x14
162 #define USB_ST_OBEX			0x15
163 #define USB_ST_CS			0x16
164 #define USB_ST_CSD			0x17
165 #define USB_ST_TCM			0x18
166 
167 /* endpoint modifiers
168  * static struct usb_endpoint_description function_default_A_1[] = {
169  *
170  *     {this_endpoint: 0, attributes: CONTROL,	 max_size: 8,  polling_interval: 0 },
171  *     {this_endpoint: 1, attributes: BULK,	 max_size: 64, polling_interval: 0, direction: IN},
172  *     {this_endpoint: 2, attributes: BULK,	 max_size: 64, polling_interval: 0, direction: OUT},
173  *     {this_endpoint: 3, attributes: INTERRUPT, max_size: 8,  polling_interval: 0},
174  *
175  *
176  */
177 #define OUT		0x00
178 #define IN		0x80
179 
180 #define CONTROL		0x00
181 #define ISOCHRONOUS	0x01
182 #define BULK		0x02
183 #define INTERRUPT	0x03
184 
185 
186 /* configuration modifiers
187  */
188 #define BMATTRIBUTE_RESERVED		0x80
189 #define BMATTRIBUTE_SELF_POWERED	0x40
190 
191 /*
192  * standard usb descriptor structures
193  */
194 
195 struct usb_endpoint_descriptor {
196 	u8 bLength;
197 	u8 bDescriptorType;	/* 0x5 */
198 	u8 bEndpointAddress;
199 	u8 bmAttributes;
200 	u16 wMaxPacketSize;
201 	u8 bInterval;
202 } __attribute__ ((packed));
203 
204 struct usb_interface_descriptor {
205 	u8 bLength;
206 	u8 bDescriptorType;	/* 0x04 */
207 	u8 bInterfaceNumber;
208 	u8 bAlternateSetting;
209 	u8 bNumEndpoints;
210 	u8 bInterfaceClass;
211 	u8 bInterfaceSubClass;
212 	u8 bInterfaceProtocol;
213 	u8 iInterface;
214 } __attribute__ ((packed));
215 
216 struct usb_configuration_descriptor {
217 	u8 bLength;
218 	u8 bDescriptorType;	/* 0x2 */
219 	u16 wTotalLength;
220 	u8 bNumInterfaces;
221 	u8 bConfigurationValue;
222 	u8 iConfiguration;
223 	u8 bmAttributes;
224 	u8 bMaxPower;
225 } __attribute__ ((packed));
226 
227 struct usb_device_descriptor {
228 	u8 bLength;
229 	u8 bDescriptorType;	/* 0x01 */
230 	u16 bcdUSB;
231 	u8 bDeviceClass;
232 	u8 bDeviceSubClass;
233 	u8 bDeviceProtocol;
234 	u8 bMaxPacketSize0;
235 	u16 idVendor;
236 	u16 idProduct;
237 	u16 bcdDevice;
238 	u8 iManufacturer;
239 	u8 iProduct;
240 	u8 iSerialNumber;
241 	u8 bNumConfigurations;
242 } __attribute__ ((packed));
243 
244 #if defined(CONFIG_USBD_HS)
245 struct usb_qualifier_descriptor {
246 	u8 bLength;
247 	u8 bDescriptorType;
248 
249 	u16 bcdUSB;
250 	u8 bDeviceClass;
251 	u8 bDeviceSubClass;
252 	u8 bDeviceProtocol;
253 	u8 bMaxPacketSize0;
254 	u8 bNumConfigurations;
255 	u8 breserved;
256 } __attribute__ ((packed));
257 #endif
258 
259 struct usb_string_descriptor {
260 	u8 bLength;
261 	u8 bDescriptorType;	/* 0x03 */
262 	u16 wData[0];
263 } __attribute__ ((packed));
264 
265 struct usb_generic_descriptor {
266 	u8 bLength;
267 	u8 bDescriptorType;
268 	u8 bDescriptorSubtype;
269 } __attribute__ ((packed));
270 
271 
272 /*
273  * communications class descriptor structures
274  *
275  * c.f. CDC 5.2 Table 25c
276  */
277 
278 struct usb_class_function_descriptor {
279 	u8 bFunctionLength;
280 	u8 bDescriptorType;
281 	u8 bDescriptorSubtype;
282 } __attribute__ ((packed));
283 
284 struct usb_class_function_descriptor_generic {
285 	u8 bFunctionLength;
286 	u8 bDescriptorType;
287 	u8 bDescriptorSubtype;
288 	u8 bmCapabilities;
289 } __attribute__ ((packed));
290 
291 struct usb_class_header_function_descriptor {
292 	u8 bFunctionLength;
293 	u8 bDescriptorType;
294 	u8 bDescriptorSubtype;	/* 0x00 */
295 	u16 bcdCDC;
296 } __attribute__ ((packed));
297 
298 struct usb_class_call_management_descriptor {
299 	u8 bFunctionLength;
300 	u8 bDescriptorType;
301 	u8 bDescriptorSubtype;	/* 0x01 */
302 	u8 bmCapabilities;
303 	u8 bDataInterface;
304 } __attribute__ ((packed));
305 
306 struct usb_class_abstract_control_descriptor {
307 	u8 bFunctionLength;
308 	u8 bDescriptorType;
309 	u8 bDescriptorSubtype;	/* 0x02 */
310 	u8 bmCapabilities;
311 } __attribute__ ((packed));
312 
313 struct usb_class_direct_line_descriptor {
314 	u8 bFunctionLength;
315 	u8 bDescriptorType;
316 	u8 bDescriptorSubtype;	/* 0x03 */
317 } __attribute__ ((packed));
318 
319 struct usb_class_telephone_ringer_descriptor {
320 	u8 bFunctionLength;
321 	u8 bDescriptorType;
322 	u8 bDescriptorSubtype;	/* 0x04 */
323 	u8 bRingerVolSeps;
324 	u8 bNumRingerPatterns;
325 } __attribute__ ((packed));
326 
327 struct usb_class_telephone_call_descriptor {
328 	u8 bFunctionLength;
329 	u8 bDescriptorType;
330 	u8 bDescriptorSubtype;	/* 0x05 */
331 	u8 bmCapabilities;
332 } __attribute__ ((packed));
333 
334 struct usb_class_union_function_descriptor {
335 	u8 bFunctionLength;
336 	u8 bDescriptorType;
337 	u8 bDescriptorSubtype;	/* 0x06 */
338 	u8 bMasterInterface;
339 	/* u8 bSlaveInterface0[0]; */
340 	u8 bSlaveInterface0;
341 } __attribute__ ((packed));
342 
343 struct usb_class_country_selection_descriptor {
344 	u8 bFunctionLength;
345 	u8 bDescriptorType;
346 	u8 bDescriptorSubtype;	/* 0x07 */
347 	u8 iCountryCodeRelDate;
348 	u16 wCountryCode0[0];
349 } __attribute__ ((packed));
350 
351 
352 struct usb_class_telephone_operational_descriptor {
353 	u8 bFunctionLength;
354 	u8 bDescriptorType;
355 	u8 bDescriptorSubtype;	/* 0x08 */
356 	u8 bmCapabilities;
357 } __attribute__ ((packed));
358 
359 
360 struct usb_class_usb_terminal_descriptor {
361 	u8 bFunctionLength;
362 	u8 bDescriptorType;
363 	u8 bDescriptorSubtype;	/* 0x09 */
364 	u8 bEntityId;
365 	u8 bInterfaceNo;
366 	u8 bOutInterfaceNo;
367 	u8 bmOptions;
368 	u8 bChild0[0];
369 } __attribute__ ((packed));
370 
371 struct usb_class_network_channel_descriptor {
372 	u8 bFunctionLength;
373 	u8 bDescriptorType;
374 	u8 bDescriptorSubtype;	/* 0x0a */
375 	u8 bEntityId;
376 	u8 iName;
377 	u8 bChannelIndex;
378 	u8 bPhysicalInterface;
379 } __attribute__ ((packed));
380 
381 struct usb_class_protocol_unit_function_descriptor {
382 	u8 bFunctionLength;
383 	u8 bDescriptorType;
384 	u8 bDescriptorSubtype;	/* 0x0b */
385 	u8 bEntityId;
386 	u8 bProtocol;
387 	u8 bChild0[0];
388 } __attribute__ ((packed));
389 
390 struct usb_class_extension_unit_descriptor {
391 	u8 bFunctionLength;
392 	u8 bDescriptorType;
393 	u8 bDescriptorSubtype;	/* 0x0c */
394 	u8 bEntityId;
395 	u8 bExtensionCode;
396 	u8 iName;
397 	u8 bChild0[0];
398 } __attribute__ ((packed));
399 
400 struct usb_class_multi_channel_descriptor {
401 	u8 bFunctionLength;
402 	u8 bDescriptorType;
403 	u8 bDescriptorSubtype;	/* 0x0d */
404 	u8 bmCapabilities;
405 } __attribute__ ((packed));
406 
407 struct usb_class_capi_control_descriptor {
408 	u8 bFunctionLength;
409 	u8 bDescriptorType;
410 	u8 bDescriptorSubtype;	/* 0x0e */
411 	u8 bmCapabilities;
412 } __attribute__ ((packed));
413 
414 struct usb_class_ethernet_networking_descriptor {
415 	u8 bFunctionLength;
416 	u8 bDescriptorType;
417 	u8 bDescriptorSubtype;	/* 0x0f */
418 	u8 iMACAddress;
419 	u32 bmEthernetStatistics;
420 	u16 wMaxSegmentSize;
421 	u16 wNumberMCFilters;
422 	u8 bNumberPowerFilters;
423 } __attribute__ ((packed));
424 
425 struct usb_class_atm_networking_descriptor {
426 	u8 bFunctionLength;
427 	u8 bDescriptorType;
428 	u8 bDescriptorSubtype;	/* 0x10 */
429 	u8 iEndSystermIdentifier;
430 	u8 bmDataCapabilities;
431 	u8 bmATMDeviceStatistics;
432 	u16 wType2MaxSegmentSize;
433 	u16 wType3MaxSegmentSize;
434 	u16 wMaxVC;
435 } __attribute__ ((packed));
436 
437 
438 struct usb_class_mdlm_descriptor {
439 	u8 bFunctionLength;
440 	u8 bDescriptorType;
441 	u8 bDescriptorSubtype;	/* 0x12 */
442 	u16 bcdVersion;
443 	u8 bGUID[16];
444 } __attribute__ ((packed));
445 
446 struct usb_class_mdlmd_descriptor {
447 	u8 bFunctionLength;
448 	u8 bDescriptorType;
449 	u8 bDescriptorSubtype;	/* 0x13 */
450 	u8 bGuidDescriptorType;
451 	u8 bDetailData[0];
452 
453 } __attribute__ ((packed));
454 
455 /*
456  * HID class descriptor structures
457  *
458  * c.f. HID 6.2.1
459  */
460 
461 struct usb_class_hid_descriptor {
462     u8	      bLength;
463     u8	      bDescriptorType;
464     u16	      bcdCDC;
465     u8	      bCountryCode;
466     u8	      bNumDescriptors;	/* 0x01 */
467     u8	      bDescriptorType0;
468     u16	      wDescriptorLength0;
469     /* optional descriptors are not supported. */
470 } __attribute__((packed));
471 
472 struct usb_class_report_descriptor {
473     u8	      bLength;	/* dummy */
474     u8	      bDescriptorType;
475     u16	      wLength;
476     u8		bData[0];
477 } __attribute__((packed));
478 
479 /*
480  * descriptor union structures
481  */
482 
483 struct usb_descriptor {
484 	union {
485 		struct usb_generic_descriptor generic;
486 		struct usb_endpoint_descriptor endpoint;
487 		struct usb_interface_descriptor interface;
488 		struct usb_configuration_descriptor configuration;
489 		struct usb_device_descriptor device;
490 		struct usb_string_descriptor string;
491 	} descriptor;
492 
493 } __attribute__ ((packed));
494 
495 struct usb_class_descriptor {
496 	union {
497 		struct usb_class_function_descriptor function;
498 		struct usb_class_function_descriptor_generic generic;
499 		struct usb_class_header_function_descriptor header_function;
500 		struct usb_class_call_management_descriptor call_management;
501 		struct usb_class_abstract_control_descriptor abstract_control;
502 		struct usb_class_direct_line_descriptor direct_line;
503 		struct usb_class_telephone_ringer_descriptor telephone_ringer;
504 		struct usb_class_telephone_operational_descriptor telephone_operational;
505 		struct usb_class_telephone_call_descriptor telephone_call;
506 		struct usb_class_union_function_descriptor union_function;
507 		struct usb_class_country_selection_descriptor country_selection;
508 		struct usb_class_usb_terminal_descriptor usb_terminal;
509 		struct usb_class_network_channel_descriptor network_channel;
510 		struct usb_class_extension_unit_descriptor extension_unit;
511 		struct usb_class_multi_channel_descriptor multi_channel;
512 		struct usb_class_capi_control_descriptor capi_control;
513 		struct usb_class_ethernet_networking_descriptor ethernet_networking;
514 		struct usb_class_atm_networking_descriptor atm_networking;
515 		struct usb_class_mdlm_descriptor mobile_direct;
516 		struct usb_class_mdlmd_descriptor mobile_direct_detail;
517 		struct usb_class_hid_descriptor hid;
518 	} descriptor;
519 
520 } __attribute__ ((packed));
521 
522 #ifdef DEBUG
523 static inline void print_device_descriptor(struct usb_device_descriptor *d)
524 {
525 	serial_printf("usb device descriptor \n");
526 	serial_printf("\tbLength %2.2x\n", d->bLength);
527 	serial_printf("\tbDescriptorType %2.2x\n", d->bDescriptorType);
528 	serial_printf("\tbcdUSB %4.4x\n", d->bcdUSB);
529 	serial_printf("\tbDeviceClass %2.2x\n", d->bDeviceClass);
530 	serial_printf("\tbDeviceSubClass %2.2x\n", d->bDeviceSubClass);
531 	serial_printf("\tbDeviceProtocol %2.2x\n", d->bDeviceProtocol);
532 	serial_printf("\tbMaxPacketSize0 %2.2x\n", d->bMaxPacketSize0);
533 	serial_printf("\tidVendor %4.4x\n", d->idVendor);
534 	serial_printf("\tidProduct %4.4x\n", d->idProduct);
535 	serial_printf("\tbcdDevice %4.4x\n", d->bcdDevice);
536 	serial_printf("\tiManufacturer %2.2x\n", d->iManufacturer);
537 	serial_printf("\tiProduct %2.2x\n", d->iProduct);
538 	serial_printf("\tiSerialNumber %2.2x\n", d->iSerialNumber);
539 	serial_printf("\tbNumConfigurations %2.2x\n", d->bNumConfigurations);
540 }
541 
542 #else
543 
544 /* stubs */
545 #define print_device_descriptor(d)
546 
547 #endif /* DEBUG */
548 #endif
549