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

xhci: debugfs: add debugfs interface to enable compliance mode for a port

Enable compliance transition for a port by writing "compliance" to the
ports portsc file in debugfs.
port must be "Not-connected" and Link must be in RxDetect state to enable
compliance mode.

Only needed for host that have CTC flag set.
Allows state transitioning to compliance at 1st LFPS timeout.

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
87a03802 65475023

+38 -1
+38 -1
drivers/usb/host/xhci-debugfs.c
··· 8 8 */ 9 9 10 10 #include <linux/slab.h> 11 + #include <linux/uaccess.h> 11 12 12 13 #include "xhci.h" 13 14 #include "xhci-debugfs.h" ··· 352 351 return single_open(file, xhci_portsc_show, inode->i_private); 353 352 } 354 353 354 + static ssize_t xhci_port_write(struct file *file, const char __user *ubuf, 355 + size_t count, loff_t *ppos) 356 + { 357 + struct seq_file *s = file->private_data; 358 + struct xhci_port *port = s->private; 359 + struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd); 360 + char buf[32]; 361 + u32 portsc; 362 + unsigned long flags; 363 + 364 + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 365 + return -EFAULT; 366 + 367 + if (!strncmp(buf, "compliance", 10)) { 368 + /* If CTC is clear, compliance is enabled by default */ 369 + if (!HCC2_CTC(xhci->hcc_params2)) 370 + return count; 371 + spin_lock_irqsave(&xhci->lock, flags); 372 + /* compliance mode can only be enabled on ports in RxDetect */ 373 + portsc = readl(port->addr); 374 + if ((portsc & PORT_PLS_MASK) != XDEV_RXDETECT) { 375 + spin_unlock_irqrestore(&xhci->lock, flags); 376 + return -EPERM; 377 + } 378 + portsc = xhci_port_state_to_neutral(portsc); 379 + portsc &= ~PORT_PLS_MASK; 380 + portsc |= PORT_LINK_STROBE | XDEV_COMP_MODE; 381 + writel(portsc, port->addr); 382 + spin_unlock_irqrestore(&xhci->lock, flags); 383 + } else { 384 + return -EINVAL; 385 + } 386 + return count; 387 + } 388 + 355 389 static const struct file_operations port_fops = { 356 390 .open = xhci_port_open, 391 + .write = xhci_port_write, 357 392 .read = seq_read, 358 393 .llseek = seq_lseek, 359 394 .release = single_release, ··· 528 491 num_ports + 1); 529 492 dir = debugfs_create_dir(port_name, parent); 530 493 port = &xhci->hw_ports[num_ports]; 531 - debugfs_create_file("portsc", 0444, dir, port, &port_fops); 494 + debugfs_create_file("portsc", 0644, dir, port, &port_fops); 532 495 } 533 496 } 534 497