xref: /openbmc/linux/drivers/usb/musb/musb_debugfs.c (revision 615c36f5)
1 /*
2  * MUSB OTG driver debugfs support
3  *
4  * Copyright 2010 Nokia Corporation
5  * Contact: Felipe Balbi <felipe.balbi@nokia.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
24  * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/init.h>
38 #include <linux/list.h>
39 #include <linux/platform_device.h>
40 #include <linux/io.h>
41 #include <linux/debugfs.h>
42 #include <linux/seq_file.h>
43 
44 #include <asm/uaccess.h>
45 
46 #include "musb_core.h"
47 #include "musb_debug.h"
48 
49 #ifdef CONFIG_ARCH_DAVINCI
50 #include "davinci.h"
51 #endif
52 
53 struct musb_register_map {
54 	char			*name;
55 	unsigned		offset;
56 	unsigned		size;
57 };
58 
59 static const struct musb_register_map musb_regmap[] = {
60 	{ "FAddr",		0x00,	8 },
61 	{ "Power",		0x01,	8 },
62 	{ "Frame",		0x0c,	16 },
63 	{ "Index",		0x0e,	8 },
64 	{ "Testmode",		0x0f,	8 },
65 	{ "TxMaxPp",		0x10,	16 },
66 	{ "TxCSRp",		0x12,	16 },
67 	{ "RxMaxPp",		0x14,	16 },
68 	{ "RxCSR",		0x16,	16 },
69 	{ "RxCount",		0x18,	16 },
70 	{ "ConfigData",		0x1f,	8 },
71 	{ "DevCtl",		0x60,	8 },
72 	{ "MISC",		0x61,	8 },
73 	{ "TxFIFOsz",		0x62,	8 },
74 	{ "RxFIFOsz",		0x63,	8 },
75 	{ "TxFIFOadd",		0x64,	16 },
76 	{ "RxFIFOadd",		0x66,	16 },
77 	{ "VControl",		0x68,	32 },
78 	{ "HWVers",		0x6C,	16 },
79 	{ "EPInfo",		0x78,	8 },
80 	{ "RAMInfo",		0x79,	8 },
81 	{ "LinkInfo",		0x7A,	8 },
82 	{ "VPLen",		0x7B,	8 },
83 	{ "HS_EOF1",		0x7C,	8 },
84 	{ "FS_EOF1",		0x7D,	8 },
85 	{ "LS_EOF1",		0x7E,	8 },
86 	{ "SOFT_RST",		0x7F,	8 },
87 	{ "DMA_CNTLch0",	0x204,	16 },
88 	{ "DMA_ADDRch0",	0x208,	32 },
89 	{ "DMA_COUNTch0",	0x20C,	32 },
90 	{ "DMA_CNTLch1",	0x214,	16 },
91 	{ "DMA_ADDRch1",	0x218,	32 },
92 	{ "DMA_COUNTch1",	0x21C,	32 },
93 	{ "DMA_CNTLch2",	0x224,	16 },
94 	{ "DMA_ADDRch2",	0x228,	32 },
95 	{ "DMA_COUNTch2",	0x22C,	32 },
96 	{ "DMA_CNTLch3",	0x234,	16 },
97 	{ "DMA_ADDRch3",	0x238,	32 },
98 	{ "DMA_COUNTch3",	0x23C,	32 },
99 	{ "DMA_CNTLch4",	0x244,	16 },
100 	{ "DMA_ADDRch4",	0x248,	32 },
101 	{ "DMA_COUNTch4",	0x24C,	32 },
102 	{ "DMA_CNTLch5",	0x254,	16 },
103 	{ "DMA_ADDRch5",	0x258,	32 },
104 	{ "DMA_COUNTch5",	0x25C,	32 },
105 	{ "DMA_CNTLch6",	0x264,	16 },
106 	{ "DMA_ADDRch6",	0x268,	32 },
107 	{ "DMA_COUNTch6",	0x26C,	32 },
108 	{ "DMA_CNTLch7",	0x274,	16 },
109 	{ "DMA_ADDRch7",	0x278,	32 },
110 	{ "DMA_COUNTch7",	0x27C,	32 },
111 	{  }	/* Terminating Entry */
112 };
113 
114 static struct dentry *musb_debugfs_root;
115 
116 static int musb_regdump_show(struct seq_file *s, void *unused)
117 {
118 	struct musb		*musb = s->private;
119 	unsigned		i;
120 
121 	seq_printf(s, "MUSB (M)HDRC Register Dump\n");
122 
123 	for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
124 		switch (musb_regmap[i].size) {
125 		case 8:
126 			seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
127 					musb_readb(musb->mregs, musb_regmap[i].offset));
128 			break;
129 		case 16:
130 			seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
131 					musb_readw(musb->mregs, musb_regmap[i].offset));
132 			break;
133 		case 32:
134 			seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
135 					musb_readl(musb->mregs, musb_regmap[i].offset));
136 			break;
137 		}
138 	}
139 
140 	return 0;
141 }
142 
143 static int musb_regdump_open(struct inode *inode, struct file *file)
144 {
145 	return single_open(file, musb_regdump_show, inode->i_private);
146 }
147 
148 static int musb_test_mode_show(struct seq_file *s, void *unused)
149 {
150 	struct musb		*musb = s->private;
151 	unsigned		test;
152 
153 	test = musb_readb(musb->mregs, MUSB_TESTMODE);
154 
155 	if (test & MUSB_TEST_FORCE_HOST)
156 		seq_printf(s, "force host\n");
157 
158 	if (test & MUSB_TEST_FIFO_ACCESS)
159 		seq_printf(s, "fifo access\n");
160 
161 	if (test & MUSB_TEST_FORCE_FS)
162 		seq_printf(s, "force full-speed\n");
163 
164 	if (test & MUSB_TEST_FORCE_HS)
165 		seq_printf(s, "force high-speed\n");
166 
167 	if (test & MUSB_TEST_PACKET)
168 		seq_printf(s, "test packet\n");
169 
170 	if (test & MUSB_TEST_K)
171 		seq_printf(s, "test K\n");
172 
173 	if (test & MUSB_TEST_J)
174 		seq_printf(s, "test J\n");
175 
176 	if (test & MUSB_TEST_SE0_NAK)
177 		seq_printf(s, "test SE0 NAK\n");
178 
179 	return 0;
180 }
181 
182 static const struct file_operations musb_regdump_fops = {
183 	.open			= musb_regdump_open,
184 	.read			= seq_read,
185 	.llseek			= seq_lseek,
186 	.release		= single_release,
187 };
188 
189 static int musb_test_mode_open(struct inode *inode, struct file *file)
190 {
191 	return single_open(file, musb_test_mode_show, inode->i_private);
192 }
193 
194 static ssize_t musb_test_mode_write(struct file *file,
195 		const char __user *ubuf, size_t count, loff_t *ppos)
196 {
197 	struct seq_file		*s = file->private_data;
198 	struct musb		*musb = s->private;
199 	u8			test = 0;
200 	char			buf[18];
201 
202 	memset(buf, 0x00, sizeof(buf));
203 
204 	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
205 		return -EFAULT;
206 
207 	if (!strncmp(buf, "force host", 9))
208 		test = MUSB_TEST_FORCE_HOST;
209 
210 	if (!strncmp(buf, "fifo access", 11))
211 		test = MUSB_TEST_FIFO_ACCESS;
212 
213 	if (!strncmp(buf, "force full-speed", 15))
214 		test = MUSB_TEST_FORCE_FS;
215 
216 	if (!strncmp(buf, "force high-speed", 15))
217 		test = MUSB_TEST_FORCE_HS;
218 
219 	if (!strncmp(buf, "test packet", 10)) {
220 		test = MUSB_TEST_PACKET;
221 		musb_load_testpacket(musb);
222 	}
223 
224 	if (!strncmp(buf, "test K", 6))
225 		test = MUSB_TEST_K;
226 
227 	if (!strncmp(buf, "test J", 6))
228 		test = MUSB_TEST_J;
229 
230 	if (!strncmp(buf, "test SE0 NAK", 12))
231 		test = MUSB_TEST_SE0_NAK;
232 
233 	musb_writeb(musb->mregs, MUSB_TESTMODE, test);
234 
235 	return count;
236 }
237 
238 static const struct file_operations musb_test_mode_fops = {
239 	.open			= musb_test_mode_open,
240 	.write			= musb_test_mode_write,
241 	.read			= seq_read,
242 	.llseek			= seq_lseek,
243 	.release		= single_release,
244 };
245 
246 int __init musb_init_debugfs(struct musb *musb)
247 {
248 	struct dentry		*root;
249 	struct dentry		*file;
250 	int			ret;
251 
252 	root = debugfs_create_dir("musb", NULL);
253 	if (IS_ERR(root)) {
254 		ret = PTR_ERR(root);
255 		goto err0;
256 	}
257 
258 	file = debugfs_create_file("regdump", S_IRUGO, root, musb,
259 			&musb_regdump_fops);
260 	if (IS_ERR(file)) {
261 		ret = PTR_ERR(file);
262 		goto err1;
263 	}
264 
265 	file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
266 			root, musb, &musb_test_mode_fops);
267 	if (IS_ERR(file)) {
268 		ret = PTR_ERR(file);
269 		goto err1;
270 	}
271 
272 	musb_debugfs_root = root;
273 
274 	return 0;
275 
276 err1:
277 	debugfs_remove_recursive(root);
278 
279 err0:
280 	return ret;
281 }
282 
283 void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
284 {
285 	debugfs_remove_recursive(musb_debugfs_root);
286 }
287