Loading...
1/**
2 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
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.
12 *
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.
17 */
18
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>
28
29#include <linux/usb/ch9.h>
30
31#include "core.h"
32#include "gadget.h"
33#include "io.h"
34#include "debug.h"
35
36#define dump_register(nm) \
37{ \
38 .name = __stringify(nm), \
39 .offset = DWC3_ ##nm, \
40}
41
42#define dump_ep_register_set(n) \
43 { \
44 .name = "DEPCMDPAR2("__stringify(n)")", \
45 .offset = DWC3_DEP_BASE(n) + \
46 DWC3_DEPCMDPAR2, \
47 }, \
48 { \
49 .name = "DEPCMDPAR1("__stringify(n)")", \
50 .offset = DWC3_DEP_BASE(n) + \
51 DWC3_DEPCMDPAR1, \
52 }, \
53 { \
54 .name = "DEPCMDPAR0("__stringify(n)")", \
55 .offset = DWC3_DEP_BASE(n) + \
56 DWC3_DEPCMDPAR0, \
57 }, \
58 { \
59 .name = "DEPCMD("__stringify(n)")", \
60 .offset = DWC3_DEP_BASE(n) + \
61 DWC3_DEPCMD, \
62 }
63
64
65static const struct debugfs_reg32 dwc3_regs[] = {
66 dump_register(GSBUSCFG0),
67 dump_register(GSBUSCFG1),
68 dump_register(GTXTHRCFG),
69 dump_register(GRXTHRCFG),
70 dump_register(GCTL),
71 dump_register(GEVTEN),
72 dump_register(GSTS),
73 dump_register(GUCTL1),
74 dump_register(GSNPSID),
75 dump_register(GGPIO),
76 dump_register(GUID),
77 dump_register(GUCTL),
78 dump_register(GBUSERRADDR0),
79 dump_register(GBUSERRADDR1),
80 dump_register(GPRTBIMAP0),
81 dump_register(GPRTBIMAP1),
82 dump_register(GHWPARAMS0),
83 dump_register(GHWPARAMS1),
84 dump_register(GHWPARAMS2),
85 dump_register(GHWPARAMS3),
86 dump_register(GHWPARAMS4),
87 dump_register(GHWPARAMS5),
88 dump_register(GHWPARAMS6),
89 dump_register(GHWPARAMS7),
90 dump_register(GDBGFIFOSPACE),
91 dump_register(GDBGLTSSM),
92 dump_register(GPRTBIMAP_HS0),
93 dump_register(GPRTBIMAP_HS1),
94 dump_register(GPRTBIMAP_FS0),
95 dump_register(GPRTBIMAP_FS1),
96
97 dump_register(GUSB2PHYCFG(0)),
98 dump_register(GUSB2PHYCFG(1)),
99 dump_register(GUSB2PHYCFG(2)),
100 dump_register(GUSB2PHYCFG(3)),
101 dump_register(GUSB2PHYCFG(4)),
102 dump_register(GUSB2PHYCFG(5)),
103 dump_register(GUSB2PHYCFG(6)),
104 dump_register(GUSB2PHYCFG(7)),
105 dump_register(GUSB2PHYCFG(8)),
106 dump_register(GUSB2PHYCFG(9)),
107 dump_register(GUSB2PHYCFG(10)),
108 dump_register(GUSB2PHYCFG(11)),
109 dump_register(GUSB2PHYCFG(12)),
110 dump_register(GUSB2PHYCFG(13)),
111 dump_register(GUSB2PHYCFG(14)),
112 dump_register(GUSB2PHYCFG(15)),
113
114 dump_register(GUSB2I2CCTL(0)),
115 dump_register(GUSB2I2CCTL(1)),
116 dump_register(GUSB2I2CCTL(2)),
117 dump_register(GUSB2I2CCTL(3)),
118 dump_register(GUSB2I2CCTL(4)),
119 dump_register(GUSB2I2CCTL(5)),
120 dump_register(GUSB2I2CCTL(6)),
121 dump_register(GUSB2I2CCTL(7)),
122 dump_register(GUSB2I2CCTL(8)),
123 dump_register(GUSB2I2CCTL(9)),
124 dump_register(GUSB2I2CCTL(10)),
125 dump_register(GUSB2I2CCTL(11)),
126 dump_register(GUSB2I2CCTL(12)),
127 dump_register(GUSB2I2CCTL(13)),
128 dump_register(GUSB2I2CCTL(14)),
129 dump_register(GUSB2I2CCTL(15)),
130
131 dump_register(GUSB2PHYACC(0)),
132 dump_register(GUSB2PHYACC(1)),
133 dump_register(GUSB2PHYACC(2)),
134 dump_register(GUSB2PHYACC(3)),
135 dump_register(GUSB2PHYACC(4)),
136 dump_register(GUSB2PHYACC(5)),
137 dump_register(GUSB2PHYACC(6)),
138 dump_register(GUSB2PHYACC(7)),
139 dump_register(GUSB2PHYACC(8)),
140 dump_register(GUSB2PHYACC(9)),
141 dump_register(GUSB2PHYACC(10)),
142 dump_register(GUSB2PHYACC(11)),
143 dump_register(GUSB2PHYACC(12)),
144 dump_register(GUSB2PHYACC(13)),
145 dump_register(GUSB2PHYACC(14)),
146 dump_register(GUSB2PHYACC(15)),
147
148 dump_register(GUSB3PIPECTL(0)),
149 dump_register(GUSB3PIPECTL(1)),
150 dump_register(GUSB3PIPECTL(2)),
151 dump_register(GUSB3PIPECTL(3)),
152 dump_register(GUSB3PIPECTL(4)),
153 dump_register(GUSB3PIPECTL(5)),
154 dump_register(GUSB3PIPECTL(6)),
155 dump_register(GUSB3PIPECTL(7)),
156 dump_register(GUSB3PIPECTL(8)),
157 dump_register(GUSB3PIPECTL(9)),
158 dump_register(GUSB3PIPECTL(10)),
159 dump_register(GUSB3PIPECTL(11)),
160 dump_register(GUSB3PIPECTL(12)),
161 dump_register(GUSB3PIPECTL(13)),
162 dump_register(GUSB3PIPECTL(14)),
163 dump_register(GUSB3PIPECTL(15)),
164
165 dump_register(GTXFIFOSIZ(0)),
166 dump_register(GTXFIFOSIZ(1)),
167 dump_register(GTXFIFOSIZ(2)),
168 dump_register(GTXFIFOSIZ(3)),
169 dump_register(GTXFIFOSIZ(4)),
170 dump_register(GTXFIFOSIZ(5)),
171 dump_register(GTXFIFOSIZ(6)),
172 dump_register(GTXFIFOSIZ(7)),
173 dump_register(GTXFIFOSIZ(8)),
174 dump_register(GTXFIFOSIZ(9)),
175 dump_register(GTXFIFOSIZ(10)),
176 dump_register(GTXFIFOSIZ(11)),
177 dump_register(GTXFIFOSIZ(12)),
178 dump_register(GTXFIFOSIZ(13)),
179 dump_register(GTXFIFOSIZ(14)),
180 dump_register(GTXFIFOSIZ(15)),
181 dump_register(GTXFIFOSIZ(16)),
182 dump_register(GTXFIFOSIZ(17)),
183 dump_register(GTXFIFOSIZ(18)),
184 dump_register(GTXFIFOSIZ(19)),
185 dump_register(GTXFIFOSIZ(20)),
186 dump_register(GTXFIFOSIZ(21)),
187 dump_register(GTXFIFOSIZ(22)),
188 dump_register(GTXFIFOSIZ(23)),
189 dump_register(GTXFIFOSIZ(24)),
190 dump_register(GTXFIFOSIZ(25)),
191 dump_register(GTXFIFOSIZ(26)),
192 dump_register(GTXFIFOSIZ(27)),
193 dump_register(GTXFIFOSIZ(28)),
194 dump_register(GTXFIFOSIZ(29)),
195 dump_register(GTXFIFOSIZ(30)),
196 dump_register(GTXFIFOSIZ(31)),
197
198 dump_register(GRXFIFOSIZ(0)),
199 dump_register(GRXFIFOSIZ(1)),
200 dump_register(GRXFIFOSIZ(2)),
201 dump_register(GRXFIFOSIZ(3)),
202 dump_register(GRXFIFOSIZ(4)),
203 dump_register(GRXFIFOSIZ(5)),
204 dump_register(GRXFIFOSIZ(6)),
205 dump_register(GRXFIFOSIZ(7)),
206 dump_register(GRXFIFOSIZ(8)),
207 dump_register(GRXFIFOSIZ(9)),
208 dump_register(GRXFIFOSIZ(10)),
209 dump_register(GRXFIFOSIZ(11)),
210 dump_register(GRXFIFOSIZ(12)),
211 dump_register(GRXFIFOSIZ(13)),
212 dump_register(GRXFIFOSIZ(14)),
213 dump_register(GRXFIFOSIZ(15)),
214 dump_register(GRXFIFOSIZ(16)),
215 dump_register(GRXFIFOSIZ(17)),
216 dump_register(GRXFIFOSIZ(18)),
217 dump_register(GRXFIFOSIZ(19)),
218 dump_register(GRXFIFOSIZ(20)),
219 dump_register(GRXFIFOSIZ(21)),
220 dump_register(GRXFIFOSIZ(22)),
221 dump_register(GRXFIFOSIZ(23)),
222 dump_register(GRXFIFOSIZ(24)),
223 dump_register(GRXFIFOSIZ(25)),
224 dump_register(GRXFIFOSIZ(26)),
225 dump_register(GRXFIFOSIZ(27)),
226 dump_register(GRXFIFOSIZ(28)),
227 dump_register(GRXFIFOSIZ(29)),
228 dump_register(GRXFIFOSIZ(30)),
229 dump_register(GRXFIFOSIZ(31)),
230
231 dump_register(GEVNTADRLO(0)),
232 dump_register(GEVNTADRHI(0)),
233 dump_register(GEVNTSIZ(0)),
234 dump_register(GEVNTCOUNT(0)),
235
236 dump_register(GHWPARAMS8),
237 dump_register(DCFG),
238 dump_register(DCTL),
239 dump_register(DEVTEN),
240 dump_register(DSTS),
241 dump_register(DGCMDPAR),
242 dump_register(DGCMD),
243 dump_register(DALEPENA),
244
245 dump_ep_register_set(0),
246 dump_ep_register_set(1),
247 dump_ep_register_set(2),
248 dump_ep_register_set(3),
249 dump_ep_register_set(4),
250 dump_ep_register_set(5),
251 dump_ep_register_set(6),
252 dump_ep_register_set(7),
253 dump_ep_register_set(8),
254 dump_ep_register_set(9),
255 dump_ep_register_set(10),
256 dump_ep_register_set(11),
257 dump_ep_register_set(12),
258 dump_ep_register_set(13),
259 dump_ep_register_set(14),
260 dump_ep_register_set(15),
261 dump_ep_register_set(16),
262 dump_ep_register_set(17),
263 dump_ep_register_set(18),
264 dump_ep_register_set(19),
265 dump_ep_register_set(20),
266 dump_ep_register_set(21),
267 dump_ep_register_set(22),
268 dump_ep_register_set(23),
269 dump_ep_register_set(24),
270 dump_ep_register_set(25),
271 dump_ep_register_set(26),
272 dump_ep_register_set(27),
273 dump_ep_register_set(28),
274 dump_ep_register_set(29),
275 dump_ep_register_set(30),
276 dump_ep_register_set(31),
277
278 dump_register(OCFG),
279 dump_register(OCTL),
280 dump_register(OEVT),
281 dump_register(OEVTEN),
282 dump_register(OSTS),
283};
284
285static int dwc3_mode_show(struct seq_file *s, void *unused)
286{
287 struct dwc3 *dwc = s->private;
288 unsigned long flags;
289 u32 reg;
290
291 spin_lock_irqsave(&dwc->lock, flags);
292 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
293 spin_unlock_irqrestore(&dwc->lock, flags);
294
295 switch (DWC3_GCTL_PRTCAP(reg)) {
296 case DWC3_GCTL_PRTCAP_HOST:
297 seq_printf(s, "host\n");
298 break;
299 case DWC3_GCTL_PRTCAP_DEVICE:
300 seq_printf(s, "device\n");
301 break;
302 case DWC3_GCTL_PRTCAP_OTG:
303 seq_printf(s, "OTG\n");
304 break;
305 default:
306 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
307 }
308
309 return 0;
310}
311
312static int dwc3_mode_open(struct inode *inode, struct file *file)
313{
314 return single_open(file, dwc3_mode_show, inode->i_private);
315}
316
317static ssize_t dwc3_mode_write(struct file *file,
318 const char __user *ubuf, size_t count, loff_t *ppos)
319{
320 struct seq_file *s = file->private_data;
321 struct dwc3 *dwc = s->private;
322 unsigned long flags;
323 u32 mode = 0;
324 char buf[32];
325
326 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
327 return -EFAULT;
328
329 if (!strncmp(buf, "host", 4))
330 mode |= DWC3_GCTL_PRTCAP_HOST;
331
332 if (!strncmp(buf, "device", 6))
333 mode |= DWC3_GCTL_PRTCAP_DEVICE;
334
335 if (!strncmp(buf, "otg", 3))
336 mode |= DWC3_GCTL_PRTCAP_OTG;
337
338 if (mode) {
339 spin_lock_irqsave(&dwc->lock, flags);
340 dwc3_set_mode(dwc, mode);
341 spin_unlock_irqrestore(&dwc->lock, flags);
342 }
343 return count;
344}
345
346static const struct file_operations dwc3_mode_fops = {
347 .open = dwc3_mode_open,
348 .write = dwc3_mode_write,
349 .read = seq_read,
350 .llseek = seq_lseek,
351 .release = single_release,
352};
353
354static int dwc3_testmode_show(struct seq_file *s, void *unused)
355{
356 struct dwc3 *dwc = s->private;
357 unsigned long flags;
358 u32 reg;
359
360 spin_lock_irqsave(&dwc->lock, flags);
361 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
362 reg &= DWC3_DCTL_TSTCTRL_MASK;
363 reg >>= 1;
364 spin_unlock_irqrestore(&dwc->lock, flags);
365
366 switch (reg) {
367 case 0:
368 seq_printf(s, "no test\n");
369 break;
370 case TEST_J:
371 seq_printf(s, "test_j\n");
372 break;
373 case TEST_K:
374 seq_printf(s, "test_k\n");
375 break;
376 case TEST_SE0_NAK:
377 seq_printf(s, "test_se0_nak\n");
378 break;
379 case TEST_PACKET:
380 seq_printf(s, "test_packet\n");
381 break;
382 case TEST_FORCE_EN:
383 seq_printf(s, "test_force_enable\n");
384 break;
385 default:
386 seq_printf(s, "UNKNOWN %d\n", reg);
387 }
388
389 return 0;
390}
391
392static int dwc3_testmode_open(struct inode *inode, struct file *file)
393{
394 return single_open(file, dwc3_testmode_show, inode->i_private);
395}
396
397static ssize_t dwc3_testmode_write(struct file *file,
398 const char __user *ubuf, size_t count, loff_t *ppos)
399{
400 struct seq_file *s = file->private_data;
401 struct dwc3 *dwc = s->private;
402 unsigned long flags;
403 u32 testmode = 0;
404 char buf[32];
405
406 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
407 return -EFAULT;
408
409 if (!strncmp(buf, "test_j", 6))
410 testmode = TEST_J;
411 else if (!strncmp(buf, "test_k", 6))
412 testmode = TEST_K;
413 else if (!strncmp(buf, "test_se0_nak", 12))
414 testmode = TEST_SE0_NAK;
415 else if (!strncmp(buf, "test_packet", 11))
416 testmode = TEST_PACKET;
417 else if (!strncmp(buf, "test_force_enable", 17))
418 testmode = TEST_FORCE_EN;
419 else
420 testmode = 0;
421
422 spin_lock_irqsave(&dwc->lock, flags);
423 dwc3_gadget_set_test_mode(dwc, testmode);
424 spin_unlock_irqrestore(&dwc->lock, flags);
425
426 return count;
427}
428
429static const struct file_operations dwc3_testmode_fops = {
430 .open = dwc3_testmode_open,
431 .write = dwc3_testmode_write,
432 .read = seq_read,
433 .llseek = seq_lseek,
434 .release = single_release,
435};
436
437static int dwc3_link_state_show(struct seq_file *s, void *unused)
438{
439 struct dwc3 *dwc = s->private;
440 unsigned long flags;
441 enum dwc3_link_state state;
442 u32 reg;
443
444 spin_lock_irqsave(&dwc->lock, flags);
445 reg = dwc3_readl(dwc->regs, DWC3_DSTS);
446 state = DWC3_DSTS_USBLNKST(reg);
447 spin_unlock_irqrestore(&dwc->lock, flags);
448
449 switch (state) {
450 case DWC3_LINK_STATE_U0:
451 seq_printf(s, "U0\n");
452 break;
453 case DWC3_LINK_STATE_U1:
454 seq_printf(s, "U1\n");
455 break;
456 case DWC3_LINK_STATE_U2:
457 seq_printf(s, "U2\n");
458 break;
459 case DWC3_LINK_STATE_U3:
460 seq_printf(s, "U3\n");
461 break;
462 case DWC3_LINK_STATE_SS_DIS:
463 seq_printf(s, "SS.Disabled\n");
464 break;
465 case DWC3_LINK_STATE_RX_DET:
466 seq_printf(s, "Rx.Detect\n");
467 break;
468 case DWC3_LINK_STATE_SS_INACT:
469 seq_printf(s, "SS.Inactive\n");
470 break;
471 case DWC3_LINK_STATE_POLL:
472 seq_printf(s, "Poll\n");
473 break;
474 case DWC3_LINK_STATE_RECOV:
475 seq_printf(s, "Recovery\n");
476 break;
477 case DWC3_LINK_STATE_HRESET:
478 seq_printf(s, "HRESET\n");
479 break;
480 case DWC3_LINK_STATE_CMPLY:
481 seq_printf(s, "Compliance\n");
482 break;
483 case DWC3_LINK_STATE_LPBK:
484 seq_printf(s, "Loopback\n");
485 break;
486 case DWC3_LINK_STATE_RESET:
487 seq_printf(s, "Reset\n");
488 break;
489 case DWC3_LINK_STATE_RESUME:
490 seq_printf(s, "Resume\n");
491 break;
492 default:
493 seq_printf(s, "UNKNOWN %d\n", state);
494 }
495
496 return 0;
497}
498
499static int dwc3_link_state_open(struct inode *inode, struct file *file)
500{
501 return single_open(file, dwc3_link_state_show, inode->i_private);
502}
503
504static ssize_t dwc3_link_state_write(struct file *file,
505 const char __user *ubuf, size_t count, loff_t *ppos)
506{
507 struct seq_file *s = file->private_data;
508 struct dwc3 *dwc = s->private;
509 unsigned long flags;
510 enum dwc3_link_state state = 0;
511 char buf[32];
512
513 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
514 return -EFAULT;
515
516 if (!strncmp(buf, "SS.Disabled", 11))
517 state = DWC3_LINK_STATE_SS_DIS;
518 else if (!strncmp(buf, "Rx.Detect", 9))
519 state = DWC3_LINK_STATE_RX_DET;
520 else if (!strncmp(buf, "SS.Inactive", 11))
521 state = DWC3_LINK_STATE_SS_INACT;
522 else if (!strncmp(buf, "Recovery", 8))
523 state = DWC3_LINK_STATE_RECOV;
524 else if (!strncmp(buf, "Compliance", 10))
525 state = DWC3_LINK_STATE_CMPLY;
526 else if (!strncmp(buf, "Loopback", 8))
527 state = DWC3_LINK_STATE_LPBK;
528 else
529 return -EINVAL;
530
531 spin_lock_irqsave(&dwc->lock, flags);
532 dwc3_gadget_set_link_state(dwc, state);
533 spin_unlock_irqrestore(&dwc->lock, flags);
534
535 return count;
536}
537
538static const struct file_operations dwc3_link_state_fops = {
539 .open = dwc3_link_state_open,
540 .write = dwc3_link_state_write,
541 .read = seq_read,
542 .llseek = seq_lseek,
543 .release = single_release,
544};
545
546struct dwc3_ep_file_map {
547 char name[25];
548 int (*show)(struct seq_file *s, void *unused);
549};
550
551static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused)
552{
553 struct dwc3_ep *dep = s->private;
554 struct dwc3 *dwc = dep->dwc;
555 unsigned long flags;
556 u32 val;
557
558 spin_lock_irqsave(&dwc->lock, flags);
559 val = dwc3_core_fifo_space(dep, DWC3_TXFIFOQ);
560 seq_printf(s, "%u\n", val);
561 spin_unlock_irqrestore(&dwc->lock, flags);
562
563 return 0;
564}
565
566static int dwc3_rx_fifo_queue_show(struct seq_file *s, void *unused)
567{
568 struct dwc3_ep *dep = s->private;
569 struct dwc3 *dwc = dep->dwc;
570 unsigned long flags;
571 u32 val;
572
573 spin_lock_irqsave(&dwc->lock, flags);
574 val = dwc3_core_fifo_space(dep, DWC3_RXFIFOQ);
575 seq_printf(s, "%u\n", val);
576 spin_unlock_irqrestore(&dwc->lock, flags);
577
578 return 0;
579}
580
581static int dwc3_tx_request_queue_show(struct seq_file *s, void *unused)
582{
583 struct dwc3_ep *dep = s->private;
584 struct dwc3 *dwc = dep->dwc;
585 unsigned long flags;
586 u32 val;
587
588 spin_lock_irqsave(&dwc->lock, flags);
589 val = dwc3_core_fifo_space(dep, DWC3_TXREQQ);
590 seq_printf(s, "%u\n", val);
591 spin_unlock_irqrestore(&dwc->lock, flags);
592
593 return 0;
594}
595
596static int dwc3_rx_request_queue_show(struct seq_file *s, void *unused)
597{
598 struct dwc3_ep *dep = s->private;
599 struct dwc3 *dwc = dep->dwc;
600 unsigned long flags;
601 u32 val;
602
603 spin_lock_irqsave(&dwc->lock, flags);
604 val = dwc3_core_fifo_space(dep, DWC3_RXREQQ);
605 seq_printf(s, "%u\n", val);
606 spin_unlock_irqrestore(&dwc->lock, flags);
607
608 return 0;
609}
610
611static int dwc3_rx_info_queue_show(struct seq_file *s, void *unused)
612{
613 struct dwc3_ep *dep = s->private;
614 struct dwc3 *dwc = dep->dwc;
615 unsigned long flags;
616 u32 val;
617
618 spin_lock_irqsave(&dwc->lock, flags);
619 val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ);
620 seq_printf(s, "%u\n", val);
621 spin_unlock_irqrestore(&dwc->lock, flags);
622
623 return 0;
624}
625
626static int dwc3_descriptor_fetch_queue_show(struct seq_file *s, void *unused)
627{
628 struct dwc3_ep *dep = s->private;
629 struct dwc3 *dwc = dep->dwc;
630 unsigned long flags;
631 u32 val;
632
633 spin_lock_irqsave(&dwc->lock, flags);
634 val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ);
635 seq_printf(s, "%u\n", val);
636 spin_unlock_irqrestore(&dwc->lock, flags);
637
638 return 0;
639}
640
641static int dwc3_event_queue_show(struct seq_file *s, void *unused)
642{
643 struct dwc3_ep *dep = s->private;
644 struct dwc3 *dwc = dep->dwc;
645 unsigned long flags;
646 u32 val;
647
648 spin_lock_irqsave(&dwc->lock, flags);
649 val = dwc3_core_fifo_space(dep, DWC3_EVENTQ);
650 seq_printf(s, "%u\n", val);
651 spin_unlock_irqrestore(&dwc->lock, flags);
652
653 return 0;
654}
655
656static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
657{
658 struct dwc3_ep *dep = s->private;
659 struct dwc3 *dwc = dep->dwc;
660 unsigned long flags;
661
662 spin_lock_irqsave(&dwc->lock, flags);
663 if (!(dep->flags & DWC3_EP_ENABLED) ||
664 !dep->endpoint.desc) {
665 seq_printf(s, "--\n");
666 goto out;
667 }
668
669 switch (usb_endpoint_type(dep->endpoint.desc)) {
670 case USB_ENDPOINT_XFER_CONTROL:
671 seq_printf(s, "control\n");
672 break;
673 case USB_ENDPOINT_XFER_ISOC:
674 seq_printf(s, "isochronous\n");
675 break;
676 case USB_ENDPOINT_XFER_BULK:
677 seq_printf(s, "bulk\n");
678 break;
679 case USB_ENDPOINT_XFER_INT:
680 seq_printf(s, "interrupt\n");
681 break;
682 default:
683 seq_printf(s, "--\n");
684 }
685
686out:
687 spin_unlock_irqrestore(&dwc->lock, flags);
688
689 return 0;
690}
691
692static inline const char *dwc3_trb_type_string(struct dwc3_trb *trb)
693{
694 switch (DWC3_TRBCTL_TYPE(trb->ctrl)) {
695 case DWC3_TRBCTL_NORMAL:
696 return "normal";
697 case DWC3_TRBCTL_CONTROL_SETUP:
698 return "control-setup";
699 case DWC3_TRBCTL_CONTROL_STATUS2:
700 return "control-status2";
701 case DWC3_TRBCTL_CONTROL_STATUS3:
702 return "control-status3";
703 case DWC3_TRBCTL_CONTROL_DATA:
704 return "control-data";
705 case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
706 return "isoc-first";
707 case DWC3_TRBCTL_ISOCHRONOUS:
708 return "isoc";
709 case DWC3_TRBCTL_LINK_TRB:
710 return "link";
711 default:
712 return "UNKNOWN";
713 }
714}
715
716static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
717{
718 struct dwc3_ep *dep = s->private;
719 struct dwc3 *dwc = dep->dwc;
720 unsigned long flags;
721 int i;
722
723 spin_lock_irqsave(&dwc->lock, flags);
724 if (dep->number <= 1) {
725 seq_printf(s, "--\n");
726 goto out;
727 }
728
729 seq_printf(s, "enqueue pointer %d\n", dep->trb_enqueue);
730 seq_printf(s, "dequeue pointer %d\n", dep->trb_dequeue);
731 seq_printf(s, "\n--------------------------------------------------\n\n");
732 seq_printf(s, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n");
733
734 for (i = 0; i < DWC3_TRB_NUM; i++) {
735 struct dwc3_trb *trb = &dep->trb_pool[i];
736
737 seq_printf(s, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d\n",
738 trb->bph, trb->bpl, trb->size,
739 dwc3_trb_type_string(trb),
740 !!(trb->ctrl & DWC3_TRB_CTRL_IOC),
741 !!(trb->ctrl & DWC3_TRB_CTRL_ISP_IMI),
742 !!(trb->ctrl & DWC3_TRB_CTRL_CSP),
743 !!(trb->ctrl & DWC3_TRB_CTRL_CHN),
744 !!(trb->ctrl & DWC3_TRB_CTRL_LST),
745 !!(trb->ctrl & DWC3_TRB_CTRL_HWO));
746 }
747
748out:
749 spin_unlock_irqrestore(&dwc->lock, flags);
750
751 return 0;
752}
753
754static struct dwc3_ep_file_map map[] = {
755 { "tx_fifo_queue", dwc3_tx_fifo_queue_show, },
756 { "rx_fifo_queue", dwc3_rx_fifo_queue_show, },
757 { "tx_request_queue", dwc3_tx_request_queue_show, },
758 { "rx_request_queue", dwc3_rx_request_queue_show, },
759 { "rx_info_queue", dwc3_rx_info_queue_show, },
760 { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show, },
761 { "event_queue", dwc3_event_queue_show, },
762 { "transfer_type", dwc3_ep_transfer_type_show, },
763 { "trb_ring", dwc3_ep_trb_ring_show, },
764};
765
766static int dwc3_endpoint_open(struct inode *inode, struct file *file)
767{
768 const char *file_name = file_dentry(file)->d_iname;
769 struct dwc3_ep_file_map *f_map;
770 int i;
771
772 for (i = 0; i < ARRAY_SIZE(map); i++) {
773 f_map = &map[i];
774
775 if (strcmp(f_map->name, file_name) == 0)
776 break;
777 }
778
779 return single_open(file, f_map->show, inode->i_private);
780}
781
782static const struct file_operations dwc3_endpoint_fops = {
783 .open = dwc3_endpoint_open,
784 .read = seq_read,
785 .llseek = seq_lseek,
786 .release = single_release,
787};
788
789static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
790 struct dentry *parent, int type)
791{
792 struct dentry *file;
793 struct dwc3_ep_file_map *ep_file = &map[type];
794
795 file = debugfs_create_file(ep_file->name, S_IRUGO, parent, dep,
796 &dwc3_endpoint_fops);
797}
798
799static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
800 struct dentry *parent)
801{
802 int i;
803
804 for (i = 0; i < ARRAY_SIZE(map); i++)
805 dwc3_debugfs_create_endpoint_file(dep, parent, i);
806}
807
808static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
809 struct dentry *parent)
810{
811 struct dentry *dir;
812
813 dir = debugfs_create_dir(dep->name, parent);
814 if (IS_ERR_OR_NULL(dir))
815 return;
816
817 dwc3_debugfs_create_endpoint_files(dep, dir);
818}
819
820static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc,
821 struct dentry *parent)
822{
823 int i;
824
825 for (i = 0; i < dwc->num_in_eps; i++) {
826 u8 epnum = (i << 1) | 1;
827 struct dwc3_ep *dep = dwc->eps[epnum];
828
829 if (!dep)
830 continue;
831
832 dwc3_debugfs_create_endpoint_dir(dep, parent);
833 }
834
835 for (i = 0; i < dwc->num_out_eps; i++) {
836 u8 epnum = (i << 1);
837 struct dwc3_ep *dep = dwc->eps[epnum];
838
839 if (!dep)
840 continue;
841
842 dwc3_debugfs_create_endpoint_dir(dep, parent);
843 }
844}
845
846void dwc3_debugfs_init(struct dwc3 *dwc)
847{
848 struct dentry *root;
849 struct dentry *file;
850
851 root = debugfs_create_dir(dev_name(dwc->dev), NULL);
852 if (IS_ERR_OR_NULL(root)) {
853 if (!root)
854 dev_err(dwc->dev, "Can't create debugfs root\n");
855 return;
856 }
857 dwc->root = root;
858
859 dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
860 if (!dwc->regset) {
861 debugfs_remove_recursive(root);
862 return;
863 }
864
865 dwc->regset->regs = dwc3_regs;
866 dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
867 dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START;
868
869 file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
870 if (!file)
871 dev_dbg(dwc->dev, "Can't create debugfs regdump\n");
872
873 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
874 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
875 dwc, &dwc3_mode_fops);
876 if (!file)
877 dev_dbg(dwc->dev, "Can't create debugfs mode\n");
878 }
879
880 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
881 IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
882 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
883 dwc, &dwc3_testmode_fops);
884 if (!file)
885 dev_dbg(dwc->dev, "Can't create debugfs testmode\n");
886
887 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR,
888 root, dwc, &dwc3_link_state_fops);
889 if (!file)
890 dev_dbg(dwc->dev, "Can't create debugfs link_state\n");
891
892 dwc3_debugfs_create_endpoint_dirs(dwc, root);
893 }
894}
895
896void dwc3_debugfs_exit(struct dwc3 *dwc)
897{
898 debugfs_remove_recursive(dwc->root);
899 kfree(dwc->regset);
900}
1/**
2 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2, as published by the Free
24 * Software Foundation.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <linux/kernel.h>
40#include <linux/slab.h>
41#include <linux/ptrace.h>
42#include <linux/types.h>
43#include <linux/spinlock.h>
44#include <linux/debugfs.h>
45#include <linux/seq_file.h>
46#include <linux/delay.h>
47#include <linux/uaccess.h>
48
49#include <linux/usb/ch9.h>
50
51#include "core.h"
52#include "gadget.h"
53#include "io.h"
54#include "debug.h"
55
56#define dump_register(nm) \
57{ \
58 .name = __stringify(nm), \
59 .offset = DWC3_ ##nm, \
60}
61
62static const struct debugfs_reg32 dwc3_regs[] = {
63 dump_register(GSBUSCFG0),
64 dump_register(GSBUSCFG1),
65 dump_register(GTXTHRCFG),
66 dump_register(GRXTHRCFG),
67 dump_register(GCTL),
68 dump_register(GEVTEN),
69 dump_register(GSTS),
70 dump_register(GSNPSID),
71 dump_register(GGPIO),
72 dump_register(GUID),
73 dump_register(GUCTL),
74 dump_register(GBUSERRADDR0),
75 dump_register(GBUSERRADDR1),
76 dump_register(GPRTBIMAP0),
77 dump_register(GPRTBIMAP1),
78 dump_register(GHWPARAMS0),
79 dump_register(GHWPARAMS1),
80 dump_register(GHWPARAMS2),
81 dump_register(GHWPARAMS3),
82 dump_register(GHWPARAMS4),
83 dump_register(GHWPARAMS5),
84 dump_register(GHWPARAMS6),
85 dump_register(GHWPARAMS7),
86 dump_register(GDBGFIFOSPACE),
87 dump_register(GDBGLTSSM),
88 dump_register(GPRTBIMAP_HS0),
89 dump_register(GPRTBIMAP_HS1),
90 dump_register(GPRTBIMAP_FS0),
91 dump_register(GPRTBIMAP_FS1),
92
93 dump_register(GUSB2PHYCFG(0)),
94 dump_register(GUSB2PHYCFG(1)),
95 dump_register(GUSB2PHYCFG(2)),
96 dump_register(GUSB2PHYCFG(3)),
97 dump_register(GUSB2PHYCFG(4)),
98 dump_register(GUSB2PHYCFG(5)),
99 dump_register(GUSB2PHYCFG(6)),
100 dump_register(GUSB2PHYCFG(7)),
101 dump_register(GUSB2PHYCFG(8)),
102 dump_register(GUSB2PHYCFG(9)),
103 dump_register(GUSB2PHYCFG(10)),
104 dump_register(GUSB2PHYCFG(11)),
105 dump_register(GUSB2PHYCFG(12)),
106 dump_register(GUSB2PHYCFG(13)),
107 dump_register(GUSB2PHYCFG(14)),
108 dump_register(GUSB2PHYCFG(15)),
109
110 dump_register(GUSB2I2CCTL(0)),
111 dump_register(GUSB2I2CCTL(1)),
112 dump_register(GUSB2I2CCTL(2)),
113 dump_register(GUSB2I2CCTL(3)),
114 dump_register(GUSB2I2CCTL(4)),
115 dump_register(GUSB2I2CCTL(5)),
116 dump_register(GUSB2I2CCTL(6)),
117 dump_register(GUSB2I2CCTL(7)),
118 dump_register(GUSB2I2CCTL(8)),
119 dump_register(GUSB2I2CCTL(9)),
120 dump_register(GUSB2I2CCTL(10)),
121 dump_register(GUSB2I2CCTL(11)),
122 dump_register(GUSB2I2CCTL(12)),
123 dump_register(GUSB2I2CCTL(13)),
124 dump_register(GUSB2I2CCTL(14)),
125 dump_register(GUSB2I2CCTL(15)),
126
127 dump_register(GUSB2PHYACC(0)),
128 dump_register(GUSB2PHYACC(1)),
129 dump_register(GUSB2PHYACC(2)),
130 dump_register(GUSB2PHYACC(3)),
131 dump_register(GUSB2PHYACC(4)),
132 dump_register(GUSB2PHYACC(5)),
133 dump_register(GUSB2PHYACC(6)),
134 dump_register(GUSB2PHYACC(7)),
135 dump_register(GUSB2PHYACC(8)),
136 dump_register(GUSB2PHYACC(9)),
137 dump_register(GUSB2PHYACC(10)),
138 dump_register(GUSB2PHYACC(11)),
139 dump_register(GUSB2PHYACC(12)),
140 dump_register(GUSB2PHYACC(13)),
141 dump_register(GUSB2PHYACC(14)),
142 dump_register(GUSB2PHYACC(15)),
143
144 dump_register(GUSB3PIPECTL(0)),
145 dump_register(GUSB3PIPECTL(1)),
146 dump_register(GUSB3PIPECTL(2)),
147 dump_register(GUSB3PIPECTL(3)),
148 dump_register(GUSB3PIPECTL(4)),
149 dump_register(GUSB3PIPECTL(5)),
150 dump_register(GUSB3PIPECTL(6)),
151 dump_register(GUSB3PIPECTL(7)),
152 dump_register(GUSB3PIPECTL(8)),
153 dump_register(GUSB3PIPECTL(9)),
154 dump_register(GUSB3PIPECTL(10)),
155 dump_register(GUSB3PIPECTL(11)),
156 dump_register(GUSB3PIPECTL(12)),
157 dump_register(GUSB3PIPECTL(13)),
158 dump_register(GUSB3PIPECTL(14)),
159 dump_register(GUSB3PIPECTL(15)),
160
161 dump_register(GTXFIFOSIZ(0)),
162 dump_register(GTXFIFOSIZ(1)),
163 dump_register(GTXFIFOSIZ(2)),
164 dump_register(GTXFIFOSIZ(3)),
165 dump_register(GTXFIFOSIZ(4)),
166 dump_register(GTXFIFOSIZ(5)),
167 dump_register(GTXFIFOSIZ(6)),
168 dump_register(GTXFIFOSIZ(7)),
169 dump_register(GTXFIFOSIZ(8)),
170 dump_register(GTXFIFOSIZ(9)),
171 dump_register(GTXFIFOSIZ(10)),
172 dump_register(GTXFIFOSIZ(11)),
173 dump_register(GTXFIFOSIZ(12)),
174 dump_register(GTXFIFOSIZ(13)),
175 dump_register(GTXFIFOSIZ(14)),
176 dump_register(GTXFIFOSIZ(15)),
177 dump_register(GTXFIFOSIZ(16)),
178 dump_register(GTXFIFOSIZ(17)),
179 dump_register(GTXFIFOSIZ(18)),
180 dump_register(GTXFIFOSIZ(19)),
181 dump_register(GTXFIFOSIZ(20)),
182 dump_register(GTXFIFOSIZ(21)),
183 dump_register(GTXFIFOSIZ(22)),
184 dump_register(GTXFIFOSIZ(23)),
185 dump_register(GTXFIFOSIZ(24)),
186 dump_register(GTXFIFOSIZ(25)),
187 dump_register(GTXFIFOSIZ(26)),
188 dump_register(GTXFIFOSIZ(27)),
189 dump_register(GTXFIFOSIZ(28)),
190 dump_register(GTXFIFOSIZ(29)),
191 dump_register(GTXFIFOSIZ(30)),
192 dump_register(GTXFIFOSIZ(31)),
193
194 dump_register(GRXFIFOSIZ(0)),
195 dump_register(GRXFIFOSIZ(1)),
196 dump_register(GRXFIFOSIZ(2)),
197 dump_register(GRXFIFOSIZ(3)),
198 dump_register(GRXFIFOSIZ(4)),
199 dump_register(GRXFIFOSIZ(5)),
200 dump_register(GRXFIFOSIZ(6)),
201 dump_register(GRXFIFOSIZ(7)),
202 dump_register(GRXFIFOSIZ(8)),
203 dump_register(GRXFIFOSIZ(9)),
204 dump_register(GRXFIFOSIZ(10)),
205 dump_register(GRXFIFOSIZ(11)),
206 dump_register(GRXFIFOSIZ(12)),
207 dump_register(GRXFIFOSIZ(13)),
208 dump_register(GRXFIFOSIZ(14)),
209 dump_register(GRXFIFOSIZ(15)),
210 dump_register(GRXFIFOSIZ(16)),
211 dump_register(GRXFIFOSIZ(17)),
212 dump_register(GRXFIFOSIZ(18)),
213 dump_register(GRXFIFOSIZ(19)),
214 dump_register(GRXFIFOSIZ(20)),
215 dump_register(GRXFIFOSIZ(21)),
216 dump_register(GRXFIFOSIZ(22)),
217 dump_register(GRXFIFOSIZ(23)),
218 dump_register(GRXFIFOSIZ(24)),
219 dump_register(GRXFIFOSIZ(25)),
220 dump_register(GRXFIFOSIZ(26)),
221 dump_register(GRXFIFOSIZ(27)),
222 dump_register(GRXFIFOSIZ(28)),
223 dump_register(GRXFIFOSIZ(29)),
224 dump_register(GRXFIFOSIZ(30)),
225 dump_register(GRXFIFOSIZ(31)),
226
227 dump_register(GEVNTADRLO(0)),
228 dump_register(GEVNTADRHI(0)),
229 dump_register(GEVNTSIZ(0)),
230 dump_register(GEVNTCOUNT(0)),
231
232 dump_register(GHWPARAMS8),
233 dump_register(DCFG),
234 dump_register(DCTL),
235 dump_register(DEVTEN),
236 dump_register(DSTS),
237 dump_register(DGCMDPAR),
238 dump_register(DGCMD),
239 dump_register(DALEPENA),
240
241 dump_register(DEPCMDPAR2(0)),
242 dump_register(DEPCMDPAR2(1)),
243 dump_register(DEPCMDPAR2(2)),
244 dump_register(DEPCMDPAR2(3)),
245 dump_register(DEPCMDPAR2(4)),
246 dump_register(DEPCMDPAR2(5)),
247 dump_register(DEPCMDPAR2(6)),
248 dump_register(DEPCMDPAR2(7)),
249 dump_register(DEPCMDPAR2(8)),
250 dump_register(DEPCMDPAR2(9)),
251 dump_register(DEPCMDPAR2(10)),
252 dump_register(DEPCMDPAR2(11)),
253 dump_register(DEPCMDPAR2(12)),
254 dump_register(DEPCMDPAR2(13)),
255 dump_register(DEPCMDPAR2(14)),
256 dump_register(DEPCMDPAR2(15)),
257 dump_register(DEPCMDPAR2(16)),
258 dump_register(DEPCMDPAR2(17)),
259 dump_register(DEPCMDPAR2(18)),
260 dump_register(DEPCMDPAR2(19)),
261 dump_register(DEPCMDPAR2(20)),
262 dump_register(DEPCMDPAR2(21)),
263 dump_register(DEPCMDPAR2(22)),
264 dump_register(DEPCMDPAR2(23)),
265 dump_register(DEPCMDPAR2(24)),
266 dump_register(DEPCMDPAR2(25)),
267 dump_register(DEPCMDPAR2(26)),
268 dump_register(DEPCMDPAR2(27)),
269 dump_register(DEPCMDPAR2(28)),
270 dump_register(DEPCMDPAR2(29)),
271 dump_register(DEPCMDPAR2(30)),
272 dump_register(DEPCMDPAR2(31)),
273
274 dump_register(DEPCMDPAR1(0)),
275 dump_register(DEPCMDPAR1(1)),
276 dump_register(DEPCMDPAR1(2)),
277 dump_register(DEPCMDPAR1(3)),
278 dump_register(DEPCMDPAR1(4)),
279 dump_register(DEPCMDPAR1(5)),
280 dump_register(DEPCMDPAR1(6)),
281 dump_register(DEPCMDPAR1(7)),
282 dump_register(DEPCMDPAR1(8)),
283 dump_register(DEPCMDPAR1(9)),
284 dump_register(DEPCMDPAR1(10)),
285 dump_register(DEPCMDPAR1(11)),
286 dump_register(DEPCMDPAR1(12)),
287 dump_register(DEPCMDPAR1(13)),
288 dump_register(DEPCMDPAR1(14)),
289 dump_register(DEPCMDPAR1(15)),
290 dump_register(DEPCMDPAR1(16)),
291 dump_register(DEPCMDPAR1(17)),
292 dump_register(DEPCMDPAR1(18)),
293 dump_register(DEPCMDPAR1(19)),
294 dump_register(DEPCMDPAR1(20)),
295 dump_register(DEPCMDPAR1(21)),
296 dump_register(DEPCMDPAR1(22)),
297 dump_register(DEPCMDPAR1(23)),
298 dump_register(DEPCMDPAR1(24)),
299 dump_register(DEPCMDPAR1(25)),
300 dump_register(DEPCMDPAR1(26)),
301 dump_register(DEPCMDPAR1(27)),
302 dump_register(DEPCMDPAR1(28)),
303 dump_register(DEPCMDPAR1(29)),
304 dump_register(DEPCMDPAR1(30)),
305 dump_register(DEPCMDPAR1(31)),
306
307 dump_register(DEPCMDPAR0(0)),
308 dump_register(DEPCMDPAR0(1)),
309 dump_register(DEPCMDPAR0(2)),
310 dump_register(DEPCMDPAR0(3)),
311 dump_register(DEPCMDPAR0(4)),
312 dump_register(DEPCMDPAR0(5)),
313 dump_register(DEPCMDPAR0(6)),
314 dump_register(DEPCMDPAR0(7)),
315 dump_register(DEPCMDPAR0(8)),
316 dump_register(DEPCMDPAR0(9)),
317 dump_register(DEPCMDPAR0(10)),
318 dump_register(DEPCMDPAR0(11)),
319 dump_register(DEPCMDPAR0(12)),
320 dump_register(DEPCMDPAR0(13)),
321 dump_register(DEPCMDPAR0(14)),
322 dump_register(DEPCMDPAR0(15)),
323 dump_register(DEPCMDPAR0(16)),
324 dump_register(DEPCMDPAR0(17)),
325 dump_register(DEPCMDPAR0(18)),
326 dump_register(DEPCMDPAR0(19)),
327 dump_register(DEPCMDPAR0(20)),
328 dump_register(DEPCMDPAR0(21)),
329 dump_register(DEPCMDPAR0(22)),
330 dump_register(DEPCMDPAR0(23)),
331 dump_register(DEPCMDPAR0(24)),
332 dump_register(DEPCMDPAR0(25)),
333 dump_register(DEPCMDPAR0(26)),
334 dump_register(DEPCMDPAR0(27)),
335 dump_register(DEPCMDPAR0(28)),
336 dump_register(DEPCMDPAR0(29)),
337 dump_register(DEPCMDPAR0(30)),
338 dump_register(DEPCMDPAR0(31)),
339
340 dump_register(DEPCMD(0)),
341 dump_register(DEPCMD(1)),
342 dump_register(DEPCMD(2)),
343 dump_register(DEPCMD(3)),
344 dump_register(DEPCMD(4)),
345 dump_register(DEPCMD(5)),
346 dump_register(DEPCMD(6)),
347 dump_register(DEPCMD(7)),
348 dump_register(DEPCMD(8)),
349 dump_register(DEPCMD(9)),
350 dump_register(DEPCMD(10)),
351 dump_register(DEPCMD(11)),
352 dump_register(DEPCMD(12)),
353 dump_register(DEPCMD(13)),
354 dump_register(DEPCMD(14)),
355 dump_register(DEPCMD(15)),
356 dump_register(DEPCMD(16)),
357 dump_register(DEPCMD(17)),
358 dump_register(DEPCMD(18)),
359 dump_register(DEPCMD(19)),
360 dump_register(DEPCMD(20)),
361 dump_register(DEPCMD(21)),
362 dump_register(DEPCMD(22)),
363 dump_register(DEPCMD(23)),
364 dump_register(DEPCMD(24)),
365 dump_register(DEPCMD(25)),
366 dump_register(DEPCMD(26)),
367 dump_register(DEPCMD(27)),
368 dump_register(DEPCMD(28)),
369 dump_register(DEPCMD(29)),
370 dump_register(DEPCMD(30)),
371 dump_register(DEPCMD(31)),
372
373 dump_register(OCFG),
374 dump_register(OCTL),
375 dump_register(OEVTEN),
376 dump_register(OSTS),
377};
378
379static int dwc3_regdump_show(struct seq_file *s, void *unused)
380{
381 struct dwc3 *dwc = s->private;
382
383 seq_printf(s, "DesignWare USB3 Core Register Dump\n");
384 debugfs_print_regs32(s, dwc3_regs, ARRAY_SIZE(dwc3_regs),
385 dwc->regs, "");
386 return 0;
387}
388
389static int dwc3_regdump_open(struct inode *inode, struct file *file)
390{
391 return single_open(file, dwc3_regdump_show, inode->i_private);
392}
393
394static const struct file_operations dwc3_regdump_fops = {
395 .open = dwc3_regdump_open,
396 .read = seq_read,
397 .release = single_release,
398};
399
400static int dwc3_mode_show(struct seq_file *s, void *unused)
401{
402 struct dwc3 *dwc = s->private;
403 unsigned long flags;
404 u32 reg;
405
406 spin_lock_irqsave(&dwc->lock, flags);
407 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
408 spin_unlock_irqrestore(&dwc->lock, flags);
409
410 switch (DWC3_GCTL_PRTCAP(reg)) {
411 case DWC3_GCTL_PRTCAP_HOST:
412 seq_printf(s, "host\n");
413 break;
414 case DWC3_GCTL_PRTCAP_DEVICE:
415 seq_printf(s, "device\n");
416 break;
417 case DWC3_GCTL_PRTCAP_OTG:
418 seq_printf(s, "OTG\n");
419 break;
420 default:
421 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
422 }
423
424 return 0;
425}
426
427static int dwc3_mode_open(struct inode *inode, struct file *file)
428{
429 return single_open(file, dwc3_mode_show, inode->i_private);
430}
431
432static ssize_t dwc3_mode_write(struct file *file,
433 const char __user *ubuf, size_t count, loff_t *ppos)
434{
435 struct seq_file *s = file->private_data;
436 struct dwc3 *dwc = s->private;
437 unsigned long flags;
438 u32 mode = 0;
439 char buf[32];
440
441 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
442 return -EFAULT;
443
444 if (!strncmp(buf, "host", 4))
445 mode |= DWC3_GCTL_PRTCAP_HOST;
446
447 if (!strncmp(buf, "device", 6))
448 mode |= DWC3_GCTL_PRTCAP_DEVICE;
449
450 if (!strncmp(buf, "otg", 3))
451 mode |= DWC3_GCTL_PRTCAP_OTG;
452
453 if (mode) {
454 spin_lock_irqsave(&dwc->lock, flags);
455 dwc3_set_mode(dwc, mode);
456 spin_unlock_irqrestore(&dwc->lock, flags);
457 }
458 return count;
459}
460
461static const struct file_operations dwc3_mode_fops = {
462 .open = dwc3_mode_open,
463 .write = dwc3_mode_write,
464 .read = seq_read,
465 .llseek = seq_lseek,
466 .release = single_release,
467};
468
469static int dwc3_testmode_show(struct seq_file *s, void *unused)
470{
471 struct dwc3 *dwc = s->private;
472 unsigned long flags;
473 u32 reg;
474
475 spin_lock_irqsave(&dwc->lock, flags);
476 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
477 reg &= DWC3_DCTL_TSTCTRL_MASK;
478 reg >>= 1;
479 spin_unlock_irqrestore(&dwc->lock, flags);
480
481 switch (reg) {
482 case 0:
483 seq_printf(s, "no test\n");
484 break;
485 case TEST_J:
486 seq_printf(s, "test_j\n");
487 break;
488 case TEST_K:
489 seq_printf(s, "test_k\n");
490 break;
491 case TEST_SE0_NAK:
492 seq_printf(s, "test_se0_nak\n");
493 break;
494 case TEST_PACKET:
495 seq_printf(s, "test_packet\n");
496 break;
497 case TEST_FORCE_EN:
498 seq_printf(s, "test_force_enable\n");
499 break;
500 default:
501 seq_printf(s, "UNKNOWN %d\n", reg);
502 }
503
504 return 0;
505}
506
507static int dwc3_testmode_open(struct inode *inode, struct file *file)
508{
509 return single_open(file, dwc3_testmode_show, inode->i_private);
510}
511
512static ssize_t dwc3_testmode_write(struct file *file,
513 const char __user *ubuf, size_t count, loff_t *ppos)
514{
515 struct seq_file *s = file->private_data;
516 struct dwc3 *dwc = s->private;
517 unsigned long flags;
518 u32 testmode = 0;
519 char buf[32];
520
521 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
522 return -EFAULT;
523
524 if (!strncmp(buf, "test_j", 6))
525 testmode = TEST_J;
526 else if (!strncmp(buf, "test_k", 6))
527 testmode = TEST_K;
528 else if (!strncmp(buf, "test_se0_nak", 12))
529 testmode = TEST_SE0_NAK;
530 else if (!strncmp(buf, "test_packet", 11))
531 testmode = TEST_PACKET;
532 else if (!strncmp(buf, "test_force_enable", 17))
533 testmode = TEST_FORCE_EN;
534 else
535 testmode = 0;
536
537 spin_lock_irqsave(&dwc->lock, flags);
538 dwc3_gadget_set_test_mode(dwc, testmode);
539 spin_unlock_irqrestore(&dwc->lock, flags);
540
541 return count;
542}
543
544static const struct file_operations dwc3_testmode_fops = {
545 .open = dwc3_testmode_open,
546 .write = dwc3_testmode_write,
547 .read = seq_read,
548 .llseek = seq_lseek,
549 .release = single_release,
550};
551
552static int dwc3_link_state_show(struct seq_file *s, void *unused)
553{
554 struct dwc3 *dwc = s->private;
555 unsigned long flags;
556 enum dwc3_link_state state;
557 u32 reg;
558
559 spin_lock_irqsave(&dwc->lock, flags);
560 reg = dwc3_readl(dwc->regs, DWC3_DSTS);
561 state = DWC3_DSTS_USBLNKST(reg);
562 spin_unlock_irqrestore(&dwc->lock, flags);
563
564 switch (state) {
565 case DWC3_LINK_STATE_U0:
566 seq_printf(s, "U0\n");
567 break;
568 case DWC3_LINK_STATE_U1:
569 seq_printf(s, "U1\n");
570 break;
571 case DWC3_LINK_STATE_U2:
572 seq_printf(s, "U2\n");
573 break;
574 case DWC3_LINK_STATE_U3:
575 seq_printf(s, "U3\n");
576 break;
577 case DWC3_LINK_STATE_SS_DIS:
578 seq_printf(s, "SS.Disabled\n");
579 break;
580 case DWC3_LINK_STATE_RX_DET:
581 seq_printf(s, "Rx.Detect\n");
582 break;
583 case DWC3_LINK_STATE_SS_INACT:
584 seq_printf(s, "SS.Inactive\n");
585 break;
586 case DWC3_LINK_STATE_POLL:
587 seq_printf(s, "Poll\n");
588 break;
589 case DWC3_LINK_STATE_RECOV:
590 seq_printf(s, "Recovery\n");
591 break;
592 case DWC3_LINK_STATE_HRESET:
593 seq_printf(s, "HRESET\n");
594 break;
595 case DWC3_LINK_STATE_CMPLY:
596 seq_printf(s, "Compliance\n");
597 break;
598 case DWC3_LINK_STATE_LPBK:
599 seq_printf(s, "Loopback\n");
600 break;
601 default:
602 seq_printf(s, "UNKNOWN %d\n", reg);
603 }
604
605 return 0;
606}
607
608static int dwc3_link_state_open(struct inode *inode, struct file *file)
609{
610 return single_open(file, dwc3_link_state_show, inode->i_private);
611}
612
613static ssize_t dwc3_link_state_write(struct file *file,
614 const char __user *ubuf, size_t count, loff_t *ppos)
615{
616 struct seq_file *s = file->private_data;
617 struct dwc3 *dwc = s->private;
618 unsigned long flags;
619 enum dwc3_link_state state = 0;
620 char buf[32];
621
622 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
623 return -EFAULT;
624
625 if (!strncmp(buf, "SS.Disabled", 11))
626 state = DWC3_LINK_STATE_SS_DIS;
627 else if (!strncmp(buf, "Rx.Detect", 9))
628 state = DWC3_LINK_STATE_RX_DET;
629 else if (!strncmp(buf, "SS.Inactive", 11))
630 state = DWC3_LINK_STATE_SS_INACT;
631 else if (!strncmp(buf, "Recovery", 8))
632 state = DWC3_LINK_STATE_RECOV;
633 else if (!strncmp(buf, "Compliance", 10))
634 state = DWC3_LINK_STATE_CMPLY;
635 else if (!strncmp(buf, "Loopback", 8))
636 state = DWC3_LINK_STATE_LPBK;
637 else
638 return -EINVAL;
639
640 spin_lock_irqsave(&dwc->lock, flags);
641 dwc3_gadget_set_link_state(dwc, state);
642 spin_unlock_irqrestore(&dwc->lock, flags);
643
644 return count;
645}
646
647static const struct file_operations dwc3_link_state_fops = {
648 .open = dwc3_link_state_open,
649 .write = dwc3_link_state_write,
650 .read = seq_read,
651 .llseek = seq_lseek,
652 .release = single_release,
653};
654
655int __devinit dwc3_debugfs_init(struct dwc3 *dwc)
656{
657 struct dentry *root;
658 struct dentry *file;
659 int ret;
660
661 root = debugfs_create_dir(dev_name(dwc->dev), NULL);
662 if (!root) {
663 ret = -ENOMEM;
664 goto err0;
665 }
666
667 dwc->root = root;
668
669 file = debugfs_create_file("regdump", S_IRUGO, root, dwc,
670 &dwc3_regdump_fops);
671 if (!file) {
672 ret = -ENOMEM;
673 goto err1;
674 }
675
676 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
677 dwc, &dwc3_mode_fops);
678 if (!file) {
679 ret = -ENOMEM;
680 goto err1;
681 }
682
683 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
684 dwc, &dwc3_testmode_fops);
685 if (!file) {
686 ret = -ENOMEM;
687 goto err1;
688 }
689
690 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
691 dwc, &dwc3_link_state_fops);
692 if (!file) {
693 ret = -ENOMEM;
694 goto err1;
695 }
696
697 return 0;
698
699err1:
700 debugfs_remove_recursive(root);
701
702err0:
703 return ret;
704}
705
706void __devexit dwc3_debugfs_exit(struct dwc3 *dwc)
707{
708 debugfs_remove_recursive(dwc->root);
709 dwc->root = NULL;
710}