aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci-hub.c
diff options
context:
space:
mode:
authorhuajun li <huajun.li.lee@gmail.com>2011-05-03 09:11:00 -0400
committerSarah Sharp <sarah.a.sharp@linux.intel.com>2011-05-12 15:54:22 -0400
commita0885924326f79e157847010a9aaf49b058b30dc (patch)
treea6ce2a417d3b9e921cdd0e5bc56ad1637e8500ba /drivers/usb/host/xhci-hub.c
parent3610ea5397b80822e417aaa0e706fd803fb05680 (diff)
xhci: move the common code to a function to get max ports and port array
There are several functions using same code to get max ports and port array, this patch moves the common code to a function in order to reuse them easily. Signed-off-by: Huajun Li <huajun.li.lee@gmail.com> Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Diffstat (limited to 'drivers/usb/host/xhci-hub.c')
-rw-r--r--drivers/usb/host/xhci-hub.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index a56963736018..0be788cc2fdb 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -376,11 +376,27 @@ static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
376 port_change_bit, wIndex, port_status); 376 port_change_bit, wIndex, port_status);
377} 377}
378 378
379static int xhci_get_ports(struct usb_hcd *hcd, __le32 __iomem ***port_array)
380{
381 int max_ports;
382 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
383
384 if (hcd->speed == HCD_USB3) {
385 max_ports = xhci->num_usb3_ports;
386 *port_array = xhci->usb3_ports;
387 } else {
388 max_ports = xhci->num_usb2_ports;
389 *port_array = xhci->usb2_ports;
390 }
391
392 return max_ports;
393}
394
379int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 395int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
380 u16 wIndex, char *buf, u16 wLength) 396 u16 wIndex, char *buf, u16 wLength)
381{ 397{
382 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 398 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
383 int ports; 399 int max_ports;
384 unsigned long flags; 400 unsigned long flags;
385 u32 temp, temp1, status; 401 u32 temp, temp1, status;
386 int retval = 0; 402 int retval = 0;
@@ -389,13 +405,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
389 struct xhci_bus_state *bus_state; 405 struct xhci_bus_state *bus_state;
390 u16 link_state = 0; 406 u16 link_state = 0;
391 407
392 if (hcd->speed == HCD_USB3) { 408 max_ports = xhci_get_ports(hcd, &port_array);
393 ports = xhci->num_usb3_ports;
394 port_array = xhci->usb3_ports;
395 } else {
396 ports = xhci->num_usb2_ports;
397 port_array = xhci->usb2_ports;
398 }
399 bus_state = &xhci->bus_state[hcd_index(hcd)]; 409 bus_state = &xhci->bus_state[hcd_index(hcd)];
400 410
401 spin_lock_irqsave(&xhci->lock, flags); 411 spin_lock_irqsave(&xhci->lock, flags);
@@ -420,7 +430,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
420 (struct usb_hub_descriptor *) buf); 430 (struct usb_hub_descriptor *) buf);
421 break; 431 break;
422 case GetPortStatus: 432 case GetPortStatus:
423 if (!wIndex || wIndex > ports) 433 if (!wIndex || wIndex > max_ports)
424 goto error; 434 goto error;
425 wIndex--; 435 wIndex--;
426 status = 0; 436 status = 0;
@@ -519,7 +529,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
519 if (wValue == USB_PORT_FEAT_LINK_STATE) 529 if (wValue == USB_PORT_FEAT_LINK_STATE)
520 link_state = (wIndex & 0xff00) >> 3; 530 link_state = (wIndex & 0xff00) >> 3;
521 wIndex &= 0xff; 531 wIndex &= 0xff;
522 if (!wIndex || wIndex > ports) 532 if (!wIndex || wIndex > max_ports)
523 goto error; 533 goto error;
524 wIndex--; 534 wIndex--;
525 temp = xhci_readl(xhci, port_array[wIndex]); 535 temp = xhci_readl(xhci, port_array[wIndex]);
@@ -637,7 +647,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
637 temp = xhci_readl(xhci, port_array[wIndex]); 647 temp = xhci_readl(xhci, port_array[wIndex]);
638 break; 648 break;
639 case ClearPortFeature: 649 case ClearPortFeature:
640 if (!wIndex || wIndex > ports) 650 if (!wIndex || wIndex > max_ports)
641 goto error; 651 goto error;
642 wIndex--; 652 wIndex--;
643 temp = xhci_readl(xhci, port_array[wIndex]); 653 temp = xhci_readl(xhci, port_array[wIndex]);
@@ -730,21 +740,15 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
730 u32 mask; 740 u32 mask;
731 int i, retval; 741 int i, retval;
732 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 742 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
733 int ports; 743 int max_ports;
734 __le32 __iomem **port_array; 744 __le32 __iomem **port_array;
735 struct xhci_bus_state *bus_state; 745 struct xhci_bus_state *bus_state;
736 746
737 if (hcd->speed == HCD_USB3) { 747 max_ports = xhci_get_ports(hcd, &port_array);
738 ports = xhci->num_usb3_ports;
739 port_array = xhci->usb3_ports;
740 } else {
741 ports = xhci->num_usb2_ports;
742 port_array = xhci->usb2_ports;
743 }
744 bus_state = &xhci->bus_state[hcd_index(hcd)]; 748 bus_state = &xhci->bus_state[hcd_index(hcd)];
745 749
746 /* Initial status is no changes */ 750 /* Initial status is no changes */
747 retval = (ports + 8) / 8; 751 retval = (max_ports + 8) / 8;
748 memset(buf, 0, retval); 752 memset(buf, 0, retval);
749 status = 0; 753 status = 0;
750 754
@@ -752,7 +756,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
752 756
753 spin_lock_irqsave(&xhci->lock, flags); 757 spin_lock_irqsave(&xhci->lock, flags);
754 /* For each port, did anything change? If so, set that bit in buf. */ 758 /* For each port, did anything change? If so, set that bit in buf. */
755 for (i = 0; i < ports; i++) { 759 for (i = 0; i < max_ports; i++) {
756 temp = xhci_readl(xhci, port_array[i]); 760 temp = xhci_readl(xhci, port_array[i]);
757 if (temp == 0xffffffff) { 761 if (temp == 0xffffffff) {
758 retval = -ENODEV; 762 retval = -ENODEV;
@@ -780,15 +784,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
780 struct xhci_bus_state *bus_state; 784 struct xhci_bus_state *bus_state;
781 unsigned long flags; 785 unsigned long flags;
782 786
783 if (hcd->speed == HCD_USB3) { 787 max_ports = xhci_get_ports(hcd, &port_array);
784 max_ports = xhci->num_usb3_ports;
785 port_array = xhci->usb3_ports;
786 xhci_dbg(xhci, "suspend USB 3.0 root hub\n");
787 } else {
788 max_ports = xhci->num_usb2_ports;
789 port_array = xhci->usb2_ports;
790 xhci_dbg(xhci, "suspend USB 2.0 root hub\n");
791 }
792 bus_state = &xhci->bus_state[hcd_index(hcd)]; 788 bus_state = &xhci->bus_state[hcd_index(hcd)];
793 789
794 spin_lock_irqsave(&xhci->lock, flags); 790 spin_lock_irqsave(&xhci->lock, flags);
@@ -873,15 +869,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
873 u32 temp; 869 u32 temp;
874 unsigned long flags; 870 unsigned long flags;
875 871
876 if (hcd->speed == HCD_USB3) { 872 max_ports = xhci_get_ports(hcd, &port_array);
877 max_ports = xhci->num_usb3_ports;
878 port_array = xhci->usb3_ports;
879 xhci_dbg(xhci, "resume USB 3.0 root hub\n");
880 } else {
881 max_ports = xhci->num_usb2_ports;
882 port_array = xhci->usb2_ports;
883 xhci_dbg(xhci, "resume USB 2.0 root hub\n");
884 }
885 bus_state = &xhci->bus_state[hcd_index(hcd)]; 873 bus_state = &xhci->bus_state[hcd_index(hcd)];
886 874
887 if (time_before(jiffies, bus_state->next_statechange)) 875 if (time_before(jiffies, bus_state->next_statechange))