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