1 /** 2 * debugfs.c - DesignWare USB3 DRD Controller DebugFS file 3 * 4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 * 6 * Authors: Felipe Balbi <balbi@ti.com>, 7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions, and the following disclaimer, 14 * without modification. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The names of the above-listed copyright holders may not be used 19 * to endorse or promote products derived from this software without 20 * specific prior written permission. 21 * 22 * ALTERNATIVELY, this software may be distributed under the terms of the 23 * GNU General Public License ("GPL") version 2, as published by the Free 24 * Software Foundation. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <linux/kernel.h> 40 #include <linux/slab.h> 41 #include <linux/ptrace.h> 42 #include <linux/types.h> 43 #include <linux/spinlock.h> 44 #include <linux/debugfs.h> 45 #include <linux/seq_file.h> 46 #include <linux/delay.h> 47 48 #include <asm/uaccess.h> 49 50 #include "core.h" 51 #include "gadget.h" 52 #include "io.h" 53 54 struct dwc3_register { 55 const char *name; 56 u32 offset; 57 }; 58 59 #define dump_register(nm) \ 60 { \ 61 .name = __stringify(nm), \ 62 .offset = DWC3_ ##nm, \ 63 } 64 65 static const struct dwc3_register dwc3_regs[] = { 66 dump_register(GSBUSCFG0), 67 dump_register(GSBUSCFG1), 68 dump_register(GTXTHRCFG), 69 dump_register(GRXTHRCFG), 70 dump_register(GCTL), 71 dump_register(GEVTEN), 72 dump_register(GSTS), 73 dump_register(GSNPSID), 74 dump_register(GGPIO), 75 dump_register(GUID), 76 dump_register(GUCTL), 77 dump_register(GBUSERRADDR0), 78 dump_register(GBUSERRADDR1), 79 dump_register(GPRTBIMAP0), 80 dump_register(GPRTBIMAP1), 81 dump_register(GHWPARAMS0), 82 dump_register(GHWPARAMS1), 83 dump_register(GHWPARAMS2), 84 dump_register(GHWPARAMS3), 85 dump_register(GHWPARAMS4), 86 dump_register(GHWPARAMS5), 87 dump_register(GHWPARAMS6), 88 dump_register(GHWPARAMS7), 89 dump_register(GDBGFIFOSPACE), 90 dump_register(GDBGLTSSM), 91 dump_register(GPRTBIMAP_HS0), 92 dump_register(GPRTBIMAP_HS1), 93 dump_register(GPRTBIMAP_FS0), 94 dump_register(GPRTBIMAP_FS1), 95 96 dump_register(GUSB2PHYCFG(0)), 97 dump_register(GUSB2PHYCFG(1)), 98 dump_register(GUSB2PHYCFG(2)), 99 dump_register(GUSB2PHYCFG(3)), 100 dump_register(GUSB2PHYCFG(4)), 101 dump_register(GUSB2PHYCFG(5)), 102 dump_register(GUSB2PHYCFG(6)), 103 dump_register(GUSB2PHYCFG(7)), 104 dump_register(GUSB2PHYCFG(8)), 105 dump_register(GUSB2PHYCFG(9)), 106 dump_register(GUSB2PHYCFG(10)), 107 dump_register(GUSB2PHYCFG(11)), 108 dump_register(GUSB2PHYCFG(12)), 109 dump_register(GUSB2PHYCFG(13)), 110 dump_register(GUSB2PHYCFG(14)), 111 dump_register(GUSB2PHYCFG(15)), 112 113 dump_register(GUSB2I2CCTL(0)), 114 dump_register(GUSB2I2CCTL(1)), 115 dump_register(GUSB2I2CCTL(2)), 116 dump_register(GUSB2I2CCTL(3)), 117 dump_register(GUSB2I2CCTL(4)), 118 dump_register(GUSB2I2CCTL(5)), 119 dump_register(GUSB2I2CCTL(6)), 120 dump_register(GUSB2I2CCTL(7)), 121 dump_register(GUSB2I2CCTL(8)), 122 dump_register(GUSB2I2CCTL(9)), 123 dump_register(GUSB2I2CCTL(10)), 124 dump_register(GUSB2I2CCTL(11)), 125 dump_register(GUSB2I2CCTL(12)), 126 dump_register(GUSB2I2CCTL(13)), 127 dump_register(GUSB2I2CCTL(14)), 128 dump_register(GUSB2I2CCTL(15)), 129 130 dump_register(GUSB2PHYACC(0)), 131 dump_register(GUSB2PHYACC(1)), 132 dump_register(GUSB2PHYACC(2)), 133 dump_register(GUSB2PHYACC(3)), 134 dump_register(GUSB2PHYACC(4)), 135 dump_register(GUSB2PHYACC(5)), 136 dump_register(GUSB2PHYACC(6)), 137 dump_register(GUSB2PHYACC(7)), 138 dump_register(GUSB2PHYACC(8)), 139 dump_register(GUSB2PHYACC(9)), 140 dump_register(GUSB2PHYACC(10)), 141 dump_register(GUSB2PHYACC(11)), 142 dump_register(GUSB2PHYACC(12)), 143 dump_register(GUSB2PHYACC(13)), 144 dump_register(GUSB2PHYACC(14)), 145 dump_register(GUSB2PHYACC(15)), 146 147 dump_register(GUSB3PIPECTL(0)), 148 dump_register(GUSB3PIPECTL(1)), 149 dump_register(GUSB3PIPECTL(2)), 150 dump_register(GUSB3PIPECTL(3)), 151 dump_register(GUSB3PIPECTL(4)), 152 dump_register(GUSB3PIPECTL(5)), 153 dump_register(GUSB3PIPECTL(6)), 154 dump_register(GUSB3PIPECTL(7)), 155 dump_register(GUSB3PIPECTL(8)), 156 dump_register(GUSB3PIPECTL(9)), 157 dump_register(GUSB3PIPECTL(10)), 158 dump_register(GUSB3PIPECTL(11)), 159 dump_register(GUSB3PIPECTL(12)), 160 dump_register(GUSB3PIPECTL(13)), 161 dump_register(GUSB3PIPECTL(14)), 162 dump_register(GUSB3PIPECTL(15)), 163 164 dump_register(GTXFIFOSIZ(0)), 165 dump_register(GTXFIFOSIZ(1)), 166 dump_register(GTXFIFOSIZ(2)), 167 dump_register(GTXFIFOSIZ(3)), 168 dump_register(GTXFIFOSIZ(4)), 169 dump_register(GTXFIFOSIZ(5)), 170 dump_register(GTXFIFOSIZ(6)), 171 dump_register(GTXFIFOSIZ(7)), 172 dump_register(GTXFIFOSIZ(8)), 173 dump_register(GTXFIFOSIZ(9)), 174 dump_register(GTXFIFOSIZ(10)), 175 dump_register(GTXFIFOSIZ(11)), 176 dump_register(GTXFIFOSIZ(12)), 177 dump_register(GTXFIFOSIZ(13)), 178 dump_register(GTXFIFOSIZ(14)), 179 dump_register(GTXFIFOSIZ(15)), 180 dump_register(GTXFIFOSIZ(16)), 181 dump_register(GTXFIFOSIZ(17)), 182 dump_register(GTXFIFOSIZ(18)), 183 dump_register(GTXFIFOSIZ(19)), 184 dump_register(GTXFIFOSIZ(20)), 185 dump_register(GTXFIFOSIZ(21)), 186 dump_register(GTXFIFOSIZ(22)), 187 dump_register(GTXFIFOSIZ(23)), 188 dump_register(GTXFIFOSIZ(24)), 189 dump_register(GTXFIFOSIZ(25)), 190 dump_register(GTXFIFOSIZ(26)), 191 dump_register(GTXFIFOSIZ(27)), 192 dump_register(GTXFIFOSIZ(28)), 193 dump_register(GTXFIFOSIZ(29)), 194 dump_register(GTXFIFOSIZ(30)), 195 dump_register(GTXFIFOSIZ(31)), 196 197 dump_register(GRXFIFOSIZ(0)), 198 dump_register(GRXFIFOSIZ(1)), 199 dump_register(GRXFIFOSIZ(2)), 200 dump_register(GRXFIFOSIZ(3)), 201 dump_register(GRXFIFOSIZ(4)), 202 dump_register(GRXFIFOSIZ(5)), 203 dump_register(GRXFIFOSIZ(6)), 204 dump_register(GRXFIFOSIZ(7)), 205 dump_register(GRXFIFOSIZ(8)), 206 dump_register(GRXFIFOSIZ(9)), 207 dump_register(GRXFIFOSIZ(10)), 208 dump_register(GRXFIFOSIZ(11)), 209 dump_register(GRXFIFOSIZ(12)), 210 dump_register(GRXFIFOSIZ(13)), 211 dump_register(GRXFIFOSIZ(14)), 212 dump_register(GRXFIFOSIZ(15)), 213 dump_register(GRXFIFOSIZ(16)), 214 dump_register(GRXFIFOSIZ(17)), 215 dump_register(GRXFIFOSIZ(18)), 216 dump_register(GRXFIFOSIZ(19)), 217 dump_register(GRXFIFOSIZ(20)), 218 dump_register(GRXFIFOSIZ(21)), 219 dump_register(GRXFIFOSIZ(22)), 220 dump_register(GRXFIFOSIZ(23)), 221 dump_register(GRXFIFOSIZ(24)), 222 dump_register(GRXFIFOSIZ(25)), 223 dump_register(GRXFIFOSIZ(26)), 224 dump_register(GRXFIFOSIZ(27)), 225 dump_register(GRXFIFOSIZ(28)), 226 dump_register(GRXFIFOSIZ(29)), 227 dump_register(GRXFIFOSIZ(30)), 228 dump_register(GRXFIFOSIZ(31)), 229 230 dump_register(GEVNTADRLO(0)), 231 dump_register(GEVNTADRHI(0)), 232 dump_register(GEVNTSIZ(0)), 233 dump_register(GEVNTCOUNT(0)), 234 235 dump_register(GHWPARAMS8), 236 dump_register(DCFG), 237 dump_register(DCTL), 238 dump_register(DEVTEN), 239 dump_register(DSTS), 240 dump_register(DGCMDPAR), 241 dump_register(DGCMD), 242 dump_register(DALEPENA), 243 244 dump_register(DEPCMDPAR2(0)), 245 dump_register(DEPCMDPAR2(1)), 246 dump_register(DEPCMDPAR2(2)), 247 dump_register(DEPCMDPAR2(3)), 248 dump_register(DEPCMDPAR2(4)), 249 dump_register(DEPCMDPAR2(5)), 250 dump_register(DEPCMDPAR2(6)), 251 dump_register(DEPCMDPAR2(7)), 252 dump_register(DEPCMDPAR2(8)), 253 dump_register(DEPCMDPAR2(9)), 254 dump_register(DEPCMDPAR2(10)), 255 dump_register(DEPCMDPAR2(11)), 256 dump_register(DEPCMDPAR2(12)), 257 dump_register(DEPCMDPAR2(13)), 258 dump_register(DEPCMDPAR2(14)), 259 dump_register(DEPCMDPAR2(15)), 260 dump_register(DEPCMDPAR2(16)), 261 dump_register(DEPCMDPAR2(17)), 262 dump_register(DEPCMDPAR2(18)), 263 dump_register(DEPCMDPAR2(19)), 264 dump_register(DEPCMDPAR2(20)), 265 dump_register(DEPCMDPAR2(21)), 266 dump_register(DEPCMDPAR2(22)), 267 dump_register(DEPCMDPAR2(23)), 268 dump_register(DEPCMDPAR2(24)), 269 dump_register(DEPCMDPAR2(25)), 270 dump_register(DEPCMDPAR2(26)), 271 dump_register(DEPCMDPAR2(27)), 272 dump_register(DEPCMDPAR2(28)), 273 dump_register(DEPCMDPAR2(29)), 274 dump_register(DEPCMDPAR2(30)), 275 dump_register(DEPCMDPAR2(31)), 276 277 dump_register(DEPCMDPAR1(0)), 278 dump_register(DEPCMDPAR1(1)), 279 dump_register(DEPCMDPAR1(2)), 280 dump_register(DEPCMDPAR1(3)), 281 dump_register(DEPCMDPAR1(4)), 282 dump_register(DEPCMDPAR1(5)), 283 dump_register(DEPCMDPAR1(6)), 284 dump_register(DEPCMDPAR1(7)), 285 dump_register(DEPCMDPAR1(8)), 286 dump_register(DEPCMDPAR1(9)), 287 dump_register(DEPCMDPAR1(10)), 288 dump_register(DEPCMDPAR1(11)), 289 dump_register(DEPCMDPAR1(12)), 290 dump_register(DEPCMDPAR1(13)), 291 dump_register(DEPCMDPAR1(14)), 292 dump_register(DEPCMDPAR1(15)), 293 dump_register(DEPCMDPAR1(16)), 294 dump_register(DEPCMDPAR1(17)), 295 dump_register(DEPCMDPAR1(18)), 296 dump_register(DEPCMDPAR1(19)), 297 dump_register(DEPCMDPAR1(20)), 298 dump_register(DEPCMDPAR1(21)), 299 dump_register(DEPCMDPAR1(22)), 300 dump_register(DEPCMDPAR1(23)), 301 dump_register(DEPCMDPAR1(24)), 302 dump_register(DEPCMDPAR1(25)), 303 dump_register(DEPCMDPAR1(26)), 304 dump_register(DEPCMDPAR1(27)), 305 dump_register(DEPCMDPAR1(28)), 306 dump_register(DEPCMDPAR1(29)), 307 dump_register(DEPCMDPAR1(30)), 308 dump_register(DEPCMDPAR1(31)), 309 310 dump_register(DEPCMDPAR0(0)), 311 dump_register(DEPCMDPAR0(1)), 312 dump_register(DEPCMDPAR0(2)), 313 dump_register(DEPCMDPAR0(3)), 314 dump_register(DEPCMDPAR0(4)), 315 dump_register(DEPCMDPAR0(5)), 316 dump_register(DEPCMDPAR0(6)), 317 dump_register(DEPCMDPAR0(7)), 318 dump_register(DEPCMDPAR0(8)), 319 dump_register(DEPCMDPAR0(9)), 320 dump_register(DEPCMDPAR0(10)), 321 dump_register(DEPCMDPAR0(11)), 322 dump_register(DEPCMDPAR0(12)), 323 dump_register(DEPCMDPAR0(13)), 324 dump_register(DEPCMDPAR0(14)), 325 dump_register(DEPCMDPAR0(15)), 326 dump_register(DEPCMDPAR0(16)), 327 dump_register(DEPCMDPAR0(17)), 328 dump_register(DEPCMDPAR0(18)), 329 dump_register(DEPCMDPAR0(19)), 330 dump_register(DEPCMDPAR0(20)), 331 dump_register(DEPCMDPAR0(21)), 332 dump_register(DEPCMDPAR0(22)), 333 dump_register(DEPCMDPAR0(23)), 334 dump_register(DEPCMDPAR0(24)), 335 dump_register(DEPCMDPAR0(25)), 336 dump_register(DEPCMDPAR0(26)), 337 dump_register(DEPCMDPAR0(27)), 338 dump_register(DEPCMDPAR0(28)), 339 dump_register(DEPCMDPAR0(29)), 340 dump_register(DEPCMDPAR0(30)), 341 dump_register(DEPCMDPAR0(31)), 342 343 dump_register(DEPCMD(0)), 344 dump_register(DEPCMD(1)), 345 dump_register(DEPCMD(2)), 346 dump_register(DEPCMD(3)), 347 dump_register(DEPCMD(4)), 348 dump_register(DEPCMD(5)), 349 dump_register(DEPCMD(6)), 350 dump_register(DEPCMD(7)), 351 dump_register(DEPCMD(8)), 352 dump_register(DEPCMD(9)), 353 dump_register(DEPCMD(10)), 354 dump_register(DEPCMD(11)), 355 dump_register(DEPCMD(12)), 356 dump_register(DEPCMD(13)), 357 dump_register(DEPCMD(14)), 358 dump_register(DEPCMD(15)), 359 dump_register(DEPCMD(16)), 360 dump_register(DEPCMD(17)), 361 dump_register(DEPCMD(18)), 362 dump_register(DEPCMD(19)), 363 dump_register(DEPCMD(20)), 364 dump_register(DEPCMD(21)), 365 dump_register(DEPCMD(22)), 366 dump_register(DEPCMD(23)), 367 dump_register(DEPCMD(24)), 368 dump_register(DEPCMD(25)), 369 dump_register(DEPCMD(26)), 370 dump_register(DEPCMD(27)), 371 dump_register(DEPCMD(28)), 372 dump_register(DEPCMD(29)), 373 dump_register(DEPCMD(30)), 374 dump_register(DEPCMD(31)), 375 376 dump_register(OCFG), 377 dump_register(OCTL), 378 dump_register(OEVTEN), 379 dump_register(OSTS), 380 }; 381 382 static int dwc3_regdump_show(struct seq_file *s, void *unused) 383 { 384 struct dwc3 *dwc = s->private; 385 int i; 386 387 seq_printf(s, "DesignWare USB3 Core Register Dump\n"); 388 389 for (i = 0; i < ARRAY_SIZE(dwc3_regs); i++) { 390 seq_printf(s, "%-20s : %08x\n", dwc3_regs[i].name, 391 dwc3_readl(dwc->regs, dwc3_regs[i].offset)); 392 } 393 394 return 0; 395 } 396 397 static int dwc3_regdump_open(struct inode *inode, struct file *file) 398 { 399 return single_open(file, dwc3_regdump_show, inode->i_private); 400 } 401 402 static const struct file_operations dwc3_regdump_fops = { 403 .open = dwc3_regdump_open, 404 .read = seq_read, 405 .release = single_release, 406 }; 407 408 int __devinit dwc3_debugfs_init(struct dwc3 *dwc) 409 { 410 struct dentry *root; 411 struct dentry *file; 412 int ret; 413 414 root = debugfs_create_dir(dev_name(dwc->dev), NULL); 415 if (IS_ERR(root)){ 416 ret = PTR_ERR(root); 417 goto err0; 418 } 419 420 dwc->root = root; 421 422 file = debugfs_create_file("regdump", S_IRUGO, root, dwc, 423 &dwc3_regdump_fops); 424 if (IS_ERR(file)) { 425 ret = PTR_ERR(file); 426 goto err1; 427 } 428 return 0; 429 430 err1: 431 debugfs_remove_recursive(root); 432 433 err0: 434 return ret; 435 } 436 437 void __devexit dwc3_debugfs_exit(struct dwc3 *dwc) 438 { 439 debugfs_remove_recursive(dwc->root); 440 dwc->root = NULL; 441 } 442