Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * xHCI host controller driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Intel Corp. |
| 5 | * |
| 6 | * Author: Sarah Sharp |
| 7 | * Some code borrowed from the Linux EHCI driver. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 16 | * for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software Foundation, |
| 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <asm/unaligned.h> |
| 24 | |
| 25 | #include "xhci.h" |
| 26 | |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 27 | #define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E) |
| 28 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ |
| 29 | PORT_RC | PORT_PLC | PORT_PE) |
| 30 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 31 | static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 32 | struct usb_hub_descriptor *desc) |
| 33 | { |
| 34 | int ports; |
| 35 | u16 temp; |
| 36 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 37 | if (hcd->speed == HCD_USB3) |
| 38 | ports = xhci->num_usb3_ports; |
| 39 | else |
| 40 | ports = xhci->num_usb2_ports; |
| 41 | |
| 42 | /* FIXME: return a USB 3.0 hub descriptor if this request was for the |
| 43 | * USB3 roothub. |
| 44 | */ |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 45 | |
| 46 | /* USB 3.0 hubs have a different descriptor, but we fake this for now */ |
| 47 | desc->bDescriptorType = 0x29; |
| 48 | desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */ |
| 49 | desc->bHubContrCurrent = 0; |
| 50 | |
| 51 | desc->bNbrPorts = ports; |
| 52 | temp = 1 + (ports / 8); |
| 53 | desc->bDescLength = 7 + 2 * temp; |
| 54 | |
John Youn | dbe79bb | 2001-09-17 00:00:00 -0700 | [diff] [blame] | 55 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
| 56 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 57 | |
| 58 | /* Ugh, these should be #defines, FIXME */ |
| 59 | /* Using table 11-13 in USB 2.0 spec. */ |
| 60 | temp = 0; |
| 61 | /* Bits 1:0 - support port power switching, or power always on */ |
| 62 | if (HCC_PPC(xhci->hcc_params)) |
| 63 | temp |= 0x0001; |
| 64 | else |
| 65 | temp |= 0x0002; |
| 66 | /* Bit 2 - root hubs are not part of a compound device */ |
| 67 | /* Bits 4:3 - individual port over current protection */ |
| 68 | temp |= 0x0008; |
| 69 | /* Bits 6:5 - no TTs in root ports */ |
| 70 | /* Bit 7 - no port indicators */ |
| 71 | desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp); |
| 72 | } |
| 73 | |
| 74 | static unsigned int xhci_port_speed(unsigned int port_status) |
| 75 | { |
| 76 | if (DEV_LOWSPEED(port_status)) |
Alan Stern | 288ead4 | 2010-03-04 11:32:30 -0500 | [diff] [blame] | 77 | return USB_PORT_STAT_LOW_SPEED; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 78 | if (DEV_HIGHSPEED(port_status)) |
Alan Stern | 288ead4 | 2010-03-04 11:32:30 -0500 | [diff] [blame] | 79 | return USB_PORT_STAT_HIGH_SPEED; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 80 | if (DEV_SUPERSPEED(port_status)) |
Alan Stern | 288ead4 | 2010-03-04 11:32:30 -0500 | [diff] [blame] | 81 | return USB_PORT_STAT_SUPER_SPEED; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 82 | /* |
| 83 | * FIXME: Yes, we should check for full speed, but the core uses that as |
| 84 | * a default in portspeed() in usb/core/hub.c (which is the only place |
Alan Stern | 288ead4 | 2010-03-04 11:32:30 -0500 | [diff] [blame] | 85 | * USB_PORT_STAT_*_SPEED is used). |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 86 | */ |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * These bits are Read Only (RO) and should be saved and written to the |
| 92 | * registers: 0, 3, 10:13, 30 |
| 93 | * connect status, over-current status, port speed, and device removable. |
| 94 | * connect status and port speed are also sticky - meaning they're in |
| 95 | * the AUX well and they aren't changed by a hot, warm, or cold reset. |
| 96 | */ |
| 97 | #define XHCI_PORT_RO ((1<<0) | (1<<3) | (0xf<<10) | (1<<30)) |
| 98 | /* |
| 99 | * These bits are RW; writing a 0 clears the bit, writing a 1 sets the bit: |
| 100 | * bits 5:8, 9, 14:15, 25:27 |
| 101 | * link state, port power, port indicator state, "wake on" enable state |
| 102 | */ |
| 103 | #define XHCI_PORT_RWS ((0xf<<5) | (1<<9) | (0x3<<14) | (0x7<<25)) |
| 104 | /* |
| 105 | * These bits are RW; writing a 1 sets the bit, writing a 0 has no effect: |
| 106 | * bit 4 (port reset) |
| 107 | */ |
| 108 | #define XHCI_PORT_RW1S ((1<<4)) |
| 109 | /* |
| 110 | * These bits are RW; writing a 1 clears the bit, writing a 0 has no effect: |
| 111 | * bits 1, 17, 18, 19, 20, 21, 22, 23 |
| 112 | * port enable/disable, and |
| 113 | * change bits: connect, PED, warm port reset changed (reserved zero for USB 2.0 ports), |
| 114 | * over-current, reset, link state, and L1 change |
| 115 | */ |
| 116 | #define XHCI_PORT_RW1CS ((1<<1) | (0x7f<<17)) |
| 117 | /* |
| 118 | * Bit 16 is RW, and writing a '1' to it causes the link state control to be |
| 119 | * latched in |
| 120 | */ |
| 121 | #define XHCI_PORT_RW ((1<<16)) |
| 122 | /* |
| 123 | * These bits are Reserved Zero (RsvdZ) and zero should be written to them: |
| 124 | * bits 2, 24, 28:31 |
| 125 | */ |
| 126 | #define XHCI_PORT_RZ ((1<<2) | (1<<24) | (0xf<<28)) |
| 127 | |
| 128 | /* |
| 129 | * Given a port state, this function returns a value that would result in the |
| 130 | * port being in the same state, if the value was written to the port status |
| 131 | * control register. |
| 132 | * Save Read Only (RO) bits and save read/write bits where |
| 133 | * writing a 0 clears the bit and writing a 1 sets the bit (RWS). |
| 134 | * For all other types (RW1S, RW1CS, RW, and RZ), writing a '0' has no effect. |
| 135 | */ |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 136 | u32 xhci_port_state_to_neutral(u32 state) |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 137 | { |
| 138 | /* Save read-only status and port state */ |
| 139 | return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS); |
| 140 | } |
| 141 | |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 142 | /* |
| 143 | * find slot id based on port number. |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 144 | * @port: The one-based port number from one of the two split roothubs. |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 145 | */ |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 146 | int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
| 147 | u16 port) |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 148 | { |
| 149 | int slot_id; |
| 150 | int i; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 151 | enum usb_device_speed speed; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 152 | |
| 153 | slot_id = 0; |
| 154 | for (i = 0; i < MAX_HC_SLOTS; i++) { |
| 155 | if (!xhci->devs[i]) |
| 156 | continue; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 157 | speed = xhci->devs[i]->udev->speed; |
| 158 | if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3)) |
| 159 | && xhci->devs[i]->port == port) { |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 160 | slot_id = i; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return slot_id; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Stop device |
| 170 | * It issues stop endpoint command for EP 0 to 30. And wait the last command |
| 171 | * to complete. |
| 172 | * suspend will set to 1, if suspend bit need to set in command. |
| 173 | */ |
| 174 | static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) |
| 175 | { |
| 176 | struct xhci_virt_device *virt_dev; |
| 177 | struct xhci_command *cmd; |
| 178 | unsigned long flags; |
| 179 | int timeleft; |
| 180 | int ret; |
| 181 | int i; |
| 182 | |
| 183 | ret = 0; |
| 184 | virt_dev = xhci->devs[slot_id]; |
| 185 | cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO); |
| 186 | if (!cmd) { |
| 187 | xhci_dbg(xhci, "Couldn't allocate command structure.\n"); |
| 188 | return -ENOMEM; |
| 189 | } |
| 190 | |
| 191 | spin_lock_irqsave(&xhci->lock, flags); |
| 192 | for (i = LAST_EP_INDEX; i > 0; i--) { |
| 193 | if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) |
| 194 | xhci_queue_stop_endpoint(xhci, slot_id, i, suspend); |
| 195 | } |
| 196 | cmd->command_trb = xhci->cmd_ring->enqueue; |
| 197 | list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list); |
| 198 | xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend); |
| 199 | xhci_ring_cmd_db(xhci); |
| 200 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 201 | |
| 202 | /* Wait for last stop endpoint command to finish */ |
| 203 | timeleft = wait_for_completion_interruptible_timeout( |
| 204 | cmd->completion, |
| 205 | USB_CTRL_SET_TIMEOUT); |
| 206 | if (timeleft <= 0) { |
| 207 | xhci_warn(xhci, "%s while waiting for stop endpoint command\n", |
| 208 | timeleft == 0 ? "Timeout" : "Signal"); |
| 209 | spin_lock_irqsave(&xhci->lock, flags); |
| 210 | /* The timeout might have raced with the event ring handler, so |
| 211 | * only delete from the list if the item isn't poisoned. |
| 212 | */ |
| 213 | if (cmd->cmd_list.next != LIST_POISON1) |
| 214 | list_del(&cmd->cmd_list); |
| 215 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 216 | ret = -ETIME; |
| 217 | goto command_cleanup; |
| 218 | } |
| 219 | |
| 220 | command_cleanup: |
| 221 | xhci_free_command(xhci, cmd); |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Ring device, it rings the all doorbells unconditionally. |
| 227 | */ |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 228 | void xhci_ring_device(struct xhci_hcd *xhci, int slot_id) |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 229 | { |
| 230 | int i; |
| 231 | |
| 232 | for (i = 0; i < LAST_EP_INDEX + 1; i++) |
| 233 | if (xhci->devs[slot_id]->eps[i].ring && |
| 234 | xhci->devs[slot_id]->eps[i].ring->dequeue) |
| 235 | xhci_ring_ep_doorbell(xhci, slot_id, i, 0); |
| 236 | |
| 237 | return; |
| 238 | } |
| 239 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 240 | static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
| 241 | u16 wIndex, u32 __iomem *addr, u32 port_status) |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 242 | { |
Sarah Sharp | 6dd0a3a7 | 2010-11-16 15:58:52 -0800 | [diff] [blame] | 243 | /* Don't allow the USB core to disable SuperSpeed ports. */ |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 244 | if (hcd->speed == HCD_USB3) { |
Sarah Sharp | 6dd0a3a7 | 2010-11-16 15:58:52 -0800 | [diff] [blame] | 245 | xhci_dbg(xhci, "Ignoring request to disable " |
| 246 | "SuperSpeed port.\n"); |
| 247 | return; |
| 248 | } |
| 249 | |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 250 | /* Write 1 to disable the port */ |
| 251 | xhci_writel(xhci, port_status | PORT_PE, addr); |
| 252 | port_status = xhci_readl(xhci, addr); |
| 253 | xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n", |
| 254 | wIndex, port_status); |
| 255 | } |
| 256 | |
Sarah Sharp | 34fb562 | 2009-12-09 15:59:08 -0800 | [diff] [blame] | 257 | static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue, |
| 258 | u16 wIndex, u32 __iomem *addr, u32 port_status) |
| 259 | { |
| 260 | char *port_change_bit; |
| 261 | u32 status; |
| 262 | |
| 263 | switch (wValue) { |
| 264 | case USB_PORT_FEAT_C_RESET: |
| 265 | status = PORT_RC; |
| 266 | port_change_bit = "reset"; |
| 267 | break; |
| 268 | case USB_PORT_FEAT_C_CONNECTION: |
| 269 | status = PORT_CSC; |
| 270 | port_change_bit = "connect"; |
| 271 | break; |
| 272 | case USB_PORT_FEAT_C_OVER_CURRENT: |
| 273 | status = PORT_OCC; |
| 274 | port_change_bit = "over-current"; |
| 275 | break; |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 276 | case USB_PORT_FEAT_C_ENABLE: |
| 277 | status = PORT_PEC; |
| 278 | port_change_bit = "enable/disable"; |
| 279 | break; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 280 | case USB_PORT_FEAT_C_SUSPEND: |
| 281 | status = PORT_PLC; |
| 282 | port_change_bit = "suspend/resume"; |
| 283 | break; |
Sarah Sharp | 34fb562 | 2009-12-09 15:59:08 -0800 | [diff] [blame] | 284 | default: |
| 285 | /* Should never happen */ |
| 286 | return; |
| 287 | } |
| 288 | /* Change bits are all write 1 to clear */ |
| 289 | xhci_writel(xhci, port_status | status, addr); |
| 290 | port_status = xhci_readl(xhci, addr); |
| 291 | xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n", |
| 292 | port_change_bit, wIndex, port_status); |
| 293 | } |
| 294 | |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 295 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 296 | u16 wIndex, char *buf, u16 wLength) |
| 297 | { |
| 298 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 299 | int ports; |
| 300 | unsigned long flags; |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 301 | u32 temp, temp1, status; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 302 | int retval = 0; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 303 | u32 __iomem **port_array; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 304 | int slot_id; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 305 | struct xhci_bus_state *bus_state; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 306 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 307 | if (hcd->speed == HCD_USB3) { |
| 308 | ports = xhci->num_usb3_ports; |
| 309 | port_array = xhci->usb3_ports; |
| 310 | } else { |
| 311 | ports = xhci->num_usb2_ports; |
| 312 | port_array = xhci->usb2_ports; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 313 | } |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 314 | bus_state = &xhci->bus_state[hcd_index(hcd)]; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 315 | |
| 316 | spin_lock_irqsave(&xhci->lock, flags); |
| 317 | switch (typeReq) { |
| 318 | case GetHubStatus: |
| 319 | /* No power source, over-current reported per port */ |
| 320 | memset(buf, 0, 4); |
| 321 | break; |
| 322 | case GetHubDescriptor: |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 323 | xhci_hub_descriptor(hcd, xhci, |
| 324 | (struct usb_hub_descriptor *) buf); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 325 | break; |
| 326 | case GetPortStatus: |
| 327 | if (!wIndex || wIndex > ports) |
| 328 | goto error; |
| 329 | wIndex--; |
| 330 | status = 0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 331 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 332 | xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); |
| 333 | |
| 334 | /* wPortChange bits */ |
| 335 | if (temp & PORT_CSC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 336 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 337 | if (temp & PORT_PEC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 338 | status |= USB_PORT_STAT_C_ENABLE << 16; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 339 | if ((temp & PORT_OCC)) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 340 | status |= USB_PORT_STAT_C_OVERCURRENT << 16; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 341 | /* |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 342 | * FIXME ignoring reset and USB 2.1/3.0 specific |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 343 | * changes |
| 344 | */ |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 345 | if ((temp & PORT_PLS_MASK) == XDEV_U3 |
| 346 | && (temp & PORT_POWER)) |
| 347 | status |= 1 << USB_PORT_FEAT_SUSPEND; |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 348 | if ((temp & PORT_PLS_MASK) == XDEV_RESUME) { |
| 349 | if ((temp & PORT_RESET) || !(temp & PORT_PE)) |
| 350 | goto error; |
| 351 | if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies, |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 352 | bus_state->resume_done[wIndex])) { |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 353 | xhci_dbg(xhci, "Resume USB2 port %d\n", |
| 354 | wIndex + 1); |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 355 | bus_state->resume_done[wIndex] = 0; |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 356 | temp1 = xhci_port_state_to_neutral(temp); |
| 357 | temp1 &= ~PORT_PLS_MASK; |
| 358 | temp1 |= PORT_LINK_STROBE | XDEV_U0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 359 | xhci_writel(xhci, temp1, port_array[wIndex]); |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 360 | |
| 361 | xhci_dbg(xhci, "set port %d resume\n", |
| 362 | wIndex + 1); |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 363 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 364 | wIndex + 1); |
| 365 | if (!slot_id) { |
| 366 | xhci_dbg(xhci, "slot_id is zero\n"); |
| 367 | goto error; |
| 368 | } |
| 369 | xhci_ring_device(xhci, slot_id); |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 370 | bus_state->port_c_suspend |= 1 << wIndex; |
| 371 | bus_state->suspended_ports &= ~(1 << wIndex); |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 372 | } |
| 373 | } |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 374 | if ((temp & PORT_PLS_MASK) == XDEV_U0 |
| 375 | && (temp & PORT_POWER) |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 376 | && (bus_state->suspended_ports & (1 << wIndex))) { |
| 377 | bus_state->suspended_ports &= ~(1 << wIndex); |
| 378 | bus_state->port_c_suspend |= 1 << wIndex; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 379 | } |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 380 | if (temp & PORT_CONNECT) { |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 381 | status |= USB_PORT_STAT_CONNECTION; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 382 | status |= xhci_port_speed(temp); |
| 383 | } |
| 384 | if (temp & PORT_PE) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 385 | status |= USB_PORT_STAT_ENABLE; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 386 | if (temp & PORT_OC) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 387 | status |= USB_PORT_STAT_OVERCURRENT; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 388 | if (temp & PORT_RESET) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 389 | status |= USB_PORT_STAT_RESET; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 390 | if (temp & PORT_POWER) |
Alan Stern | 749da5f | 2010-03-04 17:05:08 -0500 | [diff] [blame] | 391 | status |= USB_PORT_STAT_POWER; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 392 | if (bus_state->port_c_suspend & (1 << wIndex)) |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 393 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 394 | xhci_dbg(xhci, "Get port status returned 0x%x\n", status); |
| 395 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
| 396 | break; |
| 397 | case SetPortFeature: |
| 398 | wIndex &= 0xff; |
| 399 | if (!wIndex || wIndex > ports) |
| 400 | goto error; |
| 401 | wIndex--; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 402 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 403 | temp = xhci_port_state_to_neutral(temp); |
| 404 | switch (wValue) { |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 405 | case USB_PORT_FEAT_SUSPEND: |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 406 | temp = xhci_readl(xhci, port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 407 | /* In spec software should not attempt to suspend |
| 408 | * a port unless the port reports that it is in the |
| 409 | * enabled (PED = ‘1’,PLS < ‘3’) state. |
| 410 | */ |
| 411 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) |
| 412 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { |
| 413 | xhci_warn(xhci, "USB core suspending device " |
| 414 | "not in U0/U1/U2.\n"); |
| 415 | goto error; |
| 416 | } |
| 417 | |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 418 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
| 419 | wIndex + 1); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 420 | if (!slot_id) { |
| 421 | xhci_warn(xhci, "slot_id is zero\n"); |
| 422 | goto error; |
| 423 | } |
| 424 | /* unlock to execute stop endpoint commands */ |
| 425 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 426 | xhci_stop_device(xhci, slot_id, 1); |
| 427 | spin_lock_irqsave(&xhci->lock, flags); |
| 428 | |
| 429 | temp = xhci_port_state_to_neutral(temp); |
| 430 | temp &= ~PORT_PLS_MASK; |
| 431 | temp |= PORT_LINK_STROBE | XDEV_U3; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 432 | xhci_writel(xhci, temp, port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 433 | |
| 434 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 435 | msleep(10); /* wait device to enter */ |
| 436 | spin_lock_irqsave(&xhci->lock, flags); |
| 437 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 438 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 439 | bus_state->suspended_ports |= 1 << wIndex; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 440 | break; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 441 | case USB_PORT_FEAT_POWER: |
| 442 | /* |
| 443 | * Turn on ports, even if there isn't per-port switching. |
| 444 | * HC will report connect events even before this is set. |
| 445 | * However, khubd will ignore the roothub events until |
| 446 | * the roothub is registered. |
| 447 | */ |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 448 | xhci_writel(xhci, temp | PORT_POWER, |
| 449 | port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 450 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 451 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 452 | xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); |
| 453 | break; |
| 454 | case USB_PORT_FEAT_RESET: |
| 455 | temp = (temp | PORT_RESET); |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 456 | xhci_writel(xhci, temp, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 457 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 458 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 459 | xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); |
| 460 | break; |
| 461 | default: |
| 462 | goto error; |
| 463 | } |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 464 | /* unblock any posted writes */ |
| 465 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 466 | break; |
| 467 | case ClearPortFeature: |
| 468 | if (!wIndex || wIndex > ports) |
| 469 | goto error; |
| 470 | wIndex--; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 471 | temp = xhci_readl(xhci, port_array[wIndex]); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 472 | temp = xhci_port_state_to_neutral(temp); |
| 473 | switch (wValue) { |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 474 | case USB_PORT_FEAT_SUSPEND: |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 475 | temp = xhci_readl(xhci, port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 476 | xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); |
| 477 | xhci_dbg(xhci, "PORTSC %04x\n", temp); |
| 478 | if (temp & PORT_RESET) |
| 479 | goto error; |
| 480 | if (temp & XDEV_U3) { |
| 481 | if ((temp & PORT_PE) == 0) |
| 482 | goto error; |
| 483 | if (DEV_SUPERSPEED(temp)) { |
| 484 | temp = xhci_port_state_to_neutral(temp); |
| 485 | temp &= ~PORT_PLS_MASK; |
| 486 | temp |= PORT_LINK_STROBE | XDEV_U0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 487 | xhci_writel(xhci, temp, |
| 488 | port_array[wIndex]); |
| 489 | xhci_readl(xhci, port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 490 | } else { |
| 491 | temp = xhci_port_state_to_neutral(temp); |
| 492 | temp &= ~PORT_PLS_MASK; |
| 493 | temp |= PORT_LINK_STROBE | XDEV_RESUME; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 494 | xhci_writel(xhci, temp, |
| 495 | port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 496 | |
| 497 | spin_unlock_irqrestore(&xhci->lock, |
| 498 | flags); |
| 499 | msleep(20); |
| 500 | spin_lock_irqsave(&xhci->lock, flags); |
| 501 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 502 | temp = xhci_readl(xhci, |
| 503 | port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 504 | temp = xhci_port_state_to_neutral(temp); |
| 505 | temp &= ~PORT_PLS_MASK; |
| 506 | temp |= PORT_LINK_STROBE | XDEV_U0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 507 | xhci_writel(xhci, temp, |
| 508 | port_array[wIndex]); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 509 | } |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 510 | bus_state->port_c_suspend |= 1 << wIndex; |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 513 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
| 514 | wIndex + 1); |
Andiry Xu | be88fe4 | 2010-10-14 07:22:57 -0700 | [diff] [blame] | 515 | if (!slot_id) { |
| 516 | xhci_dbg(xhci, "slot_id is zero\n"); |
| 517 | goto error; |
| 518 | } |
| 519 | xhci_ring_device(xhci, slot_id); |
| 520 | break; |
| 521 | case USB_PORT_FEAT_C_SUSPEND: |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 522 | bus_state->port_c_suspend &= ~(1 << wIndex); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 523 | case USB_PORT_FEAT_C_RESET: |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 524 | case USB_PORT_FEAT_C_CONNECTION: |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 525 | case USB_PORT_FEAT_C_OVER_CURRENT: |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 526 | case USB_PORT_FEAT_C_ENABLE: |
Sarah Sharp | 34fb562 | 2009-12-09 15:59:08 -0800 | [diff] [blame] | 527 | xhci_clear_port_change_bit(xhci, wValue, wIndex, |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 528 | port_array[wIndex], temp); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 529 | break; |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 530 | case USB_PORT_FEAT_ENABLE: |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 531 | xhci_disable_port(hcd, xhci, wIndex, |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 532 | port_array[wIndex], temp); |
Sarah Sharp | 6219c047 | 2009-12-09 15:59:11 -0800 | [diff] [blame] | 533 | break; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 534 | default: |
| 535 | goto error; |
| 536 | } |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 537 | break; |
| 538 | default: |
| 539 | error: |
| 540 | /* "stall" on error */ |
| 541 | retval = -EPIPE; |
| 542 | } |
| 543 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 544 | return retval; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Returns 0 if the status hasn't changed, or the number of bytes in buf. |
| 549 | * Ports are 0-indexed from the HCD point of view, |
| 550 | * and 1-indexed from the USB core pointer of view. |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 551 | * |
| 552 | * Note that the status change bits will be cleared as soon as a port status |
| 553 | * change event is generated, so we use the saved status from that event. |
| 554 | */ |
| 555 | int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) |
| 556 | { |
| 557 | unsigned long flags; |
| 558 | u32 temp, status; |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 559 | u32 mask; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 560 | int i, retval; |
| 561 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 562 | int ports; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 563 | u32 __iomem **port_array; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 564 | struct xhci_bus_state *bus_state; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 565 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 566 | if (hcd->speed == HCD_USB3) { |
| 567 | ports = xhci->num_usb3_ports; |
| 568 | port_array = xhci->usb3_ports; |
| 569 | } else { |
| 570 | ports = xhci->num_usb2_ports; |
| 571 | port_array = xhci->usb2_ports; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 572 | } |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 573 | bus_state = &xhci->bus_state[hcd_index(hcd)]; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 574 | |
| 575 | /* Initial status is no changes */ |
William Gulland | 419a8e81 | 2010-05-12 10:20:34 -0700 | [diff] [blame] | 576 | retval = (ports + 8) / 8; |
| 577 | memset(buf, 0, retval); |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 578 | status = 0; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 579 | |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 580 | mask = PORT_CSC | PORT_PEC | PORT_OCC; |
| 581 | |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 582 | spin_lock_irqsave(&xhci->lock, flags); |
| 583 | /* For each port, did anything change? If so, set that bit in buf. */ |
| 584 | for (i = 0; i < ports; i++) { |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 585 | temp = xhci_readl(xhci, port_array[i]); |
Andiry Xu | 5619253 | 2010-10-14 07:23:00 -0700 | [diff] [blame] | 586 | if ((temp & mask) != 0 || |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 587 | (bus_state->port_c_suspend & 1 << i) || |
| 588 | (bus_state->resume_done[i] && time_after_eq( |
| 589 | jiffies, bus_state->resume_done[i]))) { |
William Gulland | 419a8e81 | 2010-05-12 10:20:34 -0700 | [diff] [blame] | 590 | buf[(i + 1) / 8] |= 1 << (i + 1) % 8; |
Sarah Sharp | 0f2a793 | 2009-04-27 19:57:12 -0700 | [diff] [blame] | 591 | status = 1; |
| 592 | } |
| 593 | } |
| 594 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 595 | return status ? retval : 0; |
| 596 | } |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 597 | |
| 598 | #ifdef CONFIG_PM |
| 599 | |
| 600 | int xhci_bus_suspend(struct usb_hcd *hcd) |
| 601 | { |
| 602 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 603 | int max_ports, port_index; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 604 | u32 __iomem **port_array; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 605 | struct xhci_bus_state *bus_state; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 606 | unsigned long flags; |
| 607 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 608 | if (hcd->speed == HCD_USB3) { |
| 609 | max_ports = xhci->num_usb3_ports; |
| 610 | port_array = xhci->usb3_ports; |
| 611 | xhci_dbg(xhci, "suspend USB 3.0 root hub\n"); |
| 612 | } else { |
| 613 | max_ports = xhci->num_usb2_ports; |
| 614 | port_array = xhci->usb2_ports; |
| 615 | xhci_dbg(xhci, "suspend USB 2.0 root hub\n"); |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 616 | } |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 617 | bus_state = &xhci->bus_state[hcd_index(hcd)]; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 618 | |
| 619 | spin_lock_irqsave(&xhci->lock, flags); |
| 620 | |
| 621 | if (hcd->self.root_hub->do_remote_wakeup) { |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 622 | port_index = max_ports; |
| 623 | while (port_index--) { |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 624 | if (bus_state->resume_done[port_index] != 0) { |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 625 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 626 | xhci_dbg(xhci, "suspend failed because " |
| 627 | "port %d is resuming\n", |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 628 | port_index + 1); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 629 | return -EBUSY; |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 634 | port_index = max_ports; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 635 | bus_state->bus_suspended = 0; |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 636 | while (port_index--) { |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 637 | /* suspend the port if the port is not suspended */ |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 638 | u32 t1, t2; |
| 639 | int slot_id; |
| 640 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 641 | t1 = xhci_readl(xhci, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 642 | t2 = xhci_port_state_to_neutral(t1); |
| 643 | |
| 644 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 645 | xhci_dbg(xhci, "port %d not suspended\n", port_index); |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 646 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 647 | port_index + 1); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 648 | if (slot_id) { |
| 649 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 650 | xhci_stop_device(xhci, slot_id, 1); |
| 651 | spin_lock_irqsave(&xhci->lock, flags); |
| 652 | } |
| 653 | t2 &= ~PORT_PLS_MASK; |
| 654 | t2 |= PORT_LINK_STROBE | XDEV_U3; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 655 | set_bit(port_index, &bus_state->bus_suspended); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 656 | } |
| 657 | if (hcd->self.root_hub->do_remote_wakeup) { |
| 658 | if (t1 & PORT_CONNECT) { |
| 659 | t2 |= PORT_WKOC_E | PORT_WKDISC_E; |
| 660 | t2 &= ~PORT_WKCONN_E; |
| 661 | } else { |
| 662 | t2 |= PORT_WKOC_E | PORT_WKCONN_E; |
| 663 | t2 &= ~PORT_WKDISC_E; |
| 664 | } |
| 665 | } else |
| 666 | t2 &= ~PORT_WAKE_BITS; |
| 667 | |
| 668 | t1 = xhci_port_state_to_neutral(t1); |
| 669 | if (t1 != t2) |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 670 | xhci_writel(xhci, t2, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 671 | |
| 672 | if (DEV_HIGHSPEED(t1)) { |
| 673 | /* enable remote wake up for USB 2.0 */ |
| 674 | u32 __iomem *addr; |
| 675 | u32 tmp; |
| 676 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 677 | /* Add one to the port status register address to get |
| 678 | * the port power control register address. |
| 679 | */ |
| 680 | addr = port_array[port_index] + 1; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 681 | tmp = xhci_readl(xhci, addr); |
| 682 | tmp |= PORT_RWE; |
| 683 | xhci_writel(xhci, tmp, addr); |
| 684 | } |
| 685 | } |
| 686 | hcd->state = HC_STATE_SUSPENDED; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 687 | bus_state->next_statechange = jiffies + msecs_to_jiffies(10); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 688 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | int xhci_bus_resume(struct usb_hcd *hcd) |
| 693 | { |
| 694 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 695 | int max_ports, port_index; |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 696 | u32 __iomem **port_array; |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 697 | struct xhci_bus_state *bus_state; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 698 | u32 temp; |
| 699 | unsigned long flags; |
| 700 | |
Sarah Sharp | f6ff0ac | 2010-12-16 11:21:10 -0800 | [diff] [blame^] | 701 | if (hcd->speed == HCD_USB3) { |
| 702 | max_ports = xhci->num_usb3_ports; |
| 703 | port_array = xhci->usb3_ports; |
| 704 | xhci_dbg(xhci, "resume USB 3.0 root hub\n"); |
| 705 | } else { |
| 706 | max_ports = xhci->num_usb2_ports; |
| 707 | port_array = xhci->usb2_ports; |
| 708 | xhci_dbg(xhci, "resume USB 2.0 root hub\n"); |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 709 | } |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 710 | bus_state = &xhci->bus_state[hcd_index(hcd)]; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 711 | |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 712 | if (time_before(jiffies, bus_state->next_statechange)) |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 713 | msleep(5); |
| 714 | |
| 715 | spin_lock_irqsave(&xhci->lock, flags); |
| 716 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
| 717 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 718 | return -ESHUTDOWN; |
| 719 | } |
| 720 | |
| 721 | /* delay the irqs */ |
| 722 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
| 723 | temp &= ~CMD_EIE; |
| 724 | xhci_writel(xhci, temp, &xhci->op_regs->command); |
| 725 | |
Sarah Sharp | 518e848 | 2010-12-15 11:56:29 -0800 | [diff] [blame] | 726 | port_index = max_ports; |
| 727 | while (port_index--) { |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 728 | /* Check whether need resume ports. If needed |
| 729 | resume port and disable remote wakeup */ |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 730 | u32 temp; |
| 731 | int slot_id; |
| 732 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 733 | temp = xhci_readl(xhci, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 734 | if (DEV_SUPERSPEED(temp)) |
| 735 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); |
| 736 | else |
| 737 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 738 | if (test_bit(port_index, &bus_state->bus_suspended) && |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 739 | (temp & PORT_PLS_MASK)) { |
| 740 | if (DEV_SUPERSPEED(temp)) { |
| 741 | temp = xhci_port_state_to_neutral(temp); |
| 742 | temp &= ~PORT_PLS_MASK; |
| 743 | temp |= PORT_LINK_STROBE | XDEV_U0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 744 | xhci_writel(xhci, temp, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 745 | } else { |
| 746 | temp = xhci_port_state_to_neutral(temp); |
| 747 | temp &= ~PORT_PLS_MASK; |
| 748 | temp |= PORT_LINK_STROBE | XDEV_RESUME; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 749 | xhci_writel(xhci, temp, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 750 | |
| 751 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 752 | msleep(20); |
| 753 | spin_lock_irqsave(&xhci->lock, flags); |
| 754 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 755 | temp = xhci_readl(xhci, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 756 | temp = xhci_port_state_to_neutral(temp); |
| 757 | temp &= ~PORT_PLS_MASK; |
| 758 | temp |= PORT_LINK_STROBE | XDEV_U0; |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 759 | xhci_writel(xhci, temp, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 760 | } |
Sarah Sharp | 5233630 | 2010-12-16 10:49:09 -0800 | [diff] [blame] | 761 | slot_id = xhci_find_slot_id_by_port(hcd, |
| 762 | xhci, port_index + 1); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 763 | if (slot_id) |
| 764 | xhci_ring_device(xhci, slot_id); |
| 765 | } else |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 766 | xhci_writel(xhci, temp, port_array[port_index]); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 767 | |
| 768 | if (DEV_HIGHSPEED(temp)) { |
| 769 | /* disable remote wake up for USB 2.0 */ |
| 770 | u32 __iomem *addr; |
| 771 | u32 tmp; |
| 772 | |
Sarah Sharp | 5308a91 | 2010-12-01 11:34:59 -0800 | [diff] [blame] | 773 | /* Add one to the port status register address to get |
| 774 | * the port power control register address. |
| 775 | */ |
| 776 | addr = port_array[port_index] + 1; |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 777 | tmp = xhci_readl(xhci, addr); |
| 778 | tmp &= ~PORT_RWE; |
| 779 | xhci_writel(xhci, tmp, addr); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | (void) xhci_readl(xhci, &xhci->op_regs->command); |
| 784 | |
Sarah Sharp | 20b67cf | 2010-12-15 12:47:14 -0800 | [diff] [blame] | 785 | bus_state->next_statechange = jiffies + msecs_to_jiffies(5); |
Andiry Xu | 9777e3c | 2010-10-14 07:23:03 -0700 | [diff] [blame] | 786 | /* re-enable irqs */ |
| 787 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
| 788 | temp |= CMD_EIE; |
| 789 | xhci_writel(xhci, temp, &xhci->op_regs->command); |
| 790 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
| 791 | |
| 792 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 793 | return 0; |
| 794 | } |
| 795 | |
Sarah Sharp | 436a389 | 2010-10-15 14:59:15 -0700 | [diff] [blame] | 796 | #endif /* CONFIG_PM */ |