blob: bba76af0c0c6d7107c08c60e966194e778c24c0f [file] [log] [blame]
Felipe Balbi7f7f9e22010-03-12 10:29:11 +02001/*
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>
Felipe Balbi7f7f9e22010-03-12 10:29:11 +020037#include <linux/init.h>
38#include <linux/list.h>
39#include <linux/kobject.h>
40#include <linux/platform_device.h>
41#include <linux/io.h>
42#include <linux/debugfs.h>
43#include <linux/seq_file.h>
44
45#ifdef CONFIG_ARM
46#include <mach/hardware.h>
47#include <mach/memory.h>
48#include <asm/mach-types.h>
49#endif
50
51#include <asm/uaccess.h>
52
53#include "musb_core.h"
54#include "musb_debug.h"
55
56#ifdef CONFIG_ARCH_DAVINCI
57#include "davinci.h"
58#endif
59
60struct musb_register_map {
61 char *name;
62 unsigned offset;
63 unsigned size;
64};
65
66static const struct musb_register_map musb_regmap[] = {
67 { "FAddr", 0x00, 8 },
68 { "Power", 0x01, 8 },
69 { "Frame", 0x0c, 16 },
70 { "Index", 0x0e, 8 },
71 { "Testmode", 0x0f, 8 },
72 { "TxMaxPp", 0x10, 16 },
73 { "TxCSRp", 0x12, 16 },
74 { "RxMaxPp", 0x14, 16 },
75 { "RxCSR", 0x16, 16 },
76 { "RxCount", 0x18, 16 },
77 { "ConfigData", 0x1f, 8 },
78 { "DevCtl", 0x60, 8 },
79 { "MISC", 0x61, 8 },
80 { "TxFIFOsz", 0x62, 8 },
81 { "RxFIFOsz", 0x63, 8 },
82 { "TxFIFOadd", 0x64, 16 },
83 { "RxFIFOadd", 0x66, 16 },
84 { "VControl", 0x68, 32 },
85 { "HWVers", 0x6C, 16 },
86 { "EPInfo", 0x78, 8 },
87 { "RAMInfo", 0x79, 8 },
88 { "LinkInfo", 0x7A, 8 },
89 { "VPLen", 0x7B, 8 },
90 { "HS_EOF1", 0x7C, 8 },
91 { "FS_EOF1", 0x7D, 8 },
92 { "LS_EOF1", 0x7E, 8 },
93 { "SOFT_RST", 0x7F, 8 },
94 { "DMA_CNTLch0", 0x204, 16 },
95 { "DMA_ADDRch0", 0x208, 16 },
96 { "DMA_COUNTch0", 0x20C, 16 },
97 { "DMA_CNTLch1", 0x214, 16 },
98 { "DMA_ADDRch1", 0x218, 16 },
99 { "DMA_COUNTch1", 0x21C, 16 },
100 { "DMA_CNTLch2", 0x224, 16 },
101 { "DMA_ADDRch2", 0x228, 16 },
102 { "DMA_COUNTch2", 0x22C, 16 },
103 { "DMA_CNTLch3", 0x234, 16 },
104 { "DMA_ADDRch3", 0x238, 16 },
105 { "DMA_COUNTch3", 0x23C, 16 },
106 { "DMA_CNTLch4", 0x244, 16 },
107 { "DMA_ADDRch4", 0x248, 16 },
108 { "DMA_COUNTch4", 0x24C, 16 },
109 { "DMA_CNTLch5", 0x254, 16 },
110 { "DMA_ADDRch5", 0x258, 16 },
111 { "DMA_COUNTch5", 0x25C, 16 },
112 { "DMA_CNTLch6", 0x264, 16 },
113 { "DMA_ADDRch6", 0x268, 16 },
114 { "DMA_COUNTch6", 0x26C, 16 },
115 { "DMA_CNTLch7", 0x274, 16 },
116 { "DMA_ADDRch7", 0x278, 16 },
117 { "DMA_COUNTch7", 0x27C, 16 },
118 { } /* Terminating Entry */
119};
120
121static struct dentry *musb_debugfs_root;
122
123static int musb_regdump_show(struct seq_file *s, void *unused)
124{
125 struct musb *musb = s->private;
126 unsigned i;
127
128 seq_printf(s, "MUSB (M)HDRC Register Dump\n");
129
130 for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
131 switch (musb_regmap[i].size) {
132 case 8:
133 seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
134 musb_readb(musb->mregs, musb_regmap[i].offset));
135 break;
136 case 16:
137 seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
138 musb_readw(musb->mregs, musb_regmap[i].offset));
139 break;
140 case 32:
141 seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
142 musb_readl(musb->mregs, musb_regmap[i].offset));
143 break;
144 }
145 }
146
147 return 0;
148}
149
150static int musb_regdump_open(struct inode *inode, struct file *file)
151{
152 return single_open(file, musb_regdump_show, inode->i_private);
153}
154
155static int musb_test_mode_show(struct seq_file *s, void *unused)
156{
157 struct musb *musb = s->private;
158 unsigned test;
159
160 test = musb_readb(musb->mregs, MUSB_TESTMODE);
161
162 if (test & MUSB_TEST_FORCE_HOST)
163 seq_printf(s, "force host\n");
164
165 if (test & MUSB_TEST_FIFO_ACCESS)
166 seq_printf(s, "fifo access\n");
167
168 if (test & MUSB_TEST_FORCE_FS)
169 seq_printf(s, "force full-speed\n");
170
171 if (test & MUSB_TEST_FORCE_HS)
172 seq_printf(s, "force high-speed\n");
173
174 if (test & MUSB_TEST_PACKET)
175 seq_printf(s, "test packet\n");
176
177 if (test & MUSB_TEST_K)
178 seq_printf(s, "test K\n");
179
180 if (test & MUSB_TEST_J)
181 seq_printf(s, "test J\n");
182
183 if (test & MUSB_TEST_SE0_NAK)
184 seq_printf(s, "test SE0 NAK\n");
185
186 return 0;
187}
188
189static const struct file_operations musb_regdump_fops = {
190 .open = musb_regdump_open,
191 .read = seq_read,
192 .llseek = seq_lseek,
193 .release = single_release,
194};
195
196static int musb_test_mode_open(struct inode *inode, struct file *file)
197{
198 file->private_data = inode->i_private;
199
200 return single_open(file, musb_test_mode_show, inode->i_private);
201}
202
203static ssize_t musb_test_mode_write(struct file *file,
204 const char __user *ubuf, size_t count, loff_t *ppos)
205{
206 struct musb *musb = file->private_data;
207 u8 test = 0;
208 char buf[18];
209
210 memset(buf, 0x00, sizeof(buf));
211
212 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
213 return -EFAULT;
214
215 if (!strncmp(buf, "force host", 9))
216 test = MUSB_TEST_FORCE_HOST;
217
218 if (!strncmp(buf, "fifo access", 11))
219 test = MUSB_TEST_FIFO_ACCESS;
220
221 if (!strncmp(buf, "force full-speed", 15))
222 test = MUSB_TEST_FORCE_FS;
223
224 if (!strncmp(buf, "force high-speed", 15))
225 test = MUSB_TEST_FORCE_HS;
226
227 if (!strncmp(buf, "test packet", 10)) {
228 test = MUSB_TEST_PACKET;
229 musb_load_testpacket(musb);
230 }
231
232 if (!strncmp(buf, "test K", 6))
233 test = MUSB_TEST_K;
234
235 if (!strncmp(buf, "test J", 6))
236 test = MUSB_TEST_J;
237
238 if (!strncmp(buf, "test SE0 NAK", 12))
239 test = MUSB_TEST_SE0_NAK;
240
241 musb_writeb(musb->mregs, MUSB_TESTMODE, test);
242
243 return count;
244}
245
246static const struct file_operations musb_test_mode_fops = {
247 .open = musb_test_mode_open,
248 .write = musb_test_mode_write,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = single_release,
252};
253
254int __init musb_init_debugfs(struct musb *musb)
255{
256 struct dentry *root;
257 struct dentry *file;
258 int ret;
259
260 root = debugfs_create_dir("musb", NULL);
261 if (IS_ERR(root)) {
262 ret = PTR_ERR(root);
263 goto err0;
264 }
265
266 file = debugfs_create_file("regdump", S_IRUGO, root, musb,
267 &musb_regdump_fops);
268 if (IS_ERR(file)) {
269 ret = PTR_ERR(file);
270 goto err1;
271 }
272
273 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
274 root, musb, &musb_test_mode_fops);
275 if (IS_ERR(file)) {
276 ret = PTR_ERR(file);
277 goto err1;
278 }
279
280 musb_debugfs_root = root;
281
282 return 0;
283
284err1:
285 debugfs_remove_recursive(root);
286
287err0:
288 return ret;
289}
290
Felipe Balbib0f9da72010-03-25 13:25:18 +0200291void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
Felipe Balbi7f7f9e22010-03-12 10:29:11 +0200292{
293 debugfs_remove_recursive(musb_debugfs_root);
294}