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 10 * 11 ********************************************************************* 12 * 13 * Copyright 2000,2001,2002,2003 14 * Broadcom Corporation. All rights reserved. 15 * 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. 22 * 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. 26 * 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. 32 * 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 ********************************************************************* */ 47 48 49 50#ifndef _USBCHAP9_H_ 51#define _USBCHAP9_H_ 52 53#define MAXIMUM_USB_STRING_LENGTH 255 54 55/* 56 * values for the bits returned by the USB GET_STATUS command 57 */ 58#define USB_GETSTATUS_SELF_POWERED 0x01 59#define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED 0x02 60 61 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 70 71#define USB_DESCRIPTOR_TYPEINDEX(d, i) ((uint16_t)((uint16_t)(d)<<8 | (i))) 72 73/* 74 * Values for bmAttributes field of an 75 * endpoint descriptor 76 */ 77 78#define USB_ENDPOINT_TYPE_MASK 0x03 79 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 84 85 86/* 87 * definitions for bits in the bmAttributes field of a 88 * configuration descriptor. 89 */ 90#define USB_CONFIG_POWERED_MASK 0xc0 91 92#define USB_CONFIG_BUS_POWERED 0x80 93#define USB_CONFIG_SELF_POWERED 0x40 94#define USB_CONFIG_REMOTE_WAKEUP 0x20 95 96/* 97 * Endpoint direction bit, stored in address 98 */ 99 100#define USB_ENDPOINT_DIRECTION_MASK 0x80 101#define USB_ENDPOINT_DIRECTION_IN 0x80 /* bit set means IN */ 102 103/* 104 * test direction bit in the bEndpointAddress field of 105 * an endpoint descriptor. 106 */ 107#define USB_ENDPOINT_DIR_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK)) 108#define USB_ENDPOINT_DIR_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK) 109 110#define USB_ENDPOINT_ADDRESS(addr) ((addr) & 0x0F) 111 112/* 113 * USB defined request codes 114 * see chapter 9 of the USB 1.0 specifcation for 115 * more information. 116 */ 117 118/* 119 * These are the correct values based on the USB 1.0 120 * specification 121 */ 122 123#define USB_REQUEST_GET_STATUS 0x00 124#define USB_REQUEST_CLEAR_FEATURE 0x01 125 126#define USB_REQUEST_SET_FEATURE 0x03 127 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 136 137 138/* 139 * defined USB device classes 140 */ 141 142 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 154 155/* 156 * USB defined Feature selectors 157 */ 158 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 165 166/* 167 * USB Device descriptor. 168 * To reduce problems with compilers trying to optimize 169 * this structure, all the fields are bytes. 170 */ 171 172#define USBWORD(x) ((x) & 0xFF),(((x) >> 8) & 0xFF) 173 174#define USB_CONTROL_ENDPOINT_MIN_SIZE 8 175 176typedef 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; 192 193typedef 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; 201 202/* 203 * values for bmAttributes Field in 204 * USB_CONFIGURATION_DESCRIPTOR 205 */ 206 207#define CONFIG_BUS_POWERED 0x80 208#define CONFIG_SELF_POWERED 0x40 209#define CONFIG_REMOTE_WAKEUP 0x20 210 211typedef 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; 221 222#define USB_INTERFACE_CLASS_HUB 0x09 223 224typedef 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; 235 236typedef struct usb_string_descr_s { 237 uint8_t bLength; 238 uint8_t bDescriptorType; 239 uint8_t bString[1]; 240} usb_string_descr_t; 241 242/* 243 * USB power descriptor added to core specification 244 * XXX Note uint16_t fields. Not currently used by CFE. 245 */ 246 247#define USB_SUPPORT_D0_COMMAND 0x01 248#define USB_SUPPORT_D1_COMMAND 0x02 249#define USB_SUPPORT_D2_COMMAND 0x04 250#define USB_SUPPORT_D3_COMMAND 0x08 251 252#define USB_SUPPORT_D1_WAKEUP 0x10 253#define USB_SUPPORT_D2_WAKEUP 0x20 254 255 256typedef struct usb_power_descr_s { 257 uint8_t bLength; 258 uint8_t bDescriptorType; 259 uint8_t bCapabilitiesFlags; 260 uint16_t EventNotification; 261 uint16_t D1LatencyTime; 262 uint16_t D2LatencyTime; 263 uint16_t D3LatencyTime; 264 uint8_t PowerUnit; 265 uint16_t D0PowerConsumption; 266 uint16_t D1PowerConsumption; 267 uint16_t D2PowerConsumption; 268} usb_power_descr_t; 269 270 271typedef struct usb_common_descr_s { 272 uint8_t bLength; 273 uint8_t bDescriptorType; 274} usb_common_descr_t; 275 276typedef struct usb_device_status_s { 277 uint8_t wDeviceStatusLow,wDeviceStatusHigh; 278} usb_device_status_t; 279 280 281/* 282 * Standard USB HUB definitions 283 * 284 * See Chapter 11 285 */ 286 287#define USB_HUB_DESCR_SIZE 8 288typedef struct usb_hub_descr_s { 289 uint8_t bDescriptorLength; /* Length of this descriptor */ 290 uint8_t bDescriptorType; /* Hub configuration type */ 291 uint8_t bNumberOfPorts; /* number of ports on this hub */ 292 uint8_t wHubCharacteristicsLow; /* Hub Charateristics */ 293 uint8_t wHubCharacteristicsHigh; 294 uint8_t bPowerOnToPowerGood; /* port power on till power good in 2ms */ 295 uint8_t bHubControlCurrent; /* max current in mA */ 296 /* room for 255 ports power control and removable bitmask */ 297 uint8_t bRemoveAndPowerMask[64]; 298} usb_hub_descr_t; 299 300#define USB_HUBCHAR_PWR_GANGED 0 301#define USB_HUBCHAR_PWR_IND 1 302#define USB_HUBCHAR_PWR_NONE 2 303 304typedef struct usb_hub_status_s { 305 uint8_t wHubStatusLow,wHubStatusHigh; 306 uint8_t wHubChangeLow,wHubChangeHigh; 307} usb_hub_status_t; 308 309#define USB_PORT_STATUS_CONNECT 0x0001 310#define USB_PORT_STATUS_ENABLED 0x0002 311#define USB_PORT_STATUS_SUSPEND 0x0004 312#define USB_PORT_STATUS_OVERCUR 0x0008 313#define USB_PORT_STATUS_RESET 0x0010 314#define USB_PORT_STATUS_POWER 0x0100 315#define USB_PORT_STATUS_LOWSPD 0x0200 316 317typedef struct usb_port_status_s { 318 uint8_t wPortStatusLow,wPortStatusHigh; 319 uint8_t wPortChangeLow,wPortChangeHigh; 320} usb_port_status_t; 321 322 323#define USB_HUBREQ_GET_STATUS 0 324#define USB_HUBREQ_CLEAR_FEATURE 1 325#define USB_HUBREQ_GET_STATE 2 326#define USB_HUBREQ_SET_FEATURE 3 327#define USB_HUBREQ_GET_DESCRIPTOR 6 328#define USB_HUBREQ_SET_DESCRIPTOR 7 329 330#define USB_HUB_FEATURE_C_LOCAL_POWER 0 331#define USB_HUB_FEATURE_C_OVER_CURRENT 1 332 333#define USB_PORT_FEATURE_CONNECTION 0 334#define USB_PORT_FEATURE_ENABLE 1 335#define USB_PORT_FEATURE_SUSPEND 2 336#define USB_PORT_FEATURE_OVER_CURRENT 3 337#define USB_PORT_FEATURE_RESET 4 338#define USB_PORT_FEATURE_POWER 8 339#define USB_PORT_FEATURE_LOW_SPEED 9 340#define USB_PORT_FEATURE_C_PORT_CONNECTION 16 341#define USB_PORT_FEATURE_C_PORT_ENABLE 17 342#define USB_PORT_FEATURE_C_PORT_SUSPEND 18 343#define USB_PORT_FEATURE_C_PORT_OVER_CURRENT 19 344#define USB_PORT_FEATURE_C_PORT_RESET 20 345 346 347#define GETUSBFIELD(s,f) (((s)->f##Low) | ((s)->f##High << 8)) 348#define PUTUSBFIELD(s,f,v) (s)->f##Low = (v & 0xFF); \ 349 (s)->f##High = ((v)>>8 & 0xFF) 350 351typedef struct usb_device_request_s { 352 uint8_t bmRequestType; 353 uint8_t bRequest; 354 uint8_t wValueLow,wValueHigh; 355 uint8_t wIndexLow,wIndexHigh; 356 uint8_t wLengthLow,wLengthHigh; 357} usb_device_request_t; 358 359/* 360 * Values for the bmAttributes field of a request 361 */ 362#define USBREQ_DIR_IN 0x80 363#define USBREQ_DIR_OUT 0x00 364#define USBREQ_TYPE_STD 0x00 365#define USBREQ_TYPE_CLASS 0x20 366#define USBREQ_TYPE_VENDOR 0x40 367#define USBREQ_TYPE_RSVD 0x60 368#define USBREQ_REC_DEVICE 0x00 369#define USBREQ_REC_INTERFACE 0x01 370#define USBREQ_REC_ENDPOINT 0x02 371#define USBREQ_REC_OTHER 0x03 372 373#define REQCODE(req,dir,type,rec) (((req) << 8) | (dir) | (type) | (rec)) 374#define REQSW(req,attr) (((req) << 8) | (attr)) 375 376/* ********************************************************************* 377 * HID stuff 378 ********************************************************************* */ 379 380typedef struct usb_hid_descr_s { 381 uint8_t bLength; 382 uint8_t bDescriptorType; 383 uint8_t bcdHIDLow,bcdHIDHigh; 384 uint8_t bCountryCode; 385 uint8_t bNumDescriptors; 386 uint8_t bClassDescrType; 387 uint8_t wClassDescrLengthLow,wClassDescrLengthHigh; 388} usb_hid_descr_t; 389 390#endif /* _USBCHAP9_H_ */ 391