aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2010-12-15 14:56:29 -0500
committerSarah Sharp <sarah.a.sharp@linux.intel.com>2011-03-13 21:07:08 -0400
commit518e848ea8e2932ce18ce2daef8ad5f55a145f27 (patch)
tree623b2a258580f6fd28584d83c276c133ed423a15
parent1d5810b6923c76fc95e52d9d3491c91824c2f075 (diff)
xhci: Rename variables and reduce register reads.
The xhci_bus_suspend() and xhci_bus_resume() functions are a bit hard to read, because they have an ambiguously named variable "port". Rename it to "port_index". Introduce a new temporary variable, "max_ports" that holds the maximum number of roothub ports the host controller supports. This will reduce the number of register reads, and make it easy to change the maximum number of ports when there are two roothubs. Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
-rw-r--r--drivers/usb/host/xhci-hub.c41
-rw-r--r--drivers/usb/host/xhci-ring.c6
2 files changed, 25 insertions, 22 deletions
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 50e250ceee96..004a46557f9c 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -568,42 +568,44 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
568int xhci_bus_suspend(struct usb_hcd *hcd) 568int xhci_bus_suspend(struct usb_hcd *hcd)
569{ 569{
570 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 570 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
571 int port; 571 int max_ports, port_index;
572 unsigned long flags; 572 unsigned long flags;
573 573
574 xhci_dbg(xhci, "suspend root hub\n"); 574 xhci_dbg(xhci, "suspend root hub\n");
575 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
575 576
576 spin_lock_irqsave(&xhci->lock, flags); 577 spin_lock_irqsave(&xhci->lock, flags);
577 578
578 if (hcd->self.root_hub->do_remote_wakeup) { 579 if (hcd->self.root_hub->do_remote_wakeup) {
579 port = HCS_MAX_PORTS(xhci->hcs_params1); 580 port_index = max_ports;
580 while (port--) { 581 while (port_index--) {
581 if (xhci->resume_done[port] != 0) { 582 if (xhci->resume_done[port_index] != 0) {
582 spin_unlock_irqrestore(&xhci->lock, flags); 583 spin_unlock_irqrestore(&xhci->lock, flags);
583 xhci_dbg(xhci, "suspend failed because " 584 xhci_dbg(xhci, "suspend failed because "
584 "port %d is resuming\n", 585 "port %d is resuming\n",
585 port + 1); 586 port_index + 1);
586 return -EBUSY; 587 return -EBUSY;
587 } 588 }
588 } 589 }
589 } 590 }
590 591
591 port = HCS_MAX_PORTS(xhci->hcs_params1); 592 port_index = max_ports;
592 xhci->bus_suspended = 0; 593 xhci->bus_suspended = 0;
593 while (port--) { 594 while (port_index--) {
594 /* suspend the port if the port is not suspended */ 595 /* suspend the port if the port is not suspended */
595 u32 __iomem *addr; 596 u32 __iomem *addr;
596 u32 t1, t2; 597 u32 t1, t2;
597 int slot_id; 598 int slot_id;
598 599
599 addr = &xhci->op_regs->port_status_base + 600 addr = &xhci->op_regs->port_status_base +
600 NUM_PORT_REGS * (port & 0xff); 601 NUM_PORT_REGS * (port_index & 0xff);
601 t1 = xhci_readl(xhci, addr); 602 t1 = xhci_readl(xhci, addr);
602 t2 = xhci_port_state_to_neutral(t1); 603 t2 = xhci_port_state_to_neutral(t1);
603 604
604 if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { 605 if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) {
605 xhci_dbg(xhci, "port %d not suspended\n", port); 606 xhci_dbg(xhci, "port %d not suspended\n", port_index);
606 slot_id = xhci_find_slot_id_by_port(xhci, port + 1); 607 slot_id = xhci_find_slot_id_by_port(xhci,
608 port_index + 1);
607 if (slot_id) { 609 if (slot_id) {
608 spin_unlock_irqrestore(&xhci->lock, flags); 610 spin_unlock_irqrestore(&xhci->lock, flags);
609 xhci_stop_device(xhci, slot_id, 1); 611 xhci_stop_device(xhci, slot_id, 1);
@@ -611,7 +613,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
611 } 613 }
612 t2 &= ~PORT_PLS_MASK; 614 t2 &= ~PORT_PLS_MASK;
613 t2 |= PORT_LINK_STROBE | XDEV_U3; 615 t2 |= PORT_LINK_STROBE | XDEV_U3;
614 set_bit(port, &xhci->bus_suspended); 616 set_bit(port_index, &xhci->bus_suspended);
615 } 617 }
616 if (hcd->self.root_hub->do_remote_wakeup) { 618 if (hcd->self.root_hub->do_remote_wakeup) {
617 if (t1 & PORT_CONNECT) { 619 if (t1 & PORT_CONNECT) {
@@ -634,7 +636,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
634 u32 tmp; 636 u32 tmp;
635 637
636 addr = &xhci->op_regs->port_power_base + 638 addr = &xhci->op_regs->port_power_base +
637 NUM_PORT_REGS * (port & 0xff); 639 NUM_PORT_REGS * (port_index & 0xff);
638 tmp = xhci_readl(xhci, addr); 640 tmp = xhci_readl(xhci, addr);
639 tmp |= PORT_RWE; 641 tmp |= PORT_RWE;
640 xhci_writel(xhci, tmp, addr); 642 xhci_writel(xhci, tmp, addr);
@@ -649,11 +651,12 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
649int xhci_bus_resume(struct usb_hcd *hcd) 651int xhci_bus_resume(struct usb_hcd *hcd)
650{ 652{
651 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 653 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
652 int port; 654 int max_ports, port_index;
653 u32 temp; 655 u32 temp;
654 unsigned long flags; 656 unsigned long flags;
655 657
656 xhci_dbg(xhci, "resume root hub\n"); 658 xhci_dbg(xhci, "resume root hub\n");
659 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
657 660
658 if (time_before(jiffies, xhci->next_statechange)) 661 if (time_before(jiffies, xhci->next_statechange))
659 msleep(5); 662 msleep(5);
@@ -669,8 +672,8 @@ int xhci_bus_resume(struct usb_hcd *hcd)
669 temp &= ~CMD_EIE; 672 temp &= ~CMD_EIE;
670 xhci_writel(xhci, temp, &xhci->op_regs->command); 673 xhci_writel(xhci, temp, &xhci->op_regs->command);
671 674
672 port = HCS_MAX_PORTS(xhci->hcs_params1); 675 port_index = max_ports;
673 while (port--) { 676 while (port_index--) {
674 /* Check whether need resume ports. If needed 677 /* Check whether need resume ports. If needed
675 resume port and disable remote wakeup */ 678 resume port and disable remote wakeup */
676 u32 __iomem *addr; 679 u32 __iomem *addr;
@@ -678,13 +681,13 @@ int xhci_bus_resume(struct usb_hcd *hcd)
678 int slot_id; 681 int slot_id;
679 682
680 addr = &xhci->op_regs->port_status_base + 683 addr = &xhci->op_regs->port_status_base +
681 NUM_PORT_REGS * (port & 0xff); 684 NUM_PORT_REGS * (port_index & 0xff);
682 temp = xhci_readl(xhci, addr); 685 temp = xhci_readl(xhci, addr);
683 if (DEV_SUPERSPEED(temp)) 686 if (DEV_SUPERSPEED(temp))
684 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); 687 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
685 else 688 else
686 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 689 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
687 if (test_bit(port, &xhci->bus_suspended) && 690 if (test_bit(port_index, &xhci->bus_suspended) &&
688 (temp & PORT_PLS_MASK)) { 691 (temp & PORT_PLS_MASK)) {
689 if (DEV_SUPERSPEED(temp)) { 692 if (DEV_SUPERSPEED(temp)) {
690 temp = xhci_port_state_to_neutral(temp); 693 temp = xhci_port_state_to_neutral(temp);
@@ -707,7 +710,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
707 temp |= PORT_LINK_STROBE | XDEV_U0; 710 temp |= PORT_LINK_STROBE | XDEV_U0;
708 xhci_writel(xhci, temp, addr); 711 xhci_writel(xhci, temp, addr);
709 } 712 }
710 slot_id = xhci_find_slot_id_by_port(xhci, port + 1); 713 slot_id = xhci_find_slot_id_by_port(xhci, port_index + 1);
711 if (slot_id) 714 if (slot_id)
712 xhci_ring_device(xhci, slot_id); 715 xhci_ring_device(xhci, slot_id);
713 } else 716 } else
@@ -719,7 +722,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
719 u32 tmp; 722 u32 tmp;
720 723
721 addr = &xhci->op_regs->port_power_base + 724 addr = &xhci->op_regs->port_power_base +
722 NUM_PORT_REGS * (port & 0xff); 725 NUM_PORT_REGS * (port_index & 0xff);
723 tmp = xhci_readl(xhci, addr); 726 tmp = xhci_readl(xhci, addr);
724 tmp &= ~PORT_RWE; 727 tmp &= ~PORT_RWE;
725 xhci_writel(xhci, tmp, addr); 728 xhci_writel(xhci, tmp, addr);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index b36d3b003fee..3264d6275bf2 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1163,7 +1163,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1163 u32 port_id; 1163 u32 port_id;
1164 u32 temp, temp1; 1164 u32 temp, temp1;
1165 u32 __iomem *addr; 1165 u32 __iomem *addr;
1166 int ports; 1166 int max_ports;
1167 int slot_id; 1167 int slot_id;
1168 1168
1169 /* Port status change events always have a successful completion code */ 1169 /* Port status change events always have a successful completion code */
@@ -1174,8 +1174,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
1174 port_id = GET_PORT_ID(event->generic.field[0]); 1174 port_id = GET_PORT_ID(event->generic.field[0]);
1175 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id); 1175 xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id);
1176 1176
1177 ports = HCS_MAX_PORTS(xhci->hcs_params1); 1177 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1178 if ((port_id <= 0) || (port_id > ports)) { 1178 if ((port_id <= 0) || (port_id > max_ports)) {
1179 xhci_warn(xhci, "Invalid port id %d\n", port_id); 1179 xhci_warn(xhci, "Invalid port id %d\n", port_id);
1180 goto cleanup; 1180 goto cleanup;
1181 } 1181 }