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