diff options
Diffstat (limited to 'drivers/usb/dwc3/debugfs.c')
-rw-r--r-- | drivers/usb/dwc3/debugfs.c | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index fcfa91517ea1..433c97c15fc5 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c | |||
@@ -44,12 +44,12 @@ | |||
44 | #include <linux/debugfs.h> | 44 | #include <linux/debugfs.h> |
45 | #include <linux/seq_file.h> | 45 | #include <linux/seq_file.h> |
46 | #include <linux/delay.h> | 46 | #include <linux/delay.h> |
47 | 47 | #include <linux/uaccess.h> | |
48 | #include <asm/uaccess.h> | ||
49 | 48 | ||
50 | #include "core.h" | 49 | #include "core.h" |
51 | #include "gadget.h" | 50 | #include "gadget.h" |
52 | #include "io.h" | 51 | #include "io.h" |
52 | #include "debug.h" | ||
53 | 53 | ||
54 | #define dump_register(nm) \ | 54 | #define dump_register(nm) \ |
55 | { \ | 55 | { \ |
@@ -395,6 +395,75 @@ static const struct file_operations dwc3_regdump_fops = { | |||
395 | .release = single_release, | 395 | .release = single_release, |
396 | }; | 396 | }; |
397 | 397 | ||
398 | static int dwc3_mode_show(struct seq_file *s, void *unused) | ||
399 | { | ||
400 | struct dwc3 *dwc = s->private; | ||
401 | unsigned long flags; | ||
402 | u32 reg; | ||
403 | |||
404 | spin_lock_irqsave(&dwc->lock, flags); | ||
405 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | ||
406 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
407 | |||
408 | switch (DWC3_GCTL_PRTCAP(reg)) { | ||
409 | case DWC3_GCTL_PRTCAP_HOST: | ||
410 | seq_printf(s, "host\n"); | ||
411 | break; | ||
412 | case DWC3_GCTL_PRTCAP_DEVICE: | ||
413 | seq_printf(s, "device\n"); | ||
414 | break; | ||
415 | case DWC3_GCTL_PRTCAP_OTG: | ||
416 | seq_printf(s, "OTG\n"); | ||
417 | break; | ||
418 | default: | ||
419 | seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); | ||
420 | } | ||
421 | |||
422 | return 0; | ||
423 | } | ||
424 | |||
425 | static int dwc3_mode_open(struct inode *inode, struct file *file) | ||
426 | { | ||
427 | return single_open(file, dwc3_mode_show, inode->i_private); | ||
428 | } | ||
429 | |||
430 | static ssize_t dwc3_mode_write(struct file *file, | ||
431 | const char __user *ubuf, size_t count, loff_t *ppos) | ||
432 | { | ||
433 | struct seq_file *s = file->private_data; | ||
434 | struct dwc3 *dwc = s->private; | ||
435 | unsigned long flags; | ||
436 | u32 mode = 0; | ||
437 | char buf[32]; | ||
438 | |||
439 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) | ||
440 | return -EFAULT; | ||
441 | |||
442 | if (!strncmp(buf, "host", 4)) | ||
443 | mode |= DWC3_GCTL_PRTCAP_HOST; | ||
444 | |||
445 | if (!strncmp(buf, "device", 6)) | ||
446 | mode |= DWC3_GCTL_PRTCAP_DEVICE; | ||
447 | |||
448 | if (!strncmp(buf, "otg", 3)) | ||
449 | mode |= DWC3_GCTL_PRTCAP_OTG; | ||
450 | |||
451 | if (mode) { | ||
452 | spin_lock_irqsave(&dwc->lock, flags); | ||
453 | dwc3_set_mode(dwc, mode); | ||
454 | spin_unlock_irqrestore(&dwc->lock, flags); | ||
455 | } | ||
456 | return count; | ||
457 | } | ||
458 | |||
459 | static const struct file_operations dwc3_mode_fops = { | ||
460 | .open = dwc3_mode_open, | ||
461 | .write = dwc3_mode_write, | ||
462 | .read = seq_read, | ||
463 | .llseek = seq_lseek, | ||
464 | .release = single_release, | ||
465 | }; | ||
466 | |||
398 | int __devinit dwc3_debugfs_init(struct dwc3 *dwc) | 467 | int __devinit dwc3_debugfs_init(struct dwc3 *dwc) |
399 | { | 468 | { |
400 | struct dentry *root; | 469 | struct dentry *root; |
@@ -402,7 +471,7 @@ int __devinit dwc3_debugfs_init(struct dwc3 *dwc) | |||
402 | int ret; | 471 | int ret; |
403 | 472 | ||
404 | root = debugfs_create_dir(dev_name(dwc->dev), NULL); | 473 | root = debugfs_create_dir(dev_name(dwc->dev), NULL); |
405 | if (IS_ERR(root)){ | 474 | if (IS_ERR(root)) { |
406 | ret = PTR_ERR(root); | 475 | ret = PTR_ERR(root); |
407 | goto err0; | 476 | goto err0; |
408 | } | 477 | } |
@@ -415,6 +484,14 @@ int __devinit dwc3_debugfs_init(struct dwc3 *dwc) | |||
415 | ret = PTR_ERR(file); | 484 | ret = PTR_ERR(file); |
416 | goto err1; | 485 | goto err1; |
417 | } | 486 | } |
487 | |||
488 | file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, | ||
489 | dwc, &dwc3_mode_fops); | ||
490 | if (IS_ERR(file)) { | ||
491 | ret = PTR_ERR(file); | ||
492 | goto err1; | ||
493 | } | ||
494 | |||
418 | return 0; | 495 | return 0; |
419 | 496 | ||
420 | err1: | 497 | err1: |