1 // SPDX-License-Identifier: GPL-2.0
3 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
5 * 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>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/ptrace.h>
14 #include <linux/types.h>
15 #include <linux/spinlock.h>
16 #include <linux/debugfs.h>
17 #include <linux/seq_file.h>
18 #include <linux/delay.h>
19 #include <linux/uaccess.h>
21 #include <linux/usb/ch9.h>
28 #define dump_register(nm) \
30 .name = __stringify(nm), \
31 .offset = DWC3_ ##nm, \
34 #define dump_ep_register_set(n) \
36 .name = "DEPCMDPAR2("__stringify(n)")", \
37 .offset = DWC3_DEP_BASE(n) + \
41 .name = "DEPCMDPAR1("__stringify(n)")", \
42 .offset = DWC3_DEP_BASE(n) + \
46 .name = "DEPCMDPAR0("__stringify(n)")", \
47 .offset = DWC3_DEP_BASE(n) + \
51 .name = "DEPCMD("__stringify(n)")", \
52 .offset = DWC3_DEP_BASE(n) + \
57 static const struct debugfs_reg32 dwc3_regs
[] = {
58 dump_register(GSBUSCFG0
),
59 dump_register(GSBUSCFG1
),
60 dump_register(GTXTHRCFG
),
61 dump_register(GRXTHRCFG
),
63 dump_register(GEVTEN
),
65 dump_register(GUCTL1
),
66 dump_register(GSNPSID
),
70 dump_register(GBUSERRADDR0
),
71 dump_register(GBUSERRADDR1
),
72 dump_register(GPRTBIMAP0
),
73 dump_register(GPRTBIMAP1
),
74 dump_register(GHWPARAMS0
),
75 dump_register(GHWPARAMS1
),
76 dump_register(GHWPARAMS2
),
77 dump_register(GHWPARAMS3
),
78 dump_register(GHWPARAMS4
),
79 dump_register(GHWPARAMS5
),
80 dump_register(GHWPARAMS6
),
81 dump_register(GHWPARAMS7
),
82 dump_register(GDBGFIFOSPACE
),
83 dump_register(GDBGLTSSM
),
84 dump_register(GPRTBIMAP_HS0
),
85 dump_register(GPRTBIMAP_HS1
),
86 dump_register(GPRTBIMAP_FS0
),
87 dump_register(GPRTBIMAP_FS1
),
89 dump_register(GUSB2PHYCFG(0)),
90 dump_register(GUSB2PHYCFG(1)),
91 dump_register(GUSB2PHYCFG(2)),
92 dump_register(GUSB2PHYCFG(3)),
93 dump_register(GUSB2PHYCFG(4)),
94 dump_register(GUSB2PHYCFG(5)),
95 dump_register(GUSB2PHYCFG(6)),
96 dump_register(GUSB2PHYCFG(7)),
97 dump_register(GUSB2PHYCFG(8)),
98 dump_register(GUSB2PHYCFG(9)),
99 dump_register(GUSB2PHYCFG(10)),
100 dump_register(GUSB2PHYCFG(11)),
101 dump_register(GUSB2PHYCFG(12)),
102 dump_register(GUSB2PHYCFG(13)),
103 dump_register(GUSB2PHYCFG(14)),
104 dump_register(GUSB2PHYCFG(15)),
106 dump_register(GUSB2I2CCTL(0)),
107 dump_register(GUSB2I2CCTL(1)),
108 dump_register(GUSB2I2CCTL(2)),
109 dump_register(GUSB2I2CCTL(3)),
110 dump_register(GUSB2I2CCTL(4)),
111 dump_register(GUSB2I2CCTL(5)),
112 dump_register(GUSB2I2CCTL(6)),
113 dump_register(GUSB2I2CCTL(7)),
114 dump_register(GUSB2I2CCTL(8)),
115 dump_register(GUSB2I2CCTL(9)),
116 dump_register(GUSB2I2CCTL(10)),
117 dump_register(GUSB2I2CCTL(11)),
118 dump_register(GUSB2I2CCTL(12)),
119 dump_register(GUSB2I2CCTL(13)),
120 dump_register(GUSB2I2CCTL(14)),
121 dump_register(GUSB2I2CCTL(15)),
123 dump_register(GUSB2PHYACC(0)),
124 dump_register(GUSB2PHYACC(1)),
125 dump_register(GUSB2PHYACC(2)),
126 dump_register(GUSB2PHYACC(3)),
127 dump_register(GUSB2PHYACC(4)),
128 dump_register(GUSB2PHYACC(5)),
129 dump_register(GUSB2PHYACC(6)),
130 dump_register(GUSB2PHYACC(7)),
131 dump_register(GUSB2PHYACC(8)),
132 dump_register(GUSB2PHYACC(9)),
133 dump_register(GUSB2PHYACC(10)),
134 dump_register(GUSB2PHYACC(11)),
135 dump_register(GUSB2PHYACC(12)),
136 dump_register(GUSB2PHYACC(13)),
137 dump_register(GUSB2PHYACC(14)),
138 dump_register(GUSB2PHYACC(15)),
140 dump_register(GUSB3PIPECTL(0)),
141 dump_register(GUSB3PIPECTL(1)),
142 dump_register(GUSB3PIPECTL(2)),
143 dump_register(GUSB3PIPECTL(3)),
144 dump_register(GUSB3PIPECTL(4)),
145 dump_register(GUSB3PIPECTL(5)),
146 dump_register(GUSB3PIPECTL(6)),
147 dump_register(GUSB3PIPECTL(7)),
148 dump_register(GUSB3PIPECTL(8)),
149 dump_register(GUSB3PIPECTL(9)),
150 dump_register(GUSB3PIPECTL(10)),
151 dump_register(GUSB3PIPECTL(11)),
152 dump_register(GUSB3PIPECTL(12)),
153 dump_register(GUSB3PIPECTL(13)),
154 dump_register(GUSB3PIPECTL(14)),
155 dump_register(GUSB3PIPECTL(15)),
157 dump_register(GTXFIFOSIZ(0)),
158 dump_register(GTXFIFOSIZ(1)),
159 dump_register(GTXFIFOSIZ(2)),
160 dump_register(GTXFIFOSIZ(3)),
161 dump_register(GTXFIFOSIZ(4)),
162 dump_register(GTXFIFOSIZ(5)),
163 dump_register(GTXFIFOSIZ(6)),
164 dump_register(GTXFIFOSIZ(7)),
165 dump_register(GTXFIFOSIZ(8)),
166 dump_register(GTXFIFOSIZ(9)),
167 dump_register(GTXFIFOSIZ(10)),
168 dump_register(GTXFIFOSIZ(11)),
169 dump_register(GTXFIFOSIZ(12)),
170 dump_register(GTXFIFOSIZ(13)),
171 dump_register(GTXFIFOSIZ(14)),
172 dump_register(GTXFIFOSIZ(15)),
173 dump_register(GTXFIFOSIZ(16)),
174 dump_register(GTXFIFOSIZ(17)),
175 dump_register(GTXFIFOSIZ(18)),
176 dump_register(GTXFIFOSIZ(19)),
177 dump_register(GTXFIFOSIZ(20)),
178 dump_register(GTXFIFOSIZ(21)),
179 dump_register(GTXFIFOSIZ(22)),
180 dump_register(GTXFIFOSIZ(23)),
181 dump_register(GTXFIFOSIZ(24)),
182 dump_register(GTXFIFOSIZ(25)),
183 dump_register(GTXFIFOSIZ(26)),
184 dump_register(GTXFIFOSIZ(27)),
185 dump_register(GTXFIFOSIZ(28)),
186 dump_register(GTXFIFOSIZ(29)),
187 dump_register(GTXFIFOSIZ(30)),
188 dump_register(GTXFIFOSIZ(31)),
190 dump_register(GRXFIFOSIZ(0)),
191 dump_register(GRXFIFOSIZ(1)),
192 dump_register(GRXFIFOSIZ(2)),
193 dump_register(GRXFIFOSIZ(3)),
194 dump_register(GRXFIFOSIZ(4)),
195 dump_register(GRXFIFOSIZ(5)),
196 dump_register(GRXFIFOSIZ(6)),
197 dump_register(GRXFIFOSIZ(7)),
198 dump_register(GRXFIFOSIZ(8)),
199 dump_register(GRXFIFOSIZ(9)),
200 dump_register(GRXFIFOSIZ(10)),
201 dump_register(GRXFIFOSIZ(11)),
202 dump_register(GRXFIFOSIZ(12)),
203 dump_register(GRXFIFOSIZ(13)),
204 dump_register(GRXFIFOSIZ(14)),
205 dump_register(GRXFIFOSIZ(15)),
206 dump_register(GRXFIFOSIZ(16)),
207 dump_register(GRXFIFOSIZ(17)),
208 dump_register(GRXFIFOSIZ(18)),
209 dump_register(GRXFIFOSIZ(19)),
210 dump_register(GRXFIFOSIZ(20)),
211 dump_register(GRXFIFOSIZ(21)),
212 dump_register(GRXFIFOSIZ(22)),
213 dump_register(GRXFIFOSIZ(23)),
214 dump_register(GRXFIFOSIZ(24)),
215 dump_register(GRXFIFOSIZ(25)),
216 dump_register(GRXFIFOSIZ(26)),
217 dump_register(GRXFIFOSIZ(27)),
218 dump_register(GRXFIFOSIZ(28)),
219 dump_register(GRXFIFOSIZ(29)),
220 dump_register(GRXFIFOSIZ(30)),
221 dump_register(GRXFIFOSIZ(31)),
223 dump_register(GEVNTADRLO(0)),
224 dump_register(GEVNTADRHI(0)),
225 dump_register(GEVNTSIZ(0)),
226 dump_register(GEVNTCOUNT(0)),
228 dump_register(GHWPARAMS8
),
231 dump_register(DEVTEN
),
233 dump_register(DGCMDPAR
),
234 dump_register(DGCMD
),
235 dump_register(DALEPENA
),
237 dump_ep_register_set(0),
238 dump_ep_register_set(1),
239 dump_ep_register_set(2),
240 dump_ep_register_set(3),
241 dump_ep_register_set(4),
242 dump_ep_register_set(5),
243 dump_ep_register_set(6),
244 dump_ep_register_set(7),
245 dump_ep_register_set(8),
246 dump_ep_register_set(9),
247 dump_ep_register_set(10),
248 dump_ep_register_set(11),
249 dump_ep_register_set(12),
250 dump_ep_register_set(13),
251 dump_ep_register_set(14),
252 dump_ep_register_set(15),
253 dump_ep_register_set(16),
254 dump_ep_register_set(17),
255 dump_ep_register_set(18),
256 dump_ep_register_set(19),
257 dump_ep_register_set(20),
258 dump_ep_register_set(21),
259 dump_ep_register_set(22),
260 dump_ep_register_set(23),
261 dump_ep_register_set(24),
262 dump_ep_register_set(25),
263 dump_ep_register_set(26),
264 dump_ep_register_set(27),
265 dump_ep_register_set(28),
266 dump_ep_register_set(29),
267 dump_ep_register_set(30),
268 dump_ep_register_set(31),
273 dump_register(OEVTEN
),
277 static int dwc3_mode_show(struct seq_file
*s
, void *unused
)
279 struct dwc3
*dwc
= s
->private;
283 spin_lock_irqsave(&dwc
->lock
, flags
);
284 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
285 spin_unlock_irqrestore(&dwc
->lock
, flags
);
287 switch (DWC3_GCTL_PRTCAP(reg
)) {
288 case DWC3_GCTL_PRTCAP_HOST
:
289 seq_printf(s
, "host\n");
291 case DWC3_GCTL_PRTCAP_DEVICE
:
292 seq_printf(s
, "device\n");
294 case DWC3_GCTL_PRTCAP_OTG
:
295 seq_printf(s
, "otg\n");
298 seq_printf(s
, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg
));
304 static int dwc3_mode_open(struct inode
*inode
, struct file
*file
)
306 return single_open(file
, dwc3_mode_show
, inode
->i_private
);
309 static ssize_t
dwc3_mode_write(struct file
*file
,
310 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
312 struct seq_file
*s
= file
->private_data
;
313 struct dwc3
*dwc
= s
->private;
317 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
320 if (!strncmp(buf
, "host", 4))
321 mode
= DWC3_GCTL_PRTCAP_HOST
;
323 if (!strncmp(buf
, "device", 6))
324 mode
= DWC3_GCTL_PRTCAP_DEVICE
;
326 if (!strncmp(buf
, "otg", 3))
327 mode
= DWC3_GCTL_PRTCAP_OTG
;
329 dwc3_set_mode(dwc
, mode
);
334 static const struct file_operations dwc3_mode_fops
= {
335 .open
= dwc3_mode_open
,
336 .write
= dwc3_mode_write
,
339 .release
= single_release
,
342 static int dwc3_testmode_show(struct seq_file
*s
, void *unused
)
344 struct dwc3
*dwc
= s
->private;
348 spin_lock_irqsave(&dwc
->lock
, flags
);
349 reg
= dwc3_readl(dwc
->regs
, DWC3_DCTL
);
350 reg
&= DWC3_DCTL_TSTCTRL_MASK
;
352 spin_unlock_irqrestore(&dwc
->lock
, flags
);
356 seq_printf(s
, "no test\n");
359 seq_printf(s
, "test_j\n");
362 seq_printf(s
, "test_k\n");
365 seq_printf(s
, "test_se0_nak\n");
368 seq_printf(s
, "test_packet\n");
371 seq_printf(s
, "test_force_enable\n");
374 seq_printf(s
, "UNKNOWN %d\n", reg
);
380 static int dwc3_testmode_open(struct inode
*inode
, struct file
*file
)
382 return single_open(file
, dwc3_testmode_show
, inode
->i_private
);
385 static ssize_t
dwc3_testmode_write(struct file
*file
,
386 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
388 struct seq_file
*s
= file
->private_data
;
389 struct dwc3
*dwc
= s
->private;
394 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
397 if (!strncmp(buf
, "test_j", 6))
399 else if (!strncmp(buf
, "test_k", 6))
401 else if (!strncmp(buf
, "test_se0_nak", 12))
402 testmode
= TEST_SE0_NAK
;
403 else if (!strncmp(buf
, "test_packet", 11))
404 testmode
= TEST_PACKET
;
405 else if (!strncmp(buf
, "test_force_enable", 17))
406 testmode
= TEST_FORCE_EN
;
410 spin_lock_irqsave(&dwc
->lock
, flags
);
411 dwc3_gadget_set_test_mode(dwc
, testmode
);
412 spin_unlock_irqrestore(&dwc
->lock
, flags
);
417 static const struct file_operations dwc3_testmode_fops
= {
418 .open
= dwc3_testmode_open
,
419 .write
= dwc3_testmode_write
,
422 .release
= single_release
,
425 static int dwc3_link_state_show(struct seq_file
*s
, void *unused
)
427 struct dwc3
*dwc
= s
->private;
429 enum dwc3_link_state state
;
432 spin_lock_irqsave(&dwc
->lock
, flags
);
433 reg
= dwc3_readl(dwc
->regs
, DWC3_DSTS
);
434 state
= DWC3_DSTS_USBLNKST(reg
);
435 spin_unlock_irqrestore(&dwc
->lock
, flags
);
437 seq_printf(s
, "%s\n", dwc3_gadget_link_string(state
));
442 static int dwc3_link_state_open(struct inode
*inode
, struct file
*file
)
444 return single_open(file
, dwc3_link_state_show
, inode
->i_private
);
447 static ssize_t
dwc3_link_state_write(struct file
*file
,
448 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
450 struct seq_file
*s
= file
->private_data
;
451 struct dwc3
*dwc
= s
->private;
453 enum dwc3_link_state state
= 0;
456 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
459 if (!strncmp(buf
, "SS.Disabled", 11))
460 state
= DWC3_LINK_STATE_SS_DIS
;
461 else if (!strncmp(buf
, "Rx.Detect", 9))
462 state
= DWC3_LINK_STATE_RX_DET
;
463 else if (!strncmp(buf
, "SS.Inactive", 11))
464 state
= DWC3_LINK_STATE_SS_INACT
;
465 else if (!strncmp(buf
, "Recovery", 8))
466 state
= DWC3_LINK_STATE_RECOV
;
467 else if (!strncmp(buf
, "Compliance", 10))
468 state
= DWC3_LINK_STATE_CMPLY
;
469 else if (!strncmp(buf
, "Loopback", 8))
470 state
= DWC3_LINK_STATE_LPBK
;
474 spin_lock_irqsave(&dwc
->lock
, flags
);
475 dwc3_gadget_set_link_state(dwc
, state
);
476 spin_unlock_irqrestore(&dwc
->lock
, flags
);
481 static const struct file_operations dwc3_link_state_fops
= {
482 .open
= dwc3_link_state_open
,
483 .write
= dwc3_link_state_write
,
486 .release
= single_release
,
489 struct dwc3_ep_file_map
{
491 int (*show
)(struct seq_file
*s
, void *unused
);
494 static int dwc3_tx_fifo_queue_show(struct seq_file
*s
, void *unused
)
496 struct dwc3_ep
*dep
= s
->private;
497 struct dwc3
*dwc
= dep
->dwc
;
501 spin_lock_irqsave(&dwc
->lock
, flags
);
502 val
= dwc3_core_fifo_space(dep
, DWC3_TXFIFOQ
);
503 seq_printf(s
, "%u\n", val
);
504 spin_unlock_irqrestore(&dwc
->lock
, flags
);
509 static int dwc3_rx_fifo_queue_show(struct seq_file
*s
, void *unused
)
511 struct dwc3_ep
*dep
= s
->private;
512 struct dwc3
*dwc
= dep
->dwc
;
516 spin_lock_irqsave(&dwc
->lock
, flags
);
517 val
= dwc3_core_fifo_space(dep
, DWC3_RXFIFOQ
);
518 seq_printf(s
, "%u\n", val
);
519 spin_unlock_irqrestore(&dwc
->lock
, flags
);
524 static int dwc3_tx_request_queue_show(struct seq_file
*s
, void *unused
)
526 struct dwc3_ep
*dep
= s
->private;
527 struct dwc3
*dwc
= dep
->dwc
;
531 spin_lock_irqsave(&dwc
->lock
, flags
);
532 val
= dwc3_core_fifo_space(dep
, DWC3_TXREQQ
);
533 seq_printf(s
, "%u\n", val
);
534 spin_unlock_irqrestore(&dwc
->lock
, flags
);
539 static int dwc3_rx_request_queue_show(struct seq_file
*s
, void *unused
)
541 struct dwc3_ep
*dep
= s
->private;
542 struct dwc3
*dwc
= dep
->dwc
;
546 spin_lock_irqsave(&dwc
->lock
, flags
);
547 val
= dwc3_core_fifo_space(dep
, DWC3_RXREQQ
);
548 seq_printf(s
, "%u\n", val
);
549 spin_unlock_irqrestore(&dwc
->lock
, flags
);
554 static int dwc3_rx_info_queue_show(struct seq_file
*s
, void *unused
)
556 struct dwc3_ep
*dep
= s
->private;
557 struct dwc3
*dwc
= dep
->dwc
;
561 spin_lock_irqsave(&dwc
->lock
, flags
);
562 val
= dwc3_core_fifo_space(dep
, DWC3_RXINFOQ
);
563 seq_printf(s
, "%u\n", val
);
564 spin_unlock_irqrestore(&dwc
->lock
, flags
);
569 static int dwc3_descriptor_fetch_queue_show(struct seq_file
*s
, void *unused
)
571 struct dwc3_ep
*dep
= s
->private;
572 struct dwc3
*dwc
= dep
->dwc
;
576 spin_lock_irqsave(&dwc
->lock
, flags
);
577 val
= dwc3_core_fifo_space(dep
, DWC3_DESCFETCHQ
);
578 seq_printf(s
, "%u\n", val
);
579 spin_unlock_irqrestore(&dwc
->lock
, flags
);
584 static int dwc3_event_queue_show(struct seq_file
*s
, void *unused
)
586 struct dwc3_ep
*dep
= s
->private;
587 struct dwc3
*dwc
= dep
->dwc
;
591 spin_lock_irqsave(&dwc
->lock
, flags
);
592 val
= dwc3_core_fifo_space(dep
, DWC3_EVENTQ
);
593 seq_printf(s
, "%u\n", val
);
594 spin_unlock_irqrestore(&dwc
->lock
, flags
);
599 static int dwc3_ep_transfer_type_show(struct seq_file
*s
, void *unused
)
601 struct dwc3_ep
*dep
= s
->private;
602 struct dwc3
*dwc
= dep
->dwc
;
605 spin_lock_irqsave(&dwc
->lock
, flags
);
606 if (!(dep
->flags
& DWC3_EP_ENABLED
) ||
607 !dep
->endpoint
.desc
) {
608 seq_printf(s
, "--\n");
612 switch (usb_endpoint_type(dep
->endpoint
.desc
)) {
613 case USB_ENDPOINT_XFER_CONTROL
:
614 seq_printf(s
, "control\n");
616 case USB_ENDPOINT_XFER_ISOC
:
617 seq_printf(s
, "isochronous\n");
619 case USB_ENDPOINT_XFER_BULK
:
620 seq_printf(s
, "bulk\n");
622 case USB_ENDPOINT_XFER_INT
:
623 seq_printf(s
, "interrupt\n");
626 seq_printf(s
, "--\n");
630 spin_unlock_irqrestore(&dwc
->lock
, flags
);
635 static int dwc3_ep_trb_ring_show(struct seq_file
*s
, void *unused
)
637 struct dwc3_ep
*dep
= s
->private;
638 struct dwc3
*dwc
= dep
->dwc
;
642 spin_lock_irqsave(&dwc
->lock
, flags
);
643 if (dep
->number
<= 1) {
644 seq_printf(s
, "--\n");
648 seq_printf(s
, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n");
650 for (i
= 0; i
< DWC3_TRB_NUM
; i
++) {
651 struct dwc3_trb
*trb
= &dep
->trb_pool
[i
];
652 unsigned int type
= DWC3_TRBCTL_TYPE(trb
->ctrl
);
654 seq_printf(s
, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d %c%c\n",
655 trb
->bph
, trb
->bpl
, trb
->size
,
656 dwc3_trb_type_string(type
),
657 !!(trb
->ctrl
& DWC3_TRB_CTRL_IOC
),
658 !!(trb
->ctrl
& DWC3_TRB_CTRL_ISP_IMI
),
659 !!(trb
->ctrl
& DWC3_TRB_CTRL_CSP
),
660 !!(trb
->ctrl
& DWC3_TRB_CTRL_CHN
),
661 !!(trb
->ctrl
& DWC3_TRB_CTRL_LST
),
662 !!(trb
->ctrl
& DWC3_TRB_CTRL_HWO
),
663 dep
->trb_enqueue
== i
? 'E' : ' ',
664 dep
->trb_dequeue
== i
? 'D' : ' ');
668 spin_unlock_irqrestore(&dwc
->lock
, flags
);
673 static struct dwc3_ep_file_map map
[] = {
674 { "tx_fifo_queue", dwc3_tx_fifo_queue_show
, },
675 { "rx_fifo_queue", dwc3_rx_fifo_queue_show
, },
676 { "tx_request_queue", dwc3_tx_request_queue_show
, },
677 { "rx_request_queue", dwc3_rx_request_queue_show
, },
678 { "rx_info_queue", dwc3_rx_info_queue_show
, },
679 { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show
, },
680 { "event_queue", dwc3_event_queue_show
, },
681 { "transfer_type", dwc3_ep_transfer_type_show
, },
682 { "trb_ring", dwc3_ep_trb_ring_show
, },
685 static int dwc3_endpoint_open(struct inode
*inode
, struct file
*file
)
687 const char *file_name
= file_dentry(file
)->d_iname
;
688 struct dwc3_ep_file_map
*f_map
;
691 for (i
= 0; i
< ARRAY_SIZE(map
); i
++) {
694 if (strcmp(f_map
->name
, file_name
) == 0)
698 return single_open(file
, f_map
->show
, inode
->i_private
);
701 static const struct file_operations dwc3_endpoint_fops
= {
702 .open
= dwc3_endpoint_open
,
705 .release
= single_release
,
708 static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep
*dep
,
709 struct dentry
*parent
, int type
)
712 struct dwc3_ep_file_map
*ep_file
= &map
[type
];
714 file
= debugfs_create_file(ep_file
->name
, S_IRUGO
, parent
, dep
,
715 &dwc3_endpoint_fops
);
718 static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep
*dep
,
719 struct dentry
*parent
)
723 for (i
= 0; i
< ARRAY_SIZE(map
); i
++)
724 dwc3_debugfs_create_endpoint_file(dep
, parent
, i
);
727 static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep
*dep
,
728 struct dentry
*parent
)
732 dir
= debugfs_create_dir(dep
->name
, parent
);
733 if (IS_ERR_OR_NULL(dir
))
736 dwc3_debugfs_create_endpoint_files(dep
, dir
);
739 static void dwc3_debugfs_create_endpoint_dirs(struct dwc3
*dwc
,
740 struct dentry
*parent
)
744 for (i
= 0; i
< dwc
->num_eps
; i
++) {
745 struct dwc3_ep
*dep
= dwc
->eps
[i
];
750 dwc3_debugfs_create_endpoint_dir(dep
, parent
);
754 void dwc3_debugfs_init(struct dwc3
*dwc
)
759 root
= debugfs_create_dir(dev_name(dwc
->dev
), NULL
);
760 if (IS_ERR_OR_NULL(root
)) {
762 dev_err(dwc
->dev
, "Can't create debugfs root\n");
767 dwc
->regset
= kzalloc(sizeof(*dwc
->regset
), GFP_KERNEL
);
769 debugfs_remove_recursive(root
);
773 dwc
->regset
->regs
= dwc3_regs
;
774 dwc
->regset
->nregs
= ARRAY_SIZE(dwc3_regs
);
775 dwc
->regset
->base
= dwc
->regs
- DWC3_GLOBALS_REGS_START
;
777 file
= debugfs_create_regset32("regdump", S_IRUGO
, root
, dwc
->regset
);
779 dev_dbg(dwc
->dev
, "Can't create debugfs regdump\n");
781 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE
)) {
782 file
= debugfs_create_file("mode", S_IRUGO
| S_IWUSR
, root
,
783 dwc
, &dwc3_mode_fops
);
785 dev_dbg(dwc
->dev
, "Can't create debugfs mode\n");
788 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE
) ||
789 IS_ENABLED(CONFIG_USB_DWC3_GADGET
)) {
790 file
= debugfs_create_file("testmode", S_IRUGO
| S_IWUSR
, root
,
791 dwc
, &dwc3_testmode_fops
);
793 dev_dbg(dwc
->dev
, "Can't create debugfs testmode\n");
795 file
= debugfs_create_file("link_state", S_IRUGO
| S_IWUSR
,
796 root
, dwc
, &dwc3_link_state_fops
);
798 dev_dbg(dwc
->dev
, "Can't create debugfs link_state\n");
800 dwc3_debugfs_create_endpoint_dirs(dwc
, root
);
804 void dwc3_debugfs_exit(struct dwc3
*dwc
)
806 debugfs_remove_recursive(dwc
->root
);