1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/spinlock.h>
18#include <linux/debugfs.h>
19#include <linux/seq_file.h>
20#include <linux/uaccess.h>
21
22#include "core.h"
23#include "debug.h"
24
25#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
26 IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
27
28
29
30
31
32
33
34static ssize_t testmode_write(struct file *file, const char __user *ubuf, size_t
35 count, loff_t *ppos)
36{
37 struct seq_file *s = file->private_data;
38 struct dwc2_hsotg *hsotg = s->private;
39 unsigned long flags;
40 u32 testmode = 0;
41 char buf[32];
42
43 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
44 return -EFAULT;
45
46 if (!strncmp(buf, "test_j", 6))
47 testmode = TEST_J;
48 else if (!strncmp(buf, "test_k", 6))
49 testmode = TEST_K;
50 else if (!strncmp(buf, "test_se0_nak", 12))
51 testmode = TEST_SE0_NAK;
52 else if (!strncmp(buf, "test_packet", 11))
53 testmode = TEST_PACKET;
54 else if (!strncmp(buf, "test_force_enable", 17))
55 testmode = TEST_FORCE_EN;
56 else
57 testmode = 0;
58
59 spin_lock_irqsave(&hsotg->lock, flags);
60 dwc2_hsotg_set_test_mode(hsotg, testmode);
61 spin_unlock_irqrestore(&hsotg->lock, flags);
62 return count;
63}
64
65
66
67
68
69
70
71
72static int testmode_show(struct seq_file *s, void *unused)
73{
74 struct dwc2_hsotg *hsotg = s->private;
75 unsigned long flags;
76 int dctl;
77
78 spin_lock_irqsave(&hsotg->lock, flags);
79 dctl = dwc2_readl(hsotg->regs + DCTL);
80 dctl &= DCTL_TSTCTL_MASK;
81 dctl >>= DCTL_TSTCTL_SHIFT;
82 spin_unlock_irqrestore(&hsotg->lock, flags);
83
84 switch (dctl) {
85 case 0:
86 seq_puts(s, "no test\n");
87 break;
88 case TEST_J:
89 seq_puts(s, "test_j\n");
90 break;
91 case TEST_K:
92 seq_puts(s, "test_k\n");
93 break;
94 case TEST_SE0_NAK:
95 seq_puts(s, "test_se0_nak\n");
96 break;
97 case TEST_PACKET:
98 seq_puts(s, "test_packet\n");
99 break;
100 case TEST_FORCE_EN:
101 seq_puts(s, "test_force_enable\n");
102 break;
103 default:
104 seq_printf(s, "UNKNOWN %d\n", dctl);
105 }
106
107 return 0;
108}
109
110static int testmode_open(struct inode *inode, struct file *file)
111{
112 return single_open(file, testmode_show, inode->i_private);
113}
114
115static const struct file_operations testmode_fops = {
116 .owner = THIS_MODULE,
117 .open = testmode_open,
118 .write = testmode_write,
119 .read = seq_read,
120 .llseek = seq_lseek,
121 .release = single_release,
122};
123
124
125
126
127
128
129
130
131
132
133static int state_show(struct seq_file *seq, void *v)
134{
135 struct dwc2_hsotg *hsotg = seq->private;
136 void __iomem *regs = hsotg->regs;
137 int idx;
138
139 seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n",
140 dwc2_readl(regs + DCFG),
141 dwc2_readl(regs + DCTL),
142 dwc2_readl(regs + DSTS));
143
144 seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n",
145 dwc2_readl(regs + DIEPMSK), dwc2_readl(regs + DOEPMSK));
146
147 seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n",
148 dwc2_readl(regs + GINTMSK),
149 dwc2_readl(regs + GINTSTS));
150
151 seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n",
152 dwc2_readl(regs + DAINTMSK),
153 dwc2_readl(regs + DAINT));
154
155 seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n",
156 dwc2_readl(regs + GNPTXSTS),
157 dwc2_readl(regs + GRXSTSR));
158
159 seq_puts(seq, "\nEndpoint status:\n");
160
161 for (idx = 0; idx < hsotg->num_of_eps; idx++) {
162 u32 in, out;
163
164 in = dwc2_readl(regs + DIEPCTL(idx));
165 out = dwc2_readl(regs + DOEPCTL(idx));
166
167 seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x",
168 idx, in, out);
169
170 in = dwc2_readl(regs + DIEPTSIZ(idx));
171 out = dwc2_readl(regs + DOEPTSIZ(idx));
172
173 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x",
174 in, out);
175
176 seq_puts(seq, "\n");
177 }
178
179 return 0;
180}
181
182static int state_open(struct inode *inode, struct file *file)
183{
184 return single_open(file, state_show, inode->i_private);
185}
186
187static const struct file_operations state_fops = {
188 .owner = THIS_MODULE,
189 .open = state_open,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = single_release,
193};
194
195
196
197
198
199
200
201
202
203static int fifo_show(struct seq_file *seq, void *v)
204{
205 struct dwc2_hsotg *hsotg = seq->private;
206 void __iomem *regs = hsotg->regs;
207 u32 val;
208 int idx;
209
210 seq_puts(seq, "Non-periodic FIFOs:\n");
211 seq_printf(seq, "RXFIFO: Size %d\n", dwc2_readl(regs + GRXFSIZ));
212
213 val = dwc2_readl(regs + GNPTXFSIZ);
214 seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n",
215 val >> FIFOSIZE_DEPTH_SHIFT,
216 val & FIFOSIZE_STARTADDR_MASK);
217
218 seq_puts(seq, "\nPeriodic TXFIFOs:\n");
219
220 for (idx = 1; idx < hsotg->num_of_eps; idx++) {
221 val = dwc2_readl(regs + DPTXFSIZN(idx));
222
223 seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx,
224 val >> FIFOSIZE_DEPTH_SHIFT,
225 val & FIFOSIZE_STARTADDR_MASK);
226 }
227
228 return 0;
229}
230
231static int fifo_open(struct inode *inode, struct file *file)
232{
233 return single_open(file, fifo_show, inode->i_private);
234}
235
236static const struct file_operations fifo_fops = {
237 .owner = THIS_MODULE,
238 .open = fifo_open,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
242};
243
244static const char *decode_direction(int is_in)
245{
246 return is_in ? "in" : "out";
247}
248
249
250
251
252
253
254
255
256
257static int ep_show(struct seq_file *seq, void *v)
258{
259 struct dwc2_hsotg_ep *ep = seq->private;
260 struct dwc2_hsotg *hsotg = ep->parent;
261 struct dwc2_hsotg_req *req;
262 void __iomem *regs = hsotg->regs;
263 int index = ep->index;
264 int show_limit = 15;
265 unsigned long flags;
266
267 seq_printf(seq, "Endpoint index %d, named %s, dir %s:\n",
268 ep->index, ep->ep.name, decode_direction(ep->dir_in));
269
270
271
272 seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n",
273 dwc2_readl(regs + DIEPCTL(index)),
274 dwc2_readl(regs + DOEPCTL(index)));
275
276 seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n",
277 dwc2_readl(regs + DIEPDMA(index)),
278 dwc2_readl(regs + DOEPDMA(index)));
279
280 seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n",
281 dwc2_readl(regs + DIEPINT(index)),
282 dwc2_readl(regs + DOEPINT(index)));
283
284 seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n",
285 dwc2_readl(regs + DIEPTSIZ(index)),
286 dwc2_readl(regs + DOEPTSIZ(index)));
287
288 seq_puts(seq, "\n");
289 seq_printf(seq, "mps %d\n", ep->ep.maxpacket);
290 seq_printf(seq, "total_data=%ld\n", ep->total_data);
291
292 seq_printf(seq, "request list (%p,%p):\n",
293 ep->queue.next, ep->queue.prev);
294
295 spin_lock_irqsave(&hsotg->lock, flags);
296
297 list_for_each_entry(req, &ep->queue, queue) {
298 if (--show_limit < 0) {
299 seq_puts(seq, "not showing more requests...\n");
300 break;
301 }
302
303 seq_printf(seq, "%c req %p: %d bytes @%p, ",
304 req == ep->req ? '*' : ' ',
305 req, req->req.length, req->req.buf);
306 seq_printf(seq, "%d done, res %d\n",
307 req->req.actual, req->req.status);
308 }
309
310 spin_unlock_irqrestore(&hsotg->lock, flags);
311
312 return 0;
313}
314
315static int ep_open(struct inode *inode, struct file *file)
316{
317 return single_open(file, ep_show, inode->i_private);
318}
319
320static const struct file_operations ep_fops = {
321 .owner = THIS_MODULE,
322 .open = ep_open,
323 .read = seq_read,
324 .llseek = seq_lseek,
325 .release = single_release,
326};
327
328
329
330
331
332
333
334
335
336
337static void dwc2_hsotg_create_debug(struct dwc2_hsotg *hsotg)
338{
339 struct dentry *root;
340 struct dentry *file;
341 unsigned int epidx;
342
343 root = hsotg->debug_root;
344
345
346
347 file = debugfs_create_file("state", 0444, root, hsotg, &state_fops);
348 if (IS_ERR(file))
349 dev_err(hsotg->dev, "%s: failed to create state\n", __func__);
350
351 file = debugfs_create_file("testmode", 0644, root, hsotg,
352 &testmode_fops);
353 if (IS_ERR(file))
354 dev_err(hsotg->dev, "%s: failed to create testmode\n",
355 __func__);
356
357 file = debugfs_create_file("fifo", 0444, root, hsotg, &fifo_fops);
358 if (IS_ERR(file))
359 dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__);
360
361
362 for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) {
363 struct dwc2_hsotg_ep *ep;
364
365 ep = hsotg->eps_out[epidx];
366 if (ep) {
367 file = debugfs_create_file(ep->name, 0444,
368 root, ep, &ep_fops);
369 if (IS_ERR(file))
370 dev_err(hsotg->dev, "failed to create %s debug file\n",
371 ep->name);
372 }
373 }
374
375 for (epidx = 1; epidx < hsotg->num_of_eps; epidx++) {
376 struct dwc2_hsotg_ep *ep;
377
378 ep = hsotg->eps_in[epidx];
379 if (ep) {
380 file = debugfs_create_file(ep->name, 0444,
381 root, ep, &ep_fops);
382 if (IS_ERR(file))
383 dev_err(hsotg->dev, "failed to create %s debug file\n",
384 ep->name);
385 }
386 }
387}
388#else
389static inline void dwc2_hsotg_create_debug(struct dwc2_hsotg *hsotg) {}
390#endif
391
392
393
394#define dump_register(nm) \
395{ \
396 .name = #nm, \
397 .offset = nm, \
398}
399
400static const struct debugfs_reg32 dwc2_regs[] = {
401
402
403
404
405
406
407 dump_register(GOTGCTL),
408 dump_register(GOTGINT),
409 dump_register(GAHBCFG),
410 dump_register(GUSBCFG),
411 dump_register(GRSTCTL),
412 dump_register(GINTSTS),
413 dump_register(GINTMSK),
414 dump_register(GRXSTSR),
415 dump_register(GRXSTSP),
416 dump_register(GRXFSIZ),
417 dump_register(GNPTXFSIZ),
418 dump_register(GNPTXSTS),
419 dump_register(GI2CCTL),
420 dump_register(GPVNDCTL),
421 dump_register(GGPIO),
422 dump_register(GUID),
423 dump_register(GSNPSID),
424 dump_register(GHWCFG1),
425 dump_register(GHWCFG2),
426 dump_register(GHWCFG3),
427 dump_register(GHWCFG4),
428 dump_register(GLPMCFG),
429 dump_register(GPWRDN),
430 dump_register(GDFIFOCFG),
431 dump_register(ADPCTL),
432 dump_register(HPTXFSIZ),
433 dump_register(DPTXFSIZN(1)),
434 dump_register(DPTXFSIZN(2)),
435 dump_register(DPTXFSIZN(3)),
436 dump_register(DPTXFSIZN(4)),
437 dump_register(DPTXFSIZN(5)),
438 dump_register(DPTXFSIZN(6)),
439 dump_register(DPTXFSIZN(7)),
440 dump_register(DPTXFSIZN(8)),
441 dump_register(DPTXFSIZN(9)),
442 dump_register(DPTXFSIZN(10)),
443 dump_register(DPTXFSIZN(11)),
444 dump_register(DPTXFSIZN(12)),
445 dump_register(DPTXFSIZN(13)),
446 dump_register(DPTXFSIZN(14)),
447 dump_register(DPTXFSIZN(15)),
448 dump_register(DCFG),
449 dump_register(DCTL),
450 dump_register(DSTS),
451 dump_register(DIEPMSK),
452 dump_register(DOEPMSK),
453 dump_register(DAINT),
454 dump_register(DAINTMSK),
455 dump_register(DTKNQR1),
456 dump_register(DTKNQR2),
457 dump_register(DTKNQR3),
458 dump_register(DTKNQR4),
459 dump_register(DVBUSDIS),
460 dump_register(DVBUSPULSE),
461 dump_register(DIEPCTL(0)),
462 dump_register(DIEPCTL(1)),
463 dump_register(DIEPCTL(2)),
464 dump_register(DIEPCTL(3)),
465 dump_register(DIEPCTL(4)),
466 dump_register(DIEPCTL(5)),
467 dump_register(DIEPCTL(6)),
468 dump_register(DIEPCTL(7)),
469 dump_register(DIEPCTL(8)),
470 dump_register(DIEPCTL(9)),
471 dump_register(DIEPCTL(10)),
472 dump_register(DIEPCTL(11)),
473 dump_register(DIEPCTL(12)),
474 dump_register(DIEPCTL(13)),
475 dump_register(DIEPCTL(14)),
476 dump_register(DIEPCTL(15)),
477 dump_register(DOEPCTL(0)),
478 dump_register(DOEPCTL(1)),
479 dump_register(DOEPCTL(2)),
480 dump_register(DOEPCTL(3)),
481 dump_register(DOEPCTL(4)),
482 dump_register(DOEPCTL(5)),
483 dump_register(DOEPCTL(6)),
484 dump_register(DOEPCTL(7)),
485 dump_register(DOEPCTL(8)),
486 dump_register(DOEPCTL(9)),
487 dump_register(DOEPCTL(10)),
488 dump_register(DOEPCTL(11)),
489 dump_register(DOEPCTL(12)),
490 dump_register(DOEPCTL(13)),
491 dump_register(DOEPCTL(14)),
492 dump_register(DOEPCTL(15)),
493 dump_register(DIEPINT(0)),
494 dump_register(DIEPINT(1)),
495 dump_register(DIEPINT(2)),
496 dump_register(DIEPINT(3)),
497 dump_register(DIEPINT(4)),
498 dump_register(DIEPINT(5)),
499 dump_register(DIEPINT(6)),
500 dump_register(DIEPINT(7)),
501 dump_register(DIEPINT(8)),
502 dump_register(DIEPINT(9)),
503 dump_register(DIEPINT(10)),
504 dump_register(DIEPINT(11)),
505 dump_register(DIEPINT(12)),
506 dump_register(DIEPINT(13)),
507 dump_register(DIEPINT(14)),
508 dump_register(DIEPINT(15)),
509 dump_register(DOEPINT(0)),
510 dump_register(DOEPINT(1)),
511 dump_register(DOEPINT(2)),
512 dump_register(DOEPINT(3)),
513 dump_register(DOEPINT(4)),
514 dump_register(DOEPINT(5)),
515 dump_register(DOEPINT(6)),
516 dump_register(DOEPINT(7)),
517 dump_register(DOEPINT(8)),
518 dump_register(DOEPINT(9)),
519 dump_register(DOEPINT(10)),
520 dump_register(DOEPINT(11)),
521 dump_register(DOEPINT(12)),
522 dump_register(DOEPINT(13)),
523 dump_register(DOEPINT(14)),
524 dump_register(DOEPINT(15)),
525 dump_register(DIEPTSIZ(0)),
526 dump_register(DIEPTSIZ(1)),
527 dump_register(DIEPTSIZ(2)),
528 dump_register(DIEPTSIZ(3)),
529 dump_register(DIEPTSIZ(4)),
530 dump_register(DIEPTSIZ(5)),
531 dump_register(DIEPTSIZ(6)),
532 dump_register(DIEPTSIZ(7)),
533 dump_register(DIEPTSIZ(8)),
534 dump_register(DIEPTSIZ(9)),
535 dump_register(DIEPTSIZ(10)),
536 dump_register(DIEPTSIZ(11)),
537 dump_register(DIEPTSIZ(12)),
538 dump_register(DIEPTSIZ(13)),
539 dump_register(DIEPTSIZ(14)),
540 dump_register(DIEPTSIZ(15)),
541 dump_register(DOEPTSIZ(0)),
542 dump_register(DOEPTSIZ(1)),
543 dump_register(DOEPTSIZ(2)),
544 dump_register(DOEPTSIZ(3)),
545 dump_register(DOEPTSIZ(4)),
546 dump_register(DOEPTSIZ(5)),
547 dump_register(DOEPTSIZ(6)),
548 dump_register(DOEPTSIZ(7)),
549 dump_register(DOEPTSIZ(8)),
550 dump_register(DOEPTSIZ(9)),
551 dump_register(DOEPTSIZ(10)),
552 dump_register(DOEPTSIZ(11)),
553 dump_register(DOEPTSIZ(12)),
554 dump_register(DOEPTSIZ(13)),
555 dump_register(DOEPTSIZ(14)),
556 dump_register(DOEPTSIZ(15)),
557 dump_register(DIEPDMA(0)),
558 dump_register(DIEPDMA(1)),
559 dump_register(DIEPDMA(2)),
560 dump_register(DIEPDMA(3)),
561 dump_register(DIEPDMA(4)),
562 dump_register(DIEPDMA(5)),
563 dump_register(DIEPDMA(6)),
564 dump_register(DIEPDMA(7)),
565 dump_register(DIEPDMA(8)),
566 dump_register(DIEPDMA(9)),
567 dump_register(DIEPDMA(10)),
568 dump_register(DIEPDMA(11)),
569 dump_register(DIEPDMA(12)),
570 dump_register(DIEPDMA(13)),
571 dump_register(DIEPDMA(14)),
572 dump_register(DIEPDMA(15)),
573 dump_register(DOEPDMA(0)),
574 dump_register(DOEPDMA(1)),
575 dump_register(DOEPDMA(2)),
576 dump_register(DOEPDMA(3)),
577 dump_register(DOEPDMA(4)),
578 dump_register(DOEPDMA(5)),
579 dump_register(DOEPDMA(6)),
580 dump_register(DOEPDMA(7)),
581 dump_register(DOEPDMA(8)),
582 dump_register(DOEPDMA(9)),
583 dump_register(DOEPDMA(10)),
584 dump_register(DOEPDMA(11)),
585 dump_register(DOEPDMA(12)),
586 dump_register(DOEPDMA(13)),
587 dump_register(DOEPDMA(14)),
588 dump_register(DOEPDMA(15)),
589 dump_register(DTXFSTS(0)),
590 dump_register(DTXFSTS(1)),
591 dump_register(DTXFSTS(2)),
592 dump_register(DTXFSTS(3)),
593 dump_register(DTXFSTS(4)),
594 dump_register(DTXFSTS(5)),
595 dump_register(DTXFSTS(6)),
596 dump_register(DTXFSTS(7)),
597 dump_register(DTXFSTS(8)),
598 dump_register(DTXFSTS(9)),
599 dump_register(DTXFSTS(10)),
600 dump_register(DTXFSTS(11)),
601 dump_register(DTXFSTS(12)),
602 dump_register(DTXFSTS(13)),
603 dump_register(DTXFSTS(14)),
604 dump_register(DTXFSTS(15)),
605 dump_register(PCGCTL),
606 dump_register(HCFG),
607 dump_register(HFIR),
608 dump_register(HFNUM),
609 dump_register(HPTXSTS),
610 dump_register(HAINT),
611 dump_register(HAINTMSK),
612 dump_register(HFLBADDR),
613 dump_register(HPRT0),
614 dump_register(HCCHAR(0)),
615 dump_register(HCCHAR(1)),
616 dump_register(HCCHAR(2)),
617 dump_register(HCCHAR(3)),
618 dump_register(HCCHAR(4)),
619 dump_register(HCCHAR(5)),
620 dump_register(HCCHAR(6)),
621 dump_register(HCCHAR(7)),
622 dump_register(HCCHAR(8)),
623 dump_register(HCCHAR(9)),
624 dump_register(HCCHAR(10)),
625 dump_register(HCCHAR(11)),
626 dump_register(HCCHAR(12)),
627 dump_register(HCCHAR(13)),
628 dump_register(HCCHAR(14)),
629 dump_register(HCCHAR(15)),
630 dump_register(HCSPLT(0)),
631 dump_register(HCSPLT(1)),
632 dump_register(HCSPLT(2)),
633 dump_register(HCSPLT(3)),
634 dump_register(HCSPLT(4)),
635 dump_register(HCSPLT(5)),
636 dump_register(HCSPLT(6)),
637 dump_register(HCSPLT(7)),
638 dump_register(HCSPLT(8)),
639 dump_register(HCSPLT(9)),
640 dump_register(HCSPLT(10)),
641 dump_register(HCSPLT(11)),
642 dump_register(HCSPLT(12)),
643 dump_register(HCSPLT(13)),
644 dump_register(HCSPLT(14)),
645 dump_register(HCSPLT(15)),
646 dump_register(HCINT(0)),
647 dump_register(HCINT(1)),
648 dump_register(HCINT(2)),
649 dump_register(HCINT(3)),
650 dump_register(HCINT(4)),
651 dump_register(HCINT(5)),
652 dump_register(HCINT(6)),
653 dump_register(HCINT(7)),
654 dump_register(HCINT(8)),
655 dump_register(HCINT(9)),
656 dump_register(HCINT(10)),
657 dump_register(HCINT(11)),
658 dump_register(HCINT(12)),
659 dump_register(HCINT(13)),
660 dump_register(HCINT(14)),
661 dump_register(HCINT(15)),
662 dump_register(HCINTMSK(0)),
663 dump_register(HCINTMSK(1)),
664 dump_register(HCINTMSK(2)),
665 dump_register(HCINTMSK(3)),
666 dump_register(HCINTMSK(4)),
667 dump_register(HCINTMSK(5)),
668 dump_register(HCINTMSK(6)),
669 dump_register(HCINTMSK(7)),
670 dump_register(HCINTMSK(8)),
671 dump_register(HCINTMSK(9)),
672 dump_register(HCINTMSK(10)),
673 dump_register(HCINTMSK(11)),
674 dump_register(HCINTMSK(12)),
675 dump_register(HCINTMSK(13)),
676 dump_register(HCINTMSK(14)),
677 dump_register(HCINTMSK(15)),
678 dump_register(HCTSIZ(0)),
679 dump_register(HCTSIZ(1)),
680 dump_register(HCTSIZ(2)),
681 dump_register(HCTSIZ(3)),
682 dump_register(HCTSIZ(4)),
683 dump_register(HCTSIZ(5)),
684 dump_register(HCTSIZ(6)),
685 dump_register(HCTSIZ(7)),
686 dump_register(HCTSIZ(8)),
687 dump_register(HCTSIZ(9)),
688 dump_register(HCTSIZ(10)),
689 dump_register(HCTSIZ(11)),
690 dump_register(HCTSIZ(12)),
691 dump_register(HCTSIZ(13)),
692 dump_register(HCTSIZ(14)),
693 dump_register(HCTSIZ(15)),
694 dump_register(HCDMA(0)),
695 dump_register(HCDMA(1)),
696 dump_register(HCDMA(2)),
697 dump_register(HCDMA(3)),
698 dump_register(HCDMA(4)),
699 dump_register(HCDMA(5)),
700 dump_register(HCDMA(6)),
701 dump_register(HCDMA(7)),
702 dump_register(HCDMA(8)),
703 dump_register(HCDMA(9)),
704 dump_register(HCDMA(10)),
705 dump_register(HCDMA(11)),
706 dump_register(HCDMA(12)),
707 dump_register(HCDMA(13)),
708 dump_register(HCDMA(14)),
709 dump_register(HCDMA(15)),
710 dump_register(HCDMAB(0)),
711 dump_register(HCDMAB(1)),
712 dump_register(HCDMAB(2)),
713 dump_register(HCDMAB(3)),
714 dump_register(HCDMAB(4)),
715 dump_register(HCDMAB(5)),
716 dump_register(HCDMAB(6)),
717 dump_register(HCDMAB(7)),
718 dump_register(HCDMAB(8)),
719 dump_register(HCDMAB(9)),
720 dump_register(HCDMAB(10)),
721 dump_register(HCDMAB(11)),
722 dump_register(HCDMAB(12)),
723 dump_register(HCDMAB(13)),
724 dump_register(HCDMAB(14)),
725 dump_register(HCDMAB(15)),
726};
727
728#define print_param(_seq, _ptr, _param) \
729seq_printf((_seq), "%-30s: %d\n", #_param, (_ptr)->_param)
730
731#define print_param_hex(_seq, _ptr, _param) \
732seq_printf((_seq), "%-30s: 0x%x\n", #_param, (_ptr)->_param)
733
734static int params_show(struct seq_file *seq, void *v)
735{
736 struct dwc2_hsotg *hsotg = seq->private;
737 struct dwc2_core_params *p = &hsotg->params;
738 int i;
739
740 print_param(seq, p, otg_cap);
741 print_param(seq, p, dma_desc_enable);
742 print_param(seq, p, dma_desc_fs_enable);
743 print_param(seq, p, speed);
744 print_param(seq, p, enable_dynamic_fifo);
745 print_param(seq, p, en_multiple_tx_fifo);
746 print_param(seq, p, host_rx_fifo_size);
747 print_param(seq, p, host_nperio_tx_fifo_size);
748 print_param(seq, p, host_perio_tx_fifo_size);
749 print_param(seq, p, max_transfer_size);
750 print_param(seq, p, max_packet_count);
751 print_param(seq, p, host_channels);
752 print_param(seq, p, phy_type);
753 print_param(seq, p, phy_utmi_width);
754 print_param(seq, p, phy_ulpi_ddr);
755 print_param(seq, p, phy_ulpi_ext_vbus);
756 print_param(seq, p, i2c_enable);
757 print_param(seq, p, ulpi_fs_ls);
758 print_param(seq, p, host_support_fs_ls_low_power);
759 print_param(seq, p, host_ls_low_power_phy_clk);
760 print_param(seq, p, ts_dline);
761 print_param(seq, p, reload_ctl);
762 print_param_hex(seq, p, ahbcfg);
763 print_param(seq, p, uframe_sched);
764 print_param(seq, p, external_id_pin_ctl);
765 print_param(seq, p, hibernation);
766 print_param(seq, p, host_dma);
767 print_param(seq, p, g_dma);
768 print_param(seq, p, g_dma_desc);
769 print_param(seq, p, g_rx_fifo_size);
770 print_param(seq, p, g_np_tx_fifo_size);
771
772 for (i = 0; i < MAX_EPS_CHANNELS; i++) {
773 char str[32];
774
775 snprintf(str, 32, "g_tx_fifo_size[%d]", i);
776 seq_printf(seq, "%-30s: %d\n", str, p->g_tx_fifo_size[i]);
777 }
778
779 return 0;
780}
781
782static int params_open(struct inode *inode, struct file *file)
783{
784 return single_open(file, params_show, inode->i_private);
785}
786
787static const struct file_operations params_fops = {
788 .owner = THIS_MODULE,
789 .open = params_open,
790 .read = seq_read,
791 .llseek = seq_lseek,
792 .release = single_release,
793};
794
795static int hw_params_show(struct seq_file *seq, void *v)
796{
797 struct dwc2_hsotg *hsotg = seq->private;
798 struct dwc2_hw_params *hw = &hsotg->hw_params;
799
800 print_param(seq, hw, op_mode);
801 print_param(seq, hw, arch);
802 print_param(seq, hw, dma_desc_enable);
803 print_param(seq, hw, enable_dynamic_fifo);
804 print_param(seq, hw, en_multiple_tx_fifo);
805 print_param(seq, hw, rx_fifo_size);
806 print_param(seq, hw, host_nperio_tx_fifo_size);
807 print_param(seq, hw, dev_nperio_tx_fifo_size);
808 print_param(seq, hw, host_perio_tx_fifo_size);
809 print_param(seq, hw, nperio_tx_q_depth);
810 print_param(seq, hw, host_perio_tx_q_depth);
811 print_param(seq, hw, dev_token_q_depth);
812 print_param(seq, hw, max_transfer_size);
813 print_param(seq, hw, max_packet_count);
814 print_param(seq, hw, host_channels);
815 print_param(seq, hw, hs_phy_type);
816 print_param(seq, hw, fs_phy_type);
817 print_param(seq, hw, i2c_enable);
818 print_param(seq, hw, num_dev_ep);
819 print_param(seq, hw, num_dev_perio_in_ep);
820 print_param(seq, hw, total_fifo_size);
821 print_param(seq, hw, power_optimized);
822 print_param(seq, hw, utmi_phy_data_width);
823 print_param_hex(seq, hw, snpsid);
824 print_param_hex(seq, hw, dev_ep_dirs);
825
826 return 0;
827}
828
829static int hw_params_open(struct inode *inode, struct file *file)
830{
831 return single_open(file, hw_params_show, inode->i_private);
832}
833
834static const struct file_operations hw_params_fops = {
835 .owner = THIS_MODULE,
836 .open = hw_params_open,
837 .read = seq_read,
838 .llseek = seq_lseek,
839 .release = single_release,
840};
841
842static int dr_mode_show(struct seq_file *seq, void *v)
843{
844 struct dwc2_hsotg *hsotg = seq->private;
845 const char *dr_mode = "";
846
847 device_property_read_string(hsotg->dev, "dr_mode", &dr_mode);
848 seq_printf(seq, "%s\n", dr_mode);
849 return 0;
850}
851
852static int dr_mode_open(struct inode *inode, struct file *file)
853{
854 return single_open(file, dr_mode_show, inode->i_private);
855}
856
857static const struct file_operations dr_mode_fops = {
858 .owner = THIS_MODULE,
859 .open = dr_mode_open,
860 .read = seq_read,
861 .llseek = seq_lseek,
862 .release = single_release,
863};
864
865int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
866{
867 int ret;
868 struct dentry *file;
869
870 hsotg->debug_root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
871 if (!hsotg->debug_root) {
872 ret = -ENOMEM;
873 goto err0;
874 }
875
876 file = debugfs_create_file("params", 0444,
877 hsotg->debug_root,
878 hsotg, ¶ms_fops);
879 if (IS_ERR(file))
880 dev_err(hsotg->dev, "%s: failed to create params\n", __func__);
881
882 file = debugfs_create_file("hw_params", 0444,
883 hsotg->debug_root,
884 hsotg, &hw_params_fops);
885 if (IS_ERR(file))
886 dev_err(hsotg->dev, "%s: failed to create hw_params\n",
887 __func__);
888
889 file = debugfs_create_file("dr_mode", 0444,
890 hsotg->debug_root,
891 hsotg, &dr_mode_fops);
892 if (IS_ERR(file))
893 dev_err(hsotg->dev, "%s: failed to create dr_mode\n", __func__);
894
895
896 dwc2_hsotg_create_debug(hsotg);
897
898 hsotg->regset = devm_kzalloc(hsotg->dev, sizeof(*hsotg->regset),
899 GFP_KERNEL);
900 if (!hsotg->regset) {
901 ret = -ENOMEM;
902 goto err1;
903 }
904
905 hsotg->regset->regs = dwc2_regs;
906 hsotg->regset->nregs = ARRAY_SIZE(dwc2_regs);
907 hsotg->regset->base = hsotg->regs;
908
909 file = debugfs_create_regset32("regdump", 0444, hsotg->debug_root,
910 hsotg->regset);
911 if (!file) {
912 ret = -ENOMEM;
913 goto err1;
914 }
915
916 return 0;
917err1:
918 debugfs_remove_recursive(hsotg->debug_root);
919err0:
920 return ret;
921}
922
923void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg)
924{
925 debugfs_remove_recursive(hsotg->debug_root);
926 hsotg->debug_root = NULL;
927}
928