xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/newhost/include/drvUSB_CH9.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 
79 #ifndef __MS_USB_CH9_H
80 #define __MS_USB_CH9_H
81 
82 #include "MsTypes.h"
83 
84 /*-------------------------------------------------------------------------*/
85 
86 #define USB_DIR_OUT             0       /* to device */
87 #define USB_DIR_IN              0x80    /* to host */
88 
89 #define USB_TYPE_MASK        (0x03 << 5) // pipe type
90 #define USB_TYPE_STANDARD    (0x00 << 5) // standard message
91 #define USB_TYPE_CLASS      (0x01 << 5)  // class specific message
92 #define USB_TYPE_VENDOR      (0x02 << 5) // vendor specific message
93 #define USB_TYPE_RESERVED    (0x03 << 5) // reserved
94 
95 #define USB_RECIP_MASK              0x1f
96 #define USB_RECIP_DEVICE            0x00 // target device
97 #define USB_RECIP_INTERFACE         0x01 // target interface
98 #define USB_RECIP_ENDPOINT          0x02 // target endpoint
99 #define USB_RECIP_OTHER             0x03
100 
101 #define USB_REQ_GET_STATUS          0x00 // control pipe standard command, get status
102 #define USB_REQ_CLEAR_FEATURE       0x01 // control pipe standard command, clear feature
103 #define USB_REQ_SET_FEATURE         0x03 // control pipe standard command, set feature
104 #define USB_REQ_SET_ADDRESS         0x05 // control pipe standard command, set address
105 #define USB_REQ_GET_DESCRIPTOR      0x06 // control pipe standard command, get descriptor
106 #define USB_REQ_SET_DESCRIPTOR      0x07 // control pipe standard command, set descriptor
107 #define USB_REQ_GET_CONFIGURATION   0x08 // control pipe standard command, get configuration
108 #define USB_REQ_SET_CONFIGURATION   0x09 // control pipe standard command, set configuration
109 #define USB_REQ_GET_INTERFACE       0x0A // control pipe standard command, get interface
110 #define USB_REQ_SET_INTERFACE       0x0B // control pipe standard command, set interface
111 #define USB_REQ_SYNCH_FRAME         0x0C // control pipe standard command, synchronize frame
112 
113 struct usb_ctrlrequest {
114   MS_U8 bRequestType;
115   MS_U8 bRequest;
116   MS_U16 wValue;
117   MS_U16 wIndex;
118   MS_U16 wLength;
119 } __attribute__((packed));
120 
121 /*-------------------------------------------------------------------------*/
122 
123 #define USB_DT_DEVICE               0x01
124 #define USB_DT_CONFIG               0x02
125 #define USB_DT_STRING               0x03
126 #define USB_DT_INTERFACE            0x04
127 #define USB_DT_ENDPOINT             0x05
128 #define USB_DT_DEVICE_QUALIFIER     0x06
129 #define USB_DT_OTHER_SPEED_CONFIG   0x07
130 #define USB_DT_INTERFACE_POWER      0x08
131 #define USB_DT_OTG                  0x09
132 
133 struct usb_descriptor_header {
134   MS_U8  bLength;
135   MS_U8  bDescriptorType;
136 } __attribute__((packed));
137 
138 
139 /*-------------------------------------------------------------------------*/
140 
141 /* USB_DT_DEVICE: Device descriptor */
142 struct usb_device_descriptor {
143   MS_U8  bLength;
144   MS_U8  bDescriptorType;
145 
146   MS_U16 bcdUSB;
147   MS_U8  bDeviceClass;
148   MS_U8  bDeviceSubClass;
149   MS_U8  bDeviceProtocol;
150   MS_U8  bMaxPacketSize0;
151   MS_U16 idVendor;
152   MS_U16 idProduct;
153   MS_U16 bcdDevice;
154   MS_U8  iManufacturer;
155   MS_U8  iProduct;
156   MS_U8  iSerialNumber;
157   MS_U8  bNumConfigurations;
158 } __attribute__((packed));
159 
160 #define USB_DT_DEVICE_SIZE    18
161 
162 #define USB_CLASS_PER_INTERFACE     0 /* for DeviceClass */
163 #define USB_CLASS_AUDIO             1 // audio class
164 #define USB_CLASS_COMM              2 // comminication class
165 #define USB_CLASS_HID               3 // HID class
166 #define USB_CLASS_PHYSICAL          5
167 #define USB_CLASS_STILL_IMAGE       6 // still image class for DSC
168 #define USB_CLASS_PRINTER           7 // printer class
169 #define USB_CLASS_STORAGE           8 // supported class, mass storage
170 #define USB_CLASS_HUB               9 // supported class, hub class
171 #define USB_CLASS_CDC_DATA          0x0a
172 #define USB_CLASS_CSCID             0x0b  /* chip+ smart card */
173 #define USB_CLASS_CONTENT_SEC       0x0d  /* content security */
174 #define USB_CLASS_APP_SPEC          0xfe
175 #define USB_CLASS_VENDOR_SPEC       0xff // vendor used
176 
177 /*-------------------------------------------------------------------------*/
178 
179 struct usb_config_descriptor {
180   MS_U8  bLength;
181   MS_U8  bDescriptorType;
182 
183   MS_U16 wTotalLength;
184   MS_U8  bNumInterfaces;
185   MS_U8  bConfigurationValue;
186   MS_U8  iConfiguration;
187   MS_U8  bmAttributes;
188   MS_U8  bMaxPower;
189 } __attribute__((packed));
190 
191 #define USB_DT_CONFIG_SIZE    9
192 
193 #define USB_CONFIG_ATT_ONE          (1 << 7)  /* must be set */
194 #define USB_CONFIG_ATT_SELFPOWER    (1 << 6)  /* self powered */
195 #define USB_CONFIG_ATT_WAKEUP       (1 << 5)  /* can wakeup */
196 
197 /*-------------------------------------------------------------------------*/
198 
199 /* USB_DT_STRING: String descriptor */
200 struct usb_string_descriptor {
201   MS_U8  bLength;
202   MS_U8  bDescriptorType;
203 
204   MS_U16 wData[1];    /* UTF-16LE encoded */
205 } __attribute__((packed));
206 
207 /*-------------------------------------------------------------------------*/
208 
209 /* USB_DT_INTERFACE: Interface descriptor */
210 struct usb_interface_descriptor {
211   MS_U8  bLength;
212   MS_U8  bDescriptorType;
213 
214   MS_U8  bInterfaceNumber;
215   MS_U8  bAlternateSetting;
216   MS_U8  bNumEndpoints;
217   MS_U8  bInterfaceClass;
218   MS_U8  bInterfaceSubClass;
219   MS_U8  bInterfaceProtocol;
220   MS_U8  iInterface;
221 } __attribute__((packed));
222 
223 #define USB_DT_INTERFACE_SIZE    9
224 
225 /*-------------------------------------------------------------------------*/
226 
227 /* USB_DT_ENDPOINT: Endpoint descriptor */
228 struct usb_endpoint_descriptor {
229   MS_U8  bLength;
230   MS_U8  bDescriptorType;
231 
232   MS_U8  bEndpointAddress;
233   MS_U8  bmAttributes;
234   MS_U16 wMaxPacketSize;
235   MS_U8  bInterval;
236 
237   MS_U8  bRefresh;
238   MS_U8  bSynchAddress;
239 } __attribute__((packed));
240 
241 #define USB_DT_ENDPOINT_SIZE    7
242 #define USB_DT_ENDPOINT_AUDIO_SIZE  9  /* Audio extension */
243 
244 #define USB_ENDPOINT_NUMBER_MASK  0x0f  /* in bEndpointAddress */
245 #define USB_ENDPOINT_DIR_MASK    0x80
246 
247 #define USB_ENDPOINT_XFERTYPE_MASK  0x03  /* in bmAttributes */
248 #define USB_ENDPOINT_XFER_CONTROL  0
249 #define USB_ENDPOINT_XFER_ISOC    1
250 #define USB_ENDPOINT_XFER_BULK    2
251 #define USB_ENDPOINT_XFER_INT    3
252 
253 /*-------------------------------------------------------------------------*/
254 
255 enum usb_device_speed {
256   USB_UNKNOWN_SPEED = 0,            /* enumerating */
257   USB_LOW_SPEED, USB_FULL_SPEED,    /* usb 1.1 */
258   USB_HIGH_SPEED                    /* usb 2.0 */
259 };
260 
261 enum usb_device_state {
262   USB_STATE_NOTATTACHED = 0, /* software created state not USB spec  */
263 
264   /* the chapter 9 device states */
265   USB_STATE_ATTACHED,
266   USB_STATE_POWERED,
267   USB_STATE_DEFAULT,      /* limited function */
268   USB_STATE_ADDRESS,
269   USB_STATE_CONFIGURED,      /* most functions */
270 
271   USB_STATE_SUSPENDED
272 
273 };
274 
275 /*-------------------------------------------------------------------------*/
276 #endif
277