Commit a7114230 authored by Andiry Xu's avatar Andiry Xu Committed by Sarah Sharp

usbcore: Refine USB3.0 device suspend and resume

In the past, we use USB2.0 request to suspend and resume a USB3.0 device.
Actually, USB3.0 hub does not support Set/Clear PORT_SUSPEND request,
instead, it uses Set PORT_LINK_STATE request. This patch makes USB3.0 device
suspend/resume comply with USB3.0 specification.

This patch fixes the issue that USB3.0 device can not be suspended when
connected to a USB3.0 external hub.
Signed-off-by: default avatarAndiry Xu <andiry.xu@amd.com>
Signed-off-by: default avatarSarah Sharp <sarah.a.sharp@linux.intel.com>
parent 0ed9a57e
...@@ -2307,14 +2307,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) ...@@ -2307,14 +2307,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
} }
/* see 7.1.7.6 */ /* see 7.1.7.6 */
/* Clear PORT_POWER if it's a USB3.0 device connected to USB 3.0 if (hub_is_superspeed(hub->hdev))
* external hub. status = set_port_feature(hub->hdev,
* FIXME: this is a temporary workaround to make the system able port1 | (USB_SS_PORT_LS_U3 << 3),
* to suspend/resume. USB_PORT_FEAT_LINK_STATE);
*/
if ((hub->hdev->parent != NULL) && hub_is_superspeed(hub->hdev))
status = clear_port_feature(hub->hdev, port1,
USB_PORT_FEAT_POWER);
else else
status = set_port_feature(hub->hdev, port1, status = set_port_feature(hub->hdev, port1,
USB_PORT_FEAT_SUSPEND); USB_PORT_FEAT_SUSPEND);
...@@ -2469,8 +2465,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) ...@@ -2469,8 +2465,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
set_bit(port1, hub->busy_bits); set_bit(port1, hub->busy_bits);
/* see 7.1.7.7; affects power usage, but not budgeting */ /* see 7.1.7.7; affects power usage, but not budgeting */
status = clear_port_feature(hub->hdev, if (hub_is_superspeed(hub->hdev))
port1, USB_PORT_FEAT_SUSPEND); status = set_port_feature(hub->hdev,
port1 | (USB_SS_PORT_LS_U0 << 3),
USB_PORT_FEAT_LINK_STATE);
else
status = clear_port_feature(hub->hdev,
port1, USB_PORT_FEAT_SUSPEND);
if (status) { if (status) {
dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", dev_dbg(hub->intfdev, "can't resume port %d, status %d\n",
port1, status); port1, status);
...@@ -2492,9 +2493,15 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) ...@@ -2492,9 +2493,15 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
SuspendCleared: SuspendCleared:
if (status == 0) { if (status == 0) {
if (portchange & USB_PORT_STAT_C_SUSPEND) if (hub_is_superspeed(hub->hdev)) {
clear_port_feature(hub->hdev, port1, if (portchange & USB_PORT_STAT_C_LINK_STATE)
USB_PORT_FEAT_C_SUSPEND); clear_port_feature(hub->hdev, port1,
USB_PORT_FEAT_C_PORT_LINK_STATE);
} else {
if (portchange & USB_PORT_STAT_C_SUSPEND)
clear_port_feature(hub->hdev, port1,
USB_PORT_FEAT_C_SUSPEND);
}
} }
clear_bit(port1, hub->busy_bits); clear_bit(port1, hub->busy_bits);
......
...@@ -483,7 +483,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -483,7 +483,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
&& (temp & PORT_POWER) && (temp & PORT_POWER)
&& (bus_state->suspended_ports & (1 << wIndex))) { && (bus_state->suspended_ports & (1 << wIndex))) {
bus_state->suspended_ports &= ~(1 << wIndex); bus_state->suspended_ports &= ~(1 << wIndex);
bus_state->port_c_suspend |= 1 << wIndex; if (hcd->speed != HCD_USB3)
bus_state->port_c_suspend |= 1 << wIndex;
} }
if (temp & PORT_CONNECT) { if (temp & PORT_CONNECT) {
status |= USB_PORT_STAT_CONNECTION; status |= USB_PORT_STAT_CONNECTION;
...@@ -656,35 +657,27 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, ...@@ -656,35 +657,27 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
if (temp & XDEV_U3) { if (temp & XDEV_U3) {
if ((temp & PORT_PE) == 0) if ((temp & PORT_PE) == 0)
goto error; goto error;
if (DEV_SUPERSPEED(temp)) {
temp = xhci_port_state_to_neutral(temp);
temp &= ~PORT_PLS_MASK;
temp |= PORT_LINK_STROBE | XDEV_U0;
xhci_writel(xhci, temp,
port_array[wIndex]);
xhci_readl(xhci, port_array[wIndex]);
} else {
temp = xhci_port_state_to_neutral(temp);
temp &= ~PORT_PLS_MASK;
temp |= PORT_LINK_STROBE | XDEV_RESUME;
xhci_writel(xhci, temp,
port_array[wIndex]);
spin_unlock_irqrestore(&xhci->lock, temp = xhci_port_state_to_neutral(temp);
flags); temp &= ~PORT_PLS_MASK;
msleep(20); temp |= PORT_LINK_STROBE | XDEV_RESUME;
spin_lock_irqsave(&xhci->lock, flags); xhci_writel(xhci, temp,
port_array[wIndex]);
temp = xhci_readl(xhci, spin_unlock_irqrestore(&xhci->lock,
port_array[wIndex]); flags);
temp = xhci_port_state_to_neutral(temp); msleep(20);
temp &= ~PORT_PLS_MASK; spin_lock_irqsave(&xhci->lock, flags);
temp |= PORT_LINK_STROBE | XDEV_U0;
xhci_writel(xhci, temp, temp = xhci_readl(xhci,
port_array[wIndex]); port_array[wIndex]);
} temp = xhci_port_state_to_neutral(temp);
bus_state->port_c_suspend |= 1 << wIndex; temp &= ~PORT_PLS_MASK;
temp |= PORT_LINK_STROBE | XDEV_U0;
xhci_writel(xhci, temp,
port_array[wIndex]);
} }
bus_state->port_c_suspend |= 1 << wIndex;
slot_id = xhci_find_slot_id_by_port(hcd, xhci, slot_id = xhci_find_slot_id_by_port(hcd, xhci,
wIndex + 1); wIndex + 1);
...@@ -755,7 +748,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) ...@@ -755,7 +748,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
memset(buf, 0, retval); memset(buf, 0, retval);
status = 0; status = 0;
mask = PORT_CSC | PORT_PEC | PORT_OCC; mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC;
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
/* For each port, did anything change? If so, set that bit in buf. */ /* For each port, did anything change? If so, set that bit in buf. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment