xref: /openbmc/linux/drivers/usb/host/fhci-dbg.c (revision 5fd54ace)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
2236dd4d1SAnton Vorontsov /*
3236dd4d1SAnton Vorontsov  * Freescale QUICC Engine USB Host Controller Driver
4236dd4d1SAnton Vorontsov  *
5236dd4d1SAnton Vorontsov  * Copyright (c) Freescale Semicondutor, Inc. 2006.
6236dd4d1SAnton Vorontsov  *               Shlomi Gridish <gridish@freescale.com>
7236dd4d1SAnton Vorontsov  *               Jerry Huang <Chang-Ming.Huang@freescale.com>
8236dd4d1SAnton Vorontsov  * Copyright (c) Logic Product Development, Inc. 2007
9236dd4d1SAnton Vorontsov  *               Peter Barada <peterb@logicpd.com>
10236dd4d1SAnton Vorontsov  * Copyright (c) MontaVista Software, Inc. 2008.
11236dd4d1SAnton Vorontsov  *               Anton Vorontsov <avorontsov@ru.mvista.com>
12236dd4d1SAnton Vorontsov  *
13236dd4d1SAnton Vorontsov  * This program is free software; you can redistribute  it and/or modify it
14236dd4d1SAnton Vorontsov  * under  the terms of  the GNU General  Public License as published by the
15236dd4d1SAnton Vorontsov  * Free Software Foundation;  either version 2 of the  License, or (at your
16236dd4d1SAnton Vorontsov  * option) any later version.
17236dd4d1SAnton Vorontsov  */
18236dd4d1SAnton Vorontsov 
19236dd4d1SAnton Vorontsov #include <linux/kernel.h>
20236dd4d1SAnton Vorontsov #include <linux/errno.h>
21236dd4d1SAnton Vorontsov #include <linux/debugfs.h>
22236dd4d1SAnton Vorontsov #include <linux/seq_file.h>
23236dd4d1SAnton Vorontsov #include <linux/usb.h>
2427729aadSEric Lescouet #include <linux/usb/hcd.h>
25236dd4d1SAnton Vorontsov #include "fhci.h"
26236dd4d1SAnton Vorontsov 
27236dd4d1SAnton Vorontsov void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er)
28236dd4d1SAnton Vorontsov {
29236dd4d1SAnton Vorontsov 	int i;
30236dd4d1SAnton Vorontsov 
31236dd4d1SAnton Vorontsov 	if (usb_er == -1) {
32236dd4d1SAnton Vorontsov 		fhci->usb_irq_stat[12]++;
33236dd4d1SAnton Vorontsov 		return;
34236dd4d1SAnton Vorontsov 	}
35236dd4d1SAnton Vorontsov 
36236dd4d1SAnton Vorontsov 	for (i = 0; i < 12; ++i) {
37236dd4d1SAnton Vorontsov 		if (usb_er & (1 << i))
38236dd4d1SAnton Vorontsov 			fhci->usb_irq_stat[i]++;
39236dd4d1SAnton Vorontsov 	}
40236dd4d1SAnton Vorontsov }
41236dd4d1SAnton Vorontsov 
42236dd4d1SAnton Vorontsov static int fhci_dfs_regs_show(struct seq_file *s, void *v)
43236dd4d1SAnton Vorontsov {
44236dd4d1SAnton Vorontsov 	struct fhci_hcd *fhci = s->private;
45cf61fdb9SGuilherme Maciel Ferreira 	struct qe_usb_ctlr __iomem *regs = fhci->regs;
46236dd4d1SAnton Vorontsov 
47236dd4d1SAnton Vorontsov 	seq_printf(s,
48236dd4d1SAnton Vorontsov 		"mode: 0x%x\n" "addr: 0x%x\n"
49236dd4d1SAnton Vorontsov 		"command: 0x%x\n" "ep0: 0x%x\n"
50236dd4d1SAnton Vorontsov 		"event: 0x%x\n" "mask: 0x%x\n"
51236dd4d1SAnton Vorontsov 		"status: 0x%x\n" "SOF timer: %d\n"
52236dd4d1SAnton Vorontsov 		"frame number: %d\n"
53236dd4d1SAnton Vorontsov 		"lines status: 0x%x\n",
54cf61fdb9SGuilherme Maciel Ferreira 		in_8(&regs->usb_usmod), in_8(&regs->usb_usadr),
55cf61fdb9SGuilherme Maciel Ferreira 		in_8(&regs->usb_uscom), in_be16(&regs->usb_usep[0]),
56cf61fdb9SGuilherme Maciel Ferreira 		in_be16(&regs->usb_usber), in_be16(&regs->usb_usbmr),
57cf61fdb9SGuilherme Maciel Ferreira 		in_8(&regs->usb_usbs), in_be16(&regs->usb_ussft),
58cf61fdb9SGuilherme Maciel Ferreira 		in_be16(&regs->usb_usfrn),
59236dd4d1SAnton Vorontsov 		fhci_ioports_check_bus_state(fhci));
60236dd4d1SAnton Vorontsov 
61236dd4d1SAnton Vorontsov 	return 0;
62236dd4d1SAnton Vorontsov }
63236dd4d1SAnton Vorontsov 
64236dd4d1SAnton Vorontsov static int fhci_dfs_irq_stat_show(struct seq_file *s, void *v)
65236dd4d1SAnton Vorontsov {
66236dd4d1SAnton Vorontsov 	struct fhci_hcd *fhci = s->private;
67236dd4d1SAnton Vorontsov 	int *usb_irq_stat = fhci->usb_irq_stat;
68236dd4d1SAnton Vorontsov 
69236dd4d1SAnton Vorontsov 	seq_printf(s,
70236dd4d1SAnton Vorontsov 		"RXB: %d\n" "TXB: %d\n" "BSY: %d\n"
71236dd4d1SAnton Vorontsov 		"SOF: %d\n" "TXE0: %d\n" "TXE1: %d\n"
72236dd4d1SAnton Vorontsov 		"TXE2: %d\n" "TXE3: %d\n" "IDLE: %d\n"
73236dd4d1SAnton Vorontsov 		"RESET: %d\n" "SFT: %d\n" "MSF: %d\n"
74236dd4d1SAnton Vorontsov 		"IDLE_ONLY: %d\n",
75236dd4d1SAnton Vorontsov 		usb_irq_stat[0], usb_irq_stat[1], usb_irq_stat[2],
76236dd4d1SAnton Vorontsov 		usb_irq_stat[3], usb_irq_stat[4], usb_irq_stat[5],
77236dd4d1SAnton Vorontsov 		usb_irq_stat[6], usb_irq_stat[7], usb_irq_stat[8],
78236dd4d1SAnton Vorontsov 		usb_irq_stat[9], usb_irq_stat[10], usb_irq_stat[11],
79236dd4d1SAnton Vorontsov 		usb_irq_stat[12]);
80236dd4d1SAnton Vorontsov 
81236dd4d1SAnton Vorontsov 	return 0;
82236dd4d1SAnton Vorontsov }
83236dd4d1SAnton Vorontsov 
84236dd4d1SAnton Vorontsov static int fhci_dfs_regs_open(struct inode *inode, struct file *file)
85236dd4d1SAnton Vorontsov {
86236dd4d1SAnton Vorontsov 	return single_open(file, fhci_dfs_regs_show, inode->i_private);
87236dd4d1SAnton Vorontsov }
88236dd4d1SAnton Vorontsov 
89236dd4d1SAnton Vorontsov static int fhci_dfs_irq_stat_open(struct inode *inode, struct file *file)
90236dd4d1SAnton Vorontsov {
91236dd4d1SAnton Vorontsov 	return single_open(file, fhci_dfs_irq_stat_show, inode->i_private);
92236dd4d1SAnton Vorontsov }
93236dd4d1SAnton Vorontsov 
94236dd4d1SAnton Vorontsov static const struct file_operations fhci_dfs_regs_fops = {
95236dd4d1SAnton Vorontsov 	.open = fhci_dfs_regs_open,
96236dd4d1SAnton Vorontsov 	.read = seq_read,
97236dd4d1SAnton Vorontsov 	.llseek = seq_lseek,
98236dd4d1SAnton Vorontsov 	.release = single_release,
99236dd4d1SAnton Vorontsov };
100236dd4d1SAnton Vorontsov 
101236dd4d1SAnton Vorontsov static const struct file_operations fhci_dfs_irq_stat_fops = {
102236dd4d1SAnton Vorontsov 	.open = fhci_dfs_irq_stat_open,
103236dd4d1SAnton Vorontsov 	.read = seq_read,
104236dd4d1SAnton Vorontsov 	.llseek = seq_lseek,
105236dd4d1SAnton Vorontsov 	.release = single_release,
106236dd4d1SAnton Vorontsov };
107236dd4d1SAnton Vorontsov 
108236dd4d1SAnton Vorontsov void fhci_dfs_create(struct fhci_hcd *fhci)
109236dd4d1SAnton Vorontsov {
110236dd4d1SAnton Vorontsov 	struct device *dev = fhci_to_hcd(fhci)->self.controller;
111236dd4d1SAnton Vorontsov 
11266536ab3SGreg Kroah-Hartman 	fhci->dfs_root = debugfs_create_dir(dev_name(dev), usb_debug_root);
113236dd4d1SAnton Vorontsov 	if (!fhci->dfs_root) {
114236dd4d1SAnton Vorontsov 		WARN_ON(1);
115236dd4d1SAnton Vorontsov 		return;
116236dd4d1SAnton Vorontsov 	}
117236dd4d1SAnton Vorontsov 
118236dd4d1SAnton Vorontsov 	fhci->dfs_regs = debugfs_create_file("regs", S_IFREG | S_IRUGO,
119236dd4d1SAnton Vorontsov 		fhci->dfs_root, fhci, &fhci_dfs_regs_fops);
120236dd4d1SAnton Vorontsov 
121236dd4d1SAnton Vorontsov 	fhci->dfs_irq_stat = debugfs_create_file("irq_stat",
122236dd4d1SAnton Vorontsov 		S_IFREG | S_IRUGO, fhci->dfs_root, fhci,
123236dd4d1SAnton Vorontsov 		&fhci_dfs_irq_stat_fops);
124236dd4d1SAnton Vorontsov 
125236dd4d1SAnton Vorontsov 	WARN_ON(!fhci->dfs_regs || !fhci->dfs_irq_stat);
126236dd4d1SAnton Vorontsov }
127236dd4d1SAnton Vorontsov 
128236dd4d1SAnton Vorontsov void fhci_dfs_destroy(struct fhci_hcd *fhci)
129236dd4d1SAnton Vorontsov {
130236dd4d1SAnton Vorontsov 	if (!fhci->dfs_root)
131236dd4d1SAnton Vorontsov 		return;
132236dd4d1SAnton Vorontsov 
133236dd4d1SAnton Vorontsov 	debugfs_remove(fhci->dfs_irq_stat);
134236dd4d1SAnton Vorontsov 	debugfs_remove(fhci->dfs_regs);
135236dd4d1SAnton Vorontsov 	debugfs_remove(fhci->dfs_root);
136236dd4d1SAnton Vorontsov }
137