2 * debug.h - DesignWare USB3 DRD Controller Debug Header
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 of
11 * the License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #ifndef __DWC3_DEBUG_H
20 #define __DWC3_DEBUG_H
25 * dwc3_gadget_ep_cmd_string - returns endpoint command string
28 static inline const char *
29 dwc3_gadget_ep_cmd_string(u8 cmd)
32 case DWC3_DEPCMD_DEPSTARTCFG:
33 return "Start New Configuration";
34 case DWC3_DEPCMD_ENDTRANSFER:
35 return "End Transfer";
36 case DWC3_DEPCMD_UPDATETRANSFER:
37 return "Update Transfer";
38 case DWC3_DEPCMD_STARTTRANSFER:
39 return "Start Transfer";
40 case DWC3_DEPCMD_CLEARSTALL:
42 case DWC3_DEPCMD_SETSTALL:
44 case DWC3_DEPCMD_GETEPSTATE:
45 return "Get Endpoint State";
46 case DWC3_DEPCMD_SETTRANSFRESOURCE:
47 return "Set Endpoint Transfer Resource";
48 case DWC3_DEPCMD_SETEPCONFIG:
49 return "Set Endpoint Configuration";
51 return "UNKNOWN command";
56 * dwc3_gadget_generic_cmd_string - returns generic command string
59 static inline const char *
60 dwc3_gadget_generic_cmd_string(u8 cmd)
63 case DWC3_DGCMD_SET_LMP:
65 case DWC3_DGCMD_SET_PERIODIC_PAR:
66 return "Set Periodic Parameters";
67 case DWC3_DGCMD_XMIT_FUNCTION:
68 return "Transmit Function Wake Device Notification";
69 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
70 return "Set Scratchpad Buffer Array Address Lo";
71 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
72 return "Set Scratchpad Buffer Array Address Hi";
73 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
74 return "Selected FIFO Flush";
75 case DWC3_DGCMD_ALL_FIFO_FLUSH:
76 return "All FIFO Flush";
77 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
78 return "Set Endpoint NRDY";
79 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
80 return "Run SoC Bus Loopback Test";
87 * dwc3_gadget_link_string - returns link name
88 * @link_state: link state code
90 static inline const char *
91 dwc3_gadget_link_string(enum dwc3_link_state link_state)
94 case DWC3_LINK_STATE_U0:
96 case DWC3_LINK_STATE_U1:
98 case DWC3_LINK_STATE_U2:
100 case DWC3_LINK_STATE_U3:
102 case DWC3_LINK_STATE_SS_DIS:
103 return "SS.Disabled";
104 case DWC3_LINK_STATE_RX_DET:
106 case DWC3_LINK_STATE_SS_INACT:
107 return "SS.Inactive";
108 case DWC3_LINK_STATE_POLL:
110 case DWC3_LINK_STATE_RECOV:
112 case DWC3_LINK_STATE_HRESET:
114 case DWC3_LINK_STATE_CMPLY:
116 case DWC3_LINK_STATE_LPBK:
118 case DWC3_LINK_STATE_RESET:
120 case DWC3_LINK_STATE_RESUME:
123 return "UNKNOWN link state\n";
128 * dwc3_trb_type_string - returns TRB type as a string
129 * @type: the type of the TRB
131 static inline const char *dwc3_trb_type_string(unsigned int type)
134 case DWC3_TRBCTL_NORMAL:
136 case DWC3_TRBCTL_CONTROL_SETUP:
138 case DWC3_TRBCTL_CONTROL_STATUS2:
140 case DWC3_TRBCTL_CONTROL_STATUS3:
142 case DWC3_TRBCTL_CONTROL_DATA:
144 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
146 case DWC3_TRBCTL_ISOCHRONOUS:
148 case DWC3_TRBCTL_LINK_TRB:
155 static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
158 case EP0_UNCONNECTED:
159 return "Unconnected";
160 case EP0_SETUP_PHASE:
161 return "Setup Phase";
164 case EP0_STATUS_PHASE:
165 return "Status Phase";
172 * dwc3_gadget_event_string - returns event name
173 * @event: the event code
175 static inline const char *
176 dwc3_gadget_event_string(const struct dwc3_event_devt *event)
178 static char str[256];
179 enum dwc3_link_state state = event->event_info & DWC3_LINK_STATE_MASK;
181 switch (event->type) {
182 case DWC3_DEVICE_EVENT_DISCONNECT:
183 sprintf(str, "Disconnect: [%s]",
184 dwc3_gadget_link_string(state));
186 case DWC3_DEVICE_EVENT_RESET:
187 sprintf(str, "Reset [%s]", dwc3_gadget_link_string(state));
189 case DWC3_DEVICE_EVENT_CONNECT_DONE:
190 sprintf(str, "Connection Done [%s]",
191 dwc3_gadget_link_string(state));
193 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
194 sprintf(str, "Link Change [%s]",
195 dwc3_gadget_link_string(state));
197 case DWC3_DEVICE_EVENT_WAKEUP:
198 sprintf(str, "WakeUp [%s]", dwc3_gadget_link_string(state));
200 case DWC3_DEVICE_EVENT_EOPF:
201 sprintf(str, "End-Of-Frame [%s]",
202 dwc3_gadget_link_string(state));
204 case DWC3_DEVICE_EVENT_SOF:
205 sprintf(str, "Start-Of-Frame [%s]",
206 dwc3_gadget_link_string(state));
208 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
209 sprintf(str, "Erratic Error [%s]",
210 dwc3_gadget_link_string(state));
212 case DWC3_DEVICE_EVENT_CMD_CMPL:
213 sprintf(str, "Command Complete [%s]",
214 dwc3_gadget_link_string(state));
216 case DWC3_DEVICE_EVENT_OVERFLOW:
217 sprintf(str, "Overflow [%s]", dwc3_gadget_link_string(state));
220 sprintf(str, "UNKNOWN");
227 * dwc3_ep_event_string - returns event name
228 * @event: then event code
230 static inline const char *
231 dwc3_ep_event_string(const struct dwc3_event_depevt *event, u32 ep0state)
233 u8 epnum = event->endpoint_number;
234 static char str[256];
239 ret = sprintf(str, "ep%d%s: ", epnum >> 1,
240 (epnum & 1) ? "in" : "out");
244 switch (event->endpoint_event) {
245 case DWC3_DEPEVT_XFERCOMPLETE:
246 strcat(str, "Transfer Complete");
250 sprintf(str + len, " [%s]", dwc3_ep0_state_string(ep0state));
252 case DWC3_DEPEVT_XFERINPROGRESS:
253 strcat(str, "Transfer In-Progress");
255 case DWC3_DEPEVT_XFERNOTREADY:
256 strcat(str, "Transfer Not Ready");
257 status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
258 strcat(str, status ? " (Active)" : " (Not Active)");
260 /* Control Endpoints */
262 int phase = DEPEVT_STATUS_CONTROL_PHASE(event->status);
265 case DEPEVT_STATUS_CONTROL_DATA:
266 strcat(str, " [Data Phase]");
268 case DEPEVT_STATUS_CONTROL_STATUS:
269 strcat(str, " [Status Phase]");
273 case DWC3_DEPEVT_RXTXFIFOEVT:
276 case DWC3_DEPEVT_STREAMEVT:
277 status = event->status;
280 case DEPEVT_STREAMEVT_FOUND:
281 sprintf(str + ret, " Stream %d Found",
284 case DEPEVT_STREAMEVT_NOTFOUND:
286 strcat(str, " Stream Not Found");
291 case DWC3_DEPEVT_EPCMDCMPLT:
292 strcat(str, "Endpoint Command Complete");
295 sprintf(str, "UNKNOWN");
302 * dwc3_gadget_event_type_string - return event name
303 * @event: the event code
305 static inline const char *dwc3_gadget_event_type_string(u8 event)
308 case DWC3_DEVICE_EVENT_DISCONNECT:
310 case DWC3_DEVICE_EVENT_RESET:
312 case DWC3_DEVICE_EVENT_CONNECT_DONE:
313 return "Connect Done";
314 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
315 return "Link Status Change";
316 case DWC3_DEVICE_EVENT_WAKEUP:
318 case DWC3_DEVICE_EVENT_HIBER_REQ:
319 return "Hibernation";
320 case DWC3_DEVICE_EVENT_EOPF:
321 return "End of Periodic Frame";
322 case DWC3_DEVICE_EVENT_SOF:
323 return "Start of Frame";
324 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
325 return "Erratic Error";
326 case DWC3_DEVICE_EVENT_CMD_CMPL:
327 return "Command Complete";
328 case DWC3_DEVICE_EVENT_OVERFLOW:
335 static inline const char *dwc3_decode_event(u32 event, u32 ep0state)
337 const union dwc3_event evt = (union dwc3_event) event;
339 if (evt.type.is_devspec)
340 return dwc3_gadget_event_string(&evt.devt);
342 return dwc3_ep_event_string(&evt.depevt, ep0state);
345 static inline const char *dwc3_ep_cmd_status_string(int status)
352 case DEPEVT_TRANSFER_NO_RESOURCE:
353 return "No Resource";
354 case DEPEVT_TRANSFER_BUS_EXPIRY:
361 static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
376 #ifdef CONFIG_DEBUG_FS
377 extern void dwc3_debugfs_init(struct dwc3 *);
378 extern void dwc3_debugfs_exit(struct dwc3 *);
380 static inline void dwc3_debugfs_init(struct dwc3 *d)
382 static inline void dwc3_debugfs_exit(struct dwc3 *d)
385 #endif /* __DWC3_DEBUG_H */