Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xhci: debugfs: add usb ports to xhci debugfs

Add ports/portxx/portsc for each xHC hardware usb port to debugfs.
Showing the content of the port status and control register for
each port (PORTSC)

Portxx is numbered starting from 1 for historical reasons to better
match port numbering shown by lsusb and other places.

Ports in debugfs are in the order XHC controller has them,
In most cases USB2 ports come first, followed by USB3 ports.
i.e. USB2 ports are port01-portxx, and USB3 portxx-portmax.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Nyman and committed by
Greg Kroah-Hartman
65475023 07f76190

+48
+48
drivers/usb/host/xhci-debugfs.c
··· 333 333 .release = single_release, 334 334 }; 335 335 336 + 337 + 338 + static int xhci_portsc_show(struct seq_file *s, void *unused) 339 + { 340 + struct xhci_port *port = s->private; 341 + u32 portsc; 342 + 343 + portsc = readl(port->addr); 344 + seq_printf(s, "%s\n", xhci_decode_portsc(portsc)); 345 + 346 + return 0; 347 + } 348 + 349 + static int xhci_port_open(struct inode *inode, struct file *file) 350 + { 351 + return single_open(file, xhci_portsc_show, inode->i_private); 352 + } 353 + 354 + static const struct file_operations port_fops = { 355 + .open = xhci_port_open, 356 + .read = seq_read, 357 + .llseek = seq_lseek, 358 + .release = single_release, 359 + }; 360 + 336 361 static void xhci_debugfs_create_files(struct xhci_hcd *xhci, 337 362 struct xhci_file_map *files, 338 363 size_t nentries, void *data, ··· 474 449 dev->debugfs_private = NULL; 475 450 } 476 451 452 + static void xhci_debugfs_create_ports(struct xhci_hcd *xhci, 453 + struct dentry *parent) 454 + { 455 + unsigned int num_ports; 456 + char port_name[8]; 457 + struct xhci_port *port; 458 + struct dentry *dir; 459 + 460 + num_ports = HCS_MAX_PORTS(xhci->hcs_params1); 461 + 462 + parent = debugfs_create_dir("ports", parent); 463 + 464 + while (num_ports--) { 465 + scnprintf(port_name, sizeof(port_name), "port%02d", 466 + num_ports + 1); 467 + dir = debugfs_create_dir(port_name, parent); 468 + port = &xhci->hw_ports[num_ports]; 469 + debugfs_create_file("portsc", 0444, dir, port, &port_fops); 470 + } 471 + } 472 + 477 473 void xhci_debugfs_init(struct xhci_hcd *xhci) 478 474 { 479 475 struct device *dev = xhci_to_hcd(xhci)->self.controller; ··· 543 497 xhci->debugfs_root); 544 498 545 499 xhci->debugfs_slots = debugfs_create_dir("devices", xhci->debugfs_root); 500 + 501 + xhci_debugfs_create_ports(xhci, xhci->debugfs_root); 546 502 } 547 503 548 504 void xhci_debugfs_exit(struct xhci_hcd *xhci)