BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / cfe / cfe / usb / usbchap9.h
blob1afd0db47ef8955c9e05396de911c08a2b4de971
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Chapter 9 definitions File: usbchap9.h
5 *
6 * This module contains definitions from the USB specification,
7 * chapter 9.
8 *
9 * Author: Mitch Lichtenberg (mpl@broadcom.com)
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
50 #ifndef _USBCHAP9_H_
51 #define _USBCHAP9_H_
53 #define MAXIMUM_USB_STRING_LENGTH 255
56 * values for the bits returned by the USB GET_STATUS command
58 #define USB_GETSTATUS_SELF_POWERED 0x01
59 #define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED 0x02
62 #define USB_DEVICE_DESCRIPTOR_TYPE 0x01
63 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
64 #define USB_STRING_DESCRIPTOR_TYPE 0x03
65 #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
66 #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
67 #define USB_POWER_DESCRIPTOR_TYPE 0x06
68 #define USB_HID_DESCRIPTOR_TYPE 0x21
69 #define USB_HUB_DESCRIPTOR_TYPE 0x29
71 #define USB_DESCRIPTOR_TYPEINDEX(d, i) ((uint16_t)((uint16_t)(d)<<8 | (i)))
74 * Values for bmAttributes field of an
75 * endpoint descriptor
78 #define USB_ENDPOINT_TYPE_MASK 0x03
80 #define USB_ENDPOINT_TYPE_CONTROL 0x00
81 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
82 #define USB_ENDPOINT_TYPE_BULK 0x02
83 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
87 * definitions for bits in the bmAttributes field of a
88 * configuration descriptor.
90 #define USB_CONFIG_POWERED_MASK 0xc0
92 #define USB_CONFIG_BUS_POWERED 0x80
93 #define USB_CONFIG_SELF_POWERED 0x40
94 #define USB_CONFIG_REMOTE_WAKEUP 0x20
97 * Endpoint direction bit, stored in address
100 #define USB_ENDPOINT_DIRECTION_MASK 0x80
101 #define USB_ENDPOINT_DIRECTION_IN 0x80 /* bit set means IN */
104 * test direction bit in the bEndpointAddress field of
105 * an endpoint descriptor.
107 #define USB_ENDPOINT_DIR_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
108 #define USB_ENDPOINT_DIR_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK)
110 #define USB_ENDPOINT_ADDRESS(addr) ((addr) & 0x0F)
113 * USB defined request codes
114 * see chapter 9 of the USB 1.0 specifcation for
115 * more information.
119 * These are the correct values based on the USB 1.0
120 * specification
123 #define USB_REQUEST_GET_STATUS 0x00
124 #define USB_REQUEST_CLEAR_FEATURE 0x01
126 #define USB_REQUEST_SET_FEATURE 0x03
128 #define USB_REQUEST_SET_ADDRESS 0x05
129 #define USB_REQUEST_GET_DESCRIPTOR 0x06
130 #define USB_REQUEST_SET_DESCRIPTOR 0x07
131 #define USB_REQUEST_GET_CONFIGURATION 0x08
132 #define USB_REQUEST_SET_CONFIGURATION 0x09
133 #define USB_REQUEST_GET_INTERFACE 0x0A
134 #define USB_REQUEST_SET_INTERFACE 0x0B
135 #define USB_REQUEST_SYNC_FRAME 0x0C
139 * defined USB device classes
143 #define USB_DEVICE_CLASS_RESERVED 0x00
144 #define USB_DEVICE_CLASS_AUDIO 0x01
145 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
146 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
147 #define USB_DEVICE_CLASS_MONITOR 0x04
148 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
149 #define USB_DEVICE_CLASS_POWER 0x06
150 #define USB_DEVICE_CLASS_PRINTER 0x07
151 #define USB_DEVICE_CLASS_STORAGE 0x08
152 #define USB_DEVICE_CLASS_HUB 0x09
153 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
156 * USB defined Feature selectors
159 #define USB_FEATURE_ENDPOINT_STALL 0x0000
160 #define USB_FEATURE_REMOTE_WAKEUP 0x0001
161 #define USB_FEATURE_POWER_D0 0x0002
162 #define USB_FEATURE_POWER_D1 0x0003
163 #define USB_FEATURE_POWER_D2 0x0004
164 #define USB_FEATURE_POWER_D3 0x0005
167 * USB Device descriptor.
168 * To reduce problems with compilers trying to optimize
169 * this structure, all the fields are bytes.
172 #define USBWORD(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
174 #define USB_CONTROL_ENDPOINT_MIN_SIZE 8
176 typedef struct usb_device_descr_s {
177 uint8_t bLength;
178 uint8_t bDescriptorType;
179 uint8_t bcdUSBLow,bcdUSBHigh;
180 uint8_t bDeviceClass;
181 uint8_t bDeviceSubClass;
182 uint8_t bDeviceProtocol;
183 uint8_t bMaxPacketSize0;
184 uint8_t idVendorLow,idVendorHigh;
185 uint8_t idProductLow,idProductHigh;
186 uint8_t bcdDeviceLow,bcdDeviceHigh;
187 uint8_t iManufacturer;
188 uint8_t iProduct;
189 uint8_t iSerialNumber;
190 uint8_t bNumConfigurations;
191 } usb_device_descr_t;
193 typedef struct usb_endpoint_descr_s {
194 uint8_t bLength;
195 uint8_t bDescriptorType;
196 uint8_t bEndpointAddress;
197 uint8_t bmAttributes;
198 uint8_t wMaxPacketSizeLow,wMaxPacketSizeHigh;
199 uint8_t bInterval;
200 } usb_endpoint_descr_t;
203 * values for bmAttributes Field in
204 * USB_CONFIGURATION_DESCRIPTOR
207 #define CONFIG_BUS_POWERED 0x80
208 #define CONFIG_SELF_POWERED 0x40
209 #define CONFIG_REMOTE_WAKEUP 0x20
211 typedef struct usb_config_descr_s {
212 uint8_t bLength;
213 uint8_t bDescriptorType;
214 uint8_t wTotalLengthLow,wTotalLengthHigh;
215 uint8_t bNumInterfaces;
216 uint8_t bConfigurationValue;
217 uint8_t iConfiguration;
218 uint8_t bmAttributes;
219 uint8_t MaxPower;
220 } usb_config_descr_t;
222 #define USB_INTERFACE_CLASS_HUB 0x09
224 typedef struct usb_interface_descr_s {
225 uint8_t bLength;
226 uint8_t bDescriptorType;
227 uint8_t bInterfaceNumber;
228 uint8_t bAlternateSetting;
229 uint8_t bNumEndpoints;
230 uint8_t bInterfaceClass;
231 uint8_t bInterfaceSubClass;
232 uint8_t bInterfaceProtocol;
233 uint8_t iInterface;
234 } usb_interface_descr_t;
236 typedef struct usb_string_descr_s {
237 uint8_t bLength;
238 uint8_t bDescriptorType;
239 uint8_t bString[1];
240 } usb_string_descr_t;
243 * USB power descriptor added to core specification
246 #define USB_SUPPORT_D0_COMMAND 0x01
247 #define USB_SUPPORT_D1_COMMAND 0x02
248 #define USB_SUPPORT_D2_COMMAND 0x04
249 #define USB_SUPPORT_D3_COMMAND 0x08
251 #define USB_SUPPORT_D1_WAKEUP 0x10
252 #define USB_SUPPORT_D2_WAKEUP 0x20
255 typedef struct usb_power_descr_s {
256 uint8_t bLength;
257 uint8_t bDescriptorType;
258 uint8_t bCapabilitiesFlags;
259 uint16_t EventNotification;
260 uint16_t D1LatencyTime;
261 uint16_t D2LatencyTime;
262 uint16_t D3LatencyTime;
263 uint8_t PowerUnit;
264 uint16_t D0PowerConsumption;
265 uint16_t D1PowerConsumption;
266 uint16_t D2PowerConsumption;
267 } usb_power_descr_t;
270 typedef struct usb_common_descr_s {
271 uint8_t bLength;
272 uint8_t bDescriptorType;
273 } usb_common_descr_t;
275 typedef struct usb_device_status_s {
276 uint8_t wDeviceStatusLow,wDeviceStatusHigh;
277 } usb_device_status_t;
281 * Standard USB HUB definitions
283 * See Chapter 11
286 #define USB_HUB_DESCR_SIZE 8
287 typedef struct usb_hub_descr_s {
288 uint8_t bDescriptorLength; /* Length of this descriptor */
289 uint8_t bDescriptorType; /* Hub configuration type */
290 uint8_t bNumberOfPorts; /* number of ports on this hub */
291 uint8_t wHubCharacteristicsLow; /* Hub Charateristics */
292 uint8_t wHubCharacteristicsHigh;
293 uint8_t bPowerOnToPowerGood; /* port power on till power good in 2ms */
294 uint8_t bHubControlCurrent; /* max current in mA */
295 /* room for 255 ports power control and removable bitmask */
296 uint8_t bRemoveAndPowerMask[64];
297 } usb_hub_descr_t;
299 #define USB_HUBCHAR_PWR_GANGED 0
300 #define USB_HUBCHAR_PWR_IND 1
301 #define USB_HUBCHAR_PWR_NONE 2
303 typedef struct usb_hub_status_s {
304 uint8_t wHubStatusLow,wHubStatusHigh;
305 uint8_t wHubChangeLow,wHubChangeHigh;
306 } usb_hub_status_t;
308 #define USB_PORT_STATUS_CONNECT 0x0001
309 #define USB_PORT_STATUS_ENABLED 0x0002
310 #define USB_PORT_STATUS_SUSPEND 0x0004
311 #define USB_PORT_STATUS_OVERCUR 0x0008
312 #define USB_PORT_STATUS_RESET 0x0010
313 #define USB_PORT_STATUS_POWER 0x0100
314 #define USB_PORT_STATUS_LOWSPD 0x0200
316 typedef struct usb_port_status_s {
317 uint8_t wPortStatusLow,wPortStatusHigh;
318 uint8_t wPortChangeLow,wPortChangeHigh;
319 } usb_port_status_t;
322 #define USB_HUBREQ_GET_STATUS 0
323 #define USB_HUBREQ_CLEAR_FEATURE 1
324 #define USB_HUBREQ_GET_STATE 2
325 #define USB_HUBREQ_SET_FEATURE 3
326 #define USB_HUBREQ_GET_DESCRIPTOR 6
327 #define USB_HUBREQ_SET_DESCRIPTOR 7
329 #define USB_HUB_FEATURE_C_LOCAL_POWER 0
330 #define USB_HUB_FEATURE_C_OVER_CURRENT 1
332 #define USB_PORT_FEATURE_CONNECTION 0
333 #define USB_PORT_FEATURE_ENABLE 1
334 #define USB_PORT_FEATURE_SUSPEND 2
335 #define USB_PORT_FEATURE_OVER_CURRENT 3
336 #define USB_PORT_FEATURE_RESET 4
337 #define USB_PORT_FEATURE_POWER 8
338 #define USB_PORT_FEATURE_LOW_SPEED 9
339 #define USB_PORT_FEATURE_C_PORT_CONNECTION 16
340 #define USB_PORT_FEATURE_C_PORT_ENABLE 17
341 #define USB_PORT_FEATURE_C_PORT_SUSPEND 18
342 #define USB_PORT_FEATURE_C_PORT_OVER_CURRENT 19
343 #define USB_PORT_FEATURE_C_PORT_RESET 20
346 #define GETUSBFIELD(s,f) (((s)->f##Low) | ((s)->f##High << 8))
347 #define PUTUSBFIELD(s,f,v) (s)->f##Low = (v & 0xFF); \
348 (s)->f##High = ((v)>>8 & 0xFF)
350 typedef struct usb_device_request_s {
351 uint8_t bmRequestType;
352 uint8_t bRequest;
353 uint8_t wValueLow,wValueHigh;
354 uint8_t wIndexLow,wIndexHigh;
355 uint8_t wLengthLow,wLengthHigh;
356 } usb_device_request_t;
359 * Values for the bmAttributes field of a request
361 #define USBREQ_DIR_IN 0x80
362 #define USBREQ_DIR_OUT 0x00
363 #define USBREQ_TYPE_STD 0x00
364 #define USBREQ_TYPE_CLASS 0x20
365 #define USBREQ_TYPE_VENDOR 0x40
366 #define USBREQ_TYPE_RSVD 0x60
367 #define USBREQ_REC_DEVICE 0x00
368 #define USBREQ_REC_INTERFACE 0x01
369 #define USBREQ_REC_ENDPOINT 0x02
370 #define USBREQ_REC_OTHER 0x03
372 #define REQCODE(req,dir,type,rec) (((req) << 8) | (dir) | (type) | (rec))
373 #define REQSW(req,attr) (((req) << 8) | (attr))
375 /* *********************************************************************
376 * HID stuff
377 ********************************************************************* */
379 typedef struct usb_hid_descr_s {
380 uint8_t bLength;
381 uint8_t bDescriptorType;
382 uint8_t bcdHIDLow,bcdHIDHigh;
383 uint8_t bCountryCode;
384 uint8_t bNumDescriptors;
385 uint8_t bClassDescrType;
386 uint8_t wClassDescrLengthLow,wClassDescrLengthHigh;
387 } usb_hid_descr_t;
389 #endif /* _USBCHAP9_H_ */