24 #include <asm/unaligned.h>
28 #define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
29 #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
30 PORT_RC | PORT_PLC | PORT_PE)
51 static void xhci_common_hub_descriptor(
struct xhci_hcd *xhci,
75 static void xhci_usb2_hub_descriptor(
struct usb_hcd *hcd,
struct xhci_hcd *xhci,
80 __u8 port_removable[(USB_MAXCHILDREN + 1 + 7) / 8];
86 xhci_common_hub_descriptor(xhci, desc, ports);
88 temp = 1 + (ports / 8);
94 memset(port_removable, 0,
sizeof(port_removable));
95 for (i = 0; i < ports; i++) {
96 portsc = xhci_readl(xhci, xhci->
usb2_ports[i]);
104 port_removable[(i + 1) / 8] |= 1 << ((i + 1) % 8);
122 for (i = 0; i < (ports + 1 + 7) / 8; i++)
128 static void xhci_usb3_hub_descriptor(
struct usb_hcd *hcd,
struct xhci_hcd *xhci,
137 xhci_common_hub_descriptor(xhci, desc, ports);
149 for (i = 0; i < ports; i++) {
150 portsc = xhci_readl(xhci, xhci->
usb3_ports[i]);
151 if (portsc & PORT_DEV_REMOVE)
152 port_removable |= 1 << (i + 1);
158 static void xhci_hub_descriptor(
struct usb_hcd *hcd,
struct xhci_hcd *xhci,
162 if (hcd->speed == HCD_USB3)
163 xhci_usb3_hub_descriptor(hcd, xhci, desc);
165 xhci_usb2_hub_descriptor(hcd, xhci, desc);
169 static unsigned int xhci_port_speed(
unsigned int port_status)
190 #define XHCI_PORT_RO ((1<<0) | (1<<3) | (0xf<<10) | (1<<30))
196 #define XHCI_PORT_RWS ((0xf<<5) | (1<<9) | (0x3<<14) | (0x7<<25))
201 #define XHCI_PORT_RW1S ((1<<4))
209 #define XHCI_PORT_RW1CS ((1<<1) | (0x7f<<17))
214 #define XHCI_PORT_RW ((1<<16))
219 #define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28))
250 speed = xhci->
devs[
i]->udev->speed;
252 && xhci->
devs[i]->fake_port == port) {
267 static int xhci_stop_device(
struct xhci_hcd *xhci,
int slot_id,
int suspend)
277 virt_dev = xhci->
devs[slot_id];
280 xhci_dbg(xhci,
"Couldn't allocate command structure.\n");
286 if (virt_dev->
eps[i].ring && virt_dev->
eps[i].ring->dequeue)
293 spin_unlock_irqrestore(&xhci->
lock, flags);
298 USB_CTRL_SET_TIMEOUT);
300 xhci_warn(xhci,
"%s while waiting for stop endpoint command\n",
301 timeleft == 0 ?
"Timeout" :
"Signal");
308 spin_unlock_irqrestore(&xhci->
lock, flags);
310 goto command_cleanup;
326 if (xhci->
devs[slot_id]->eps[i].ring &&
327 xhci->
devs[slot_id]->eps[i].ring->dequeue)
333 static void xhci_disable_port(
struct usb_hcd *hcd,
struct xhci_hcd *xhci,
337 if (hcd->speed == HCD_USB3) {
338 xhci_dbg(xhci,
"Ignoring request to disable "
339 "SuperSpeed port.\n");
344 xhci_writel(xhci, port_status |
PORT_PE, addr);
345 port_status = xhci_readl(xhci, addr);
346 xhci_dbg(xhci,
"disable port, actual port %d status = 0x%x\n",
347 wIndex, port_status);
353 char *port_change_bit;
359 port_change_bit =
"reset";
363 port_change_bit =
"warm(BH) reset";
367 port_change_bit =
"connect";
371 port_change_bit =
"over-current";
375 port_change_bit =
"enable/disable";
379 port_change_bit =
"suspend/resume";
383 port_change_bit =
"link state";
390 xhci_writel(xhci, port_status | status, addr);
391 port_status = xhci_readl(xhci, addr);
392 xhci_dbg(xhci,
"clear port %s change, actual port %d status = 0x%x\n",
393 port_change_bit, wIndex, port_status);
396 static int xhci_get_ports(
struct usb_hcd *hcd,
__le32 __iomem ***port_array)
399 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
401 if (hcd->speed == HCD_USB3) {
417 temp = xhci_readl(xhci, port_array[port_id]);
421 xhci_writel(xhci, temp, port_array[port_id]);
424 static void xhci_set_remote_wake_mask(
struct xhci_hcd *xhci,
429 temp = xhci_readl(xhci, port_array[port_id]);
447 xhci_writel(xhci, temp, port_array[port_id]);
452 int port_id,
u32 port_bit)
456 temp = xhci_readl(xhci, port_array[port_id]);
457 if (temp & port_bit) {
460 xhci_writel(xhci, temp, port_array[port_id]);
465 static void xhci_hub_report_link_state(
u32 *status,
u32 status_reg)
531 xhci_dbg(xhci,
"All USB3 ports have entered U0 already!\n");
532 xhci_dbg(xhci,
"Compliance Mode Recovery Timer Deleted.\n");
540 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
552 max_ports = xhci_get_ports(hcd, &port_array);
553 bus_state = &xhci->
bus_state[hcd_index(hcd)];
561 case GetHubDescriptor:
566 if (hcd->speed == HCD_USB3 &&
569 xhci_dbg(xhci,
"Wrong hub descriptor type for "
570 "USB 3.0 roothub.\n");
573 xhci_hub_descriptor(hcd, xhci,
580 if (hcd->speed != HCD_USB3)
586 temp = xhci_readl(xhci, &xhci->
cap_regs->hcs_params3);
591 temp = xhci_readl(xhci, &xhci->
cap_regs->hcc_params);
595 spin_unlock_irqrestore(&xhci->
lock, flags);
598 if (!wIndex || wIndex > max_ports)
602 temp = xhci_readl(xhci, port_array[wIndex]);
603 if (temp == 0xffffffff) {
607 xhci_dbg(xhci,
"get port status, actual port %d status = 0x%x\n", wIndex, temp);
619 if (hcd->speed == HCD_USB3) {
626 if (hcd->speed != HCD_USB3) {
627 if ((temp & PORT_PLS_MASK) ==
XDEV_U3
637 xhci_dbg(xhci,
"Resume USB2 port %d\n",
643 xhci_dbg(xhci,
"set port %d resume\n",
648 xhci_dbg(xhci,
"slot_id is zero\n");
664 if ((temp & PORT_PLS_MASK) ==
XDEV_U0
668 if (hcd->speed != HCD_USB3)
673 status |= xhci_port_speed(temp);
682 if (hcd->speed == HCD_USB3)
688 if (hcd->speed == HCD_USB3) {
689 xhci_hub_report_link_state(&status, temp);
698 xhci_dbg(xhci,
"Get port status returned 0x%x\n", status);
703 link_state = (wIndex & 0xff00) >> 3;
705 wake_mask = wIndex & 0xff00;
707 timeout = (wIndex & 0xff00) >> 8;
709 if (!wIndex || wIndex > max_ports)
712 temp = xhci_readl(xhci, port_array[wIndex]);
713 if (temp == 0xffffffff) {
721 temp = xhci_readl(xhci, port_array[wIndex]);
722 if ((temp & PORT_PLS_MASK) !=
XDEV_U0) {
726 spin_unlock_irqrestore(&xhci->
lock, flags);
734 temp = xhci_readl(xhci, port_array[wIndex]);
735 if ((temp & PORT_PE) == 0 || (temp & PORT_RESET)
736 || (temp & PORT_PLS_MASK) >=
XDEV_U3) {
737 xhci_warn(xhci,
"USB core suspending device "
738 "not in U0/U1/U2.\n");
749 spin_unlock_irqrestore(&xhci->
lock, flags);
750 xhci_stop_device(xhci, slot_id, 1);
755 spin_unlock_irqrestore(&xhci->
lock, flags);
759 temp = xhci_readl(xhci, port_array[wIndex]);
763 temp = xhci_readl(xhci, port_array[wIndex]);
768 if ((temp & PORT_PE) == 0 ||
770 xhci_warn(xhci,
"Cannot set link state.\n");
780 spin_unlock_irqrestore(&xhci->
lock,
782 xhci_stop_device(xhci, slot_id, 1);
790 spin_unlock_irqrestore(&xhci->
lock, flags);
794 temp = xhci_readl(xhci, port_array[wIndex]);
805 xhci_writel(xhci, temp | PORT_POWER,
808 temp = xhci_readl(xhci, port_array[wIndex]);
809 xhci_dbg(xhci,
"set port power, actual port %d status = 0x%x\n", wIndex, temp);
811 spin_unlock_irqrestore(&xhci->
lock, flags);
821 xhci_writel(xhci, temp, port_array[wIndex]);
823 temp = xhci_readl(xhci, port_array[wIndex]);
824 xhci_dbg(xhci,
"set port reset, actual port %d status = 0x%x\n", wIndex, temp);
827 xhci_set_remote_wake_mask(xhci, port_array,
829 temp = xhci_readl(xhci, port_array[wIndex]);
830 xhci_dbg(xhci,
"set port remote wake mask, "
831 "actual port %d status = 0x%x\n",
836 xhci_writel(xhci, temp, port_array[wIndex]);
838 temp = xhci_readl(xhci, port_array[wIndex]);
841 if (hcd->speed != HCD_USB3)
843 temp = xhci_readl(xhci, port_array[wIndex] + 1);
846 xhci_writel(xhci, temp, port_array[wIndex] + 1);
849 if (hcd->speed != HCD_USB3)
851 temp = xhci_readl(xhci, port_array[wIndex] + 1);
854 xhci_writel(xhci, temp, port_array[wIndex] + 1);
860 temp = xhci_readl(xhci, port_array[wIndex]);
862 case ClearPortFeature:
863 if (!wIndex || wIndex > max_ports)
866 temp = xhci_readl(xhci, port_array[wIndex]);
867 if (temp == 0xffffffff) {
875 temp = xhci_readl(xhci, port_array[wIndex]);
876 xhci_dbg(xhci,
"clear USB_PORT_FEAT_SUSPEND\n");
877 xhci_dbg(xhci,
"PORTSC %04x\n", temp);
878 if (temp & PORT_RESET)
880 if ((temp & PORT_PLS_MASK) ==
XDEV_U3) {
881 if ((temp & PORT_PE) == 0)
886 spin_unlock_irqrestore(&xhci->
lock, flags);
897 xhci_dbg(xhci,
"slot_id is zero\n");
910 xhci_clear_port_change_bit(xhci, wValue, wIndex,
911 port_array[wIndex], temp);
914 xhci_disable_port(hcd, xhci, wIndex,
915 port_array[wIndex], temp);
918 xhci_writel(xhci, temp & ~PORT_POWER,
921 spin_unlock_irqrestore(&xhci->
lock, flags);
938 spin_unlock_irqrestore(&xhci->
lock, flags);
956 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
961 max_ports = xhci_get_ports(hcd, &port_array);
962 bus_state = &xhci->
bus_state[hcd_index(hcd)];
965 retval = (max_ports + 8) / 8;
978 for (i = 0; i < max_ports; i++) {
979 temp = xhci_readl(xhci, port_array[i]);
980 if (temp == 0xffffffff) {
984 if ((temp & mask) != 0 ||
988 buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
992 spin_unlock_irqrestore(&xhci->
lock, flags);
993 return status ? retval : 0;
1000 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1004 unsigned long flags;
1006 max_ports = xhci_get_ports(hcd, &port_array);
1007 bus_state = &xhci->
bus_state[hcd_index(hcd)];
1011 if (hcd->self.root_hub->do_remote_wakeup) {
1013 spin_unlock_irqrestore(&xhci->
lock, flags);
1014 xhci_dbg(xhci,
"suspend failed because "
1015 "a port is resuming\n");
1020 port_index = max_ports;
1022 while (port_index--) {
1027 t1 = xhci_readl(xhci, port_array[port_index]);
1030 if ((t1 &
PORT_PE) && !(t1 & PORT_PLS_MASK)) {
1031 xhci_dbg(xhci,
"port %d not suspended\n", port_index);
1035 spin_unlock_irqrestore(&xhci->
lock, flags);
1036 xhci_stop_device(xhci, slot_id, 1);
1039 t2 &= ~PORT_PLS_MASK;
1047 if (hcd->self.root_hub->do_remote_wakeup) {
1060 xhci_writel(xhci, t2, port_array[port_index]);
1062 if (hcd->speed != HCD_USB3) {
1070 addr = port_array[port_index] + 1;
1071 tmp = xhci_readl(xhci, addr);
1073 xhci_writel(xhci, tmp, addr);
1076 hcd->state = HC_STATE_SUSPENDED;
1078 spin_unlock_irqrestore(&xhci->
lock, flags);
1084 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1089 unsigned long flags;
1091 max_ports = xhci_get_ports(hcd, &port_array);
1092 bus_state = &xhci->
bus_state[hcd_index(hcd)];
1098 if (!HCD_HW_ACCESSIBLE(hcd)) {
1099 spin_unlock_irqrestore(&xhci->
lock, flags);
1104 temp = xhci_readl(xhci, &xhci->
op_regs->command);
1106 xhci_writel(xhci, temp, &xhci->
op_regs->command);
1108 port_index = max_ports;
1109 while (port_index--) {
1115 temp = xhci_readl(xhci, port_array[port_index]);
1129 spin_unlock_irqrestore(&xhci->
lock, flags);
1139 spin_unlock_irqrestore(&xhci->
lock, flags);
1148 xhci, port_index + 1);
1152 xhci_writel(xhci, temp, port_array[port_index]);
1154 if (hcd->speed != HCD_USB3) {
1162 addr = port_array[port_index] + 1;
1163 tmp = xhci_readl(xhci, addr);
1165 xhci_writel(xhci, tmp, addr);
1173 temp = xhci_readl(xhci, &xhci->
op_regs->command);
1175 xhci_writel(xhci, temp, &xhci->
op_regs->command);
1176 temp = xhci_readl(xhci, &xhci->
op_regs->command);
1178 spin_unlock_irqrestore(&xhci->
lock, flags);