2 * gadget.h - DesignWare USB3 DRD Gadget Header
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The names of the above-listed copyright holders may not be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2, as published by the Free
25 * Software Foundation.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #ifndef __DRIVERS_USB_DWC3_GADGET_H
41 #define __DRIVERS_USB_DWC3_GADGET_H
43 #include <linux/list.h>
44 #include <linux/usb/gadget.h>
48 #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint))
49 #define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget))
52 * struct dwc3_gadget_ep_depcfg_param1 - DEPCMDPAR0 for DEPCFG command
53 * @interrupt_number: self-explanatory
54 * @reserved7_5: set to zero
55 * @xfer_complete_enable: event generated when transfer completed
56 * @xfer_in_progress_enable: event generated when transfer in progress
57 * @xfer_not_ready_enable: event generated when transfer not read
58 * @fifo_error_enable: generates events when FIFO Underrun (IN eps)
59 * or FIFO Overrun (OUT) eps
60 * @reserved_12: set to zero
61 * @stream_event_enable: event generated on stream
62 * @reserved14_15: set to zero
63 * @binterval_m1: bInterval minus 1
64 * @stream_capable: this EP is capable of handling streams
65 * @ep_number: self-explanatory
66 * @bulk_based: Set to ‘1’ if this isochronous endpoint represents a bulk
67 * data stream that ignores the relationship of bus time to the
68 * intervals programmed in TRBs.
69 * @fifo_based: Set to ‘1’ if this isochronous endpoint represents a
70 * FIFO-based data stream where TRBs have fixed values and are never
71 * written back by the core.
73 struct dwc3_gadget_ep_depcfg_param1
{
74 u32 interrupt_number
:5;
75 u32 reserved7_5
:3; /* set to zero */
76 u32 xfer_complete_enable
:1;
77 u32 xfer_in_progress_enable
:1;
78 u32 xfer_not_ready_enable
:1;
79 u32 fifo_error_enable
:1; /* IN-underrun, OUT-overrun */
80 u32 reserved12
:1; /* set to zero */
81 u32 stream_event_enable
:1;
83 u32 binterval_m1
:8; /* bInterval minus 1 */
91 * struct dwc3_gadget_ep_depcfg_param0 - Parameter 0 for DEPCFG
92 * @reserved0: set to zero
93 * @ep_type: Endpoint Type (control, bulk, iso, interrupt)
94 * @max_packet_size: max packet size in bytes
95 * @reserved16_14: set to zero
96 * @fifo_number: self-explanatory
97 * @burst_size: burst size minus 1
98 * @data_sequence_number: Must be 0 when an endpoint is initially configured
99 * May be non-zero when an endpoint is configured after a power transition
100 * that requires a save/restore.
101 * @ignore_sequence_number: Set to ‘1’ to avoid resetting the sequence
102 * number. This setting is used by software to modify the DEPEVTEN
103 * event enable bits without modifying other endpoint settings.
105 struct dwc3_gadget_ep_depcfg_param0
{
108 u32 max_packet_size
:11;
112 u32 data_sequence_number
:5;
113 u32 ignore_sequence_number
:1;
117 * struct dwc3_gadget_ep_depxfercfg_param0 - Parameter 0 of DEPXFERCFG
118 * @number_xfer_resources: Defines the number of Transfer Resources allocated
119 * to this endpoint. This field must be set to 1.
120 * @reserved16_31: set to zero;
122 struct dwc3_gadget_ep_depxfercfg_param0
{
123 u32 number_xfer_resources
:16;
124 u32 reserved16_31
:16;
128 * struct dwc3_gadget_ep_depstrtxfer_param1 - Parameter 1 of DEPSTRTXFER
129 * @transfer_desc_addr_low: Indicates the lower 32 bits of the external
130 * memory's start address for the transfer descriptor. Because TRBs
131 * must be aligned to a 16-byte boundary, the lower 4 bits of this
134 struct dwc3_gadget_ep_depstrtxfer_param1
{
135 u32 transfer_desc_addr_low
;
139 * struct dwc3_gadget_ep_depstrtxfer_param1 - Parameter 1 of DEPSTRTXFER
140 * @transfer_desc_addr_high: Indicates the higher 32 bits of the external
141 * memory’s start address for the transfer descriptor.
143 struct dwc3_gadget_ep_depstrtxfer_param0
{
144 u32 transfer_desc_addr_high
;
147 struct dwc3_gadget_ep_cmd_params
{
154 struct dwc3_gadget_ep_depcfg_param1 depcfg
;
155 struct dwc3_gadget_ep_depstrtxfer_param1 depstrtxfer
;
160 struct dwc3_gadget_ep_depcfg_param0 depcfg
;
161 struct dwc3_gadget_ep_depxfercfg_param0 depxfercfg
;
162 struct dwc3_gadget_ep_depstrtxfer_param0 depstrtxfer
;
166 /* -------------------------------------------------------------------------- */
168 struct dwc3_request
{
169 struct usb_request request
;
170 struct list_head list
;
174 struct dwc3_trb_hw
*trb
;
177 unsigned direction
:1;
181 #define to_dwc3_request(r) (container_of(r, struct dwc3_request, request))
183 static inline struct dwc3_request
*next_request(struct list_head
*list
)
185 if (list_empty(list
))
188 return list_first_entry(list
, struct dwc3_request
, list
);
191 static inline void dwc3_gadget_move_request_queued(struct dwc3_request
*req
)
193 struct dwc3_ep
*dep
= req
->dep
;
196 list_move_tail(&req
->list
, &dep
->req_queued
);
199 #if defined(CONFIG_USB_GADGET_DWC3) || defined(CONFIG_USB_GADGET_DWC3_MODULE)
200 int dwc3_gadget_init(struct dwc3
*dwc
);
201 void dwc3_gadget_exit(struct dwc3
*dwc
);
203 static inline int dwc3_gadget_init(struct dwc3
*dwc
) { return 0; }
204 static inline void dwc3_gadget_exit(struct dwc3
*dwc
) { }
205 static inline int dwc3_send_gadget_ep_cmd(struct dwc3
*dwc
, unsigned ep
,
206 unsigned cmd
, struct dwc3_gadget_ep_cmd_params
*params
)
212 void dwc3_gadget_giveback(struct dwc3_ep
*dep
, struct dwc3_request
*req
,
215 void dwc3_ep0_interrupt(struct dwc3
*dwc
, const struct dwc3_event_depevt
*event
);
216 void dwc3_ep0_out_start(struct dwc3
*dwc
);
217 int dwc3_gadget_ep0_queue(struct usb_ep
*ep
, struct usb_request
*request
,
219 int __dwc3_gadget_ep_set_halt(struct dwc3_ep
*dep
, int value
);
220 int dwc3_send_gadget_ep_cmd(struct dwc3
*dwc
, unsigned ep
,
221 unsigned cmd
, struct dwc3_gadget_ep_cmd_params
*params
);
222 void dwc3_map_buffer_to_dma(struct dwc3_request
*req
);
223 void dwc3_unmap_buffer_from_dma(struct dwc3_request
*req
);
226 * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
227 * @dwc: DesignWare USB3 Pointer
228 * @number: DWC endpoint number
230 * Caller should take care of locking
232 static inline u32
dwc3_gadget_ep_get_transfer_index(struct dwc3
*dwc
, u8 number
)
236 res_id
= dwc3_readl(dwc
->regs
, DWC3_DEPCMD(number
));
238 return DWC3_DEPCMD_GET_RSC_IDX(res_id
);
242 * dwc3_gadget_event_string - returns event name
243 * @event: the event code
245 static inline const char *dwc3_gadget_event_string(u8 event
)
248 case DWC3_DEVICE_EVENT_DISCONNECT
:
250 case DWC3_DEVICE_EVENT_RESET
:
252 case DWC3_DEVICE_EVENT_CONNECT_DONE
:
253 return "Connection Done";
254 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE
:
255 return "Link Status Change";
256 case DWC3_DEVICE_EVENT_WAKEUP
:
258 case DWC3_DEVICE_EVENT_EOPF
:
259 return "End-Of-Frame";
260 case DWC3_DEVICE_EVENT_SOF
:
261 return "Start-Of-Frame";
262 case DWC3_DEVICE_EVENT_ERRATIC_ERROR
:
263 return "Erratic Error";
264 case DWC3_DEVICE_EVENT_CMD_CMPL
:
265 return "Command Complete";
266 case DWC3_DEVICE_EVENT_OVERFLOW
:
274 * dwc3_ep_event_string - returns event name
275 * @event: then event code
277 static inline const char *dwc3_ep_event_string(u8 event
)
280 case DWC3_DEPEVT_XFERCOMPLETE
:
281 return "Transfer Complete";
282 case DWC3_DEPEVT_XFERINPROGRESS
:
283 return "Transfer In-Progress";
284 case DWC3_DEPEVT_XFERNOTREADY
:
285 return "Transfer Not Ready";
286 case DWC3_DEPEVT_RXTXFIFOEVT
:
288 case DWC3_DEPEVT_STREAMEVT
:
290 case DWC3_DEPEVT_EPCMDCMPLT
:
291 return "Endpoint Command Complete";
297 #endif /* __DRIVERS_USB_DWC3_GADGET_H */