global: Migrate CONFIG_STACKBASE to CFG
[platform/kernel/u-boot.git] / include / usbdescriptors.h
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 struct usb_string_descriptor {
231         u8 bLength;
232         u8 bDescriptorType;     /* 0x03 */
233         u16 wData[0];
234 } __attribute__ ((packed));
235
236 struct usb_generic_descriptor {
237         u8 bLength;
238         u8 bDescriptorType;
239         u8 bDescriptorSubtype;
240 } __attribute__ ((packed));
241
242
243 /*
244  * communications class descriptor structures
245  *
246  * c.f. CDC 5.2 Table 25c
247  */
248
249 struct usb_class_function_descriptor {
250         u8 bFunctionLength;
251         u8 bDescriptorType;
252         u8 bDescriptorSubtype;
253 } __attribute__ ((packed));
254
255 struct usb_class_function_descriptor_generic {
256         u8 bFunctionLength;
257         u8 bDescriptorType;
258         u8 bDescriptorSubtype;
259         u8 bmCapabilities;
260 } __attribute__ ((packed));
261
262 struct usb_class_header_function_descriptor {
263         u8 bFunctionLength;
264         u8 bDescriptorType;
265         u8 bDescriptorSubtype;  /* 0x00 */
266         u16 bcdCDC;
267 } __attribute__ ((packed));
268
269 struct usb_class_call_management_descriptor {
270         u8 bFunctionLength;
271         u8 bDescriptorType;
272         u8 bDescriptorSubtype;  /* 0x01 */
273         u8 bmCapabilities;
274         u8 bDataInterface;
275 } __attribute__ ((packed));
276
277 struct usb_class_abstract_control_descriptor {
278         u8 bFunctionLength;
279         u8 bDescriptorType;
280         u8 bDescriptorSubtype;  /* 0x02 */
281         u8 bmCapabilities;
282 } __attribute__ ((packed));
283
284 struct usb_class_direct_line_descriptor {
285         u8 bFunctionLength;
286         u8 bDescriptorType;
287         u8 bDescriptorSubtype;  /* 0x03 */
288 } __attribute__ ((packed));
289
290 struct usb_class_telephone_ringer_descriptor {
291         u8 bFunctionLength;
292         u8 bDescriptorType;
293         u8 bDescriptorSubtype;  /* 0x04 */
294         u8 bRingerVolSeps;
295         u8 bNumRingerPatterns;
296 } __attribute__ ((packed));
297
298 struct usb_class_telephone_call_descriptor {
299         u8 bFunctionLength;
300         u8 bDescriptorType;
301         u8 bDescriptorSubtype;  /* 0x05 */
302         u8 bmCapabilities;
303 } __attribute__ ((packed));
304
305 struct usb_class_union_function_descriptor {
306         u8 bFunctionLength;
307         u8 bDescriptorType;
308         u8 bDescriptorSubtype;  /* 0x06 */
309         u8 bMasterInterface;
310         /* u8 bSlaveInterface0[0]; */
311         u8 bSlaveInterface0;
312 } __attribute__ ((packed));
313
314 struct usb_class_country_selection_descriptor {
315         u8 bFunctionLength;
316         u8 bDescriptorType;
317         u8 bDescriptorSubtype;  /* 0x07 */
318         u8 iCountryCodeRelDate;
319         u16 wCountryCode0[0];
320 } __attribute__ ((packed));
321
322
323 struct usb_class_telephone_operational_descriptor {
324         u8 bFunctionLength;
325         u8 bDescriptorType;
326         u8 bDescriptorSubtype;  /* 0x08 */
327         u8 bmCapabilities;
328 } __attribute__ ((packed));
329
330
331 struct usb_class_usb_terminal_descriptor {
332         u8 bFunctionLength;
333         u8 bDescriptorType;
334         u8 bDescriptorSubtype;  /* 0x09 */
335         u8 bEntityId;
336         u8 bInterfaceNo;
337         u8 bOutInterfaceNo;
338         u8 bmOptions;
339         u8 bChild0[0];
340 } __attribute__ ((packed));
341
342 struct usb_class_network_channel_descriptor {
343         u8 bFunctionLength;
344         u8 bDescriptorType;
345         u8 bDescriptorSubtype;  /* 0x0a */
346         u8 bEntityId;
347         u8 iName;
348         u8 bChannelIndex;
349         u8 bPhysicalInterface;
350 } __attribute__ ((packed));
351
352 struct usb_class_protocol_unit_function_descriptor {
353         u8 bFunctionLength;
354         u8 bDescriptorType;
355         u8 bDescriptorSubtype;  /* 0x0b */
356         u8 bEntityId;
357         u8 bProtocol;
358         u8 bChild0[0];
359 } __attribute__ ((packed));
360
361 struct usb_class_extension_unit_descriptor {
362         u8 bFunctionLength;
363         u8 bDescriptorType;
364         u8 bDescriptorSubtype;  /* 0x0c */
365         u8 bEntityId;
366         u8 bExtensionCode;
367         u8 iName;
368         u8 bChild0[0];
369 } __attribute__ ((packed));
370
371 struct usb_class_multi_channel_descriptor {
372         u8 bFunctionLength;
373         u8 bDescriptorType;
374         u8 bDescriptorSubtype;  /* 0x0d */
375         u8 bmCapabilities;
376 } __attribute__ ((packed));
377
378 struct usb_class_capi_control_descriptor {
379         u8 bFunctionLength;
380         u8 bDescriptorType;
381         u8 bDescriptorSubtype;  /* 0x0e */
382         u8 bmCapabilities;
383 } __attribute__ ((packed));
384
385 struct usb_class_ethernet_networking_descriptor {
386         u8 bFunctionLength;
387         u8 bDescriptorType;
388         u8 bDescriptorSubtype;  /* 0x0f */
389         u8 iMACAddress;
390         u32 bmEthernetStatistics;
391         u16 wMaxSegmentSize;
392         u16 wNumberMCFilters;
393         u8 bNumberPowerFilters;
394 } __attribute__ ((packed));
395
396 struct usb_class_atm_networking_descriptor {
397         u8 bFunctionLength;
398         u8 bDescriptorType;
399         u8 bDescriptorSubtype;  /* 0x10 */
400         u8 iEndSystermIdentifier;
401         u8 bmDataCapabilities;
402         u8 bmATMDeviceStatistics;
403         u16 wType2MaxSegmentSize;
404         u16 wType3MaxSegmentSize;
405         u16 wMaxVC;
406 } __attribute__ ((packed));
407
408
409 struct usb_class_mdlm_descriptor {
410         u8 bFunctionLength;
411         u8 bDescriptorType;
412         u8 bDescriptorSubtype;  /* 0x12 */
413         u16 bcdVersion;
414         u8 bGUID[16];
415 } __attribute__ ((packed));
416
417 struct usb_class_mdlmd_descriptor {
418         u8 bFunctionLength;
419         u8 bDescriptorType;
420         u8 bDescriptorSubtype;  /* 0x13 */
421         u8 bGuidDescriptorType;
422         u8 bDetailData[0];
423
424 } __attribute__ ((packed));
425
426 /*
427  * HID class descriptor structures
428  *
429  * c.f. HID 6.2.1
430  */
431
432 struct usb_class_hid_descriptor {
433     u8        bLength;
434     u8        bDescriptorType;
435     u16       bcdCDC;
436     u8        bCountryCode;
437     u8        bNumDescriptors;  /* 0x01 */
438     u8        bDescriptorType0;
439     u16       wDescriptorLength0;
440     /* optional descriptors are not supported. */
441 } __attribute__((packed));
442
443 struct usb_class_report_descriptor {
444     u8        bLength;  /* dummy */
445     u8        bDescriptorType;
446     u16       wLength;
447     u8          bData[0];
448 } __attribute__((packed));
449
450 /*
451  * descriptor union structures
452  */
453
454 struct usb_descriptor {
455         union {
456                 struct usb_generic_descriptor generic;
457                 struct usb_endpoint_descriptor endpoint;
458                 struct usb_interface_descriptor interface;
459                 struct usb_configuration_descriptor configuration;
460                 struct usb_device_descriptor device;
461                 struct usb_string_descriptor string;
462         } descriptor;
463
464 } __attribute__ ((packed));
465
466 struct usb_class_descriptor {
467         union {
468                 struct usb_class_function_descriptor function;
469                 struct usb_class_function_descriptor_generic generic;
470                 struct usb_class_header_function_descriptor header_function;
471                 struct usb_class_call_management_descriptor call_management;
472                 struct usb_class_abstract_control_descriptor abstract_control;
473                 struct usb_class_direct_line_descriptor direct_line;
474                 struct usb_class_telephone_ringer_descriptor telephone_ringer;
475                 struct usb_class_telephone_operational_descriptor telephone_operational;
476                 struct usb_class_telephone_call_descriptor telephone_call;
477                 struct usb_class_union_function_descriptor union_function;
478                 struct usb_class_country_selection_descriptor country_selection;
479                 struct usb_class_usb_terminal_descriptor usb_terminal;
480                 struct usb_class_network_channel_descriptor network_channel;
481                 struct usb_class_extension_unit_descriptor extension_unit;
482                 struct usb_class_multi_channel_descriptor multi_channel;
483                 struct usb_class_capi_control_descriptor capi_control;
484                 struct usb_class_ethernet_networking_descriptor ethernet_networking;
485                 struct usb_class_atm_networking_descriptor atm_networking;
486                 struct usb_class_mdlm_descriptor mobile_direct;
487                 struct usb_class_mdlmd_descriptor mobile_direct_detail;
488                 struct usb_class_hid_descriptor hid;
489         } descriptor;
490
491 } __attribute__ ((packed));
492
493 #ifdef DEBUG
494 static inline void print_device_descriptor(struct usb_device_descriptor *d)
495 {
496         serial_printf("usb device descriptor \n");
497         serial_printf("\tbLength %2.2x\n", d->bLength);
498         serial_printf("\tbDescriptorType %2.2x\n", d->bDescriptorType);
499         serial_printf("\tbcdUSB %4.4x\n", d->bcdUSB);
500         serial_printf("\tbDeviceClass %2.2x\n", d->bDeviceClass);
501         serial_printf("\tbDeviceSubClass %2.2x\n", d->bDeviceSubClass);
502         serial_printf("\tbDeviceProtocol %2.2x\n", d->bDeviceProtocol);
503         serial_printf("\tbMaxPacketSize0 %2.2x\n", d->bMaxPacketSize0);
504         serial_printf("\tidVendor %4.4x\n", d->idVendor);
505         serial_printf("\tidProduct %4.4x\n", d->idProduct);
506         serial_printf("\tbcdDevice %4.4x\n", d->bcdDevice);
507         serial_printf("\tiManufacturer %2.2x\n", d->iManufacturer);
508         serial_printf("\tiProduct %2.2x\n", d->iProduct);
509         serial_printf("\tiSerialNumber %2.2x\n", d->iSerialNumber);
510         serial_printf("\tbNumConfigurations %2.2x\n", d->bNumConfigurations);
511 }
512
513 #else
514
515 /* stubs */
516 #define print_device_descriptor(d)
517
518 #endif /* DEBUG */
519 #endif