2 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
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 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/ptrace.h>
22 #include <linux/types.h>
23 #include <linux/spinlock.h>
24 #include <linux/debugfs.h>
25 #include <linux/seq_file.h>
26 #include <linux/delay.h>
27 #include <linux/uaccess.h>
29 #include <linux/usb/ch9.h>
36 #define dump_register(nm) \
38 .name = __stringify(nm), \
39 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \
42 static const struct debugfs_reg32 dwc3_regs
[] = {
43 dump_register(GSBUSCFG0
),
44 dump_register(GSBUSCFG1
),
45 dump_register(GTXTHRCFG
),
46 dump_register(GRXTHRCFG
),
48 dump_register(GEVTEN
),
50 dump_register(GSNPSID
),
54 dump_register(GBUSERRADDR0
),
55 dump_register(GBUSERRADDR1
),
56 dump_register(GPRTBIMAP0
),
57 dump_register(GPRTBIMAP1
),
58 dump_register(GHWPARAMS0
),
59 dump_register(GHWPARAMS1
),
60 dump_register(GHWPARAMS2
),
61 dump_register(GHWPARAMS3
),
62 dump_register(GHWPARAMS4
),
63 dump_register(GHWPARAMS5
),
64 dump_register(GHWPARAMS6
),
65 dump_register(GHWPARAMS7
),
66 dump_register(GDBGFIFOSPACE
),
67 dump_register(GDBGLTSSM
),
68 dump_register(GPRTBIMAP_HS0
),
69 dump_register(GPRTBIMAP_HS1
),
70 dump_register(GPRTBIMAP_FS0
),
71 dump_register(GPRTBIMAP_FS1
),
73 dump_register(GUSB2PHYCFG(0)),
74 dump_register(GUSB2PHYCFG(1)),
75 dump_register(GUSB2PHYCFG(2)),
76 dump_register(GUSB2PHYCFG(3)),
77 dump_register(GUSB2PHYCFG(4)),
78 dump_register(GUSB2PHYCFG(5)),
79 dump_register(GUSB2PHYCFG(6)),
80 dump_register(GUSB2PHYCFG(7)),
81 dump_register(GUSB2PHYCFG(8)),
82 dump_register(GUSB2PHYCFG(9)),
83 dump_register(GUSB2PHYCFG(10)),
84 dump_register(GUSB2PHYCFG(11)),
85 dump_register(GUSB2PHYCFG(12)),
86 dump_register(GUSB2PHYCFG(13)),
87 dump_register(GUSB2PHYCFG(14)),
88 dump_register(GUSB2PHYCFG(15)),
90 dump_register(GUSB2I2CCTL(0)),
91 dump_register(GUSB2I2CCTL(1)),
92 dump_register(GUSB2I2CCTL(2)),
93 dump_register(GUSB2I2CCTL(3)),
94 dump_register(GUSB2I2CCTL(4)),
95 dump_register(GUSB2I2CCTL(5)),
96 dump_register(GUSB2I2CCTL(6)),
97 dump_register(GUSB2I2CCTL(7)),
98 dump_register(GUSB2I2CCTL(8)),
99 dump_register(GUSB2I2CCTL(9)),
100 dump_register(GUSB2I2CCTL(10)),
101 dump_register(GUSB2I2CCTL(11)),
102 dump_register(GUSB2I2CCTL(12)),
103 dump_register(GUSB2I2CCTL(13)),
104 dump_register(GUSB2I2CCTL(14)),
105 dump_register(GUSB2I2CCTL(15)),
107 dump_register(GUSB2PHYACC(0)),
108 dump_register(GUSB2PHYACC(1)),
109 dump_register(GUSB2PHYACC(2)),
110 dump_register(GUSB2PHYACC(3)),
111 dump_register(GUSB2PHYACC(4)),
112 dump_register(GUSB2PHYACC(5)),
113 dump_register(GUSB2PHYACC(6)),
114 dump_register(GUSB2PHYACC(7)),
115 dump_register(GUSB2PHYACC(8)),
116 dump_register(GUSB2PHYACC(9)),
117 dump_register(GUSB2PHYACC(10)),
118 dump_register(GUSB2PHYACC(11)),
119 dump_register(GUSB2PHYACC(12)),
120 dump_register(GUSB2PHYACC(13)),
121 dump_register(GUSB2PHYACC(14)),
122 dump_register(GUSB2PHYACC(15)),
124 dump_register(GUSB3PIPECTL(0)),
125 dump_register(GUSB3PIPECTL(1)),
126 dump_register(GUSB3PIPECTL(2)),
127 dump_register(GUSB3PIPECTL(3)),
128 dump_register(GUSB3PIPECTL(4)),
129 dump_register(GUSB3PIPECTL(5)),
130 dump_register(GUSB3PIPECTL(6)),
131 dump_register(GUSB3PIPECTL(7)),
132 dump_register(GUSB3PIPECTL(8)),
133 dump_register(GUSB3PIPECTL(9)),
134 dump_register(GUSB3PIPECTL(10)),
135 dump_register(GUSB3PIPECTL(11)),
136 dump_register(GUSB3PIPECTL(12)),
137 dump_register(GUSB3PIPECTL(13)),
138 dump_register(GUSB3PIPECTL(14)),
139 dump_register(GUSB3PIPECTL(15)),
141 dump_register(GTXFIFOSIZ(0)),
142 dump_register(GTXFIFOSIZ(1)),
143 dump_register(GTXFIFOSIZ(2)),
144 dump_register(GTXFIFOSIZ(3)),
145 dump_register(GTXFIFOSIZ(4)),
146 dump_register(GTXFIFOSIZ(5)),
147 dump_register(GTXFIFOSIZ(6)),
148 dump_register(GTXFIFOSIZ(7)),
149 dump_register(GTXFIFOSIZ(8)),
150 dump_register(GTXFIFOSIZ(9)),
151 dump_register(GTXFIFOSIZ(10)),
152 dump_register(GTXFIFOSIZ(11)),
153 dump_register(GTXFIFOSIZ(12)),
154 dump_register(GTXFIFOSIZ(13)),
155 dump_register(GTXFIFOSIZ(14)),
156 dump_register(GTXFIFOSIZ(15)),
157 dump_register(GTXFIFOSIZ(16)),
158 dump_register(GTXFIFOSIZ(17)),
159 dump_register(GTXFIFOSIZ(18)),
160 dump_register(GTXFIFOSIZ(19)),
161 dump_register(GTXFIFOSIZ(20)),
162 dump_register(GTXFIFOSIZ(21)),
163 dump_register(GTXFIFOSIZ(22)),
164 dump_register(GTXFIFOSIZ(23)),
165 dump_register(GTXFIFOSIZ(24)),
166 dump_register(GTXFIFOSIZ(25)),
167 dump_register(GTXFIFOSIZ(26)),
168 dump_register(GTXFIFOSIZ(27)),
169 dump_register(GTXFIFOSIZ(28)),
170 dump_register(GTXFIFOSIZ(29)),
171 dump_register(GTXFIFOSIZ(30)),
172 dump_register(GTXFIFOSIZ(31)),
174 dump_register(GRXFIFOSIZ(0)),
175 dump_register(GRXFIFOSIZ(1)),
176 dump_register(GRXFIFOSIZ(2)),
177 dump_register(GRXFIFOSIZ(3)),
178 dump_register(GRXFIFOSIZ(4)),
179 dump_register(GRXFIFOSIZ(5)),
180 dump_register(GRXFIFOSIZ(6)),
181 dump_register(GRXFIFOSIZ(7)),
182 dump_register(GRXFIFOSIZ(8)),
183 dump_register(GRXFIFOSIZ(9)),
184 dump_register(GRXFIFOSIZ(10)),
185 dump_register(GRXFIFOSIZ(11)),
186 dump_register(GRXFIFOSIZ(12)),
187 dump_register(GRXFIFOSIZ(13)),
188 dump_register(GRXFIFOSIZ(14)),
189 dump_register(GRXFIFOSIZ(15)),
190 dump_register(GRXFIFOSIZ(16)),
191 dump_register(GRXFIFOSIZ(17)),
192 dump_register(GRXFIFOSIZ(18)),
193 dump_register(GRXFIFOSIZ(19)),
194 dump_register(GRXFIFOSIZ(20)),
195 dump_register(GRXFIFOSIZ(21)),
196 dump_register(GRXFIFOSIZ(22)),
197 dump_register(GRXFIFOSIZ(23)),
198 dump_register(GRXFIFOSIZ(24)),
199 dump_register(GRXFIFOSIZ(25)),
200 dump_register(GRXFIFOSIZ(26)),
201 dump_register(GRXFIFOSIZ(27)),
202 dump_register(GRXFIFOSIZ(28)),
203 dump_register(GRXFIFOSIZ(29)),
204 dump_register(GRXFIFOSIZ(30)),
205 dump_register(GRXFIFOSIZ(31)),
207 dump_register(GEVNTADRLO(0)),
208 dump_register(GEVNTADRHI(0)),
209 dump_register(GEVNTSIZ(0)),
210 dump_register(GEVNTCOUNT(0)),
212 dump_register(GHWPARAMS8
),
215 dump_register(DEVTEN
),
217 dump_register(DGCMDPAR
),
218 dump_register(DGCMD
),
219 dump_register(DALEPENA
),
221 dump_register(DEPCMDPAR2(0)),
222 dump_register(DEPCMDPAR2(1)),
223 dump_register(DEPCMDPAR2(2)),
224 dump_register(DEPCMDPAR2(3)),
225 dump_register(DEPCMDPAR2(4)),
226 dump_register(DEPCMDPAR2(5)),
227 dump_register(DEPCMDPAR2(6)),
228 dump_register(DEPCMDPAR2(7)),
229 dump_register(DEPCMDPAR2(8)),
230 dump_register(DEPCMDPAR2(9)),
231 dump_register(DEPCMDPAR2(10)),
232 dump_register(DEPCMDPAR2(11)),
233 dump_register(DEPCMDPAR2(12)),
234 dump_register(DEPCMDPAR2(13)),
235 dump_register(DEPCMDPAR2(14)),
236 dump_register(DEPCMDPAR2(15)),
237 dump_register(DEPCMDPAR2(16)),
238 dump_register(DEPCMDPAR2(17)),
239 dump_register(DEPCMDPAR2(18)),
240 dump_register(DEPCMDPAR2(19)),
241 dump_register(DEPCMDPAR2(20)),
242 dump_register(DEPCMDPAR2(21)),
243 dump_register(DEPCMDPAR2(22)),
244 dump_register(DEPCMDPAR2(23)),
245 dump_register(DEPCMDPAR2(24)),
246 dump_register(DEPCMDPAR2(25)),
247 dump_register(DEPCMDPAR2(26)),
248 dump_register(DEPCMDPAR2(27)),
249 dump_register(DEPCMDPAR2(28)),
250 dump_register(DEPCMDPAR2(29)),
251 dump_register(DEPCMDPAR2(30)),
252 dump_register(DEPCMDPAR2(31)),
254 dump_register(DEPCMDPAR1(0)),
255 dump_register(DEPCMDPAR1(1)),
256 dump_register(DEPCMDPAR1(2)),
257 dump_register(DEPCMDPAR1(3)),
258 dump_register(DEPCMDPAR1(4)),
259 dump_register(DEPCMDPAR1(5)),
260 dump_register(DEPCMDPAR1(6)),
261 dump_register(DEPCMDPAR1(7)),
262 dump_register(DEPCMDPAR1(8)),
263 dump_register(DEPCMDPAR1(9)),
264 dump_register(DEPCMDPAR1(10)),
265 dump_register(DEPCMDPAR1(11)),
266 dump_register(DEPCMDPAR1(12)),
267 dump_register(DEPCMDPAR1(13)),
268 dump_register(DEPCMDPAR1(14)),
269 dump_register(DEPCMDPAR1(15)),
270 dump_register(DEPCMDPAR1(16)),
271 dump_register(DEPCMDPAR1(17)),
272 dump_register(DEPCMDPAR1(18)),
273 dump_register(DEPCMDPAR1(19)),
274 dump_register(DEPCMDPAR1(20)),
275 dump_register(DEPCMDPAR1(21)),
276 dump_register(DEPCMDPAR1(22)),
277 dump_register(DEPCMDPAR1(23)),
278 dump_register(DEPCMDPAR1(24)),
279 dump_register(DEPCMDPAR1(25)),
280 dump_register(DEPCMDPAR1(26)),
281 dump_register(DEPCMDPAR1(27)),
282 dump_register(DEPCMDPAR1(28)),
283 dump_register(DEPCMDPAR1(29)),
284 dump_register(DEPCMDPAR1(30)),
285 dump_register(DEPCMDPAR1(31)),
287 dump_register(DEPCMDPAR0(0)),
288 dump_register(DEPCMDPAR0(1)),
289 dump_register(DEPCMDPAR0(2)),
290 dump_register(DEPCMDPAR0(3)),
291 dump_register(DEPCMDPAR0(4)),
292 dump_register(DEPCMDPAR0(5)),
293 dump_register(DEPCMDPAR0(6)),
294 dump_register(DEPCMDPAR0(7)),
295 dump_register(DEPCMDPAR0(8)),
296 dump_register(DEPCMDPAR0(9)),
297 dump_register(DEPCMDPAR0(10)),
298 dump_register(DEPCMDPAR0(11)),
299 dump_register(DEPCMDPAR0(12)),
300 dump_register(DEPCMDPAR0(13)),
301 dump_register(DEPCMDPAR0(14)),
302 dump_register(DEPCMDPAR0(15)),
303 dump_register(DEPCMDPAR0(16)),
304 dump_register(DEPCMDPAR0(17)),
305 dump_register(DEPCMDPAR0(18)),
306 dump_register(DEPCMDPAR0(19)),
307 dump_register(DEPCMDPAR0(20)),
308 dump_register(DEPCMDPAR0(21)),
309 dump_register(DEPCMDPAR0(22)),
310 dump_register(DEPCMDPAR0(23)),
311 dump_register(DEPCMDPAR0(24)),
312 dump_register(DEPCMDPAR0(25)),
313 dump_register(DEPCMDPAR0(26)),
314 dump_register(DEPCMDPAR0(27)),
315 dump_register(DEPCMDPAR0(28)),
316 dump_register(DEPCMDPAR0(29)),
317 dump_register(DEPCMDPAR0(30)),
318 dump_register(DEPCMDPAR0(31)),
320 dump_register(DEPCMD(0)),
321 dump_register(DEPCMD(1)),
322 dump_register(DEPCMD(2)),
323 dump_register(DEPCMD(3)),
324 dump_register(DEPCMD(4)),
325 dump_register(DEPCMD(5)),
326 dump_register(DEPCMD(6)),
327 dump_register(DEPCMD(7)),
328 dump_register(DEPCMD(8)),
329 dump_register(DEPCMD(9)),
330 dump_register(DEPCMD(10)),
331 dump_register(DEPCMD(11)),
332 dump_register(DEPCMD(12)),
333 dump_register(DEPCMD(13)),
334 dump_register(DEPCMD(14)),
335 dump_register(DEPCMD(15)),
336 dump_register(DEPCMD(16)),
337 dump_register(DEPCMD(17)),
338 dump_register(DEPCMD(18)),
339 dump_register(DEPCMD(19)),
340 dump_register(DEPCMD(20)),
341 dump_register(DEPCMD(21)),
342 dump_register(DEPCMD(22)),
343 dump_register(DEPCMD(23)),
344 dump_register(DEPCMD(24)),
345 dump_register(DEPCMD(25)),
346 dump_register(DEPCMD(26)),
347 dump_register(DEPCMD(27)),
348 dump_register(DEPCMD(28)),
349 dump_register(DEPCMD(29)),
350 dump_register(DEPCMD(30)),
351 dump_register(DEPCMD(31)),
356 dump_register(OEVTEN
),
360 static int dwc3_mode_show(struct seq_file
*s
, void *unused
)
362 struct dwc3
*dwc
= s
->private;
366 spin_lock_irqsave(&dwc
->lock
, flags
);
367 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
368 spin_unlock_irqrestore(&dwc
->lock
, flags
);
370 switch (DWC3_GCTL_PRTCAP(reg
)) {
371 case DWC3_GCTL_PRTCAP_HOST
:
372 seq_printf(s
, "host\n");
374 case DWC3_GCTL_PRTCAP_DEVICE
:
375 seq_printf(s
, "device\n");
377 case DWC3_GCTL_PRTCAP_OTG
:
378 seq_printf(s
, "OTG\n");
381 seq_printf(s
, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg
));
387 static int dwc3_mode_open(struct inode
*inode
, struct file
*file
)
389 return single_open(file
, dwc3_mode_show
, inode
->i_private
);
392 static ssize_t
dwc3_mode_write(struct file
*file
,
393 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
395 struct seq_file
*s
= file
->private_data
;
396 struct dwc3
*dwc
= s
->private;
401 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
404 if (!strncmp(buf
, "host", 4))
405 mode
|= DWC3_GCTL_PRTCAP_HOST
;
407 if (!strncmp(buf
, "device", 6))
408 mode
|= DWC3_GCTL_PRTCAP_DEVICE
;
410 if (!strncmp(buf
, "otg", 3))
411 mode
|= DWC3_GCTL_PRTCAP_OTG
;
414 spin_lock_irqsave(&dwc
->lock
, flags
);
415 dwc3_set_mode(dwc
, mode
);
416 spin_unlock_irqrestore(&dwc
->lock
, flags
);
421 static const struct file_operations dwc3_mode_fops
= {
422 .open
= dwc3_mode_open
,
423 .write
= dwc3_mode_write
,
426 .release
= single_release
,
429 static int dwc3_testmode_show(struct seq_file
*s
, void *unused
)
431 struct dwc3
*dwc
= s
->private;
435 spin_lock_irqsave(&dwc
->lock
, flags
);
436 reg
= dwc3_readl(dwc
->regs
, DWC3_DCTL
);
437 reg
&= DWC3_DCTL_TSTCTRL_MASK
;
439 spin_unlock_irqrestore(&dwc
->lock
, flags
);
443 seq_printf(s
, "no test\n");
446 seq_printf(s
, "test_j\n");
449 seq_printf(s
, "test_k\n");
452 seq_printf(s
, "test_se0_nak\n");
455 seq_printf(s
, "test_packet\n");
458 seq_printf(s
, "test_force_enable\n");
461 seq_printf(s
, "UNKNOWN %d\n", reg
);
467 static int dwc3_testmode_open(struct inode
*inode
, struct file
*file
)
469 return single_open(file
, dwc3_testmode_show
, inode
->i_private
);
472 static ssize_t
dwc3_testmode_write(struct file
*file
,
473 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
475 struct seq_file
*s
= file
->private_data
;
476 struct dwc3
*dwc
= s
->private;
481 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
484 if (!strncmp(buf
, "test_j", 6))
486 else if (!strncmp(buf
, "test_k", 6))
488 else if (!strncmp(buf
, "test_se0_nak", 12))
489 testmode
= TEST_SE0_NAK
;
490 else if (!strncmp(buf
, "test_packet", 11))
491 testmode
= TEST_PACKET
;
492 else if (!strncmp(buf
, "test_force_enable", 17))
493 testmode
= TEST_FORCE_EN
;
497 spin_lock_irqsave(&dwc
->lock
, flags
);
498 dwc3_gadget_set_test_mode(dwc
, testmode
);
499 spin_unlock_irqrestore(&dwc
->lock
, flags
);
504 static const struct file_operations dwc3_testmode_fops
= {
505 .open
= dwc3_testmode_open
,
506 .write
= dwc3_testmode_write
,
509 .release
= single_release
,
512 static int dwc3_link_state_show(struct seq_file
*s
, void *unused
)
514 struct dwc3
*dwc
= s
->private;
516 enum dwc3_link_state state
;
519 spin_lock_irqsave(&dwc
->lock
, flags
);
520 reg
= dwc3_readl(dwc
->regs
, DWC3_DSTS
);
521 state
= DWC3_DSTS_USBLNKST(reg
);
522 spin_unlock_irqrestore(&dwc
->lock
, flags
);
525 case DWC3_LINK_STATE_U0
:
526 seq_printf(s
, "U0\n");
528 case DWC3_LINK_STATE_U1
:
529 seq_printf(s
, "U1\n");
531 case DWC3_LINK_STATE_U2
:
532 seq_printf(s
, "U2\n");
534 case DWC3_LINK_STATE_U3
:
535 seq_printf(s
, "U3\n");
537 case DWC3_LINK_STATE_SS_DIS
:
538 seq_printf(s
, "SS.Disabled\n");
540 case DWC3_LINK_STATE_RX_DET
:
541 seq_printf(s
, "Rx.Detect\n");
543 case DWC3_LINK_STATE_SS_INACT
:
544 seq_printf(s
, "SS.Inactive\n");
546 case DWC3_LINK_STATE_POLL
:
547 seq_printf(s
, "Poll\n");
549 case DWC3_LINK_STATE_RECOV
:
550 seq_printf(s
, "Recovery\n");
552 case DWC3_LINK_STATE_HRESET
:
553 seq_printf(s
, "HRESET\n");
555 case DWC3_LINK_STATE_CMPLY
:
556 seq_printf(s
, "Compliance\n");
558 case DWC3_LINK_STATE_LPBK
:
559 seq_printf(s
, "Loopback\n");
561 case DWC3_LINK_STATE_RESET
:
562 seq_printf(s
, "Reset\n");
564 case DWC3_LINK_STATE_RESUME
:
565 seq_printf(s
, "Resume\n");
568 seq_printf(s
, "UNKNOWN %d\n", state
);
574 static int dwc3_link_state_open(struct inode
*inode
, struct file
*file
)
576 return single_open(file
, dwc3_link_state_show
, inode
->i_private
);
579 static ssize_t
dwc3_link_state_write(struct file
*file
,
580 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
582 struct seq_file
*s
= file
->private_data
;
583 struct dwc3
*dwc
= s
->private;
585 enum dwc3_link_state state
= 0;
588 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
591 if (!strncmp(buf
, "SS.Disabled", 11))
592 state
= DWC3_LINK_STATE_SS_DIS
;
593 else if (!strncmp(buf
, "Rx.Detect", 9))
594 state
= DWC3_LINK_STATE_RX_DET
;
595 else if (!strncmp(buf
, "SS.Inactive", 11))
596 state
= DWC3_LINK_STATE_SS_INACT
;
597 else if (!strncmp(buf
, "Recovery", 8))
598 state
= DWC3_LINK_STATE_RECOV
;
599 else if (!strncmp(buf
, "Compliance", 10))
600 state
= DWC3_LINK_STATE_CMPLY
;
601 else if (!strncmp(buf
, "Loopback", 8))
602 state
= DWC3_LINK_STATE_LPBK
;
606 spin_lock_irqsave(&dwc
->lock
, flags
);
607 dwc3_gadget_set_link_state(dwc
, state
);
608 spin_unlock_irqrestore(&dwc
->lock
, flags
);
613 static const struct file_operations dwc3_link_state_fops
= {
614 .open
= dwc3_link_state_open
,
615 .write
= dwc3_link_state_write
,
618 .release
= single_release
,
621 struct dwc3_ep_file_map
{
623 int (*show
)(struct seq_file
*s
, void *unused
);
626 static int dwc3_tx_fifo_queue_show(struct seq_file
*s
, void *unused
)
628 struct dwc3_ep
*dep
= s
->private;
629 struct dwc3
*dwc
= dep
->dwc
;
633 spin_lock_irqsave(&dwc
->lock
, flags
);
634 val
= dwc3_core_fifo_space(dep
, DWC3_TXFIFOQ
);
635 seq_printf(s
, "%u\n", val
);
636 spin_unlock_irqrestore(&dwc
->lock
, flags
);
641 static int dwc3_rx_fifo_queue_show(struct seq_file
*s
, void *unused
)
643 struct dwc3_ep
*dep
= s
->private;
644 struct dwc3
*dwc
= dep
->dwc
;
648 spin_lock_irqsave(&dwc
->lock
, flags
);
649 val
= dwc3_core_fifo_space(dep
, DWC3_RXFIFOQ
);
650 seq_printf(s
, "%u\n", val
);
651 spin_unlock_irqrestore(&dwc
->lock
, flags
);
656 static int dwc3_tx_request_queue_show(struct seq_file
*s
, void *unused
)
658 struct dwc3_ep
*dep
= s
->private;
659 struct dwc3
*dwc
= dep
->dwc
;
663 spin_lock_irqsave(&dwc
->lock
, flags
);
664 val
= dwc3_core_fifo_space(dep
, DWC3_TXREQQ
);
665 seq_printf(s
, "%u\n", val
);
666 spin_unlock_irqrestore(&dwc
->lock
, flags
);
671 static int dwc3_rx_request_queue_show(struct seq_file
*s
, void *unused
)
673 struct dwc3_ep
*dep
= s
->private;
674 struct dwc3
*dwc
= dep
->dwc
;
678 spin_lock_irqsave(&dwc
->lock
, flags
);
679 val
= dwc3_core_fifo_space(dep
, DWC3_RXREQQ
);
680 seq_printf(s
, "%u\n", val
);
681 spin_unlock_irqrestore(&dwc
->lock
, flags
);
686 static int dwc3_rx_info_queue_show(struct seq_file
*s
, void *unused
)
688 struct dwc3_ep
*dep
= s
->private;
689 struct dwc3
*dwc
= dep
->dwc
;
693 spin_lock_irqsave(&dwc
->lock
, flags
);
694 val
= dwc3_core_fifo_space(dep
, DWC3_RXINFOQ
);
695 seq_printf(s
, "%u\n", val
);
696 spin_unlock_irqrestore(&dwc
->lock
, flags
);
701 static int dwc3_descriptor_fetch_queue_show(struct seq_file
*s
, void *unused
)
703 struct dwc3_ep
*dep
= s
->private;
704 struct dwc3
*dwc
= dep
->dwc
;
708 spin_lock_irqsave(&dwc
->lock
, flags
);
709 val
= dwc3_core_fifo_space(dep
, DWC3_DESCFETCHQ
);
710 seq_printf(s
, "%u\n", val
);
711 spin_unlock_irqrestore(&dwc
->lock
, flags
);
716 static int dwc3_event_queue_show(struct seq_file
*s
, void *unused
)
718 struct dwc3_ep
*dep
= s
->private;
719 struct dwc3
*dwc
= dep
->dwc
;
723 spin_lock_irqsave(&dwc
->lock
, flags
);
724 val
= dwc3_core_fifo_space(dep
, DWC3_EVENTQ
);
725 seq_printf(s
, "%u\n", val
);
726 spin_unlock_irqrestore(&dwc
->lock
, flags
);
731 static int dwc3_ep_transfer_type_show(struct seq_file
*s
, void *unused
)
733 struct dwc3_ep
*dep
= s
->private;
734 struct dwc3
*dwc
= dep
->dwc
;
737 spin_lock_irqsave(&dwc
->lock
, flags
);
738 if (!(dep
->flags
& DWC3_EP_ENABLED
) ||
739 !dep
->endpoint
.desc
) {
740 seq_printf(s
, "--\n");
744 switch (usb_endpoint_type(dep
->endpoint
.desc
)) {
745 case USB_ENDPOINT_XFER_CONTROL
:
746 seq_printf(s
, "control\n");
748 case USB_ENDPOINT_XFER_ISOC
:
749 seq_printf(s
, "isochronous\n");
751 case USB_ENDPOINT_XFER_BULK
:
752 seq_printf(s
, "bulk\n");
754 case USB_ENDPOINT_XFER_INT
:
755 seq_printf(s
, "interrupt\n");
758 seq_printf(s
, "--\n");
762 spin_unlock_irqrestore(&dwc
->lock
, flags
);
767 static inline const char *dwc3_trb_type_string(struct dwc3_trb
*trb
)
769 switch (DWC3_TRBCTL_TYPE(trb
->ctrl
)) {
770 case DWC3_TRBCTL_NORMAL
:
772 case DWC3_TRBCTL_CONTROL_SETUP
:
773 return "control-setup";
774 case DWC3_TRBCTL_CONTROL_STATUS2
:
775 return "control-status2";
776 case DWC3_TRBCTL_CONTROL_STATUS3
:
777 return "control-status3";
778 case DWC3_TRBCTL_CONTROL_DATA
:
779 return "control-data";
780 case DWC3_TRBCTL_ISOCHRONOUS_FIRST
:
782 case DWC3_TRBCTL_ISOCHRONOUS
:
784 case DWC3_TRBCTL_LINK_TRB
:
791 static int dwc3_ep_trb_ring_show(struct seq_file
*s
, void *unused
)
793 struct dwc3_ep
*dep
= s
->private;
794 struct dwc3
*dwc
= dep
->dwc
;
798 spin_lock_irqsave(&dwc
->lock
, flags
);
799 if (dep
->number
<= 1) {
800 seq_printf(s
, "--\n");
804 seq_printf(s
, "enqueue pointer %d\n", dep
->trb_enqueue
);
805 seq_printf(s
, "dequeue pointer %d\n", dep
->trb_dequeue
);
806 seq_printf(s
, "\n--------------------------------------------------\n\n");
807 seq_printf(s
, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n");
809 for (i
= 0; i
< DWC3_TRB_NUM
; i
++) {
810 struct dwc3_trb
*trb
= &dep
->trb_pool
[i
];
812 seq_printf(s
, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d\n",
813 trb
->bph
, trb
->bpl
, trb
->size
,
814 dwc3_trb_type_string(trb
),
815 !!(trb
->ctrl
& DWC3_TRB_CTRL_IOC
),
816 !!(trb
->ctrl
& DWC3_TRB_CTRL_ISP_IMI
),
817 !!(trb
->ctrl
& DWC3_TRB_CTRL_CSP
),
818 !!(trb
->ctrl
& DWC3_TRB_CTRL_CHN
),
819 !!(trb
->ctrl
& DWC3_TRB_CTRL_LST
),
820 !!(trb
->ctrl
& DWC3_TRB_CTRL_HWO
));
824 spin_unlock_irqrestore(&dwc
->lock
, flags
);
829 static struct dwc3_ep_file_map map
[] = {
830 { "tx_fifo_queue", dwc3_tx_fifo_queue_show
, },
831 { "rx_fifo_queue", dwc3_rx_fifo_queue_show
, },
832 { "tx_request_queue", dwc3_tx_request_queue_show
, },
833 { "rx_request_queue", dwc3_rx_request_queue_show
, },
834 { "rx_info_queue", dwc3_rx_info_queue_show
, },
835 { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show
, },
836 { "event_queue", dwc3_event_queue_show
, },
837 { "transfer_type", dwc3_ep_transfer_type_show
, },
838 { "trb_ring", dwc3_ep_trb_ring_show
, },
841 static int dwc3_endpoint_open(struct inode
*inode
, struct file
*file
)
843 const char *file_name
= file_dentry(file
)->d_iname
;
844 struct dwc3_ep_file_map
*f_map
;
847 for (i
= 0; i
< ARRAY_SIZE(map
); i
++) {
850 if (strcmp(f_map
->name
, file_name
) == 0)
854 return single_open(file
, f_map
->show
, inode
->i_private
);
857 static const struct file_operations dwc3_endpoint_fops
= {
858 .open
= dwc3_endpoint_open
,
861 .release
= single_release
,
864 static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep
*dep
,
865 struct dentry
*parent
, int type
)
868 struct dwc3_ep_file_map
*ep_file
= &map
[type
];
870 file
= debugfs_create_file(ep_file
->name
, S_IRUGO
, parent
, dep
,
871 &dwc3_endpoint_fops
);
874 static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep
*dep
,
875 struct dentry
*parent
)
879 for (i
= 0; i
< ARRAY_SIZE(map
); i
++)
880 dwc3_debugfs_create_endpoint_file(dep
, parent
, i
);
883 static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep
*dep
,
884 struct dentry
*parent
)
888 dir
= debugfs_create_dir(dep
->name
, parent
);
889 if (IS_ERR_OR_NULL(dir
))
892 dwc3_debugfs_create_endpoint_files(dep
, dir
);
895 static void dwc3_debugfs_create_endpoint_dirs(struct dwc3
*dwc
,
896 struct dentry
*parent
)
900 for (i
= 0; i
< dwc
->num_in_eps
; i
++) {
901 u8 epnum
= (i
<< 1) | 1;
902 struct dwc3_ep
*dep
= dwc
->eps
[epnum
];
907 dwc3_debugfs_create_endpoint_dir(dep
, parent
);
910 for (i
= 0; i
< dwc
->num_out_eps
; i
++) {
912 struct dwc3_ep
*dep
= dwc
->eps
[epnum
];
917 dwc3_debugfs_create_endpoint_dir(dep
, parent
);
921 void dwc3_debugfs_init(struct dwc3
*dwc
)
926 root
= debugfs_create_dir(dev_name(dwc
->dev
), NULL
);
927 if (IS_ERR_OR_NULL(root
)) {
929 dev_err(dwc
->dev
, "Can't create debugfs root\n");
934 dwc
->regset
= kzalloc(sizeof(*dwc
->regset
), GFP_KERNEL
);
936 debugfs_remove_recursive(root
);
940 dwc
->regset
->regs
= dwc3_regs
;
941 dwc
->regset
->nregs
= ARRAY_SIZE(dwc3_regs
);
942 dwc
->regset
->base
= dwc
->regs
;
944 file
= debugfs_create_regset32("regdump", S_IRUGO
, root
, dwc
->regset
);
946 dev_dbg(dwc
->dev
, "Can't create debugfs regdump\n");
948 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE
)) {
949 file
= debugfs_create_file("mode", S_IRUGO
| S_IWUSR
, root
,
950 dwc
, &dwc3_mode_fops
);
952 dev_dbg(dwc
->dev
, "Can't create debugfs mode\n");
955 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE
) ||
956 IS_ENABLED(CONFIG_USB_DWC3_GADGET
)) {
957 file
= debugfs_create_file("testmode", S_IRUGO
| S_IWUSR
, root
,
958 dwc
, &dwc3_testmode_fops
);
960 dev_dbg(dwc
->dev
, "Can't create debugfs testmode\n");
962 file
= debugfs_create_file("link_state", S_IRUGO
| S_IWUSR
,
963 root
, dwc
, &dwc3_link_state_fops
);
965 dev_dbg(dwc
->dev
, "Can't create debugfs link_state\n");
967 dwc3_debugfs_create_endpoint_dirs(dwc
, root
);
971 void dwc3_debugfs_exit(struct dwc3
*dwc
)
973 debugfs_remove_recursive(dwc
->root
);