blob: a851b15d587bafbe6224ea09914158813fa35d17 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2* °æÈ¨ËùÓÐ (C)2010, ÉîÛÚÊÐÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3*
4* ÎļþÃû³Æ£º drv_usb3slave.h
5* Îļþ±êʶ£º
6* ÄÚÈÝÕªÒª£º
7* ÆäËü˵Ã÷£º zx297520 project
8* µ±Ç°°æ±¾£º 1.0
9* ×÷¡¡¡¡Õߣº tangjian
10* Íê³ÉÈÕÆÚ£º
11*
12*
13*******************************************************************************/
14
15#ifndef __USB3_SLAVE_DRV_H
16#define __USB3_SLAVE_DRV_H
17
18/* *INDENT-OFF* */
19#ifdef __cplusplus
20extern "C" {
21#endif
22/* *INDENT-ON* */
23
24/*
25**==================================================================
26** Include files
27**==================================================================
28*/
29#include "usb.h"
30#include "global.h"
31#include "drv_usb3slave_reg.h"
32
33#include "dwc_otg_cil.h" //ÓÃÓÚ¶¨Ò廨µ÷º¯Êý
34
35/* DRV´íÎóÂë */
36#define SOK (0) /**< ÕýÈ· */
37#define ERR_FAIL (0x01) /**< Ò»°ã´íÎó */
38#define ERR_INUSE (0x02) /**< ÍâÉè×ÊÔ´ÕýÔÚʹÓà */
39#define ERR_XIO (0x03) /**< ¹²Ïí×ÊÔ´¾ºÕù */
40#define ERR_OVFL (0x04) /**< ¿ÉÓÃ×ÊÔ´ºÄ¾¡ */
41#define ERR_INVHANDLE (0x05) /**< ´«Èë¾ä±úÎÞЧ */
42#define ERR_INVPARAMS (0x06) /**< ²ÎÊýÎÞЧ */
43#define ERR_INVCMD (0x07) /**< ÃüÁîÎÞЧ */
44#define ERR_NOMEM (0x08) /**< ÄÚ´æºÄ¾¡ */
45#define ERR_UNSUPPORTED (0x09) /**< ÐÐΪ²»Ö§³Ö */
46#define ERR_INVHWVERSION (0x10) /**< Ó²¼þ°æ±¾²»Æ¥Åä */
47
48#define FALSE 0
49#define TRUE 1
50
51#define DWC3_DCFG_SPEED_MASK (7 << 0)
52
53#define DWC3_DCFG 0xc700
54#define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
55#define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
56#define DWC3_DCTL 0xc704
57#define DWC3_DCTL_CSFTRST (1 << 30)
58/*0x200-0x23c*/
59#define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04))
60/*0x2C0-0x2fc*/
61#define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04))
62
63/*0x300-0x37C*/
64#define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04))
65
66/*0x380-0x3fc*/
67#define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04))
68
69#define DWC3_GCTL 0xc110
70#define DWC3_DCTL_RUN_STOP (1 << 31)
71
72#define DWC3_DEVTEN_USBSUSPENDEN (1 << 6)
73#define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
74#define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
75#define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
76#define DWC3_DEVTEN_USBRSTEN (1 << 1)
77#define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
78
79#define DWC3_DEVTEN 0xc708
80#define DWC3_DSTS 0xc70c
81
82#define DWC3_DALEPENA 0xc720
83/** ¶¨ÒåÃèÊö·ûÀàÐÍ */
84#define USB_DT_DEVICE 0x01
85#define USB_DT_CONFIG 0x02
86#define USB_DT_STRING 0x03
87#define USB_DT_INTERFACE 0x04
88#define USB_DT_ENDPOINT 0x05
89#define USB_DT_DEVICE_QUALIFIER 0x06
90#define USB_DT_OTHER_SPEED_CONFIG 0x07
91#define USB_DT_INTERFACE_POWER 0x08
92/** these are from a minor usb 2.0 revision (ECN) */
93#define USB_DT_OTG 0x09
94#define USB_DT_DEBUG 0x0a
95#define USB_DT_INTERFACE_ASSOCIATION 0x0b
96/** these are from the Wireless USB spec */
97#define USB_DT_SECURITY 0x0c
98#define USB_DT_KEY 0x0d
99#define USB_DT_ENCRYPTION_TYPE 0x0e
100#define USB_DT_BOS 0x0f
101#define USB_DT_DEVICE_CAPABILITY 0x10
102#define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
103#define USB_DT_WIRE_ADAPTER 0x21
104#define USB_DT_RPIPE 0x22
105#define USB_DT_CS_RADIO_CONTROL 0x23
106/** From the T10 UAS specification */
107#define USB_DT_PIPE_USAGE 0x24
108/** From the USB 3.0 spec */
109#define USB_DT_SS_ENDPOINT_COMP 0x30
110/** USB directions */
111#define USB_DIR_OUT 0 /* to device */
112#define USB_DIR_IN 0x80 /* to host */
113/** USB types, the second of three bmRequestType fields, ЭÒé9.3.1 */
114#define USB_TYPE_MASK (0x03 << 5)
115#define USB_TYPE_STANDARD (0x00 << 5)
116#define USB_TYPE_CLASS (0x01 << 5)
117#define USB_TYPE_VENDOR (0x02 << 5)
118#define USB_TYPE_RESERVED (0x03 << 5)
119/** USB recipients, the third of three bmRequestType fields */
120#define USB_RECIP_MASK 0x1f
121#define USB_RECIP_DEVICE 0x00
122#define USB_RECIP_INTERFACE 0x01
123#define USB_RECIP_ENDPOINT 0x02
124#define USB_RECIP_OTHER 0x03
125/** From Wireless USB 1.0 */
126#define USB_RECIP_PORT 0x04
127#define USB_RECIP_RPIPE 0x05
128/*
129* Standard requests, for the bRequest field of a SETUP packet.
130*
131* These are qualified by the bmRequestType field, so that for example
132* TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
133* by a GET_STATUS request.
134*/
135#define USB_REQ_GET_STATUS 0x00
136#define USB_REQ_CLEAR_FEATURE 0x01
137#define USB_REQ_SET_FEATURE 0x03
138#define USB_REQ_SET_ADDRESS 0x05
139#define USB_REQ_GET_DESCRIPTOR 0x06
140#define USB_REQ_SET_DESCRIPTOR 0x07
141#define USB_REQ_GET_CONFIGURATION 0x08
142#define USB_REQ_SET_CONFIGURATION 0x09
143#define USB_REQ_GET_INTERFACE 0x0A
144#define USB_REQ_SET_INTERFACE 0x0B
145#define USB_REQ_SYNCH_FRAME 0x0C
146#define USB_REQ_GET_MAX_LUN 0xFE
147/*
148* USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
149* are read as a bit array returned by USB_REQ_GET_STATUS. (So there
150* are at most sixteen features of each type.) Hubs may also support a
151* new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
152*/
153#define USB_DEVICE_SELF_POWERED 0 /**< (read only) */
154#define USB_DEVICE_REMOTE_WAKEUP 1 /**< dev may initiate wakeup */
155#define USB_DEVICE_TEST_MODE 2 /**< (wired high speed only) */
156#define USB_DEVICE_BATTERY 2 /**< (wireless) */
157#define USB_DEVICE_B_HNP_ENABLE 3 /**< (otg) dev may initiate HNP */
158#define USB_DEVICE_WUSB_DEVICE 3 /**< (wireless)*/
159#define USB_DEVICE_A_HNP_SUPPORT 4 /**< (otg) RH port supports HNP */
160#define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /**< (otg) other RH port does */
161#define USB_DEVICE_DEBUG_MODE 6 /**< (special devices only) */
162/*
163* New Feature Selectors as added by USB 3.0
164* See USB 3.0 spec Table 9-7
165* Suspend Options, Table 9-7 USB 3.0 spec
166*/
167#define USB_DEVICE_U1_ENABLE 48 /**< dev may initiate U1 transition */
168#define USB_DEVICE_U2_ENABLE 49 /**< dev may initiate U2 transition */
169#define USB_DEVICE_LTM_ENABLE 50 /**< dev may send LTM */
170
171#define USB_INTRF_FUNC_SUSPEND 0 /**< function suspend */
172#define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
173#define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
174#define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))
175
176#define USB_ENDPOINT_HALT 0 /**< IN/OUT will STALL */
177
178/** Bit array elements as returned by the USB_REQ_GET_STATUS request */
179#define USB_DEV_STAT_U1_ENABLED 2 /**< transition into U1 state */
180#define USB_DEV_STAT_U2_ENABLED 3 /**< transition into U2 state */
181#define USB_DEV_STAT_LTM_ENABLED 4 /**< Latency tolerance messages */
182/**
183* USB function drivers should return USB_GADGET_DELAYED_STATUS if they
184* wish to delay the data/status stages of the control transfer till they
185* are ready. The control transfer will then be kept from completing till
186* all the function drivers that requested for USB_GADGET_DELAYED_STAUS
187* invoke usb_composite_setup_continue().
188*/
189#define USB_GADGET_DELAYED_STATUS 0x7fff /**< Impossibly large value */
190//#define EP0_PACKET_SIZE 64
191//#define MAX_EPS (0x8)
192
193/**
194* struct usb_ctrlrequest - SETUP data for a USB device control request
195* Note that the driver for any interface can issue control requests.
196* For most devices, interfaces don't coordinate with each other, so
197* such requests may be made at any time.
198*/
199
200 typedef struct T_USB3Slave_CtrlReq
201{
202 u8 bmRequestType; /**< Æ¥Åäsetup°übmRequestTypeÓò */
203 u8 bRequest; /**< Æ¥Åäsetup°übRequestÓò */
204 u16 wValue; /**< Æ¥Åäsetup°üwValueÓò */
205 u16 wIndex; /**< Æ¥Åäsetup°üwIndexÓò */
206 u16 wLength; /**< Æ¥Åäsetup°üwLengthÓò */
207}__attribute__ ((__packed__)) T_USB3Slave_CtrlReq;
208
209/** ¶Ëµã´«ÊäÀàÐ͵Ⱥ궨Òå */
210#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
211#define USB_ENDPOINT_DIR_MASK 0x80
212
213#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
214#define USB_ENDPOINT_XFER_CONTROL 0
215#define USB_ENDPOINT_XFER_ISOC 1
216#define USB_ENDPOINT_XFER_BULK 2
217#define USB_ENDPOINT_XFER_INT 3
218#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
219
220/** ×î´ó°ü´óС£¬²ÎÕÕЭÒ飬¾ù¿ÉÉèÖÃΪ1024 */
221#define HS_MAX_PACKET_SIZE 512
222#define FS_MAX_PACKET_SIZE 64
223/** ¿ØÖÆ´«Êä×î´ó°ü´óС */
224/** ¶ËµãÊýÄ¿ */
225#define ENDPOINTS_NUM 6
226/** ЭÒé¶ËµãÃèÊö·û */
227
228/** TRB¿ØÖÆÖи÷¸öλ¶ÎµÄºê¶¨Òå*/
229#define TRBCTL_NORMAL 1
230#define TRBCTL_CONTROL_SETUP 2
231#define TRBCTL_CONTROL_STATUS2 3
232#define TRBCTL_CONTROL_STATUS3 4
233#define TRBCTL_CONTROL_DATA 5
234#define TRBCTL_ISOCHRONOUS_FIRST 6
235#define TRBCTL_ISOCHRONOUS 7
236#define TRBCTL_LINK_TRB 8
237/** struct T_USB3Slave_TRBToHW - transfer request block (hw format) */
238typedef struct T_USB3Slave_TRBToHW
239{
240 u32 udBpl; /**< Ö¸ÏòbufferµÄµÍ32λµØÖ· */
241 u32 udBph; /**< Ö¸ÏòbufferµÄ¸ß32λµØÖ· */
242 u32 udSize; /**< Êý¾Ý´«ÊäµÄ³¤¶È */
243 u32 udCtrl; /**< TRB¿ØÖÆ */
244}__attribute__ ((__packed__)) T_USB3Slave_TRBToHW;
245
246/** struct T_USB3Slave_TRB - transfer request block */
247 typedef struct T_USB3Slave_TRB
248{
249 u64 bplh; /**< Ö¸ÏòbufferµØÖ· */
250
251 union
252 {
253 struct
254 {
255 u32 BUFSIZ:24; /**< Êý¾Ý´«ÊäµÄ³¤¶È */
256 u32 PCM1:2; /**< Packet Count M1 */
257 u32 Reserved27_26:2;
258 u32 TRBSTS:4; /**< TRB״̬ */
259 }bit;
260 u32 udVal;
261 }len_pcm;
262
263 union
264 {
265 struct
266 {
267 u32 HWO:1; /**< ָʾӲ¼þÓµÓеÄTRB */
268 u32 LST:1; /**< ×îºóÒ»¸öTRB */
269 u32 CHN:1; /**< ´ËTRBÓëÏÂÒ»¸öTRBÏà¹ØÁª */
270 u32 CSP:1; /**< µ±½ÓÊÕµ½Ò»¸ö¶Ì°ücore½«»á¼ÌÐøµ½ÏÂÒ»¸öBuffer Descriptor */
271 u32 TRBCTL:6; /**< TRB ¿ØÖÆ */
272 u32 ISP_IMI:1; /**< Interrupt on Short Packet/Interrupt on Missed ISOC */
273 u32 IOC:1; /**< Èç¹û±»ÉèÖ㬱íʾ´«ÊäÍê³Éºó²úÉúÖÐ¶Ï */
274 u32 Reserved13_12:2;
275 u32 StreamID_SOFNum:16; /**< Stream ID/SOF Number */
276 u32 Reserved31_30:2;
277 }bit;
278 u32 udVal;
279 }control;
280}__attribute__ ((__packed__)) T_USB3Slave_TRB;
281
282/** EVENT buffer´óС */
283#define EVENT_BUFFERS_SIZE 256//256
284
285/**
286* struct T_USB3Slave_EventBuf - Software event buffer representation
287*/
288
289typedef struct
290{
291 u32 EvtBuf[EVENT_BUFFERS_SIZE]; /**< ·ÖÅäµÄEVENT Buffer */
292 u32 udLength; /**< ·ÖÅäEVENT Buffer ´óС */
293 u32 udLpos; /**< ÓÃÓÚָʾµ±Ç°EVENTµÄÆðʼλÖà */
294}T_USB3Slave_EventBuf;
295
296
297/** EVENTÀàÐÍ */
298#define EVENT_TYPE_MASK 0xfe
299#define EVENT_TYPE_DEV 0
300#define EVENT_TYPE_CARKIT 3
301#define EVENT_TYPE_I2C 4
302typedef struct T_USB3Slave_EventType
303{
304 u32 udIs_devspec:1; /**< ÓÃÓÚÅжÏÊǶ˵ãÀàÐÍEVENT»¹ÊÇÉ豸ÀàÐÍEVENT */
305 u32 udType:6; /**< EVENT ÀàÐÍ */
306 u32 udReserved8_31:25;
307}__attribute__ ((__packed__)) T_USB3Slave_EventType;
308
309/** ¶ËµãÀàÐÍEVENTÀàÐÍ */
310#define DEPEVT_XFERCOMPLETE 0x01
311#define DEPEVT_XFERINPROGRESS 0x02
312#define DEPEVT_XFERNOTREADY 0x03
313#define DEPEVT_RXTXFIFOEVT 0x04
314#define DEPEVT_STREAMEVT 0x06
315#define DEPEVT_EPCMDCMPLT 0x07
316
317#define DEPEVT_STATUS_BUSERR (1 << 0)
318#define DEPEVT_STATUS_SHORT (1 << 1)
319#define DEPEVT_STATUS_IOC (1 << 2)
320#define DEPEVT_STATUS_LST (1 << 3)
321/** Stream event only */
322#define DEPEVT_STREAMEVT_FOUND 1
323#define DEPEVT_STREAMEVT_NOTFOUND 2
324/** Control-only Status */
325#define DEPEVT_STATUS_CONTROL_SETUP 0
326#define DEPEVT_STATUS_CONTROL_DATA 1
327#define DEPEVT_STATUS_CONTROL_STATUS 2
328#define DEPEVT_STATUS_STATUS_SETUP 10
329
330/**
331* struct dwc3_event_depvt - Device Endpoint Events
332* @udOne_bit: indicates this is an endpoint event (not used)
333* @udEndpoint_number: number of the endpoint
334* @udEndpoint_event: The event we have:
335* 0x00 - Reserved
336* 0x01 - XferComplete
337* 0x02 - XferInProgress
338* 0x03 - XferNotReady
339* 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
340* 0x05 - Reserved
341* 0x06 - StreamEvt
342* 0x07 - EPCmdCmplt
343* @udReserved11_10: Reserved, don't use.
344* @EventStatus: Indicates the status of the event. Refer to databook for more information.
345* @EventParam: Parameters of the current event. Refer to databook for more information.
346*/
347/** ²Î¼ûÊÖ²á7.2.8.1ÃèÊö¶ËµãÀàÐÍEVENT */
348 typedef struct T_USB3Slave_EpEvt
349{
350 u32 udOne_bit:1; /**< 1bitÓÃÓÚÅжÏÊǶ˵ãÀàÐÍevent»¹ÊÇÉ豸ÀàÐÍevent */
351 u32 udEndpoint_number:5; /**< ָʾÎïÀí¶ËµãºÅ */
352 u32 udEndpoint_event:4; /**< ָʾ¶ËµãÀàÐÍevent */
353 u32 udReserved11_10:2;
354 u32 EventStatus:4; /**< ָʾevent״̬£¬Refer to databook for more information*/
355 u32 EventParam:16; /**< µ±Ç°event²ÎÊý. Refer to databook for more information */
356}__attribute__ ((__packed__)) T_USB3Slave_EpEvt;
357
358/**
359* struct T_USB3Slave_DevEvt - Device Events
360* @udOne_bit: indicates this is a non-endpoint event (not used)
361* @udDevice_event: indicates it's a device event. Should read as 0x00
362* @udType: indicates the type of device event.
363* 0 - DisconnEvt
364* 1 - USBRst
365* 2 - ConnectDone
366* 3 - ULStChng
367* 4 - WkUpEvt
368* 5 - Reserved
369* 6 - EOPF
370* 7 - SOF
371* 8 - Reserved
372* 9 - ErrticErr
373* 10 - CmdCmplt
374* 11 - EvntOverflow
375* 12 - VndrDevTstRcved
376* @udReserved15_12: Reserved, not used
377* @udEvtInfo: Information about this event
378* @udReserved31_24: Reserved, not used
379*/
380/** DEVICE EVENT ÀàÐÍ */
381#define DEVICE_EVENT_DISCONNECT 0
382#define DEVICE_EVENT_RESET 1
383#define DEVICE_EVENT_CONNECT_DONE 2
384#define DEVICE_EVENT_LINK_STATUS_CHANGE 3
385#define DEVICE_EVENT_WAKEUP 4
386#define DEVICE_EVENT_EOPF 6
387#define DEVICE_EVENT_SOF 7
388#define DEVICE_EVENT_ERRATIC_ERROR 9
389#define DEVICE_EVENT_CMD_CMPL 10
390#define DEVICE_EVENT_OVERFLOW 11
391
392typedef struct T_USB3Slave_DevEvt
393{
394 u32 udOne_bit:1; /**< 1bitÓÃÓÚÅжÏÊǶ˵ãÀàÐÍevent»¹ÊÇÉ豸ÀàÐÍevent */
395 u32 udDevice_event:7; /**< É豸ÀàÐÍevent */
396 u32 udType:4; /**< ָʾ·¢ÉúµÄ¸÷ÖÖevent */
397 u32 udReserved15_12:4;
398 u32 udEvtInfo:8; /**< event ÐÅÏ¢±ÈÌØ¡£ÓÃÓÚָʾÊÇ·ñÊÇSSºÍlink state */
399 u32 udReserved31_24:8;
400}__attribute__ ((__packed__)) T_USB3Slave_DevEvt;
401
402/**
403* struct T_USB3Slave_Event_GEvt - Other Core Events
404* @udOne_bit: indicates this is a non-endpoint event (not used)
405* @udDevice_event: indicates it's (0x03) Carkit or (0x04) I2C event.
406* @udPhy_port_number: self-explanatory
407* @udReserved31_12: Reserved, not used.
408*/
409
410 typedef struct T_USB3Slave_Event_GEvt
411{
412 u32 udOne_bit:1;
413 u32 udDevice_event:7;
414 u32 udPhy_port_number:4;
415 u32 udReserved31_12:20;
416}__attribute__ ((__packed__)) T_USB3Slave_Event_GEvt;
417
418/** union T_USB3Slave_Event - representation of Event Buffer contents */
419
420typedef union
421{
422 u32 udRaw; /**< ָʾµ±Ç°eventµÄÖµ */
423 T_USB3Slave_EventType tType; /**< ָʾevent ÀàÐÍ(00h±íʾdevice specific event) */
424 T_USB3Slave_EpEvt tEpEvt; /**< ¶ËµãÀàÐÍevent */
425 T_USB3Slave_DevEvt tDevEvt; /**< É豸ÀàÐÍevent */
426 T_USB3Slave_Event_GEvt tGetEvt; /**< Other Core Events */
427}T_USB3Slave_Event;
428
429/** ¶¨ÒåEPµÄ±ê¼Çºê */
430#define EP_ENABLED (1 << 0)
431#define EP_STALL (1 << 1)
432#define EP_WEDGE (1 << 2)
433#define EP_BUSY (1 << 4)
434#define EP_PENDING_REQUEST (1 << 5)
435/** This last one is specific to EP0 */
436#define EP0_DIR_IN ((u32)1 << 31)
437/** EP񈬀 */
438#define EP_FLAG_STALLED (1 << 0)
439#define EP_FLAG_WEDGED (1 << 1)
440/** EP·½Ïò */
441#define EP_DIRECTION_TX true
442#define EP_DIRECTION_RX false
443
444/** ¶ËµãµÄ״̬±ä»¯*/
445typedef enum
446{
447 EP_IDLE = 0, /**< EP¿ÕÏÐ */
448 EP_HALTED, /**< EP halt */
449 EP0_CTRLIN_SETUP, /**< EP0¿ØÖƽ¨Á¢IN½×¶Î */
450 EP0_CTRLOUT_SETUP, /**< EP0¿ØÖƽ¨Á¢OUT½×¶Î */
451 EP0_CTRLNULL_SETUP, /**< EP0¿ØÖƽ¨Á¢Îª¿Õ */
452 EP0_CTRL_INDATA, /**< EP0¿ØÖÆINÊý¾Ý½×¶Î */
453 EP0_CTRL_OUTDATA, /**< EP0¿ØÖÆOUTÊý¾Ý½×¶Î */
454 EP0_CTRL_INSTATUS, /**< EP0¿ØÖÆIN״̬½×¶Î */
455 EP0_CTRL_OUTSTATUS, /**< EP0¿ØÖÆOUT״̬½×¶Î */
456 EP_RX, /**< EP½ÓÊÕ״ָ̬ʾ */
457 EP_TX /**< EP·¢ËÍ״ָ̬ʾ */
458}E_USB3Slave_EpState;
459
460/** ָʾEp0ÏÂÒ»¸öEVENTÀàÐÍ */
461typedef enum
462{
463 EP0_UNKNOWN = 0,
464 EP0_COMPLETE, /**< EP0״ָ̬ʾΪÍê³É*/
465 EP0_NRDY_SETUP, /**< EP0״̬NRDYָʾΪ½¨Á¢½×¶Î*/
466 EP0_NRDY_DATA, /**< EP0״̬NRDYָʾΪÊý¾Ý½×¶Î*/
467 EP0_NRDY_STATUS, /**< EP0״̬NRDYָʾΪ״̬½×¶Î*/
468} E_USB3Slave_Ep0Next;
469/** ָʾEP0¿ØÖÆ´«ÊäµÄÈý¸ö½×¶Î */
470typedef enum
471{
472 EP0_UNCONNECTED = 0,
473 EP0_SETUP_PHASE, /**< EP0¿ØÖÆ´«ÊäµÄ½¨Á¢½×¶Î */
474 EP0_DATA_PHASE, /**< EP0¿ØÖÆ´«ÊäµÄÊý¾Ý½×¶Î */
475 EP0_STATUS_PHASE, /**< EP0¿ØÖÆ´«ÊäµÄ״̬½×¶Î */
476}E_USB3Slave_Ep0State;
477/** ³¬¸ßËÙģʽϵÄÁ¬½Ó״̬ */
478
479
480/** ¿ØÖÆ´«ÊäÖÐö¾ÙËù´¦µÄ״̬½×¶Î */
481typedef enum
482{
483 DEFAULT_STATE = 0, /**< ȱʡ״̬ */
484 ADDRESS_STATE, /**< µØÖ·×´Ì¬ */
485 CONFIGURED_STATE, /**< ÅäÖÃ״̬ */
486 SETINTERFACE_STATE, /**< ÉèÖýӿÚ״̬*/
487 GETMAXLUN_STATE, /**<GET MAX lUN*/
488 BULKIN_CMPL, /**< BULK IN´«ÊäÍê³É״̬ */
489 BULKOUT_CMPL, /**< BULK OUT´«ÊäÍê³É״̬ */
490 IntrIN_CMPL, /**< Interrupt IN´«ÊäÍê³É״̬ */
491 IntrOUT_CMPL, /**< Interrupt OUT´«ÊäÍê³É״̬ */
492}E_USB3Slave_ReqState;
493
494/** ¶¨ÒåUSB3.0µÄËÙ¶ÈÀàÐÍ£¬²ÎÕÕ¿ØÖÆÆ÷ÊÖ²áP513, DCFG¼Ä´æÆ÷0:2±ÈÌØ */
495typedef enum
496{
497 USB3_HIGHSPEED = 0, /**< 3'b000 USB2.0 PHY clock is 30 MHz or 60 MHz */
498 USB3_FULLSPEED = 1, /**< 3'b001 USB2.0 PHY clock is 30 MHz or 60 MHz */
499 USB3_SUPERSPEED = 4, /**< 3'b100 USB3.0 PHY clock is 30 MHz or 60 MH */
500}E_USB3Slave_SpeedMode;
501/** ָʾÁ¬½ÓµÄÉ豸µÄËÙ¶ÈÀàÐÍ */
502typedef enum
503{
504 USB30_SPEED_UNKNOWN = 0, /**< enumerating */
505 USB30_SPEED_LOW, USB30_SPEED_FULL, /**< usb 1.1 */
506 USB30_SPEED_HIGH, /**< usb 2.0 */
507 USB30_SPEED_WIRELESS, /**< wireless (usb 2.5) */
508 USB30_SPEED_SUPER, /**< usb 3.0 */
509}E_USB3Slave_Speed;
510
511/** T_USB3Slave_HWPARAMS - copy of HWPARAMS registers */
512
513typedef struct
514{
515 u32 udHwparams0; /**< ¶ÔÓ¦ÓÚGHWPARAMS0¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
516 u32 udHwparams1; /**< ¶ÔÓ¦ÓÚGHWPARAMS1¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
517 u32 udHwparams2; /**< ¶ÔÓ¦ÓÚGHWPARAMS2¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
518 u32 udHwparams3; /**< ¶ÔÓ¦ÓÚGHWPARAMS3¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
519 u32 udHwparams4; /**< ¶ÔÓ¦ÓÚGHWPARAMS4¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
520 u32 udHwparams5; /**< ¶ÔÓ¦ÓÚGHWPARAMS5¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
521 u32 udHwparams6; /**< ¶ÔÓ¦ÓÚGHWPARAMS6¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
522 u32 udHwparams7; /**< ¶ÔÓ¦ÓÚGHWPARAMS7¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
523 u32 udHwparams8; /**< ¶ÔÓ¦ÓÚGHWPARAMS8¼Ä´æÆ÷¶ÁÈ¡µÄÖµ */
524}T_USB3Slave_HWPARAMS;
525
526
527/** ÓÃÓڶ˵ãÃüÁîµÄÈý¸ö²ÎÊý */
528 typedef struct T_USB3Slave_EpCmdPara
529{
530 u32 Parameter2; /**< ָʾÉ豸ÎïÀí¶ËµãÃüÁî²ÎÊý2 */
531 u32 Parameter1; /**< ָʾÉ豸ÎïÀí¶ËµãÃüÁî²ÎÊý1 */
532 u32 Parameter0; /**< ָʾÉ豸ÎïÀí¶ËµãÃüÁî²ÎÊý0 */
533}__attribute__ ((__packed__)) T_USB3Slave_EpCmdPara;
534
535/** DEPCFG parameter 1 */
536#define DEPCFG_INT_NUM(n) ((n) << 0)
537#define DEPCFG_XFER_COMPLETE_EN (1 << 8)
538#define DEPCFG_XFER_IN_PROGRESS_EN (1 << 9)
539#define DEPCFG_XFER_NOT_READY_EN (1 << 10)
540#define DEPCFG_FIFO_ERROR_EN (1 << 11)
541#define DEPCFG_STREAM_EVENT_EN (1 << 13)
542#define DEPCFG_BINTERVAL_M1(n) ((n) << 16)
543#define DEPCFG_STREAM_CAPABLE (1 << 24)
544#define DEPCFG_EP_NUMBER(n) ((n) << 25)
545#define DEPCFG_BULK_BASED (1 << 30)
546#define DEPCFG_FIFO_BASED (1 << 31)
547
548/** DEPCFG parameter 0 */
549#define DEPCFG_EP_TYPE(n) ((n) << 1)
550#define DEPCFG_MAX_PACKET_SIZE(n) ((n) << 3)
551#define DEPCFG_FIFO_NUMBER(n) ((n) << 17)
552#define DEPCFG_BURST_SIZE(n) ((n) << 22)
553#define DEPCFG_DATA_SEQ_NUM(n) ((n) << 26)
554#define DEPCFG_IGN_SEQ_NUM (1 << 31)
555
556/** DEPXFERCFG parameter 0 */
557#define DEPXFERCFG_NUM_XFER_RES(n) ((n) & 0xffff)
558
559/** ¶ËµãÐÅÏ¢½á¹¹Ìå */
560#pragma pack (4) /*Ö¸¶¨°´4×Ö½Ú¶ÔÆë*/
561typedef struct
562{
563
564 u32 udEpNum; /**< µ±Ç°epºÅ */
565 u8 *pucBuf; /**< »º³åÇøÖ¸Õë */
566 u32 udPos; /**< »º³åÇø¶ÁдָÕë */
567 u32 udLen; /**< »º³åÇø×ܳ¤¶È */
568 u32 udMaxPacket; /**< ×î´ó°üµÄ´óС */
569 u32 udMaxStream; /**< Ö§³ÖµÄ×î´óÁ÷Êý */
570 u32 udMaxBurst; /**< ¸Ã¶ËµãÖ§³ÖµÄ×î´óburstÊý */
571 T_USB3Slave_TRBToHW *ptTRB; /**< ×¼±¸ÓÃÓÚtrbµÄ»º³åÇø */
572 u32 udDMAChannel; /**< ¶ËµãʹÓõÄdmaͨµÀ, ¸ß16Ϊģʽ£¬µÍ16ΪͨµÀºÅ */
573 u8 ucType; /**< Ö§³ÖµÄ´«ÊäÀàÐÍ */
574 void *pPara; /**< »Øµ÷º¯ÊýµÄ²ÎÊý */
575 E_USB3Slave_EpState eEpState; /**< ¶Ëµã״̬ */
576 u32 udDirection; /**< ¶Ëµã´«Êä·½Ïò * @direction: true for TX, false for RX */
577 void *DriverData; /**< Êý¾ÝÓÃÓÚ´«Êä,ºóÐøµ÷ÊÔ¿ÉÄÜ»áÓõ½*/
578 u32 udInterval; /**< ¶ËµãµÄInterval */
579 u32 udBusySlot; /**< ´¦ÓÚæ״̬TRB¸öÊý */
580 u32 udFreeSlot; /**< ´¦ÓÚ¿ÕÏÐ״̬TRB¸öÊý */
581 u32 *pudAddrData; /**< ĿǰÖ÷ÒªÊÇBULK´«ÊäÓÃÓÚ½ÓÊպͷ¢ËÍÊý¾ÝµÄµØÖ· */
582 u8 ucAddress; /**< µØÖ· */
583 u32 udFlags; /**< ¶Ëµã±ê¼Ç */
584 u32 udCurrentTrb; /**< µ±Ç°TRB */
585 u8 ucResTransIdx; /**< ´«Êä×ÊÔ´Ë÷Òý */
586 u32 udStreamCapable; /**< ÊÇ·ñ¾ßÓÐÁ÷ÄÜÁ¦ */
587 F_USB_CB fnUsbCb; //¶Ëµã²Ù×÷Íê³ÉºóµÄ»Øµ÷º¯Êý
588
589}T_USB3Slave_Ep;
590#pragma pack () /*È¡Ïû¶ÔÆë*/
591/** struct dwc3 - representation of our controller */
592/** È«¾ÖdeviceÐÅÏ¢½á¹¹Ì壬ÓÃÓÚÈí¼þ */
593#pragma pack (4) /*Ö¸¶¨°´4×Ö½Ú¶ÔÆë*/
594typedef struct
595{
596
597 u32 udRegs_base; /**< ¼Ç¼¼Ä´æÆ÷»ùÖ· */
598 E_USB3Slave_SpeedMode eSpeedMode; /**< µ±Ç°É豸µÄËÙ¶È */
599 E_USB3Slave_Speed eDeviceSpeedType; /**< ËÙ¶ÈÀàÐÍ£¬¼æÈÝlinuxÇý¶¯Ëù×÷£¬¾ßÌåʹÓôýÒé */
600 T_USB3Slave_HWPARAMS tHwParams; /**< ±£´æËùÓÐÓ²¼þ²ÎÊý */
601 u32 udMode; /**< ±£´æ¿ØÖÆÆ÷µ±Ç°Ëù´¦Ä£Ê½ */
602 T_USB3Slave_EventBuf *ptEvtBuffs; /**< ±£´æevent */
603 u32 udNumEvtBufs; /**< ¼Ç¼evnet¸öÊý£¬´ÓÓ²¼þ²ÎÊýÖлñµÃ*/
604 T_USB3Slave_Ep tEps[ENDPOINTS_NUM]; /**< ±£´æ¶ËµãÐÅÏ¢ */
605 u32 udIsSelfPowered; /**< ×Ô¹©µçture*/
606 u32 udThreeStageSetup; /**< Èý½×¶ÎÉèÖÃ*/
607 u32 udEp0Bounced; /**< bounce buffer for ep0 */
608 u32 udEp0ExpectIn; /**< true when we expect a DATA IN transfer */
609 u32 udSetupPacketPending; /**< true when there's a Setup Packet in FIFO. Workaround */
610 u32 udDelayedStatus; /**< ÑÓ³Ù״̬*/
611 u32 udEventsequence; /**< eventÐòºÅ */
612 E_USB3Slave_Ep0Next eEp0NextEvent; /**< ָʾ¶ËµãµÄÏÂÒ»¸öEVENT */
613 E_USB3Slave_Ep0State eEp0State; /**< ep0״̬*/
614 E_USB3Slave_ReqState eDevState; /**< É豸״̬ */
615 u32 udUSBSate; /**< ö¾Ù״̬ */
616/*ÒÔÏÂÊý¾Ý³ÉÔ±³¤¶ÈÉèÖòÎÕÕlinux 3.3.6ÖжÔusb3¿ØÖÆÆ÷µÄ³õʼº¯Êý*/
617 T_USB3Slave_CtrlReq *tCtrlReq; /**< ¿ØÖÆÇëÇó */
618 T_USB3Slave_TRBToHW *ptEp0TRB; /**< ep0 TRBÉèÖÃ*/
619 u8 aucSetupBuf[2]; /**< ½¨Á¢buffer δÓÃĿǰ */
620 u8 ucSpeed; /**< ËÙ¶È */
621 u32 *pudTxData; /**< Ö¸Ïò·¢Ë͵ÄÊý¾Ý´óС */
622}T_USB3Slave_SlaveObj;
623#pragma pack () /*È¡Ïû¶ÔÆë*/
624
625/** ¶¨ÒåSlaveObj ¶ÔÏóµÄÈ«¾Ö±äÁ¿*/
626
627/** DWC3 Features to be used as Driver Data ĿǰûÓÐÓõ½ÔÝʱ·ÅÔÚÕâÀï*/
628/*#define HAS_PERIPHERAL BIT(0)
629#define HAS_XHCI BIT(1)
630#define HAS_OTG BIT(3)*/
631#define DATA_32BIT_MASK 0xFFFFFFFF
632#define ADDRESS_MAX 127
633
634/* *INDENT-OFF* */
635#ifdef __cplusplus
636}
637#endif
638/* *INDENT-ON* */
639
640#endif /* __USB3_SLAVE_DRV_H */
641
642
643/** @} */