| 1 | /* |
| 2 | * Copyright (C) 2009 Qi Hardware Inc., |
| 3 | * Author: Xiangfu Liu <xiangfu@qi-hardware.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * version 3 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA |
| 18 | */ |
| 19 | #ifndef __USB_H |
| 20 | #define __USB_H |
| 21 | |
| 22 | #ifndef u8 |
| 23 | #define u8 unsigned char |
| 24 | #endif |
| 25 | |
| 26 | #ifndef u16 |
| 27 | #define u16 unsigned short |
| 28 | #endif |
| 29 | |
| 30 | #ifndef u32 |
| 31 | #define u32 unsigned int |
| 32 | #endif |
| 33 | |
| 34 | #ifndef s8 |
| 35 | #define s8 char |
| 36 | #endif |
| 37 | |
| 38 | #ifndef s16 |
| 39 | #define s16 short |
| 40 | #endif |
| 41 | |
| 42 | #ifndef s32 |
| 43 | #define s32 int |
| 44 | #endif |
| 45 | |
| 46 | extern int usbdebug; |
| 47 | |
| 48 | enum USB_ENDPOINT_TYPE |
| 49 | { |
| 50 | ENDPOINT_TYPE_CONTROL, |
| 51 | /* Typically used to configure a device when attached to the host. |
| 52 | * It may also be used for other device specific purposes, including |
| 53 | * control of other pipes on the device. |
| 54 | */ |
| 55 | ENDPOINT_TYPE_ISOCHRONOUS, |
| 56 | /* Typically used for applications which need guaranteed speed. |
| 57 | * Isochronous transfer is fast but with possible data loss. A typical |
| 58 | * use is audio data which requires a constant data rate. |
| 59 | */ |
| 60 | ENDPOINT_TYPE_BULK, |
| 61 | /* Typically used by devices that generate or consume data in relatively |
| 62 | * large and bursty quantities. Bulk transfer has wide dynamic latitude |
| 63 | * in transmission constraints. It can use all remaining available bandwidth, |
| 64 | * but with no guarantees on bandwidth or latency. Since the USB bus is |
| 65 | * normally not very busy, there is typically 90% or more of the bandwidth |
| 66 | * available for USB transfers. |
| 67 | */ |
| 68 | ENDPOINT_TYPE_INTERRUPT |
| 69 | /* Typically used by devices that need guaranteed quick responses |
| 70 | * (bounded latency). |
| 71 | */ |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | enum USB_STANDARD_REQUEST_CODE { |
| 76 | GET_STATUS, |
| 77 | CLEAR_FEATURE, |
| 78 | SET_FEATURE = 3, |
| 79 | SET_ADDRESS = 5, |
| 80 | GET_DESCRIPTOR, |
| 81 | SET_DESCRIPTOR, |
| 82 | GET_CONFIGURATION, |
| 83 | SET_CONFIGURATION, |
| 84 | GET_INTERFACE, |
| 85 | SET_INTERFACE, |
| 86 | SYNCH_FRAME |
| 87 | }; |
| 88 | |
| 89 | |
| 90 | enum USB_DESCRIPTOR_TYPE { |
| 91 | DEVICE_DESCRIPTOR = 1, |
| 92 | CONFIGURATION_DESCRIPTOR, |
| 93 | STRING_DESCRIPTOR, |
| 94 | INTERFACE_DESCRIPTOR, |
| 95 | ENDPOINT_DESCRIPTOR, |
| 96 | DEVICE_QUALIFIER_DESCRIPTOR, |
| 97 | OTHER_SPEED_CONFIGURATION_DESCRIPTOR, |
| 98 | INTERFACE_POWER1_DESCRIPTOR |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | enum USB_FEATURE_SELECTOR { |
| 103 | ENDPOINT_HALT, |
| 104 | DEVICE_REMOTE_WAKEUP, |
| 105 | TEST_MODE |
| 106 | }; |
| 107 | |
| 108 | enum USB_CLASS_CODE { |
| 109 | CLASS_DEVICE, |
| 110 | CLASS_AUDIO, |
| 111 | CLASS_COMM_AND_CDC_CONTROL, |
| 112 | CLASS_HID, |
| 113 | CLASS_PHYSICAL = 0x05, |
| 114 | CLASS_STILL_IMAGING, |
| 115 | CLASS_PRINTER, |
| 116 | CLASS_MASS_STORAGE, |
| 117 | CLASS_HUB, |
| 118 | CLASS_CDC_DATA, |
| 119 | CLASS_SMART_CARD, |
| 120 | CLASS_CONTENT_SECURITY = 0x0d, |
| 121 | CLASS_VIDEO, |
| 122 | CLASS_DIAGNOSTIC_DEVICE = 0xdc, |
| 123 | CLASS_WIRELESS_CONTROLLER = 0xe0, |
| 124 | CLASS_MISCELLANEOUS = 0xef, |
| 125 | CLASS_APP_SPECIFIC = 0xfe, |
| 126 | CLASS_VENDOR_SPECIFIC = 0xff |
| 127 | }; |
| 128 | |
| 129 | |
| 130 | typedef struct { |
| 131 | u8 bmRequestType; |
| 132 | u8 bRequest; |
| 133 | u16 wValue; |
| 134 | u16 wIndex; |
| 135 | u16 wLength; |
| 136 | } __attribute__ ((packed)) USB_DeviceRequest; |
| 137 | |
| 138 | |
| 139 | typedef struct { |
| 140 | u8 bLength; |
| 141 | u8 bDescriptorType; |
| 142 | u16 bcdUSB; |
| 143 | u8 bDeviceClass; |
| 144 | u8 bDeviceSubClass; |
| 145 | u8 bDeviceProtocol; |
| 146 | u8 bMaxPacketSize0; |
| 147 | u16 idVendor; |
| 148 | u16 idProduct; |
| 149 | u16 bcdDevice; |
| 150 | u8 iManufacturer; |
| 151 | u8 iProduct; |
| 152 | u8 iSerialNumber; |
| 153 | u8 bNumConfigurations; |
| 154 | } __attribute__ ((packed)) USB_DeviceDescriptor; |
| 155 | |
| 156 | |
| 157 | typedef struct { |
| 158 | u8 bLength; |
| 159 | u8 bDescriptorType; |
| 160 | u16 bcdUSB; |
| 161 | u8 bDeviceClass; |
| 162 | u8 bDeviceSubClass; |
| 163 | u8 bDeviceProtocol; |
| 164 | u8 bMaxPacketSize0; |
| 165 | u8 bNumConfigurations; |
| 166 | u8 bReserved; |
| 167 | } __attribute__ ((packed)) USB_DeviceQualifierDescriptor; |
| 168 | |
| 169 | |
| 170 | typedef struct { |
| 171 | u8 bLength; |
| 172 | u8 bDescriptorType; |
| 173 | u16 wTotalLength; |
| 174 | u8 bNumInterfaces; |
| 175 | u8 bConfigurationValue; |
| 176 | u8 iConfiguration; |
| 177 | u8 bmAttributes; |
| 178 | u8 MaxPower; |
| 179 | } __attribute__ ((packed)) USB_ConfigDescriptor; |
| 180 | |
| 181 | |
| 182 | typedef struct { |
| 183 | u8 bLength; |
| 184 | u8 bDescriptorType; |
| 185 | u16 wTotalLength; |
| 186 | u8 bNumInterfaces; |
| 187 | u8 bConfigurationValue; |
| 188 | u8 iConfiguration; |
| 189 | u8 bmAttributes; |
| 190 | u8 bMaxPower; |
| 191 | } __attribute__ ((packed)) USB_OtherSpeedConfigDescriptor; |
| 192 | |
| 193 | |
| 194 | typedef struct { |
| 195 | u8 bLength; |
| 196 | u8 bDescriptorType; |
| 197 | u8 bInterfaceNumber; |
| 198 | u8 bAlternateSetting; |
| 199 | u8 bNumEndpoints; |
| 200 | u8 bInterfaceClass; |
| 201 | u8 bInterfaceSubClass; |
| 202 | u8 bInterfaceProtocol; |
| 203 | u8 iInterface; |
| 204 | } __attribute__ ((packed)) USB_InterfaceDescriptor; |
| 205 | |
| 206 | |
| 207 | typedef struct { |
| 208 | u8 bLegth; |
| 209 | u8 bDescriptorType; |
| 210 | u8 bEndpointAddress; |
| 211 | u8 bmAttributes; |
| 212 | u16 wMaxPacketSize; |
| 213 | u8 bInterval; |
| 214 | } __attribute__ ((packed)) USB_EndPointDescriptor; |
| 215 | |
| 216 | |
| 217 | typedef struct { |
| 218 | u8 bLength; |
| 219 | u8 bDescriptorType; |
| 220 | u16 SomeDesriptor[1]; |
| 221 | } __attribute__ ((packed)) USB_StringDescriptor; |
| 222 | |
| 223 | |
| 224 | #endif // !defined(__USB_H) |
| 225 | |
| 226 | |