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